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/dispatcher.h" | 5 #include "chrome/renderer/extensions/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" |
| 11 #include "base/string_split.h" | |
| 11 #include "chrome/common/child_process_logging.h" | 12 #include "chrome/common/child_process_logging.h" |
| 12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/chrome_version_info.h" | 14 #include "chrome/common/chrome_version_info.h" |
| 14 #include "chrome/common/extensions/api/extension_api.h" | 15 #include "chrome/common/extensions/api/extension_api.h" |
| 15 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/extensions/extension_messages.h" | 17 #include "chrome/common/extensions/extension_messages.h" |
| 17 #include "chrome/common/extensions/manifest.h" | 18 #include "chrome/common/extensions/manifest.h" |
| 18 #include "chrome/common/extensions/permissions/permission_set.h" | 19 #include "chrome/common/extensions/permissions/permission_set.h" |
| 19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 20 #include "chrome/common/view_type.h" | 21 #include "chrome/common/view_type.h" |
| 21 #include "chrome/renderer/chrome_render_process_observer.h" | 22 #include "chrome/renderer/chrome_render_process_observer.h" |
| 22 #include "chrome/renderer/extensions/api_definitions_natives.h" | 23 #include "chrome/renderer/extensions/api_definitions_natives.h" |
| 23 #include "chrome/renderer/extensions/app_bindings.h" | 24 #include "chrome/renderer/extensions/app_bindings.h" |
| 24 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h" | 25 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h" |
| 25 #include "chrome/renderer/extensions/app_window_custom_bindings.h" | 26 #include "chrome/renderer/extensions/app_window_custom_bindings.h" |
| 27 #include "chrome/renderer/extensions/binding_generating_native_handler.h" | |
| 26 #include "chrome/renderer/extensions/chrome_v8_context.h" | 28 #include "chrome/renderer/extensions/chrome_v8_context.h" |
| 27 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 29 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
| 28 #include "chrome/renderer/extensions/content_watcher.h" | 30 #include "chrome/renderer/extensions/content_watcher.h" |
| 29 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" | 31 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" |
| 30 #include "chrome/renderer/extensions/event_bindings.h" | 32 #include "chrome/renderer/extensions/event_bindings.h" |
| 31 #include "chrome/renderer/extensions/extension_custom_bindings.h" | 33 #include "chrome/renderer/extensions/extension_custom_bindings.h" |
| 32 #include "chrome/renderer/extensions/extension_groups.h" | 34 #include "chrome/renderer/extensions/extension_groups.h" |
| 33 #include "chrome/renderer/extensions/extension_helper.h" | 35 #include "chrome/renderer/extensions/extension_helper.h" |
| 34 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" | 36 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" |
| 35 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" | 37 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" |
| 36 #include "chrome/renderer/extensions/file_system_natives.h" | 38 #include "chrome/renderer/extensions/file_system_natives.h" |
| 37 #include "chrome/renderer/extensions/i18n_custom_bindings.h" | 39 #include "chrome/renderer/extensions/i18n_custom_bindings.h" |
| 38 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" | 40 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" |
| 39 #include "chrome/renderer/extensions/miscellaneous_bindings.h" | 41 #include "chrome/renderer/extensions/miscellaneous_bindings.h" |
| 40 #include "chrome/renderer/extensions/module_system.h" | 42 #include "chrome/renderer/extensions/module_system.h" |
| 41 #include "chrome/renderer/extensions/native_handler.h" | 43 #include "chrome/renderer/extensions/object_backed_native_handler.h" |
| 42 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" | 44 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" |
| 43 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" | 45 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" |
| 44 #include "chrome/renderer/extensions/request_sender.h" | 46 #include "chrome/renderer/extensions/request_sender.h" |
| 45 #include "chrome/renderer/extensions/runtime_custom_bindings.h" | 47 #include "chrome/renderer/extensions/runtime_custom_bindings.h" |
| 46 #include "chrome/renderer/extensions/send_request_natives.h" | 48 #include "chrome/renderer/extensions/send_request_natives.h" |
| 47 #include "chrome/renderer/extensions/set_icon_natives.h" | 49 #include "chrome/renderer/extensions/set_icon_natives.h" |
| 48 #include "chrome/renderer/extensions/sync_file_system_custom_bindings.h" | 50 #include "chrome/renderer/extensions/sync_file_system_custom_bindings.h" |
| 49 #include "chrome/renderer/extensions/tab_finder.h" | 51 #include "chrome/renderer/extensions/tab_finder.h" |
| 50 #include "chrome/renderer/extensions/tabs_custom_bindings.h" | 52 #include "chrome/renderer/extensions/tabs_custom_bindings.h" |
| 51 #include "chrome/renderer/extensions/tts_custom_bindings.h" | 53 #include "chrome/renderer/extensions/tts_custom_bindings.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 82 namespace extensions { | 84 namespace extensions { |
| 83 | 85 |
| 84 namespace { | 86 namespace { |
| 85 | 87 |
| 86 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; | 88 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; |
| 87 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; | 89 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; |
| 88 static const char kEventDispatchFunction[] = "Event.dispatchEvent"; | 90 static const char kEventDispatchFunction[] = "Event.dispatchEvent"; |
| 89 static const char kOnUnloadEvent[] = "runtime.onSuspend"; | 91 static const char kOnUnloadEvent[] = "runtime.onSuspend"; |
| 90 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; | 92 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; |
| 91 | 93 |
| 92 class ChromeHiddenNativeHandler : public NativeHandler { | 94 static v8::Handle<v8::Object> GetOrCreateChrome( |
| 95 v8::Handle<v8::Context> context) { | |
| 96 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); | |
| 97 v8::Handle<v8::Object> global(context->Global()); | |
| 98 v8::Handle<v8::Value> chrome(global->Get(chrome_string)); | |
| 99 if (chrome.IsEmpty() || chrome->IsUndefined()) { | |
| 100 v8::Handle<v8::Object> chrome_object(v8::Object::New()); | |
| 101 global->Set(chrome_string, chrome_object); | |
| 102 return chrome_object; | |
| 103 } | |
| 104 CHECK(chrome->IsObject()); | |
| 105 return chrome->ToObject(); | |
| 106 } | |
| 107 | |
| 108 class SchemaRegistryNativeHandler : public ObjectBackedNativeHandler { | |
| 109 public: | |
| 110 SchemaRegistryNativeHandler(V8SchemaRegistry* registry, v8::Isolate* isolate) | |
| 111 : ObjectBackedNativeHandler(isolate), | |
| 112 registry_(registry) { | |
| 113 RouteFunction("GetSchema", | |
| 114 base::Bind(&SchemaRegistryNativeHandler::GetSchema, | |
| 115 base::Unretained(this))); | |
| 116 } | |
| 117 | |
| 118 private: | |
| 119 v8::Handle<v8::Value> GetSchema(const v8::Arguments& args) { | |
| 120 return registry_->GetSchema(*v8::String::AsciiValue(args[0])); | |
| 121 } | |
| 122 | |
| 123 V8SchemaRegistry* registry_; | |
| 124 }; | |
| 125 | |
| 126 class V8ContextNativeHandler : public ObjectBackedNativeHandler { | |
| 127 public: | |
| 128 V8ContextNativeHandler(ChromeV8Context* context, v8::Isolate* isolate) | |
| 129 : ObjectBackedNativeHandler(isolate), | |
| 130 context_(context) { | |
| 131 RouteFunction("GetAvailability", | |
| 132 base::Bind(&V8ContextNativeHandler::GetAvailability, | |
| 133 base::Unretained(this))); | |
| 134 } | |
| 135 | |
| 136 private: | |
| 137 v8::Handle<v8::Value> GetAvailability(const v8::Arguments& args) { | |
| 138 if (args.Length() < 1) | |
| 139 return v8::Undefined(); | |
|
not at google - send to devlin
2013/02/13 01:45:49
CHECK?
cduvall
2013/02/15 00:40:28
Done.
| |
| 140 | |
| 141 std::string api_name = *v8::String::AsciiValue(args[0]->ToString()); | |
| 142 v8::Handle<v8::Object> ret = v8::Object::New(); | |
| 143 const std::set<std::string>& available_apis = | |
| 144 context_->GetAvailableExtensionAPIs(); | |
| 145 | |
| 146 if (available_apis.find(api_name) == available_apis.end()) { | |
| 147 ret->Set(v8::String::New("is_available"), v8::Boolean::New(false)); | |
| 148 ret->Set(v8::String::New("message"), v8::String::New("SORRY!")); | |
| 149 } else { | |
| 150 ret->Set(v8::String::New("is_available"), v8::Boolean::New(true)); | |
| 151 } | |
|
not at google - send to devlin
2013/02/13 01:45:49
Heh - ok so let's add a GetAvailability method to
cduvall
2013/02/15 00:40:28
Done.
| |
| 152 return ret; | |
| 153 } | |
| 154 | |
| 155 ChromeV8Context* context_; | |
| 156 }; | |
| 157 | |
| 158 class ChromeHiddenNativeHandler : public ObjectBackedNativeHandler { | |
| 93 public: | 159 public: |
| 94 explicit ChromeHiddenNativeHandler(v8::Isolate* isolate) | 160 explicit ChromeHiddenNativeHandler(v8::Isolate* isolate) |
| 95 : NativeHandler(isolate) { | 161 : ObjectBackedNativeHandler(isolate) { |
| 96 RouteFunction("GetChromeHidden", | 162 RouteFunction("GetChromeHidden", |
| 97 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, | 163 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, |
| 98 base::Unretained(this))); | 164 base::Unretained(this))); |
| 99 } | 165 } |
| 100 | 166 |
| 101 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) { | 167 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) { |
| 102 return ChromeV8Context::GetOrCreateChromeHidden(v8::Context::GetCurrent()); | 168 return ChromeV8Context::GetOrCreateChromeHidden(v8::Context::GetCurrent()); |
| 103 } | 169 } |
| 104 }; | 170 }; |
| 105 | 171 |
| 106 class PrintNativeHandler : public NativeHandler { | 172 class ChromeNativeHandler : public ObjectBackedNativeHandler { |
| 173 public: | |
| 174 explicit ChromeNativeHandler(v8::Isolate* isolate) | |
| 175 : ObjectBackedNativeHandler(isolate) { | |
| 176 RouteFunction("GetChrome", | |
| 177 base::Bind(&ChromeNativeHandler::GetChrome, base::Unretained(this))); | |
| 178 } | |
| 179 | |
| 180 v8::Handle<v8::Value> GetChrome(const v8::Arguments& args) { | |
| 181 return GetOrCreateChrome(v8::Context::GetCurrent()); | |
| 182 } | |
| 183 }; | |
| 184 | |
| 185 class PrintNativeHandler : public ObjectBackedNativeHandler { | |
| 107 public: | 186 public: |
| 108 explicit PrintNativeHandler(v8::Isolate* isolate) | 187 explicit PrintNativeHandler(v8::Isolate* isolate) |
| 109 : NativeHandler(isolate) { | 188 : ObjectBackedNativeHandler(isolate) { |
| 110 RouteFunction("Print", | 189 RouteFunction("Print", |
| 111 base::Bind(&PrintNativeHandler::Print, | 190 base::Bind(&PrintNativeHandler::Print, |
| 112 base::Unretained(this))); | 191 base::Unretained(this))); |
| 113 } | 192 } |
| 114 | 193 |
| 115 v8::Handle<v8::Value> Print(const v8::Arguments& args) { | 194 v8::Handle<v8::Value> Print(const v8::Arguments& args) { |
| 116 if (args.Length() < 1) | 195 if (args.Length() < 1) |
| 117 return v8::Undefined(); | 196 return v8::Undefined(); |
| 118 | 197 |
| 119 std::vector<std::string> components; | 198 std::vector<std::string> components; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 } | 310 } |
| 232 | 311 |
| 233 private: | 312 private: |
| 234 std::string extension_id_; | 313 std::string extension_id_; |
| 235 std::string context_type_; | 314 std::string context_type_; |
| 236 bool is_incognito_context_; | 315 bool is_incognito_context_; |
| 237 int manifest_version_; | 316 int manifest_version_; |
| 238 bool send_request_disabled_; | 317 bool send_request_disabled_; |
| 239 }; | 318 }; |
| 240 | 319 |
| 241 class LoggingNativeHandler : public NativeHandler { | 320 class LoggingNativeHandler : public ObjectBackedNativeHandler { |
| 242 public: | 321 public: |
| 243 explicit LoggingNativeHandler(v8::Isolate* isolate) | 322 explicit LoggingNativeHandler(v8::Isolate* isolate) |
| 244 : NativeHandler(isolate) { | 323 : ObjectBackedNativeHandler(isolate) { |
| 245 RouteFunction("DCHECK", | 324 RouteFunction("DCHECK", |
| 246 base::Bind(&LoggingNativeHandler::Dcheck, | 325 base::Bind(&LoggingNativeHandler::Dcheck, |
| 247 base::Unretained(this))); | 326 base::Unretained(this))); |
| 248 } | 327 } |
| 249 | 328 |
| 250 v8::Handle<v8::Value> Dcheck(const v8::Arguments& args) { | 329 v8::Handle<v8::Value> Dcheck(const v8::Arguments& args) { |
| 251 CHECK_LE(args.Length(), 2); | 330 CHECK_LE(args.Length(), 2); |
| 252 bool check_value = args[0]->BooleanValue(); | 331 bool check_value = args[0]->BooleanValue(); |
| 253 std::string error_message; | 332 std::string error_message; |
| 254 if (args.Length() == 2) | 333 if (args.Length() == 2) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 } | 374 } |
| 296 | 375 |
| 297 void InstallWebstoreBindings(ModuleSystem* module_system, | 376 void InstallWebstoreBindings(ModuleSystem* module_system, |
| 298 v8::Handle<v8::Object> chrome, | 377 v8::Handle<v8::Object> chrome, |
| 299 v8::Handle<v8::Object> chrome_hidden) { | 378 v8::Handle<v8::Object> chrome_hidden) { |
| 300 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore"); | 379 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore"); |
| 301 module_system->SetLazyField(chrome_hidden, "webstore", "webstore", | 380 module_system->SetLazyField(chrome_hidden, "webstore", "webstore", |
| 302 "chromeHiddenWebstore"); | 381 "chromeHiddenWebstore"); |
| 303 } | 382 } |
| 304 | 383 |
| 305 static v8::Handle<v8::Object> GetOrCreateChrome( | |
| 306 v8::Handle<v8::Context> context) { | |
| 307 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); | |
| 308 v8::Handle<v8::Object> global(context->Global()); | |
| 309 v8::Handle<v8::Value> chrome(global->Get(chrome_string)); | |
| 310 if (chrome.IsEmpty() || chrome->IsUndefined()) { | |
| 311 v8::Handle<v8::Object> chrome_object(v8::Object::New()); | |
| 312 global->Set(chrome_string, chrome_object); | |
| 313 return chrome_object; | |
| 314 } | |
| 315 CHECK(chrome->IsObject()); | |
| 316 return chrome->ToObject(); | |
| 317 } | |
| 318 | |
| 319 } // namespace | 384 } // namespace |
| 320 | 385 |
| 321 Dispatcher::Dispatcher() | 386 Dispatcher::Dispatcher() |
| 322 : content_watcher_(new ContentWatcher(this)), | 387 : content_watcher_(new ContentWatcher(this)), |
| 323 is_webkit_initialized_(false), | 388 is_webkit_initialized_(false), |
| 324 webrequest_adblock_(false), | 389 webrequest_adblock_(false), |
| 325 webrequest_adblock_plus_(false), | 390 webrequest_adblock_plus_(false), |
| 326 webrequest_other_(false), | 391 webrequest_other_(false), |
| 327 source_map_(&ResourceBundle::GetSharedInstance()) { | 392 source_map_(&ResourceBundle::GetSharedInstance()) { |
| 328 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); | 393 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 } // namespace | 618 } // namespace |
| 554 | 619 |
| 555 bool Dispatcher::AllowScriptExtension(WebFrame* frame, | 620 bool Dispatcher::AllowScriptExtension(WebFrame* frame, |
| 556 const std::string& v8_extension_name, | 621 const std::string& v8_extension_name, |
| 557 int extension_group, | 622 int extension_group, |
| 558 int world_id) { | 623 int world_id) { |
| 559 g_hack_extension_group = extension_group; | 624 g_hack_extension_group = extension_group; |
| 560 return true; | 625 return true; |
| 561 } | 626 } |
| 562 | 627 |
| 628 v8::Handle<v8::Object> Dispatcher::GetOrCreateObject( | |
| 629 v8::Handle<v8::Object> object, | |
| 630 const std::string& field) { | |
| 631 v8::Handle<v8::String> key = v8::String::New(field.c_str()); | |
| 632 // This little dance is for APIs that may be unavailable but have available | |
| 633 // children. For example, chrome.app can be unavailable, while | |
| 634 // chrome.app.runtime is available. The lazy getter for chrome.app must be | |
| 635 // deleted, so that there isn't an error when accessing chrome.app.runtime. | |
| 636 if (object->Has(key)) { | |
| 637 v8::Handle<v8::Object> existing = | |
| 638 v8::Handle<v8::Object>::Cast(object->Get(key)); | |
| 639 if (!existing->IsUndefined()) | |
|
not at google - send to devlin
2013/02/13 01:45:49
koz@ can't remember which of the many existence ch
koz (OOO until 15th September)
2013/02/14 06:21:13
Just existing.IsEmpty() to make sure the handle is
cduvall
2013/02/15 00:40:28
Done.
| |
| 640 return existing; | |
| 641 else | |
| 642 object->Delete(key); | |
| 643 } | |
| 644 | |
| 645 v8::Handle<v8::Object> new_object = v8::Object::New(); | |
| 646 object->Set(key, new_object); | |
| 647 return new_object; | |
| 648 } | |
| 649 | |
| 650 void Dispatcher::RegisterSchemaGeneratedBindings( | |
| 651 ModuleSystem* module_system, | |
| 652 ChromeV8Context* context, | |
| 653 v8::Handle<v8::Context> v8_context) { | |
| 654 std::set<std::string> apis = | |
| 655 ExtensionAPI::GetSharedInstance()->GetAllAPINames(); | |
| 656 for (std::set<std::string>::iterator it = apis.begin(); | |
| 657 it != apis.end(); ++it) { | |
| 658 const std::string& api_name = *it; | |
| 659 | |
| 660 std::vector<std::string> split; | |
| 661 base::SplitString(api_name, '.', &split); | |
| 662 | |
| 663 v8::Handle<v8::Object> bind_object = GetOrCreateChrome(v8_context); | |
| 664 for (size_t i = 0; i < split.size() - 1; ++i) | |
| 665 bind_object = GetOrCreateObject(bind_object, split[i]); | |
| 666 | |
| 667 if (lazy_bindings_map_.find(api_name) != lazy_bindings_map_.end()) { | |
| 668 InstallBindings(module_system, v8_context, api_name); | |
| 669 } else if (!source_map_.Contains(api_name)) { | |
| 670 module_system->RegisterNativeHandler( | |
| 671 api_name, | |
| 672 scoped_ptr<NativeHandler>(new BindingGeneratingNativeHandler( | |
| 673 module_system, | |
| 674 v8_schema_registry(), | |
| 675 api_name, | |
| 676 "binding"))); | |
| 677 module_system->SetNativeLazyField(bind_object, | |
| 678 split.back(), | |
| 679 api_name, | |
| 680 "binding"); | |
| 681 } else { | |
| 682 module_system->SetLazyField(bind_object, | |
| 683 split.back(), | |
| 684 api_name, | |
| 685 "binding"); | |
| 686 } | |
| 687 } | |
| 688 } | |
| 689 | |
| 563 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 690 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
| 564 ChromeV8Context* context) { | 691 ChromeV8Context* context) { |
| 565 module_system->RegisterNativeHandler("event_bindings", | 692 module_system->RegisterNativeHandler("event_bindings", |
| 566 scoped_ptr<NativeHandler>(EventBindings::Get(this))); | 693 scoped_ptr<NativeHandler>(EventBindings::Get(this))); |
| 567 module_system->RegisterNativeHandler("miscellaneous_bindings", | 694 module_system->RegisterNativeHandler("miscellaneous_bindings", |
| 568 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); | 695 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); |
| 569 module_system->RegisterNativeHandler("apiDefinitions", | 696 module_system->RegisterNativeHandler("apiDefinitions", |
| 570 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); | 697 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); |
| 571 module_system->RegisterNativeHandler("sendRequest", | 698 module_system->RegisterNativeHandler("sendRequest", |
| 572 scoped_ptr<NativeHandler>( | 699 scoped_ptr<NativeHandler>( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 module_system->RegisterNativeHandler("web_request", | 744 module_system->RegisterNativeHandler("web_request", |
| 618 scoped_ptr<NativeHandler>(new WebRequestCustomBindings())); | 745 scoped_ptr<NativeHandler>(new WebRequestCustomBindings())); |
| 619 module_system->RegisterNativeHandler("webstore", | 746 module_system->RegisterNativeHandler("webstore", |
| 620 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); | 747 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); |
| 621 } | 748 } |
| 622 | 749 |
| 623 void Dispatcher::PopulateSourceMap() { | 750 void Dispatcher::PopulateSourceMap() { |
| 624 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); | 751 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); |
| 625 source_map_.RegisterSource("miscellaneous_bindings", | 752 source_map_.RegisterSource("miscellaneous_bindings", |
| 626 IDR_MISCELLANEOUS_BINDINGS_JS); | 753 IDR_MISCELLANEOUS_BINDINGS_JS); |
| 627 source_map_.RegisterSource("schema_generated_bindings", | |
| 628 IDR_SCHEMA_GENERATED_BINDINGS_JS); | |
| 629 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); | 754 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); |
| 630 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS); | 755 source_map_.RegisterSource("test", IDR_EXTENSION_APITEST_JS); |
| 631 | 756 |
| 632 // Libraries. | 757 // Libraries. |
| 633 source_map_.RegisterSource("contentWatcher", IDR_CONTENT_WATCHER_JS); | 758 source_map_.RegisterSource("contentWatcher", IDR_CONTENT_WATCHER_JS); |
| 634 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); | 759 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); |
| 635 source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS); | 760 source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS); |
| 636 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS); | 761 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS); |
| 637 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS); | 762 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS); |
| 638 source_map_.RegisterSource("utils", IDR_UTILS_JS); | 763 source_map_.RegisterSource("utils", IDR_UTILS_JS); |
| 639 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); | 764 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); |
| 640 | 765 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 684 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS); | 809 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS); |
| 685 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS); | 810 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS); |
| 686 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); | 811 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); |
| 687 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); | 812 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); |
| 688 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); | 813 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); |
| 689 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); | 814 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); |
| 690 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); | 815 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); |
| 691 source_map_.RegisterSource("webRequestInternal", | 816 source_map_.RegisterSource("webRequestInternal", |
| 692 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); | 817 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); |
| 693 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); | 818 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); |
| 819 source_map_.RegisterSource("binding", IDR_BINDING_JS); | |
| 694 | 820 |
| 695 // Platform app sources that are not API-specific.. | 821 // Platform app sources that are not API-specific.. |
| 696 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS); | 822 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS); |
| 697 source_map_.RegisterSource("webview", IDR_WEB_VIEW_JS); | 823 source_map_.RegisterSource("web_view", IDR_WEB_VIEW_JS); |
| 698 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS); | 824 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS); |
| 699 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); | 825 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); |
| 700 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS); | 826 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS); |
| 701 } | 827 } |
| 702 | 828 |
| 703 void Dispatcher::PopulateLazyBindingsMap() { | 829 void Dispatcher::PopulateLazyBindingsMap() { |
| 704 lazy_bindings_map_["app"] = InstallAppBindings; | 830 lazy_bindings_map_["app"] = InstallAppBindings; |
| 705 lazy_bindings_map_["webstore"] = InstallWebstoreBindings; | 831 lazy_bindings_map_["webstore"] = InstallWebstoreBindings; |
| 706 } | 832 } |
| 707 | 833 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 753 ExtensionURLInfo url_info(frame->document().securityOrigin(), | 879 ExtensionURLInfo url_info(frame->document().securityOrigin(), |
| 754 UserScriptSlave::GetDataSourceURLForFrame(frame)); | 880 UserScriptSlave::GetDataSourceURLForFrame(frame)); |
| 755 | 881 |
| 756 Feature::Context context_type = | 882 Feature::Context context_type = |
| 757 ClassifyJavaScriptContext(extension_id, extension_group, url_info); | 883 ClassifyJavaScriptContext(extension_id, extension_group, url_info); |
| 758 | 884 |
| 759 ChromeV8Context* context = | 885 ChromeV8Context* context = |
| 760 new ChromeV8Context(v8_context, frame, extension, context_type); | 886 new ChromeV8Context(v8_context, frame, extension, context_type); |
| 761 v8_context_set_.Add(context); | 887 v8_context_set_.Add(context); |
| 762 | 888 |
| 763 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, | 889 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(context, |
| 764 &source_map_)); | 890 &source_map_)); |
| 765 // Enable natives in startup. | 891 // Enable natives in startup. |
| 766 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); | 892 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); |
| 767 | 893 |
| 768 RegisterNativeHandlers(module_system.get(), context); | 894 RegisterNativeHandlers(module_system.get(), context); |
| 769 | 895 |
| 770 v8::Isolate* isolate = v8_context->GetIsolate(); | 896 v8::Isolate* isolate = v8_context->GetIsolate(); |
| 897 module_system->RegisterNativeHandler("chrome", | |
| 898 scoped_ptr<NativeHandler>(new ChromeNativeHandler(isolate))); | |
| 771 module_system->RegisterNativeHandler("chrome_hidden", | 899 module_system->RegisterNativeHandler("chrome_hidden", |
| 772 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler(isolate))); | 900 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler(isolate))); |
| 773 module_system->RegisterNativeHandler("print", | 901 module_system->RegisterNativeHandler("print", |
| 774 scoped_ptr<NativeHandler>(new PrintNativeHandler(isolate))); | 902 scoped_ptr<NativeHandler>(new PrintNativeHandler(isolate))); |
| 775 module_system->RegisterNativeHandler("lazy_background_page", | 903 module_system->RegisterNativeHandler("lazy_background_page", |
| 776 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); | 904 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); |
| 777 module_system->RegisterNativeHandler("logging", | 905 module_system->RegisterNativeHandler("logging", |
| 778 scoped_ptr<NativeHandler>(new LoggingNativeHandler(isolate))); | 906 scoped_ptr<NativeHandler>(new LoggingNativeHandler(isolate))); |
| 907 module_system->RegisterNativeHandler("schema_registry", | |
| 908 scoped_ptr<NativeHandler>( | |
| 909 new SchemaRegistryNativeHandler(v8_schema_registry(), isolate))); | |
| 910 module_system->RegisterNativeHandler("v8_context", | |
| 911 scoped_ptr<NativeHandler>(new V8ContextNativeHandler(context, isolate))); | |
| 779 | 912 |
| 780 int manifest_version = extension ? extension->manifest_version() : 1; | 913 int manifest_version = extension ? extension->manifest_version() : 1; |
| 781 bool send_request_disabled = | 914 bool send_request_disabled = |
| 782 (extension && extension->location() == Manifest::LOAD && | 915 (extension && extension->location() == Manifest::LOAD && |
| 783 extension->has_lazy_background_page()); | 916 extension->has_lazy_background_page()); |
| 784 module_system->RegisterNativeHandler("process", | 917 module_system->RegisterNativeHandler("process", |
| 785 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 918 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
| 786 this, context->GetExtensionID(), | 919 this, context->GetExtensionID(), |
| 787 context->GetContextTypeDescription(), | 920 context->GetContextTypeDescription(), |
| 788 ChromeRenderProcessObserver::is_incognito_process(), | 921 ChromeRenderProcessObserver::is_incognito_process(), |
| 789 manifest_version, send_request_disabled))); | 922 manifest_version, send_request_disabled))); |
| 790 | 923 |
| 791 GetOrCreateChrome(v8_context); | 924 GetOrCreateChrome(v8_context); |
| 792 | 925 |
| 793 // Loading JavaScript is expensive, so only run the full API bindings | 926 // Loading JavaScript is expensive, so only run the full API bindings |
| 794 // generation mechanisms in extension pages (NOT all web pages). | 927 // generation mechanisms in extension pages (NOT all web pages). |
| 795 switch (context_type) { | 928 switch (context_type) { |
| 796 case Feature::UNSPECIFIED_CONTEXT: | 929 case Feature::UNSPECIFIED_CONTEXT: |
| 797 case Feature::WEB_PAGE_CONTEXT: | 930 case Feature::WEB_PAGE_CONTEXT: |
| 798 // TODO(kalman): see comment below about ExtensionAPI. | 931 // TODO(kalman): see comment below about ExtensionAPI. |
| 799 InstallBindings(module_system.get(), v8_context, "app"); | 932 InstallBindings(module_system.get(), v8_context, "app"); |
| 800 InstallBindings(module_system.get(), v8_context, "webstore"); | 933 InstallBindings(module_system.get(), v8_context, "webstore"); |
| 801 break; | 934 break; |
| 802 | |
| 803 case Feature::BLESSED_EXTENSION_CONTEXT: | 935 case Feature::BLESSED_EXTENSION_CONTEXT: |
| 804 case Feature::UNBLESSED_EXTENSION_CONTEXT: | 936 case Feature::UNBLESSED_EXTENSION_CONTEXT: |
| 805 case Feature::CONTENT_SCRIPT_CONTEXT: { | 937 case Feature::CONTENT_SCRIPT_CONTEXT: { |
| 806 module_system->Require("miscellaneous_bindings"); | 938 if (extension && !extension->is_platform_app()) |
| 807 module_system->Require("schema_generated_bindings"); | 939 module_system->Require("miscellaneous_bindings"); |
| 808 module_system->Require("apitest"); | |
| 809 | 940 |
| 810 // TODO(kalman): move this code back out of the switch and execute it | 941 // TODO(kalman): move this code back out of the switch and execute it |
| 811 // regardless of |context_type|. ExtensionAPI knows how to return the | 942 // regardless of |context_type|. ExtensionAPI knows how to return the |
| 812 // correct APIs, however, until it doesn't have a 2MB overhead we can't | 943 // correct APIs, however, until it doesn't have a 2MB overhead we can't |
| 813 // load it in every process. | 944 // load it in every process. |
| 814 const std::set<std::string>& apis = context->GetAvailableExtensionAPIs(); | 945 RegisterSchemaGeneratedBindings(module_system.get(), |
| 815 for (std::set<std::string>::const_iterator i = apis.begin(); | 946 context, |
| 816 i != apis.end(); ++i) { | 947 v8_context); |
| 817 InstallBindings(module_system.get(), v8_context, *i); | |
| 818 } | |
| 819 | |
| 820 break; | 948 break; |
| 821 } | 949 } |
| 822 } | 950 } |
| 951 // TODO(cduvall): Hack for loading JSON into chromeHidden (event.js). | |
|
not at google - send to devlin
2013/02/13 01:45:49
what JSON?
cduvall
2013/02/15 00:40:28
Clarified the comment.
| |
| 952 // This is for ExtensionApiTest.Messaging. | |
| 953 module_system->Require("event_bindings"); | |
| 823 | 954 |
| 824 // Inject custom JS into the platform app context. | 955 // Inject custom JS into the platform app context. |
| 825 if (IsWithinPlatformApp(frame)) | 956 if (IsWithinPlatformApp(frame)) |
| 826 module_system->Require("platformApp"); | 957 module_system->Require("platformApp"); |
| 827 | 958 |
| 828 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 959 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
| 829 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView); | 960 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView); |
| 830 module_system->Require(has_permission ? "webview" : "denyWebview"); | 961 module_system->Require(has_permission ? "web_view" : "denyWebview"); |
| 831 } | 962 } |
| 832 | 963 |
| 833 context->set_module_system(module_system.Pass()); | 964 context->set_module_system(module_system.Pass()); |
| 834 | 965 |
| 835 context->DispatchOnLoadEvent( | 966 context->DispatchOnLoadEvent( |
| 836 ChromeRenderProcessObserver::is_incognito_process(), | 967 ChromeRenderProcessObserver::is_incognito_process(), |
| 837 manifest_version); | 968 manifest_version); |
| 838 | 969 |
| 839 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); | 970 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); |
| 840 } | 971 } |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1149 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1280 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
| 1150 v8::ThrowException( | 1281 v8::ThrowException( |
| 1151 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1282 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
| 1152 return false; | 1283 return false; |
| 1153 } | 1284 } |
| 1154 | 1285 |
| 1155 return true; | 1286 return true; |
| 1156 } | 1287 } |
| 1157 | 1288 |
| 1158 } // namespace extensions | 1289 } // namespace extensions |
| OLD | NEW |