Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/browser_plugin/browser_plugin_channel_manager.h" | |
| 6 | |
| 7 #include "base/process_util.h" | |
| 8 #include "content/common/browser_plugin_messages.h" | |
| 9 #include "content/common/view_messages.h" | |
| 10 #include "content/renderer/browser_plugin/browser_plugin.h" | |
| 11 #include "content/renderer/browser_plugin/guest_to_embedder_channel.h" | |
| 12 #include "content/renderer/render_thread_impl.h" | |
| 13 #include "content/renderer/render_view_impl.h" | |
| 14 #include "ppapi/c/pp_instance.h" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 BrowserPluginChannelManager::BrowserPluginChannelManager() { | |
| 19 } | |
| 20 | |
| 21 void BrowserPluginChannelManager::CreateRenderView( | |
| 22 const ViewMsg_New_Params& params) { | |
| 23 IPC::ChannelHandle plugin_handle; | |
| 24 plugin_handle.name = | |
| 25 IPC::Channel::GenerateVerifiedChannelID(params.embedder_channel_name); | |
| 26 bool success = true; | |
| 27 scoped_refptr<GuestToEmbedderChannel> channel = | |
| 28 GetChannelByName(params.embedder_channel_name); | |
| 29 if (!channel) { | |
| 30 channel = new GuestToEmbedderChannel(params.embedder_channel_name); | |
| 31 success = channel->InitChannel(plugin_handle); | |
| 32 | |
| 33 #if defined(OS_POSIX) | |
| 34 // On POSIX, transfer ownership of the renderer-side (client) FD. | |
| 35 // This ensures this process will be notified when it is closed even if a | |
| 36 // connection is not established. | |
| 37 plugin_handle.socket = | |
| 38 base::FileDescriptor(channel->TakeRendererFD(), true); | |
| 39 if (plugin_handle.socket.fd == -1) | |
| 40 success = false; | |
| 41 #endif | |
| 42 DCHECK(success); | |
| 43 embedder_channels_[params.embedder_channel_name] = channel; | |
| 44 } | |
| 45 DCHECK(pending_navigations_.find(params.view_id) == | |
| 46 pending_navigations_.end()); | |
| 47 pending_navigations_[params.view_id] = | |
| 48 RenderViewImpl::Create( | |
| 49 params.parent_window, | |
| 50 params.opener_route_id, | |
| 51 params.renderer_preferences, | |
| 52 params.web_preferences, | |
| 53 new SharedRenderViewCounter(0), | |
| 54 params.view_id, | |
| 55 params.surface_id, | |
| 56 params.session_storage_namespace_id, | |
| 57 params.frame_name, | |
| 58 false, | |
| 59 params.swapped_out, | |
| 60 params.next_page_id, | |
| 61 params.screen_info, | |
| 62 channel, | |
| 63 params.accessibility_mode)->AsWeakPtr(); | |
| 64 Send(new BrowserPluginHostMsg_ConnectToChannel(params.view_id, | |
| 65 success ? plugin_handle : IPC::ChannelHandle())); | |
| 66 } | |
| 67 | |
| 68 bool BrowserPluginChannelManager::Send(IPC::Message* message) { | |
|
jam
2012/05/16 02:22:40
nit: no need to have this wrapper function. just c
Fady Samuel
2012/05/16 04:43:54
Done.
| |
| 69 return RenderThreadImpl::current()->Send(message); | |
| 70 } | |
| 71 | |
| 72 bool BrowserPluginChannelManager::OnControlMessageReceived( | |
| 73 const IPC::Message& message) { | |
| 74 bool handled = true; | |
| 75 IPC_BEGIN_MESSAGE_MAP(BrowserPluginChannelManager, message) | |
| 76 IPC_MESSAGE_HANDLER(BrowserPluginMsg_CompleteNavigation, | |
| 77 OnCompleteNavigation) | |
| 78 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadGuest, OnLoadGuest) | |
| 79 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 80 IPC_END_MESSAGE_MAP() | |
| 81 | |
| 82 return handled; | |
| 83 } | |
| 84 | |
| 85 GuestToEmbedderChannel* BrowserPluginChannelManager::GetChannelByName( | |
| 86 const std::string& embedder_channel_name) { | |
| 87 EmbedderChannelNameToChannelMap::iterator it = | |
| 88 embedder_channels_.find(embedder_channel_name); | |
| 89 if (it != embedder_channels_.end()) | |
| 90 return it->second; | |
| 91 return NULL; | |
| 92 } | |
| 93 | |
| 94 void BrowserPluginChannelManager::RemoveChannelByName( | |
| 95 const std::string& embedder_channel_name) { | |
| 96 embedder_channels_.erase(embedder_channel_name); | |
| 97 } | |
| 98 | |
| 99 void BrowserPluginChannelManager::OnCompleteNavigation( | |
| 100 int guest_routing_id, | |
| 101 PP_Instance instance) { | |
| 102 CHECK(pending_navigations_.find(guest_routing_id) != | |
| 103 pending_navigations_.end()); | |
| 104 RenderViewImpl* render_view = pending_navigations_[guest_routing_id]; | |
| 105 pending_navigations_.erase(guest_routing_id); | |
| 106 GuestToEmbedderChannel* channel = render_view->guest_to_embedder_channel(); | |
| 107 // Associate the RenderView with the provided PP_Instance ID, request the | |
| 108 // receipt of events, and initialize the graphics context. | |
| 109 channel->AddGuest(instance, render_view); | |
| 110 channel->RequestInputEvents(instance); | |
| 111 render_view->GuestReady(instance); | |
| 112 } | |
| 113 | |
| 114 void BrowserPluginChannelManager::OnLoadGuest( | |
| 115 int instance_id, | |
| 116 int guest_process_id, | |
| 117 const IPC::ChannelHandle& channel_handle) { | |
| 118 BrowserPlugin* browser_plugin = BrowserPlugin::FromID(instance_id); | |
| 119 DCHECK(browser_plugin); | |
|
jam
2012/05/16 02:22:40
nit: dcheck not useful here. if it's null, the nex
Fady Samuel
2012/05/16 04:43:54
Done.
| |
| 120 browser_plugin->LoadGuest(guest_process_id, channel_handle); | |
| 121 } | |
| 122 | |
| 123 } // namespace content | |
| OLD | NEW |