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