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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.h

Issue 10868012: Browser Plugin: New Implementation (Browser Side) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master-trial-obrowser
Patch Set: Rework tests to use timeouts instead of waiting indefinitely, not store any Guest* in embedder. 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 // 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 (ViewHostMsg_*) directed at the browser
13 // plugin and redirects them to this class. Any messages the embedder might be
14 // interested in knowing or modifying about the guest should be listened for
15 // here.
16 //
17 // Since BrowserPlugin is a WebPlugin, we need to provide overriden behaviors
18 // for messages like handleInputEvent, updateGeometry. Such messages gets
19 // routed into BrowserPluginGuest via its embedder (BrowserPluginEmbedder).
20 // These are BrowserPluginHost_* messages sent from the BrowserPlugin.
21 //
22 // BrowserPluginGuest knows about its embedder process, communication to
23 // renderer happens through the embedder process.
24 //
25 // A BrowserPluginGuest is also associated directly with the WebContents related
26 // to the BrowserPlugin. BrowserPluginGuest is a WebContentsDelegate and
27 // WebContentsObserver for the WebContents.
28
29 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_
30 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_
31
32 #include <string>
33 #include <map>
34
35 #include "base/compiler_specific.h"
36 #include "base/id_map.h"
37 #include "content/browser/browser_plugin/browser_plugin_host_factory.h"
38 #include "content/public/browser/render_view_host_observer.h"
39 #include "content/public/browser/web_contents_delegate.h"
40 #include "content/public/browser/web_contents_observer.h"
41 #include "ipc/ipc_channel_handle.h"
42 #include "ipc/ipc_sync_message.h"
43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
44 #include "ui/surface/transport_dib.h"
45 #include "ui/gfx/rect.h"
46 #include "ui/gfx/size.h"
47 #include "webkit/glue/webcursor.h"
48
49 namespace gfx {
50 class Size;
51 }
52
53 struct BrowserPluginHostMsg_ResizeGuest_Params;
54 struct ViewHostMsg_UpdateRect_Params;
55
56 namespace content {
57
58 class BrowserPluginHostFactory;
59 class BrowserPluginEmbedder;
60 class RenderProcessHost;
61
62 // A browser plugin guest provides functionality for WebContents to operate in
63 // the guest role and implements guest specific overrides for ViewHostMsg_*
64 // messages.
65 //
66 // BrowserPluginEmbedder is responsible for creating and destroying a guest.
67 class CONTENT_EXPORT BrowserPluginGuest : public WebContentsDelegate,
68 public WebContentsObserver {
69 public:
70 virtual ~BrowserPluginGuest();
71
72 static BrowserPluginGuest* Create(int instance_id,
73 WebContentsImpl* web_contents,
74 content::RenderViewHost* render_view_host);
75
76 // Overrides factory for testing. Default (NULL) value indicates regular
77 // (non-test) environment.
78 static void set_factory_for_testing(BrowserPluginHostFactory* factory) {
79 content::BrowserPluginGuest::factory_ = factory;
80 }
81
82 // WebContentsObserver implementation.
83 virtual void DidCommitProvisionalLoadForFrame(
84 int64 frame_id,
85 bool is_main_frame,
86 const GURL& url,
87 PageTransition transition_type,
88 RenderViewHost* render_view_host) OVERRIDE;
89 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
90
91 // WebContentsDelegate implementation.
92 virtual void RendererUnresponsive(WebContents* source) OVERRIDE;
93
94 private:
95 friend class BrowserPluginEmbedder;
96 friend class BrowserPluginGuestHelper;
97 friend class TestBrowserPluginGuest;
98
99 BrowserPluginGuest(int instance_id,
100 WebContentsImpl* web_contents,
101 RenderViewHost* render_view_host);
102
103 void set_embedder_render_process_host(
104 RenderProcessHost* render_process_host) {
105 embedder_render_process_host_ = render_process_host;
106 }
107 RenderProcessHost* embedder_render_process_host() {
108 return embedder_render_process_host_;
109 }
110 // Returns the identifier that uniquely identifies a browser plugin guest
111 // within an embedder.
112 int instance_id() const { return instance_id_; }
113
114 void SetDamageBuffer(TransportDIB* damage_buffer,
115 const gfx::Size& size,
116 float scale_factor);
117 TransportDIB* damage_buffer() const { return damage_buffer_.get(); }
118 const gfx::Size& damage_buffer_size() const { return damage_buffer_size_; }
119 float damage_buffer_scale_factor() const {
120 return damage_buffer_scale_factor_;
121 }
122
123 void UpdateRect(RenderViewHost* render_view_host,
124 const ViewHostMsg_UpdateRect_Params& params);
125 void UpdateRectACK(int message_id, const gfx::Size& size);
126 // Handles input event routed through the embedder (which is initiated in the
127 // browser plugin (renderer side of the embedder)).
128 void HandleInputEvent(RenderViewHost* render_view_host,
129 const gfx::Rect& guest_rect,
130 const WebKit::WebInputEvent& event,
131 IPC::Message* reply_message);
132 // Overrides default ShowWidget message so we show them on the correct
133 // coordinates.
134 void ShowWidget(RenderViewHost* render_view_host,
135 int route_id,
136 const gfx::Rect& initial_pos);
137 void SetFocus(bool focused);
138 void SetCursor(const WebCursor& cursor);
139 // Handles input event acks so they are sent to browser plugin host (via
140 // embedder) instead of default view/widget host.
141 void HandleInputEventAck(RenderViewHost* render_view_host, bool handled);
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 int guest_hang_timeout_ms_;
165
166 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest);
167 };
168
169 } // namespace content
170
171 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698