Files
palemoon27/dom/html/HTMLMetaElement.cpp
T
roytam1 29e855d998 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1176782 part 2 - [css-align] Implement the 'justify-self' property in the style system. r=SimonSapin (273ee9a0a1)
- Bug 1194480: Only update overflow region (& trigger DLBI) for changes to CSS 'box-shadow' or 'text-shadow', instead of triggering a reflow. r=heycam (0af1ee160b)
- Bug 1137889 part 1 - Update predefined counter style name table to match the spec. r=jfkthame (ff678af4a9)
- Bug 1137889 part 2 - Move around definitions in counterstyles.css to match the order in spec for clarity. r=jfkthame (c1a95688d9)
- Bug 1187649 - Free constructed widget path in nsLookAndFeel on GTK. r=karlt (fe80b73514)
- Bug 1165513 - Translate GTK3 widgets with snapped pixel coordinates into identity space. r=jrmuizel (563c252255)
- Bug 1113206 patch 2: Disable use of Cocoa and Gtk native-theme dropdown rendering that doesn't play well with vertical writing mode. r=roc (3b8134aced)
- Bug 1187203 - Implement GtkInfoBar appearance style on GTK3. r=karlt (0500e6297a)
- Bug 1168527 - Replay clips into the system cairo on GTK3. r=lsalzman (9f739f58cc)
- Bug 1168527 - Variable was re-declared causing a bustage on gcc 5. r=lsalzman (4e7f5453f2)
- Bug 1167239 - Make GTK button activity require hover. r=karlt (34cb428ed3)
- Bug 1177024 - Fix clang warnings-as-errors in GTK3 build. r=karlt (d45119470b)
- Bug 1179780 - Render opaque scrollbar troughs in the root viewport on GTK3. r=karlt (8f04f119b0)
- Bug 1210560 - Part 1: Add an API specifically intended for users that just Push and Pop-Mask/Pop-Paint. r=jrmuizel (e08db740f9)
- Bug 991249 - Ensure that we can check for OOMs when we run out of ballast space. r=jandem (0742c71158)
- Bug 1219419 - Keep DefaultTracer simple for now; r=fitzgen (bb621675d5)
- Bug 1220310 - Generalize GC container trace function dispatch as GCPolicy; r=sfink (314b3aa009)
- Bug 1187782 (part 10) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (1def283d70)
- Bug 1187782 (part 11) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (e9a71fae11)
- Bug 1187782 (part 12) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (44afb0d6f6)
- Bug 1187782 (part 13) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (4e253c8d18)
- Bug 1187782 (part 14) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (cf8ecf213a)
- Bug 859042 - Show onload and DOMContentLoaded markers in the timeline, r=smaug, jsantell (8ff8c43a36)
- Bug 1187801 part 2 - Put clearing fullscreen state on element into an independent function. r=smaug (c8a135fbc9)
- Bug 1187801 part 3 - Add iframe fullscreen flag and stop auto-rollback when this flag presents. r=smaug (f0c928090a)
- Bug 1187801 part 4 - Add test for iframe fullscreen flag. r=smaug (851d97d772)
- Bug 1188028 - Use channel->ascynOpen2 in dom/security/nsCSPContext.cpp (r=sicking) (54c9e0017e)
- Bug 1218315 - Replace NS_LITERAL_STRING(...).get() with MOZ_UTF16(...) on dom. r=nfroyd (4439f10159)
- Bug 1188028 - Queue up CSP console messages till windowID is available (r=sicking) (b060ba7ea3)
- Bug 1085293 - File renames for WebIDL Iterable Implementation; r=bz (5d61d3ae34)
- Bug 1085293 - WebIDL Iterable Implementation and Tests; r=bz (720efc275f)
- Bug 1215559. Create separate iterator native types for one-type and two-type iterators, so we don't force the one-type case to implement GetKeyAtIndex. r=qdot (649284e6fc)
- Bug 1174915 - Allow changing meta referrer policy on the fly, tests (r=sstamm) (02b8482802)
- Bug 1211624. document.all should be iterable, and so should be various other things that have an anonymous indexed getter. r=qdot (6620287943)
- Bug 1052139 - Reorder CGCreateInterfaceObjectsMethod a bit to correspond to the ordering of generated code. r=bz (cc16b9c3b2)
- Bug 1052139 - Perform proper failure handling in interfaces' CreateInterfaceObjects method, after dom::CreateInterfaceObjects has been called and possibly created the interface's constructor and prototype. r=bz (6690e2a9de)
- Bug 1052139 - Make more parts of the global object's prototype chain immutable, when we flip that switch. r=bz (6f1878822b)
- Bug 1210570 - Ensure that ToPrimitive(location) is not spoofable. r=bz. (48ac711b2e)
- Bug 1220900 - Remove unused JSBindingFinalized, r=peterv (7f6cbd6483)
- missing bit of Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T> (48a0a7b75a)
- Bug 1052139 - Make the [[Prototype]] of various (but not all) objects on the window object's [[Prototype]] chain immutable. BUT, also disable the code that actually respects immutable-prototype handling -- it'll be a one-liner to revert this when we're ready to do so. Making the rest of the chain immutable will happen in separate patches. r=bz (091e4f4ad0)
- Bug 1174915 - Allow changing meta referrer policy on the fly (r=baku,sstamm) (e8b6f30f88)
- Bug 1211607, part 1 - Document JSAPI functions that call object internal methods: JS_GetPrototype through JS_PreventExtensions. r=jandem. (4ebe70f5ea)
- Bug 1211607, part 2 - JS_GetOwnPropertyDescriptor and friends. r=jandem. (73de8f3e51)
- Bug 1211607, part 3 - JS_DefineProperty and friends. r=jandem. (29da979627)
- Bug 1211607, part 4 - JS_HasProperty and friends. r=jandem. (130aa265c8)
- Bug 1211607, part 5 - JS_GetProperty and friends. r=jandem. (a19f9d5d1c)
- Bug 1211607, part 6 - JS_SetProperty and friends. r=jandem. (75de9a5774)
- Bug 1211607, part 7 - JS_DeleteProperty and friends. r=jandem. (fe88179d48)
- Bug 1211607, part 8 - JS_Enumerate. r=jandem. (332a0cf1a9)
- Bug 1211607, part 9 - JS::Call, JS::Construct, and friends. r=jandem. (a68585dfdb)
- Bug 663570 - MetaCSP Part 1: CSP parser changes (r=sicking) (b6c5e80c44)
- Bug 1220602 - Make the documentation for nsIPrincipal.domain useful. r=bholley IGNORE IDL (afa28df415)
- Bug 1218039 - Add a nice interface for both C++ and JS to access the principal kind. r=gabor (4449599c4b)
- Bug 663570 - MetaCSP Part 2: Principal changes (r=bz) (84fe26e407)
- Bug 1201783 - Throw range error for too long array spread before updating length. r=Waldo, a=abillings (633b55a5f8)
- Bug 1194052 - Update Clone() functionality of LoadInfo (r=sicking) (f3bb041849)
- Bug 663570 - MetaCSP Part 3: Upgrade insecure requests changes (r=bz) (0c8e3f49e5)
- fix misspatch of 1194052 (743dd0269b)
- Bug 663570 - MetaCSP Part 4: Speculative parser changes (r=bz) (c94c58b160)
- Bug 663570 - MetaCSP Part 5: HTMLMetaElement changes (r=bz) (f4b8bd8af1)
- Bug 1215140 P3 Flush pending console reports on http channels. r=bz (32d2767b68)
- Bug 1188545 - respondWith promise should extend the service worker's lifetime. r=nsm (5a8e02a500)
- Bug 1179401 - Call stopImmediatePropagation() on the Event object in respondWith(); r=jdm (0e33f8d8fb)
- Bug 1188545 - ServiceWorkerRegistrationInfo::Clear() should terminated workers. r=nsm (a35c5df80a)
- Bug 1188545 - Cosmetic changes regarding workerPrivate properties shared between shared workers and service workers. r=nsm (516c70e34e)
- Bug 1188545 - Terminate service workers that have been idle for some time. r=nsm (d7582cb1bb)
- Bug 1182113 - Test XSLT serviceworker load. r=bkelly (797ca864a6)
- Bug 1188545 - Cancel network interceptions when the service worker is being terminated with unresolved respondWith promises. r=nsm (6df3a8eda6)
- Bug 1221308 Fix some service worker related warnings. r=baku (dd6f62379e)
- Bug 1208559 - Do a CSP Check in ServiceWorkerManager::Register (r=ckerschb) (5cc2df68ab)
- Bug 1221365 - Move "Is origin potentially trustworthy?" logic outside ServiceWorkerManager.cpp. r=ckerschb,bkelly (91c6f8e2b5)
- Bug 1208559 - Hook up ServicerWorkers with CSP (r=sicking,bkelly,dveditz) (6a6f92e8c7)
- Bug 1185558 - Send a "Service-Worker: script" header when downloading service worker scripts; r=bkelly (22162634a4)
- Bug 1207727 - Rework updating service workers according to the latest spec. r=bkelly (475c185ee4)
2022-11-17 11:29:02 +08:00

