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/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 §ion, | |
| 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 = render_view_host()->GetProcess()-> | |
| 72 GetTransportDIB(params.damage_buffer_id); | |
| 73 #elif defined(OS_ANDROID) | |
| 74 damage_buffer = TransportDIB::Map(params.damage_buffer_id); | |
| 75 #elif defined(OS_POSIX) | |
| 76 damage_buffer = TransportDIB::Map(params.damage_buffer_id.shmkey); | |
| 77 #endif // defined(OS_POSIX) | |
| 78 DCHECK(damage_buffer); | |
| 79 // TODO(fsamuel): Schedule this later so that we don't stall the embedder for | |
| 80 // too long. | |
| 81 embedder_->ResizeGuest(instance_id, | |
| 82 damage_buffer, | |
| 83 params.width, | |
| 84 params.height, | |
| 85 params.resize_pending, | |
| 86 params.scale_factor); | |
| 87 } | |
| 88 | |
| 89 void BrowserPluginEmbedderHelper::OnHandleInputEvent( | |
| 90 const IPC::SyncMessage& message, | |
| 91 bool* handled) { | |
| 92 *handled = true; | |
| 93 PickleIterator iter(message); | |
| 94 | |
| 95 // TODO(fsamuel): This appears to be a monotonically increasing value. | |
| 96 int instance_id = -1; | |
| 97 const char* guest_rect_data = NULL; | |
| 98 int guest_rect_data_length = -1; | |
| 99 const char* input_event_data = NULL; | |
| 100 int input_event_data_length = -1; | |
| 101 if (!iter.SkipBytes(4) || | |
| 102 !message.ReadInt(&iter, &instance_id) || | |
| 103 !message.ReadData(&iter, &guest_rect_data, &guest_rect_data_length) || | |
| 104 !message.ReadData(&iter, &input_event_data, &input_event_data_length)) { | |
| 105 *handled = false; | |
| 106 return; | |
| 107 } | |
| 108 const gfx::Rect* guest_rect = | |
| 109 reinterpret_cast<const gfx::Rect*>(guest_rect_data); | |
| 110 const WebKit::WebInputEvent* input_event = | |
| 111 reinterpret_cast<const WebKit::WebInputEvent*>(input_event_data); | |
| 112 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
| 113 render_view_host()); | |
| 114 | |
| 115 // Convert the window coordinates into screen coordinates. | |
| 116 gfx::Rect guest_screen_rect(*guest_rect); | |
| 117 if (rvh->GetView()) | |
|
awong
2012/09/06 00:23:27
Use braces if body of if is multi-line.
lazyboy
2012/09/06 04:33:53
Done.
| |
| 118 guest_screen_rect.Offset( | |
| 119 rvh->GetView()->GetViewBounds().origin()); | |
| 120 | |
| 121 IPC::Message* reply_message = | |
| 122 IPC::SyncMessage::GenerateReply(&message); | |
| 123 embedder_->HandleInputEvent(instance_id, | |
| 124 rvh, | |
| 125 guest_screen_rect, | |
| 126 *input_event, | |
| 127 reply_message); | |
| 128 } | |
| 129 | |
| 130 void BrowserPluginEmbedderHelper::OnNavigateGuest(int instance_id, | |
| 131 int64 frame_id, | |
| 132 const std::string& src, | |
| 133 const gfx::Size& size) { | |
| 134 embedder_->NavigateGuest(render_view_host(), instance_id, frame_id, src, | |
| 135 size); | |
| 136 } | |
| 137 | |
| 138 void BrowserPluginEmbedderHelper::OnUpdateRectACK(int instance_id, | |
| 139 int message_id, | |
| 140 const gfx::Size& size) { | |
| 141 embedder_->UpdateRectACK(instance_id, message_id, size); | |
| 142 } | |
| 143 | |
| 144 void BrowserPluginEmbedderHelper::OnSetFocus(int instance_id, bool focused) { | |
| 145 embedder_->SetFocus(instance_id, focused); | |
| 146 } | |
| 147 | |
| 148 void BrowserPluginEmbedderHelper::OnPluginDestroyed(int instance_id) { | |
| 149 embedder_->PluginDestroyed(instance_id); | |
| 150 } | |
| 151 | |
| 152 } // namespace content | |
| OLD | NEW |