| OLD | NEW |
| 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/browser/extensions/api/messaging/message_service.h" | 5 #include "chrome/browser/extensions/api/messaging/message_service.h" |
| 6 | 6 |
| 7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/api/messaging/extension_message_port.h" | 13 #include "chrome/browser/extensions/api/messaging/extension_message_port.h" |
| 14 #include "chrome/browser/extensions/api/messaging/native_message_port.h" | 14 #include "chrome/browser/extensions/api/messaging/native_message_port.h" |
| 15 #include "chrome/browser/extensions/extension_host.h" | 15 #include "chrome/browser/extensions/extension_host.h" |
| 16 #include "chrome/browser/extensions/extension_process_manager.h" | 16 #include "chrome/browser/extensions/extension_process_manager.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
| 19 #include "chrome/browser/extensions/extension_tab_util.h" | 19 #include "chrome/browser/extensions/extension_tab_util.h" |
| 20 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 20 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
| 21 #include "chrome/browser/extensions/process_map.h" | 21 #include "chrome/browser/extensions/process_map.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/tab_contents/tab_util.h" | 23 #include "chrome/browser/tab_contents/tab_util.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 25 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
| 26 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
| 27 #include "chrome/common/extensions/extension_messages.h" | 26 #include "chrome/common/extensions/extension_messages.h" |
| 28 #include "chrome/common/view_type.h" | 27 #include "chrome/common/view_type.h" |
| 29 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 31 #include "content/public/browser/render_process_host.h" | 30 #include "content/public/browser/render_process_host.h" |
| 32 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
| 33 #include "content/public/browser/site_instance.h" | 32 #include "content/public/browser/site_instance.h" |
| 34 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 void MessageService::OpenChannelToTab( | 255 void MessageService::OpenChannelToTab( |
| 257 int source_process_id, int source_routing_id, int receiver_port_id, | 256 int source_process_id, int source_routing_id, int receiver_port_id, |
| 258 int tab_id, const std::string& extension_id, | 257 int tab_id, const std::string& extension_id, |
| 259 const std::string& channel_name) { | 258 const std::string& channel_name) { |
| 260 content::RenderProcessHost* source = | 259 content::RenderProcessHost* source = |
| 261 content::RenderProcessHost::FromID(source_process_id); | 260 content::RenderProcessHost::FromID(source_process_id); |
| 262 if (!source) | 261 if (!source) |
| 263 return; | 262 return; |
| 264 Profile* profile = Profile::FromBrowserContext(source->GetBrowserContext()); | 263 Profile* profile = Profile::FromBrowserContext(source->GetBrowserContext()); |
| 265 | 264 |
| 266 TabContents* contents = NULL; | 265 WebContents* contents = NULL; |
| 267 scoped_ptr<MessagePort> receiver; | 266 scoped_ptr<MessagePort> receiver; |
| 268 if (ExtensionTabUtil::GetTabById(tab_id, profile, true, | 267 if (ExtensionTabUtil::GetTabById(tab_id, profile, true, |
| 269 NULL, NULL, &contents, NULL)) { | 268 NULL, NULL, &contents, NULL)) { |
| 270 receiver.reset(new ExtensionMessagePort( | 269 receiver.reset(new ExtensionMessagePort( |
| 271 contents->web_contents()->GetRenderProcessHost(), | 270 contents->GetRenderProcessHost(), |
| 272 contents->web_contents()->GetRenderViewHost()->GetRoutingID(), | 271 contents->GetRenderViewHost()->GetRoutingID(), |
| 273 extension_id)); | 272 extension_id)); |
| 274 } | 273 } |
| 275 | 274 |
| 276 if (contents && contents->web_contents()->GetController().NeedsReload()) { | 275 if (contents && contents->GetController().NeedsReload()) { |
| 277 // The tab isn't loaded yet. Don't attempt to connect. Treat this as a | 276 // The tab isn't loaded yet. Don't attempt to connect. Treat this as a |
| 278 // disconnect. | 277 // disconnect. |
| 279 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, extension_id); | 278 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, extension_id); |
| 280 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(receiver_port_id), true); | 279 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(receiver_port_id), true); |
| 281 return; | 280 return; |
| 282 } | 281 } |
| 283 | 282 |
| 284 WebContents* source_contents = tab_util::GetWebContentsByID( | 283 WebContents* source_contents = tab_util::GetWebContentsByID( |
| 285 source_process_id, source_routing_id); | 284 source_process_id, source_routing_id); |
| 286 | 285 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 return; | 500 return; |
| 502 | 501 |
| 503 params->source = source; | 502 params->source = source; |
| 504 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), | 503 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), |
| 505 MSG_ROUTING_CONTROL, | 504 MSG_ROUTING_CONTROL, |
| 506 params->target_extension_id)); | 505 params->target_extension_id)); |
| 507 OpenChannelImpl(params.Pass()); | 506 OpenChannelImpl(params.Pass()); |
| 508 } | 507 } |
| 509 | 508 |
| 510 } // namespace extensions | 509 } // namespace extensions |
| OLD | NEW |