Bug 1503465 - Part 2: Add a docshell API for retrieving the top-level content blocking log r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 31 Oct 2018 21:21:36 +0000
changeset 443831 f7fda20ef298e560e6905d97e25e25ee21a043a2
parent 443830 59ad09405dadc868d78180fe2b5596a22458506b
child 443832 79a9c9f0946ee1971a5dc9c4ed075adee2a4da15
push id34972
push userebalazs@mozilla.com
push dateThu, 01 Nov 2018 09:11:48 +0000
treeherdermozilla-central@cfb6077ee31b [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 2: Add a docshell API for retrieving the top-level content blocking log r=baku Depends on D10362 Differential Revision: https://phabricator.services.mozilla.com/D10363
docshell/base/nsDocShell.cpp
docshell/base/nsIDocShell.idl
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -3922,16 +3922,37 @@ nsDocShell::GetMessageManager(ContentFra
   } else if (nsPIDOMWindowOuter* win = GetWindow()) {
     mm = win->GetMessageManager();
   }
   mm.forget(aMessageManager);
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsDocShell::GetContentBlockingLog(Promise** aPromise)
+{
+  NS_ENSURE_ARG_POINTER(aPromise);
+
+  if (!mContentViewer) {
+    *aPromise = nullptr;
+    return NS_ERROR_FAILURE;
+  }
+
+  nsIDocument* doc = mContentViewer->GetDocument();
+  ErrorResult rv;
+  RefPtr<Promise> promise = Promise::Create(doc->GetOwnerGlobal(), rv);
+  if (NS_WARN_IF(rv.Failed())) {
+    return rv.StealNSResult();
+  }
+  promise->MaybeResolve(doc->GetContentBlockingLog()->Stringify());
+  promise.forget(aPromise);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsDocShell::SetDeviceSizeIsPageSize(bool aValue)
 {
   if (mDeviceSizeIsPageSize != aValue) {
     mDeviceSizeIsPageSize = aValue;
     RefPtr<nsPresContext> presContext;
     GetPresContext(getter_AddRefs(presContext));
     if (presContext) {
       presContext->MediaFeatureValuesChanged({
--- a/docshell/base/nsIDocShell.idl
+++ b/docshell/base/nsIDocShell.idl
@@ -1257,9 +1257,20 @@ interface nsIDocShell : nsIDocShellTreeI
    */
   attribute unsigned long displayMode;
 
   /**
    * The message manager for this docshell.  This does not throw, but
    * can return null if the docshell has no message manager.
    */
   [infallible] readonly attribute ContentFrameMessageManager messageManager;
+
+  /**
+   * 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();
 };