| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/dispatcher.h" | 5 #include "extensions/renderer/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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 | 384 |
| 385 void Dispatcher::DispatchEvent(const std::string& extension_id, | 385 void Dispatcher::DispatchEvent(const std::string& extension_id, |
| 386 const std::string& event_name) const { | 386 const std::string& event_name) const { |
| 387 base::ListValue args; | 387 base::ListValue args; |
| 388 args.Set(0, new base::StringValue(event_name)); | 388 args.Set(0, new base::StringValue(event_name)); |
| 389 args.Set(1, new base::ListValue()); | 389 args.Set(1, new base::ListValue()); |
| 390 | 390 |
| 391 // Needed for Windows compilation, since kEventBindings is declared extern. | 391 // Needed for Windows compilation, since kEventBindings is declared extern. |
| 392 const char* local_event_bindings = kEventBindings; | 392 const char* local_event_bindings = kEventBindings; |
| 393 script_context_set_.ForEach(extension_id, | 393 script_context_set_.ForEach(extension_id, |
| 394 NULL, // all render views | |
| 395 base::Bind(&CallModuleMethod, | 394 base::Bind(&CallModuleMethod, |
| 396 local_event_bindings, | 395 local_event_bindings, |
| 397 kEventDispatchFunction, | 396 kEventDispatchFunction, |
| 398 &args)); | 397 &args)); |
| 399 } | 398 } |
| 400 | 399 |
| 401 void Dispatcher::InvokeModuleSystemMethod(content::RenderView* render_view, | 400 void Dispatcher::InvokeModuleSystemMethod(content::RenderView* render_view, |
| 402 const std::string& extension_id, | 401 const std::string& extension_id, |
| 403 const std::string& module_name, | 402 const std::string& module_name, |
| 404 const std::string& function_name, | 403 const std::string& function_name, |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 | 568 |
| 570 void Dispatcher::OnDeliverMessage(int target_port_id, const Message& message) { | 569 void Dispatcher::OnDeliverMessage(int target_port_id, const Message& message) { |
| 571 scoped_ptr<RequestSender::ScopedTabID> scoped_tab_id; | 570 scoped_ptr<RequestSender::ScopedTabID> scoped_tab_id; |
| 572 std::map<int, int>::const_iterator it = | 571 std::map<int, int>::const_iterator it = |
| 573 port_to_tab_id_map_.find(target_port_id); | 572 port_to_tab_id_map_.find(target_port_id); |
| 574 if (it != port_to_tab_id_map_.end()) { | 573 if (it != port_to_tab_id_map_.end()) { |
| 575 scoped_tab_id.reset( | 574 scoped_tab_id.reset( |
| 576 new RequestSender::ScopedTabID(request_sender(), it->second)); | 575 new RequestSender::ScopedTabID(request_sender(), it->second)); |
| 577 } | 576 } |
| 578 | 577 |
| 579 MessagingBindings::DeliverMessage(script_context_set_.GetAll(), | 578 MessagingBindings::DeliverMessage(script_context_set_, |
| 580 target_port_id, | 579 target_port_id, |
| 581 message, | 580 message, |
| 582 NULL); // All render views. | 581 NULL); // All render views. |
| 583 } | 582 } |
| 584 | 583 |
| 585 void Dispatcher::OnDispatchOnConnect( | 584 void Dispatcher::OnDispatchOnConnect( |
| 586 int target_port_id, | 585 int target_port_id, |
| 587 const std::string& channel_name, | 586 const std::string& channel_name, |
| 588 const base::DictionaryValue& source_tab, | 587 const base::DictionaryValue& source_tab, |
| 589 const ExtensionMsg_ExternalConnectionInfo& info, | 588 const ExtensionMsg_ExternalConnectionInfo& info, |
| 590 const std::string& tls_channel_id) { | 589 const std::string& tls_channel_id) { |
| 591 DCHECK(!ContainsKey(port_to_tab_id_map_, target_port_id)); | 590 DCHECK(!ContainsKey(port_to_tab_id_map_, target_port_id)); |
| 592 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. |
| 593 int sender_tab_id = -1; | 592 int sender_tab_id = -1; |
| 594 source_tab.GetInteger("id", &sender_tab_id); | 593 source_tab.GetInteger("id", &sender_tab_id); |
| 595 port_to_tab_id_map_[target_port_id] = sender_tab_id; | 594 port_to_tab_id_map_[target_port_id] = sender_tab_id; |
| 596 | 595 |
| 597 MessagingBindings::DispatchOnConnect(script_context_set_.GetAll(), | 596 MessagingBindings::DispatchOnConnect(script_context_set_, |
| 598 target_port_id, | 597 target_port_id, |
| 599 channel_name, | 598 channel_name, |
| 600 source_tab, | 599 source_tab, |
| 601 info.source_id, | 600 info, |
| 602 info.target_id, | |
| 603 info.source_url, | |
| 604 tls_channel_id, | 601 tls_channel_id, |
| 605 NULL); // All render views. | 602 NULL); // All render views. |
| 606 } | 603 } |
| 607 | 604 |
| 608 void Dispatcher::OnDispatchOnDisconnect(int port_id, | 605 void Dispatcher::OnDispatchOnDisconnect(int port_id, |
| 609 const std::string& error_message) { | 606 const std::string& error_message) { |
| 610 MessagingBindings::DispatchOnDisconnect(script_context_set_.GetAll(), | 607 MessagingBindings::DispatchOnDisconnect(script_context_set_, |
| 611 port_id, | 608 port_id, |
| 612 error_message, | 609 error_message, |
| 613 NULL); // All render views. | 610 NULL); // All render views. |
| 614 } | 611 } |
| 615 | 612 |
| 616 void Dispatcher::OnLoaded( | 613 void Dispatcher::OnLoaded( |
| 617 const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions) { | 614 const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions) { |
| 618 std::vector<ExtensionMsg_Loaded_Params>::const_iterator i; | 615 std::vector<ExtensionMsg_Loaded_Params>::const_iterator i; |
| 619 for (i = loaded_extensions.begin(); i != loaded_extensions.end(); ++i) { | 616 for (i = loaded_extensions.begin(); i != loaded_extensions.end(); ++i) { |
| 620 std::string error; | 617 std::string error; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 | 832 |
| 836 void Dispatcher::EnableCustomElementWhiteList() { | 833 void Dispatcher::EnableCustomElementWhiteList() { |
| 837 blink::WebCustomElement::addEmbedderCustomElementName("webview"); | 834 blink::WebCustomElement::addEmbedderCustomElementName("webview"); |
| 838 // TODO(fsamuel): Add <adview> to the whitelist once it has been converted | 835 // TODO(fsamuel): Add <adview> to the whitelist once it has been converted |
| 839 // into a custom element. | 836 // into a custom element. |
| 840 blink::WebCustomElement::addEmbedderCustomElementName("browser-plugin"); | 837 blink::WebCustomElement::addEmbedderCustomElementName("browser-plugin"); |
| 841 } | 838 } |
| 842 | 839 |
| 843 void Dispatcher::UpdateBindings(const std::string& extension_id) { | 840 void Dispatcher::UpdateBindings(const std::string& extension_id) { |
| 844 script_context_set().ForEach(extension_id, | 841 script_context_set().ForEach(extension_id, |
| 845 NULL, // all render views | |
| 846 base::Bind(&Dispatcher::UpdateBindingsForContext, | 842 base::Bind(&Dispatcher::UpdateBindingsForContext, |
| 847 base::Unretained(this))); | 843 base::Unretained(this))); |
| 848 } | 844 } |
| 849 | 845 |
| 850 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { | 846 void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { |
| 851 v8::HandleScope handle_scope(context->isolate()); | 847 v8::HandleScope handle_scope(context->isolate()); |
| 852 v8::Context::Scope context_scope(context->v8_context()); | 848 v8::Context::Scope context_scope(context->v8_context()); |
| 853 | 849 |
| 854 // TODO(kalman): Make the bindings registration have zero overhead then run | 850 // TODO(kalman): Make the bindings registration have zero overhead then run |
| 855 // the same code regardless of context type. | 851 // the same code regardless of context type. |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1233 return v8::Handle<v8::Object>(); | 1229 return v8::Handle<v8::Object>(); |
| 1234 | 1230 |
| 1235 if (bind_name) | 1231 if (bind_name) |
| 1236 *bind_name = split.back(); | 1232 *bind_name = split.back(); |
| 1237 | 1233 |
| 1238 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) | 1234 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) |
| 1239 : bind_object; | 1235 : bind_object; |
| 1240 } | 1236 } |
| 1241 | 1237 |
| 1242 } // namespace extensions | 1238 } // namespace extensions |
| OLD | NEW |