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/debug/alias.h" | 9 #include "base/debug/alias.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 InvokeModuleSystemMethod( | 580 InvokeModuleSystemMethod( |
581 NULL, extension_id, module_name, function_name, args, user_gesture); | 581 NULL, extension_id, module_name, function_name, args, user_gesture); |
582 } | 582 } |
583 | 583 |
584 void Dispatcher::OnDispatchOnConnect( | 584 void Dispatcher::OnDispatchOnConnect( |
585 int target_port_id, | 585 int target_port_id, |
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)); |
| 591 DCHECK_EQ(1, target_port_id % 2); // target renderer ports have odd IDs. |
| 592 int sender_tab_id = -1; |
| 593 source_tab.GetInteger("id", &sender_tab_id); |
| 594 port_to_tab_id_map_[target_port_id] = sender_tab_id; |
| 595 |
590 MessagingBindings::DispatchOnConnect( | 596 MessagingBindings::DispatchOnConnect( |
591 v8_context_set_.GetAll(), | 597 v8_context_set_.GetAll(), |
592 target_port_id, channel_name, source_tab, | 598 target_port_id, channel_name, source_tab, |
593 info.source_id, info.target_id, info.source_url, | 599 info.source_id, info.target_id, info.source_url, |
594 tls_channel_id, | 600 tls_channel_id, |
595 NULL); // All render views. | 601 NULL); // All render views. |
596 } | 602 } |
597 | 603 |
598 void Dispatcher::OnDeliverMessage(int target_port_id, | 604 void Dispatcher::OnDeliverMessage(int target_port_id, |
599 const Message& message) { | 605 const Message& message) { |
| 606 scoped_ptr<RequestSender::ScopedTabID> scoped_tab_id; |
| 607 std::map<int, int>::const_iterator it = |
| 608 port_to_tab_id_map_.find(target_port_id); |
| 609 if (it != port_to_tab_id_map_.end()) { |
| 610 scoped_tab_id.reset(new RequestSender::ScopedTabID(request_sender(), |
| 611 it->second)); |
| 612 } |
| 613 |
600 MessagingBindings::DeliverMessage( | 614 MessagingBindings::DeliverMessage( |
601 v8_context_set_.GetAll(), | 615 v8_context_set_.GetAll(), |
602 target_port_id, | 616 target_port_id, |
603 message, | 617 message, |
604 NULL); // All render views. | 618 NULL); // All render views. |
605 } | 619 } |
606 | 620 |
607 void Dispatcher::OnDispatchOnDisconnect(int port_id, | 621 void Dispatcher::OnDispatchOnDisconnect(int port_id, |
608 const std::string& error_message) { | 622 const std::string& error_message) { |
609 MessagingBindings::DispatchOnDisconnect( | 623 MessagingBindings::DispatchOnDisconnect( |
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1665 function_name == kEventDispatchFunction) { | 1679 function_name == kEventDispatchFunction) { |
1666 RenderView* background_view = | 1680 RenderView* background_view = |
1667 ExtensionHelper::GetBackgroundPage(extension_id); | 1681 ExtensionHelper::GetBackgroundPage(extension_id); |
1668 if (background_view) { | 1682 if (background_view) { |
1669 background_view->Send(new ExtensionHostMsg_EventAck( | 1683 background_view->Send(new ExtensionHostMsg_EventAck( |
1670 background_view->GetRoutingID())); | 1684 background_view->GetRoutingID())); |
1671 } | 1685 } |
1672 } | 1686 } |
1673 } | 1687 } |
1674 | 1688 |
| 1689 void Dispatcher::ClearPortData(int port_id) { |
| 1690 // Only the target port side has entries in |port_to_tab_id_map_|. If |
| 1691 // |port_id| is a source port, std::map::erase() will just silently fail |
| 1692 // here as a no-op. |
| 1693 port_to_tab_id_map_.erase(port_id); |
| 1694 } |
| 1695 |
1675 } // namespace extensions | 1696 } // namespace extensions |
OLD | NEW |