Skip to content

Commit 4137a92

Browse files
author
Ehsan Akhgari
committed
Bug 1514340 - Part 2: Break out the content blocking related notifications into nsIWebProgressListener.onContentBlockingEvent(); r=baku,johannh
Differential Revision: https://phabricator.services.mozilla.com/D16052
1 parent 5d7e383 commit 4137a92

File tree

77 files changed

+496
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+496
-172
lines changed

accessible/base/DocManager.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ DocManager::OnSecurityChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest,
308308
return NS_OK;
309309
}
310310

311+
NS_IMETHODIMP
312+
DocManager::OnContentBlockingEvent(nsIWebProgress* aWebProgress,
313+
nsIRequest* aRequest, uint32_t aEvent) {
314+
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
315+
return NS_OK;
316+
}
317+
311318
////////////////////////////////////////////////////////////////////////////////
312319
// nsIDOMEventListener
313320

browser/base/content/browser-contentblocking.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ var ContentBlocking = {
812812
Services.telemetry.getHistogramById("TRACKING_PROTECTION_SHIELD").add(value);
813813
},
814814

815-
onSecurityChange(state, webProgress, isSimulated) {
815+
onContentBlockingEvent(event, webProgress, isSimulated) {
816816
let baseURI = this._baseURIForChannelClassifier;
817817

818818
// Don't deal with about:, file: etc.
@@ -831,9 +831,9 @@ var ContentBlocking = {
831831
// reporting it using the "report breakage" dialog. Under normal circumstances this
832832
// dialog should only be able to open in the currently selected tab and onSecurityChange
833833
// runs on tab switch, so we can avoid associating the data with the document directly.
834-
blocker.activated = blocker.isBlocking(state);
834+
blocker.activated = blocker.isBlocking(event);
835835
blocker.categoryItem.classList.toggle("blocked", blocker.enabled);
836-
let detected = blocker.isDetected(state);
836+
let detected = blocker.isDetected(event);
837837
blocker.categoryItem.hidden = !detected;
838838
anyDetected = anyDetected || detected;
839839
anyBlocking = anyBlocking || blocker.activated;

browser/base/content/browser.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4898,13 +4898,40 @@ var XULBrowserWindow = {
48984898
// Properties used to cache security state used to update the UI
48994899
_state: null,
49004900
_lastLocation: null,
4901+
_event: null,
4902+
_lastLocationForEvent: null,
49014903

49024904
// This is called in multiple ways:
4903-
// 1. Due to the nsIWebProgressListener.onSecurityChange notification.
4905+
// 1. Due to the nsIWebProgressListener.onContentBlockingEvent notification.
49044906
// 2. Called by tabbrowser.xml when updating the current browser.
49054907
// 3. Called directly during this object's initializations.
4908+
// 4. Due to the nsIWebProgressListener.onLocationChange notification.
49064909
// aRequest will be null always in case 2 and 3, and sometimes in case 1 (for
49074910
// instance, there won't be a request when STATE_BLOCKED_TRACKING_CONTENT is observed).
4911+
onContentBlockingEvent(aWebProgress, aRequest, aEvent, aIsSimulated) {
4912+
// Don't need to do anything if the data we use to update the UI hasn't
4913+
// changed
4914+
let uri = gBrowser.currentURI;
4915+
let spec = uri.spec;
4916+
if (this._event == aEvent &&
4917+
this._lastLocationForEvent == spec) {
4918+
return;
4919+
}
4920+
this._event = aEvent;
4921+
this._lastLocationForEvent = spec;
4922+
4923+
if (typeof(aIsSimulated) != "boolean" && typeof(aIsSimulated) != "undefined") {
4924+
throw "onContentBlockingEvent: aIsSimulated receieved an unexpected type";
4925+
}
4926+
4927+
ContentBlocking.onContentBlockingEvent(this._event, aWebProgress, aIsSimulated);
4928+
},
4929+
4930+
// This is called in multiple ways:
4931+
// 1. Due to the nsIWebProgressListener.onSecurityChange notification.
4932+
// 2. Called by tabbrowser.xml when updating the current browser.
4933+
// 3. Called directly during this object's initializations.
4934+
// aRequest will be null always in case 2 and 3, and sometimes in case 1.
49084935
onSecurityChange(aWebProgress, aRequest, aState, aIsSimulated) {
49094936
// Don't need to do anything if the data we use to update the UI hasn't
49104937
// changed
@@ -4920,10 +4947,6 @@ var XULBrowserWindow = {
49204947
this._state = aState;
49214948
this._lastLocation = spec;
49224949

4923-
if (typeof(aIsSimulated) != "boolean" && typeof(aIsSimulated) != "undefined") {
4924-
throw "onSecurityChange: aIsSimulated receieved an unexpected type";
4925-
}
4926-
49274950
// Make sure the "https" part of the URL is striked out or not,
49284951
// depending on the current mixed active content blocking state.
49294952
gURLBar.formatValue();
@@ -4932,7 +4955,6 @@ var XULBrowserWindow = {
49324955
uri = Services.uriFixup.createExposableURI(uri);
49334956
} catch (e) {}
49344957
gIdentityHandler.updateIdentity(this._state, uri);
4935-
ContentBlocking.onSecurityChange(this._state, aWebProgress, aIsSimulated);
49364958
},
49374959

49384960
// simulate all change notifications after switching tabs

browser/base/content/tabbrowser.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -968,10 +968,13 @@ window._gBrowser = {
968968

969969
let securityUI = newBrowser.securityUI;
970970
if (securityUI) {
971+
this._callProgressListeners(null, "onSecurityChange",
972+
[webProgress, null, securityUI.state],
973+
true, false);
971974
// Include the true final argument to indicate that this event is
972975
// simulated (instead of being observed by the webProgressListener).
973-
this._callProgressListeners(null, "onSecurityChange",
974-
[webProgress, null, securityUI.state, true],
976+
this._callProgressListeners(null, "onContentBlockingEvent",
977+
[webProgress, null, securityUI.contentBlockingEvent, true],
975978
true, false);
976979
}
977980

@@ -1718,10 +1721,14 @@ window._gBrowser = {
17181721
let securityUI = aBrowser.securityUI;
17191722
let state = securityUI ? securityUI.state :
17201723
Ci.nsIWebProgressListener.STATE_IS_INSECURE;
1724+
this._callProgressListeners(aBrowser, "onSecurityChange",
1725+
[aBrowser.webProgress, null, state],
1726+
true, false);
1727+
let event = securityUI ? securityUI.contentBlockingEvent : 0;
17211728
// Include the true final argument to indicate that this event is
17221729
// simulated (instead of being observed by the webProgressListener).
1723-
this._callProgressListeners(aBrowser, "onSecurityChange",
1724-
[aBrowser.webProgress, null, state, true],
1730+
this._callProgressListeners(aBrowser, "onContentBlockingEvent",
1731+
[aBrowser.webProgress, null, event, true],
17251732
true, false);
17261733

17271734
if (aShouldBeRemote) {
@@ -5192,6 +5199,10 @@ class TabProgressListener {
51925199
if (!this.mBlank) {
51935200
this._callProgressListeners("onLocationChange",
51945201
[aWebProgress, aRequest, aLocation, aFlags]);
5202+
// Include the true final argument to indicate that this event is
5203+
// simulated (instead of being observed by the webProgressListener).
5204+
this._callProgressListeners("onContentBlockingEvent",
5205+
[aWebProgress, null, 0, true]);
51955206
}
51965207

51975208
if (topLevel) {
@@ -5215,6 +5226,11 @@ class TabProgressListener {
52155226
[aWebProgress, aRequest, aState]);
52165227
}
52175228

5229+
onContentBlockingEvent(aWebProgress, aRequest, aEvent) {
5230+
this._callProgressListeners("onContentBlockingEvent",
5231+
[aWebProgress, aRequest, aEvent]);
5232+
}
5233+
52185234
onRefreshAttempted(aWebProgress, aURI, aDelay, aSameURI) {
52195235
return this._callProgressListeners("onRefreshAttempted",
52205236
[aWebProgress, aURI, aDelay, aSameURI]);

browser/base/content/test/trackingUI/browser_trackingUI_animation_2.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,21 @@ async function testTrackingProtectionAnimation(tabbrowser) {
6969
ok(!ContentBlocking.iconBox.hasAttribute("animate"), "iconBox not animating");
7070

7171
info("Reload tracking cookies tab");
72-
securityChanged = waitForSecurityChange(2, tabbrowser.ownerGlobal);
72+
securityChanged = waitForSecurityChange(1, tabbrowser.ownerGlobal);
73+
let contentBlockingEvent = waitForContentBlockingEvent(2, tabbrowser.ownerGlobal);
7374
tabbrowser.reload();
74-
await securityChanged;
75+
await Promise.all([securityChanged, contentBlockingEvent]);
7576

7677
ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active");
7778
ok(ContentBlocking.iconBox.hasAttribute("animate"), "iconBox animating");
7879
await BrowserTestUtils.waitForEvent(ContentBlocking.animatedIcon, "animationend");
7980

8081
info("Reload tracking tab");
81-
securityChanged = waitForSecurityChange(3, tabbrowser.ownerGlobal);
82+
securityChanged = waitForSecurityChange(2, tabbrowser.ownerGlobal);
83+
contentBlockingEvent = waitForContentBlockingEvent(3, tabbrowser.ownerGlobal);
8284
tabbrowser.selectedTab = trackingTab;
8385
tabbrowser.reload();
84-
await securityChanged;
86+
await Promise.all([securityChanged, contentBlockingEvent]);
8587

8688
ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active");
8789
ok(ContentBlocking.iconBox.hasAttribute("animate"), "iconBox animating");

browser/base/content/test/trackingUI/browser_trackingUI_fetch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ add_task(async function test_fetch() {
66
]});
77

88
await BrowserTestUtils.withNewTab({ gBrowser, url: URL }, async function(newTabBrowser) {
9-
let securityChange = waitForSecurityChange();
9+
let contentBlockingEvent = waitForContentBlockingEvent();
1010
await ContentTask.spawn(newTabBrowser, null, async function() {
1111
await content.wrappedJSObject.test_fetch()
1212
.then(response => Assert.ok(false, "should have denied the request"))
1313
.catch(e => Assert.ok(true, `Caught exception: ${e}`));
1414
});
15-
await securityChange;
15+
await contentBlockingEvent;
1616

1717
let ContentBlocking = newTabBrowser.ownerGlobal.ContentBlocking;
1818
ok(ContentBlocking, "got CB object");

browser/base/content/test/trackingUI/browser_trackingUI_telemetry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ add_task(async function testShieldHistogram() {
5454

5555
await promiseTabLoadEvent(tab, TRACKING_PAGE);
5656
// Note that right now the shield histogram is not measuring what
57-
// you might think. Since onSecurityChange fires twice for a tracking page,
57+
// you might think. Since onContentBlockingEvent fires twice for a tracking page,
5858
// the total page loads count is double counting, and the shield count
5959
// (which is meant to measure times when the shield wasn't shown) fires even
6060
// when tracking elements exist on the page.

browser/base/content/test/trackingUI/head.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,23 @@ function waitForSecurityChange(numChanges = 1, win = null) {
5959
win.gBrowser.addProgressListener(listener);
6060
});
6161
}
62+
63+
function waitForContentBlockingEvent(numChanges = 1, win = null) {
64+
if (!win) {
65+
win = window;
66+
}
67+
return new Promise(resolve => {
68+
let n = 0;
69+
let listener = {
70+
onContentBlockingEvent() {
71+
n = n + 1;
72+
info("Received onContentBlockingEvent event " + n + " of " + numChanges);
73+
if (n >= numChanges) {
74+
win.gBrowser.removeProgressListener(listener);
75+
resolve(n);
76+
}
77+
},
78+
};
79+
win.gBrowser.addProgressListener(listener);
80+
});
81+
}

browser/components/extensions/parent/ext-tabs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,7 @@ this.tabs = class extends ExtensionAPI {
12441244
onLocationChange(webProgress, request, location, flags) { },
12451245
onProgressChange(webProgress, request, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) { },
12461246
onSecurityChange(webProgress, request, state) { },
1247+
onContentBlockingEvent(webProgress, request, event) { },
12471248
onStateChange(webProgress, request, flags, status) {
12481249
if ((flags & Ci.nsIWebProgressListener.STATE_STOP) && (flags & Ci.nsIWebProgressListener.STATE_IS_DOCUMENT)) {
12491250
resolve(retval == 0 ? "saved" : "replaced");

browser/components/shell/nsMacShellService.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ nsMacShellService::OnSecurityChange(nsIWebProgress* aWebProgress,
188188
return NS_OK;
189189
}
190190

191+
NS_IMETHODIMP
192+
nsMacShellService::OnContentBlockingEvent(nsIWebProgress* aWebProgress,
193+
nsIRequest* aRequest,
194+
uint32_t aEvent) {
195+
return NS_OK;
196+
}
197+
191198
NS_IMETHODIMP
192199
nsMacShellService::OnStateChange(nsIWebProgress* aWebProgress,
193200
nsIRequest* aRequest, uint32_t aStateFlags,

0 commit comments

Comments
 (0)