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