Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: third_party/WebKit/Source/core/dom/ModuleScript.h

Issue 2823483002: Make ModuleScript to have a reference to Modulator explicitly (Closed)
Patch Set: unit tests fix Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ModuleScript_h 5 #ifndef ModuleScript_h
6 #define ModuleScript_h 6 #define ModuleScript_h
7 7
8 #include "bindings/core/v8/ScriptModule.h" 8 #include "bindings/core/v8/ScriptModule.h"
9 #include "bindings/core/v8/ScriptValue.h" 9 #include "bindings/core/v8/ScriptValue.h"
10 #include "bindings/core/v8/ScriptWrappable.h" 10 #include "bindings/core/v8/ScriptWrappable.h"
11 #include "bindings/core/v8/TraceWrapperV8Reference.h" 11 #include "bindings/core/v8/TraceWrapperV8Reference.h"
12 #include "core/CoreExport.h" 12 #include "core/CoreExport.h"
13 #include "core/dom/Modulator.h"
13 #include "core/dom/Script.h" 14 #include "core/dom/Script.h"
14 #include "platform/heap/Handle.h" 15 #include "platform/heap/Handle.h"
15 #include "platform/loader/fetch/ResourceLoaderOptions.h" 16 #include "platform/loader/fetch/ResourceLoaderOptions.h"
16 #include "platform/weborigin/KURL.h" 17 #include "platform/weborigin/KURL.h"
17 #include "public/platform/WebURLRequest.h" 18 #include "public/platform/WebURLRequest.h"
18 19
19 namespace blink { 20 namespace blink {
20 21
21 // https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script- instantiation-state 22 // https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script- instantiation-state
22 enum class ModuleInstantiationState { 23 enum class ModuleInstantiationState {
23 kUninstantiated, 24 kUninstantiated,
24 kErrored, 25 kErrored,
25 kInstantiated, 26 kInstantiated,
26 }; 27 };
27 28
28 // ModuleScript is a model object for the "module script" spec concept. 29 // ModuleScript is a model object for the "module script" spec concept.
29 // https://html.spec.whatwg.org/multipage/webappapis.html#module-script 30 // https://html.spec.whatwg.org/multipage/webappapis.html#module-script
30 class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase { 31 class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase {
31 public: 32 public:
32 static ModuleScript* Create( 33 static ModuleScript* Create(
34 Modulator* settings_object,
33 ScriptModule record, 35 ScriptModule record,
34 const KURL& base_url, 36 const KURL& base_url,
35 const String& nonce, 37 const String& nonce,
36 ParserDisposition parser_state, 38 ParserDisposition parser_state,
37 WebURLRequest::FetchCredentialsMode credentials_mode) { 39 WebURLRequest::FetchCredentialsMode credentials_mode) {
38 return new ModuleScript(record, base_url, nonce, parser_state, 40 return new ModuleScript(settings_object, record, base_url, nonce,
39 credentials_mode); 41 parser_state, credentials_mode);
40 } 42 }
41 ~ModuleScript() override = default; 43 ~ModuleScript() override = default;
42 44
43 ScriptModule& Record() { return record_; } 45 ScriptModule& Record() { return record_; }
44 void ClearRecord() { record_ = ScriptModule(); } 46 void ClearRecord() { record_ = ScriptModule(); }
45 const KURL& BaseURL() const { return base_url_; } 47 const KURL& BaseURL() const { return base_url_; }
46 48
47 ModuleInstantiationState InstantiationState() const { 49 ModuleInstantiationState InstantiationState() const {
48 return instantiation_state_; 50 return instantiation_state_;
49 } 51 }
50 52
51 void SetInstantiationSuccess(); 53 void SetInstantiationSuccess();
52 void SetInstantiationError(v8::Isolate*, v8::Local<v8::Value> error); 54 void SetInstantiationError(v8::Isolate*, v8::Local<v8::Value> error);
53 55
54 ParserDisposition ParserState() const { return parser_state_; } 56 ParserDisposition ParserState() const { return parser_state_; }
55 WebURLRequest::FetchCredentialsMode CredentialsMode() const { 57 WebURLRequest::FetchCredentialsMode CredentialsMode() const {
56 return credentials_mode_; 58 return credentials_mode_;
57 } 59 }
58 const String& Nonce() const { return nonce_; } 60 const String& Nonce() const { return nonce_; }
59 61
60 DECLARE_TRACE(); 62 DECLARE_TRACE();
61 DECLARE_TRACE_WRAPPERS(); 63 DECLARE_TRACE_WRAPPERS();
62 64
63 private: 65 private:
64 ModuleScript(ScriptModule record, 66 ModuleScript(Modulator* settings_object,
67 ScriptModule record,
65 const KURL& base_url, 68 const KURL& base_url,
66 const String& nonce, 69 const String& nonce,
67 ParserDisposition parser_state, 70 ParserDisposition parser_state,
68 WebURLRequest::FetchCredentialsMode credentials_mode) 71 WebURLRequest::FetchCredentialsMode credentials_mode)
69 : record_(record), 72 : settings_object_(settings_object),
73 record_(record),
70 base_url_(base_url), 74 base_url_(base_url),
71 instantiation_error_(this), 75 instantiation_error_(this),
72 nonce_(nonce), 76 nonce_(nonce),
73 parser_state_(parser_state), 77 parser_state_(parser_state),
74 credentials_mode_(credentials_mode) {} 78 credentials_mode_(credentials_mode) {}
75 79
76 ScriptType GetScriptType() const override { return ScriptType::kModule; } 80 ScriptType GetScriptType() const override { return ScriptType::kModule; }
77 bool IsEmpty() const override; 81 bool IsEmpty() const override;
78 bool CheckMIMETypeBeforeRunScript(Document* context_document, 82 bool CheckMIMETypeBeforeRunScript(Document* context_document,
79 const SecurityOrigin*) const override; 83 const SecurityOrigin*) const override;
80 void RunScript(LocalFrame*, const SecurityOrigin*) const override; 84 void RunScript(LocalFrame*, const SecurityOrigin*) const override;
81 String InlineSourceTextForCSP() const override; 85 String InlineSourceTextForCSP() const override;
82 86
83 // Note: A "module script"'s "setttings object" is ommitted, as we currently
84 // always have access to the corresponding Modulator when operating on a
85 // ModuleScript instance.
86 // https://html.spec.whatwg.org/multipage/webappapis.html#settings-object 87 // https://html.spec.whatwg.org/multipage/webappapis.html#settings-object
88 Member<Modulator> settings_object_;
87 89
88 // https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-scrip t-module-record 90 // https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-scrip t-module-record
89 ScriptModule record_; 91 ScriptModule record_;
90 92
91 // https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-scrip t-base-url 93 // https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-scrip t-base-url
92 const KURL base_url_; 94 const KURL base_url_;
93 95
94 // https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-scrip t-instantiation-state 96 // https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-scrip t-instantiation-state
95 ModuleInstantiationState instantiation_state_ = 97 ModuleInstantiationState instantiation_state_ =
96 ModuleInstantiationState::kUninstantiated; 98 ModuleInstantiationState::kUninstantiated;
(...skipping 14 matching lines...) Expand all
111 // https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-scrip t-parser 113 // https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-scrip t-parser
112 const ParserDisposition parser_state_; 114 const ParserDisposition parser_state_;
113 115
114 // https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-scrip t-credentials-mode 116 // https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-scrip t-credentials-mode
115 const WebURLRequest::FetchCredentialsMode credentials_mode_; 117 const WebURLRequest::FetchCredentialsMode credentials_mode_;
116 }; 118 };
117 119
118 } // namespace blink 120 } // namespace blink
119 121
120 #endif 122 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/ModuleMapTest.cpp ('k') | third_party/WebKit/Source/core/dom/ModuleScript.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698