2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-02-07 12:08:58 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2014-03-17 10:56:54 +04:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2013-02-07 12:08:58 +04:00
|
|
|
#include "mozilla/dom/HTMLMetaElement.h"
|
2013-02-07 12:08:58 +04:00
|
|
|
#include "mozilla/dom/HTMLMetaElementBinding.h"
|
2015-11-15 06:29:05 +03:00
|
|
|
#include "mozilla/dom/nsCSPService.h"
|
2013-02-07 12:08:58 +04:00
|
|
|
#include "nsContentUtils.h"
|
2014-03-17 10:56:54 +04:00
|
|
|
#include "nsStyleConsts.h"
|
2015-11-15 06:29:05 +03:00
|
|
|
#include "nsIContentSecurityPolicy.h"
|
2013-02-07 12:08:58 +04:00
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Meta)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
HTMLMetaElement::HTMLMetaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-02-07 12:08:58 +04:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLMetaElement::~HTMLMetaElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(HTMLMetaElement, nsGenericHTMLElement,
|
|
|
|
nsIDOMHTMLMetaElement)
|
2013-02-07 12:08:58 +04:00
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLMetaElement)
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLMetaElement, Content, content)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLMetaElement, HttpEquiv, httpEquiv)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLMetaElement, Name, name)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLMetaElement, Scheme, scheme)
|
|
|
|
|
|
|
|
void
|
2015-02-13 04:27:39 +03:00
|
|
|
HTMLMetaElement::GetItemValueText(DOMString& aValue)
|
2013-02-07 12:08:58 +04:00
|
|
|
{
|
|
|
|
GetContent(aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLMetaElement::SetItemValueText(const nsAString& aValue)
|
|
|
|
{
|
|
|
|
SetContent(aValue);
|
|
|
|
}
|
|
|
|
|
2015-06-20 03:42:49 +03:00
|
|
|
nsresult
|
|
|
|
HTMLMetaElement::SetMetaReferrer(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
if (!aDocument ||
|
|
|
|
!AttrValueIs(kNameSpaceID_None, nsGkAtoms::name, nsGkAtoms::referrer, eIgnoreCase)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsAutoString content;
|
|
|
|
nsresult rv = GetContent(content);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
Element* headElt = aDocument->GetHeadElement();
|
|
|
|
if (headElt && nsContentUtils::ContentIsDescendantOf(this, headElt)) {
|
|
|
|
content = nsContentUtils::TrimWhitespace<nsContentUtils::IsHTMLWhitespace>(content);
|
|
|
|
aDocument->SetHeaderData(nsGkAtoms::referrer, content);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-02-07 12:08:58 +04:00
|
|
|
|
2014-07-12 15:28:48 +04:00
|
|
|
nsresult
|
|
|
|
HTMLMetaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
|
|
|
{
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
2015-06-20 03:42:49 +03:00
|
|
|
nsIDocument *document = GetUncomposedDoc();
|
2014-07-12 15:28:48 +04:00
|
|
|
if (aName == nsGkAtoms::content) {
|
2015-08-24 22:34:00 +03:00
|
|
|
if (document && AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
|
|
|
|
nsGkAtoms::viewport, eIgnoreCase)) {
|
|
|
|
nsAutoString content;
|
|
|
|
nsresult rv = GetContent(content);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsContentUtils::ProcessViewportInfo(document, content);
|
|
|
|
}
|
2014-07-12 15:28:48 +04:00
|
|
|
CreateAndDispatchEvent(document, NS_LITERAL_STRING("DOMMetaChanged"));
|
|
|
|
}
|
2015-06-20 03:42:49 +03:00
|
|
|
// Update referrer policy when it got changed from JS
|
|
|
|
nsresult rv = SetMetaReferrer(document);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-07-12 15:28:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
|
|
|
|
aNotify);
|
|
|
|
}
|
|
|
|
|
2013-02-07 12:08:58 +04:00
|
|
|
nsresult
|
|
|
|
HTMLMetaElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (aDocument &&
|
|
|
|
AttrValueIs(kNameSpaceID_None, nsGkAtoms::name, nsGkAtoms::viewport, eIgnoreCase)) {
|
|
|
|
nsAutoString content;
|
|
|
|
rv = GetContent(content);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-11-18 16:46:29 +03:00
|
|
|
nsContentUtils::ProcessViewportInfo(aDocument, content);
|
|
|
|
}
|
2015-11-15 06:29:05 +03:00
|
|
|
|
|
|
|
if (CSPService::sCSPEnabled && aDocument &&
|
|
|
|
AttrValueIs(kNameSpaceID_None, nsGkAtoms::httpEquiv, nsGkAtoms::headerCSP, eIgnoreCase)) {
|
|
|
|
|
|
|
|
// only accept <meta http-equiv="Content-Security-Policy" content=""> if it appears
|
|
|
|
// in the <head> element.
|
|
|
|
Element* headElt = aDocument->GetHeadElement();
|
|
|
|
if (headElt && nsContentUtils::ContentIsDescendantOf(this, headElt)) {
|
|
|
|
|
|
|
|
nsAutoString content;
|
|
|
|
rv = GetContent(content);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
content = nsContentUtils::TrimWhitespace<nsContentUtils::IsHTMLWhitespace>(content);
|
|
|
|
|
|
|
|
nsIPrincipal* principal = aDocument->NodePrincipal();
|
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> csp;
|
2016-01-15 00:21:31 +03:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(aDocument);
|
|
|
|
rv = principal->EnsureCSP(domDoc, getter_AddRefs(csp));
|
2015-11-15 06:29:05 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Multiple CSPs (delivered through either header of meta tag) need to be
|
|
|
|
// joined together, see:
|
|
|
|
// https://w3c.github.io/webappsec/specs/content-security-policy/#delivery-html-meta-element
|
|
|
|
rv = csp->AppendPolicy(content,
|
|
|
|
false, // csp via meta tag can not be report only
|
|
|
|
true); // delivered through the meta tag
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
aDocument->ApplySettingsFromCSP(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-20 03:42:49 +03:00
|
|
|
// Referrer Policy spec requires a <meta name="referrer" tag to be in the
|
|
|
|
// <head> element.
|
|
|
|
rv = SetMetaReferrer(aDocument);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
2013-02-07 12:08:58 +04:00
|
|
|
}
|
|
|
|
CreateAndDispatchEvent(aDocument, NS_LITERAL_STRING("DOMMetaAdded"));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLMetaElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
|
|
|
{
|
2014-10-02 23:07:24 +04:00
|
|
|
nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
|
2013-02-07 12:08:58 +04:00
|
|
|
CreateAndDispatchEvent(oldDoc, NS_LITERAL_STRING("DOMMetaRemoved"));
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLMetaElement::CreateAndDispatchEvent(nsIDocument* aDoc,
|
|
|
|
const nsAString& aEventName)
|
|
|
|
{
|
|
|
|
if (!aDoc)
|
|
|
|
return;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AsyncEventDispatcher> asyncDispatcher =
|
2014-03-17 10:56:54 +04:00
|
|
|
new AsyncEventDispatcher(this, aEventName, true, true);
|
2015-07-31 20:08:40 +03:00
|
|
|
asyncDispatcher->RunDOMEventWhenSafe();
|
2013-02-07 12:08:58 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 12:08:58 +04:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
HTMLMetaElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-07 12:08:58 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return HTMLMetaElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-07 12:08:58 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 12:08:58 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|