Bug 1113431 - Expose referrer policy to UI code via Document and nsIWebNavigation. r=jst, sr=bz

This commit is contained in:
Alex Verstak 2015-01-05 09:42:31 -08:00
parent 2cf633a3fb
commit d0c9d91dc1
11 changed files with 95 additions and 54 deletions

View File

@ -4735,17 +4735,19 @@ nsDocShell::LoadURI(const char16_t* aURI,
nsIInputStream* aPostStream,
nsIInputStream* aHeaderStream)
{
return LoadURIWithBase(aURI, aLoadFlags, aReferringURI, aPostStream,
aHeaderStream, nullptr);
return LoadURIWithOptions(aURI, aLoadFlags, aReferringURI,
mozilla::net::RP_Default, aPostStream,
aHeaderStream, nullptr);
}
NS_IMETHODIMP
nsDocShell::LoadURIWithBase(const char16_t* aURI,
uint32_t aLoadFlags,
nsIURI* aReferringURI,
nsIInputStream* aPostStream,
nsIInputStream* aHeaderStream,
nsIURI* aBaseURI)
nsDocShell::LoadURIWithOptions(const char16_t* aURI,
uint32_t aLoadFlags,
nsIURI* aReferringURI,
uint32_t aReferrerPolicy,
nsIInputStream* aPostStream,
nsIInputStream* aHeaderStream,
nsIURI* aBaseURI)
{
NS_ASSERTION((aLoadFlags & 0xf) == 0, "Unexpected flags");
@ -4855,6 +4857,7 @@ nsDocShell::LoadURIWithBase(const char16_t* aURI,
loadInfo->SetLoadType(ConvertLoadTypeToDocShellLoadInfo(loadType));
loadInfo->SetPostDataStream(postStream);
loadInfo->SetReferrer(aReferringURI);
loadInfo->SetReferrerPolicy(aReferrerPolicy);
loadInfo->SetHeadersStream(aHeaderStream);
loadInfo->SetBaseURI(aBaseURI);

View File

@ -16,7 +16,7 @@ interface nsIURI;
* location, stop or restart an in process load, or determine where the object
* has previously gone.
*/
[scriptable, uuid(b7568a50-4c50-442c-a6be-3a340a48d89a)]
[scriptable, uuid(0e92d522-53a5-4af6-9a24-4eccdcbf4f91)]
interface nsIWebNavigation : nsISupports
{
/**
@ -240,11 +240,8 @@ interface nsIWebNavigation : nsISupports
* in the object implementing this interface. If it can't be loaded here
* however, the URI dispatcher will go through its normal process of content
* loading.
* Behaves like loadURI, except an additional parameter is provided to supply
* a base URI to be used in specific situations where one cannot be inferred
* by other means, for example when this is called to view selection source.
* Outside of these situations, the behaviour of this function is no
* different to loadURI.
*
* Behaves like loadURI, but allows passing of additional parameters.
*
* @param aURI
* The URI string to load. For HTTP and FTP URLs and possibly others,
@ -258,6 +255,9 @@ interface nsIWebNavigation : nsISupports
* @param aReferrer
* The referring URI. If this argument is null, then the referring
* URI will be inferred internally.
* @param aReferrerPolicy
* One of the REFERRER_POLICY_* constants from nsIHttpChannel.
* Normal case is REFERRER_POLICY_DEFAULT.
* @param aPostData
* If the URI corresponds to a HTTP request, then this stream is
* appended directly to the HTTP request headers. It may be prefixed
@ -276,12 +276,13 @@ interface nsIWebNavigation : nsISupports
* and cannot be used to resolve aURI.
* This parameter is optional and may be null.
*/
void loadURIWithBase(in wstring aURI,
in unsigned long aLoadFlags,
in nsIURI aReferrer,
in nsIInputStream aPostData,
in nsIInputStream aHeaders,
in nsIURI aBaseURI);
void loadURIWithOptions(in wstring aURI,
in unsigned long aLoadFlags,
in nsIURI aReferrer,
in unsigned long aReferrerPolicy,
in nsIInputStream aPostData,
in nsIInputStream aHeaders,
in nsIURI aBaseURI);
/**
* Tells the Object to reload the current page. There may be cases where the

View File

@ -1513,12 +1513,13 @@ nsSHistory::GetSessionHistory(nsISHistory** aSessionHistory)
}
NS_IMETHODIMP
nsSHistory::LoadURIWithBase(const char16_t* aURI,
uint32_t aLoadFlags,
nsIURI* aReferringURI,
nsIInputStream* aPostStream,
nsIInputStream* aExtraHeaderStream,
nsIURI* aBaseURI)
nsSHistory::LoadURIWithOptions(const char16_t* aURI,
uint32_t aLoadFlags,
nsIURI* aReferringURI,
uint32_t aReferrerPolicy,
nsIInputStream* aPostStream,
nsIInputStream* aExtraHeaderStream,
nsIURI* aBaseURI)
{
return NS_OK;
}

View File

@ -686,6 +686,7 @@ class nsDocument : public nsIDocument,
public:
typedef mozilla::dom::Element Element;
using nsIDocument::GetElementsByTagName;
typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
NS_DECL_CYCLE_COLLECTING_ISUPPORTS

View File

@ -183,7 +183,7 @@ class nsIDocument : public nsINode
{
typedef mozilla::dom::GlobalObject GlobalObject;
public:
typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
typedef mozilla::net::ReferrerPolicy ReferrerPolicyEnum;
typedef mozilla::dom::Element Element;
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID)
@ -290,11 +290,19 @@ public:
* Return the referrer policy of the document. Return "default" if there's no
* valid meta referrer tag found in the document.
*/
ReferrerPolicy GetReferrerPolicy() const
ReferrerPolicyEnum GetReferrerPolicy() const
{
return mReferrerPolicy;
}
/**
* GetReferrerPolicy() for Document.webidl.
*/
uint32_t ReferrerPolicy() const
{
return GetReferrerPolicy();
}
/**
* Set the principal responsible for this document.
*/
@ -1969,7 +1977,7 @@ public:
*/
virtual void MaybePreLoadImage(nsIURI* uri,
const nsAString& aCrossOriginAttr,
ReferrerPolicy aReferrerPolicy) = 0;
ReferrerPolicyEnum aReferrerPolicy) = 0;
/**
* Called by images to forget an image preload when they start doing
@ -1984,7 +1992,7 @@ public:
*/
virtual void PreloadStyle(nsIURI* aURI, const nsAString& aCharset,
const nsAString& aCrossOriginAttr,
ReferrerPolicy aReferrerPolicy) = 0;
ReferrerPolicyEnum aReferrerPolicy) = 0;
/**
* Called by the chrome registry to load style sheets. Can be put
@ -2581,7 +2589,7 @@ protected:
nsWeakPtr mDocumentLoadGroup;
bool mReferrerPolicySet;
ReferrerPolicy mReferrerPolicy;
ReferrerPolicyEnum mReferrerPolicy;
mozilla::WeakPtr<nsDocShell> mDocumentContainer;

View File

@ -204,6 +204,13 @@ partial interface Document {
[ChromeOnly]
readonly attribute URI? documentURIObject;
/**
* Current referrer policy - one of the REFERRER_POLICY_* constants
* from nsIHttpChannel.
*/
[ChromeOnly]
readonly attribute unsigned long referrerPolicy;
};
// http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html#api

