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

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

Issue 2494653005: Support API aliases (Closed)
Patch Set: rebase Created 4 years, 1 month 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // USE THIS METHOD RATHER THAN v8::Function::Call WHEREVER POSSIBLE. 119 // USE THIS METHOD RATHER THAN v8::Function::Call WHEREVER POSSIBLE.
120 // TODO(devlin): Remove the above variants in favor of this. 120 // TODO(devlin): Remove the above variants in favor of this.
121 void SafeCallFunction(const v8::Local<v8::Function>& function, 121 void SafeCallFunction(const v8::Local<v8::Function>& function,
122 int argc, 122 int argc,
123 v8::Local<v8::Value> argv[]); 123 v8::Local<v8::Value> argv[]);
124 124
125 void DispatchEvent(const char* event_name, v8::Local<v8::Array> args) const; 125 void DispatchEvent(const char* event_name, v8::Local<v8::Array> args) const;
126 126
127 // Returns the availability of the API |api_name|. 127 // Returns the availability of the API |api_name|.
128 Feature::Availability GetAvailability(const std::string& api_name); 128 Feature::Availability GetAvailability(const std::string& api_name);
129 // Returns the availability of the API |api_name|.
130 // |allow_alias| Whether API that has an alias that is available should be
131 // considered available (even if the API itself is not available).
132 Feature::Availability GetAvailability(const std::string& api_name,
133 bool allow_alias);
129 134
130 // Returns a string description of the type of context this is. 135 // Returns a string description of the type of context this is.
131 std::string GetContextTypeDescription() const; 136 std::string GetContextTypeDescription() const;
132 137
133 // Returns a string description of the effective type of context this is. 138 // Returns a string description of the effective type of context this is.
134 std::string GetEffectiveContextTypeDescription() const; 139 std::string GetEffectiveContextTypeDescription() const;
135 140
136 v8::Isolate* isolate() const { return isolate_; } 141 v8::Isolate* isolate() const { return isolate_; }
137 142
138 // Get the URL of this context's web frame. 143 // Get the URL of this context's web frame.
139 // 144 //
140 // TODO(kalman): Remove this and replace with a GetOrigin() call which reads 145 // TODO(kalman): Remove this and replace with a GetOrigin() call which reads
141 // of WebDocument::getSecurityOrigin(): 146 // of WebDocument::getSecurityOrigin():
142 // - The URL can change (e.g. pushState) but the origin cannot. Luckily it 147 // - 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 148 // appears as though callers don't make security decisions based on the
144 // result of url() so it's not a problem... yet. 149 // result of url() so it's not a problem... yet.
145 // - Origin is the correct check to be making. 150 // - Origin is the correct check to be making.
146 // - It might let us remove the about:blank resolving? 151 // - It might let us remove the about:blank resolving?
147 const GURL& url() const { return url_; } 152 const GURL& url() const { return url_; }
148 153
149 // Sets the URL of this ScriptContext. Usually this will automatically be set 154 // Sets the URL of this ScriptContext. Usually this will automatically be set
150 // on construction, unless this isn't constructed with enough information to 155 // on construction, unless this isn't constructed with enough information to
151 // determine the URL (e.g. frame was null). 156 // determine the URL (e.g. frame was null).
152 // TODO(kalman): Make this a constructor parameter (as an origin). 157 // TODO(kalman): Make this a constructor parameter (as an origin).
153 void set_url(const GURL& url) { url_ = url; } 158 void set_url(const GURL& url) { url_ = url; }
154 159
155 // Returns whether the API |api| or any part of the API could be 160 // 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 161 // this context without taking into account the context's extension.
157 // extension. 162 // |allow_alias| Whether the API should be considered available if it has an
158 bool IsAnyFeatureAvailableToContext(const extensions::Feature& api); 163 // alias that is available.
164 bool IsAnyFeatureAvailableToContext(const extensions::Feature& api,
165 bool allow_alias);
159 166
160 // Utility to get the URL we will match against for a frame. If the frame has 167 // 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. 168 // committed, this is the commited URL. Otherwise it is the provisional URL.
162 // The returned URL may be invalid. 169 // The returned URL may be invalid.
163 static GURL GetDataSourceURLForFrame(const blink::WebFrame* frame); 170 static GURL GetDataSourceURLForFrame(const blink::WebFrame* frame);
164 171
165 // Similar to GetDataSourceURLForFrame, but only returns the data source URL 172 // 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 173 // if the frame's document url is empty and the frame has a security origin
167 // that allows access to the data source url. 174 // that allows access to the data source url.
168 // TODO(asargent/devlin) - there may be places that should switch to using 175 // 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_; 269 std::unique_ptr<Runner> runner_;
263 270
264 base::ThreadChecker thread_checker_; 271 base::ThreadChecker thread_checker_;
265 272
266 DISALLOW_COPY_AND_ASSIGN(ScriptContext); 273 DISALLOW_COPY_AND_ASSIGN(ScriptContext);
267 }; 274 };
268 275
269 } // namespace extensions 276 } // namespace extensions
270 277
271 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ 278 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698