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 // A BrowserPluginGuest represents the browser side of browser <--> renderer |
| 6 // communication. A BrowserPlugin (a WebPlugin) is on the renderer side of |
| 7 // browser <--> guest renderer communication. The 'guest' renderer is a |
| 8 // <browser> tag. |
| 9 // |
| 10 // BrowserPluginGuest lives on the UI thread of the browser process. It has a |
| 11 // helper, BrowserPluginGuestHelper, which is a RenderViewHostObserver. The |
| 12 // helper object receives messages (RenderViewHostMsg_*) directed at the browser |
| 13 // plugin and redirects them to this class. |
| 14 // |
| 15 // Since BrowserPlugin is a WebPlugin, we need to provide overriden behaviors |
| 16 // for messages like handleInputEvent, updateGeometry. Such messages gets |
| 17 // routed into BrowserPluginGuest via its embedder (BrowserPluginEmbedder). |
| 18 // These are BrowserPluginHost_* messages sent from the BrowserPlugin. |
| 19 // |
| 20 // BrowserPluginGuest knows about its embedder process, communication to |
| 21 // renderer happens through the embedder process. |
| 22 // |
| 23 // A BrowserPluginGuest is also associated directly with the WebContents related |
| 24 // to the BrowserPlugin. BrowserPluginGuest is a WebContentsDelegate and |
| 25 // WebContentsObserver for the WebContents. |
| 26 |
| 27 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
| 28 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
| 29 |
| 30 #include <string> |
| 31 #include <map> |
| 32 |
| 33 #include "base/compiler_specific.h" |
| 34 #include "base/id_map.h" |
| 35 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 36 #include "content/public/browser/render_view_host_observer.h" |
| 37 #include "content/public/browser/web_contents_delegate.h" |
| 38 #include "content/public/browser/web_contents_observer.h" |
| 39 #include "ipc/ipc_channel_handle.h" |
| 40 #include "ipc/ipc_sync_message.h" |
| 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 42 #include "ui/surface/transport_dib.h" |
| 43 #include "ui/gfx/rect.h" |
| 44 #include "ui/gfx/size.h" |
| 45 #include "webkit/glue/webcursor.h" |
| 46 |
| 47 namespace gfx { |
| 48 class Size; |
| 49 } |
| 50 |
| 51 struct BrowserPluginHostMsg_ResizeGuest_Params; |
| 52 struct ViewHostMsg_UpdateRect_Params; |
| 53 |
| 54 namespace content { |
| 55 |
| 56 class BrowserPluginHostFactory; |
| 57 class BrowserPluginEmbedder; |
| 58 class RenderProcessHost; |
| 59 |
| 60 // A browser plugin guest provides functionality for WebContents to operate in |
| 61 // the guest role and implements guest specific overrides for ViewHostMsg_* |
| 62 // messages. |
| 63 // |
| 64 // BrowserPluginEmbedder is responsible for creating and destroying a guest. |
| 65 class CONTENT_EXPORT BrowserPluginGuest : public WebContentsDelegate, |
| 66 public WebContentsObserver { |
| 67 public: |
| 68 virtual ~BrowserPluginGuest(); |
| 69 |
| 70 static BrowserPluginGuest* Create(int instance_id, |
| 71 WebContentsImpl* web_contents, |
| 72 content::RenderViewHost* render_view_host); |
| 73 |
| 74 // Overrides factory for testing. Default (NULL) value indicates regular |
| 75 // (non-test) environment. |
| 76 static void set_factory_for_testing(BrowserPluginHostFactory* factory) { |
| 77 content::BrowserPluginGuest::factory_ = factory; |
| 78 } |
| 79 |
| 80 // WebContentsObserver implementation. |
| 81 virtual void DidCommitProvisionalLoadForFrame( |
| 82 int64 frame_id, |
| 83 bool is_main_frame, |
| 84 const GURL& url, |
| 85 PageTransition transition_type, |
| 86 RenderViewHost* render_view_host) OVERRIDE; |
| 87 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; |
| 88 |
| 89 // WebContentsDelegate implementation. |
| 90 virtual void RendererUnresponsive(WebContents* source) OVERRIDE; |
| 91 |
| 92 private: |
| 93 friend class BrowserPluginEmbedder; |
| 94 friend class BrowserPluginGuestHelper; |
| 95 friend class TestBrowserPluginGuest; |
| 96 |
| 97 BrowserPluginGuest(int instance_id, |
| 98 WebContentsImpl* web_contents, |
| 99 RenderViewHost* render_view_host); |
| 100 |
| 101 void set_embedder_render_process_host( |
| 102 RenderProcessHost* render_process_host) { |
| 103 embedder_render_process_host_ = render_process_host; |
| 104 } |
| 105 RenderProcessHost* embedder_render_process_host() { |
| 106 return embedder_render_process_host_; |
| 107 } |
| 108 // Returns the identifier that uniquely identifies a browser plugin guest |
| 109 // within an embedder. |
| 110 int instance_id() const { return instance_id_; } |
| 111 |
| 112 void SetDamageBuffer(TransportDIB* damage_buffer, |
| 113 const gfx::Size& size, |
| 114 float scale_factor); |
| 115 TransportDIB* damage_buffer() const { return damage_buffer_.get(); } |
| 116 const gfx::Size& damage_buffer_size() const { return damage_buffer_size_; } |
| 117 float damage_buffer_scale_factor() const { |
| 118 return damage_buffer_scale_factor_; |
| 119 } |
| 120 |
| 121 void UpdateRect(RenderViewHost* render_view_host, |
| 122 const ViewHostMsg_UpdateRect_Params& params); |
| 123 void UpdateRectACK(int message_id, const gfx::Size& size); |
| 124 // Handles input event routed through the embedder (which is initiated in the |
| 125 // browser plugin (renderer side of the embedder)). |
| 126 void HandleInputEvent(RenderViewHost* render_view_host, |
| 127 const gfx::Rect& guest_rect, |
| 128 const WebKit::WebInputEvent& event, |
| 129 IPC::Message* reply_message); |
| 130 // Overrides default ShowWidget message so we show them on the correct |
| 131 // coordinates. |
| 132 void ShowWidget(RenderViewHost* render_view_host, |
| 133 int route_id, |
| 134 const gfx::Rect& initial_pos); |
| 135 void SetFocus(bool focused); |
| 136 void SetCursor(const WebCursor& cursor); |
| 137 // Handles input event acks so they are sent to browser plugin host (via |
| 138 // embedder) instead of default view/widget host. |
| 139 void HandleInputEventAck(RenderViewHost* render_view_host, bool handled); |
| 140 |
| 141 void Destroy(); |
| 142 |
| 143 // Helper to send messages to embedder. Overriden in test implementation since |
| 144 // we want to intercept certain messages for testing. |
| 145 virtual void SendMessageToEmbedder(IPC::Message*); |
| 146 |
| 147 // Static factory instance (always NULL for non-test). |
| 148 static content::BrowserPluginHostFactory* factory_; |
| 149 |
| 150 bool ViewTakeFocus(bool reverse); |
| 151 |
| 152 RenderProcessHost* embedder_render_process_host_; |
| 153 // An identifier that uniquely identifies a browser plugin guest within an |
| 154 // embedder. |
| 155 int instance_id_; |
| 156 scoped_ptr<TransportDIB> damage_buffer_; |
| 157 gfx::Size damage_buffer_size_; |
| 158 float damage_buffer_scale_factor_; |
| 159 scoped_ptr<IPC::Message> pending_input_event_reply_; |
| 160 gfx::Rect guest_rect_; |
| 161 WebCursor cursor_; |
| 162 IDMap<RenderViewHost> pending_updates_; |
| 163 int pending_update_counter_; |
| 164 |
| 165 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); |
| 166 }; |
| 167 |
| 168 } // namespace content |
| 169 |
| 170 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
OLD | NEW |