Skip to content

Commit

Permalink
Bug 1493563 - Part 5: Present the old state and the content blocking …
Browse files Browse the repository at this point in the history
…log to the web progress listeners; r=baku

Differential Revision: https://phabricator.services.mozilla.com/D6595
  • Loading branch information
ehsan committed Sep 26, 2018
1 parent 69860e8 commit 4ced8fe
Show file tree
Hide file tree
Showing 54 changed files with 304 additions and 66 deletions.
4 changes: 3 additions & 1 deletion accessible/base/DocManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ DocManager::OnStatusChange(nsIWebProgress* aWebProgress,
NS_IMETHODIMP
DocManager::OnSecurityChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
uint32_t aState)
uint32_t aOldState,
uint32_t aState,
const nsAString& aContentBlockingLogJSON)
{
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
return NS_OK;
Expand Down
3 changes: 2 additions & 1 deletion browser/base/content/browser-contentblocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ var ContentBlocking = {
Services.telemetry.getHistogramById("TRACKING_PROTECTION_SHIELD").add(value);
},

onSecurityChange(state, webProgress, isSimulated) {
onSecurityChange(oldState, state, webProgress, isSimulated,
contentBlockingLogJSON) {
let baseURI = this._baseURIForChannelClassifier;

// Don't deal with about:, file: etc.
Expand Down
6 changes: 4 additions & 2 deletions browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4987,7 +4987,8 @@ var XULBrowserWindow = {
// 3. Called directly during this object's initializations.
// aRequest will be null always in case 2 and 3, and sometimes in case 1 (for
// instance, there won't be a request when STATE_BLOCKED_TRACKING_CONTENT is observed).
onSecurityChange(aWebProgress, aRequest, aState, aIsSimulated) {
onSecurityChange(aWebProgress, aRequest, aOldState, aState,
aContentBlockingLogJSON, aIsSimulated) {
// Don't need to do anything if the data we use to update the UI hasn't
// changed
let uri = gBrowser.currentURI;
Expand All @@ -5014,7 +5015,8 @@ var XULBrowserWindow = {
uri = Services.uriFixup.createExposableURI(uri);
} catch (e) {}
gIdentityHandler.updateIdentity(this._state, uri);
ContentBlocking.onSecurityChange(this._state, aWebProgress, aIsSimulated);
ContentBlocking.onSecurityChange(aOldState, this._state, aWebProgress, aIsSimulated,
aContentBlockingLogJSON);
},

// simulate all change notifications after switching tabs
Expand Down
19 changes: 15 additions & 4 deletions browser/base/content/tabbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,13 @@ window._gBrowser = {
if (securityUI) {
// Include the true final argument to indicate that this event is
// simulated (instead of being observed by the webProgressListener).
// Note: check state first to make sure the security UI object updates its
// state from the docshell correctly.
let state = securityUI.state;
let oldState = securityUI.oldState;
this._callProgressListeners(null, "onSecurityChange",
[webProgress, null, securityUI.state, true],
[webProgress, null, oldState, state,
securityUI.contentBlockingLogJSON, true],
true, false);
}

Expand Down Expand Up @@ -1665,12 +1670,17 @@ window._gBrowser = {

// Restore the securityUI state.
let securityUI = aBrowser.securityUI;
// Make sure to call the state getter before the oldState getter to give
// the securityUI object a chance to sync its state with the docshell
let state = securityUI ? securityUI.state :
Ci.nsIWebProgressListener.STATE_IS_INSECURE;
let oldState = securityUI ? securityUI.oldState :
Ci.nsIWebProgressListener.STATE_IS_INSECURE;
// Include the true final argument to indicate that this event is
// simulated (instead of being observed by the webProgressListener).
this._callProgressListeners(aBrowser, "onSecurityChange",
[aBrowser.webProgress, null, state, true],
[aBrowser.webProgress, null, oldState, state,
securityUI.contentBlockingLogJSON, true],
true, false);

if (aShouldBeRemote) {
Expand Down Expand Up @@ -5060,9 +5070,10 @@ class TabProgressListener {
this.mMessage = aMessage;
}

onSecurityChange(aWebProgress, aRequest, aState) {
onSecurityChange(aWebProgress, aRequest, aOldState, aState, aContentBlockingLogJSON) {
this._callProgressListeners("onSecurityChange",
[aWebProgress, aRequest, aState]);
[aWebProgress, aRequest, aOldState, aState,
aContentBlockingLogJSON]);
}

onRefreshAttempted(aWebProgress, aURI, aDelay, aSameURI) {
Expand Down
6 changes: 4 additions & 2 deletions browser/base/content/test/general/browser_alltabslistener.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ var gFrontProgressListener = {
onStatusChange(aWebProgress, aRequest, aStatus, aMessage) {
},

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

onSecurityChange(aBrowser, aWebProgress, aRequest, aState) {
onSecurityChange(aBrowser, aWebProgress, aRequest, aOldState, aState,
aContentBlockingLogJSON) {
var state = "onSecurityChange";
info("AllProgress: " + state + " 0x" + aState.toString(16));
ok(aBrowser == gTestBrowser, state + " notification came from the correct browser");
Expand Down
3 changes: 2 additions & 1 deletion browser/components/extensions/parent/ext-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,8 @@ this.tabs = class extends ExtensionAPI {
let printProgressListener = {
onLocationChange(webProgress, request, location, flags) { },
onProgressChange(webProgress, request, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) { },
onSecurityChange(webProgress, request, state) { },
onSecurityChange(webProgress, request, oldState, state,
contentBlockingLogJSON) { },
onStateChange(webProgress, request, flags, status) {
if ((flags & Ci.nsIWebProgressListener.STATE_STOP) && (flags & Ci.nsIWebProgressListener.STATE_IS_DOCUMENT)) {
resolve(retval == 0 ? "saved" : "replaced");
Expand Down
4 changes: 3 additions & 1 deletion browser/components/shell/nsMacShellService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ nsMacShellService::OnStatusChange(nsIWebProgress* aWebProgress,
NS_IMETHODIMP
nsMacShellService::OnSecurityChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
uint32_t aState)
uint32_t aOldState,
uint32_t aState,
const nsAString& aContentBlockingLogJSON)
{
return NS_OK;
}
Expand Down
4 changes: 3 additions & 1 deletion docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7008,7 +7008,9 @@ nsDocShell::OnStatusChange(nsIWebProgress* aWebProgress,

NS_IMETHODIMP
nsDocShell::OnSecurityChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest, uint32_t aState)
nsIRequest* aRequest, uint32_t aOldState,
uint32_t aState,
const nsAString& aContentBlockingLogJSON)
{
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
return NS_OK;
Expand Down
4 changes: 3 additions & 1 deletion docshell/base/nsDocShellTreeOwner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,9 @@ nsDocShellTreeOwner::OnStatusChange(nsIWebProgress* aWebProgress,
NS_IMETHODIMP
nsDocShellTreeOwner::OnSecurityChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
uint32_t aState)
uint32_t aOldState,
uint32_t aState,
const nsAString& aContentBlockingLogJSON)
{
return NS_OK;
}
Expand Down
46 changes: 46 additions & 0 deletions dom/base/ContentBlockingLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
#ifndef mozilla_dom_ContentBlockingLog_h
#define mozilla_dom_ContentBlockingLog_h

#include "mozilla/JSONWriter.h"
#include "mozilla/Pair.h"
#include "mozilla/UniquePtr.h"
#include "nsClassHashtable.h"
#include "nsHashKeys.h"
#include "nsReadableUtils.h"
#include "nsTArray.h"

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

struct StringWriteFunc : public JSONWriteFunc
{
nsAString& mBuffer; // The lifetime of the struct must be bound to the buffer
explicit StringWriteFunc(nsAString& aBuffer)
: mBuffer(aBuffer)
{}

void Write(const char* aStr) override
{
mBuffer.Append(NS_ConvertUTF8toUTF16(aStr));
}
};

public:
ContentBlockingLog() = default;
~ContentBlockingLog() = default;
Expand All @@ -43,6 +58,37 @@ class ContentBlockingLog final
}
}

nsAutoString Stringify()
{
nsAutoString buffer;

JSONWriter w(MakeUnique<StringWriteFunc>(buffer));
w.Start();

for (auto iter = mLog.Iter(); !iter.Done(); iter.Next()) {
if (!iter.UserData()) {
w.StartArrayProperty(NS_ConvertUTF16toUTF8(iter.Key()).get(), w.SingleLineStyle);
w.EndArray();
continue;
}

w.StartArrayProperty(NS_ConvertUTF16toUTF8(iter.Key()).get(), w.SingleLineStyle);
for (auto& item: *iter.UserData()) {
w.StartArrayElement(w.SingleLineStyle);
{
w.IntElement(item.first());
w.BoolElement(item.second());
}
w.EndArray();
}
w.EndArray();
}

w.End();

return buffer;
}

private:
nsClassHashtable<nsStringHashKey, OriginLog> mLog;
};
Expand Down
3 changes: 2 additions & 1 deletion dom/browser-element/BrowserElementChildPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,8 @@ BrowserElementChild.prototype = {
}
},

onSecurityChange: function(webProgress, request, state) {
onSecurityChange: function(webProgress, request, oldState, state,
contentBlockingLogJSON) {
if (webProgress != docShell) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion dom/clients/manager/ClientNavigateOpChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ class NavigateLoadListener final : public nsIWebProgressListener

NS_IMETHOD
OnSecurityChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest,
uint32_t aState) override
uint32_t aOldState, uint32_t aState,
const nsAString& aContentBlockingLogJSON) override
{
MOZ_CRASH("Unexpected notification.");
return NS_OK;
Expand Down
4 changes: 3 additions & 1 deletion dom/clients/manager/ClientOpenWindowUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ class WebProgressListener final : public nsIWebProgressListener
NS_IMETHOD
OnSecurityChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
uint32_t aState) override
uint32_t aOldState,
uint32_t aState,
const nsAString& aContentBlockingLogJSON) override
{
MOZ_ASSERT(false, "Unexpected notification.");
return NS_OK;
Expand Down
4 changes: 3 additions & 1 deletion dom/html/HTMLFormElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,9 @@ HTMLFormElement::OnStatusChange(nsIWebProgress* aWebProgress,
NS_IMETHODIMP
HTMLFormElement::OnSecurityChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
uint32_t state)
uint32_t aOldState,
uint32_t aState,
const nsAString& aContentBlockingLogJSON)
{
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
return NS_OK;
Expand Down
4 changes: 3 additions & 1 deletion dom/html/nsHTMLDNSPrefetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,9 @@ nsHTMLDNSPrefetch::nsDeferrals::OnStatusChange(nsIWebProgress* aWebProgress,
NS_IMETHODIMP
nsHTMLDNSPrefetch::nsDeferrals::OnSecurityChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
uint32_t state)
uint32_t aOldState,
uint32_t aState,
const nsAString& aContentBlockingLogJSON)
{
return NS_OK;
}
Expand Down
17 changes: 17 additions & 0 deletions dom/ipc/TabParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,15 @@ TabParent::Init(mozIDOMWindowProxy *window)
return NS_OK;
}

NS_IMETHODIMP
TabParent::GetOldState(uint32_t *aOldState)
{
NS_ENSURE_ARG(aOldState);
NS_WARNING("SecurityState not valid here");
*aOldState = 0;
return NS_OK;
}

NS_IMETHODIMP
TabParent::GetState(uint32_t *aState)
{
Expand All @@ -893,6 +902,14 @@ TabParent::GetState(uint32_t *aState)
return NS_OK;
}

NS_IMETHODIMP
TabParent::GetContentBlockingLogJSON(nsAString& aContentBlockingLogJSON)
{
NS_WARNING("ContentBlockingLog not valid here");
aContentBlockingLogJSON.SetIsVoid(true);
return NS_OK;
}

NS_IMETHODIMP
TabParent::GetSecInfo(nsITransportSecurityInfo** _result)
{
Expand Down
4 changes: 3 additions & 1 deletion dom/presentation/PresentationCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ PresentationResponderLoadingCallback::OnStatusChange(nsIWebProgress* aWebProgres
NS_IMETHODIMP
PresentationResponderLoadingCallback::OnSecurityChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
uint32_t state)
uint32_t aOldState,
uint32_t aState,
const nsAString& aContentBlockingLogJSON)
{
// Do nothing.
return NS_OK;
Expand Down
5 changes: 4 additions & 1 deletion editor/composer/nsEditingSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,10 @@ nsEditingSession::OnStatusChange(nsIWebProgress *aWebProgress,
----------------------------------------------------------------------------*/
NS_IMETHODIMP
nsEditingSession::OnSecurityChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest, uint32_t state)
nsIRequest *aRequest,
uint32_t aOldState,
uint32_t aState,
const nsAString& aContentBlockingLogJSON)
{
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
return NS_OK;
Expand Down
3 changes: 2 additions & 1 deletion editor/composer/test/test_bug434998.xul
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=434998
{
},

onSecurityChange : function(aWebProgress, aRequest, aState)
onSecurityChange : function(aWebProgress, aRequest, aOldState, aState,
aContentBlockingLogJSON)
{
},

Expand Down
3 changes: 2 additions & 1 deletion editor/libeditor/tests/test_bug607584.xul
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=607584
{
},

onSecurityChange : function(aWebProgress, aRequest, aState)
onSecurityChange : function(aWebProgress, aRequest, aOldState, aState,
aContentBlockingLogJSON)
{
},

Expand Down
3 changes: 2 additions & 1 deletion editor/libeditor/tests/test_bug616590.xul
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=616590
{
},

onSecurityChange : function(aWebProgress, aRequest, aState)
onSecurityChange : function(aWebProgress, aRequest, aOldState, aState,
aContentBlockingLogJSON)
{
},

Expand Down
3 changes: 2 additions & 1 deletion editor/libeditor/tests/test_bug780908.xul
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ adapted from test_bug607584.xul by Kent James <[email protected]>
{
},

onSecurityChange : function(aWebProgress, aRequest, aState)
onSecurityChange : function(aWebProgress, aRequest, aOldState, aState,
aContentBlockingLogJSON)
{
},

Expand Down
3 changes: 2 additions & 1 deletion layout/base/tests/chrome/printpreview_bug396024_helper.xul
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ function printpreview() {
onProgressChange: function(webProgress, request, curSelfProgress,
maxSelfProgress, curTotalProgress,
maxTotalProgress) { },
onSecurityChange: function(webProgress, request, state) { },
onSecurityChange: function(webProgress, request, oldState, state,
contentBlockingLogJSON) { },
onStateChange: function(webProgress, request, stateFlags, status) { },
onStatusChange: function(webProgress, request, status, message) { },
QueryInterface: function(iid) {
Expand Down
3 changes: 2 additions & 1 deletion layout/base/tests/chrome/printpreview_bug482976_helper.xul
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ function printpreview() {
onProgressChange: function(webProgress, request, curSelfProgress,
maxSelfProgress, curTotalProgress,
maxTotalProgress) { },
onSecurityChange: function(webProgress, request, state) { },
onSecurityChange: function(webProgress, request, oldState, state,
contentBlockingLogJSON) { },
onStateChange: function(webProgress, request, stateFlags, status) { },
onStatusChange: function(webProgress, request, status, message) { },
QueryInterface: function(iid) {
Expand Down
3 changes: 2 additions & 1 deletion layout/base/tests/chrome/printpreview_helper.xul
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function printpreview() {
onProgressChange: function(webProgress, request, curSelfProgress,
maxSelfProgress, curTotalProgress,
maxTotalProgress) { },
onSecurityChange: function(webProgress, request, state) { },
onSecurityChange: function(webProgress, request, oldState, state,
contentBlockingLogJSON) { },
onStateChange: function(webProgress, request, stateFlags, status) { },
onStatusChange: function(webProgress, request, status, message) { },
QueryInterface: function(iid) {
Expand Down
Loading

0 comments on commit 4ced8fe

Please sign in to comment.