mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-09 17:31:47 +09:00
ported from mozilla: Bug 1460920 - Part 2 : Support referrerpolicy attribute in script HTMLScriptElement r=hsivonen (3309aa6d27)
This commit is contained in:
parent
281e3f4d1b
commit
ed16ab739e
7 changed files with 48 additions and 5 deletions
|
|
@ -324,6 +324,12 @@ HTMLScriptElement::GetCORSMode() const
|
|||
return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
|
||||
}
|
||||
|
||||
mozilla::net::ReferrerPolicy
|
||||
HTMLScriptElement::GetReferrerPolicy()
|
||||
{
|
||||
return GetReferrerPolicyAsEnum();
|
||||
}
|
||||
|
||||
bool
|
||||
HTMLScriptElement::HasScriptContent()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ public:
|
|||
virtual void GetScriptCharset(nsAString& charset) override;
|
||||
virtual void FreezeExecutionAttrs(nsIDocument* aOwnerDoc) override;
|
||||
virtual CORSMode GetCORSMode() const override;
|
||||
virtual mozilla::net::ReferrerPolicy GetReferrerPolicy() override;
|
||||
|
||||
// nsIContent
|
||||
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
||||
|
|
@ -96,6 +97,14 @@ public:
|
|||
{
|
||||
SetHTMLAttr(nsGkAtoms::integrity, aIntegrity, rv);
|
||||
}
|
||||
void SetReferrerPolicy(const nsAString& aReferrerPolicy, ErrorResult& aError)
|
||||
{
|
||||
SetHTMLAttr(nsGkAtoms::referrerpolicy, aReferrerPolicy, aError);
|
||||
}
|
||||
void GetReferrerPolicy(nsAString& aReferrerPolicy)
|
||||
{
|
||||
GetEnumAttr(nsGkAtoms::referrerpolicy, EmptyCString().get(), aReferrerPolicy);
|
||||
}
|
||||
bool Async();
|
||||
void SetAsync(bool aValue, ErrorResult& rv);
|
||||
bool NoModule();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ SimpleTest.waitForExplicitFinish();
|
|||
SimpleTest.waitForFocus(runTests);
|
||||
|
||||
function runTests() {
|
||||
var elements = [ "iframe", "img", "a", "area", "link" ];
|
||||
var elements = [ "iframe", "img", "a", "area", "link", "script"];
|
||||
|
||||
for (var i = 0; i < elements.length; ++i) {
|
||||
reflectLimitedEnumerated({
|
||||
|
|
|
|||
|
|
@ -1563,7 +1563,7 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
|||
// Step 15. and later in the HTML5 spec
|
||||
nsresult rv = NS_OK;
|
||||
RefPtr<ScriptLoadRequest> request;
|
||||
mozilla::net::ReferrerPolicy ourRefPolicy = mDocument->GetReferrerPolicy();
|
||||
mozilla::net::ReferrerPolicy referrerPolicy = GetReferrerPolicy(aElement);
|
||||
if (aElement->GetScriptExternal()) {
|
||||
// external script
|
||||
nsCOMPtr<nsIURI> scriptURI = aElement->GetScriptURI();
|
||||
|
|
@ -1593,7 +1593,7 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
|||
aElement->GetScriptCharset(elementCharset);
|
||||
if (elementCharset.Equals(preloadCharset) &&
|
||||
ourCORSMode == request->CORSMode() &&
|
||||
ourRefPolicy == request->ReferrerPolicy() &&
|
||||
referrerPolicy == request->ReferrerPolicy() &&
|
||||
scriptKind == request->mKind) {
|
||||
rv = CheckContentPolicy(mDocument, aElement, request->mURI, type, false);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
|
@ -1639,7 +1639,7 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
|||
nsCOMPtr<nsIPrincipal> principal = scriptContent->NodePrincipal();
|
||||
|
||||
request = CreateLoadRequest(scriptKind, scriptURI, aElement, principal,
|
||||
ourCORSMode, sriMetadata, ourRefPolicy);
|
||||
ourCORSMode, sriMetadata, referrerPolicy);
|
||||
request->mIsInline = false;
|
||||
request->SetScriptMode(aElement->GetScriptDeferred(),
|
||||
aElement->GetScriptAsync());
|
||||
|
|
@ -1760,7 +1760,7 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
|||
mDocument->NodePrincipal(),
|
||||
CORS_NONE,
|
||||
SRIMetadata(), // SRI doesn't apply
|
||||
ourRefPolicy);
|
||||
referrerPolicy);
|
||||
request->mIsInline = true;
|
||||
request->mLineNo = aElement->GetScriptLineNumber();
|
||||
|
||||
|
|
@ -1826,6 +1826,17 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
|||
return ProcessRequest(request) == NS_ERROR_HTMLPARSER_BLOCK;
|
||||
}
|
||||
|
||||
mozilla::net::ReferrerPolicy
|
||||
ScriptLoader::GetReferrerPolicy(nsIScriptElement* aElement)
|
||||
{
|
||||
mozilla::net::ReferrerPolicy scriptReferrerPolicy =
|
||||
aElement->GetReferrerPolicy();
|
||||
if (scriptReferrerPolicy != mozilla::net::RP_Unset) {
|
||||
return scriptReferrerPolicy;
|
||||
}
|
||||
return mDocument->GetReferrerPolicy();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class NotifyOffThreadScriptLoadCompletedRunnable : public Runnable
|
||||
|
|
|
|||
|
|
@ -619,6 +619,12 @@ private:
|
|||
void ContinueParserAsync(ScriptLoadRequest* aParserBlockingRequest);
|
||||
|
||||
|
||||
/**
|
||||
* Given a script element, get the referrer policy should be applied to load
|
||||
* requests.
|
||||
*/
|
||||
mozilla::net::ReferrerPolicy GetReferrerPolicy(nsIScriptElement* aElement);
|
||||
|
||||
/**
|
||||
* Helper function to check the content policy for a given request.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include "nsContentCreatorFunctions.h"
|
||||
#include "nsIDOMHTMLScriptElement.h"
|
||||
#include "mozilla/CORSMode.h"
|
||||
#include "mozilla/net/ReferrerPolicy.h"
|
||||
|
||||
#define NS_ISCRIPTELEMENT_IID \
|
||||
{ 0xe60fca9b, 0x1b96, 0x4e4e, \
|
||||
|
|
@ -263,6 +264,14 @@ public:
|
|||
return mozilla::CORS_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get referrer policy of the script element
|
||||
*/
|
||||
virtual mozilla::net::ReferrerPolicy GetReferrerPolicy()
|
||||
{
|
||||
return mozilla::net::RP_Unset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire an error event
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ interface HTMLScriptElement : HTMLElement {
|
|||
[CEReactions, SetterThrows]
|
||||
attribute DOMString? crossOrigin;
|
||||
[CEReactions, SetterThrows]
|
||||
attribute DOMString referrerPolicy;
|
||||
[CEReactions, SetterThrows]
|
||||
attribute DOMString text;
|
||||
[CEReactions, SetterThrows, Pure]
|
||||
attribute DOMString nonce;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue