Skip to content

Instantly share code, notes, and snippets.

@ehsan
Created January 17, 2019 18:55
Show Gist options
  • Save ehsan/9fe69631657d67aacc277ff449ef9d93 to your computer and use it in GitHub Desktop.
Save ehsan/9fe69631657d67aacc277ff449ef9d93 to your computer and use it in GitHub Desktop.
commit 6ede048523fe1ea3db963d04d5daec5df8d6f32b (HEAD -> baku)
Author: Ehsan Akhgari <ehsan@mozilla.com>
Date: Wed Jan 16 19:03:20 2019 -0500
x
diff --git a/devtools/client/responsive.html/browser/tunnel.js b/devtools/client/responsive.html/browser/tunnel.js
index bafd353c2ec14..c71345a7a3514 100644
--- a/devtools/client/responsive.html/browser/tunnel.js
+++ b/devtools/client/responsive.html/browser/tunnel.js
@@ -422,7 +422,6 @@ MessageManagerTunnel.prototype = {
"Content:SecurityChange",
"Content:StateChange",
"Content:StatusChange",
- "Content:ContentBlockingEvent",
// Messages sent to browser.js
"DOMTitleChanged",
"ImageDocumentLoaded",
diff --git a/dom/ipc/PBrowser.ipdl b/dom/ipc/PBrowser.ipdl
index d8bc58063da82..d914fe13c1a35 100644
--- a/dom/ipc/PBrowser.ipdl
+++ b/dom/ipc/PBrowser.ipdl
@@ -104,6 +104,21 @@ struct ShowInfo
double defaultScale;
};
+struct WebProgressData
+{
+ bool isTopLevel;
+ bool isLoadingDocument;
+ uint32_t loadType;
+ uint64_t DOMWindowID;
+};
+
+struct RequestData
+{
+ nsIURI requestURI;
+ nsIURI originalRequestURI;
+ nsCString matchedList;
+};
+
union OptionalShmem
{
void_t;
@@ -524,6 +539,9 @@ parent:
async RegisterProtocolHandler(nsString scheme, nsIURI handlerURI, nsString title,
nsIURI documentURI);
+ async OnContentBlockingEvent(WebProgressData webProgressData,
+ RequestData requestData, uint32_t aEvent);
+
child:
async NativeSynthesisResponse(uint64_t aObserverId, nsCString aResponse);
diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp
index 4064be7abc286..1a9bcdc001c70 100644
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -28,6 +28,7 @@
#include "mozilla/dom/MouseEventBinding.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/PaymentRequestChild.h"
+#include "mozilla/dom/PBrowser.h"
#include "mozilla/dom/WindowProxyHolder.h"
#include "mozilla/gfx/CrossProcessPaint.h"
#include "mozilla/IMEStateManager.h"
@@ -69,6 +70,7 @@
#include "nsGlobalWindow.h"
#include "nsIBaseWindow.h"
#include "nsIBrowserDOMWindow.h"
+#include "nsIClassifiedChannel.h"
#include "DocumentInlines.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIDOMChromeWindow.h"
@@ -534,6 +536,11 @@ nsresult TabChild::Init(mozIDOMWindowProxy* aParent) {
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(WebNavigation());
MOZ_ASSERT(docShell);
+ nsCOMPtr<nsIWebProgress> webProgress = do_QueryInterface(docShell);
+ webProgress->AddProgressListener(this,
+ nsIWebProgress::NOTIFY_CONTENT_BLOCKING);
+ mProgressListenerRegistered = true;
+
docShell->SetAffectPrivateSessionLifetime(
mChromeFlags & nsIWebBrowserChrome::CHROME_PRIVATE_LIFETIME);
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(WebNavigation());
@@ -949,6 +956,14 @@ void TabChild::DestroyWindow() {
}
mLayersId = layers::LayersId{0};
}
+
+ if (mProgressListenerRegistered) {
+ nsCOMPtr<nsIWebProgress> webProgress = do_QueryInterface(WebNavigation());
+ if (webProgress) {
+ webProgress->RemoveProgressListener(this);
+ mProgressListenerRegistered = false;
+ }
+ }
}
void TabChild::ActorDestroy(ActorDestroyReason why) {
@@ -3220,6 +3235,101 @@ nsresult TabChild::SetHasSiblings(bool aHasSiblings) {
return NS_OK;
}
+NS_IMETHODIMP TabChild::OnStateChange(nsIWebProgress* aWebProgress,
+ nsIRequest* aRequest,
+ uint32_t aStateFlags, nsresult aStatus) {
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP TabChild::OnProgressChange(nsIWebProgress* aWebProgress,
+ nsIRequest* aRequest,
+ int32_t aCurSelfProgress,
+ int32_t aMaxSelfProgress,
+ int32_t aCurTotalProgress,
+ int32_t aMaxTotalProgress) {
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP TabChild::OnLocationChange(nsIWebProgress* aWebProgress,
+ nsIRequest* aRequest,
+ nsIURI* aLocation, uint32_t aFlags) {
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP TabChild::OnStatusChange(nsIWebProgress* aWebProgress,
+ nsIRequest* aRequest, nsresult aStatus,
+ const char16_t* aMessage) {
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+NS_IMETHODIMP TabChild::OnSecurityChange(nsIWebProgress* aWebProgress,
+ nsIRequest* aRequest,
+ uint32_t aState) {
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+NS_IMETHODIMP TabChild::OnContentBlockingEvent(nsIWebProgress* aWebProgress,
+ nsIRequest* aRequest,
+ uint32_t aEvent) {
+ NS_ENSURE_ARG_POINTER(aWebProgress);
+ NS_ENSURE_ARG_POINTER(aRequest);
+
+ WebProgressData webProgressData;
+ RequestData requestData;
+ nsresult rv = PrepareProgressListenerData(aWebProgress, aRequest,
+ webProgressData, requestData);
+ NS_ENSURE_SUCCESS(rv, rv);
+ SendOnContentBlockingEvent(webProgressData, requestData, aEvent);
+
+ return NS_OK;
+}
+
+nsresult TabChild::PrepareProgressListenerData(
+ nsIWebProgress* aWebProgress, nsIRequest* aRequest,
+ WebProgressData& aWebProgressData, RequestData& aRequestData) {
+ bool isTopLevel = false;
+ nsresult rv = aWebProgress->GetIsTopLevel(&isTopLevel);
+ NS_ENSURE_SUCCESS(rv, rv);
+ aWebProgressData.isTopLevel() = isTopLevel;
+
+ bool isLoadingDocument = false;
+ rv = aWebProgress->GetIsLoadingDocument(&isLoadingDocument);
+ NS_ENSURE_SUCCESS(rv, rv);
+ aWebProgressData.isLoadingDocument() = isLoadingDocument;
+
+ uint32_t loadType = 0;
+ rv = aWebProgress->GetLoadType(&loadType);
+ NS_ENSURE_SUCCESS(rv, rv);
+ aWebProgressData.loadType() = loadType;
+
+ uint64_t DOMWindowID = 0;
+ // The DOM Window ID getter here may throw if the inner or outer windows
+ // aren't created yet or are destroyed at the time we're making this call but
+ // that isn't fatal so ignore the exceptions here.
+ Unused << aWebProgress->GetDOMWindowID(&DOMWindowID);
+ aWebProgressData.DOMWindowID() = DOMWindowID;
+
+ nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
+ if (channel) {
+ nsCOMPtr<nsIURI> uri;
+ rv = channel->GetURI(getter_AddRefs(uri));
+ NS_ENSURE_SUCCESS(rv, rv);
+ aRequestData.requestURI() = uri;
+
+ rv = channel->GetOriginalURI(getter_AddRefs(uri));
+ NS_ENSURE_SUCCESS(rv, rv);
+ aRequestData.originalRequestURI() = uri;
+
+ nsCOMPtr<nsIClassifiedChannel> classifiedChannel =
+ do_QueryInterface(channel);
+ if (classifiedChannel) {
+ nsAutoCString matchedList;
+ rv = classifiedChannel->GetMatchedList(matchedList);
+ NS_ENSURE_SUCCESS(rv, rv);
+ aRequestData.matchedList() = std::move(matchedList);
+ }
+ }
+ return NS_OK;
+}
+
TabChildMessageManager::TabChildMessageManager(TabChild* aTabChild)
: ContentFrameMessageManager(new nsFrameMessageManager(aTabChild)),
mTabChild(aTabChild) {}
diff --git a/dom/ipc/TabChild.h b/dom/ipc/TabChild.h
index 762e2243bac26..d5ce641e79437 100644
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -26,6 +26,7 @@
#include "nsWeakReference.h"
#include "nsITabChild.h"
#include "nsITooltipListener.h"
+#include "nsIWebProgressListener.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/TabContext.h"
#include "mozilla/dom/CoalescedMouseData.h"
@@ -46,7 +47,9 @@
class nsIDOMWindowUtils;
class nsIHttpChannel;
+class nsIRequest;
class nsISerialEventTarget;
+class nsIWebProgress;
class nsWebBrowser;
template <typename T>
@@ -77,6 +80,8 @@ class TabGroup;
class ClonedMessageData;
class CoalescedMouseData;
class CoalescedWheelData;
+class RequestData;
+class WebProgressData;
class TabChildMessageManager : public ContentFrameMessageManager,
public nsIMessageSender,
@@ -198,6 +203,7 @@ class TabChild final : public TabChildBase,
public nsSupportsWeakReference,
public nsITabChild,
public nsIObserver,
+ public nsIWebProgressListener,
public TabContext,
public nsITooltipListener,
public mozilla::ipc::IShmemAllocator {
@@ -252,6 +258,7 @@ class TabChild final : public TabChildBase,
NS_DECL_NSIWINDOWPROVIDER
NS_DECL_NSITABCHILD
NS_DECL_NSIOBSERVER
+ NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSITOOLTIPLISTENER
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(TabChild, TabChildBase)
@@ -776,6 +783,11 @@ class TabChild final : public TabChildBase,
bool CreateRemoteLayerManager(
mozilla::layers::PCompositorBridgeChild* aCompositorChild);
+ nsresult PrepareProgressListenerData(nsIWebProgress* aWebProgress,
+ nsIRequest* aRequest,
+ WebProgressData& aWebProgressData,
+ RequestData& aRequestData);
+
class DelayedDeleteRunnable;
TextureFactoryIdentifier mTextureFactoryIdentifier;
@@ -801,6 +813,7 @@ class TabChild final : public TabChildBase,
SetAllowedTouchBehaviorCallback mSetAllowedTouchBehaviorCallback;
bool mHasValidInnerSize;
bool mDestroyed;
+ bool mProgressListenerRegistered;
// Position of client area relative to the outer window
LayoutDeviceIntPoint mClientOffset;
// Position of tab, relative to parent widget (typically the window)
diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp
index 97b28c3d78edd..209ac71fd9750 100644
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -2113,6 +2113,12 @@ mozilla::ipc::IPCResult TabParent::RecvRegisterProtocolHandler(
return IPC_OK();
}
+mozilla::ipc::IPCResult TabParent::RecvOnContentBlockingEvent(
+ const WebProgressData& webProgressData, const RequestData& requestData,
+ const uint32_t& aEvent) {
+ return IPC_OK();
+}
+
bool TabParent::HandleQueryContentEvent(WidgetQueryContentEvent& aEvent) {
nsCOMPtr<nsIWidget> widget = GetWidget();
if (!widget) {
diff --git a/dom/ipc/TabParent.h b/dom/ipc/TabParent.h
index cadcdd0434da0..90b8ddfd68bd4 100644
--- a/dom/ipc/TabParent.h
+++ b/dom/ipc/TabParent.h
@@ -160,6 +160,10 @@ class TabParent final : public PBrowserParent,
const nsString& aScheme, nsIURI* aHandlerURI, const nsString& aTitle,
nsIURI* aDocURI) override;
+ virtual mozilla::ipc::IPCResult RecvOnContentBlockingEvent(
+ const WebProgressData& webProgressData, const RequestData& requestData,
+ const uint32_t& aEvent) override;
+
virtual mozilla::ipc::IPCResult RecvBrowserFrameOpenWindow(
PBrowserParent* aOpener, const nsString& aURL, const nsString& aName,
const nsString& aFeatures,
diff --git a/toolkit/modules/RemoteWebProgress.jsm b/toolkit/modules/RemoteWebProgress.jsm
index 5bbf9f70b97c4..46f774203a635 100644
--- a/toolkit/modules/RemoteWebProgress.jsm
+++ b/toolkit/modules/RemoteWebProgress.jsm
@@ -81,7 +81,6 @@ RemoteWebProgressManager.prototype = {
this._messageManager.removeMessageListener("Content:StatusChange", this);
this._messageManager.removeMessageListener("Content:ProgressChange", this);
this._messageManager.removeMessageListener("Content:LoadURIResult", this);
- this._messageManager.removeMessageListener("Content:ContentBlockingEvent", this);
}
this._browser = aBrowser;
@@ -92,7 +91,6 @@ RemoteWebProgressManager.prototype = {
this._messageManager.addMessageListener("Content:StatusChange", this);
this._messageManager.addMessageListener("Content:ProgressChange", this);
this._messageManager.addMessageListener("Content:LoadURIResult", this);
- this._messageManager.addMessageListener("Content:ContentBlockingEvent", this);
},
swapListeners(aOtherRemoteWebProgressManager) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment