Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: mobile/android/chrome/content/browser.js

Issue 5365916275572736: Issue 2351 - Add a custom menu item for whitelisting the current site (Closed)
Patch Set: Created April 25, 2015, 9:45 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mobile/android/base/strings.xml.in ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #filter substitution 1 #filter substitution
2 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2- skip-preprocessor-directives: t; -*- 2 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2- skip-preprocessor-directives: t; -*-
3 /* This Source Code Form is subject to the terms of the Mozilla Public 3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 "use strict"; 6 "use strict";
7 7
8 let Cc = Components.classes; 8 let Cc = Components.classes;
9 let Ci = Components.interfaces; 9 let Ci = Components.interfaces;
10 let Cu = Components.utils; 10 let Cu = Components.utils;
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 Services.obs.addObserver(this, "webapps-runtime-install", false); 356 Services.obs.addObserver(this, "webapps-runtime-install", false);
357 Services.obs.addObserver(this, "webapps-runtime-install-package", false); 357 Services.obs.addObserver(this, "webapps-runtime-install-package", false);
358 Services.obs.addObserver(this, "webapps-ask-install", false); 358 Services.obs.addObserver(this, "webapps-ask-install", false);
359 Services.obs.addObserver(this, "webapps-ask-uninstall", false); 359 Services.obs.addObserver(this, "webapps-ask-uninstall", false);
360 Services.obs.addObserver(this, "webapps-launch", false); 360 Services.obs.addObserver(this, "webapps-launch", false);
361 Services.obs.addObserver(this, "webapps-runtime-uninstall", false); 361 Services.obs.addObserver(this, "webapps-runtime-uninstall", false);
362 Services.obs.addObserver(this, "Webapps:AutoInstall", false); 362 Services.obs.addObserver(this, "Webapps:AutoInstall", false);
363 Services.obs.addObserver(this, "Webapps:Load", false); 363 Services.obs.addObserver(this, "Webapps:Load", false);
364 Services.obs.addObserver(this, "Webapps:AutoUninstall", false); 364 Services.obs.addObserver(this, "Webapps:AutoUninstall", false);
365 Services.obs.addObserver(this, "sessionstore-state-purge-complete", false); 365 Services.obs.addObserver(this, "sessionstore-state-purge-complete", false);
366 Services.obs.addObserver(this, "BlockAds:Change", false);
366 367
367 function showFullScreenWarning() { 368 function showFullScreenWarning() {
368 NativeWindow.toast.show(Strings.browser.GetStringFromName("alertFullScreen Toast"), "short"); 369 NativeWindow.toast.show(Strings.browser.GetStringFromName("alertFullScreen Toast"), "short");
369 } 370 }
370 371
371 window.addEventListener("fullscreen", function() { 372 window.addEventListener("fullscreen", function() {
372 sendMessageToJava({ 373 sendMessageToJava({
373 type: window.fullScreen ? "ToggleChrome:Show" : "ToggleChrome:Hide" 374 type: window.fullScreen ? "ToggleChrome:Show" : "ToggleChrome:Hide"
374 }); 375 });
375 }, false); 376 }, false);
(...skipping 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 1756
1756 // Ensure that this choice is immediately persisted, because 1757 // Ensure that this choice is immediately persisted, because
1757 // Gecko won't be told again if it forgets. 1758 // Gecko won't be told again if it forgets.
1758 Services.prefs.savePrefFile(null); 1759 Services.prefs.savePrefFile(null);
1759 1760
1760 // Blow away the string cache so that future lookups get the 1761 // Blow away the string cache so that future lookups get the
1761 // correct locale. 1762 // correct locale.
1762 Services.strings.flushBundles(); 1763 Services.strings.flushBundles();
1763 break; 1764 break;
1764 1765
1766 case "BlockAds:Change":
1767 let {blockAds, url} = JSON.parse(aData);
1768 let ioService = Cc["@mozilla.org/network/io-service;1"]
1769 .getService(Ci.nsIIOService);
1770 url = ioService.newURI(url, null, null).QueryInterface(Ci.nsIURL);
1771 AdblockPlusApi.whitelistSite(url, !blockAds);
1772 browser.webNavigation.reload(Ci.nsIWebNavigation.LOAD_FLAGS_NONE);
1773
1765 default: 1774 default:
1766 dump('BrowserApp.observe: unexpected topic "' + aTopic + '"\n'); 1775 dump('BrowserApp.observe: unexpected topic "' + aTopic + '"\n');
1767 break; 1776 break;
1768 1777
1769 } 1778 }
1770 }, 1779 },
1771 1780
1772 get defaultBrowserWidth() { 1781 get defaultBrowserWidth() {
1773 delete this.defaultBrowserWidth; 1782 delete this.defaultBrowserWidth;
1774 let width = Services.prefs.getIntPref("browser.viewport.desktopWidth"); 1783 let width = Services.prefs.getIntPref("browser.viewport.desktopWidth");
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 1927
1919 sendMessageToJava(msg); 1928 sendMessageToJava(msg);
1920 } 1929 }
1921 }, 1930 },
1922 1931
1923 menu: { 1932 menu: {
1924 _callbacks: [], 1933 _callbacks: [],
1925 _menuId: 1, 1934 _menuId: 1,
1926 toolsMenuID: -1, 1935 toolsMenuID: -1,
1927 add: function() { 1936 add: function() {
1937 // Adblock Browser doesn't support add-ons, so the only menu item that
1938 // could be added is the one for whitelisting the current domain added by
1939 // ABP - Adblock Browser has its own item for that.
1940 return;
1941
1928 let options; 1942 let options;
1929 if (arguments.length == 1) { 1943 if (arguments.length == 1) {
1930 options = arguments[0]; 1944 options = arguments[0];
1931 } else if (arguments.length == 3) { 1945 } else if (arguments.length == 3) {
1932 options = { 1946 options = {
1933 name: arguments[0], 1947 name: arguments[0],
1934 icon: arguments[1], 1948 icon: arguments[1],
1935 callback: arguments[2] 1949 callback: arguments[2]
1936 }; 1950 };
1937 } else { 1951 } else {
(...skipping 2271 matching lines...) Expand 10 before | Expand all | Expand 10 after
4209 if (bannedSchemes.indexOf(fixedURI.scheme) > -1) { 4223 if (bannedSchemes.indexOf(fixedURI.scheme) > -1) {
4210 aRequest.cancel(Cr.NS_BINDING_ABORTED); 4224 aRequest.cancel(Cr.NS_BINDING_ABORTED);
4211 4225
4212 aRequest = this.browser.docShell.displayLoadError(Cr.NS_ERROR_UNKNOWN_PR OTOCOL, fixedURI, null); 4226 aRequest = this.browser.docShell.displayLoadError(Cr.NS_ERROR_UNKNOWN_PR OTOCOL, fixedURI, null);
4213 if (aRequest) { 4227 if (aRequest) {
4214 fixedURI = aRequest.URI; 4228 fixedURI = aRequest.URI;
4215 } 4229 }
4216 } 4230 }
4217 } 4231 }
4218 4232
4233 let canBlockAds = !AdblockPlusApi.isLocal(fixedURI);
4234 sendMessageToJava({
4235 type: "BlockAds:Update",
4236 canBlockAds: canBlockAds,
4237 blockAds: canBlockAds && !AdblockPlusApi.isPageWhitelisted(fixedURI)
4238 });
4239
4219 let contentType = contentWin.document.contentType; 4240 let contentType = contentWin.document.contentType;
4220 4241
4221 // If fixedURI matches browser.lastURI, we assume this isn't a real location 4242 // If fixedURI matches browser.lastURI, we assume this isn't a real location
4222 // change but rather a spurious addition like a wyciwyg URI prefix. See Bug 747883. 4243 // change but rather a spurious addition like a wyciwyg URI prefix. See Bug 747883.
4223 // Note that we have to ensure fixedURI is not the same as aLocationURI so w e 4244 // Note that we have to ensure fixedURI is not the same as aLocationURI so w e
4224 // don't false-positive page reloads as spurious additions. 4245 // don't false-positive page reloads as spurious additions.
4225 let sameDocument = (aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_ DOCUMENT) != 0 || 4246 let sameDocument = (aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_ DOCUMENT) != 0 ||
4226 ((this.browser.lastURI != null) && fixedURI.equals(this.b rowser.lastURI) && !fixedURI.equals(aLocationURI)); 4247 ((this.browser.lastURI != null) && fixedURI.equals(this.b rowser.lastURI) && !fixedURI.equals(aLocationURI));
4227 this.browser.lastURI = fixedURI; 4248 this.browser.lastURI = fixedURI;
4228 4249
(...skipping 4216 matching lines...) Expand 10 before | Expand all | Expand 10 after
8445 disabled: elt.disabled, 8466 disabled: elt.disabled,
8446 menu: elt instanceof Ci.nsIDOMHTMLMenuElement 8467 menu: elt instanceof Ci.nsIDOMHTMLMenuElement
8447 }; 8468 };
8448 } 8469 }
8449 }, 8470 },
8450 }); 8471 });
8451 8472
8452 let {AdblockPlusApi} = Cu.import("chrome://adblockplus/content/Api.jsm"); 8473 let {AdblockPlusApi} = Cu.import("chrome://adblockplus/content/Api.jsm");
8453 AdblockPlusApi.initCommunication(); 8474 AdblockPlusApi.initCommunication();
8454 8475
OLDNEW
« no previous file with comments | « mobile/android/base/strings.xml.in ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld