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

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

Issue 1966283002: Remove port lifetime management from renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use MakeUnique instead of WrapUnique Created 4 years, 7 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
« no previous file with comments | « extensions/renderer/dispatcher.h ('k') | extensions/renderer/extension_frame_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 ExtensionFrameHelper::GetBackgroundPageFrame(extension_id); 622 ExtensionFrameHelper::GetBackgroundPageFrame(extension_id);
623 if (background_frame) { 623 if (background_frame) {
624 int message_id; 624 int message_id;
625 args.GetInteger(3, &message_id); 625 args.GetInteger(3, &message_id);
626 background_frame->Send(new ExtensionHostMsg_EventAck( 626 background_frame->Send(new ExtensionHostMsg_EventAck(
627 background_frame->GetRoutingID(), message_id)); 627 background_frame->GetRoutingID(), message_id));
628 } 628 }
629 } 629 }
630 } 630 }
631 631
632 void Dispatcher::ClearPortData(int port_id) {
633 // Only the target port side has entries in |port_to_tab_id_map_|. If
634 // |port_id| is a source port, std::map::erase() will just silently fail
635 // here as a no-op.
636 port_to_tab_id_map_.erase(port_id);
637 }
638
639 // static 632 // static
640 std::vector<std::pair<std::string, int> > Dispatcher::GetJsResources() { 633 std::vector<std::pair<std::string, int> > Dispatcher::GetJsResources() {
641 std::vector<std::pair<std::string, int> > resources; 634 std::vector<std::pair<std::string, int> > resources;
642 635
643 // Libraries. 636 // Libraries.
644 resources.push_back(std::make_pair("appView", IDR_APP_VIEW_JS)); 637 resources.push_back(std::make_pair("appView", IDR_APP_VIEW_JS));
645 resources.push_back(std::make_pair("entryIdManager", IDR_ENTRY_ID_MANAGER)); 638 resources.push_back(std::make_pair("entryIdManager", IDR_ENTRY_ID_MANAGER));
646 resources.push_back(std::make_pair(kEventBindings, IDR_EVENT_BINDINGS_JS)); 639 resources.push_back(std::make_pair(kEventBindings, IDR_EVENT_BINDINGS_JS));
647 resources.push_back(std::make_pair("extensionOptions", 640 resources.push_back(std::make_pair("extensionOptions",
648 IDR_EXTENSION_OPTIONS_JS)); 641 IDR_EXTENSION_OPTIONS_JS));
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 std::unique_ptr<NativeHandler>(new UserGesturesNativeHandler(context))); 830 std::unique_ptr<NativeHandler>(new UserGesturesNativeHandler(context)));
838 module_system->RegisterNativeHandler( 831 module_system->RegisterNativeHandler(
839 "utils", std::unique_ptr<NativeHandler>(new UtilsNativeHandler(context))); 832 "utils", std::unique_ptr<NativeHandler>(new UtilsNativeHandler(context)));
840 module_system->RegisterNativeHandler( 833 module_system->RegisterNativeHandler(
841 "v8_context", 834 "v8_context",
842 std::unique_ptr<NativeHandler>(new V8ContextNativeHandler(context))); 835 std::unique_ptr<NativeHandler>(new V8ContextNativeHandler(context)));
843 module_system->RegisterNativeHandler( 836 module_system->RegisterNativeHandler(
844 "event_natives", 837 "event_natives",
845 std::unique_ptr<NativeHandler>(new EventBindings(context))); 838 std::unique_ptr<NativeHandler>(new EventBindings(context)));
846 module_system->RegisterNativeHandler( 839 module_system->RegisterNativeHandler(
847 "messaging_natives", std::unique_ptr<NativeHandler>( 840 "messaging_natives",
848 MessagingBindings::Get(dispatcher, context))); 841 std::unique_ptr<NativeHandler>(MessagingBindings::Get(context)));
849 module_system->RegisterNativeHandler( 842 module_system->RegisterNativeHandler(
850 "apiDefinitions", std::unique_ptr<NativeHandler>( 843 "apiDefinitions", std::unique_ptr<NativeHandler>(
851 new ApiDefinitionsNatives(dispatcher, context))); 844 new ApiDefinitionsNatives(dispatcher, context)));
852 module_system->RegisterNativeHandler( 845 module_system->RegisterNativeHandler(
853 "sendRequest", std::unique_ptr<NativeHandler>( 846 "sendRequest", std::unique_ptr<NativeHandler>(
854 new SendRequestNatives(request_sender, context))); 847 new SendRequestNatives(request_sender, context)));
855 module_system->RegisterNativeHandler( 848 module_system->RegisterNativeHandler(
856 "setIcon", std::unique_ptr<NativeHandler>(new SetIconNatives(context))); 849 "setIcon", std::unique_ptr<NativeHandler>(new SetIconNatives(context)));
857 module_system->RegisterNativeHandler( 850 module_system->RegisterNativeHandler(
858 "activityLogger", 851 "activityLogger",
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 978
986 InitOriginPermissions(extension); 979 InitOriginPermissions(extension);
987 980
988 UpdateActiveExtensions(); 981 UpdateActiveExtensions();
989 } 982 }
990 983
991 void Dispatcher::OnCancelSuspend(const std::string& extension_id) { 984 void Dispatcher::OnCancelSuspend(const std::string& extension_id) {
992 DispatchEvent(extension_id, kOnSuspendCanceledEvent); 985 DispatchEvent(extension_id, kOnSuspendCanceledEvent);
993 } 986 }
994 987
995 void Dispatcher::OnDeliverMessage(int target_port_id, const Message& message) { 988 void Dispatcher::OnDeliverMessage(int target_port_id,
989 int source_tab_id,
990 const Message& message) {
996 std::unique_ptr<RequestSender::ScopedTabID> scoped_tab_id; 991 std::unique_ptr<RequestSender::ScopedTabID> scoped_tab_id;
997 std::map<int, int>::const_iterator it = 992 if (source_tab_id != -1) {
998 port_to_tab_id_map_.find(target_port_id);
999 if (it != port_to_tab_id_map_.end()) {
1000 scoped_tab_id.reset( 993 scoped_tab_id.reset(
1001 new RequestSender::ScopedTabID(request_sender(), it->second)); 994 new RequestSender::ScopedTabID(request_sender(), source_tab_id));
1002 } 995 }
1003 996
1004 MessagingBindings::DeliverMessage(*script_context_set_, target_port_id, 997 MessagingBindings::DeliverMessage(*script_context_set_, target_port_id,
1005 message, 998 message,
1006 NULL); // All render frames. 999 NULL); // All render frames.
1007 } 1000 }
1008 1001
1009 void Dispatcher::OnDispatchOnConnect( 1002 void Dispatcher::OnDispatchOnConnect(
1010 int target_port_id, 1003 int target_port_id,
1011 const std::string& channel_name, 1004 const std::string& channel_name,
1012 const ExtensionMsg_TabConnectionInfo& source, 1005 const ExtensionMsg_TabConnectionInfo& source,
1013 const ExtensionMsg_ExternalConnectionInfo& info, 1006 const ExtensionMsg_ExternalConnectionInfo& info,
1014 const std::string& tls_channel_id) { 1007 const std::string& tls_channel_id) {
1015 DCHECK(!ContainsKey(port_to_tab_id_map_, target_port_id));
1016 DCHECK_EQ(1, target_port_id % 2); // target renderer ports have odd IDs. 1008 DCHECK_EQ(1, target_port_id % 2); // target renderer ports have odd IDs.
1017 int sender_tab_id = -1;
1018 source.tab.GetInteger("id", &sender_tab_id);
1019 port_to_tab_id_map_[target_port_id] = sender_tab_id;
1020 1009
1021 MessagingBindings::DispatchOnConnect(*script_context_set_, target_port_id, 1010 MessagingBindings::DispatchOnConnect(*script_context_set_, target_port_id,
1022 channel_name, source, info, 1011 channel_name, source, info,
1023 tls_channel_id, 1012 tls_channel_id,
1024 NULL); // All render frames. 1013 NULL); // All render frames.
1025 } 1014 }
1026 1015
1027 void Dispatcher::OnDispatchOnDisconnect(int port_id, 1016 void Dispatcher::OnDispatchOnDisconnect(int port_id,
1028 const std::string& error_message) { 1017 const std::string& error_message) {
1029 MessagingBindings::DispatchOnDisconnect(*script_context_set_, port_id, 1018 MessagingBindings::DispatchOnDisconnect(*script_context_set_, port_id,
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 // The "guestViewDeny" module must always be loaded last. It registers 1585 // The "guestViewDeny" module must always be loaded last. It registers
1597 // error-providing custom elements for the GuestView types that are not 1586 // error-providing custom elements for the GuestView types that are not
1598 // available, and thus all of those types must have been checked and loaded 1587 // available, and thus all of those types must have been checked and loaded
1599 // (or not loaded) beforehand. 1588 // (or not loaded) beforehand.
1600 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { 1589 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) {
1601 module_system->Require("guestViewDeny"); 1590 module_system->Require("guestViewDeny");
1602 } 1591 }
1603 } 1592 }
1604 1593
1605 } // namespace extensions 1594 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/dispatcher.h ('k') | extensions/renderer/extension_frame_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698