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

Side by Side Diff: content/renderer/browser_plugin/browser_plugin.h

Issue 11826005: Browser Plugin: Implement BrowserPluginObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT Created 7 years, 9 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_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_
6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_
7
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
9
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/process_util.h"
13 #include "base/sequenced_task_runner_helpers.h"
14 #if defined(OS_WIN)
15 #include "base/shared_memory.h"
16 #endif
17 #include "content/common/browser_plugin_message_enums.h"
18 #include "content/renderer/browser_plugin/browser_plugin_backing_store.h"
19 #include "content/renderer/browser_plugin/browser_plugin_bindings.h"
20 #include "content/renderer/render_view_impl.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h"
22
23 struct BrowserPluginHostMsg_AutoSize_Params;
24 struct BrowserPluginHostMsg_ResizeGuest_Params;
25 struct BrowserPluginMsg_LoadCommit_Params;
26 struct BrowserPluginMsg_UpdateRect_Params;
27
28 namespace content {
29
30 class BrowserPluginCompositingHelper;
31 class BrowserPluginManager;
32 class MockBrowserPlugin;
33
34 class CONTENT_EXPORT BrowserPlugin :
35 NON_EXPORTED_BASE(public WebKit::WebPlugin) {
36 public:
37 RenderViewImpl* render_view() const { return render_view_.get(); }
38 int render_view_routing_id() const { return render_view_routing_id_; }
39
40 bool OnMessageReceived(const IPC::Message& msg);
41
42 // Update Browser Plugin's DOM Node attribute |attribute_name| with the value
43 // |attribute_value|.
44 void UpdateDOMAttribute(const std::string& attribute_name,
45 const std::string& attribute_value);
46 // Remove the DOM Node attribute with the name |attribute_name|.
47 void RemoveDOMAttribute(const std::string& attribute_name);
48 // Get Browser Plugin's DOM Node attribute |attribute_name|'s value.
49 std::string GetDOMAttributeValue(const std::string& attribute_name) const;
50 // Checks if the attribute |attribute_name| exists in the DOM.
51 bool HasDOMAttribute(const std::string& attribute_name) const;
52
53 // Get the name attribute value.
54 std::string GetNameAttribute() const;
55 // Parse the name attribute value.
56 void ParseNameAttribute();
57 // Get the src attribute value of the BrowserPlugin instance.
58 std::string GetSrcAttribute() const;
59 // Parse the src attribute value of the BrowserPlugin instance.
60 bool ParseSrcAttribute(std::string* error_message);
61 // Get the autosize attribute value.
62 bool GetAutoSizeAttribute() const;
63 // Parses the autosize attribute value.
64 void ParseAutoSizeAttribute();
65 // Get the maxheight attribute value.
66 int GetMaxHeightAttribute() const;
67 // Get the maxwidth attribute value.
68 int GetMaxWidthAttribute() const;
69 // Get the minheight attribute value.
70 int GetMinHeightAttribute() const;
71 // Get the minwidth attribute value.
72 int GetMinWidthAttribute() const;
73 // Parse the minwidth, maxwidth, minheight, and maxheight attribute values.
74 void ParseSizeContraintsChanged();
75 // The partition identifier string is stored as UTF-8.
76 std::string GetPartitionAttribute() const;
77 // This method can be successfully called only before the first navigation for
78 // this instance of BrowserPlugin. If an error occurs, the |error_message| is
79 // set appropriately to indicate the failure reason.
80 bool ParsePartitionAttribute(std::string* error_message);
81 // True if the partition attribute can be removed.
82 bool CanRemovePartitionAttribute(std::string* error_message);
83
84 bool InAutoSizeBounds(const gfx::Size& size) const;
85
86 // Get the guest's DOMWindow proxy.
87 NPObject* GetContentWindow() const;
88
89 // Returns Chrome's process ID for the current guest.
90 int guest_process_id() const { return guest_process_id_; }
91 // Returns Chrome's route ID for the current guest.
92 int guest_route_id() const { return guest_route_id_; }
93 // Returns whether the guest process has crashed.
94 bool guest_crashed() const { return guest_crashed_; }
95
96 // Query whether the guest can navigate back to the previous entry.
97 bool CanGoBack() const;
98 // Query whether the guest can navigation forward to the next entry.
99 bool CanGoForward() const;
100
101 // Informs the guest of an updated focus state.
102 void UpdateGuestFocusState();
103 // Indicates whether the guest should be focused.
104 bool ShouldGuestBeFocused() const;
105
106 // Tells the BrowserPlugin to tell the guest to navigate to the previous
107 // navigation entry in the navigation history.
108 void Back();
109 // Tells the BrowserPlugin to tell the guest to navigate to the next
110 // navigation entry in the navigation history.
111 void Forward();
112 // Tells the BrowserPlugin to tell the guest to navigate to a position
113 // relative to the current index in its navigation history.
114 void Go(int relativeIndex);
115 // Tells the BrowserPlugin to terminate the guest process.
116 void TerminateGuest();
117
118 // A request from JavaScript has been made to stop the loading of the page.
119 void Stop();
120 // A request from JavaScript has been made to reload the page.
121 void Reload();
122 // A request to enable hardware compositing.
123 void EnableCompositing(bool enable);
124 // A request from content client to track lifetime of a JavaScript object
125 // related to a permission request object.
126 // This is used to clean up hanging permission request objects.
127 void PersistRequestObject(const NPVariant* request,
128 const std::string& type,
129 int id);
130
131 // Returns true if |point| lies within the bounds of the plugin rectangle.
132 // Not OK to use this function for making security-sensitive decision since it
133 // can return false positives when the plugin has rotation transformation
134 // applied.
135 bool InBounds(const gfx::Point& point) const;
136
137 gfx::Point ToLocalCoordinates(const gfx::Point& point) const;
138 // Called by browser plugin binding.
139 void OnEmbedderDecidedPermission(int request_id, bool allow);
140
141
142 // WebKit::WebPlugin implementation.
143 virtual WebKit::WebPluginContainer* container() const OVERRIDE;
144 virtual bool initialize(WebKit::WebPluginContainer* container) OVERRIDE;
145 virtual void destroy() OVERRIDE;
146 virtual NPObject* scriptableObject() OVERRIDE;
147 virtual bool supportsKeyboardFocus() const OVERRIDE;
148 virtual bool canProcessDrag() const OVERRIDE;
149 virtual void paint(
150 WebKit::WebCanvas* canvas,
151 const WebKit::WebRect& rect) OVERRIDE;
152 virtual void updateGeometry(
153 const WebKit::WebRect& frame_rect,
154 const WebKit::WebRect& clip_rect,
155 const WebKit::WebVector<WebKit::WebRect>& cut_outs_rects,
156 bool is_visible) OVERRIDE;
157 virtual void updateFocus(bool focused) OVERRIDE;
158 virtual void updateVisibility(bool visible) OVERRIDE;
159 virtual bool acceptsInputEvents() OVERRIDE;
160 virtual bool handleInputEvent(
161 const WebKit::WebInputEvent& event,
162 WebKit::WebCursorInfo& cursor_info) OVERRIDE;
163 virtual bool handleDragStatusUpdate(WebKit::WebDragStatus drag_status,
164 const WebKit::WebDragData& drag_data,
165 WebKit::WebDragOperationsMask mask,
166 const WebKit::WebPoint& position,
167 const WebKit::WebPoint& screen) OVERRIDE;
168 virtual void didReceiveResponse(
169 const WebKit::WebURLResponse& response) OVERRIDE;
170 virtual void didReceiveData(const char* data, int data_length) OVERRIDE;
171 virtual void didFinishLoading() OVERRIDE;
172 virtual void didFailLoading(const WebKit::WebURLError& error) OVERRIDE;
173 virtual void didFinishLoadingFrameRequest(
174 const WebKit::WebURL& url,
175 void* notify_data) OVERRIDE;
176 virtual void didFailLoadingFrameRequest(
177 const WebKit::WebURL& url,
178 void* notify_data,
179 const WebKit::WebURLError& error) OVERRIDE;
180 private:
181 friend class base::DeleteHelper<BrowserPlugin>;
182 // Only the manager is allowed to create a BrowserPlugin.
183 friend class BrowserPluginManagerImpl;
184 friend class MockBrowserPluginManager;
185
186 // For unit/integration tests.
187 friend class MockBrowserPlugin;
188
189 // A BrowserPlugin object is a controller that represents an instance of a
190 // browser plugin within the embedder renderer process. Each BrowserPlugin
191 // within a process has a unique instance_id that is used to route messages
192 // to it. It takes in a RenderViewImpl that it's associated with along
193 // with the frame within which it lives and the initial attributes assigned
194 // to it on creation.
195 BrowserPlugin(
196 RenderViewImpl* render_view,
197 WebKit::WebFrame* frame,
198 const WebKit::WebPluginParams& params);
199
200 virtual ~BrowserPlugin();
201
202 int width() const { return plugin_rect_.width(); }
203 int height() const { return plugin_rect_.height(); }
204 int instance_id() const { return instance_id_; }
205 // Gets the Max Height value used for auto size.
206 int GetAdjustedMaxHeight() const;
207 // Gets the Max Width value used for auto size.
208 int GetAdjustedMaxWidth() const;
209 // Gets the Min Height value used for auto size.
210 int GetAdjustedMinHeight() const;
211 // Gets the Min Width value used for auto size.
212 int GetAdjustedMinWidth() const;
213 BrowserPluginManager* browser_plugin_manager() const {
214 return browser_plugin_manager_;
215 }
216
217 // Virtual to allow for mocking in tests.
218 virtual float GetDeviceScaleFactor() const;
219
220 // Parses the attributes of the browser plugin from the element's attributes
221 // and sets them appropriately.
222 void ParseAttributes();
223
224 // Triggers the event-listeners for |event_name|. Note that the function
225 // frees all the values in |props|.
226 void TriggerEvent(const std::string& event_name,
227 std::map<std::string, base::Value*>* props);
228
229 // Creates and maps a shared damage buffer.
230 virtual base::SharedMemory* CreateDamageBuffer(
231 const size_t size,
232 base::SharedMemoryHandle* shared_memory_handle);
233 // Swaps out the |current_damage_buffer_| with the |pending_damage_buffer_|.
234 void SwapDamageBuffers();
235
236 // Populates BrowserPluginHostMsg_ResizeGuest_Params with resize state and
237 // allocates a new |pending_damage_buffer_| if in software rendering mode.
238 void PopulateResizeGuestParameters(
239 BrowserPluginHostMsg_ResizeGuest_Params* params,
240 const gfx::Size& view_size);
241
242 // Populates BrowserPluginHostMsg_AutoSize_Params object with autosize state.
243 void PopulateAutoSizeParameters(
244 BrowserPluginHostMsg_AutoSize_Params* params, bool current_auto_size);
245
246 // Populates both AutoSize and ResizeGuest parameters based on the current
247 // autosize state.
248 void GetDamageBufferWithSizeParams(
249 BrowserPluginHostMsg_AutoSize_Params* auto_size_params,
250 BrowserPluginHostMsg_ResizeGuest_Params* resize_guest_params);
251
252 // Informs the guest of an updated autosize state.
253 void UpdateGuestAutoSizeState(bool current_auto_size);
254
255 // Informs the BrowserPlugin that guest has changed its size in autosize mode.
256 void SizeChangedDueToAutoSize(const gfx::Size& old_view_size);
257
258 bool HasEventListeners(const std::string& event_name);
259
260 // Indicates whether a damage buffer was used by the guest process for the
261 // provided |params|.
262 static bool UsesDamageBuffer(
263 const BrowserPluginMsg_UpdateRect_Params& params);
264
265 // Indicates whether the |pending_damage_buffer_| was used to copy over pixels
266 // given the provided |params|.
267 bool UsesPendingDamageBuffer(
268 const BrowserPluginMsg_UpdateRect_Params& params);
269
270 // Sets the instance ID of the BrowserPlugin and requests a guest from the
271 // browser process.
272 void SetInstanceID(int instance_id);
273
274 // Requests media access permission from the embedder.
275 void RequestMediaPermission(int request_id,
276 const base::DictionaryValue& request_info);
277 // Informs the BrowserPlugin that the guest's permission request has been
278 // allowed or denied by the embedder.
279 void RespondPermission(BrowserPluginPermissionType permission_type,
280 int request_id,
281 bool allow);
282
283 // If the request with id |request_id| is pending then informs the
284 // BrowserPlugin that the guest's permission request has been allowed or
285 // denied by the embedder.
286 void RespondPermissionIfRequestIsPending(int request_id, bool allow);
287 // Cleans up pending permission request once the associated event.request
288 // object goes out of scope in JavaScript.
289 void OnRequestObjectGarbageCollected(int request_id);
290 // V8 garbage collection callback for |object|.
291 static void WeakCallbackForPersistObject(v8::Persistent<v8::Value> object,
292 void* param);
293
294 // IPC message handlers.
295 // Please keep in alphabetical order.
296 void OnAdvanceFocus(int instance_id, bool reverse);
297 void OnBuffersSwapped(int instance_id,
298 const gfx::Size& size,
299 std::string mailbox_name,
300 int gpu_route_id,
301 int gpu_host_id);
302 void OnGuestContentWindowReady(int instance_id,
303 int content_window_routing_id);
304 void OnGuestGone(int instance_id, int process_id, int status);
305 void OnGuestResponsive(int instance_id, int process_id);
306 void OnGuestUnresponsive(int instance_id, int process_id);
307 void OnLoadAbort(int instance_id,
308 const GURL& url,
309 bool is_top_level,
310 const std::string& type);
311 void OnLoadCommit(int instance_id,
312 const BrowserPluginMsg_LoadCommit_Params& params);
313 void OnLoadRedirect(int instance_id,
314 const GURL& old_url,
315 const GURL& new_url,
316 bool is_top_level);
317 void OnLoadStart(int instance_id, const GURL& url, bool is_top_level);
318 void OnLoadStop(int instance_id);
319 // Requests permission from the embedder.
320 void OnRequestPermission(int instance_id,
321 BrowserPluginPermissionType permission_type,
322 int request_id,
323 const base::DictionaryValue& request_info);
324 void OnSetCursor(int instance_id, const WebCursor& cursor);
325 void OnShouldAcceptTouchEvents(int instance_id, bool accept);
326 void OnUpdatedName(int instance_id, const std::string& name);
327 void OnUpdateRect(int instance_id,
328 const BrowserPluginMsg_UpdateRect_Params& params);
329
330 int instance_id_;
331 base::WeakPtr<RenderViewImpl> render_view_;
332 // We cache the |render_view_|'s routing ID because we need it on destruction.
333 // If the |render_view_| is destroyed before the BrowserPlugin is destroyed
334 // then we will attempt to access a NULL pointer.
335 int render_view_routing_id_;
336 WebKit::WebPluginContainer* container_;
337 scoped_ptr<BrowserPluginBindings> bindings_;
338 scoped_ptr<BrowserPluginBackingStore> backing_store_;
339 scoped_ptr<base::SharedMemory> current_damage_buffer_;
340 scoped_ptr<base::SharedMemory> pending_damage_buffer_;
341 uint32 damage_buffer_sequence_id_;
342 bool resize_ack_received_;
343 gfx::Rect plugin_rect_;
344 // Bitmap for crashed plugin. Lazily initialized, non-owning pointer.
345 SkBitmap* sad_guest_;
346 bool guest_crashed_;
347 scoped_ptr<BrowserPluginHostMsg_ResizeGuest_Params> pending_resize_params_;
348 // True if we have ever sent a NavigateGuest message to the embedder.
349 bool navigate_src_sent_;
350 bool auto_size_ack_pending_;
351 int guest_process_id_;
352 int guest_route_id_;
353 std::string storage_partition_id_;
354 bool persist_storage_;
355 bool valid_partition_id_;
356 int content_window_routing_id_;
357 bool plugin_focused_;
358 // Tracks the visibility of the browser plugin regardless of the whole
359 // embedder RenderView's visibility.
360 bool visible_;
361
362 WebCursor cursor_;
363
364 gfx::Size last_view_size_;
365 bool size_changed_in_flight_;
366 bool allocate_instance_id_sent_;
367
368 // Each permission request item in the map is a pair of request id and
369 // permission type.
370 typedef std::map<int, std::pair<int, BrowserPluginPermissionType> >
371 PendingPermissionRequests;
372 PendingPermissionRequests pending_permission_requests_;
373
374 typedef std::pair<int, base::WeakPtr<BrowserPlugin> >
375 AliveV8PermissionRequestItem;
376 std::map<int, AliveV8PermissionRequestItem*>
377 alive_v8_permission_request_objects_;
378
379 // BrowserPlugin outlives RenderViewImpl in Chrome Apps and so we need to
380 // store the BrowserPlugin's BrowserPluginManager in a member variable to
381 // avoid accessing the RenderViewImpl.
382 scoped_refptr<BrowserPluginManager> browser_plugin_manager_;
383
384 // Important: Do not add more history state here.
385 // We strongly discourage storing additional history state (such as page IDs)
386 // in the embedder process, at the risk of having incorrect information that
387 // can lead to broken back/forward logic in apps.
388 // It's also important that this state does not get modified by any logic in
389 // the embedder process. It should only be updated in response to navigation
390 // events in the guest. No assumptions should be made about how the index
391 // will change after a navigation (e.g., for back, forward, or go), because
392 // the changes are not always obvious. For example, there is a maximum
393 // number of entries and earlier ones will automatically be pruned.
394 int current_nav_entry_index_;
395 int nav_entry_count_;
396
397 // Used for HW compositing.
398 bool compositing_enabled_;
399 scoped_refptr<BrowserPluginCompositingHelper> compositing_helper_;
400
401 // Weak factory used in v8 |MakeWeak| callback, since the v8 callback might
402 // get called after BrowserPlugin has been destroyed.
403 base::WeakPtrFactory<BrowserPlugin> weak_ptr_factory_;
404
405 DISALLOW_COPY_AND_ASSIGN(BrowserPlugin);
406 };
407
408 } // namespace content
409
410 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_
OLDNEW
« no previous file with comments | « content/public/renderer/content_renderer_client.h ('k') | content/renderer/browser_plugin/browser_plugin.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698