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

Side by Side Diff: chrome/browser/extensions/extension_message_service.cc

Issue 8515027: Define the public version of the browser side RenderProcessHost interface. This interface is not ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/browser/extensions/extension_message_service.h" 5 #include "chrome/browser/extensions/extension_message_service.h"
6 6
7 #include "base/atomic_sequence_num.h" 7 #include "base/atomic_sequence_num.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/extensions/extension_process_manager.h" 11 #include "chrome/browser/extensions/extension_process_manager.h"
12 #include "chrome/browser/extensions/extension_tab_util.h" 12 #include "chrome/browser/extensions/extension_tab_util.h"
13 #include "chrome/browser/extensions/process_map.h" 13 #include "chrome/browser/extensions/process_map.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/tab_contents/tab_util.h" 15 #include "chrome/browser/tab_contents/tab_util.h"
16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
17 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/extensions/extension_messages.h" 18 #include "chrome/common/extensions/extension_messages.h"
19 #include "content/browser/child_process_security_policy.h" 19 #include "content/browser/child_process_security_policy.h"
20 #include "content/browser/renderer_host/render_process_host.h"
21 #include "content/browser/renderer_host/render_view_host.h" 20 #include "content/browser/renderer_host/render_view_host.h"
22 #include "content/browser/tab_contents/tab_contents.h" 21 #include "content/browser/tab_contents/tab_contents.h"
23 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/notification_types.h" 23 #include "content/public/browser/notification_types.h"
24 #include "content/public/browser/render_process_host.h"
25 25
26 // Since we have 2 ports for every channel, we just index channels by half the 26 // Since we have 2 ports for every channel, we just index channels by half the
27 // port ID. 27 // port ID.
28 #define GET_CHANNEL_ID(port_id) ((port_id) / 2) 28 #define GET_CHANNEL_ID(port_id) ((port_id) / 2)
29 #define GET_CHANNEL_OPENER_ID(channel_id) ((channel_id) * 2) 29 #define GET_CHANNEL_OPENER_ID(channel_id) ((channel_id) * 2)
30 #define GET_CHANNEL_RECEIVERS_ID(channel_id) ((channel_id) * 2 + 1) 30 #define GET_CHANNEL_RECEIVERS_ID(channel_id) ((channel_id) * 2 + 1)
31 31
32 // Port1 is always even, port2 is always odd. 32 // Port1 is always even, port2 is always odd.
33 #define IS_OPENER_PORT_ID(port_id) (((port_id) & 1) == 0) 33 #define IS_OPENER_PORT_ID(port_id) (((port_id) & 1) == 0)
34 34
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 149 }
150 150
151 void ExtensionMessageService::OpenChannelToExtension( 151 void ExtensionMessageService::OpenChannelToExtension(
152 int source_process_id, int source_routing_id, int receiver_port_id, 152 int source_process_id, int source_routing_id, int receiver_port_id,
153 const std::string& source_extension_id, 153 const std::string& source_extension_id,
154 const std::string& target_extension_id, 154 const std::string& target_extension_id,
155 const std::string& channel_name) { 155 const std::string& channel_name) {
156 RenderProcessHost* source = RenderProcessHost::FromID(source_process_id); 156 RenderProcessHost* source = RenderProcessHost::FromID(source_process_id);
157 if (!source) 157 if (!source)
158 return; 158 return;
159 Profile* profile = Profile::FromBrowserContext(source->browser_context()); 159 Profile* profile = Profile::FromBrowserContext(source->GetBrowserContext());
160 160
161 // Note: we use the source's profile here. If the source is an incognito 161 // Note: we use the source's profile here. If the source is an incognito
162 // process, we will use the incognito EPM to find the right extension process, 162 // process, we will use the incognito EPM to find the right extension process,
163 // which depends on whether the extension uses spanning or split mode. 163 // which depends on whether the extension uses spanning or split mode.
164 MessagePort receiver( 164 MessagePort receiver(
165 GetExtensionProcess(profile, target_extension_id), 165 GetExtensionProcess(profile, target_extension_id),
166 MSG_ROUTING_CONTROL); 166 MSG_ROUTING_CONTROL);
167 TabContents* source_contents = tab_util::GetTabContentsByID( 167 TabContents* source_contents = tab_util::GetTabContentsByID(
168 source_process_id, source_routing_id); 168 source_process_id, source_routing_id);
169 169
170 // Include info about the opener's tab (if it was a tab). 170 // Include info about the opener's tab (if it was a tab).
171 std::string tab_json = "null"; 171 std::string tab_json = "null";
172 if (source_contents) { 172 if (source_contents) {
173 scoped_ptr<DictionaryValue> tab_value( 173 scoped_ptr<DictionaryValue> tab_value(
174 ExtensionTabUtil::CreateTabValue(source_contents)); 174 ExtensionTabUtil::CreateTabValue(source_contents));
175 base::JSONWriter::Write(tab_value.get(), false, &tab_json); 175 base::JSONWriter::Write(tab_value.get(), false, &tab_json);
176 } 176 }
177 177
178 OpenChannelImpl(source, tab_json, receiver, receiver_port_id, 178 OpenChannelImpl(source, tab_json, receiver, receiver_port_id,
179 source_extension_id, target_extension_id, channel_name); 179 source_extension_id, target_extension_id, channel_name);
180 } 180 }
181 181
182 void ExtensionMessageService::OpenChannelToTab( 182 void ExtensionMessageService::OpenChannelToTab(
183 int source_process_id, int source_routing_id, int receiver_port_id, 183 int source_process_id, int source_routing_id, int receiver_port_id,
184 int tab_id, const std::string& extension_id, 184 int tab_id, const std::string& extension_id,
185 const std::string& channel_name) { 185 const std::string& channel_name) {
186 RenderProcessHost* source = RenderProcessHost::FromID(source_process_id); 186 RenderProcessHost* source = RenderProcessHost::FromID(source_process_id);
187 if (!source) 187 if (!source)
188 return; 188 return;
189 Profile* profile = Profile::FromBrowserContext(source->browser_context()); 189 Profile* profile = Profile::FromBrowserContext(source->GetBrowserContext());
190 190
191 TabContentsWrapper* contents = NULL; 191 TabContentsWrapper* contents = NULL;
192 MessagePort receiver; 192 MessagePort receiver;
193 if (ExtensionTabUtil::GetTabById(tab_id, profile, true, 193 if (ExtensionTabUtil::GetTabById(tab_id, profile, true,
194 NULL, NULL, &contents, NULL)) { 194 NULL, NULL, &contents, NULL)) {
195 receiver.sender = contents->render_view_host(); 195 receiver.sender = contents->render_view_host();
196 receiver.routing_id = contents->render_view_host()->routing_id(); 196 receiver.routing_id = contents->render_view_host()->routing_id();
197 } 197 }
198 198
199 if (contents && contents->controller().needs_reload()) { 199 if (contents && contents->controller().needs_reload()) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 372
373 if (current->second->opener.sender == sender) { 373 if (current->second->opener.sender == sender) {
374 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first), 374 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first),
375 notify_other_port); 375 notify_other_port);
376 } else if (current->second->receiver.sender == sender) { 376 } else if (current->second->receiver.sender == sender) {
377 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first), 377 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first),
378 notify_other_port); 378 notify_other_port);
379 } 379 }
380 } 380 }
381 } 381 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698