Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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", | |
|
not at google - send to devlin
2012/03/25 22:42:58
add TODO to pull appNotifications out into its own
koz (OOO until 15th September)
2012/03/26 01:36:09
The 'app' module has variables in it that are shar
not at google - send to devlin
2012/03/26 02:29:49
I don't think they do really; rather I think that
koz (OOO until 15th September)
2012/03/26 03:58:59
Ah, true. Though looking at the code I see that th
| |
| 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 } | |
|
not at google - send to devlin
2012/03/25 22:42:58
I guess this isn't scalable to arbitrary APIs.
No
koz (OOO until 15th September)
2012/03/26 01:36:09
You mean being able to make arbitrary modules lazy
not at google - send to devlin
2012/03/26 02:29:49
Yeah agreed.
| |
| 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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 RegisterNativeHandlers(module_system.get(), context); | 481 RegisterNativeHandlers(module_system.get(), context); |
| 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 |
|
not at google - send to devlin
2012/03/25 22:42:58
could just have the typedef here?
koz (OOO until 15th September)
2012/03/26 01:36:09
Done.
| |
| 492 std::map<std::string, BindingInstaller> optimized_bindings; | |
| 493 optimized_bindings["app"] = InstallAppBindings; | |
| 494 optimized_bindings["webstore"] = InstallWebstoreBindings; | |
|
not at google - send to devlin
2012/03/25 22:42:58
lazy_bindings?
koz (OOO until 15th September)
2012/03/26 01:36:09
Nice. Done.
| |
| 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 Loading... | |
| 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) { |
| 538 if (optimized_bindings.count(*i) > 0) { | |
|
not at google - send to devlin
2012/03/25 22:42:58
nit: use find() here, ->second below.
koz (OOO until 15th September)
2012/03/26 01:36:09
Done.
| |
| 539 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global()); | |
| 540 v8::Handle<v8::Object> chrome = | |
| 541 global->Get(v8::String::New("chrome"))->ToObject(); | |
|
not at google - send to devlin
2012/03/25 22:42:58
re-use the reference to "chrome" from the one crea
koz (OOO until 15th September)
2012/03/26 01:36:09
I think better to not. This method is already way
| |
| 542 v8::Handle<v8::Object> chrome_hidden = | |
| 543 ChromeV8Context::GetOrCreateChromeHidden(v8_context)->ToObject(); | |
| 544 optimized_bindings[*i](module_system.get(), chrome, chrome_hidden); | |
| 545 continue; | |
| 546 } | |
|
not at google - send to devlin
2012/03/25 22:42:58
nit: else not continue
koz (OOO until 15th September)
2012/03/26 01:36:09
Done.
| |
| 516 module_system->Require(*i); | 547 module_system->Require(*i); |
| 517 } | 548 } |
| 518 | 549 |
| 519 module_system->set_natives_enabled(false); | 550 module_system->set_natives_enabled(false); |
| 520 | 551 |
| 521 context->set_module_system(module_system.Pass()); | 552 context->set_module_system(module_system.Pass()); |
| 522 | 553 |
| 523 context->DispatchOnLoadEvent( | 554 context->DispatchOnLoadEvent( |
| 524 is_extension_process_, | 555 is_extension_process_, |
| 525 ChromeRenderProcessObserver::is_incognito_process(), | 556 ChromeRenderProcessObserver::is_incognito_process(), |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 return Feature::BLESSED_EXTENSION_CONTEXT; | 733 return Feature::BLESSED_EXTENSION_CONTEXT; |
| 703 | 734 |
| 704 if (extensions_.ExtensionBindingsAllowed(url_info)) | 735 if (extensions_.ExtensionBindingsAllowed(url_info)) |
| 705 return Feature::UNBLESSED_EXTENSION_CONTEXT; | 736 return Feature::UNBLESSED_EXTENSION_CONTEXT; |
| 706 | 737 |
| 707 if (url_info.url().is_valid()) | 738 if (url_info.url().is_valid()) |
| 708 return Feature::WEB_PAGE_CONTEXT; | 739 return Feature::WEB_PAGE_CONTEXT; |
| 709 | 740 |
| 710 return Feature::UNSPECIFIED_CONTEXT; | 741 return Feature::UNSPECIFIED_CONTEXT; |
| 711 } | 742 } |
| OLD | NEW |