Bug 1508310 - Implement Report-to header support - part 8 - ChromeUtils methods for testing, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Sat, 01 Dec 2018 21:26:10 +0100
changeset 505582 33bb5a1368e824f30e04a7793e86bf63613ba37b
parent 505581 696af9c24623fb963ebc25b5e21ca9caf5055077
child 505583 c0e1002895a6f975ea6ac879b841b25123fd3522
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1508310
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 1508310 - Implement Report-to header support - part 8 - ChromeUtils methods for testing, r=smaug
dom/base/ChromeUtils.cpp
dom/base/ChromeUtils.h
dom/chrome-webidl/ChromeUtils.webidl
dom/reporting/ReportingHeader.cpp
dom/reporting/ReportingHeader.h
--- a/dom/base/ChromeUtils.cpp
+++ b/dom/base/ChromeUtils.cpp
@@ -14,16 +14,17 @@
 #include "mozilla/Base64.h"
 #include "mozilla/BasePrincipal.h"
 #include "mozilla/CycleCollectedJSRuntime.h"
 #include "mozilla/PerformanceMetricsCollector.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/dom/BrowsingContext.h"
 #include "mozilla/dom/IdleDeadline.h"
+#include "mozilla/dom/ReportingHeader.h"
 #include "mozilla/dom/UnionTypes.h"
 #include "mozilla/dom/WindowBinding.h"  // For IdleRequestCallback/Options
 #include "IOActivityMonitor.h"
 #include "nsThreadUtils.h"
 #include "mozJSComponentLoader.h"
 #include "GeckoProfiler.h"
 
 namespace mozilla {
@@ -721,10 +722,21 @@ constexpr auto kSkipSelfHosted = JS::Sav
 }
 
 /* static */ void ChromeUtils::GetRootBrowsingContexts(
     GlobalObject& aGlobal,
     nsTArray<RefPtr<BrowsingContext>>& aBrowsingContexts) {
   BrowsingContext::GetRootBrowsingContexts(aBrowsingContexts);
 }
 
+/* static */ bool ChromeUtils::HasReportingHeaderForOrigin(
+    GlobalObject& global, const nsAString& aOrigin, ErrorResult& aRv) {
+  if (!XRE_IsParentProcess()) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return false;
+  }
+
+  return ReportingHeader::HasReportingHeaderForOrigin(
+      NS_ConvertUTF16toUTF8(aOrigin));
+}
+
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/base/ChromeUtils.h
+++ b/dom/base/ChromeUtils.h
@@ -160,14 +160,18 @@ class ChromeUtils {
                                                      ErrorResult& aRv);
 
   static already_AddRefed<BrowsingContext> GetBrowsingContext(
       GlobalObject& aGlobal, uint64_t id);
 
   static void GetRootBrowsingContexts(
       GlobalObject& aGlobal,
       nsTArray<RefPtr<BrowsingContext>>& aBrowsingContexts);
+
+  static bool HasReportingHeaderForOrigin(GlobalObject& global,
+                                          const nsAString& aOrigin,
+                                          ErrorResult& aRv);
 };
 
 }  // namespace dom
 }  // namespace mozilla
 
 #endif  // mozilla_dom_ChromeUtils__
--- a/dom/chrome-webidl/ChromeUtils.webidl
+++ b/dom/chrome-webidl/ChromeUtils.webidl
@@ -359,16 +359,19 @@ partial namespace ChromeUtils {
   [ChromeOnly]
   BrowsingContext? getBrowsingContext(unsigned long long id);
 
   /**
    * Returns all the root BrowsingContexts.
    */
   [ChromeOnly]
   sequence<BrowsingContext> getRootBrowsingContexts();
+
+  [ChromeOnly, Throws]
+  boolean hasReportingHeaderForOrigin(DOMString aOrigin);
 };
 
 /**
  * Dictionaries duplicating IPDL types in dom/ipc/DOMTypes.ipdlh
  * Used by requestPerformanceMetrics
  */
 
 dictionary MediaMemoryInfoDictionary {
--- a/dom/reporting/ReportingHeader.cpp
+++ b/dom/reporting/ReportingHeader.cpp
@@ -648,16 +648,25 @@ void ReportingHeader::RemoveOriginsFromO
     if (aPattern.Matches(attr)) {
       iter.Remove();
     }
   }
 }
 
 void ReportingHeader::RemoveOrigins() { mOrigins.Clear(); }
 
+/* static */ bool ReportingHeader::HasReportingHeaderForOrigin(
+    const nsACString& aOrigin) {
+  if (!gReporting) {
+    return false;
+  }
+
+  return gReporting->mOrigins.Contains(aOrigin);
+}
+
 NS_INTERFACE_MAP_BEGIN(ReportingHeader)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
   NS_INTERFACE_MAP_ENTRY(nsIObserver)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_ADDREF(ReportingHeader)
 NS_IMPL_RELEASE(ReportingHeader)
 
--- a/dom/reporting/ReportingHeader.h
+++ b/dom/reporting/ReportingHeader.h
@@ -60,16 +60,20 @@ class ReportingHeader final : public nsI
       const nsAString& aGroupName,
       const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
       nsACString& aEndpointURI);
 
   static void RemoveEndpoint(const nsAString& aGroupName,
                              const nsACString& aEndpointURL,
                              const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
 
+  // ChromeOnly-WebIDL methods
+
+  static bool HasReportingHeaderForOrigin(const nsACString& aOrigin);
+
  private:
   ReportingHeader();
   ~ReportingHeader();
 
   static void Shutdown();
 
   // Checks if a channel contains a Report-To header and parses its value.
   void ReportingFromChannel(nsIHttpChannel* aChannel);