View File

@ -578,21 +578,23 @@ NS_IMETHODIMP nsWebBrowser::GoForward()
return mDocShellAsNav->GoForward();
}
NS_IMETHODIMP nsWebBrowser::LoadURIWithBase(const char16_t* aURI,
uint32_t aLoadFlags,
nsIURI* aReferringURI,
nsIInputStream* aPostDataStream,
nsIInputStream* aExtraHeaderStream,
nsIURI* aBaseURI)
NS_IMETHODIMP nsWebBrowser::LoadURIWithOptions(const char16_t* aURI,
uint32_t aLoadFlags,
nsIURI* aReferringURI,
uint32_t aReferrerPolicy,
nsIInputStream* aPostDataStream,
nsIInputStream* aExtraHeaderStream,
nsIURI* aBaseURI)
{
NS_ENSURE_STATE(mDocShell);
return mDocShellAsNav->LoadURIWithBase(aURI,
aLoadFlags,
aReferringURI,
aPostDataStream,
aExtraHeaderStream,
aBaseURI);
return mDocShellAsNav->LoadURIWithOptions(aURI,
aLoadFlags,
aReferringURI,
aReferrerPolicy,
aPostDataStream,
aExtraHeaderStream,
aBaseURI);
}
NS_IMETHODIMP nsWebBrowser::LoadURI(const char16_t* aURI,

View File

@ -14,7 +14,7 @@ interface nsIHttpHeaderVisitor;
* the inspection of the resulting HTTP response status and headers when they
* become available.
*/
[scriptable, uuid(a8bed710-653c-4ea4-9747-a629cc482cf8)]
[scriptable, uuid(86ad7e1f-3a64-4e0f-a104-395ebecd7d5c)]
interface nsIHttpChannel : nsIChannel
{
/**************************************************************************
@ -59,6 +59,8 @@ interface nsIHttpChannel : nsIChannel
* Referrer policies. See ReferrerPolicy.h for more details.
*/
/* default state, a shorter name for no-referrer-when-downgrade */
const unsigned long REFERRER_POLICY_DEFAULT = 0;
/* default state, doesn't send referrer from https->http */
const unsigned long REFERRER_POLICY_NO_REFERRER_WHEN_DOWNGRADE = 0;
/* sends no referrer */

View File

@ -173,12 +173,15 @@ function viewPartialSourceForSelection(selection)
// all our content is held by the data:URI and URIs are internally stored as utf-8 (see nsIURI.idl)
var loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
getWebNavigation().loadURIWithBase((isHTML ?
"view-source:data:text/html;charset=utf-8," :
"view-source:data:application/xml;charset=utf-8,")
+ encodeURIComponent(tmpNode.innerHTML),
loadFlags, null, null, null,
Services.io.newURI(doc.baseURI, null, null));
var referrerPolicy = Components.interfaces.nsIHttpChannel.REFERRER_POLICY_DEFAULT;
getWebNavigation().loadURIWithOptions((isHTML ?
"view-source:data:text/html;charset=utf-8," :
"view-source:data:application/xml;charset=utf-8,")
+ encodeURIComponent(tmpNode.innerHTML),
loadFlags,
null, referrerPolicy, // referrer
null, null, // postData, headers
Services.io.newURI(doc.baseURI, null, null));
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -218,7 +218,9 @@ let WebNavigation = {
this.gotoIndex(message.data.index);
break;
case "WebNavigation:LoadURI":
this.loadURI(message.data.uri, message.data.flags, message.data.referrer);
this.loadURI(message.data.uri, message.data.flags,
message.data.referrer, message.data.referrerPolicy,
message.data.baseURI);
break;
case "WebNavigation:Reload":
this.reload(message.data.flags);
@ -244,14 +246,17 @@ let WebNavigation = {
this._webNavigation.gotoIndex(index);
},
loadURI: function(uri, flags, referrer) {
loadURI: function(uri, flags, referrer, referrerPolicy, baseURI) {
#ifdef MOZ_CRASHREPORTER
if (CrashReporter.enabled)
CrashReporter.annotateCrashReport("URL", uri);
#endif
if (referrer)
referrer = Services.io.newURI(referrer, null, null);
this._webNavigation.loadURI(uri, flags, referrer, null, null);
if (baseURI)
baseURI = Services.io.newURI(baseURI, null, null);
this._webNavigation.loadURIWithOptions(uri, flags, referrer, referrerPolicy,
null, null, baseURI);
},
reload: function(flags) {

View File

@ -67,13 +67,21 @@ RemoteWebNavigation.prototype = {
this._sendMessage("WebNavigation:GotoIndex", {index: aIndex});
},
loadURI: function(aURI, aLoadFlags, aReferrer, aPostData, aHeaders) {
this.loadURIWithOptions(aURI, aLoadFlags, aReferrer,
Ci.nsIHttpChannel.REFERRER_POLICY_DEFAULT,
aPostData, aHeaders, null);
},
loadURIWithOptions: function(aURI, aLoadFlags, aReferrer, aReferrerPolicy,
aPostData, aHeaders, aBaseURI) {
if (aPostData || aHeaders)
throw Components.Exception("RemoteWebNavigation doesn't accept postdata or headers.", Cr.NS_ERROR_INVALID_ARGS);
this._sendMessage("WebNavigation:LoadURI", {
uri: aURI,
flags: aLoadFlags,
referrer: aReferrer ? aReferrer.spec : null
referrer: aReferrer ? aReferrer.spec : null,
referrerPolicy: aReferrerPolicy,
baseURI: aBaseURI ? aBaseURI.spec : null,
});
},
reload: function(aReloadFlags) {