Skip to content

Commit 59e50ba

Browse files
author
Ehsan Akhgari
committed
Bug 1493563 - Part 5: Present the old state and the content blocking log to the web progress listeners; r=baku
Differential Revision: https://phabricator.services.mozilla.com/D6595
1 parent 4765aac commit 59e50ba

File tree

54 files changed

+304
-66
lines changed

Some content is hidden

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

54 files changed

+304
-66
lines changed

accessible/base/DocManager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,9 @@ DocManager::OnStatusChange(nsIWebProgress* aWebProgress,
344344
NS_IMETHODIMP
345345
DocManager::OnSecurityChange(nsIWebProgress* aWebProgress,
346346
nsIRequest* aRequest,
347-
uint32_t aState)
347+
uint32_t aOldState,
348+
uint32_t aState,
349+
const nsAString& aContentBlockingLogJSON)
348350
{
349351
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
350352
return NS_OK;

browser/base/content/browser-contentblocking.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ var ContentBlocking = {
464464
Services.telemetry.getHistogramById("TRACKING_PROTECTION_SHIELD").add(value);
465465
},
466466

467-
onSecurityChange(state, webProgress, isSimulated) {
467+
onSecurityChange(oldState, state, webProgress, isSimulated,
468+
contentBlockingLogJSON) {
468469
let baseURI = this._baseURIForChannelClassifier;
469470

470471
// Don't deal with about:, file: etc.

browser/base/content/browser.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4987,7 +4987,8 @@ var XULBrowserWindow = {
49874987
// 3. Called directly during this object's initializations.
49884988
// aRequest will be null always in case 2 and 3, and sometimes in case 1 (for
49894989
// instance, there won't be a request when STATE_BLOCKED_TRACKING_CONTENT is observed).
4990-
onSecurityChange(aWebProgress, aRequest, aState, aIsSimulated) {
4990+
onSecurityChange(aWebProgress, aRequest, aOldState, aState,
4991+
aContentBlockingLogJSON, aIsSimulated) {
49914992
// Don't need to do anything if the data we use to update the UI hasn't
49924993
// changed
49934994
let uri = gBrowser.currentURI;
@@ -5014,7 +5015,8 @@ var XULBrowserWindow = {
50145015
uri = Services.uriFixup.createExposableURI(uri);
50155016
} catch (e) {}
50165017
gIdentityHandler.updateIdentity(this._state, uri);
5017-
ContentBlocking.onSecurityChange(this._state, aWebProgress, aIsSimulated);
5018+
ContentBlocking.onSecurityChange(aOldState, this._state, aWebProgress, aIsSimulated,
5019+
aContentBlockingLogJSON);
50185020
},
50195021

50205022
// simulate all change notifications after switching tabs

browser/base/content/tabbrowser.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,13 @@ window._gBrowser = {
944944
if (securityUI) {
945945
// Include the true final argument to indicate that this event is
946946
// simulated (instead of being observed by the webProgressListener).
947+
// Note: check state first to make sure the security UI object updates its
948+
// state from the docshell correctly.
949+
let state = securityUI.state;
950+
let oldState = securityUI.oldState;
947951
this._callProgressListeners(null, "onSecurityChange",
948-
[webProgress, null, securityUI.state, true],
952+
[webProgress, null, oldState, state,
953+
securityUI.contentBlockingLogJSON, true],
949954
true, false);
950955
}
951956

@@ -1667,12 +1672,17 @@ window._gBrowser = {
16671672

16681673
// Restore the securityUI state.
16691674
let securityUI = aBrowser.securityUI;
1675+
// Make sure to call the state getter before the oldState getter to give
1676+
// the securityUI object a chance to sync its state with the docshell
16701677
let state = securityUI ? securityUI.state :
16711678
Ci.nsIWebProgressListener.STATE_IS_INSECURE;
1679+
let oldState = securityUI ? securityUI.oldState :
1680+
Ci.nsIWebProgressListener.STATE_IS_INSECURE;
16721681
// Include the true final argument to indicate that this event is
16731682
// simulated (instead of being observed by the webProgressListener).
16741683
this._callProgressListeners(aBrowser, "onSecurityChange",
1675-
[aBrowser.webProgress, null, state, true],
1684+
[aBrowser.webProgress, null, oldState, state,
1685+
securityUI.contentBlockingLogJSON, true],
16761686
true, false);
16771687

16781688
if (aShouldBeRemote) {
@@ -5062,9 +5072,10 @@ class TabProgressListener {
50625072
this.mMessage = aMessage;
50635073
}
50645074

5065-
onSecurityChange(aWebProgress, aRequest, aState) {
5075+
onSecurityChange(aWebProgress, aRequest, aOldState, aState, aContentBlockingLogJSON) {
50665076
this._callProgressListeners("onSecurityChange",
5067-
[aWebProgress, aRequest, aState]);
5077+
[aWebProgress, aRequest, aOldState, aState,
5078+
aContentBlockingLogJSON]);
50685079
}
50695080

50705081
onRefreshAttempted(aWebProgress, aURI, aDelay, aSameURI) {

browser/base/content/test/general/browser_alltabslistener.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ var gFrontProgressListener = {
2626
onStatusChange(aWebProgress, aRequest, aStatus, aMessage) {
2727
},
2828

29-
onSecurityChange(aWebProgress, aRequest, aState) {
29+
onSecurityChange(aWebProgress, aRequest, aOldState, aState,
30+
aContentBlockingLogJSON) {
3031
var state = "onSecurityChange";
3132
info("FrontProgress: " + state + " 0x" + aState.toString(16));
3233
ok(gFrontNotificationsPos < gFrontNotifications.length, "Got an expected notification for the front notifications listener");
@@ -66,7 +67,8 @@ var gAllProgressListener = {
6667
ok(aBrowser == gTestBrowser, state + " notification came from the correct browser");
6768
},
6869

69-
onSecurityChange(aBrowser, aWebProgress, aRequest, aState) {
70+
onSecurityChange(aBrowser, aWebProgress, aRequest, aOldState, aState,
71+
aContentBlockingLogJSON) {
7072
var state = "onSecurityChange";
7173
info("AllProgress: " + state + " 0x" + aState.toString(16));
7274
ok(aBrowser == gTestBrowser, state + " notification came from the correct browser");

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,8 @@ this.tabs = class extends ExtensionAPI {
12011201
let printProgressListener = {
12021202
onLocationChange(webProgress, request, location, flags) { },
12031203
onProgressChange(webProgress, request, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) { },
1204-
onSecurityChange(webProgress, request, state) { },
1204+
onSecurityChange(webProgress, request, oldState, state,
1205+
contentBlockingLogJSON) { },
12051206
onStateChange(webProgress, request, flags, status) {
12061207
if ((flags & Ci.nsIWebProgressListener.STATE_STOP) && (flags & Ci.nsIWebProgressListener.STATE_IS_DOCUMENT)) {
12071208
resolve(retval == 0 ? "saved" : "replaced");

browser/components/shell/nsMacShellService.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ nsMacShellService::OnStatusChange(nsIWebProgress* aWebProgress,
191191
NS_IMETHODIMP
192192
nsMacShellService::OnSecurityChange(nsIWebProgress* aWebProgress,
193193
nsIRequest* aRequest,
194-
uint32_t aState)
194+
uint32_t aOldState,
195+
uint32_t aState,
196+
const nsAString& aContentBlockingLogJSON)
195197
{
196198
return NS_OK;
197199
}

docshell/base/nsDocShell.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7008,7 +7008,9 @@ nsDocShell::OnStatusChange(nsIWebProgress* aWebProgress,
70087008

70097009
NS_IMETHODIMP
70107010
nsDocShell::OnSecurityChange(nsIWebProgress* aWebProgress,
7011-
nsIRequest* aRequest, uint32_t aState)
7011+
nsIRequest* aRequest, uint32_t aOldState,
7012+
uint32_t aState,
7013+
const nsAString& aContentBlockingLogJSON)
70127014
{
70137015
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
70147016
return NS_OK;

docshell/base/nsDocShellTreeOwner.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,9 @@ nsDocShellTreeOwner::OnStatusChange(nsIWebProgress* aWebProgress,
767767
NS_IMETHODIMP
768768
nsDocShellTreeOwner::OnSecurityChange(nsIWebProgress* aWebProgress,
769769
nsIRequest* aRequest,
770-
uint32_t aState)
770+
uint32_t aOldState,
771+
uint32_t aState,
772+
const nsAString& aContentBlockingLogJSON)
771773
{
772774
return NS_OK;
773775
}

dom/base/ContentBlockingLog.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
#ifndef mozilla_dom_ContentBlockingLog_h
88
#define mozilla_dom_ContentBlockingLog_h
99

10+
#include "mozilla/JSONWriter.h"
1011
#include "mozilla/Pair.h"
1112
#include "mozilla/UniquePtr.h"
1213
#include "nsClassHashtable.h"
1314
#include "nsHashKeys.h"
15+
#include "nsReadableUtils.h"
1416
#include "nsTArray.h"
1517

1618
namespace mozilla {
@@ -22,6 +24,19 @@ class ContentBlockingLog final
2224
// blocking types defined in nsIWebProgressListener.
2325
typedef nsTArray<mozilla::Pair<uint32_t, bool>> OriginLog;
2426

27+
struct StringWriteFunc : public JSONWriteFunc
28+
{
29+
nsAString& mBuffer; // The lifetime of the struct must be bound to the buffer
30+
explicit StringWriteFunc(nsAString& aBuffer)
31+
: mBuffer(aBuffer)
32+
{}
33+
34+
void Write(const char* aStr) override
35+
{
36+
mBuffer.Append(NS_ConvertUTF8toUTF16(aStr));
37+
}
38+
};
39+
2540
public:
2641
ContentBlockingLog() = default;
2742
~ContentBlockingLog() = default;
@@ -43,6 +58,37 @@ class ContentBlockingLog final
4358
}
4459
}
4560

61+
nsAutoString Stringify()
62+
{
63+
nsAutoString buffer;
64+
65+
JSONWriter w(MakeUnique<StringWriteFunc>(buffer));
66+
w.Start();
67+
68+
for (auto iter = mLog.Iter(); !iter.Done(); iter.Next()) {
69+
if (!iter.UserData()) {
70+
w.StartArrayProperty(NS_ConvertUTF16toUTF8(iter.Key()).get(), w.SingleLineStyle);
71+
w.EndArray();
72+
continue;
73+
}
74+
75+
w.StartArrayProperty(NS_ConvertUTF16toUTF8(iter.Key()).get(), w.SingleLineStyle);
76+
for (auto& item: *iter.UserData()) {
77+
w.StartArrayElement(w.SingleLineStyle);
78+
{
79+
w.IntElement(item.first());
80+
w.BoolElement(item.second());
81+
}
82+
w.EndArray();
83+
}
84+
w.EndArray();
85+
}
86+
87+
w.End();
88+
89+
return buffer;
90+
}
91+
4692
private:
4793
nsClassHashtable<nsStringHashKey, OriginLog> mLog;
4894
};

0 commit comments

Comments
 (0)