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

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

Issue 1142993002: Don't send unnecessary ExtensionMsg_Loaded IPCs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: commnets Created 5 years, 6 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
« no previous file with comments | « extensions/renderer/script_context.h ('k') | no next file » | 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/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 v8_context_(v8_context->GetIsolate(), v8_context), 89 v8_context_(v8_context->GetIsolate(), v8_context),
90 web_frame_(web_frame), 90 web_frame_(web_frame),
91 extension_(extension), 91 extension_(extension),
92 context_type_(context_type), 92 context_type_(context_type),
93 effective_extension_(effective_extension), 93 effective_extension_(effective_extension),
94 effective_context_type_(effective_context_type), 94 effective_context_type_(effective_context_type),
95 safe_builtins_(this), 95 safe_builtins_(this),
96 isolate_(v8_context->GetIsolate()), 96 isolate_(v8_context->GetIsolate()),
97 url_(web_frame_ ? GetDataSourceURLForFrame(web_frame_) : GURL()), 97 url_(web_frame_ ? GetDataSourceURLForFrame(web_frame_) : GURL()),
98 runner_(new Runner(this)) { 98 runner_(new Runner(this)) {
99 VLOG(1) << "Created context:\n" 99 VLOG(1) << "Created context:\n" << GetDebugString();
100 << " extension id: " << GetExtensionID() << "\n"
101 << " frame: " << web_frame_ << "\n"
102 << " URL: " << GetURL() << "\n"
103 << " context type: " << GetContextTypeDescription() << "\n"
104 << " effective extension id: "
105 << (effective_extension_.get() ? effective_extension_->id() : "")
106 << " effective context type: "
107 << GetEffectiveContextTypeDescription();
108 gin::PerContextData* gin_data = gin::PerContextData::From(v8_context); 100 gin::PerContextData* gin_data = gin::PerContextData::From(v8_context);
109 CHECK(gin_data); // may fail if the v8::Context hasn't been registered yet 101 CHECK(gin_data); // may fail if the v8::Context hasn't been registered yet
110 gin_data->set_runner(runner_.get()); 102 gin_data->set_runner(runner_.get());
111 } 103 }
112 104
113 ScriptContext::~ScriptContext() { 105 ScriptContext::~ScriptContext() {
114 VLOG(1) << "Destroyed context for extension\n" 106 VLOG(1) << "Destroyed context for extension\n"
115 << " extension id: " << GetExtensionID() << "\n" 107 << " extension id: " << GetExtensionID() << "\n"
116 << " effective extension id: " 108 << " effective extension id: "
117 << (effective_extension_.get() ? effective_extension_->id() : ""); 109 << (effective_extension_.get() ? effective_extension_->id() : "");
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 module_system_->CallModuleMethod( 218 module_system_->CallModuleMethod(
227 kEventBindings, "dispatchEvent", arraysize(argv), argv); 219 kEventBindings, "dispatchEvent", arraysize(argv), argv);
228 } 220 }
229 221
230 void ScriptContext::DispatchOnUnloadEvent() { 222 void ScriptContext::DispatchOnUnloadEvent() {
231 v8::HandleScope handle_scope(isolate()); 223 v8::HandleScope handle_scope(isolate());
232 v8::Context::Scope context_scope(v8_context()); 224 v8::Context::Scope context_scope(v8_context());
233 module_system_->CallModuleMethod("unload_event", "dispatch"); 225 module_system_->CallModuleMethod("unload_event", "dispatch");
234 } 226 }
235 227
236 std::string ScriptContext::GetContextTypeDescription() { 228 std::string ScriptContext::GetContextTypeDescription() const {
237 return GetContextTypeDescriptionString(context_type_); 229 return GetContextTypeDescriptionString(context_type_);
238 } 230 }
239 231
240 std::string ScriptContext::GetEffectiveContextTypeDescription() { 232 std::string ScriptContext::GetEffectiveContextTypeDescription() const {
241 return GetContextTypeDescriptionString(effective_context_type_); 233 return GetContextTypeDescriptionString(effective_context_type_);
242 } 234 }
243 235
244 GURL ScriptContext::GetURL() const { 236 GURL ScriptContext::GetURL() const {
245 return url_; 237 return url_;
246 } 238 }
247 239
248 bool ScriptContext::IsAnyFeatureAvailableToContext(const Feature& api) { 240 bool ScriptContext::IsAnyFeatureAvailableToContext(const Feature& api) {
249 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext( 241 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext(
250 api, extension(), context_type(), GetDataSourceURLForFrame(web_frame())); 242 api, extension(), context_type(), GetDataSourceURLForFrame(web_frame()));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 Feature::Availability availability = GetAvailability(name); 358 Feature::Availability availability = GetAvailability(name);
367 if (!availability.is_available()) { 359 if (!availability.is_available()) {
368 isolate()->ThrowException(v8::Exception::Error( 360 isolate()->ThrowException(v8::Exception::Error(
369 v8::String::NewFromUtf8(isolate(), availability.message().c_str()))); 361 v8::String::NewFromUtf8(isolate(), availability.message().c_str())));
370 return false; 362 return false;
371 } 363 }
372 364
373 return true; 365 return true;
374 } 366 }
375 367
368 std::string ScriptContext::GetDebugString() const {
369 return base::StringPrintf(
370 " extension id: %s\n"
371 " frame: %p\n"
372 " URL: %s\n"
373 " context_type: %s\n"
374 " effective extension id: %s\n"
375 " effective context type: %s",
376 extension_.get() ? extension_->id().c_str() : "(none)", web_frame_,
377 GetURL().spec().c_str(), GetContextTypeDescription().c_str(),
378 effective_extension_.get() ? effective_extension_->id().c_str()
379 : "(none)",
380 GetEffectiveContextTypeDescription().c_str());
381 }
382
376 ScriptContext::Runner::Runner(ScriptContext* context) : context_(context) { 383 ScriptContext::Runner::Runner(ScriptContext* context) : context_(context) {
377 } 384 }
378 385
379 void ScriptContext::Runner::Run(const std::string& source, 386 void ScriptContext::Runner::Run(const std::string& source,
380 const std::string& resource_name) { 387 const std::string& resource_name) {
381 context_->module_system()->RunString(source, resource_name); 388 context_->module_system()->RunString(source, resource_name);
382 } 389 }
383 390
384 v8::Local<v8::Value> ScriptContext::Runner::Call( 391 v8::Local<v8::Value> ScriptContext::Runner::Call(
385 v8::Local<v8::Function> function, 392 v8::Local<v8::Function> function,
386 v8::Local<v8::Value> receiver, 393 v8::Local<v8::Value> receiver,
387 int argc, 394 int argc,
388 v8::Local<v8::Value> argv[]) { 395 v8::Local<v8::Value> argv[]) {
389 return context_->CallFunction(function, argc, argv); 396 return context_->CallFunction(function, argc, argv);
390 } 397 }
391 398
392 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { 399 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() {
393 v8::HandleScope handle_scope(context_->isolate()); 400 v8::HandleScope handle_scope(context_->isolate());
394 return gin::PerContextData::From(context_->v8_context())->context_holder(); 401 return gin::PerContextData::From(context_->v8_context())->context_holder();
395 } 402 }
396 403
397 } // namespace extensions 404 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/script_context.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698