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

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

Issue 145463002: Extensions: Send the tab id to platform apps. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: get rid of js changes, correctly handle disconnects Created 6 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/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
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);
not at google - send to devlin 2014/01/29 00:45:51 // target renderer ports are assigned odd IDs
Lei Zhang 2014/01/29 00:53:23 Done.
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 std::map<int, int>::const_iterator it =
607 port_to_tab_id_map_.find(target_port_id);
608 DCHECK(it != port_to_tab_id_map_.end());
609 RequestSender::ScopedTabID scoped_tab_id(request_sender(), it->second);
610
600 MessagingBindings::DeliverMessage( 611 MessagingBindings::DeliverMessage(
601 v8_context_set_.GetAll(), 612 v8_context_set_.GetAll(),
602 target_port_id, 613 target_port_id,
603 message, 614 message,
604 NULL); // All render views. 615 NULL); // All render views.
605 } 616 }
606 617
607 void Dispatcher::OnDispatchOnDisconnect(int port_id, 618 void Dispatcher::OnDispatchOnDisconnect(int port_id,
608 const std::string& error_message) { 619 const std::string& error_message) {
609 MessagingBindings::DispatchOnDisconnect( 620 MessagingBindings::DispatchOnDisconnect(
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 function_name == kEventDispatchFunction) { 1676 function_name == kEventDispatchFunction) {
1666 RenderView* background_view = 1677 RenderView* background_view =
1667 ExtensionHelper::GetBackgroundPage(extension_id); 1678 ExtensionHelper::GetBackgroundPage(extension_id);
1668 if (background_view) { 1679 if (background_view) {
1669 background_view->Send(new ExtensionHostMsg_EventAck( 1680 background_view->Send(new ExtensionHostMsg_EventAck(
1670 background_view->GetRoutingID())); 1681 background_view->GetRoutingID()));
1671 } 1682 }
1672 } 1683 }
1673 } 1684 }
1674 1685
1686 void Dispatcher::ClearPortData(int port_id) {
1687 // Only the target port side has entries in |port_to_tab_id_map_|. If
1688 // |port_id| is a source port, std::map::erase() will just silently fail
1689 // here as a no-op.
1690 port_to_tab_id_map_.erase(port_id);
1691 }
1692
1675 } // namespace extensions 1693 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/dispatcher.h ('k') | chrome/renderer/extensions/messaging_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698