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

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

Issue 240603003: Remove ChromeV8Extension & most of ChromeV8Context (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 6 years, 8 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/debug/alias.h" 9 #include "base/debug/alias.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/user_metrics_action.h" 12 #include "base/metrics/user_metrics_action.h"
13 #include "base/sha1.h" 13 #include "base/sha1.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_piece.h" 15 #include "base/strings/string_piece.h"
16 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/chrome_version_info.h" 19 #include "chrome/common/chrome_version_info.h"
20 #include "chrome/common/crash_keys.h" 20 #include "chrome/common/crash_keys.h"
21 #include "chrome/common/extensions/features/feature_channel.h" 21 #include "chrome/common/extensions/features/feature_channel.h"
22 #include "chrome/common/extensions/manifest_handlers/externally_connectable.h" 22 #include "chrome/common/extensions/manifest_handlers/externally_connectable.h"
23 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
24 #include "chrome/renderer/chrome_render_process_observer.h" 24 #include "chrome/renderer/chrome_render_process_observer.h"
25 #include "chrome/renderer/extensions/api_activity_logger.h" 25 #include "chrome/renderer/extensions/api_activity_logger.h"
26 #include "chrome/renderer/extensions/app_bindings.h" 26 #include "chrome/renderer/extensions/app_bindings.h"
27 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h" 27 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h"
28 #include "chrome/renderer/extensions/app_window_custom_bindings.h" 28 #include "chrome/renderer/extensions/app_window_custom_bindings.h"
29 #include "chrome/renderer/extensions/chrome_v8_context.h" 29 #include "chrome/renderer/extensions/chrome_v8_context.h"
30 #include "chrome/renderer/extensions/chrome_v8_extension.h"
31 #include "chrome/renderer/extensions/dom_activity_logger.h" 30 #include "chrome/renderer/extensions/dom_activity_logger.h"
32 #include "chrome/renderer/extensions/extension_helper.h" 31 #include "chrome/renderer/extensions/extension_helper.h"
33 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" 32 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h"
34 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" 33 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h"
35 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" 34 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h"
36 #include "chrome/renderer/extensions/messaging_bindings.h" 35 #include "chrome/renderer/extensions/messaging_bindings.h"
37 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" 36 #include "chrome/renderer/extensions/page_actions_custom_bindings.h"
38 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" 37 #include "chrome/renderer/extensions/page_capture_custom_bindings.h"
39 #include "chrome/renderer/extensions/pepper_request_natives.h" 38 #include "chrome/renderer/extensions/pepper_request_natives.h"
40 #include "chrome/renderer/extensions/runtime_custom_bindings.h" 39 #include "chrome/renderer/extensions/runtime_custom_bindings.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 #include "extensions/renderer/file_system_natives.h" 74 #include "extensions/renderer/file_system_natives.h"
76 #include "extensions/renderer/i18n_custom_bindings.h" 75 #include "extensions/renderer/i18n_custom_bindings.h"
77 #include "extensions/renderer/id_generator_custom_bindings.h" 76 #include "extensions/renderer/id_generator_custom_bindings.h"
78 #include "extensions/renderer/logging_native_handler.h" 77 #include "extensions/renderer/logging_native_handler.h"
79 #include "extensions/renderer/module_system.h" 78 #include "extensions/renderer/module_system.h"
80 #include "extensions/renderer/object_backed_native_handler.h" 79 #include "extensions/renderer/object_backed_native_handler.h"
81 #include "extensions/renderer/render_view_observer_natives.h" 80 #include "extensions/renderer/render_view_observer_natives.h"
82 #include "extensions/renderer/request_sender.h" 81 #include "extensions/renderer/request_sender.h"
83 #include "extensions/renderer/safe_builtins.h" 82 #include "extensions/renderer/safe_builtins.h"
84 #include "extensions/renderer/script_context.h" 83 #include "extensions/renderer/script_context.h"
84 #include "extensions/renderer/script_context_set.h"
85 #include "extensions/renderer/send_request_natives.h" 85 #include "extensions/renderer/send_request_natives.h"
86 #include "extensions/renderer/set_icon_natives.h" 86 #include "extensions/renderer/set_icon_natives.h"
87 #include "extensions/renderer/utils_native_handler.h" 87 #include "extensions/renderer/utils_native_handler.h"
88 #include "grit/common_resources.h" 88 #include "grit/common_resources.h"
89 #include "grit/renderer_resources.h" 89 #include "grit/renderer_resources.h"
90 #include "third_party/WebKit/public/platform/WebString.h" 90 #include "third_party/WebKit/public/platform/WebString.h"
91 #include "third_party/WebKit/public/platform/WebURLRequest.h" 91 #include "third_party/WebKit/public/platform/WebURLRequest.h"
92 #include "third_party/WebKit/public/web/WebCustomElement.h" 92 #include "third_party/WebKit/public/web/WebCustomElement.h"
93 #include "third_party/WebKit/public/web/WebDataSource.h" 93 #include "third_party/WebKit/public/web/WebDataSource.h"
94 #include "third_party/WebKit/public/web/WebDocument.h" 94 #include "third_party/WebKit/public/web/WebDocument.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 return chrome; 145 return chrome;
146 } 146 }
147 147
148 // Returns |value| cast to an object if possible, else an empty handle. 148 // Returns |value| cast to an object if possible, else an empty handle.
149 v8::Handle<v8::Object> AsObjectOrEmpty(v8::Handle<v8::Value> value) { 149 v8::Handle<v8::Object> AsObjectOrEmpty(v8::Handle<v8::Value> value) {
150 return value->IsObject() ? value.As<v8::Object>() : v8::Handle<v8::Object>(); 150 return value->IsObject() ? value.As<v8::Object>() : v8::Handle<v8::Object>();
151 } 151 }
152 152
153 class TestFeaturesNativeHandler : public ObjectBackedNativeHandler { 153 class TestFeaturesNativeHandler : public ObjectBackedNativeHandler {
154 public: 154 public:
155 explicit TestFeaturesNativeHandler(ChromeV8Context* context) 155 explicit TestFeaturesNativeHandler(ScriptContext* context)
156 : ObjectBackedNativeHandler(context) { 156 : ObjectBackedNativeHandler(context) {
157 RouteFunction("GetAPIFeatures", 157 RouteFunction("GetAPIFeatures",
158 base::Bind(&TestFeaturesNativeHandler::GetAPIFeatures, 158 base::Bind(&TestFeaturesNativeHandler::GetAPIFeatures,
159 base::Unretained(this))); 159 base::Unretained(this)));
160 } 160 }
161 161
162 private: 162 private:
163 void GetAPIFeatures(const v8::FunctionCallbackInfo<v8::Value>& args) { 163 void GetAPIFeatures(const v8::FunctionCallbackInfo<v8::Value>& args) {
164 base::Value* value = base::JSONReader::Read( 164 base::Value* value = base::JSONReader::Read(
165 ResourceBundle::GetSharedInstance().GetRawDataResource( 165 ResourceBundle::GetSharedInstance().GetRawDataResource(
166 IDR_EXTENSION_API_FEATURES).as_string()); 166 IDR_EXTENSION_API_FEATURES).as_string());
167 scoped_ptr<content::V8ValueConverter> converter( 167 scoped_ptr<content::V8ValueConverter> converter(
168 content::V8ValueConverter::create()); 168 content::V8ValueConverter::create());
169 args.GetReturnValue().Set( 169 args.GetReturnValue().Set(
170 converter->ToV8Value(value, context()->v8_context())); 170 converter->ToV8Value(value, context()->v8_context()));
171 } 171 }
172 }; 172 };
173 173
174 class UserGesturesNativeHandler : public ObjectBackedNativeHandler { 174 class UserGesturesNativeHandler : public ObjectBackedNativeHandler {
175 public: 175 public:
176 explicit UserGesturesNativeHandler(ChromeV8Context* context) 176 explicit UserGesturesNativeHandler(ScriptContext* context)
177 : ObjectBackedNativeHandler(context) { 177 : ObjectBackedNativeHandler(context) {
178 RouteFunction("IsProcessingUserGesture", 178 RouteFunction("IsProcessingUserGesture",
179 base::Bind(&UserGesturesNativeHandler::IsProcessingUserGesture, 179 base::Bind(&UserGesturesNativeHandler::IsProcessingUserGesture,
180 base::Unretained(this))); 180 base::Unretained(this)));
181 RouteFunction("RunWithUserGesture", 181 RouteFunction("RunWithUserGesture",
182 base::Bind(&UserGesturesNativeHandler::RunWithUserGesture, 182 base::Bind(&UserGesturesNativeHandler::RunWithUserGesture,
183 base::Unretained(this))); 183 base::Unretained(this)));
184 RouteFunction("RunWithoutUserGesture", 184 RouteFunction("RunWithoutUserGesture",
185 base::Bind(&UserGesturesNativeHandler::RunWithoutUserGesture, 185 base::Bind(&UserGesturesNativeHandler::RunWithoutUserGesture,
186 base::Unretained(this))); 186 base::Unretained(this)));
(...skipping 23 matching lines...) Expand all
210 CHECK_EQ(args.Length(), 1); 210 CHECK_EQ(args.Length(), 1);
211 CHECK(args[0]->IsFunction()); 211 CHECK(args[0]->IsFunction());
212 v8::Handle<v8::Value> no_args; 212 v8::Handle<v8::Value> no_args;
213 context()->CallFunction(v8::Handle<v8::Function>::Cast(args[0]), 213 context()->CallFunction(v8::Handle<v8::Function>::Cast(args[0]),
214 0, &no_args); 214 0, &no_args);
215 } 215 }
216 }; 216 };
217 217
218 class V8ContextNativeHandler : public ObjectBackedNativeHandler { 218 class V8ContextNativeHandler : public ObjectBackedNativeHandler {
219 public: 219 public:
220 V8ContextNativeHandler(ChromeV8Context* context, Dispatcher* dispatcher) 220 V8ContextNativeHandler(ScriptContext* context, Dispatcher* dispatcher)
221 : ObjectBackedNativeHandler(context), 221 : ObjectBackedNativeHandler(context),
222 context_(context), 222 context_(context),
223 dispatcher_(dispatcher) { 223 dispatcher_(dispatcher) {
224 RouteFunction("GetAvailability", 224 RouteFunction("GetAvailability",
225 base::Bind(&V8ContextNativeHandler::GetAvailability, 225 base::Bind(&V8ContextNativeHandler::GetAvailability,
226 base::Unretained(this))); 226 base::Unretained(this)));
227 RouteFunction("GetModuleSystem", 227 RouteFunction("GetModuleSystem",
228 base::Bind(&V8ContextNativeHandler::GetModuleSystem, 228 base::Bind(&V8ContextNativeHandler::GetModuleSystem,
229 base::Unretained(this))); 229 base::Unretained(this)));
230 } 230 }
(...skipping 13 matching lines...) Expand all
244 ret->Set(v8::String::NewFromUtf8(isolate, "result"), 244 ret->Set(v8::String::NewFromUtf8(isolate, "result"),
245 v8::Integer::New(isolate, availability.result())); 245 v8::Integer::New(isolate, availability.result()));
246 args.GetReturnValue().Set(ret); 246 args.GetReturnValue().Set(ret);
247 } 247 }
248 248
249 void GetModuleSystem(const v8::FunctionCallbackInfo<v8::Value>& args) { 249 void GetModuleSystem(const v8::FunctionCallbackInfo<v8::Value>& args) {
250 CHECK_EQ(args.Length(), 1); 250 CHECK_EQ(args.Length(), 1);
251 CHECK(args[0]->IsObject()); 251 CHECK(args[0]->IsObject());
252 v8::Handle<v8::Context> v8_context = 252 v8::Handle<v8::Context> v8_context =
253 v8::Handle<v8::Object>::Cast(args[0])->CreationContext(); 253 v8::Handle<v8::Object>::Cast(args[0])->CreationContext();
254 ChromeV8Context* context = dispatcher_->v8_context_set().GetByV8Context( 254 ScriptContext* context =
255 v8_context); 255 dispatcher_->script_context_set().GetByV8Context(v8_context);
256 args.GetReturnValue().Set(context->module_system()->NewInstance()); 256 args.GetReturnValue().Set(context->module_system()->NewInstance());
257 } 257 }
258 258
259 ChromeV8Context* context_; 259 ScriptContext* context_;
260 Dispatcher* dispatcher_; 260 Dispatcher* dispatcher_;
261 }; 261 };
262 262
263 class ChromeNativeHandler : public ObjectBackedNativeHandler { 263 class ChromeNativeHandler : public ObjectBackedNativeHandler {
264 public: 264 public:
265 explicit ChromeNativeHandler(ChromeV8Context* context) 265 explicit ChromeNativeHandler(ScriptContext* context)
266 : ObjectBackedNativeHandler(context) { 266 : ObjectBackedNativeHandler(context) {
267 RouteFunction("GetChrome", 267 RouteFunction("GetChrome",
268 base::Bind(&ChromeNativeHandler::GetChrome, base::Unretained(this))); 268 base::Bind(&ChromeNativeHandler::GetChrome, base::Unretained(this)));
269 } 269 }
270 270
271 void GetChrome(const v8::FunctionCallbackInfo<v8::Value>& args) { 271 void GetChrome(const v8::FunctionCallbackInfo<v8::Value>& args) {
272 args.GetReturnValue().Set(GetOrCreateChrome(context())); 272 args.GetReturnValue().Set(GetOrCreateChrome(context()));
273 } 273 }
274 }; 274 };
275 275
276 class PrintNativeHandler : public ObjectBackedNativeHandler { 276 class PrintNativeHandler : public ObjectBackedNativeHandler {
277 public: 277 public:
278 explicit PrintNativeHandler(ChromeV8Context* context) 278 explicit PrintNativeHandler(ScriptContext* context)
279 : ObjectBackedNativeHandler(context) { 279 : ObjectBackedNativeHandler(context) {
280 RouteFunction("Print", 280 RouteFunction("Print",
281 base::Bind(&PrintNativeHandler::Print, 281 base::Bind(&PrintNativeHandler::Print,
282 base::Unretained(this))); 282 base::Unretained(this)));
283 } 283 }
284 284
285 void Print(const v8::FunctionCallbackInfo<v8::Value>& args) { 285 void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
286 if (args.Length() < 1) 286 if (args.Length() < 1)
287 return; 287 return;
288 288
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 module_system->SetLazyField(chrome, "app", "app", "chromeApp"); 420 module_system->SetLazyField(chrome, "app", "app", "chromeApp");
421 } 421 }
422 422
423 void InstallWebstoreBindings(ModuleSystem* module_system, 423 void InstallWebstoreBindings(ModuleSystem* module_system,
424 v8::Handle<v8::Object> chrome) { 424 v8::Handle<v8::Object> chrome) {
425 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore"); 425 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore");
426 } 426 }
427 427
428 // Calls a method |method_name| in a module |module_name| belonging to the 428 // Calls a method |method_name| in a module |module_name| belonging to the
429 // module system from |context|. Intended as a callback target from 429 // module system from |context|. Intended as a callback target from
430 // ChromeV8ContextSet::ForEach. 430 // ScriptContextSet::ForEach.
431 void CallModuleMethod(const std::string& module_name, 431 void CallModuleMethod(const std::string& module_name,
432 const std::string& method_name, 432 const std::string& method_name,
433 const base::ListValue* args, 433 const base::ListValue* args,
434 ChromeV8Context* context) { 434 ScriptContext* context) {
435 v8::HandleScope handle_scope(context->isolate()); 435 v8::HandleScope handle_scope(context->isolate());
436 v8::Context::Scope context_scope(context->v8_context()); 436 v8::Context::Scope context_scope(context->v8_context());
437 437
438 scoped_ptr<content::V8ValueConverter> converter( 438 scoped_ptr<content::V8ValueConverter> converter(
439 content::V8ValueConverter::create()); 439 content::V8ValueConverter::create());
440 440
441 std::vector<v8::Handle<v8::Value> > arguments; 441 std::vector<v8::Handle<v8::Value> > arguments;
442 for (base::ListValue::const_iterator it = args->begin(); it != args->end(); 442 for (base::ListValue::const_iterator it = args->begin(); it != args->end();
443 ++it) { 443 ++it) {
444 arguments.push_back(converter->ToV8Value(*it, context->v8_context())); 444 arguments.push_back(converter->ToV8Value(*it, context->v8_context()));
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 const std::string& channel_name, 586 const std::string& channel_name,
587 const base::DictionaryValue& source_tab, 587 const base::DictionaryValue& source_tab,
588 const ExtensionMsg_ExternalConnectionInfo& info, 588 const ExtensionMsg_ExternalConnectionInfo& info,
589 const std::string& tls_channel_id) { 589 const std::string& tls_channel_id) {
590 DCHECK(!ContainsKey(port_to_tab_id_map_, target_port_id)); 590 DCHECK(!ContainsKey(port_to_tab_id_map_, target_port_id));
591 DCHECK_EQ(1, target_port_id % 2); // target renderer ports have odd IDs. 591 DCHECK_EQ(1, target_port_id % 2); // target renderer ports have odd IDs.
592 int sender_tab_id = -1; 592 int sender_tab_id = -1;
593 source_tab.GetInteger("id", &sender_tab_id); 593 source_tab.GetInteger("id", &sender_tab_id);
594 port_to_tab_id_map_[target_port_id] = sender_tab_id; 594 port_to_tab_id_map_[target_port_id] = sender_tab_id;
595 595
596 MessagingBindings::DispatchOnConnect( 596 MessagingBindings::DispatchOnConnect(script_context_set_.GetAll(),
not at google - send to devlin 2014/04/17 15:11:10 MessagingBindings is another class that should be
597 v8_context_set_.GetAll(), 597 target_port_id,
598 target_port_id, channel_name, source_tab, 598 channel_name,
599 info.source_id, info.target_id, info.source_url, 599 source_tab,
600 tls_channel_id, 600 info.source_id,
601 NULL); // All render views. 601 info.target_id,
602 info.source_url,
603 tls_channel_id,
604 NULL); // All render views.
602 } 605 }
603 606
604 void Dispatcher::OnDeliverMessage(int target_port_id, 607 void Dispatcher::OnDeliverMessage(int target_port_id,
605 const Message& message) { 608 const Message& message) {
606 scoped_ptr<RequestSender::ScopedTabID> scoped_tab_id; 609 scoped_ptr<RequestSender::ScopedTabID> scoped_tab_id;
607 std::map<int, int>::const_iterator it = 610 std::map<int, int>::const_iterator it =
608 port_to_tab_id_map_.find(target_port_id); 611 port_to_tab_id_map_.find(target_port_id);
609 if (it != port_to_tab_id_map_.end()) { 612 if (it != port_to_tab_id_map_.end()) {
610 scoped_tab_id.reset(new RequestSender::ScopedTabID(request_sender(), 613 scoped_tab_id.reset(new RequestSender::ScopedTabID(request_sender(),
611 it->second)); 614 it->second));
612 } 615 }
613 616
614 MessagingBindings::DeliverMessage( 617 MessagingBindings::DeliverMessage(script_context_set_.GetAll(),
615 v8_context_set_.GetAll(), 618 target_port_id,
616 target_port_id, 619 message,
617 message, 620 NULL); // All render views.
618 NULL); // All render views.
619 } 621 }
620 622
621 void Dispatcher::OnDispatchOnDisconnect(int port_id, 623 void Dispatcher::OnDispatchOnDisconnect(int port_id,
622 const std::string& error_message) { 624 const std::string& error_message) {
623 MessagingBindings::DispatchOnDisconnect( 625 MessagingBindings::DispatchOnDisconnect(script_context_set_.GetAll(),
624 v8_context_set_.GetAll(), 626 port_id,
625 port_id, error_message, 627 error_message,
626 NULL); // All render views. 628 NULL); // All render views.
627 } 629 }
628 630
629 void Dispatcher::OnLoaded( 631 void Dispatcher::OnLoaded(
630 const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions) { 632 const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions) {
631 std::vector<ExtensionMsg_Loaded_Params>::const_iterator i; 633 std::vector<ExtensionMsg_Loaded_Params>::const_iterator i;
632 for (i = loaded_extensions.begin(); i != loaded_extensions.end(); ++i) { 634 for (i = loaded_extensions.begin(); i != loaded_extensions.end(); ++i) {
633 std::string error; 635 std::string error;
634 scoped_refptr<const Extension> extension = i->ConvertToExtension(&error); 636 scoped_refptr<const Extension> extension = i->ConvertToExtension(&error);
635 if (!extension.get()) { 637 if (!extension.get()) {
636 extension_load_errors_[i->id] = error; 638 extension_load_errors_[i->id] = error;
(...skipping 14 matching lines...) Expand all
651 void Dispatcher::OnUnloaded(const std::string& id) { 653 void Dispatcher::OnUnloaded(const std::string& id) {
652 extensions_.Remove(id); 654 extensions_.Remove(id);
653 active_extension_ids_.erase(id); 655 active_extension_ids_.erase(id);
654 656
655 // If the extension is later reloaded with a different set of permissions, 657 // If the extension is later reloaded with a different set of permissions,
656 // we'd like it to get a new isolated world ID, so that it can pick up the 658 // we'd like it to get a new isolated world ID, so that it can pick up the
657 // changed origin whitelist. 659 // changed origin whitelist.
658 user_script_slave_->RemoveIsolatedWorld(id); 660 user_script_slave_->RemoveIsolatedWorld(id);
659 661
660 // Invalidate all of the contexts that were removed. 662 // Invalidate all of the contexts that were removed.
661 // TODO(kalman): add an invalidation observer interface to ChromeV8Context. 663 // TODO(kalman): add an invalidation observer interface to ScriptContext.
662 ChromeV8ContextSet::ContextSet removed_contexts = 664 ScriptContextSet::ContextSet removed_contexts =
663 v8_context_set_.OnExtensionUnloaded(id); 665 script_context_set_.OnExtensionUnloaded(id);
664 for (ChromeV8ContextSet::ContextSet::iterator it = removed_contexts.begin(); 666 for (ScriptContextSet::ContextSet::iterator it = removed_contexts.begin();
665 it != removed_contexts.end(); ++it) { 667 it != removed_contexts.end();
668 ++it) {
666 request_sender_->InvalidateSource(*it); 669 request_sender_->InvalidateSource(*it);
667 } 670 }
668 671
669 // Update the available bindings for the remaining contexts. These may have 672 // Update the available bindings for the remaining contexts. These may have
670 // changed if an externally_connectable extension is unloaded and a webpage 673 // changed if an externally_connectable extension is unloaded and a webpage
671 // is no longer accessible. 674 // is no longer accessible.
672 AddOrRemoveBindings(""); 675 AddOrRemoveBindings("");
673 676
674 // Invalidates the messages map for the extension in case the extension is 677 // Invalidates the messages map for the extension in case the extension is
675 // reloaded with a new messages map. 678 // reloaded with a new messages map.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 v8::Handle<v8::Value> value = object->Get(key); 711 v8::Handle<v8::Value> value = object->Get(key);
709 CHECK(value->IsObject()); 712 CHECK(value->IsObject());
710 return v8::Handle<v8::Object>::Cast(value); 713 return v8::Handle<v8::Object>::Cast(value);
711 } 714 }
712 715
713 v8::Handle<v8::Object> new_object = v8::Object::New(isolate); 716 v8::Handle<v8::Object> new_object = v8::Object::New(isolate);
714 object->Set(key, new_object); 717 object->Set(key, new_object);
715 return new_object; 718 return new_object;
716 } 719 }
717 720
718 void Dispatcher::AddOrRemoveBindingsForContext(ChromeV8Context* context) { 721 void Dispatcher::AddOrRemoveBindingsForContext(ScriptContext* context) {
719 v8::HandleScope handle_scope(context->isolate()); 722 v8::HandleScope handle_scope(context->isolate());
720 v8::Context::Scope context_scope(context->v8_context()); 723 v8::Context::Scope context_scope(context->v8_context());
721 724
722 // TODO(kalman): Make the bindings registration have zero overhead then run 725 // TODO(kalman): Make the bindings registration have zero overhead then run
723 // the same code regardless of context type. 726 // the same code regardless of context type.
724 switch (context->context_type()) { 727 switch (context->context_type()) {
725 case Feature::UNSPECIFIED_CONTEXT: 728 case Feature::UNSPECIFIED_CONTEXT:
726 case Feature::WEB_PAGE_CONTEXT: 729 case Feature::WEB_PAGE_CONTEXT:
727 case Feature::BLESSED_WEB_PAGE_CONTEXT: { 730 case Feature::BLESSED_WEB_PAGE_CONTEXT: {
728 // Web page context; it's too expensive to run the full bindings code. 731 // Web page context; it's too expensive to run the full bindings code.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 RegisterBinding("test", context); 782 RegisterBinding("test", context);
780 } 783 }
781 break; 784 break;
782 } 785 }
783 } 786 }
784 } 787 }
785 788
786 v8::Handle<v8::Object> Dispatcher::GetOrCreateBindObjectIfAvailable( 789 v8::Handle<v8::Object> Dispatcher::GetOrCreateBindObjectIfAvailable(
787 const std::string& api_name, 790 const std::string& api_name,
788 std::string* bind_name, 791 std::string* bind_name,
789 ChromeV8Context* context) { 792 ScriptContext* context) {
790 std::vector<std::string> split; 793 std::vector<std::string> split;
791 base::SplitString(api_name, '.', &split); 794 base::SplitString(api_name, '.', &split);
792 795
793 v8::Handle<v8::Object> bind_object; 796 v8::Handle<v8::Object> bind_object;
794 797
795 // Check if this API has an ancestor. If the API's ancestor is available and 798 // Check if this API has an ancestor. If the API's ancestor is available and
796 // the API is not available, don't install the bindings for this API. If 799 // the API is not available, don't install the bindings for this API. If
797 // the API is available and its ancestor is not, delete the ancestor and 800 // the API is available and its ancestor is not, delete the ancestor and
798 // install the bindings for the API. This is to prevent loading the ancestor 801 // install the bindings for the API. This is to prevent loading the ancestor
799 // API schema if it will not be needed. 802 // API schema if it will not be needed.
(...skipping 27 matching lines...) Expand all
827 return v8::Handle<v8::Object>(); 830 return v8::Handle<v8::Object>();
828 831
829 if (bind_name) 832 if (bind_name)
830 *bind_name = split.back(); 833 *bind_name = split.back();
831 834
832 return bind_object.IsEmpty() ? 835 return bind_object.IsEmpty() ?
833 AsObjectOrEmpty(GetOrCreateChrome(context)) : bind_object; 836 AsObjectOrEmpty(GetOrCreateChrome(context)) : bind_object;
834 } 837 }
835 838
836 void Dispatcher::RegisterBinding(const std::string& api_name, 839 void Dispatcher::RegisterBinding(const std::string& api_name,
837 ChromeV8Context* context) { 840 ScriptContext* context) {
838 std::string bind_name; 841 std::string bind_name;
839 v8::Handle<v8::Object> bind_object = 842 v8::Handle<v8::Object> bind_object =
840 GetOrCreateBindObjectIfAvailable(api_name, &bind_name, context); 843 GetOrCreateBindObjectIfAvailable(api_name, &bind_name, context);
841 844
842 // Empty if the bind object failed to be created, probably because the 845 // Empty if the bind object failed to be created, probably because the
843 // extension overrode chrome with a non-object, e.g. window.chrome = true. 846 // extension overrode chrome with a non-object, e.g. window.chrome = true.
844 if (bind_object.IsEmpty()) 847 if (bind_object.IsEmpty())
845 return; 848 return;
846 849
847 v8::Local<v8::String> v8_api_name = 850 v8::Local<v8::String> v8_api_name =
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 } else { 882 } else {
880 module_system->SetLazyField(bind_object, 883 module_system->SetLazyField(bind_object,
881 bind_name, 884 bind_name,
882 api_name, 885 api_name,
883 "binding"); 886 "binding");
884 } 887 }
885 } 888 }
886 889
887 // NOTE: please use the naming convention "foo_natives" for these. 890 // NOTE: please use the naming convention "foo_natives" for these.
888 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, 891 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system,
889 ChromeV8Context* context) { 892 ScriptContext* context) {
890 module_system->RegisterNativeHandler( 893 module_system->RegisterNativeHandler(
891 "event_natives", 894 "event_natives",
892 scoped_ptr<NativeHandler>(new EventBindings(this, context))); 895 scoped_ptr<NativeHandler>(new EventBindings(this, context)));
893 module_system->RegisterNativeHandler("messaging_natives", 896 module_system->RegisterNativeHandler("messaging_natives",
894 scoped_ptr<NativeHandler>(MessagingBindings::Get(this, context))); 897 scoped_ptr<NativeHandler>(MessagingBindings::Get(this, context)));
895 module_system->RegisterNativeHandler("apiDefinitions", 898 module_system->RegisterNativeHandler("apiDefinitions",
896 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this, context))); 899 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this, context)));
897 module_system->RegisterNativeHandler( 900 module_system->RegisterNativeHandler(
898 "sendRequest", 901 "sendRequest",
899 scoped_ptr<NativeHandler>( 902 scoped_ptr<NativeHandler>(
900 new SendRequestNatives(request_sender_.get(), context))); 903 new SendRequestNatives(request_sender_.get(), context)));
901 module_system->RegisterNativeHandler( 904 module_system->RegisterNativeHandler(
902 "setIcon", 905 "setIcon",
903 scoped_ptr<NativeHandler>( 906 scoped_ptr<NativeHandler>(
904 new SetIconNatives(request_sender_.get(), context))); 907 new SetIconNatives(request_sender_.get(), context)));
905 module_system->RegisterNativeHandler("activityLogger", 908 module_system->RegisterNativeHandler(
906 scoped_ptr<NativeHandler>(new APIActivityLogger(this, context))); 909 "activityLogger",
910 scoped_ptr<NativeHandler>(new APIActivityLogger(context)));
907 module_system->RegisterNativeHandler( 911 module_system->RegisterNativeHandler(
908 "renderViewObserverNatives", 912 "renderViewObserverNatives",
909 scoped_ptr<NativeHandler>(new RenderViewObserverNatives(context))); 913 scoped_ptr<NativeHandler>(new RenderViewObserverNatives(context)));
910 914
911 // Natives used by multiple APIs. 915 // Natives used by multiple APIs.
912 module_system->RegisterNativeHandler("file_system_natives", 916 module_system->RegisterNativeHandler("file_system_natives",
913 scoped_ptr<NativeHandler>(new FileSystemNatives(context))); 917 scoped_ptr<NativeHandler>(new FileSystemNatives(context)));
914 918
915 // Custom bindings. 919 // Custom bindings.
916 module_system->RegisterNativeHandler("app", 920 module_system->RegisterNativeHandler("app",
917 scoped_ptr<NativeHandler>(new AppBindings(this, context))); 921 scoped_ptr<NativeHandler>(new AppBindings(this, context)));
918 module_system->RegisterNativeHandler("app_runtime", 922 module_system->RegisterNativeHandler(
919 scoped_ptr<NativeHandler>( 923 "app_runtime",
920 new AppRuntimeCustomBindings(this, context))); 924 scoped_ptr<NativeHandler>(new AppRuntimeCustomBindings(context)));
921 module_system->RegisterNativeHandler("app_window_natives", 925 module_system->RegisterNativeHandler("app_window_natives",
922 scoped_ptr<NativeHandler>( 926 scoped_ptr<NativeHandler>(
923 new AppWindowCustomBindings(this, context))); 927 new AppWindowCustomBindings(this, context)));
924 module_system->RegisterNativeHandler("blob_natives", 928 module_system->RegisterNativeHandler("blob_natives",
925 scoped_ptr<NativeHandler>(new BlobNativeHandler(context))); 929 scoped_ptr<NativeHandler>(new BlobNativeHandler(context)));
926 module_system->RegisterNativeHandler( 930 module_system->RegisterNativeHandler(
927 "context_menus", 931 "context_menus",
928 scoped_ptr<NativeHandler>(new ContextMenusCustomBindings(context))); 932 scoped_ptr<NativeHandler>(new ContextMenusCustomBindings(context)));
929 module_system->RegisterNativeHandler( 933 module_system->RegisterNativeHandler(
930 "css_natives", scoped_ptr<NativeHandler>(new CssNativeHandler(context))); 934 "css_natives", scoped_ptr<NativeHandler>(new CssNativeHandler(context)));
931 module_system->RegisterNativeHandler( 935 module_system->RegisterNativeHandler(
932 "document_natives", 936 "document_natives",
933 scoped_ptr<NativeHandler>(new DocumentCustomBindings(context))); 937 scoped_ptr<NativeHandler>(new DocumentCustomBindings(context)));
934 module_system->RegisterNativeHandler("sync_file_system", 938 module_system->RegisterNativeHandler(
935 scoped_ptr<NativeHandler>( 939 "sync_file_system",
936 new SyncFileSystemCustomBindings(this, context))); 940 scoped_ptr<NativeHandler>(new SyncFileSystemCustomBindings(context)));
937 module_system->RegisterNativeHandler("file_browser_handler", 941 module_system->RegisterNativeHandler(
938 scoped_ptr<NativeHandler>(new FileBrowserHandlerCustomBindings( 942 "file_browser_handler",
939 this, context))); 943 scoped_ptr<NativeHandler>(new FileBrowserHandlerCustomBindings(context)));
940 module_system->RegisterNativeHandler("file_browser_private", 944 module_system->RegisterNativeHandler(
941 scoped_ptr<NativeHandler>(new FileBrowserPrivateCustomBindings( 945 "file_browser_private",
942 this, context))); 946 scoped_ptr<NativeHandler>(new FileBrowserPrivateCustomBindings(context)));
943 module_system->RegisterNativeHandler( 947 module_system->RegisterNativeHandler(
944 "i18n", scoped_ptr<NativeHandler>(new I18NCustomBindings(context))); 948 "i18n", scoped_ptr<NativeHandler>(new I18NCustomBindings(context)));
945 module_system->RegisterNativeHandler( 949 module_system->RegisterNativeHandler(
946 "id_generator", 950 "id_generator",
947 scoped_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); 951 scoped_ptr<NativeHandler>(new IdGeneratorCustomBindings(context)));
948 module_system->RegisterNativeHandler("mediaGalleries", 952 module_system->RegisterNativeHandler(
949 scoped_ptr<NativeHandler>( 953 "mediaGalleries",
950 new MediaGalleriesCustomBindings(this, context))); 954 scoped_ptr<NativeHandler>(new MediaGalleriesCustomBindings(context)));
951 module_system->RegisterNativeHandler("page_actions", 955 module_system->RegisterNativeHandler(
952 scoped_ptr<NativeHandler>( 956 "page_actions",
953 new PageActionsCustomBindings(this, context))); 957 scoped_ptr<NativeHandler>(new PageActionsCustomBindings(this, context)));
954 module_system->RegisterNativeHandler("page_capture", 958 module_system->RegisterNativeHandler(
955 scoped_ptr<NativeHandler>( 959 "page_capture",
956 new PageCaptureCustomBindings(this, context))); 960 scoped_ptr<NativeHandler>(new PageCaptureCustomBindings(context)));
957 module_system->RegisterNativeHandler( 961 module_system->RegisterNativeHandler(
958 "pepper_request_natives", 962 "pepper_request_natives",
959 scoped_ptr<NativeHandler>(new PepperRequestNatives(context))); 963 scoped_ptr<NativeHandler>(new PepperRequestNatives(context)));
960 module_system->RegisterNativeHandler("runtime", 964 module_system->RegisterNativeHandler(
961 scoped_ptr<NativeHandler>(new RuntimeCustomBindings(this, context))); 965 "runtime", scoped_ptr<NativeHandler>(new RuntimeCustomBindings(context)));
962 module_system->RegisterNativeHandler("tabs", 966 module_system->RegisterNativeHandler(
963 scoped_ptr<NativeHandler>(new TabsCustomBindings(this, context))); 967 "tabs", scoped_ptr<NativeHandler>(new TabsCustomBindings(context)));
964 module_system->RegisterNativeHandler("webstore", 968 module_system->RegisterNativeHandler(
965 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); 969 "webstore", scoped_ptr<NativeHandler>(new WebstoreBindings(context)));
966 #if defined(ENABLE_WEBRTC) 970 #if defined(ENABLE_WEBRTC)
967 module_system->RegisterNativeHandler("cast_streaming_natives", 971 module_system->RegisterNativeHandler("cast_streaming_natives",
968 scoped_ptr<NativeHandler>(new CastStreamingNativeHandler(context))); 972 scoped_ptr<NativeHandler>(new CastStreamingNativeHandler(context)));
969 #endif 973 #endif
970 } 974 }
971 975
972 void Dispatcher::PopulateSourceMap() { 976 void Dispatcher::PopulateSourceMap() {
973 // Libraries. 977 // Libraries.
974 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); 978 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER);
975 source_map_.RegisterSource(kEventBindings, IDR_EVENT_BINDINGS_JS); 979 source_map_.RegisterSource(kEventBindings, IDR_EVENT_BINDINGS_JS);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 1134
1131 extension_id = ""; 1135 extension_id = "";
1132 } 1136 }
1133 1137
1134 Feature::Context context_type = 1138 Feature::Context context_type =
1135 ClassifyJavaScriptContext(extension, 1139 ClassifyJavaScriptContext(extension,
1136 extension_group, 1140 extension_group,
1137 ScriptContext::GetDataSourceURLForFrame(frame), 1141 ScriptContext::GetDataSourceURLForFrame(frame),
1138 frame->document().securityOrigin()); 1142 frame->document().securityOrigin());
1139 1143
1140 ChromeV8Context* context = 1144 ScriptContext* context =
1141 new ChromeV8Context(v8_context, frame, extension, context_type); 1145 new ChromeV8Context(v8_context, frame, extension, context_type);
1142 v8_context_set_.Add(context); 1146 script_context_set_.Add(context);
1143 1147
1144 if (extension) 1148 if (extension)
1145 InitOriginPermissions(extension, context_type); 1149 InitOriginPermissions(extension, context_type);
1146 1150
1147 { 1151 {
1148 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(context, 1152 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(context,
1149 &source_map_)); 1153 &source_map_));
1150 context->set_module_system(module_system.Pass()); 1154 context->set_module_system(module_system.Pass());
1151 } 1155 }
1152 ModuleSystem* module_system = context->module_system(); 1156 ModuleSystem* module_system = context->module_system();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 if (CommandLine::ForCurrentProcess()->HasSwitch( 1257 if (CommandLine::ForCurrentProcess()->HasSwitch(
1254 ::switches::kEnableAdview)) { 1258 ::switches::kEnableAdview)) {
1255 if (extension->HasAPIPermission(APIPermission::kAdView)) { 1259 if (extension->HasAPIPermission(APIPermission::kAdView)) {
1256 module_system->Require("adView"); 1260 module_system->Require("adView");
1257 } else { 1261 } else {
1258 module_system->Require("denyAdView"); 1262 module_system->Require("denyAdView");
1259 } 1263 }
1260 } 1264 }
1261 } 1265 }
1262 1266
1263 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); 1267 VLOG(1) << "Num tracked contexts: " << script_context_set_.size();
1264 } 1268 }
1265 1269
1266 std::string Dispatcher::GetExtensionID(const WebFrame* frame, int world_id) { 1270 std::string Dispatcher::GetExtensionID(const WebFrame* frame, int world_id) {
1267 if (world_id != 0) { 1271 if (world_id != 0) {
1268 // Isolated worlds (content script). 1272 // Isolated worlds (content script).
1269 return user_script_slave_->GetExtensionIdForIsolatedWorld(world_id); 1273 return user_script_slave_->GetExtensionIdForIsolatedWorld(world_id);
1270 } 1274 }
1271 1275
1272 // TODO(kalman): Delete this check. 1276 // TODO(kalman): Delete this check.
1273 if (frame->document().securityOrigin().isUnique()) 1277 if (frame->document().securityOrigin().isUnique())
1274 return std::string(); 1278 return std::string();
1275 1279
1276 // Extension pages (chrome-extension:// URLs). 1280 // Extension pages (chrome-extension:// URLs).
1277 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame); 1281 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame);
1278 return extensions_.GetExtensionOrAppIDByURL(frame_url); 1282 return extensions_.GetExtensionOrAppIDByURL(frame_url);
1279 } 1283 }
1280 1284
1281 bool Dispatcher::IsWithinPlatformApp() { 1285 bool Dispatcher::IsWithinPlatformApp() {
1282 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); 1286 for (std::set<std::string>::iterator iter = active_extension_ids_.begin();
1283 iter != active_extension_ids_.end(); ++iter) { 1287 iter != active_extension_ids_.end(); ++iter) {
1284 const Extension* extension = extensions_.GetByID(*iter); 1288 const Extension* extension = extensions_.GetByID(*iter);
1285 if (extension && extension->is_platform_app()) 1289 if (extension && extension->is_platform_app())
1286 return true; 1290 return true;
1287 } 1291 }
1288 return false; 1292 return false;
1289 } 1293 }
1290 1294
1291 void Dispatcher::WillReleaseScriptContext( 1295 void Dispatcher::WillReleaseScriptContext(
1292 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { 1296 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) {
1293 ChromeV8Context* context = v8_context_set_.GetByV8Context(v8_context); 1297 ScriptContext* context = script_context_set_.GetByV8Context(v8_context);
1294 if (!context) 1298 if (!context)
1295 return; 1299 return;
1296 1300
1297 context->DispatchOnUnloadEvent(); 1301 context->DispatchOnUnloadEvent();
1298 // TODO(kalman): add an invalidation observer interface to ChromeV8Context. 1302 // TODO(kalman): add an invalidation observer interface to ScriptContext.
1299 request_sender_->InvalidateSource(context); 1303 request_sender_->InvalidateSource(context);
1300 1304
1301 v8_context_set_.Remove(context); 1305 script_context_set_.Remove(context);
1302 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); 1306 VLOG(1) << "Num tracked contexts: " << script_context_set_.size();
1303 } 1307 }
1304 1308
1305 void Dispatcher::DidCreateDocumentElement(blink::WebFrame* frame) { 1309 void Dispatcher::DidCreateDocumentElement(blink::WebFrame* frame) {
1306 if (IsWithinPlatformApp()) { 1310 if (IsWithinPlatformApp()) {
1307 // WebKit doesn't let us define an additional user agent stylesheet, so we 1311 // WebKit doesn't let us define an additional user agent stylesheet, so we
1308 // insert the default platform app stylesheet into all documents that are 1312 // insert the default platform app stylesheet into all documents that are
1309 // loaded in each app. 1313 // loaded in each app.
1310 std::string stylesheet = 1314 std::string stylesheet =
1311 ResourceBundle::GetSharedInstance(). 1315 ResourceBundle::GetSharedInstance().
1312 GetRawDataResource(IDR_PLATFORM_APP_CSS).as_string(); 1316 GetRawDataResource(IDR_PLATFORM_APP_CSS).as_string();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 } 1411 }
1408 1412
1409 void Dispatcher::EnableCustomElementWhiteList() { 1413 void Dispatcher::EnableCustomElementWhiteList() {
1410 blink::WebCustomElement::addEmbedderCustomElementName("webview"); 1414 blink::WebCustomElement::addEmbedderCustomElementName("webview");
1411 // TODO(fsamuel): Add <adview> to the whitelist once it has been converted 1415 // TODO(fsamuel): Add <adview> to the whitelist once it has been converted
1412 // into a custom element. 1416 // into a custom element.
1413 blink::WebCustomElement::addEmbedderCustomElementName("browser-plugin"); 1417 blink::WebCustomElement::addEmbedderCustomElementName("browser-plugin");
1414 } 1418 }
1415 1419
1416 void Dispatcher::AddOrRemoveBindings(const std::string& extension_id) { 1420 void Dispatcher::AddOrRemoveBindings(const std::string& extension_id) {
1417 v8_context_set().ForEach( 1421 script_context_set().ForEach(
1418 extension_id, 1422 extension_id,
1419 NULL, // all render views 1423 NULL, // all render views
1420 base::Bind(&Dispatcher::AddOrRemoveBindingsForContext, 1424 base::Bind(&Dispatcher::AddOrRemoveBindingsForContext,
1421 base::Unretained(this))); 1425 base::Unretained(this)));
1422 } 1426 }
1423 1427
1424 void Dispatcher::OnUpdatePermissions( 1428 void Dispatcher::OnUpdatePermissions(
1425 const ExtensionMsg_UpdatePermissions_Params& params) { 1429 const ExtensionMsg_UpdatePermissions_Params& params) {
1426 int reason_id = params.reason_id; 1430 int reason_id = params.reason_id;
1427 const std::string& extension_id = params.extension_id; 1431 const std::string& extension_id = params.extension_id;
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 } 1649 }
1646 1650
1647 void Dispatcher::DispatchEvent(const std::string& extension_id, 1651 void Dispatcher::DispatchEvent(const std::string& extension_id,
1648 const std::string& event_name) const { 1652 const std::string& event_name) const {
1649 base::ListValue args; 1653 base::ListValue args;
1650 args.Set(0, new base::StringValue(event_name)); 1654 args.Set(0, new base::StringValue(event_name));
1651 args.Set(1, new base::ListValue()); 1655 args.Set(1, new base::ListValue());
1652 1656
1653 // Needed for Windows compilation, since kEventBindings is declared extern. 1657 // Needed for Windows compilation, since kEventBindings is declared extern.
1654 const char* local_event_bindings = kEventBindings; 1658 const char* local_event_bindings = kEventBindings;
1655 v8_context_set_.ForEach( 1659 script_context_set_.ForEach(extension_id,
1656 extension_id, 1660 NULL, // all render views
1657 NULL, // all render views 1661 base::Bind(&CallModuleMethod,
1658 base::Bind(&CallModuleMethod, 1662 local_event_bindings,
1659 local_event_bindings, 1663 kEventDispatchFunction,
1660 kEventDispatchFunction, 1664 &args));
1661 &args));
1662 } 1665 }
1663 1666
1664 void Dispatcher::InvokeModuleSystemMethod( 1667 void Dispatcher::InvokeModuleSystemMethod(
1665 content::RenderView* render_view, 1668 content::RenderView* render_view,
1666 const std::string& extension_id, 1669 const std::string& extension_id,
1667 const std::string& module_name, 1670 const std::string& module_name,
1668 const std::string& function_name, 1671 const std::string& function_name,
1669 const base::ListValue& args, 1672 const base::ListValue& args,
1670 bool user_gesture) { 1673 bool user_gesture) {
1671 scoped_ptr<WebScopedUserGesture> web_user_gesture; 1674 scoped_ptr<WebScopedUserGesture> web_user_gesture;
1672 if (user_gesture) 1675 if (user_gesture)
1673 web_user_gesture.reset(new WebScopedUserGesture); 1676 web_user_gesture.reset(new WebScopedUserGesture);
1674 1677
1675 v8_context_set_.ForEach( 1678 script_context_set_.ForEach(
1676 extension_id, 1679 extension_id,
1677 render_view, 1680 render_view,
1678 base::Bind(&CallModuleMethod, module_name, function_name, &args)); 1681 base::Bind(&CallModuleMethod, module_name, function_name, &args));
1679 1682
1680 // Reset the idle handler each time there's any activity like event or message 1683 // Reset the idle handler each time there's any activity like event or message
1681 // dispatch, for which Invoke is the chokepoint. 1684 // dispatch, for which Invoke is the chokepoint.
1682 if (is_extension_process_) { 1685 if (is_extension_process_) {
1683 RenderThread::Get()->ScheduleIdleHandler( 1686 RenderThread::Get()->ScheduleIdleHandler(
1684 kInitialExtensionIdleHandlerDelayMs); 1687 kInitialExtensionIdleHandlerDelayMs);
1685 } 1688 }
(...skipping 14 matching lines...) Expand all
1700 } 1703 }
1701 1704
1702 void Dispatcher::ClearPortData(int port_id) { 1705 void Dispatcher::ClearPortData(int port_id) {
1703 // Only the target port side has entries in |port_to_tab_id_map_|. If 1706 // Only the target port side has entries in |port_to_tab_id_map_|. If
1704 // |port_id| is a source port, std::map::erase() will just silently fail 1707 // |port_id| is a source port, std::map::erase() will just silently fail
1705 // here as a no-op. 1708 // here as a no-op.
1706 port_to_tab_id_map_.erase(port_id); 1709 port_to_tab_id_map_.erase(port_id);
1707 } 1710 }
1708 1711
1709 } // namespace extensions 1712 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698