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