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: */
|
2012-05-21 15:12:37 +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/. */
|
2006-04-20 07:36:57 +04:00
|
|
|
|
2013-08-30 21:16:32 +04:00
|
|
|
#include "mozilla/dom/DOMParser.h"
|
2013-08-22 10:30:55 +04:00
|
|
|
|
2006-04-20 07:36:57 +04:00
|
|
|
#include "nsNetUtil.h"
|
2018-04-21 06:01:25 +03:00
|
|
|
#include "nsDOMString.h"
|
2018-04-21 06:01:25 +03:00
|
|
|
#include "MainThreadUtils.h"
|
2015-09-29 07:31:56 +03:00
|
|
|
#include "nsIStreamListener.h"
|
2006-04-20 07:39:49 +04:00
|
|
|
#include "nsStringStream.h"
|
2016-06-08 04:57:45 +03:00
|
|
|
#include "nsIScriptError.h"
|
2006-04-20 07:36:57 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2006-04-20 07:38:00 +04:00
|
|
|
#include "nsCRT.h"
|
2006-04-20 07:39:03 +04:00
|
|
|
#include "nsStreamUtils.h"
|
2006-04-26 13:19:48 +04:00
|
|
|
#include "nsContentUtils.h"
|
2006-06-13 07:07:47 +04:00
|
|
|
#include "nsDOMJSUtils.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2007-12-12 11:33:32 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2014-07-10 10:56:37 +04:00
|
|
|
#include "mozilla/LoadInfo.h"
|
2018-07-17 22:37:48 +03:00
|
|
|
#include "mozilla/NullPrincipal.h"
|
2012-12-26 03:06:15 +04:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2014-08-21 04:45:04 +04:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2010-10-05 05:25:44 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-12-04 05:26:16 +04:00
|
|
|
using namespace mozilla::dom;
|
2006-04-20 07:39:03 +04:00
|
|
|
|
2018-04-21 06:04:45 +03:00
|
|
|
DOMParser::DOMParser(nsIGlobalObject* aOwner, nsIPrincipal* aDocPrincipal,
|
|
|
|
nsIURI* aDocumentURI, nsIURI* aBaseURI)
|
2018-04-21 06:04:45 +03:00
|
|
|
: mOwner(aOwner),
|
|
|
|
mPrincipal(aDocPrincipal),
|
2018-04-21 06:04:45 +03:00
|
|
|
mDocumentURI(aDocumentURI),
|
|
|
|
mBaseURI(aBaseURI),
|
2019-07-08 13:47:05 +03:00
|
|
|
mForceEnableXULXBL(false),
|
|
|
|
mForceEnableDTD(false) {
|
2018-04-21 06:04:45 +03:00
|
|
|
MOZ_ASSERT(aDocPrincipal);
|
2018-04-21 06:04:45 +03:00
|
|
|
MOZ_ASSERT(aDocumentURI);
|
2018-04-21 06:04:45 +03:00
|
|
|
}
|
|
|
|
|
2013-08-30 21:16:32 +04:00
|
|
|
DOMParser::~DOMParser() {}
|
2006-04-20 07:36:57 +04:00
|
|
|
|
2013-08-30 21:16:32 +04:00
|
|
|
// QueryInterface implementation for DOMParser
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMParser)
|
2012-12-04 05:26:16 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2018-04-21 06:04:46 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2006-04-20 07:37:17 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMParser, mOwner)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2006-04-20 07:37:17 +04:00
|
|
|
|
2013-08-30 21:16:32 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMParser)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMParser)
|
2012-12-04 05:26:16 +04:00
|
|
|
|
2013-05-06 23:28:13 +04:00
|
|
|
static const char* StringFromSupportedType(SupportedType aType) {
|
|
|
|
return SupportedTypeValues::strings[static_cast<int>(aType)].value;
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
already_AddRefed<Document> DOMParser::ParseFromString(const nsAString& aStr,
|
|
|
|
SupportedType aType,
|
|
|
|
ErrorResult& aRv) {
|
2018-04-21 06:01:25 +03:00
|
|
|
if (aType == SupportedType::Text_html) {
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> document = SetUpDocument(DocumentFlavorHTML, aRv);
|
2018-04-21 06:01:25 +03:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
2018-04-21 06:01:25 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-01-20 16:03:49 +04:00
|
|
|
|
2017-02-03 00:54:34 +03:00
|
|
|
// Keep the XULXBL state in sync with the XML case.
|
2018-04-21 06:01:24 +03:00
|
|
|
if (mForceEnableXULXBL) {
|
2012-01-20 16:03:49 +04:00
|
|
|
document->ForceEnableXULXBL();
|
|
|
|
}
|
|
|
|
|
2019-07-08 13:47:05 +03:00
|
|
|
if (mForceEnableDTD) {
|
|
|
|
document->ForceSkipDTDSecurityChecks();
|
|
|
|
}
|
|
|
|
|
2018-04-21 06:01:25 +03:00
|
|
|
nsresult rv = nsContentUtils::ParseDocumentHTML(aStr, document, false);
|
2018-04-21 06:01:25 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-07-09 22:24:58 +04:00
|
|
|
|
2018-04-21 06:01:25 +03:00
|
|
|
return document.forget();
|
2012-01-20 16:03:49 +04:00
|
|
|
}
|
|
|
|
|
2014-01-07 19:18:30 +04:00
|
|
|
nsAutoCString utf8str;
|
|
|
|
// Convert from UTF16 to UTF8 using fallible allocations
|
2018-04-21 06:01:25 +03:00
|
|
|
if (!AppendUTF16toUTF8(aStr, utf8str, mozilla::fallible)) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return nullptr;
|
2014-01-07 19:18:30 +04:00
|
|
|
}
|
2006-04-20 07:36:57 +04:00
|
|
|
|
2006-04-20 07:39:49 +04:00
|
|
|
// The new stream holds a reference to the buffer
|
|
|
|
nsCOMPtr<nsIInputStream> stream;
|
2019-02-25 22:11:20 +03:00
|
|
|
nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream), utf8str,
|
|
|
|
NS_ASSIGNMENT_DEPEND);
|
2018-04-21 06:01:25 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2006-04-20 07:36:57 +04:00
|
|
|
|
2018-04-21 06:01:25 +03:00
|
|
|
return ParseFromStream(stream, NS_LITERAL_STRING("UTF-8"), utf8str.Length(),
|
|
|
|
aType, aRv);
|
2006-04-20 07:39:00 +04:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
already_AddRefed<Document> DOMParser::ParseFromBuffer(const Uint8Array& aBuf,
|
|
|
|
SupportedType aType,
|
|
|
|
ErrorResult& aRv) {
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
aBuf.ComputeLengthAndData();
|
2018-04-21 06:01:25 +03:00
|
|
|
return ParseFromBuffer(MakeSpan(aBuf.Data(), aBuf.Length()), aType, aRv);
|
2012-12-04 05:26:16 +04:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
already_AddRefed<Document> DOMParser::ParseFromBuffer(Span<const uint8_t> aBuf,
|
|
|
|
SupportedType aType,
|
|
|
|
ErrorResult& aRv) {
|
2006-04-20 07:39:49 +04:00
|
|
|
// The new stream holds a reference to the buffer
|
2006-04-20 07:39:00 +04:00
|
|
|
nsCOMPtr<nsIInputStream> stream;
|
2006-04-20 07:39:49 +04:00
|
|
|
nsresult rv = NS_NewByteInputStream(
|
2019-02-25 22:11:20 +03:00
|
|
|
getter_AddRefs(stream),
|
|
|
|
MakeSpan(reinterpret_cast<const char*>(aBuf.Elements()), aBuf.Length()),
|
|
|
|
NS_ASSIGNMENT_DEPEND);
|
2018-04-21 06:01:25 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2006-04-20 07:39:00 +04:00
|
|
|
|
2018-04-21 06:01:25 +03:00
|
|
|
return ParseFromStream(stream, VoidString(), aBuf.Length(), aType, aRv);
|
2006-04-20 07:36:57 +04:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
already_AddRefed<Document> DOMParser::ParseFromStream(nsIInputStream* aStream,
|
|
|
|
const nsAString& aCharset,
|
|
|
|
int32_t aContentLength,
|
|
|
|
SupportedType aType,
|
|
|
|
ErrorResult& aRv) {
|
2018-04-21 06:01:25 +03:00
|
|
|
bool svg = (aType == SupportedType::Image_svg_xml);
|
2011-10-13 14:50:05 +04:00
|
|
|
|
2006-04-20 07:36:57 +04:00
|
|
|
// For now, we can only create XML documents.
|
2011-10-13 14:50:05 +04:00
|
|
|
// XXXsmaug Should we create an HTMLDocument (in XHTML mode)
|
|
|
|
// for "application/xhtml+xml"?
|
2018-04-21 06:01:25 +03:00
|
|
|
if (aType != SupportedType::Text_xml &&
|
|
|
|
aType != SupportedType::Application_xml &&
|
|
|
|
aType != SupportedType::Application_xhtml_xml && !svg) {
|
|
|
|
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2006-09-09 08:54:03 +04:00
|
|
|
|
|
|
|
// Put the nsCOMPtr out here so we hold a ref to the stream as needed
|
2017-10-19 12:39:30 +03:00
|
|
|
nsCOMPtr<nsIInputStream> stream = aStream;
|
2006-04-20 07:39:03 +04:00
|
|
|
if (!NS_InputStreamIsBuffered(stream)) {
|
2017-10-19 12:39:30 +03:00
|
|
|
nsCOMPtr<nsIInputStream> bufferedStream;
|
2018-04-21 06:01:25 +03:00
|
|
|
nsresult rv = NS_NewBufferedInputStream(getter_AddRefs(bufferedStream),
|
2017-10-19 12:39:30 +03:00
|
|
|
stream.forget(), 4096);
|
2018-04-21 06:01:25 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2006-06-16 00:30:44 +04:00
|
|
|
|
2006-04-20 07:39:03 +04:00
|
|
|
stream = bufferedStream;
|
|
|
|
}
|
2007-10-01 14:02:32 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> document =
|
2018-04-21 06:01:25 +03:00
|
|
|
SetUpDocument(svg ? DocumentFlavorSVG : DocumentFlavorLegacyGuess, aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2006-04-20 07:36:57 +04:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
// Create a fake channel
|
2006-04-20 07:39:49 +04:00
|
|
|
nsCOMPtr<nsIChannel> parserChannel;
|
2014-10-16 22:14:42 +04:00
|
|
|
NS_NewInputStreamChannel(getter_AddRefs(parserChannel), mDocumentURI,
|
|
|
|
nullptr, // aStream
|
|
|
|
mPrincipal, nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL,
|
|
|
|
nsIContentPolicy::TYPE_OTHER,
|
2018-04-21 06:01:25 +03:00
|
|
|
nsDependentCString(StringFromSupportedType(aType)));
|
|
|
|
if (NS_WARN_IF(!parserChannel)) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2006-04-20 07:36:57 +04:00
|
|
|
|
2018-04-21 06:01:25 +03:00
|
|
|
if (!DOMStringIsNull(aCharset)) {
|
|
|
|
parserChannel->SetContentCharset(NS_ConvertUTF16toUTF8(aCharset));
|
2006-04-20 07:39:02 +04:00
|
|
|
}
|
|
|
|
|
2006-04-20 07:36:57 +04:00
|
|
|
// Tell the document to start loading
|
|
|
|
nsCOMPtr<nsIStreamListener> listener;
|
2006-04-20 07:37:35 +04:00
|
|
|
|
2017-02-03 00:54:34 +03:00
|
|
|
// Keep the XULXBL state in sync with the HTML case
|
2018-04-21 06:01:24 +03:00
|
|
|
if (mForceEnableXULXBL) {
|
2010-08-20 03:12:46 +04:00
|
|
|
document->ForceEnableXULXBL();
|
|
|
|
}
|
|
|
|
|
2019-07-08 13:47:05 +03:00
|
|
|
if (mForceEnableDTD) {
|
|
|
|
document->ForceSkipDTDSecurityChecks();
|
|
|
|
}
|
|
|
|
|
2018-04-21 06:01:25 +03:00
|
|
|
// Have to pass false for reset here, else the reset will remove
|
|
|
|
// our event listener. Should that listener addition move to later
|
|
|
|
// than this call?
|
2018-04-21 06:01:25 +03:00
|
|
|
nsresult rv =
|
|
|
|
document->StartDocumentLoad(kLoadAsData, parserChannel, nullptr, nullptr,
|
|
|
|
getter_AddRefs(listener), false);
|
2006-04-20 07:36:57 +04:00
|
|
|
|
2006-04-20 07:37:35 +04:00
|
|
|
if (NS_FAILED(rv) || !listener) {
|
2018-04-21 06:01:25 +03:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2006-04-20 07:37:35 +04:00
|
|
|
}
|
2006-04-20 07:36:57 +04:00
|
|
|
|
|
|
|
// Now start pumping data to the listener
|
|
|
|
nsresult status;
|
|
|
|
|
2019-02-28 02:41:04 +03:00
|
|
|
rv = listener->OnStartRequest(parserChannel);
|
2006-04-20 07:39:49 +04:00
|
|
|
if (NS_FAILED(rv)) parserChannel->Cancel(rv);
|
|
|
|
parserChannel->GetStatus(&status);
|
2006-04-20 07:36:57 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(status)) {
|
2019-02-28 02:42:27 +03:00
|
|
|
rv = listener->OnDataAvailable(parserChannel, stream, 0, aContentLength);
|
2006-04-20 07:39:49 +04:00
|
|
|
if (NS_FAILED(rv)) parserChannel->Cancel(rv);
|
|
|
|
parserChannel->GetStatus(&status);
|
2006-04-20 07:36:57 +04:00
|
|
|
}
|
|
|
|
|
2019-02-28 02:41:31 +03:00
|
|
|
rv = listener->OnStopRequest(parserChannel, status);
|
2006-04-20 07:39:49 +04:00
|
|
|
// Failure returned from OnStopRequest does not affect the final status of
|
|
|
|
// the channel, so we do not need to call Cancel(rv) as we do above.
|
2006-04-20 07:38:20 +04:00
|
|
|
|
2006-04-20 07:37:35 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2018-04-21 06:01:25 +03:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2006-04-20 07:37:35 +04:00
|
|
|
}
|
|
|
|
|
2018-04-21 06:01:25 +03:00
|
|
|
return document.forget();
|
2006-04-20 07:36:57 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/*static */
|
|
|
|
already_AddRefed<DOMParser> DOMParser::Constructor(const GlobalObject& aOwner,
|
|
|
|
ErrorResult& rv) {
|
2018-04-21 06:01:25 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
nsCOMPtr<nsIPrincipal> docPrincipal = aOwner.GetSubjectPrincipal();
|
2018-04-21 06:04:45 +03:00
|
|
|
nsCOMPtr<nsIURI> documentURI;
|
2018-04-21 06:04:45 +03:00
|
|
|
nsIURI* baseURI = nullptr;
|
2018-04-21 06:01:25 +03:00
|
|
|
if (nsContentUtils::IsSystemPrincipal(docPrincipal)) {
|
|
|
|
docPrincipal = NullPrincipal::CreateWithoutOriginAttributes();
|
2018-04-21 06:04:45 +03:00
|
|
|
docPrincipal->GetURI(getter_AddRefs(documentURI));
|
2018-04-21 06:01:25 +03:00
|
|
|
} else {
|
2018-04-21 06:04:45 +03:00
|
|
|
// Grab document and base URIs off the window our constructor was
|
|
|
|
// called on. Error out if anything untoward happens.
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window =
|
|
|
|
do_QueryInterface(aOwner.GetAsSupports());
|
2012-12-26 15:00:05 +04:00
|
|
|
if (!window) {
|
2018-04-21 06:04:45 +03:00
|
|
|
rv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2007-12-12 11:33:32 +03:00
|
|
|
}
|
|
|
|
|
2012-12-26 15:00:05 +04:00
|
|
|
baseURI = window->GetDocBaseURI();
|
|
|
|
documentURI = window->GetDocumentURI();
|
2006-09-09 08:54:03 +04:00
|
|
|
}
|
|
|
|
|
2018-04-21 06:04:45 +03:00
|
|
|
if (!documentURI) {
|
|
|
|
rv.Throw(NS_ERROR_UNEXPECTED);
|
2018-04-21 06:04:45 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2018-04-21 06:04:45 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aOwner.GetAsSupports());
|
2018-04-21 06:04:46 +03:00
|
|
|
MOZ_ASSERT(global);
|
2018-04-21 06:04:45 +03:00
|
|
|
RefPtr<DOMParser> domParser =
|
|
|
|
new DOMParser(global, docPrincipal, documentURI, baseURI);
|
2018-04-21 06:04:45 +03:00
|
|
|
return domParser.forget();
|
2006-09-09 08:54:03 +04:00
|
|
|
}
|
|
|
|
|
2018-04-21 06:04:46 +03:00
|
|
|
// static
|
|
|
|
already_AddRefed<DOMParser> DOMParser::CreateWithoutGlobal(ErrorResult& aRv) {
|
|
|
|
nsCOMPtr<nsIPrincipal> docPrincipal =
|
|
|
|
NullPrincipal::CreateWithoutOriginAttributes();
|
|
|
|
nsCOMPtr<nsIURI> documentURI;
|
|
|
|
docPrincipal->GetURI(getter_AddRefs(documentURI));
|
|
|
|
|
|
|
|
if (!documentURI) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<DOMParser> domParser =
|
|
|
|
new DOMParser(nullptr, docPrincipal, documentURI, nullptr);
|
|
|
|
return domParser.forget();
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
already_AddRefed<Document> DOMParser::SetUpDocument(DocumentFlavor aFlavor,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
// We should really just use mOwner here, but Document gets confused
|
2014-08-21 04:45:04 +04:00
|
|
|
// if we pass it a scriptHandlingObject that doesn't QI to
|
|
|
|
// nsIScriptGlobalObject, and test_isequalnode.js (an xpcshell test without
|
2019-01-02 16:05:23 +03:00
|
|
|
// a window global) breaks. The correct solution is just to wean Document off
|
|
|
|
// of nsIScriptGlobalObject, but that's a yak to shave another day.
|
2012-01-20 16:03:49 +04:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> scriptHandlingObject =
|
2018-04-21 06:04:45 +03:00
|
|
|
do_QueryInterface(mOwner);
|
2012-01-20 16:03:49 +04:00
|
|
|
|
Bug 1389300 - Inherit style backend into NS_NewDOMDocument. r=smaug,r=heycam
Our current machinery for enabling stylo requires a docshell - if there isn't
one, we default to the Gecko style system.
When getComputedStyle operates on an element without a presshell, it uses the
caller's presshell instead. If the element has previously been styled with
one style system (but no longer has a presshell), and the caller uses a
different style backend, using the caller's style system can cause crashes when
we pull bits of cached data off the DOM (like cached style attributes).
So we want to throw when window.getComputedStyle(element) is called for a
(window, element) pair with different style backends (which is what the next
patch in this bug does).
However, that causes a few failures where stylo-backed documents try to do
getComputedStyle on an XHR document (which, without a docshell, will use the
gecko style system).
So this patch does some work to propagate the creator's style backend into
various docshell-less documents. This should allow both chrome (which uses gecko)
and content (which uses stylo) to use getComputedStyle on the response document
for XHRs they create.
Note that the second patch in this bug will make
chromeWin.getComputedStyle(contentObj) throw. If we discover code that does
that, we can just make it invoke the content's getComputedStyle method over Xrays.
MozReview-Commit-ID: 5OsmHJKq5Ui
2017-08-15 05:50:28 +03:00
|
|
|
// Try to inherit a style backend.
|
2012-01-20 16:03:49 +04:00
|
|
|
NS_ASSERTION(mPrincipal, "Must have principal by now");
|
|
|
|
NS_ASSERTION(mDocumentURI, "Must have document URI by now");
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> doc;
|
2018-05-11 20:46:15 +03:00
|
|
|
nsresult rv = NS_NewDOMDocument(
|
|
|
|
getter_AddRefs(doc), EmptyString(), EmptyString(), nullptr, mDocumentURI,
|
2018-04-21 06:04:45 +03:00
|
|
|
mBaseURI, mPrincipal, true, scriptHandlingObject, aFlavor);
|
2018-04-21 06:01:25 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-04-21 06:01:25 +03:00
|
|
|
|
2018-04-21 06:01:25 +03:00
|
|
|
return doc.forget();
|
2012-01-20 16:03:49 +04:00
|
|
|
}
|