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

Side by Side Diff: extensions/renderer/script_context.h

Issue 2494653005: Support API aliases (Closed)
Patch Set: . Created 4 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ 5 #ifndef EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_
6 #define EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ 6 #define EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 15 matching lines...) Expand all
26 namespace blink { 26 namespace blink {
27 class WebFrame; 27 class WebFrame;
28 class WebLocalFrame; 28 class WebLocalFrame;
29 } 29 }
30 30
31 namespace content { 31 namespace content {
32 class RenderFrame; 32 class RenderFrame;
33 } 33 }
34 34
35 namespace extensions { 35 namespace extensions {
36 enum class CheckAliasStatus;
36 class Extension; 37 class Extension;
37 38
38 // Extensions wrapper for a v8::Context. 39 // Extensions wrapper for a v8::Context.
39 // 40 //
40 // v8::Contexts can be constructed on any thread, and must only be accessed or 41 // v8::Contexts can be constructed on any thread, and must only be accessed or
41 // destroyed that thread. 42 // destroyed that thread.
42 // 43 //
43 // Note that ScriptContexts bound to worker threads will not have the full 44 // Note that ScriptContexts bound to worker threads will not have the full
44 // functionality as those bound to the main RenderThread. 45 // functionality as those bound to the main RenderThread.
45 class ScriptContext : public RequestSender::Source { 46 class ScriptContext : public RequestSender::Source {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // USE THIS METHOD RATHER THAN v8::Function::Call WHEREVER POSSIBLE. 120 // USE THIS METHOD RATHER THAN v8::Function::Call WHEREVER POSSIBLE.
120 // TODO(devlin): Remove the above variants in favor of this. 121 // TODO(devlin): Remove the above variants in favor of this.
121 void SafeCallFunction(const v8::Local<v8::Function>& function, 122 void SafeCallFunction(const v8::Local<v8::Function>& function,
122 int argc, 123 int argc,
123 v8::Local<v8::Value> argv[]); 124 v8::Local<v8::Value> argv[]);
124 125
125 void DispatchEvent(const char* event_name, v8::Local<v8::Array> args) const; 126 void DispatchEvent(const char* event_name, v8::Local<v8::Array> args) const;
126 127
127 // Returns the availability of the API |api_name|. 128 // Returns the availability of the API |api_name|.
128 Feature::Availability GetAvailability(const std::string& api_name); 129 Feature::Availability GetAvailability(const std::string& api_name);
130 // Returns the availability of the API |api_name|.
131 // |check_alias| Whether API that has an alias that is available should be
132 // considered available (even if the API itself is not available).
133 Feature::Availability GetAvailability(const std::string& api_name,
134 CheckAliasStatus check_alias);
129 135
130 // Returns a string description of the type of context this is. 136 // Returns a string description of the type of context this is.
131 std::string GetContextTypeDescription() const; 137 std::string GetContextTypeDescription() const;
132 138
133 // Returns a string description of the effective type of context this is. 139 // Returns a string description of the effective type of context this is.
134 std::string GetEffectiveContextTypeDescription() const; 140 std::string GetEffectiveContextTypeDescription() const;
135 141
136 v8::Isolate* isolate() const { return isolate_; } 142 v8::Isolate* isolate() const { return isolate_; }
137 143
138 // Get the URL of this context's web frame. 144 // Get the URL of this context's web frame.
139 // 145 //
140 // TODO(kalman): Remove this and replace with a GetOrigin() call which reads 146 // TODO(kalman): Remove this and replace with a GetOrigin() call which reads
141 // of WebDocument::getSecurityOrigin(): 147 // of WebDocument::getSecurityOrigin():
142 // - The URL can change (e.g. pushState) but the origin cannot. Luckily it 148 // - The URL can change (e.g. pushState) but the origin cannot. Luckily it
143 // appears as though callers don't make security decisions based on the 149 // appears as though callers don't make security decisions based on the
144 // result of url() so it's not a problem... yet. 150 // result of url() so it's not a problem... yet.
145 // - Origin is the correct check to be making. 151 // - Origin is the correct check to be making.
146 // - It might let us remove the about:blank resolving? 152 // - It might let us remove the about:blank resolving?
147 const GURL& url() const { return url_; } 153 const GURL& url() const { return url_; }
148 154
149 // Sets the URL of this ScriptContext. Usually this will automatically be set 155 // Sets the URL of this ScriptContext. Usually this will automatically be set
150 // on construction, unless this isn't constructed with enough information to 156 // on construction, unless this isn't constructed with enough information to
151 // determine the URL (e.g. frame was null). 157 // determine the URL (e.g. frame was null).
152 // TODO(kalman): Make this a constructor parameter (as an origin). 158 // TODO(kalman): Make this a constructor parameter (as an origin).
153 void set_url(const GURL& url) { url_ = url; } 159 void set_url(const GURL& url) { url_ = url; }
154 160
155 // Returns whether the API |api| or any part of the API could be 161 // Returns whether the API |api| or any part of the API could be available in
156 // available in this context without taking into account the context's 162 // this context without taking into account the context's extension.
157 // extension. 163 // |check_alias| Whether the API should be considered available if it has an
158 bool IsAnyFeatureAvailableToContext(const extensions::Feature& api); 164 // alias that is available.
165 bool IsAnyFeatureAvailableToContext(const extensions::Feature& api,
166 CheckAliasStatus check_alias);
159 167
160 // Utility to get the URL we will match against for a frame. If the frame has 168 // Utility to get the URL we will match against for a frame. If the frame has
161 // committed, this is the commited URL. Otherwise it is the provisional URL. 169 // committed, this is the commited URL. Otherwise it is the provisional URL.
162 // The returned URL may be invalid. 170 // The returned URL may be invalid.
163 static GURL GetDataSourceURLForFrame(const blink::WebFrame* frame); 171 static GURL GetDataSourceURLForFrame(const blink::WebFrame* frame);
164 172
165 // Similar to GetDataSourceURLForFrame, but only returns the data source URL 173 // Similar to GetDataSourceURLForFrame, but only returns the data source URL
166 // if the frame's document url is empty and the frame has a security origin 174 // if the frame's document url is empty and the frame has a security origin
167 // that allows access to the data source url. 175 // that allows access to the data source url.
168 // TODO(asargent/devlin) - there may be places that should switch to using 176 // TODO(asargent/devlin) - there may be places that should switch to using
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 std::unique_ptr<Runner> runner_; 270 std::unique_ptr<Runner> runner_;
263 271
264 base::ThreadChecker thread_checker_; 272 base::ThreadChecker thread_checker_;
265 273
266 DISALLOW_COPY_AND_ASSIGN(ScriptContext); 274 DISALLOW_COPY_AND_ASSIGN(ScriptContext);
267 }; 275 };
268 276
269 } // namespace extensions 277 } // namespace extensions
270 278
271 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ 279 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_
OLDNEW
« no previous file with comments | « extensions/renderer/native_extension_bindings_system.cc ('k') | extensions/renderer/script_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698