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

Side by Side Diff: chrome/renderer/extensions/extension_dispatcher.cc

Issue 9838044: Make the chrome.webstore bindings load lazily. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/extension_dispatcher.h" 5 #include "chrome/renderer/extensions/extension_dispatcher.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/string_piece.h" 10 #include "base/string_piece.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 std::vector<std::string> components; 112 std::vector<std::string> components;
113 for (int i = 0; i < args.Length(); ++i) 113 for (int i = 0; i < args.Length(); ++i)
114 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); 114 components.push_back(*v8::String::Utf8Value(args[i]->ToString()));
115 115
116 LOG(ERROR) << JoinString(components, ','); 116 LOG(ERROR) << JoinString(components, ',');
117 return v8::Undefined(); 117 return v8::Undefined();
118 } 118 }
119 }; 119 };
120 120
121 void InstallAppBindings(ModuleSystem* module_system,
122 v8::Handle<v8::Object> chrome,
123 v8::Handle<v8::Object> chrome_hidden) {
124 module_system->SetLazyField(chrome, "app", "app", "chromeApp");
125 module_system->SetLazyField(chrome, "appNotifications", "app",
126 "chromeAppNotifications");
127 module_system->SetLazyField(chrome_hidden, "app", "app",
128 "chromeHiddenApp");
129 }
130
131 void InstallWebstoreBindings(ModuleSystem* module_system,
132 v8::Handle<v8::Object> chrome,
133 v8::Handle<v8::Object> chrome_hidden) {
134 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore");
135 module_system->SetLazyField(chrome_hidden, "webstore", "webstore",
136 "chromeHiddenWebstore");
137 }
138
121 } 139 }
122 140
123 ExtensionDispatcher::ExtensionDispatcher() 141 ExtensionDispatcher::ExtensionDispatcher()
124 : is_webkit_initialized_(false), 142 : is_webkit_initialized_(false),
125 webrequest_adblock_(false), 143 webrequest_adblock_(false),
126 webrequest_adblock_plus_(false), 144 webrequest_adblock_plus_(false),
127 webrequest_other_(false), 145 webrequest_other_(false),
128 source_map_(&ResourceBundle::GetSharedInstance()) { 146 source_map_(&ResourceBundle::GetSharedInstance()) {
129 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); 147 const CommandLine& command_line = *(CommandLine::ForCurrentProcess());
130 is_extension_process_ = 148 is_extension_process_ =
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 482
465 module_system->RegisterNativeHandler("chrome_hidden", 483 module_system->RegisterNativeHandler("chrome_hidden",
466 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); 484 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler()));
467 module_system->RegisterNativeHandler("print", 485 module_system->RegisterNativeHandler("print",
468 scoped_ptr<NativeHandler>(new PrintNativeHandler())); 486 scoped_ptr<NativeHandler>(new PrintNativeHandler()));
469 487
470 int manifest_version = 1; 488 int manifest_version = 1;
471 if (extension) 489 if (extension)
472 manifest_version = extension->manifest_version(); 490 manifest_version = extension->manifest_version();
473 491
492 std::map<std::string, BindingInstaller> optimized_bindings;
493 optimized_bindings["app"] = InstallAppBindings;
494 optimized_bindings["webstore"] = InstallWebstoreBindings;
495
474 // Create the 'chrome' variable if it doesn't already exist. 496 // Create the 'chrome' variable if it doesn't already exist.
475 { 497 {
476 v8::HandleScope handle_scope; 498 v8::HandleScope handle_scope;
477 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); 499 v8::Handle<v8::String> chrome_string(v8::String::New("chrome"));
478 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global()); 500 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global());
479 if (global->Get(chrome_string)->IsUndefined()) 501 if (global->Get(chrome_string)->IsUndefined())
480 global->Set(chrome_string, v8::Object::New()); 502 global->Set(chrome_string, v8::Object::New());
481 } 503 }
482 504
483 // Loading JavaScript is expensive, so only run the full API bindings 505 // Loading JavaScript is expensive, so only run the full API bindings
(...skipping 22 matching lines...) Expand all
506 // to write. We really need to factor things differently to delete the 528 // to write. We really need to factor things differently to delete the
507 // concept of a test extension ID. 529 // concept of a test extension ID.
508 if (IsTestExtensionId(extension_id)) { 530 if (IsTestExtensionId(extension_id)) {
509 module_system->Require("miscellaneous_bindings"); 531 module_system->Require("miscellaneous_bindings");
510 module_system->Require("schema_generated_bindings"); 532 module_system->Require("schema_generated_bindings");
511 apis->insert("extension"); 533 apis->insert("extension");
512 } 534 }
513 535
514 for (std::set<std::string>::iterator i = apis->begin(); i != apis->end(); 536 for (std::set<std::string>::iterator i = apis->begin(); i != apis->end();
515 ++i) { 537 ++i) {
516 if (*i == "app") { 538 if (optimized_bindings.count(*i) > 0) {
517 // As 'app' is loaded on every page we implement lazy bindings in C++ 539 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global());
518 // here to improve performance (ie: don't load any JS).
519 v8::Handle<v8::Object> global = v8::Context::GetCurrent()->Global();
520 v8::Handle<v8::Object> chrome = 540 v8::Handle<v8::Object> chrome =
521 global->Get(v8::String::New("chrome"))->ToObject(); 541 global->Get(v8::String::New("chrome"))->ToObject();
522
523 module_system->SetLazyField(chrome, "app", "app", "chromeApp");
524 module_system->SetLazyField(chrome, "appNotifications", "app",
525 "chromeAppNotifications");
526 v8::Handle<v8::Object> chrome_hidden = 542 v8::Handle<v8::Object> chrome_hidden =
527 ChromeV8Context::GetOrCreateChromeHidden(v8_context)->ToObject(); 543 ChromeV8Context::GetOrCreateChromeHidden(v8_context)->ToObject();
528 module_system->SetLazyField(chrome_hidden, "app", "app", 544 optimized_bindings[*i](module_system.get(), chrome, chrome_hidden);
529 "chromeHiddenApp");
530 continue; 545 continue;
531 } 546 }
532 module_system->Require(*i); 547 module_system->Require(*i);
533 } 548 }
534 549
535 module_system->set_natives_enabled(false); 550 module_system->set_natives_enabled(false);
536 551
537 context->set_module_system(module_system.Pass()); 552 context->set_module_system(module_system.Pass());
538 553
539 context->DispatchOnLoadEvent( 554 context->DispatchOnLoadEvent(
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 return Feature::BLESSED_EXTENSION_CONTEXT; 733 return Feature::BLESSED_EXTENSION_CONTEXT;
719 734
720 if (extensions_.ExtensionBindingsAllowed(url_info)) 735 if (extensions_.ExtensionBindingsAllowed(url_info))
721 return Feature::UNBLESSED_EXTENSION_CONTEXT; 736 return Feature::UNBLESSED_EXTENSION_CONTEXT;
722 737
723 if (url_info.url().is_valid()) 738 if (url_info.url().is_valid())
724 return Feature::WEB_PAGE_CONTEXT; 739 return Feature::WEB_PAGE_CONTEXT;
725 740
726 return Feature::UNSPECIFIED_CONTEXT; 741 return Feature::UNSPECIFIED_CONTEXT;
727 } 742 }
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/extension_dispatcher.h ('k') | chrome/renderer/resources/extensions/webstore_custom_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698