Index: content/browser/browser_plugin/browser_plugin_host_embedder_role.cc |
diff --git a/content/browser/browser_plugin/browser_plugin_host_embedder_role.cc b/content/browser/browser_plugin/browser_plugin_host_embedder_role.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b871a9a4952ed33a7da5fc8160b3854abf2f74e4 |
--- /dev/null |
+++ b/content/browser/browser_plugin/browser_plugin_host_embedder_role.cc |
@@ -0,0 +1,179 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/browser_plugin/browser_plugin_host_embedder_role.h" |
+ |
+#include "base/time.h" |
+#include "content/browser/browser_plugin/browser_plugin_host_embedder_delegate.h" |
+#include "content/browser/renderer_host/render_view_host_impl.h" |
+#include "content/browser/renderer_host/render_widget_host_impl.h" |
+#include "content/browser/web_contents/web_contents_impl.h" |
+#include "content/common/browser_plugin_messages.h" |
+#include "content/common/view_messages.h" |
+#include "content/public/browser/notification_details.h" |
+#include "content/public/browser/notification_service.h" |
+#include "content/public/browser/notification_source.h" |
+#include "content/public/browser/notification_types.h" |
+#include "content/public/browser/render_process_host.h" |
+#include "content/public/browser/render_view_host.h" |
+#include "content/public/browser/render_widget_host_view.h" |
+#include "ui/gfx/size.h" |
+ |
+namespace content { |
+ |
+BrowserPluginHostEmbedderRole::BrowserPluginHostEmbedderRole( |
+ WebContentsImpl* web_contents, RenderViewHost* render_view_host) |
+ : RenderViewHostObserver(render_view_host) { |
+ delegate_.reset(new BrowserPluginHostEmbedderDelegate(web_contents)); |
+ // Listen to visibility changes so that an embedder hides its guests |
+ // as well. |
+ registrar_.Add(this, |
+ NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
+ Source<WebContents>(web_contents)); |
+} |
+ |
+BrowserPluginHostEmbedderRole::~BrowserPluginHostEmbedderRole() { |
+} |
+ |
+bool BrowserPluginHostEmbedderRole::Send(IPC::Message* message) { |
+ return RenderViewHostObserver::Send(message); |
+} |
+ |
+bool BrowserPluginHostEmbedderRole::OnMessageReceived( |
+ const IPC::Message& message) { |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(BrowserPluginHostEmbedderRole, message) |
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, |
+ OnNavigateGuest); |
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) |
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK); |
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus); |
+ IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_HandleInputEvent, |
+ OnHandleInputEvent(*static_cast<const IPC::SyncMessage*>(&message), |
+ &handled)) |
+ IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, |
+ OnPluginDestroyed); |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+void BrowserPluginHostEmbedderRole::NavigateGuest(int instance_id, |
+ int64 frame_id, |
+ const std::string& src, |
+ const gfx::Size& size) { |
+ delegate_->NavigateGuest(render_view_host(), instance_id, frame_id, src, |
+ size); |
+} |
+ |
+void BrowserPluginHostEmbedderRole::OnResizeGuest( |
+ int instance_id, |
+ const BrowserPluginHostMsg_ResizeGuest_Params& params) { |
+ TransportDIB* damage_buffer = NULL; |
+#if defined(OS_WIN) |
+ // On Windows we need to duplicate the handle from the remote process |
rjkroege
2012/08/22 21:57:38
need a . at end of setnence.
lazyboy
2012/08/23 00:45:22
Done.
|
+ HANDLE section; |
+ DuplicateHandle(GetHandle(), |
+ params.damage_buffer_id.handle, |
+ GetCurrentProcess(), |
+ §ion, |
+ STANDARD_RIGHTS_REQUIRED | FILE_MAP_READ | FILE_MAP_WRITE, |
+ FALSE, 0); |
+ damage_buffer = TransportDIB::Map(section); |
+#elif defined(OS_MACOSX) |
+ // On OSX, the browser allocates all DIBs and keeps a file descriptor around |
+ // for each. |
+ damage_buffer = widget_helper_->MapTransportDIB(params.damage_buffer_id); |
+#elif defined(OS_ANDROID) |
+ damage_buffer = TransportDIB::Map(params.damage_buffer_id); |
+#elif defined(OS_POSIX) |
+ damage_buffer = TransportDIB::Map(params.damage_buffer_id.shmkey); |
+#endif // defined(OS_POSIX) |
+ DCHECK(damage_buffer); |
+ // TODO(fsamuel): Schedule this later so that we don't stall the embedder for |
+ // too long. |
+ delegate_->ResizeGuest(instance_id, |
+ damage_buffer, |
+ params.width, |
+ params.height, |
+ params.resize_pending, |
+ params.scale_factor); |
+} |
+ |
+void BrowserPluginHostEmbedderRole::OnHandleInputEvent( |
+ const IPC::SyncMessage& message, |
+ bool* handled) { |
+ *handled = true; |
+ PickleIterator iter(message); |
+ |
+ // TODO(fsamuel): This appears to be a monotonically increasing value. |
rjkroege
2012/08/22 21:57:38
let's DCHECK that we believe it to be so.
lazyboy
2012/08/23 00:45:22
I have no idea abt this TODO, Fady is probably the
|
+ int instance_id = -1; |
+ const char* guest_rect_data = NULL; |
+ int guest_rect_data_length = -1; |
+ const char* input_event_data = NULL; |
+ int input_event_data_length = -1; |
+ if (!iter.SkipBytes(4) || |
+ !message.ReadInt(&iter, &instance_id) || |
+ !message.ReadData(&iter, &guest_rect_data, &guest_rect_data_length) || |
+ !message.ReadData(&iter, &input_event_data, &input_event_data_length)) { |
+ *handled = false; |
+ return; |
+ } |
+ const gfx::Rect* guest_rect = |
+ reinterpret_cast<const gfx::Rect*>(guest_rect_data); |
+ const WebKit::WebInputEvent* input_event = |
+ reinterpret_cast<const WebKit::WebInputEvent*>(input_event_data); |
+ RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
+ render_view_host()); |
+ |
+ // Convert the window coordinates into screen coordinates. |
+ gfx::Rect guest_screen_rect(*guest_rect); |
+ if (rvh->GetView()) |
+ guest_screen_rect.Offset( |
+ rvh->GetView()->GetViewBounds().origin()); |
+ |
+ IPC::Message* reply_message = |
+ IPC::SyncMessage::GenerateReply(&message); |
+ delegate_->HandleInputEvent(instance_id, rvh, guest_screen_rect, *input_event, |
+ reply_message); |
+} |
+ |
+void BrowserPluginHostEmbedderRole::OnNavigateGuest(int instance_id, |
+ int64 frame_id, |
+ const std::string& src, |
+ const gfx::Size& size) { |
+ delegate_->NavigateGuest(render_view_host(), instance_id, frame_id, src, |
+ size); |
+} |
+ |
+void BrowserPluginHostEmbedderRole::OnUpdateRectACK(int instance_id, |
+ int message_id, |
+ const gfx::Size& size) { |
+ delegate_->UpdateRectACK(instance_id, message_id, size); |
+} |
+ |
+void BrowserPluginHostEmbedderRole::OnSetFocus(int instance_id, bool focused) { |
+ delegate_->SetFocus(instance_id, focused); |
+} |
+ |
+void BrowserPluginHostEmbedderRole::OnPluginDestroyed(int instance_id) { |
+ delegate_->PluginDestroyed(instance_id); |
+} |
+ |
+void BrowserPluginHostEmbedderRole::Observe( |
+ int type, |
+ const NotificationSource& source, |
+ const NotificationDetails& details) { |
+ switch (type) { |
+ case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: { |
+ bool visible = *Details<bool>(details).ptr(); |
+ delegate_->WebContentsVisiblitlyChanged(visible); |
+ break; |
+ } |
+ default: |
+ NOTREACHED() << "Unexpected notification type: " << type; |
+ } |
+} |
+ |
+} // namespace content |