OLD | NEW |
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" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 | 137 |
138 void ExtensionMessageService::OpenChannelToExtension( | 138 void ExtensionMessageService::OpenChannelToExtension( |
139 int source_process_id, int source_routing_id, int receiver_port_id, | 139 int source_process_id, int source_routing_id, int receiver_port_id, |
140 const std::string& source_extension_id, | 140 const std::string& source_extension_id, |
141 const std::string& target_extension_id, | 141 const std::string& target_extension_id, |
142 const std::string& channel_name) { | 142 const std::string& channel_name) { |
143 RenderProcessHost* source = RenderProcessHost::FromID(source_process_id); | 143 RenderProcessHost* source = RenderProcessHost::FromID(source_process_id); |
144 if (!source) | 144 if (!source) |
145 return; | 145 return; |
| 146 Profile* profile = Profile::FromBrowserContext(source->browser_context()); |
146 | 147 |
147 // Note: we use the source's profile here. If the source is an incognito | 148 // Note: we use the source's profile here. If the source is an incognito |
148 // process, we will use the incognito EPM to find the right extension process, | 149 // process, we will use the incognito EPM to find the right extension process, |
149 // which depends on whether the extension uses spanning or split mode. | 150 // which depends on whether the extension uses spanning or split mode. |
150 MessagePort receiver( | 151 MessagePort receiver( |
151 source->profile()->GetExtensionProcessManager()->GetExtensionProcess( | 152 profile->GetExtensionProcessManager()->GetExtensionProcess( |
152 target_extension_id), | 153 target_extension_id), |
153 MSG_ROUTING_CONTROL); | 154 MSG_ROUTING_CONTROL); |
154 TabContents* source_contents = tab_util::GetTabContentsByID( | 155 TabContents* source_contents = tab_util::GetTabContentsByID( |
155 source_process_id, source_routing_id); | 156 source_process_id, source_routing_id); |
156 | 157 |
157 // Include info about the opener's tab (if it was a tab). | 158 // Include info about the opener's tab (if it was a tab). |
158 std::string tab_json = "null"; | 159 std::string tab_json = "null"; |
159 if (source_contents) { | 160 if (source_contents) { |
160 scoped_ptr<DictionaryValue> tab_value( | 161 scoped_ptr<DictionaryValue> tab_value( |
161 ExtensionTabUtil::CreateTabValue(source_contents)); | 162 ExtensionTabUtil::CreateTabValue(source_contents)); |
162 base::JSONWriter::Write(tab_value.get(), false, &tab_json); | 163 base::JSONWriter::Write(tab_value.get(), false, &tab_json); |
163 } | 164 } |
164 | 165 |
165 OpenChannelImpl(source, tab_json, receiver, receiver_port_id, | 166 OpenChannelImpl(source, tab_json, receiver, receiver_port_id, |
166 source_extension_id, target_extension_id, channel_name); | 167 source_extension_id, target_extension_id, channel_name); |
167 } | 168 } |
168 | 169 |
169 void ExtensionMessageService::OpenChannelToTab( | 170 void ExtensionMessageService::OpenChannelToTab( |
170 int source_process_id, int source_routing_id, int receiver_port_id, | 171 int source_process_id, int source_routing_id, int receiver_port_id, |
171 int tab_id, const std::string& extension_id, | 172 int tab_id, const std::string& extension_id, |
172 const std::string& channel_name) { | 173 const std::string& channel_name) { |
173 RenderProcessHost* source = RenderProcessHost::FromID(source_process_id); | 174 RenderProcessHost* source = RenderProcessHost::FromID(source_process_id); |
174 if (!source) | 175 if (!source) |
175 return; | 176 return; |
| 177 Profile* profile = Profile::FromBrowserContext(source->browser_context()); |
176 | 178 |
177 TabContentsWrapper* contents = NULL; | 179 TabContentsWrapper* contents = NULL; |
178 MessagePort receiver; | 180 MessagePort receiver; |
179 if (ExtensionTabUtil::GetTabById(tab_id, source->profile(), true, | 181 if (ExtensionTabUtil::GetTabById(tab_id, profile, true, |
180 NULL, NULL, &contents, NULL)) { | 182 NULL, NULL, &contents, NULL)) { |
181 receiver.sender = contents->render_view_host(); | 183 receiver.sender = contents->render_view_host(); |
182 receiver.routing_id = contents->render_view_host()->routing_id(); | 184 receiver.routing_id = contents->render_view_host()->routing_id(); |
183 } | 185 } |
184 | 186 |
185 if (contents && contents->controller().needs_reload()) { | 187 if (contents && contents->controller().needs_reload()) { |
186 // The tab isn't loaded yet. Don't attempt to connect. Treat this as a | 188 // The tab isn't loaded yet. Don't attempt to connect. Treat this as a |
187 // disconnect. | 189 // disconnect. |
188 DispatchOnDisconnect(MessagePort(source, MSG_ROUTING_CONTROL), | 190 DispatchOnDisconnect(MessagePort(source, MSG_ROUTING_CONTROL), |
189 GET_OPPOSITE_PORT_ID(receiver_port_id), true); | 191 GET_OPPOSITE_PORT_ID(receiver_port_id), true); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 358 |
357 if (current->second->opener.sender == sender) { | 359 if (current->second->opener.sender == sender) { |
358 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first), | 360 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first), |
359 notify_other_port); | 361 notify_other_port); |
360 } else if (current->second->receiver.sender == sender) { | 362 } else if (current->second->receiver.sender == sender) { |
361 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first), | 363 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first), |
362 notify_other_port); | 364 notify_other_port); |
363 } | 365 } |
364 } | 366 } |
365 } | 367 } |
OLD | NEW |