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 int sender_tab_id = -1; | |
592 source_tab.GetInteger("id", &sender_tab_id); | |
593 port_to_tab_id_map_[target_port_id] = sender_tab_id; | |
594 | |
590 MessagingBindings::DispatchOnConnect( | 595 MessagingBindings::DispatchOnConnect( |
591 v8_context_set_.GetAll(), | 596 v8_context_set_.GetAll(), |
592 target_port_id, channel_name, source_tab, | 597 target_port_id, channel_name, source_tab, |
593 info.source_id, info.target_id, info.source_url, | 598 info.source_id, info.target_id, info.source_url, |
594 tls_channel_id, | 599 tls_channel_id, |
595 NULL); // All render views. | 600 NULL); // All render views. |
596 } | 601 } |
597 | 602 |
598 void Dispatcher::OnDeliverMessage(int target_port_id, | 603 void Dispatcher::OnDeliverMessage(int target_port_id, |
599 const Message& message) { | 604 const Message& message) { |
605 std::map<int, int>::const_iterator it = | |
606 port_to_tab_id_map_.find(target_port_id); | |
607 DCHECK(it != port_to_tab_id_map_.end()); | |
608 RequestSender::ScopedTabID scoped_tab_id(request_sender(), it->second); | |
609 | |
600 MessagingBindings::DeliverMessage( | 610 MessagingBindings::DeliverMessage( |
601 v8_context_set_.GetAll(), | 611 v8_context_set_.GetAll(), |
602 target_port_id, | 612 target_port_id, |
603 message, | 613 message, |
604 NULL); // All render views. | 614 NULL); // All render views. |
605 } | 615 } |
606 | 616 |
607 void Dispatcher::OnDispatchOnDisconnect(int port_id, | 617 void Dispatcher::OnDispatchOnDisconnect(int port_id, |
608 const std::string& error_message) { | 618 const std::string& error_message) { |
619 int target_port = port_id ^ 1; | |
620 port_to_tab_id_map_.erase(target_port); | |
not at google - send to devlin
2014/01/28 18:45:45
maybe you could also DCHECK(port_to_tab_id_map_.fi
Lei Zhang
2014/01/28 22:52:27
Done... and the DCHECK fails. It turns out in this
| |
621 | |
609 MessagingBindings::DispatchOnDisconnect( | 622 MessagingBindings::DispatchOnDisconnect( |
610 v8_context_set_.GetAll(), | 623 v8_context_set_.GetAll(), |
611 port_id, error_message, | 624 port_id, error_message, |
612 NULL); // All render views. | 625 NULL); // All render views. |
613 } | 626 } |
614 | 627 |
615 void Dispatcher::OnLoaded( | 628 void Dispatcher::OnLoaded( |
616 const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions) { | 629 const std::vector<ExtensionMsg_Loaded_Params>& loaded_extensions) { |
617 std::vector<ExtensionMsg_Loaded_Params>::const_iterator i; | 630 std::vector<ExtensionMsg_Loaded_Params>::const_iterator i; |
618 for (i = loaded_extensions.begin(); i != loaded_extensions.end(); ++i) { | 631 for (i = loaded_extensions.begin(); i != loaded_extensions.end(); ++i) { |
(...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1666 RenderView* background_view = | 1679 RenderView* background_view = |
1667 ExtensionHelper::GetBackgroundPage(extension_id); | 1680 ExtensionHelper::GetBackgroundPage(extension_id); |
1668 if (background_view) { | 1681 if (background_view) { |
1669 background_view->Send(new ExtensionHostMsg_EventAck( | 1682 background_view->Send(new ExtensionHostMsg_EventAck( |
1670 background_view->GetRoutingID())); | 1683 background_view->GetRoutingID())); |
1671 } | 1684 } |
1672 } | 1685 } |
1673 } | 1686 } |
1674 | 1687 |
1675 } // namespace extensions | 1688 } // namespace extensions |
OLD | NEW |