199 lines
6.3 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/dom/HTMLMetaElement.h"
#include "mozilla/dom/HTMLMetaElementBinding.h"
#include "mozilla/dom/nsCSPService.h"
#include "nsContentUtils.h"
#include "nsStyleConsts.h"
#include "nsIContentSecurityPolicy.h"
NS_IMPL_NS_NEW_HTML_ELEMENT(Meta)
namespace mozilla {
namespace dom {
HTMLMetaElement::HTMLMetaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
: nsGenericHTMLElement(aNodeInfo)
{
}
HTMLMetaElement::~HTMLMetaElement()
{
}
NS_IMPL_ISUPPORTS_INHERITED(HTMLMetaElement, nsGenericHTMLElement,
nsIDOMHTMLMetaElement)
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
HTMLMetaElement::GetItemValueText(DOMString& aValue)
{
GetContent(aValue);
}
void
HTMLMetaElement::SetItemValueText(const nsAString& aValue)
{
SetContent(aValue);
}
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;
}
nsresult
HTMLMetaElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue, bool aNotify)
{
if (aNameSpaceID == kNameSpaceID_None) {
nsIDocument *document = GetUncomposedDoc();
if (aName == nsGkAtoms::content) {
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);
}
CreateAndDispatchEvent(document, NS_LITERAL_STRING("DOMMetaChanged"));
}
// Update referrer policy when it got changed from JS
nsresult rv = SetMetaReferrer(document);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
aNotify);
}
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);
nsContentUtils::ProcessViewportInfo(aDocument, content);
}
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;
rv = principal->GetCsp(getter_AddRefs(csp));
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
if (!csp) {
csp = do_CreateInstance("@mozilla.org/cspcontext;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
// Store the request context so CSP can resolve 'self'
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(aDocument);
rv = csp->SetRequestContext(domDoc, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
// set the new CSP
rv = principal->SetCsp(csp);
NS_ENSURE_SUCCESS(rv, rv);
}
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);
}
}
// 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;
}
CreateAndDispatchEvent(aDocument, NS_LITERAL_STRING("DOMMetaAdded"));
return rv;
}
void
HTMLMetaElement::UnbindFromTree(bool aDeep, bool aNullParent)
{
nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
CreateAndDispatchEvent(oldDoc, NS_LITERAL_STRING("DOMMetaRemoved"));
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
}
void
HTMLMetaElement::CreateAndDispatchEvent(nsIDocument* aDoc,
const nsAString& aEventName)
{
if (!aDoc)
return;
RefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(this, aEventName, true, true);
asyncDispatcher->PostDOMEvent();
}
JSObject*
HTMLMetaElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return HTMLMetaElementBinding::Wrap(aCx, this, aGivenProto);
}
} // namespace dom
} // namespace mozilla