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

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

Issue 10560022: Browser Plugin: New Implementation (Browser Side) (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Address some of creis@'s comments. Handing off to Istiaque as I head for vacation. Created 8 years, 4 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 | Annotate | Revision Log
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 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_H__
6 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_HOST_H__
7
8 #include <map>
9
10 #include "base/compiler_specific.h"
11 #include "base/id_map.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "content/public/browser/web_contents_delegate.h"
15 #include "content/public/browser/web_contents_observer.h"
16 #include "ppapi/c/pp_instance.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
18 #include "ui/gfx/rect.h"
19 #include "ui/gfx/size.h"
20 #include "ui/surface/transport_dib.h"
21 #include "webkit/glue/webcursor.h"
22
23 class WebContentsImpl;
24 struct BrowserPluginHostMsg_PostMessage_Params;
25 struct ViewHostMsg_UpdateRect_Params;
26
27 namespace IPC {
28 struct ChannelHandle;
29 }
30
31 namespace content {
32
33 class BrowserPluginHost;
34 class RenderProcessHost;
35 class RenderWidgetHostView;
36
37 typedef std::map<WebContents*, int64> GuestMap;
38 typedef std::map<int, BrowserPluginHost*> ContainerInstanceMap;
39
40 // A BrowserPluginHost object is used by both embedders and guests.
41 // The primary purpose of BrowserPluginHost is to allow an embedder
42 // to manage the lifetime of its guests. It cleans up its guests
43 // on navigation, crashes, and "hides" guests when it hides.
44 // For the guest, BrowserPluginHost keeps track of its embedder,
45 // and its BrowserPlugin instance ID.
46 class BrowserPluginHost : public WebContentsObserver,
47 public NotificationObserver,
48 public WebContentsDelegate {
49 public:
50 // BrowserPluginHost is owned by a WebContentsImpl. Here it takes in its
51 // owner. The owner can be either a guest or embedder WebContents.
52 explicit BrowserPluginHost(WebContentsImpl* web_contents);
53
54 virtual ~BrowserPluginHost();
55
56 // This is called on navigation of the browser plugin. On the first
57 // navigation, it creates a new WebContentsImpl for the guest, associates
58 // it with its embedder, and navigates it to the src URL. On subsequent
59 // navigations, it calls up the guest's existign WebContents and navigates
60 // it.
61 void NavigateGuest(RenderViewHost* render_view_host,
62 int instance_id,
63 int64 frame_id,
64 const std::string& src,
65 const gfx::Size& size);
66
67 // This is called when the browser plugin's container has resized in the
68 // embedder. In additon to specifying the new size, and new scale factor,
69 // it also passes a TransportDIB that is shared with the embedder.
70 // The browser process is free to write to this buffer whenever it receives
71 // damage from the guest because if it receives damage from the guest,
72 // then the previous damage has already been accessed and ACK'ed by the
73 // embedder.
74 void ResizeGuest(int instance_id,
75 TransportDIB* damage_buffer,
76 int width,
77 int height,
78 bool resize_pending,
79 float scale_factor);
80
81 void UpdateRect(RenderViewHost* render_view_host,
82 const ViewHostMsg_UpdateRect_Params& params);
83
84 // Called on the guest BrowserPluginHost.
85 void UpdateRectACK(int message_id, const gfx::Size& size);
86 void HandleInputEvent(RenderViewHost* render_view_host,
87 const gfx::Rect& guest_rect,
88 const WebKit::WebInputEvent& event,
89 IPC::Message* reply_message);
90 void HandleInputEventAck(RenderViewHost* render_view_host, bool handled);
91 void SetFocus(bool focused);
92 void ShowWidget(RenderViewHost* render_view_host,
93 int route_id,
94 const gfx::Rect& initial_pos);
95 void SetCursor(const WebCursor& cursor);
96
97 RenderProcessHost* embedder_render_process_host() const {
98 return embedder_render_process_host_;
99 }
100 int instance_id() const { return instance_id_; }
101 void SetDamageBuffer(TransportDIB* damage_buffer,
102 const gfx::Size& size,
103 float scale_factor);
104 TransportDIB* damage_buffer() const { return damage_buffer_; }
105 const gfx::Size& damage_buffer_size() const { return damage_buffer_size_; }
106 float damage_buffer_scale_factor() const {
107 return damage_buffer_scale_factor_;
108 }
109
110 const ContainerInstanceMap& guests_for_testing() const {
111 return guests_by_instance_id_;
112 }
113
114 protected:
115 friend class BrowserPluginHostHelper;
116 friend class BrowserPluginHostTest;
117
118 // Get a guest BrowserPluginHost by its container ID specified
119 // in BrowserPlugin.
120 BrowserPluginHost* GetGuestByInstanceID(int instance_id) const;
121
122 // An embedder BrowserPluginHost keeps track of
123 // its guests so that if it navigates away, its associated RenderView
124 // crashes or it is hidden, it takes appropriate action on the guest.
125 void AddGuest(int instance_id, BrowserPluginHost* guest, int64 frame_id);
126
127 void set_embedder_render_process_host(
128 RenderProcessHost* embedder_render_process_host) {
129 embedder_render_process_host_ = embedder_render_process_host;
130 }
131 void set_instance_id(int instance_id) { instance_id_ = instance_id; }
132
133 void DestroyGuests();
134 // Destroy a specific guest if possible. This is a no-op if the guest id is
135 // unknown as we may already have removed it for a different reason.
136 void DestroyGuestByInstanceID(int instance_id);
137
138 // WebContentsDelegate implementation.
139 virtual bool TakeFocus(bool reverse) OVERRIDE;
140 virtual void RendererUnresponsive(WebContents* source) OVERRIDE;
141
142 // WebContentsObserver implementation.
143 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
144 // Used to monitor frame navigation to cleanup guests when a frame navigates
145 // away from the browser plugin it's hosting.
146 virtual void DidCommitProvisionalLoadForFrame(
147 int64 frame_id,
148 bool is_main_frame,
149 const GURL& url,
150 PageTransition transition_type,
151 RenderViewHost* render_view_host) OVERRIDE;
152 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
153 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
154
155 // NotificationObserver method override.
156 virtual void Observe(int type,
157 const NotificationSource& source,
158 const NotificationDetails& details) OVERRIDE;
159
160 // A scoped container for notification registries.
161 NotificationRegistrar registrar_;
162 RenderProcessHost* embedder_render_process_host_;
163 std::string embedder_channel_name_;
164 // An identifier that uniquely identifies a browser plugin container
165 // within an embedder.
166 int instance_id_;
167 TransportDIB* damage_buffer_;
168 gfx::Size damage_buffer_size_;
169 float damage_buffer_scale_factor_;
170 GuestMap guests_;
171 ContainerInstanceMap guests_by_instance_id_;
172
173 IDMap<RenderViewHost> pending_updates_;
174 int pending_update_counter_;
175 scoped_ptr<IPC::Message> pending_input_event_reply_;
176 gfx::Rect guest_rect_;
177 WebCursor cursor_;
178
179 DISALLOW_COPY_AND_ASSIGN(BrowserPluginHost);
180 };
181
182 } // namespace content
183
184 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_OLD_BROWSER_PLUGIN_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698