| 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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/common/extensions/background_info.h" | 27 #include "chrome/common/extensions/background_info.h" |
| 28 #include "chrome/common/extensions/extension.h" | 28 #include "chrome/common/extensions/extension.h" |
| 29 #include "chrome/common/extensions/extension_manifest_constants.h" | 29 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 30 #include "chrome/common/extensions/extension_messages.h" | 30 #include "chrome/common/extensions/extension_messages.h" |
| 31 #include "chrome/common/extensions/incognito_handler.h" | 31 #include "chrome/common/extensions/incognito_handler.h" |
| 32 #include "chrome/common/extensions/manifest_handlers/externally_connectable.h" | 32 #include "chrome/common/extensions/manifest_handlers/externally_connectable.h" |
| 33 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 34 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 35 #include "content/public/browser/render_process_host.h" | 35 #include "content/public/browser/render_process_host.h" |
| 36 #include "content/public/browser/render_view_host.h" | 36 #include "content/public/browser/render_view_host.h" |
| 37 #include "content/public/browser/render_widget_host.h" |
| 38 #include "content/public/browser/render_widget_host_view.h" |
| 37 #include "content/public/browser/site_instance.h" | 39 #include "content/public/browser/site_instance.h" |
| 38 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 39 #include "url/gurl.h" | 41 #include "url/gurl.h" |
| 40 | 42 |
| 41 using content::SiteInstance; | 43 using content::SiteInstance; |
| 42 using content::WebContents; | 44 using content::WebContents; |
| 43 | 45 |
| 44 // Since we have 2 ports for every channel, we just index channels by half the | 46 // Since we have 2 ports for every channel, we just index channels by half the |
| 45 // port ID. | 47 // port ID. |
| 46 #define GET_CHANNEL_ID(port_id) ((port_id) / 2) | 48 #define GET_CHANNEL_ID(port_id) ((port_id) / 2) |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 | 316 |
| 315 if (!has_permission) { | 317 if (!has_permission) { |
| 316 DispatchOnDisconnect(source, receiver_port_id, kMissingPermissionError); | 318 DispatchOnDisconnect(source, receiver_port_id, kMissingPermissionError); |
| 317 return; | 319 return; |
| 318 } | 320 } |
| 319 | 321 |
| 320 scoped_ptr<MessageChannel> channel(new MessageChannel()); | 322 scoped_ptr<MessageChannel> channel(new MessageChannel()); |
| 321 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, | 323 channel->opener.reset(new ExtensionMessagePort(source, MSG_ROUTING_CONTROL, |
| 322 source_extension_id)); | 324 source_extension_id)); |
| 323 | 325 |
| 326 // Get handle of the native view and pass it to the native messaging host. |
| 327 gfx::NativeView native_view = |
| 328 content::RenderWidgetHost::FromID(source_process_id, source_routing_id)-> |
| 329 GetView()->GetNativeView(); |
| 330 |
| 324 scoped_ptr<NativeMessageProcessHost> native_process = | 331 scoped_ptr<NativeMessageProcessHost> native_process = |
| 325 NativeMessageProcessHost::Create( | 332 NativeMessageProcessHost::Create( |
| 333 native_view, |
| 326 base::WeakPtr<NativeMessageProcessHost::Client>( | 334 base::WeakPtr<NativeMessageProcessHost::Client>( |
| 327 weak_factory_.GetWeakPtr()), | 335 weak_factory_.GetWeakPtr()), |
| 328 source_extension_id, native_app_name, receiver_port_id); | 336 source_extension_id, native_app_name, receiver_port_id); |
| 329 | 337 |
| 330 // Abandon the channel. | 338 // Abandon the channel. |
| 331 if (!native_process.get()) { | 339 if (!native_process.get()) { |
| 332 LOG(ERROR) << "Failed to create native process."; | 340 LOG(ERROR) << "Failed to create native process."; |
| 333 DispatchOnDisconnect( | 341 DispatchOnDisconnect( |
| 334 source, receiver_port_id, kReceivingEndDoesntExistError); | 342 source, receiver_port_id, kReceivingEndDoesntExistError); |
| 335 return; | 343 return; |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 } | 603 } |
| 596 | 604 |
| 597 void MessageService::DispatchOnDisconnect(content::RenderProcessHost* source, | 605 void MessageService::DispatchOnDisconnect(content::RenderProcessHost* source, |
| 598 int port_id, | 606 int port_id, |
| 599 const std::string& error_message) { | 607 const std::string& error_message) { |
| 600 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); | 608 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); |
| 601 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(port_id), error_message); | 609 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(port_id), error_message); |
| 602 } | 610 } |
| 603 | 611 |
| 604 } // namespace extensions | 612 } // namespace extensions |
| OLD | NEW |