Commit f5504c3f authored by Mason Freed's avatar Mason Freed Committed by Commit Bot

Convert DOMParser constructor argument to parseFromString parameter

Per more feedback [1] on the issue thread, it would be preferred
to remove the state from DOMParser and add it instead to the
parseFromString method.

[1] https://github.com/whatwg/dom/issues/912#issuecomment-725825635

Bug: 1042130
Change-Id: I316c008b80436bdacf7d0548e4ccd891a5c15411
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2533848
Commit-Queue: Mason Freed <masonfreed@chromium.org>
Commit-Queue: Kouhei Ueno <kouhei@chromium.org>
Auto-Submit: Mason Freed <masonfreed@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826693}
parent b9bcda06
...@@ -665,7 +665,7 @@ static_idl_files_in_core = get_path_info( ...@@ -665,7 +665,7 @@ static_idl_files_in_core = get_path_info(
"//third_party/blink/renderer/core/workers/worklet_options.idl", "//third_party/blink/renderer/core/workers/worklet_options.idl",
"//third_party/blink/renderer/core/xml/document_xpath_evaluator.idl", "//third_party/blink/renderer/core/xml/document_xpath_evaluator.idl",
"//third_party/blink/renderer/core/xml/dom_parser.idl", "//third_party/blink/renderer/core/xml/dom_parser.idl",
"//third_party/blink/renderer/core/xml/dom_parser_init.idl", "//third_party/blink/renderer/core/xml/parse_from_string_options.idl",
"//third_party/blink/renderer/core/xml/xml_serializer.idl", "//third_party/blink/renderer/core/xml/xml_serializer.idl",
"//third_party/blink/renderer/core/xml/xpath_evaluator.idl", "//third_party/blink/renderer/core/xml/xpath_evaluator.idl",
"//third_party/blink/renderer/core/xml/xpath_expression.idl", "//third_party/blink/renderer/core/xml/xpath_expression.idl",
......
...@@ -759,7 +759,7 @@ core_dictionary_idl_files = ...@@ -759,7 +759,7 @@ core_dictionary_idl_files =
"trustedtypes/trusted_type_policy_options.idl", "trustedtypes/trusted_type_policy_options.idl",
"workers/worker_options.idl", "workers/worker_options.idl",
"workers/worklet_options.idl", "workers/worklet_options.idl",
"xml/dom_parser_init.idl", "xml/parse_from_string_options.idl",
], ],
"abspath") "abspath")
......
...@@ -22,28 +22,30 @@ ...@@ -22,28 +22,30 @@
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/document_init.h" #include "third_party/blink/renderer/core/dom/document_init.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/xml/dom_parser_init.h" #include "third_party/blink/renderer/core/xml/parse_from_string_options.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h" #include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h" #include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink { namespace blink {
Document* DOMParser::parseFromString(const String& str, const String& type) { Document* DOMParser::parseFromString(const String& str,
const String& type,
const ParseFromStringOptions* options) {
Document* doc = DocumentInit::Create() Document* doc = DocumentInit::Create()
.WithURL(window_->Url()) .WithURL(window_->Url())
.WithTypeFrom(type) .WithTypeFrom(type)
.WithExecutionContext(window_) .WithExecutionContext(window_)
.CreateDocument(); .CreateDocument();
doc->setAllowDeclarativeShadowRoot(allow_shadow_root_); doc->setAllowDeclarativeShadowRoot(options->hasAllowShadowRoot() &&
options->allowShadowRoot());
doc->SetContent(str); doc->SetContent(str);
doc->SetMimeType(AtomicString(type)); doc->SetMimeType(AtomicString(type));
return doc; return doc;
} }
DOMParser::DOMParser(ScriptState* script_state, const DOMParserInit* init) DOMParser::DOMParser(ScriptState* script_state)
: allow_shadow_root_(init->hasAllowShadowRoot() && init->allowShadowRoot()), : window_(LocalDOMWindow::From(script_state)) {}
window_(LocalDOMWindow::From(script_state)) {}
void DOMParser::Trace(Visitor* visitor) const { void DOMParser::Trace(Visitor* visitor) const {
visitor->Trace(window_); visitor->Trace(window_);
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
namespace blink { namespace blink {
class Document; class Document;
class DOMParserInit; class ParseFromStringOptions;
class LocalDOMWindow; class LocalDOMWindow;
class ScriptState; class ScriptState;
...@@ -35,21 +35,21 @@ class DOMParser final : public ScriptWrappable { ...@@ -35,21 +35,21 @@ class DOMParser final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
static DOMParser* Create(ScriptState* script_state, static DOMParser* Create(ScriptState* script_state) {
const DOMParserInit* dict) { return MakeGarbageCollected<DOMParser>(script_state);
return MakeGarbageCollected<DOMParser>(script_state, dict);
} }
explicit DOMParser(ScriptState*, const DOMParserInit*); explicit DOMParser(ScriptState*);
Document* parseFromString(const String&, const String& type); Document* parseFromString(const String&,
const String& type,
const ParseFromStringOptions* options);
void Trace(Visitor*) const override; void Trace(Visitor*) const override;
LocalDOMWindow* GetWindow() const { return window_.Get(); } LocalDOMWindow* GetWindow() const { return window_.Get(); }
private: private:
const bool allow_shadow_root_;
WeakMember<LocalDOMWindow> window_; WeakMember<LocalDOMWindow> window_;
}; };
......
...@@ -30,6 +30,6 @@ enum SupportedType { ...@@ -30,6 +30,6 @@ enum SupportedType {
[ [
Exposed=Window Exposed=Window
] interface DOMParser { ] interface DOMParser {
[CallWith=ScriptState] constructor(optional DOMParserInit options = {}); [CallWith=ScriptState] constructor();
[NewObject] Document parseFromString(HTMLString str, SupportedType type); [NewObject] Document parseFromString(HTMLString str, SupportedType type, optional ParseFromStringOptions options = {});
}; };
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
dictionary DOMParserInit { dictionary ParseFromStringOptions {
boolean allowShadowRoot = false; boolean allowShadowRoot = false;
}; };
...@@ -110,11 +110,12 @@ test(() => { ...@@ -110,11 +110,12 @@ test(() => {
}, 'setInnerHTML on shadowRoot'); }, 'setInnerHTML on shadowRoot');
test(() => { test(() => {
let parser = new DOMParser(); const parser = new DOMParser();
let fragment = parser.parseFromString(content,'text/html'); let fragment = parser.parseFromString(content, 'text/html');
assert_dsd(fragment.body,false); assert_dsd(fragment.body,false);
parser = new DOMParser({allowShadowRoot: true}); fragment = parser.parseFromString(content, 'text/html', {allowShadowRoot: false});
fragment = parser.parseFromString(content,'text/html'); assert_dsd(fragment.body,false);
fragment = parser.parseFromString(content, 'text/html', {allowShadowRoot: true});
assert_dsd(fragment.body,true); assert_dsd(fragment.body,true);
}, 'DOMParser'); }, 'DOMParser');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment