Mozilla Home
Privacy
Cookies
Legal
Bugzilla
Browse
Advanced Search
New Bug
Reports
Documentation
Log In
Log In with GitHub
or
Remember me
Browse
Advanced Search
New Bug
Reports
Documentation
Attachment 8372574 Details for
Bug 966505
[patch]
bug966505-contentpref-retrieval
bug966505-contentpref-retrieval (text/plain), 13.30 KB, created by
Sid Stamm [:geekboy or :sstamm]
(
hide
)
Description:
bug966505-contentpref-retrieval
Filename:
MIME Type:
Creator:
Sid Stamm [:geekboy or :sstamm]
Size:
13.30 KB
patch
obsolete
># HG changeset patch ># Parent d05c721ea1b0def89ed49532845398722478e909 ># User Sid Stamm <sstamm@mozilla.com> >bug 966505 - store per-site referrer policies in permission manager. > >diff -r d05c721ea1b0 netwerk/protocol/http/HttpBaseChannel.cpp >--- a/netwerk/protocol/http/HttpBaseChannel.cpp Fri Feb 07 09:54:06 2014 +0100 >+++ b/netwerk/protocol/http/HttpBaseChannel.cpp Fri Feb 07 13:57:34 2014 -0800 >@@ -63,16 +63,17 @@ HttpBaseChannel::HttpBaseChannel() > , mContentDispositionHint(UINT32_MAX) > , mHttpHandler(gHttpHandler) > { > LOG(("Creating HttpBaseChannel @%x\n", this)); > > // Subfields of unions cannot be targeted in an initializer list > mSelfAddr.raw.family = PR_AF_UNSPEC; > mPeerAddr.raw.family = PR_AF_UNSPEC; >+ mSiteReferrerSettings = {false, 0, false, 0, 0}; > } > > HttpBaseChannel::~HttpBaseChannel() > { > LOG(("Destroying HttpBaseChannel @%x\n", this)); > > // Make sure we don't leak > CleanRedirectCacheChainIfNecessary(); >@@ -861,22 +862,31 @@ HttpBaseChannel::SetReferrer(nsIURI *ref > > // false: use real referrer > // true: spoof with URI of the current request > bool userSpoofReferrerSource = gHttpHandler->SpoofReferrerSource(); > > // 0: full URI > // 1: scheme+host+port+path > // 2: scheme+host+port >- int userReferrerTrimmingPolicy = gHttpHandler->ReferrerTrimmingPolicy(); >+ uint32_t userReferrerTrimmingPolicy = gHttpHandler->ReferrerTrimmingPolicy(); > > // 0: send referer no matter what > // 1: send referer ONLY when base domains match > // 2: send referer ONLY when hosts match >- int userReferrerXOriginPolicy = gHttpHandler->ReferrerXOriginPolicy(); >+ uint32_t userReferrerXOriginPolicy = gHttpHandler->ReferrerXOriginPolicy(); >+ >+ // Note: Any per-site prefs will override the global settings >+ if (mSiteReferrerSettings.hasSitePrefs) { >+ LOG(("HttpBaseChannel::SetReferrer : hasSitePrefs=true [this=%p]\n", this)); >+ userReferrerLevel = mSiteReferrerSettings.level; >+ userSpoofReferrerSource = mSiteReferrerSettings.spoof; >+ userReferrerTrimmingPolicy = mSiteReferrerSettings.trim; >+ userReferrerXOriginPolicy = mSiteReferrerSettings.xorigin; >+ } > > // check referrer blocking pref > uint32_t referrerLevel; > if (mLoadFlags & LOAD_INITIAL_DOCUMENT_URI) > referrerLevel = 1; // user action > else > referrerLevel = 2; // inline content > if (userReferrerLevel < referrerLevel) >diff -r d05c721ea1b0 netwerk/protocol/http/HttpBaseChannel.h >--- a/netwerk/protocol/http/HttpBaseChannel.h Fri Feb 07 09:54:06 2014 +0100 >+++ b/netwerk/protocol/http/HttpBaseChannel.h Fri Feb 07 13:57:34 2014 -0800 >@@ -198,16 +198,24 @@ public: > }; > > nsHttpResponseHead * GetResponseHead() const { return mResponseHead; } > nsHttpRequestHead * GetRequestHead() { return &mRequestHead; } > > const NetAddr& GetSelfAddr() { return mSelfAddr; } > const NetAddr& GetPeerAddr() { return mPeerAddr; } > >+ struct ReferrerSettings { >+ bool hasSitePrefs; >+ int32_t level; >+ bool spoof; >+ int32_t trim; >+ int32_t xorigin; >+ }; >+ > public: /* Necko internal use only... */ > > protected: > nsCOMArray<nsISecurityConsoleMessage> mSecurityConsoleMessages; > > // Handle notifying listener, removing from loadgroup if request failed. > void DoNotifyListener(); > virtual void DoNotifyListenerCleanup() = 0; >@@ -309,16 +317,18 @@ protected: > > uint32_t mProxyResolveFlags; > nsCOMPtr<nsIURI> mProxyURI; > > uint32_t mContentDispositionHint; > nsAutoPtr<nsString> mContentDispositionFilename; > > nsRefPtr<nsHttpHandler> mHttpHandler; // keep gHttpHandler alive >+ >+ ReferrerSettings mSiteReferrerSettings; > }; > > // Share some code while working around C++'s absurd inability to handle casting > // of member functions between base/derived types. > // - We want to store member function pointer to call at resume time, but one > // such function--HandleAsyncAbort--we want to share between the > // nsHttpChannel/HttpChannelChild. Can't define it in base class, because > // then we'd have to cast member function ptr between base/derived class >diff -r d05c721ea1b0 netwerk/protocol/http/nsHttpChannel.cpp >--- a/netwerk/protocol/http/nsHttpChannel.cpp Fri Feb 07 09:54:06 2014 +0100 >+++ b/netwerk/protocol/http/nsHttpChannel.cpp Fri Feb 07 13:57:34 2014 -0800 >@@ -206,16 +206,17 @@ nsHttpChannel::nsHttpChannel() > , mHasQueryString(0) > , mConcurentCacheAccess(0) > , mIsPartialRequest(0) > , mDidReval(false) > { > LOG(("Creating nsHttpChannel [this=%p]\n", this)); > mChannelCreationTime = PR_Now(); > mChannelCreationTimestamp = TimeStamp::Now(); >+ mRefPolicyFetcher = new ReferrerPolicyFetcher(); > } > > nsHttpChannel::~nsHttpChannel() > { > LOG(("Destroying nsHttpChannel [this=%p]\n", this)); > > if (mAuthProvider) > mAuthProvider->Disconnect(NS_ERROR_ABORT); >@@ -4423,16 +4424,20 @@ nsHttpChannel::AsyncOpen(nsIStreamListen > nsresult rv; > > rv = NS_CheckPortSafety(mURI); > if (NS_FAILED(rv)) { > ReleaseListeners(); > return rv; > } > >+ // Look up any content pref stored referrer policy. >+ // mRefPolicyFetcher is in HttpBaseChannel. >+ mRefPolicyFetcher->Fetch(mURI); >+ > // Remember the cookie header that was set, if any > const char *cookieHeader = mRequestHead.PeekHeader(nsHttp::Cookie); > if (cookieHeader) { > mUserSetCookieHeader = cookieHeader; > } > > AddCookiesToRequest(); > >@@ -4506,16 +4511,25 @@ nsHttpChannel::BeginConnect() > mAuthProvider = > do_CreateInstance("@mozilla.org/network/http-channel-auth-provider;1", > &rv); > if (NS_SUCCEEDED(rv)) > rv = mAuthProvider->Init(this); > if (NS_FAILED(rv)) > return rv; > >+ // Ensure that this happened before we tried to open the channel >+ MOZ_ASSERT(mRefPolicyFetcher->mCheckedPrefs, >+ "Should have checked referrer content prefs before BeginConnect()"); >+ // copy prefs into HttpBaseChannel's data structure >+ rv = mRefPolicyFetcher->Get(mSiteReferrerSettings); >+ NS_ENSURE_SUCCESS(rv, rv); >+ // and force a referrer policy update. >+ SetReferrer(mReferrer); >+ > // check to see if authorization headers should be included > mAuthProvider->AddAuthorizationHeaders(); > > // notify "http-on-modify-request" observers > CallOnModifyRequestObservers(); > > // Check to see if we should redirect this channel elsewhere by > // nsIHttpChannel.redirectTo API request >@@ -6009,16 +6023,95 @@ nsHttpChannel::OnLookupComplete(nsICance > mTransaction->SetDNSWasRefreshed(); > } > } > > return NS_OK; > } > > //----------------------------------------------------------------------------- >+// nsHttpChannel::ReferrerPolicyFetcher >+//----------------------------------------------------------------------------- >+ >+NS_IMPL_ISUPPORTS1(nsHttpChannel::ReferrerPolicyFetcher, >+ nsIContentPrefCallback2); >+ >+NS_IMETHODIMP >+nsHttpChannel::ReferrerPolicyFetcher::HandleResult(nsIContentPref* aPref) >+{ >+ LOG(("ReferrerPolicyFetcher::HandleResult\n")); >+ uint16_t packedPrefs; >+ nsCOMPtr<nsIVariant> value; >+ nsresult rv; >+ >+ rv = aPref->GetValue(getter_AddRefs(value)); >+ NS_ENSURE_SUCCESS(rv, rv); >+ >+ rv = value->GetAsUint16(&packedPrefs); >+ NS_ENSURE_SUCCESS(rv, rv); >+ >+ // unpack the pref which is packed as 3-bit values, except the spoof >+ // which is a boolean (so it's one bit) >+ mSiteReferrerLevel = (packedPrefs <<= 3) % 8; >+ mSiteSpoofReferrerSource = (packedPrefs <<= 1) % 2; >+ mSiteReferrerTrimmingPolicy = (packedPrefs <<= 3) % 8; >+ mSiteReferrerXOriginPolicy = (packedPrefs <<= 3) % 8; >+ >+ mHasSiteSpecificReferrerPrefs = true; >+ >+ return NS_OK; >+} >+ >+NS_IMETHODIMP >+nsHttpChannel::ReferrerPolicyFetcher::HandleCompletion(uint16_t reason) >+{ >+ mCheckedPrefs = true; >+ return NS_OK; >+} >+ >+NS_IMETHODIMP >+nsHttpChannel::ReferrerPolicyFetcher::HandleError(nsresult error) >+{ >+ return NS_OK; >+} >+ >+nsresult >+nsHttpChannel::ReferrerPolicyFetcher::Get(ReferrerSettings &prefs) >+{ >+ prefs.hasSitePrefs = true; >+ prefs.level = mSiteReferrerLevel; >+ prefs.spoof = (mSiteSpoofReferrerSource == 1); >+ prefs.trim = mSiteReferrerTrimmingPolicy; >+ prefs.xorigin = mSiteReferrerXOriginPolicy; >+ return NS_OK; >+} >+ >+nsresult >+nsHttpChannel::ReferrerPolicyFetcher::Fetch(nsIURI* aChannelURI) >+{ >+ NS_ENSURE_ARG(aChannelURI); >+ >+ nsAutoCString uriSpec; >+ nsresult rv = aChannelURI->GetSpec(uriSpec); >+ LOG(("ReferrerPolicyFetcher::Fetch : [uri=%p]\n", uriSpec.get())); >+ NS_ENSURE_SUCCESS(rv, rv); >+ >+ nsCOMPtr<nsIContentPrefService2> cps = do_GetService(NS_CONTENT_PREF_SERVICE_CONTRACTID); >+ if (cps) { >+ // TODO(sstamm): should we get the load context for private browsing? >+ rv = cps->GetByDomainAndName(NS_ConvertUTF8toUTF16(uriSpec), >+ NS_LITERAL_STRING("referrerPolicy"), nullptr, this); >+ NS_ENSURE_SUCCESS(rv, rv); >+ } >+ return NS_OK; >+} >+ >+ >+ >+//----------------------------------------------------------------------------- > // nsHttpChannel internal functions > //----------------------------------------------------------------------------- > > void > nsHttpChannel::MaybeInvalidateCacheEntryForSubsequentGet() > { > // See RFC 2616 section 5.1.1. These are considered valid > // methods which DO NOT invalidate cache-entries for the >diff -r d05c721ea1b0 netwerk/protocol/http/nsHttpChannel.h >--- a/netwerk/protocol/http/nsHttpChannel.h Fri Feb 07 09:54:06 2014 +0100 >+++ b/netwerk/protocol/http/nsHttpChannel.h Fri Feb 07 13:57:34 2014 -0800 >@@ -19,16 +19,18 @@ > #include "nsIAsyncVerifyRedirectCallback.h" > #include "nsITimedChannel.h" > #include "nsIThreadRetargetableRequest.h" > #include "nsIThreadRetargetableStreamListener.h" > #include "nsWeakReference.h" > #include "TimingStruct.h" > #include "AutoClose.h" > #include "mozilla/Telemetry.h" >+#include "nsIContentPrefService.h" >+#include "nsIContentPrefService2.h" > > class nsIPrincipal; > class nsDNSPrefetch; > class nsICacheEntryDescriptor; > class nsICancelable; > class nsIHttpChannelAuthProvider; > class nsInputStreamPump; > >@@ -114,32 +116,68 @@ public: > // nsISupportsPriority > NS_IMETHOD SetPriority(int32_t value); > // nsIResumableChannel > NS_IMETHOD ResumeAt(uint64_t startPos, const nsACString& entityID); > > NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks); > NS_IMETHOD SetLoadGroup(nsILoadGroup *aLoadGroup); > >+ > public: /* internal necko use only */ > > void InternalSetUploadStream(nsIInputStream *uploadStream) > { mUploadStream = uploadStream; } > void SetUploadStreamHasHeaders(bool hasHeaders) > { mUploadStreamHasHeaders = hasHeaders; } > > nsresult SetReferrerInternal(nsIURI *referrer) { > nsAutoCString spec; > nsresult rv = referrer->GetAsciiSpec(spec); > if (NS_FAILED(rv)) return rv; > mReferrer = referrer; > mRequestHead.SetHeader(nsHttp::Referer, spec); > return NS_OK; > } > >+ // This class fetches the referrer policy content prefs and maintains state >+ // during the async fetch. >+ class ReferrerPolicyFetcher MOZ_FINAL : public nsIContentPrefCallback2 { >+ friend class HttpBaseChannel; >+ friend class nsHttpChannel; >+ >+ public: >+ ReferrerPolicyFetcher() >+ : mCheckedPrefs(false), >+ mHasSiteSpecificReferrerPrefs(false) >+ { } >+ >+ virtual ~ReferrerPolicyFetcher() >+ { } >+ >+ NS_DECL_ISUPPORTS >+ NS_DECL_NSICONTENTPREFCALLBACK2 >+ >+ NS_IMETHOD Fetch(nsIURI* aChannelURI); >+ nsresult Get(ReferrerSettings &prefs); >+ >+ private: >+ // set to true after the prefs check completes >+ bool mCheckedPrefs; >+ >+ // true if there were prefs in the DB >+ bool mHasSiteSpecificReferrerPrefs; >+ >+ // referrer policies for this channel (see HttpBaseChannel::SetReferrer) >+ uint32_t mSiteReferrerLevel; >+ uint32_t mSiteSpoofReferrerSource; >+ uint32_t mSiteReferrerTrimmingPolicy; >+ uint32_t mSiteReferrerXOriginPolicy; >+ }; >+ > // This allows cache entry to be marked as foreign even after channel itself > // is gone. Needed for e10s (see HttpChannelParent::RecvDocumentChannelCleanup) > class OfflineCacheEntryAsForeignMarker { > nsCOMPtr<nsIApplicationCache> mApplicationCache; > nsCOMPtr<nsIURI> mCacheURI; > public: > OfflineCacheEntryAsForeignMarker(nsIApplicationCache* appCache, > nsIURI* aURI) >@@ -405,16 +443,20 @@ private: > TimeStamp mCacheReadStart; > TimeStamp mCacheReadEnd; > // copied from the transaction before we null out mTransaction > // so that the timing can still be queried from OnStopRequest > TimingStruct mTransactionTimings; > // Needed for accurate DNS timing > nsRefPtr<nsDNSPrefetch> mDNSPrefetch; > >+ // Needed for asynchronous fetch of referrer policies from the content pref >+ // service >+ ReferrerPolicyFetcher* mRefPolicyFetcher; >+ > nsresult WaitForRedirectCallback(); > void PushRedirectAsyncFunc(nsContinueRedirectionFunc func); > void PopRedirectAsyncFunc(nsContinueRedirectionFunc func); > > protected: > virtual void DoNotifyListenerCleanup(); > > private: // cache telemetry
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Actions:
View
|
Diff
|
Review
Attachments on
bug 966505
:
8368970
|
8369574
| 8372574