Bug 1426253 P4 Assert that ClientSource::SetController() is never called on a client in private browsing mode. r=asuth
authorBen Kelly <ben@wanderview.com>
Wed, 20 Dec 2017 10:53:19 -0500
changeset 448774 661c1ca56b09907f19299040eb7baa6209728997
parent 448773 83c725dad7a9cefe2a9bc82b1886141ad536ca36
child 448775 3ac6f5c8acccd6bae735a4a1edbda18355fc36c9
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1426253
milestone59.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 1426253 P4 Assert that ClientSource::SetController() is never called on a client in private browsing mode. r=asuth
dom/clients/manager/ClientInfo.cpp
dom/clients/manager/ClientInfo.h
dom/clients/manager/ClientSource.cpp
--- a/dom/clients/manager/ClientInfo.cpp
+++ b/dom/clients/manager/ClientInfo.cpp
@@ -6,16 +6,18 @@
 
 #include "ClientInfo.h"
 
 #include "mozilla/dom/ClientIPCTypes.h"
 
 namespace mozilla {
 namespace dom {
 
+using mozilla::ipc::PrincipalInfo;
+
 ClientInfo::ClientInfo(const nsID& aId,
                        ClientType aType,
                        const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
                        const TimeStamp& aCreationTime)
   : mData(MakeUnique<IPCClientInfo>(aId, aType, aPrincipalInfo, aCreationTime,
                                     EmptyCString(),
                                     mozilla::dom::FrameType::None))
 {
@@ -105,10 +107,36 @@ ClientInfo::SetFrameType(mozilla::dom::F
 }
 
 const IPCClientInfo&
 ClientInfo::ToIPC() const
 {
   return *mData;
 }
 
+bool
+ClientInfo::IsPrivateBrowsing() const
+{
+  switch(PrincipalInfo().type()) {
+    case PrincipalInfo::TContentPrincipalInfo:
+    {
+      auto& p = PrincipalInfo().get_ContentPrincipalInfo();
+      return p.attrs().mPrivateBrowsingId != 0;
+    }
+    case PrincipalInfo::TSystemPrincipalInfo:
+    {
+      return false;
+    }
+    case PrincipalInfo::TNullPrincipalInfo:
+    {
+      auto& p = PrincipalInfo().get_NullPrincipalInfo();
+      return p.attrs().mPrivateBrowsingId != 0;
+    }
+    default:
+    {
+      // clients should never be expanded principals
+      MOZ_CRASH("unexpected principal type!");
+    }
+  }
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/clients/manager/ClientInfo.h
+++ b/dom/clients/manager/ClientInfo.h
@@ -86,14 +86,18 @@ public:
   // Set the frame type for the global.  This should only happen once the
   // global has become execution ready.
   void
   SetFrameType(mozilla::dom::FrameType aFrameType);
 
   // Convert to the ipdl generated type.
   const IPCClientInfo&
   ToIPC() const;
+
+  // Determine if the client is in private browsing mode.
+  bool
+  IsPrivateBrowsing() const;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // _mozilla_dom_ClientInfo_h
--- a/dom/clients/manager/ClientSource.cpp
+++ b/dom/clients/manager/ClientSource.cpp
@@ -350,16 +350,21 @@ ClientSource::WorkerSyncPing(WorkerPriva
   GetActor()->SendWorkerSyncPing();
 }
 
 void
 ClientSource::SetController(const ServiceWorkerDescriptor& aServiceWorker)
 {
   NS_ASSERT_OWNINGTHREAD(ClientSource);
 
+  // A client in private browsing mode should never be controlled by
+  // a service worker.  The principal origin attributes should guarantee
+  // this invariant.
+  MOZ_DIAGNOSTIC_ASSERT(!mClientInfo.IsPrivateBrowsing());
+
   if (mController.isSome() && mController.ref() == aServiceWorker) {
     return;
   }
 
   mController.reset();
   mController.emplace(aServiceWorker);
 
   RefPtr<ServiceWorkerContainer> swc;