Bug 1503465 - Part 1: Add a tabparent API for retrieving the top-level content blocking log r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 31 Oct 2018 21:21:34 +0000
changeset 443846 59ad09405dadc868d78180fe2b5596a22458506b
parent 443845 678417cd76f48563d6233800e6973a2a7f4d6f9b
child 443847 f7fda20ef298e560e6905d97e25e25ee21a043a2
push id72113
push usereakhgari@mozilla.com
push dateWed, 31 Oct 2018 22:27:57 +0000
treeherderautoland@79a9c9f0946e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1503465
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1503465 - Part 1: Add a tabparent API for retrieving the top-level content blocking log r=baku Differential Revision: https://phabricator.services.mozilla.com/D10362
dom/interfaces/base/nsITabParent.idl
dom/ipc/PBrowser.ipdl
dom/ipc/TabChild.cpp
dom/ipc/TabChild.h
dom/ipc/TabParent.cpp
--- a/dom/interfaces/base/nsITabParent.idl
+++ b/dom/interfaces/base/nsITabParent.idl
@@ -120,9 +120,20 @@ interface nsITabParent : nsISupports
    */
   void stopApzAutoscroll(in nsViewID aScrollId, in uint32_t aPresShellId);
 
   /**
    * Save a recording of the associated content process' behavior to the
    * specified filename. Returns whether the process is being recorded.
    */
   bool saveRecording(in AString aFileName);
+
+  /**
+   * Asynchronously retrieve a JSON string representing a log of the
+   * content blocking events happened so far in the current tab from the
+   * content process.
+   *
+   * This returns a Promise which resolves to a string on success, and is
+   * rejected on failure.  For documentation on the string format, please
+   * see nsISecureBrowserUI.contentBlockingLogJSON.
+   */
+  Promise getContentBlockingLog();
 };
--- a/dom/ipc/PBrowser.ipdl
+++ b/dom/ipc/PBrowser.ipdl
@@ -885,16 +885,21 @@ child:
     async SetOriginAttributes(OriginAttributes aOriginAttributes);
 
     /**
      * Pass the current handle for the current native widget to the content
      * process, so it can be used by PuppetWidget.
      */
     async SetWidgetNativeData(WindowsHandle aHandle);
 
+    /**
+     * Requests the content blocking log, which is sent back in response.
+     */
+    async GetContentBlockingLog() returns(nsString log, bool success);
+
 /*
  * FIXME: write protocol!
 
 state LIVE:
     send LoadURL goto LIVE;
 //etc.
     send Destroy goto DYING;
 
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -3402,16 +3402,31 @@ TabChild::RecvSetOriginAttributes(const 
 
 mozilla::ipc::IPCResult
 TabChild::RecvSetWidgetNativeData(const WindowsHandle& aWidgetNativeData)
 {
   mWidgetNativeData = aWidgetNativeData;
   return IPC_OK();
 }
 
+mozilla::ipc::IPCResult
+TabChild::RecvGetContentBlockingLog(GetContentBlockingLogResolver&& aResolve)
+{
+  bool success = false;
+  nsAutoString result;
+
+  if (nsCOMPtr<nsIDocument> doc = GetDocument()) {
+    result = doc->GetContentBlockingLog()->Stringify();
+    success = true;
+  }
+
+  aResolve(Tuple<const nsString&, const bool&>(result, success));
+  return IPC_OK();
+}
+
 mozilla::plugins::PPluginWidgetChild*
 TabChild::AllocPPluginWidgetChild()
 {
 #ifdef XP_WIN
   return new mozilla::plugins::PluginWidgetChild();
 #else
   MOZ_ASSERT_UNREACHABLE("AllocPPluginWidgetChild only supports Windows");
   return nullptr;
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -747,16 +747,18 @@ protected:
   virtual mozilla::ipc::IPCResult RecvSetWindowName(const nsString& aName) override;
 
   virtual mozilla::ipc::IPCResult RecvAllowScriptsToClose() override;
 
   virtual mozilla::ipc::IPCResult RecvSetOriginAttributes(const OriginAttributes& aOriginAttributes) override;
 
   virtual mozilla::ipc::IPCResult RecvSetWidgetNativeData(const WindowsHandle& aWidgetNativeData) override;
 
+  virtual mozilla::ipc::IPCResult RecvGetContentBlockingLog(GetContentBlockingLogResolver&& aResolve) override;
+
 private:
   void HandleDoubleTap(const CSSPoint& aPoint, const Modifiers& aModifiers,
                        const ScrollableLayerGuid& aGuid);
 
   // Notify others that our TabContext has been updated.
   //
   // You should call this after calling TabContext::SetTabContext().  We also
   // call this during Init().
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -2984,16 +2984,52 @@ TabParent::SaveRecording(const nsAString
   nsresult rv = NS_NewLocalFile(aFilename, false, getter_AddRefs(file));
   if (NS_FAILED(rv)) {
     return rv;
   }
   return Manager()->AsContentParent()->SaveRecording(file, aRetval);
 }
 
 NS_IMETHODIMP
+TabParent::GetContentBlockingLog(Promise** aPromise)
+{
+  NS_ENSURE_ARG_POINTER(aPromise);
+
+  *aPromise = nullptr;
+  if (!mFrameElement) {
+    return NS_ERROR_FAILURE;
+  }
+
+  ErrorResult rv;
+  RefPtr<Promise> jsPromise =
+    Promise::Create(mFrameElement->OwnerDoc()->GetOwnerGlobal(), rv);
+  if (rv.Failed()) {
+    return NS_ERROR_FAILURE;
+  }
+
+  RefPtr<Promise> copy(jsPromise);
+  copy.forget(aPromise);
+
+  auto cblPromise = SendGetContentBlockingLog();
+  cblPromise->Then(GetMainThreadSerialEventTarget(), __func__,
+                   [jsPromise] (Tuple<nsString, bool> aResult) {
+                     if (Get<1>(aResult)) {
+                       jsPromise->MaybeResolve(Get<0>(aResult));
+                     } else {
+                       jsPromise->MaybeRejectWithUndefined();
+                     }
+                   },
+                   [jsPromise] (ResponseRejectReason aReason) {
+                     jsPromise->MaybeRejectWithUndefined();
+                   });
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 TabParent::SuppressDisplayport(bool aEnabled)
 {
   if (IsDestroyed()) {
     return NS_OK;
   }
 
 #ifdef DEBUG
   if (aEnabled) {