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

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

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 7 years, 10 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/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
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
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
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
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
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_schema", IDR_JSON_SCHEMA_JS); 748 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS);
630 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS); 749 source_map_.RegisterSource("test", IDR_EXTENSION_APITEST_JS);
631 750
632 // Libraries. 751 // Libraries.
633 source_map_.RegisterSource("contentWatcher", IDR_CONTENT_WATCHER_JS); 752 source_map_.RegisterSource("contentWatcher", IDR_CONTENT_WATCHER_JS);
634 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); 753 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS);
635 source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS); 754 source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS);
636 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS); 755 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS);
637 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS); 756 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS);
638 source_map_.RegisterSource("utils", IDR_UTILS_JS); 757 source_map_.RegisterSource("utils", IDR_UTILS_JS);
639 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); 758 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER);
640 759
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS); 803 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS);
685 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS); 804 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS);
686 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); 805 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS);
687 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); 806 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS);
688 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); 807 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS);
689 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); 808 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS);
690 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); 809 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS);
691 source_map_.RegisterSource("webRequestInternal", 810 source_map_.RegisterSource("webRequestInternal",
692 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); 811 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS);
693 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); 812 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS);
813 source_map_.RegisterSource("binding", IDR_BINDING_JS);
694 814
695 // Platform app sources that are not API-specific.. 815 // Platform app sources that are not API-specific..
696 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS); 816 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS);
697 source_map_.RegisterSource("webview", IDR_WEB_VIEW_JS); 817 source_map_.RegisterSource("web_view", IDR_WEB_VIEW_JS);
698 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS); 818 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS);
699 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); 819 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS);
700 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS); 820 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS);
701 } 821 }
702 822
703 void Dispatcher::PopulateLazyBindingsMap() { 823 void Dispatcher::PopulateLazyBindingsMap() {
704 lazy_bindings_map_["app"] = InstallAppBindings; 824 lazy_bindings_map_["app"] = InstallAppBindings;
705 lazy_bindings_map_["webstore"] = InstallWebstoreBindings; 825 lazy_bindings_map_["webstore"] = InstallWebstoreBindings;
706 } 826 }
707 827
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 v8_context_set_.Add(context); 881 v8_context_set_.Add(context);
762 882
763 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, 883 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context,
764 &source_map_)); 884 &source_map_));
765 // Enable natives in startup. 885 // Enable natives in startup.
766 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); 886 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get());
767 887
768 RegisterNativeHandlers(module_system.get(), context); 888 RegisterNativeHandlers(module_system.get(), context);
769 889
770 v8::Isolate* isolate = v8_context->GetIsolate(); 890 v8::Isolate* isolate = v8_context->GetIsolate();
891 module_system->RegisterNativeHandler("chrome",
892 scoped_ptr<NativeHandler>(new ChromeNativeHandler(isolate)));
771 module_system->RegisterNativeHandler("chrome_hidden", 893 module_system->RegisterNativeHandler("chrome_hidden",
772 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler(isolate))); 894 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler(isolate)));
773 module_system->RegisterNativeHandler("print", 895 module_system->RegisterNativeHandler("print",
774 scoped_ptr<NativeHandler>(new PrintNativeHandler(isolate))); 896 scoped_ptr<NativeHandler>(new PrintNativeHandler(isolate)));
775 module_system->RegisterNativeHandler("lazy_background_page", 897 module_system->RegisterNativeHandler("lazy_background_page",
776 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); 898 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this)));
777 module_system->RegisterNativeHandler("logging", 899 module_system->RegisterNativeHandler("logging",
778 scoped_ptr<NativeHandler>(new LoggingNativeHandler(isolate))); 900 scoped_ptr<NativeHandler>(new LoggingNativeHandler(isolate)));
901 module_system->RegisterNativeHandler("schema_registry",
902 scoped_ptr<NativeHandler>(
903 new SchemaRegistryNativeHandler(v8_schema_registry(), isolate)));
904 module_system->RegisterNativeHandler("v8_context",
905 scoped_ptr<NativeHandler>(new V8ContextNativeHandler(context, isolate)));
779 906
780 int manifest_version = extension ? extension->manifest_version() : 1; 907 int manifest_version = extension ? extension->manifest_version() : 1;
781 bool send_request_disabled = 908 bool send_request_disabled =
782 (extension && extension->location() == Manifest::LOAD && 909 (extension && extension->location() == Manifest::LOAD &&
783 extension->has_lazy_background_page()); 910 extension->has_lazy_background_page());
784 module_system->RegisterNativeHandler("process", 911 module_system->RegisterNativeHandler("process",
785 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( 912 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler(
786 this, context->GetExtensionID(), 913 this, context->GetExtensionID(),
787 context->GetContextTypeDescription(), 914 context->GetContextTypeDescription(),
788 ChromeRenderProcessObserver::is_incognito_process(), 915 ChromeRenderProcessObserver::is_incognito_process(),
789 manifest_version, send_request_disabled))); 916 manifest_version, send_request_disabled)));
790 917
791 GetOrCreateChrome(v8_context); 918 GetOrCreateChrome(v8_context);
792 919
793 // Loading JavaScript is expensive, so only run the full API bindings 920 // Loading JavaScript is expensive, so only run the full API bindings
794 // generation mechanisms in extension pages (NOT all web pages). 921 // generation mechanisms in extension pages (NOT all web pages).
795 switch (context_type) { 922 switch (context_type) {
796 case Feature::UNSPECIFIED_CONTEXT: 923 case Feature::UNSPECIFIED_CONTEXT:
797 case Feature::WEB_PAGE_CONTEXT: 924 case Feature::WEB_PAGE_CONTEXT:
798 // TODO(kalman): see comment below about ExtensionAPI. 925 // TODO(kalman): see comment below about ExtensionAPI.
799 InstallBindings(module_system.get(), v8_context, "app"); 926 InstallBindings(module_system.get(), v8_context, "app");
800 InstallBindings(module_system.get(), v8_context, "webstore"); 927 InstallBindings(module_system.get(), v8_context, "webstore");
801 break; 928 break;
802
803 case Feature::BLESSED_EXTENSION_CONTEXT: 929 case Feature::BLESSED_EXTENSION_CONTEXT:
804 case Feature::UNBLESSED_EXTENSION_CONTEXT: 930 case Feature::UNBLESSED_EXTENSION_CONTEXT:
805 case Feature::CONTENT_SCRIPT_CONTEXT: { 931 case Feature::CONTENT_SCRIPT_CONTEXT: {
806 module_system->Require("miscellaneous_bindings"); 932 if (extension && !extension->is_platform_app())
807 module_system->Require("schema_generated_bindings"); 933 module_system->Require("miscellaneous_bindings");
808 module_system->Require("apitest");
809 934
810 // TODO(kalman): move this code back out of the switch and execute it 935 // TODO(kalman): move this code back out of the switch and execute it
811 // regardless of |context_type|. ExtensionAPI knows how to return the 936 // 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 937 // correct APIs, however, until it doesn't have a 2MB overhead we can't
813 // load it in every process. 938 // load it in every process.
814 const std::set<std::string>& apis = context->GetAvailableExtensionAPIs(); 939 RegisterSchemaGeneratedBindings(module_system.get(),
815 for (std::set<std::string>::const_iterator i = apis.begin(); 940 context,
816 i != apis.end(); ++i) { 941 v8_context);
817 InstallBindings(module_system.get(), v8_context, *i);
818 }
819 942
943 // TODO(cduvall): Hack for loading chromeHidden.JSON before an extension
944 // can trash the global JSON object (event.js).
945 // This is for ExtensionApiTest.Messaging.
946 module_system->Require("event_bindings");
820 break; 947 break;
821 } 948 }
822 } 949 }
823 950
824 // Inject custom JS into the platform app context. 951 // Inject custom JS into the platform app context.
825 if (IsWithinPlatformApp(frame)) 952 if (IsWithinPlatformApp(frame))
826 module_system->Require("platformApp"); 953 module_system->Require("platformApp");
827 954
828 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { 955 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) {
829 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView); 956 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView);
830 module_system->Require(has_permission ? "webview" : "denyWebview"); 957 module_system->Require(has_permission ? "web_view" : "denyWebview");
831 } 958 }
832 959
833 context->set_module_system(module_system.Pass()); 960 context->set_module_system(module_system.Pass());
834 961
835 context->DispatchOnLoadEvent( 962 context->DispatchOnLoadEvent(
836 ChromeRenderProcessObserver::is_incognito_process(), 963 ChromeRenderProcessObserver::is_incognito_process(),
837 manifest_version); 964 manifest_version);
838 965
839 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); 966 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size();
840 } 967 }
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); 1276 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
1150 v8::ThrowException( 1277 v8::ThrowException(
1151 v8::Exception::Error(v8::String::New(error_msg.c_str()))); 1278 v8::Exception::Error(v8::String::New(error_msg.c_str())));
1152 return false; 1279 return false;
1153 } 1280 }
1154 1281
1155 return true; 1282 return true;
1156 } 1283 }
1157 1284
1158 } // namespace extensions 1285 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698