diff --git a/caps/BasePrincipal.cpp b/caps/BasePrincipal.cpp index 6db7c3120a..1f8907c932 100644 --- a/caps/BasePrincipal.cpp +++ b/caps/BasePrincipal.cpp @@ -28,74 +28,26 @@ namespace mozilla { using dom::URLParams; -void -PrincipalOriginAttributes::InheritFromDocShellToDoc(const DocShellOriginAttributes& aAttrs, - const nsIURI* aURI) +void OriginAttributes::InheritFromDocShellParent(const OriginAttributes& aParent) { - mAppId = aAttrs.mAppId; - mInBrowser = aAttrs.mInBrowser; - - // addonId is computed from the principal URI and never propagated - mUserContextId = aAttrs.mUserContextId; - - // TODO: - // Bug 1225349 - PrincipalOriginAttributes should inherit mSignedPkg - // accordingly by URI - mSignedPkg = aAttrs.mSignedPkg; + mAppId = aParent.mAppId; + mInBrowser = aParent.mInBrowser; + mUserContextId = aParent.mUserContextId; + mSignedPkg = aParent.mSignedPkg; } -void -PrincipalOriginAttributes::InheritFromNecko(const NeckoOriginAttributes& aAttrs) +bool OriginAttributes::CopyFromLoadContext(nsILoadContext* aLoadContext) { - mAppId = aAttrs.mAppId; - mInBrowser = aAttrs.mInBrowser; + OriginAttributes attrs; + bool result = aLoadContext->GetOriginAttributes(attrs); + NS_ENSURE_TRUE(result, false); - // addonId is computed from the principal URI and never propagated - mUserContextId = aAttrs.mUserContextId; - mSignedPkg = aAttrs.mSignedPkg; -} - -void -DocShellOriginAttributes::InheritFromDocToChildDocShell(const PrincipalOriginAttributes& aAttrs) -{ - mAppId = aAttrs.mAppId; - mInBrowser = aAttrs.mInBrowser; - - // addonId is computed from the principal URI and never propagated - mUserContextId = aAttrs.mUserContextId; - - // TODO: - // Bug 1225353 - DocShell/NeckoOriginAttributes should inherit - // mSignedPkg accordingly by mSignedPkgInBrowser - mSignedPkg = aAttrs.mSignedPkg; -} - -void -NeckoOriginAttributes::InheritFromDocToNecko(const PrincipalOriginAttributes& aAttrs) -{ - mAppId = aAttrs.mAppId; - mInBrowser = aAttrs.mInBrowser; - - // addonId is computed from the principal URI and never propagated - mUserContextId = aAttrs.mUserContextId; - - // TODO: - // Bug 1225353 - DocShell/NeckoOriginAttributes should inherit - // mSignedPkg accordingly by mSignedPkgInBrowser -} - -void -NeckoOriginAttributes::InheritFromDocShellToNecko(const DocShellOriginAttributes& aAttrs) -{ - mAppId = aAttrs.mAppId; - mInBrowser = aAttrs.mInBrowser; - - // addonId is computed from the principal URI and never propagated - mUserContextId = aAttrs.mUserContextId; - - // TODO: - // Bug 1225353 - DocShell/NeckoOriginAttributes should inherit - // mSignedPkg accordingly by mSignedPkgInBrowser + mAppId = attrs.mAppId; + mInBrowser = attrs.mInBrowser; + mAddonId = attrs.mAddonId; + mUserContextId = attrs.mUserContextId; + mSignedPkg = attrs.mSignedPkg; + return true; } void @@ -490,7 +442,7 @@ BasePrincipal::GetUnknownAppId(bool* aUnknownAppId) } already_AddRefed -BasePrincipal::CreateCodebasePrincipal(nsIURI* aURI, const PrincipalOriginAttributes& aAttrs) +BasePrincipal::CreateCodebasePrincipal(nsIURI* aURI, const OriginAttributes& aAttrs) { // If the URI is supposed to inherit the security context of whoever loads it, // we shouldn't make a codebase principal for it. diff --git a/caps/BasePrincipal.h b/caps/BasePrincipal.h index e8efd66180..e3918582a3 100644 --- a/caps/BasePrincipal.h +++ b/caps/BasePrincipal.h @@ -14,19 +14,26 @@ #include "mozilla/dom/ChromeUtilsBinding.h" class nsIContentSecurityPolicy; +class nsILoadContext; class nsIObjectOutputStream; class nsIObjectInputStream; -class nsIURI; class nsExpandedPrincipal; namespace mozilla { -// Base OriginAttributes class. This has several subclass flavors, and is not -// directly constructable itself. class OriginAttributes : public dom::OriginAttributesDictionary { public: + OriginAttributes() {} + OriginAttributes(uint32_t aAppId, bool aInBrowser) + { + mAppId = aAppId; + mInBrowser = aInBrowser; + } + explicit OriginAttributes(const OriginAttributesDictionary& aOther) + : OriginAttributesDictionary(aOther) {} + bool operator==(const OriginAttributes& aOther) const { return mAppId == aOther.mAppId && @@ -40,6 +47,28 @@ public: return !(*this == aOther); } + // The docshell often influences the origin attributes of content loaded + // inside of it, and in some cases also influences the origin attributes of + // content loaded in child docshells. We say that a given attribute "lives on + // the docshell" to indicate that this attribute is specified by the docshell + // (if any) associated with a given content document. + // + // In practice, this usually means that we need to store a copy of those + // attributes on each docshell, or provide methods on the docshell to compute + // them on-demand. + // We could track each of these attributes individually, but since the + // majority of the existing origin attributes currently live on the docshell, + // it's cleaner to simply store an entire OriginAttributes struct on each + // docshell, and selectively copy them to child docshells and content + // principals in a manner that implements our desired semantics. + // + // This method is used to propagate attributes from parent to child + // docshells. + void InheritFromDocShellParent(const OriginAttributes& aParent); + + // Copy from the origin attributes of the nsILoadContext. + bool CopyFromLoadContext(nsILoadContext* aLoadContext); + // Serializes/Deserializes non-default values into the suffix format, i.e. // |!key1=value1&key2=value2|. If there are no non-default attributes, this // returns an empty string. @@ -50,92 +79,6 @@ public: // |uri!key1=value1&key2=value2| and returns the uri without the suffix. bool PopulateFromOrigin(const nsACString& aOrigin, nsACString& aOriginNoSuffix); - -protected: - OriginAttributes() {} - explicit OriginAttributes(const OriginAttributesDictionary& aOther) - : OriginAttributesDictionary(aOther) {} -}; - -class PrincipalOriginAttributes; -class DocShellOriginAttributes; -class NeckoOriginAttributes; - -// Various classes in Gecko contain OriginAttributes members, and those -// OriginAttributes get propagated to other classes according to certain rules. -// For example, the OriginAttributes on the docshell affect the OriginAttributes -// for the principal of a document loaded inside it, whose OriginAttributes in -// turn affect those of network loads and child docshells. To codify and -// centralize these rules, we introduce separate subclasses for the different -// flavors, and a variety of InheritFrom* methods to implement the transfer -// behavior. - -// For OriginAttributes stored on principals. -class PrincipalOriginAttributes : public OriginAttributes -{ -public: - PrincipalOriginAttributes() {} - PrincipalOriginAttributes(uint32_t aAppId, bool aInBrowser) - { - mAppId = aAppId; - mInBrowser = aInBrowser; - } - - // Inheriting OriginAttributes from docshell to document when user navigates. - // - // @param aAttrs Origin Attributes of the docshell. - // @param aURI The URI of the document. - void InheritFromDocShellToDoc(const DocShellOriginAttributes& aAttrs, - const nsIURI* aURI); - - // Inherit OriginAttributes from Necko. - void InheritFromNecko(const NeckoOriginAttributes& aAttrs); -}; - -// For OriginAttributes stored on docshells / loadcontexts / browsing contexts. -class DocShellOriginAttributes : public OriginAttributes -{ -public: - DocShellOriginAttributes() {} - DocShellOriginAttributes(uint32_t aAppId, bool aInBrowser) - { - mAppId = aAppId; - mInBrowser = aInBrowser; - } - - // Inheriting OriginAttributes from document to child docshell when an - // \r ---NKWXJUAFXB\r +--X3JDIZCX8G\r Content-Location: scripts/script.js\r Content-Type: text/javascript\r \r // script.js \r ---NKWXJUAFXB\r +--X3JDIZCX8G\r Content-Location: scripts/library.js\r Content-Type: text/javascript\r \r // library.js \r ---NKWXJUAFXB--`; +--X3JDIZCX8G--`; diff --git a/netwerk/test/mochitests/test_origin_attributes_conversion.html b/netwerk/test/mochitests/test_origin_attributes_conversion.html deleted file mode 100644 index b9fb914ee1..0000000000 --- a/netwerk/test/mochitests/test_origin_attributes_conversion.html +++ /dev/null @@ -1,135 +0,0 @@ - - - - Bug 1209162 - Test Origin Attributes Conversion - - - - -

- -
-
-
- - diff --git a/netwerk/test/mochitests/test_signed_web_packaged_app_origin.html b/netwerk/test/mochitests/test_signed_web_packaged_app_origin.html index 684762415d..577a97b519 100644 --- a/netwerk/test/mochitests/test_signed_web_packaged_app_origin.html +++ b/netwerk/test/mochitests/test_signed_web_packaged_app_origin.html @@ -91,4 +91,4 @@ function getNodePrincipalOrigin() { - + \ No newline at end of file diff --git a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp index a8ad3a3445..55690a539c 100644 --- a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp +++ b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp @@ -102,7 +102,7 @@ nsUrlClassifierStreamUpdater::FetchUpdate(nsIURI *aUpdateUrl, NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr loadInfo = mChannel->GetLoadInfo(); - loadInfo->SetOriginAttributes(mozilla::NeckoOriginAttributes(NECKO_SAFEBROWSING_APP_ID, false)); + loadInfo->SetOriginAttributes(mozilla::OriginAttributes(NECKO_SAFEBROWSING_APP_ID, false)); mBeganStream = false; diff --git a/uriloader/prefetch/OfflineCacheUpdateParent.cpp b/uriloader/prefetch/OfflineCacheUpdateParent.cpp index 3fb8d0f828..e50432e800 100644 --- a/uriloader/prefetch/OfflineCacheUpdateParent.cpp +++ b/uriloader/prefetch/OfflineCacheUpdateParent.cpp @@ -17,8 +17,7 @@ using namespace mozilla::ipc; using mozilla::BasePrincipal; -using mozilla::DocShellOriginAttributes; -using mozilla::PrincipalOriginAttributes; +using mozilla::OriginAttributes; using mozilla::dom::TabParent; // @@ -53,7 +52,7 @@ NS_IMPL_ISUPPORTS(OfflineCacheUpdateParent, // OfflineCacheUpdateParent //----------------------------------------------------------------------------- -OfflineCacheUpdateParent::OfflineCacheUpdateParent(const DocShellOriginAttributes& aAttrs) +OfflineCacheUpdateParent::OfflineCacheUpdateParent(const OriginAttributes& aAttrs) : mIPCClosed(false) , mOriginAttributes(aAttrs) { @@ -94,10 +93,8 @@ OfflineCacheUpdateParent::Schedule(const URIParams& aManifestURI, bool offlinePermissionAllowed = false; - PrincipalOriginAttributes principalAttrs; - principalAttrs.InheritFromDocShellToDoc(mOriginAttributes, manifestURI); nsCOMPtr principal = - BasePrincipal::CreateCodebasePrincipal(manifestURI, principalAttrs); + BasePrincipal::CreateCodebasePrincipal(manifestURI, mOriginAttributes); nsresult rv = service->OfflineAppAllowed( principal, nullptr, &offlinePermissionAllowed); diff --git a/uriloader/prefetch/OfflineCacheUpdateParent.h b/uriloader/prefetch/OfflineCacheUpdateParent.h index b98bcc9bd1..c7a83223fa 100644 --- a/uriloader/prefetch/OfflineCacheUpdateParent.h +++ b/uriloader/prefetch/OfflineCacheUpdateParent.h @@ -45,7 +45,7 @@ public: mIPCClosed = true; } - explicit OfflineCacheUpdateParent(const mozilla::DocShellOriginAttributes& aAttrs); + explicit OfflineCacheUpdateParent(const mozilla::OriginAttributes& aAttrs); virtual void ActorDestroy(ActorDestroyReason aWhy) override; private: @@ -53,7 +53,7 @@ private: bool mIPCClosed; - mozilla::DocShellOriginAttributes mOriginAttributes; + mozilla::OriginAttributes mOriginAttributes; }; } // namespace docshell