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

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

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
« no previous file with comments | « extensions/renderer/script_context.h ('k') | tools/json_schema_compiler/feature_compiler.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "extensions/renderer/script_context.h" 5 #include "extensions/renderer/script_context.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 web_frame_->requestExecuteV8Function(v8_context(), function, global, argc, 214 web_frame_->requestExecuteV8Function(v8_context(), function, global, argc,
215 argv, nullptr); 215 argv, nullptr);
216 } else { 216 } else {
217 // TODO(devlin): This probably isn't safe. 217 // TODO(devlin): This probably isn't safe.
218 function->Call(global, argc, argv); 218 function->Call(global, argc, argv);
219 } 219 }
220 } 220 }
221 221
222 Feature::Availability ScriptContext::GetAvailability( 222 Feature::Availability ScriptContext::GetAvailability(
223 const std::string& api_name) { 223 const std::string& api_name) {
224 return GetAvailability(api_name, CheckAliasStatus::ALLOWED);
225 }
226
227 Feature::Availability ScriptContext::GetAvailability(
228 const std::string& api_name,
229 CheckAliasStatus check_alias) {
224 DCHECK(thread_checker_.CalledOnValidThread()); 230 DCHECK(thread_checker_.CalledOnValidThread());
225 if (base::StartsWith(api_name, "test", base::CompareCase::SENSITIVE)) { 231 if (base::StartsWith(api_name, "test", base::CompareCase::SENSITIVE)) {
226 bool allowed = base::CommandLine::ForCurrentProcess()-> 232 bool allowed = base::CommandLine::ForCurrentProcess()->
227 HasSwitch(::switches::kTestType); 233 HasSwitch(::switches::kTestType);
228 Feature::AvailabilityResult result = 234 Feature::AvailabilityResult result =
229 allowed ? Feature::IS_AVAILABLE : Feature::MISSING_COMMAND_LINE_SWITCH; 235 allowed ? Feature::IS_AVAILABLE : Feature::MISSING_COMMAND_LINE_SWITCH;
230 return Feature::Availability(result, 236 return Feature::Availability(result,
231 allowed ? "" : "Only allowed in tests"); 237 allowed ? "" : "Only allowed in tests");
232 } 238 }
233 // Hack: Hosted apps should have the availability of messaging APIs based on 239 // Hack: Hosted apps should have the availability of messaging APIs based on
234 // the URL of the page (which might have access depending on some extension 240 // the URL of the page (which might have access depending on some extension
235 // with externally_connectable), not whether the app has access to messaging 241 // with externally_connectable), not whether the app has access to messaging
236 // (which it won't). 242 // (which it won't).
237 const Extension* extension = extension_.get(); 243 const Extension* extension = extension_.get();
238 if (extension && extension->is_hosted_app() && 244 if (extension && extension->is_hosted_app() &&
239 (api_name == "runtime.connect" || api_name == "runtime.sendMessage")) { 245 (api_name == "runtime.connect" || api_name == "runtime.sendMessage")) {
240 extension = NULL; 246 extension = NULL;
241 } 247 }
242 return ExtensionAPI::GetSharedInstance()->IsAvailable(api_name, extension, 248 return ExtensionAPI::GetSharedInstance()->IsAvailable(
243 context_type_, url()); 249 api_name, extension, context_type_, url(), check_alias);
244 } 250 }
245 251
246 void ScriptContext::DispatchEvent(const char* event_name, 252 void ScriptContext::DispatchEvent(const char* event_name,
247 v8::Local<v8::Array> args) const { 253 v8::Local<v8::Array> args) const {
248 DCHECK(thread_checker_.CalledOnValidThread()); 254 DCHECK(thread_checker_.CalledOnValidThread());
249 v8::HandleScope handle_scope(isolate()); 255 v8::HandleScope handle_scope(isolate());
250 v8::Context::Scope context_scope(v8_context()); 256 v8::Context::Scope context_scope(v8_context());
251 257
252 v8::Local<v8::Value> argv[] = {v8::String::NewFromUtf8(isolate(), event_name), 258 v8::Local<v8::Value> argv[] = {v8::String::NewFromUtf8(isolate(), event_name),
253 args}; 259 args};
254 module_system_->CallModuleMethodSafe(kEventBindings, "dispatchEvent", 260 module_system_->CallModuleMethodSafe(kEventBindings, "dispatchEvent",
255 arraysize(argv), argv); 261 arraysize(argv), argv);
256 } 262 }
257 263
258 std::string ScriptContext::GetContextTypeDescription() const { 264 std::string ScriptContext::GetContextTypeDescription() const {
259 DCHECK(thread_checker_.CalledOnValidThread()); 265 DCHECK(thread_checker_.CalledOnValidThread());
260 return GetContextTypeDescriptionString(context_type_); 266 return GetContextTypeDescriptionString(context_type_);
261 } 267 }
262 268
263 std::string ScriptContext::GetEffectiveContextTypeDescription() const { 269 std::string ScriptContext::GetEffectiveContextTypeDescription() const {
264 DCHECK(thread_checker_.CalledOnValidThread()); 270 DCHECK(thread_checker_.CalledOnValidThread());
265 return GetContextTypeDescriptionString(effective_context_type_); 271 return GetContextTypeDescriptionString(effective_context_type_);
266 } 272 }
267 273
268 bool ScriptContext::IsAnyFeatureAvailableToContext(const Feature& api) { 274 bool ScriptContext::IsAnyFeatureAvailableToContext(
275 const Feature& api,
276 CheckAliasStatus check_alias) {
269 DCHECK(thread_checker_.CalledOnValidThread()); 277 DCHECK(thread_checker_.CalledOnValidThread());
270 // TODO(lazyboy): Decide what we should do for SERVICE_WORKER_CONTEXT, where 278 // TODO(lazyboy): Decide what we should do for SERVICE_WORKER_CONTEXT, where
271 // web_frame() is null. 279 // web_frame() is null.
272 GURL url = web_frame() ? GetDataSourceURLForFrame(web_frame()) : url_; 280 GURL url = web_frame() ? GetDataSourceURLForFrame(web_frame()) : url_;
273 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext( 281 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext(
274 api, extension(), context_type(), url); 282 api, extension(), context_type(), url, check_alias);
275 } 283 }
276 284
277 // static 285 // static
278 GURL ScriptContext::GetDataSourceURLForFrame(const blink::WebFrame* frame) { 286 GURL ScriptContext::GetDataSourceURLForFrame(const blink::WebFrame* frame) {
279 // Normally we would use frame->document().url() to determine the document's 287 // Normally we would use frame->document().url() to determine the document's
280 // URL, but to decide whether to inject a content script, we use the URL from 288 // URL, but to decide whether to inject a content script, we use the URL from
281 // the data source. This "quirk" helps prevents content scripts from 289 // the data source. This "quirk" helps prevents content scripts from
282 // inadvertently adding DOM elements to the compose iframe in Gmail because 290 // inadvertently adding DOM elements to the compose iframe in Gmail because
283 // the compose iframe's dataSource URL is about:blank, but the document URL 291 // the compose iframe's dataSource URL is about:blank, but the document URL
284 // changes to match the parent document after Gmail document.writes into 292 // changes to match the parent document after Gmail document.writes into
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 v8::Local<v8::Value> argv[]) { 519 v8::Local<v8::Value> argv[]) {
512 return context_->CallFunction(function, argc, argv); 520 return context_->CallFunction(function, argc, argv);
513 } 521 }
514 522
515 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { 523 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() {
516 v8::HandleScope handle_scope(context_->isolate()); 524 v8::HandleScope handle_scope(context_->isolate());
517 return gin::PerContextData::From(context_->v8_context())->context_holder(); 525 return gin::PerContextData::From(context_->v8_context())->context_holder();
518 } 526 }
519 527
520 } // namespace extensions 528 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/script_context.h ('k') | tools/json_schema_compiler/feature_compiler.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698