зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1333589 - 3. Convert SiteIdentityPopup observers to events; r=sebastian
Convert the "Permissions:*" and "Session:Reload" observers to events that go through GlobalEventDispatcher.
This commit is contained in:
Родитель
174b21ef30
Коммит
caaf58697a
|
@ -865,12 +865,16 @@ public abstract class GeckoApp
|
|||
SparseBooleanArray checkedItemPositions = listView.getCheckedItemPositions();
|
||||
|
||||
// An array of the indices of the permissions we want to clear
|
||||
JSONArray permissionsToClear = new JSONArray();
|
||||
for (int i = 0; i < checkedItemPositions.size(); i++)
|
||||
if (checkedItemPositions.get(i))
|
||||
permissionsToClear.put(i);
|
||||
final ArrayList<Integer> permissionsToClear = new ArrayList<>();
|
||||
for (int i = 0; i < checkedItemPositions.size(); i++) {
|
||||
if (checkedItemPositions.get(i)) {
|
||||
permissionsToClear.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
GeckoAppShell.notifyObservers("Permissions:Clear", permissionsToClear.toString());
|
||||
final GeckoBundle data = new GeckoBundle(1);
|
||||
data.putIntArray("permissions", permissionsToClear);
|
||||
EventDispatcher.getInstance().dispatch("Permissions:Clear", data);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -572,7 +572,9 @@ public class Tab {
|
|||
}
|
||||
|
||||
public void doReload(boolean bypassCache) {
|
||||
GeckoAppShell.notifyObservers("Session:Reload", "{\"bypassCache\":" + String.valueOf(bypassCache) + "}");
|
||||
final GeckoBundle data = new GeckoBundle(1);
|
||||
data.putBoolean("bypassCache", bypassCache);
|
||||
EventDispatcher.getInstance().dispatch("Session:Reload", data);
|
||||
}
|
||||
|
||||
// Our version of nsSHistory::GetCanGoBack
|
||||
|
|
|
@ -153,7 +153,7 @@ public class SiteIdentityPopup extends AnchoredPopup implements BundleEventListe
|
|||
updateIdentityInformation(siteIdentity);
|
||||
}
|
||||
|
||||
GeckoAppShell.notifyObservers("Permissions:Check", null);
|
||||
EventDispatcher.getInstance().dispatch("Permissions:Check", null);
|
||||
}
|
||||
|
||||
@Override // BundleEventListener
|
||||
|
@ -175,7 +175,7 @@ public class SiteIdentityPopup extends AnchoredPopup implements BundleEventListe
|
|||
mSiteSettingsLink.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
GeckoAppShell.notifyObservers("Permissions:Get", null);
|
||||
EventDispatcher.getInstance().dispatch("Permissions:Get", null);
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
@ -552,7 +552,7 @@ public class SiteIdentityPopup extends AnchoredPopup implements BundleEventListe
|
|||
private class ContentNotificationButtonListener implements OnButtonClickListener {
|
||||
@Override
|
||||
public void onButtonClick(final GeckoBundle response, final DoorHanger doorhanger) {
|
||||
GeckoAppShell.notifyObservers("Session:Reload", response.toString());
|
||||
EventDispatcher.getInstance().dispatch("Session:Reload", response);
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,13 +55,15 @@ var PermissionsHelper = {
|
|||
}
|
||||
},
|
||||
|
||||
observe: function observe(aSubject, aTopic, aData) {
|
||||
onEvent: function onEvent(event, data, callback) {
|
||||
let uri = BrowserApp.selectedBrowser.currentURI;
|
||||
let check = false;
|
||||
|
||||
switch (aTopic) {
|
||||
switch (event) {
|
||||
case "Permissions:Check":
|
||||
check = true;
|
||||
// fall-through
|
||||
|
||||
case "Permissions:Get":
|
||||
let permissions = [];
|
||||
for (let i = 0; i < this._permissonTypes.length; i++) {
|
||||
|
@ -114,7 +116,7 @@ var PermissionsHelper = {
|
|||
|
||||
case "Permissions:Clear":
|
||||
// An array of the indices of the permissions we want to clear
|
||||
let permissionsToClear = JSON.parse(aData);
|
||||
let permissionsToClear = data.permissions;
|
||||
let privacyContext = BrowserApp.selectedBrowser.docShell
|
||||
.QueryInterface(Ci.nsILoadContext);
|
||||
|
||||
|
|
|
@ -155,7 +155,6 @@ lazilyLoadedBrowserScripts.forEach(function (aScript) {
|
|||
var lazilyLoadedObserverScripts = [
|
||||
["MemoryObserver", ["memory-pressure", "Memory:Dump"], "chrome://browser/content/MemoryObserver.js"],
|
||||
["ConsoleAPI", ["console-api-log-event"], "chrome://browser/content/ConsoleAPI.js"],
|
||||
["PermissionsHelper", ["Permissions:Check", "Permissions:Get", "Permissions:Clear"], "chrome://browser/content/PermissionsHelper.js"],
|
||||
["FeedHandler", ["Feeds:Subscribe"], "chrome://browser/content/FeedHandler.js"],
|
||||
["Feedback", ["Feedback:Show"], "chrome://browser/content/Feedback.js"],
|
||||
["EmbedRT", ["GeckoView:ImportScript"], "chrome://browser/content/EmbedRT.js"],
|
||||
|
@ -243,6 +242,9 @@ lazilyLoadedObserverScripts.forEach(function (aScript) {
|
|||
["HomeBanner:Get", "HomePanels:Get", "HomePanels:Authenticate",
|
||||
"HomePanels:RefreshView", "HomePanels:Installed", "HomePanels:Uninstalled"],
|
||||
"resource://gre/modules/Home.jsm"],
|
||||
["PermissionsHelper", GlobalEventDispatcher,
|
||||
["Permissions:Check", "Permissions:Get", "Permissions:Clear"],
|
||||
"chrome://browser/content/PermissionsHelper.js"],
|
||||
].forEach(module => {
|
||||
let [name, dispatcher, events, script] = module;
|
||||
XPCOMUtils.defineLazyGetter(window, name, function() {
|
||||
|
@ -382,6 +384,7 @@ var BrowserApp = {
|
|||
"Tab:Selected",
|
||||
"Tab:Closed",
|
||||
"Browser:LoadManifest",
|
||||
"Session:Reload",
|
||||
]);
|
||||
|
||||
Services.obs.addObserver(this, "Locale:OS", false);
|
||||
|
@ -389,7 +392,6 @@ var BrowserApp = {
|
|||
Services.obs.addObserver(this, "Session:Back", false);
|
||||
Services.obs.addObserver(this, "Session:Forward", false);
|
||||
Services.obs.addObserver(this, "Session:Navigate", false);
|
||||
Services.obs.addObserver(this, "Session:Reload", false);
|
||||
Services.obs.addObserver(this, "Session:Stop", false);
|
||||
Services.obs.addObserver(this, "SaveAs:PDF", false);
|
||||
Services.obs.addObserver(this, "Browser:Quit", false);
|
||||
|
@ -1638,6 +1640,58 @@ var BrowserApp = {
|
|||
break;
|
||||
}
|
||||
|
||||
case "Session:Reload": {
|
||||
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
|
||||
|
||||
// Check to see if this is a message to enable/disable mixed content blocking.
|
||||
if (data) {
|
||||
if (data.bypassCache) {
|
||||
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE |
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY;
|
||||
}
|
||||
|
||||
if (data.contentType === "tracking") {
|
||||
// Convert document URI into the format used by
|
||||
// nsChannelClassifier::ShouldEnableTrackingProtection
|
||||
// (any scheme turned into https is correct)
|
||||
let normalizedUrl = Services.io.newURI("https://" + browser.currentURI.hostPort);
|
||||
if (data.allowContent) {
|
||||
// Add the current host in the 'trackingprotection' consumer of
|
||||
// the permission manager using a normalized URI. This effectively
|
||||
// places this host on the tracking protection white list.
|
||||
if (PrivateBrowsingUtils.isBrowserPrivate(browser)) {
|
||||
PrivateBrowsingUtils.addToTrackingAllowlist(normalizedUrl);
|
||||
} else {
|
||||
Services.perms.add(normalizedUrl, "trackingprotection", Services.perms.ALLOW_ACTION);
|
||||
Telemetry.addData("TRACKING_PROTECTION_EVENTS", 1);
|
||||
}
|
||||
} else {
|
||||
// Remove the current host from the 'trackingprotection' consumer
|
||||
// of the permission manager. This effectively removes this host
|
||||
// from the tracking protection white list (any list actually).
|
||||
if (PrivateBrowsingUtils.isBrowserPrivate(browser)) {
|
||||
PrivateBrowsingUtils.removeFromTrackingAllowlist(normalizedUrl);
|
||||
} else {
|
||||
Services.perms.remove(normalizedUrl, "trackingprotection");
|
||||
Telemetry.addData("TRACKING_PROTECTION_EVENTS", 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try to use the session history to reload so that framesets are
|
||||
// handled properly. If the window has no session history, fall back
|
||||
// to using the web navigation's reload method.
|
||||
let webNav = browser.webNavigation;
|
||||
try {
|
||||
let sh = webNav.sessionHistory;
|
||||
if (sh)
|
||||
webNav = sh.QueryInterface(Ci.nsIWebNavigation);
|
||||
} catch (e) {}
|
||||
webNav.reload(flags);
|
||||
break;
|
||||
}
|
||||
|
||||
case "Tab:Load": {
|
||||
let url = data.url;
|
||||
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP
|
||||
|
@ -1727,60 +1781,6 @@ var BrowserApp = {
|
|||
browser.gotoIndex(index);
|
||||
break;
|
||||
|
||||
case "Session:Reload": {
|
||||
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
|
||||
|
||||
// Check to see if this is a message to enable/disable mixed content blocking.
|
||||
if (aData) {
|
||||
let data = JSON.parse(aData);
|
||||
|
||||
if (data.bypassCache) {
|
||||
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE |
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY;
|
||||
}
|
||||
|
||||
if (data.contentType === "tracking") {
|
||||
// Convert document URI into the format used by
|
||||
// nsChannelClassifier::ShouldEnableTrackingProtection
|
||||
// (any scheme turned into https is correct)
|
||||
let normalizedUrl = Services.io.newURI("https://" + browser.currentURI.hostPort);
|
||||
if (data.allowContent) {
|
||||
// Add the current host in the 'trackingprotection' consumer of
|
||||
// the permission manager using a normalized URI. This effectively
|
||||
// places this host on the tracking protection white list.
|
||||
if (PrivateBrowsingUtils.isBrowserPrivate(browser)) {
|
||||
PrivateBrowsingUtils.addToTrackingAllowlist(normalizedUrl);
|
||||
} else {
|
||||
Services.perms.add(normalizedUrl, "trackingprotection", Services.perms.ALLOW_ACTION);
|
||||
Telemetry.addData("TRACKING_PROTECTION_EVENTS", 1);
|
||||
}
|
||||
} else {
|
||||
// Remove the current host from the 'trackingprotection' consumer
|
||||
// of the permission manager. This effectively removes this host
|
||||
// from the tracking protection white list (any list actually).
|
||||
if (PrivateBrowsingUtils.isBrowserPrivate(browser)) {
|
||||
PrivateBrowsingUtils.removeFromTrackingAllowlist(normalizedUrl);
|
||||
} else {
|
||||
Services.perms.remove(normalizedUrl, "trackingprotection");
|
||||
Telemetry.addData("TRACKING_PROTECTION_EVENTS", 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try to use the session history to reload so that framesets are
|
||||
// handled properly. If the window has no session history, fall back
|
||||
// to using the web navigation's reload method.
|
||||
let webNav = browser.webNavigation;
|
||||
try {
|
||||
let sh = webNav.sessionHistory;
|
||||
if (sh)
|
||||
webNav = sh.QueryInterface(Ci.nsIWebNavigation);
|
||||
} catch (e) {}
|
||||
webNav.reload(flags);
|
||||
break;
|
||||
}
|
||||
|
||||
case "Session:Stop":
|
||||
browser.stop();
|
||||
break;
|
||||
|
@ -2174,8 +2174,10 @@ var BrowserApp = {
|
|||
|
||||
var NativeWindow = {
|
||||
init: function() {
|
||||
GlobalEventDispatcher.registerListener(this, [
|
||||
"Doorhanger:Reply",
|
||||
]);
|
||||
Services.obs.addObserver(this, "Menu:Clicked", false);
|
||||
Services.obs.addObserver(this, "Doorhanger:Reply", false);
|
||||
this.contextmenus.init();
|
||||
},
|
||||
|
||||
|
@ -2307,12 +2309,8 @@ var NativeWindow = {
|
|||
}
|
||||
},
|
||||
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
if (aTopic == "Menu:Clicked") {
|
||||
if (this.menu._callbacks[aData])
|
||||
this.menu._callbacks[aData]();
|
||||
} else if (aTopic == "Doorhanger:Reply") {
|
||||
let data = JSON.parse(aData);
|
||||
onEvent: function (event, data, callback) {
|
||||
if (event == "Doorhanger:Reply") {
|
||||
let reply_id = data["callback"];
|
||||
|
||||
if (this.doorhanger._callbacks[reply_id]) {
|
||||
|
@ -2330,6 +2328,13 @@ var NativeWindow = {
|
|||
}
|
||||
},
|
||||
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
if (aTopic == "Menu:Clicked") {
|
||||
if (this.menu._callbacks[aData])
|
||||
this.menu._callbacks[aData]();
|
||||
}
|
||||
},
|
||||
|
||||
contextmenus: {
|
||||
items: {}, // a list of context menu items that we may show
|
||||
DEFAULT_HTML5_ORDER: -1, // Sort order for HTML5 context menu items
|
||||
|
|
|
@ -111,13 +111,19 @@ add_task(function* test_tracking_pb() {
|
|||
// Simulate a click on the "Disable protection" button in the site identity popup.
|
||||
// We need to wait for a "load" event because "Session:Reload" will cause a full page reload.
|
||||
yield promiseLoadEvent(browser, undefined, undefined, () => {
|
||||
Services.obs.notifyObservers(null, "Session:Reload", "{\"allowContent\":true,\"contentType\":\"tracking\"}");
|
||||
EventDispatcher.instance.dispatch("Session:Reload", {
|
||||
allowContent: true,
|
||||
contentType: "tracking",
|
||||
});
|
||||
});
|
||||
Messaging.sendRequest({ type: "Test:Expected", expected: "tracking_content_loaded" });
|
||||
|
||||
// Simulate a click on the "Enable protection" button in the site identity popup.
|
||||
yield promiseLoadEvent(browser, undefined, undefined, () => {
|
||||
Services.obs.notifyObservers(null, "Session:Reload", "{\"allowContent\":false,\"contentType\":\"tracking\"}");
|
||||
EventDispatcher.instance.dispatch("Session:Reload", {
|
||||
allowContent: false,
|
||||
contentType: "tracking",
|
||||
});
|
||||
});
|
||||
Messaging.sendRequest({ type: "Test:Expected", expected: "tracking_content_blocked" });
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче