Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: content/browser/browser_plugin/browser_plugin_embedder_helper.cc

Issue 10868012: Browser Plugin: New Implementation (Browser Side) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master-trial-obrowser
Patch Set: Fix incorrect sync+rebase. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/browser/browser_plugin/browser_plugin_embedder_helper.h"
6
7 #include "base/time.h"
8 #include "content/browser/browser_plugin/browser_plugin_embedder.h"
9 #include "content/browser/renderer_host/render_view_host_impl.h"
10 #include "content/browser/renderer_host/render_widget_host_impl.h"
11 #include "content/browser/web_contents/web_contents_impl.h"
12 #include "content/common/browser_plugin_messages.h"
13 #include "content/common/view_messages.h"
14 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/render_widget_host_view.h"
17 #include "ui/gfx/size.h"
18
19 namespace content {
20
21 BrowserPluginEmbedderHelper::BrowserPluginEmbedderHelper(
22 BrowserPluginEmbedder* embedder,
23 RenderViewHost* render_view_host)
24 : RenderViewHostObserver(render_view_host),
25 embedder_(embedder) {
26 }
27
28 BrowserPluginEmbedderHelper::~BrowserPluginEmbedderHelper() {
29 }
30
31 bool BrowserPluginEmbedderHelper::Send(IPC::Message* message) {
32 return RenderViewHostObserver::Send(message);
33 }
34
35 bool BrowserPluginEmbedderHelper::OnMessageReceived(
36 const IPC::Message& message) {
37 bool handled = true;
38 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedderHelper, message)
39 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest,
40 OnNavigateGuest);
41 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest)
42 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK);
43 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus);
44 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_HandleInputEvent,
45 OnHandleInputEvent(*static_cast<const IPC::SyncMessage*>(&message),
46 &handled))
47 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed,
48 OnPluginDestroyed);
49 IPC_MESSAGE_UNHANDLED(handled = false)
50 IPC_END_MESSAGE_MAP()
51 return handled;
52 }
53
54 void BrowserPluginEmbedderHelper::OnResizeGuest(
55 int instance_id,
56 const BrowserPluginHostMsg_ResizeGuest_Params& params) {
57 TransportDIB* damage_buffer = NULL;
58 #if defined(OS_WIN)
59 // On Windows we need to duplicate the handle from the remote process.
60 HANDLE section;
61 DuplicateHandle(GetHandle(),
62 params.damage_buffer_id.handle,
63 GetCurrentProcess(),
64 &section,
65 STANDARD_RIGHTS_REQUIRED | FILE_MAP_READ | FILE_MAP_WRITE,
66 FALSE, 0);
67 damage_buffer = TransportDIB::Map(section);
68 #elif defined(OS_MACOSX)
69 // On OSX, the browser allocates all DIBs and keeps a file descriptor around
70 // for each.
71 damage_buffer = widget_helper_->MapTransportDIB(params.damage_buffer_id);
72 #elif defined(OS_ANDROID)
73 damage_buffer = TransportDIB::Map(params.damage_buffer_id);
74 #elif defined(OS_POSIX)
75 damage_buffer = TransportDIB::Map(params.damage_buffer_id.shmkey);
76 #endif // defined(OS_POSIX)
77 DCHECK(damage_buffer);
78 // TODO(fsamuel): Schedule this later so that we don't stall the embedder for
79 // too long.
80 embedder_->ResizeGuest(instance_id,
81 damage_buffer,
82 params.width,
83 params.height,
84 params.resize_pending,
85 params.scale_factor);
86 }
87
88 void BrowserPluginEmbedderHelper::OnHandleInputEvent(
89 const IPC::SyncMessage& message,
90 bool* handled) {
91 *handled = true;
92 PickleIterator iter(message);
93
94 // TODO(fsamuel): This appears to be a monotonically increasing value.
95 int instance_id = -1;
96 const char* guest_rect_data = NULL;
97 int guest_rect_data_length = -1;
98 const char* input_event_data = NULL;
99 int input_event_data_length = -1;
100 if (!iter.SkipBytes(4) ||
101 !message.ReadInt(&iter, &instance_id) ||
102 !message.ReadData(&iter, &guest_rect_data, &guest_rect_data_length) ||
103 !message.ReadData(&iter, &input_event_data, &input_event_data_length)) {
104 *handled = false;
105 return;
106 }
107 const gfx::Rect* guest_rect =
108 reinterpret_cast<const gfx::Rect*>(guest_rect_data);
109 const WebKit::WebInputEvent* input_event =
110 reinterpret_cast<const WebKit::WebInputEvent*>(input_event_data);
111 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
112 render_view_host());
113
114 // Convert the window coordinates into screen coordinates.
115 gfx::Rect guest_screen_rect(*guest_rect);
116 if (rvh->GetView())
117 guest_screen_rect.Offset(
118 rvh->GetView()->GetViewBounds().origin());
119
120 IPC::Message* reply_message =
121 IPC::SyncMessage::GenerateReply(&message);
122 embedder_->HandleInputEvent(instance_id,
123 rvh,
124 guest_screen_rect,
125 *input_event,
126 reply_message);
127 }
128
129 void BrowserPluginEmbedderHelper::OnNavigateGuest(int instance_id,
130 int64 frame_id,
131 const std::string& src,
132 const gfx::Size& size) {
133 embedder_->NavigateGuest(render_view_host(), instance_id, frame_id, src,
134 size);
135 }
136
137 void BrowserPluginEmbedderHelper::OnUpdateRectACK(int instance_id,
138 int message_id,
139 const gfx::Size& size) {
140 embedder_->UpdateRectACK(instance_id, message_id, size);
141 }
142
143 void BrowserPluginEmbedderHelper::OnSetFocus(int instance_id, bool focused) {
144 embedder_->SetFocus(instance_id, focused);
145 }
146
147 void BrowserPluginEmbedderHelper::OnPluginDestroyed(int instance_id) {
148 embedder_->PluginDestroyed(instance_id);
149 }
150
151 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698