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 BrowserPluginChannelManager::~BrowserPluginChannelManager() { | |
22 } | |
23 | |
24 void BrowserPluginChannelManager::CreateRenderView( | |
25 const ViewMsg_New_Params& params) { | |
26 IPC::ChannelHandle embedder_channel_handle; | |
27 embedder_channel_handle.name = | |
28 IPC::Channel::GenerateVerifiedChannelID(params.embedder_channel_name); | |
29 bool success = true; | |
30 scoped_refptr<GuestToEmbedderChannel> channel = | |
31 GetChannelByName(params.embedder_channel_name); | |
32 if (!channel) { | |
33 channel = new GuestToEmbedderChannel(params.embedder_channel_name, | |
34 embedder_channel_handle.name); | |
35 success = channel->InitChannel(embedder_channel_handle); | |
36 | |
37 #if defined(OS_POSIX) | |
38 // On POSIX, transfer ownership of the renderer-side (client) FD. | |
39 // This ensures this process will be notified when it is closed even if a | |
40 // connection is not established. | |
41 embedder_channel_handle.socket = | |
42 base::FileDescriptor(channel->TakeRendererFD(), true); | |
43 if (embedder_channel_handle.socket.fd == -1) | |
44 success = false; | |
45 #endif | |
46 DCHECK(success); | |
47 embedder_channels_[params.embedder_channel_name] = channel; | |
48 } | |
49 RenderViewImpl* render_view = | |
50 RenderViewImpl::Create( | |
51 params.parent_window, | |
52 params.opener_route_id, | |
53 params.renderer_preferences, | |
54 params.web_preferences, | |
55 new SharedRenderViewCounter(0), | |
56 params.view_id, | |
57 params.surface_id, | |
58 params.session_storage_namespace_id, | |
59 params.frame_name, | |
60 false, | |
61 params.swapped_out, | |
62 params.next_page_id, | |
63 params.screen_info, | |
64 channel, | |
65 params.accessibility_mode); | |
66 ReportChannelToEmbedder(render_view, | |
67 embedder_channel_handle, | |
68 params.embedder_channel_name, | |
69 params.embedder_container_id); | |
70 } | |
71 | |
72 void BrowserPluginChannelManager::ReportChannelToEmbedder( | |
73 RenderViewImpl* render_view, | |
74 const IPC::ChannelHandle& embedder_channel_handle, | |
75 const std::string& embedder_channel_name, | |
76 int embedder_container_id) { | |
77 std::pair<std::string, int> pending_guests_key = | |
78 std::make_pair(embedder_channel_name, embedder_container_id); | |
79 DCHECK(pending_guests_.find(pending_guests_key) == | |
80 pending_guests_.end()); | |
81 pending_guests_[pending_guests_key] = render_view->AsWeakPtr(); | |
82 RenderThreadImpl::current()->Send( | |
83 new BrowserPluginHostMsg_ConnectToChannel(render_view->GetRoutingID(), | |
84 embedder_channel_handle)); | |
85 } | |
86 | |
87 bool BrowserPluginChannelManager::OnControlMessageReceived( | |
88 const IPC::Message& message) { | |
89 bool handled = true; | |
90 IPC_BEGIN_MESSAGE_MAP(BrowserPluginChannelManager, message) | |
91 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadGuest, OnLoadGuest) | |
92 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) | |
93 IPC_MESSAGE_UNHANDLED(handled = false) | |
94 IPC_END_MESSAGE_MAP() | |
95 | |
96 return handled; | |
97 } | |
98 | |
99 GuestToEmbedderChannel* BrowserPluginChannelManager::GetChannelByName( | |
100 const std::string& embedder_channel_name) { | |
101 EmbedderChannelNameToChannelMap::iterator it = | |
102 embedder_channels_.find(embedder_channel_name); | |
103 if (it != embedder_channels_.end()) | |
104 return it->second; | |
105 return NULL; | |
106 } | |
107 | |
108 void BrowserPluginChannelManager::RemoveChannelByName( | |
109 const std::string& embedder_channel_name) { | |
110 embedder_channels_.erase(embedder_channel_name); | |
111 } | |
112 | |
113 void BrowserPluginChannelManager::GuestReady( | |
114 PP_Instance instance, | |
115 const std::string& embedder_channel_name, | |
116 int embedder_container_id) { | |
117 std::pair<std::string, int> pending_guests_key = | |
118 make_pair(embedder_channel_name, embedder_container_id); | |
119 DCHECK(pending_guests_.find(pending_guests_key) != | |
120 pending_guests_.end()); | |
121 RenderViewImpl* render_view = pending_guests_[pending_guests_key]; | |
122 pending_guests_.erase(pending_guests_key); | |
123 GuestToEmbedderChannel* channel = render_view->GetGuestToEmbedderChannel(); | |
124 // Associate the RenderView with the provided PP_Instance ID, request the | |
125 // receipt of events, and initialize the graphics context. | |
126 channel->AddGuest(instance, render_view); | |
127 render_view->GuestReady(instance); | |
128 } | |
129 | |
130 void BrowserPluginChannelManager::OnLoadGuest( | |
131 int instance_id, | |
132 int guest_process_id, | |
133 const IPC::ChannelHandle& channel_handle) { | |
134 BrowserPlugin* browser_plugin = BrowserPlugin::FromID(instance_id); | |
135 browser_plugin->LoadGuest(guest_process_id, channel_handle); | |
136 } | |
137 | |
138 void BrowserPluginChannelManager::OnAdvanceFocus(int instance_id, | |
139 bool reverse) { | |
140 BrowserPlugin* browser_plugin = BrowserPlugin::FromID(instance_id); | |
141 browser_plugin->AdvanceFocus(reverse); | |
142 } | |
143 | |
144 } // namespace content | |
OLD | NEW |