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

Side by Side Diff: content/renderer/browser_plugin/browser_plugin_impl.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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ 5 #ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_IMPL_H_
6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ 6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_IMPL_H_
7
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
9 7
10 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h"
12 #include "base/process_util.h" 11 #include "base/process_util.h"
13 #include "base/sequenced_task_runner_helpers.h" 12 #include "base/sequenced_task_runner_helpers.h"
14 #if defined(OS_WIN) 13 #if defined(OS_WIN)
15 #include "base/shared_memory.h" 14 #include "base/shared_memory.h"
16 #endif 15 #endif
17 #include "content/common/browser_plugin_message_enums.h" 16 #include "content/common/browser_plugin_message_enums.h"
17 #include "content/public/renderer/browser_plugin/browser_plugin.h"
18 #include "content/renderer/browser_plugin/browser_plugin_backing_store.h" 18 #include "content/renderer/browser_plugin/browser_plugin_backing_store.h"
19 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" 19 #include "content/renderer/browser_plugin/browser_plugin_bindings.h"
20 #include "content/renderer/render_view_impl.h" 20 #include "content/renderer/render_view_impl.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
22 23
23 struct BrowserPluginHostMsg_AutoSize_Params; 24 struct BrowserPluginHostMsg_AutoSize_Params;
24 struct BrowserPluginHostMsg_ResizeGuest_Params; 25 struct BrowserPluginHostMsg_ResizeGuest_Params;
25 struct BrowserPluginMsg_LoadCommit_Params; 26 struct BrowserPluginMsg_LoadCommit_Params;
26 struct BrowserPluginMsg_UpdateRect_Params; 27 struct BrowserPluginMsg_UpdateRect_Params;
27 28
28 namespace content { 29 namespace content {
29 30
30 class BrowserPluginCompositingHelper; 31 class BrowserPluginCompositingHelper;
31 class BrowserPluginManager; 32 class BrowserPluginManager;
33 class BrowserPluginObserver;
32 class MockBrowserPlugin; 34 class MockBrowserPlugin;
33 35
34 class CONTENT_EXPORT BrowserPlugin : 36 class CONTENT_EXPORT BrowserPluginImpl :
35 NON_EXPORTED_BASE(public WebKit::WebPlugin) { 37 NON_EXPORTED_BASE(public WebKit::WebPlugin),
38 public BrowserPlugin {
36 public: 39 public:
37 RenderViewImpl* render_view() const { return render_view_.get(); } 40 RenderViewImpl* render_view() const { return render_view_.get(); }
38 int render_view_routing_id() const { return render_view_routing_id_; } 41 int render_view_routing_id() const { return render_view_routing_id_; }
39 42
40 bool OnMessageReceived(const IPC::Message& msg); 43 bool OnMessageReceived(const IPC::Message& msg);
41 44
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. 45 // Get the name attribute value.
54 std::string GetNameAttribute() const; 46 std::string GetNameAttribute() const;
55 // Parse the name attribute value. 47 // Parse the name attribute value.
56 void ParseNameAttribute(); 48 void ParseNameAttribute();
57 // Get the src attribute value of the BrowserPlugin instance. 49 // Get the src attribute value of the BrowserPlugin instance.
58 std::string GetSrcAttribute() const; 50 std::string GetSrcAttribute() const;
59 // Parse the src attribute value of the BrowserPlugin instance. 51 // Parse the src attribute value of the BrowserPlugin instance.
60 bool ParseSrcAttribute(std::string* error_message); 52 bool ParseSrcAttribute(std::string* error_message);
61 // Get the autosize attribute value. 53 // Get the autosize attribute value.
62 bool GetAutoSizeAttribute() const; 54 bool GetAutoSizeAttribute() const;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 // Not OK to use this function for making security-sensitive decision since it 124 // Not OK to use this function for making security-sensitive decision since it
133 // can return false positives when the plugin has rotation transformation 125 // can return false positives when the plugin has rotation transformation
134 // applied. 126 // applied.
135 bool InBounds(const gfx::Point& point) const; 127 bool InBounds(const gfx::Point& point) const;
136 128
137 gfx::Point ToLocalCoordinates(const gfx::Point& point) const; 129 gfx::Point ToLocalCoordinates(const gfx::Point& point) const;
138 // Called by browser plugin binding. 130 // Called by browser plugin binding.
139 void OnEmbedderDecidedPermission(int request_id, bool allow); 131 void OnEmbedderDecidedPermission(int request_id, bool allow);
140 132
141 133
134 // BrowserPlugin implementation.
135 virtual RenderView* GetRenderView() const OVERRIDE;
136 virtual WebKit::WebPluginContainer* GetContainer() const OVERRIDE;
137 virtual void AddMethodBinding(
138 BrowserPluginMethodBinding* method_binding) OVERRIDE;
139 virtual void AddPropertyBinding(
140 BrowserPluginPropertyBinding* method_binding) OVERRIDE;
141 virtual void TriggerEvent(
142 const std::string& event_name,
143 std::map<std::string, base::Value*>* props) OVERRIDE;
144 virtual void UpdateDOMAttribute(const std::string& attribute_name,
145 const std::string& attribute_value) OVERRIDE;
146 virtual void RemoveDOMAttribute(const std::string& attribute_name) OVERRIDE;
147 virtual std::string GetDOMAttributeValue(
148 const std::string& attribute_name) const OVERRIDE;
149 virtual bool HasDOMAttribute(
150 const std::string& attribute_name) const OVERRIDE;
151 virtual bool HasNavigated() const OVERRIDE;
152
153 // IPC::Sender implementation.
154 virtual bool Send(IPC::Message* message) OVERRIDE;
155
142 // WebKit::WebPlugin implementation. 156 // WebKit::WebPlugin implementation.
143 virtual WebKit::WebPluginContainer* container() const OVERRIDE; 157 virtual WebKit::WebPluginContainer* container() const OVERRIDE;
144 virtual bool initialize(WebKit::WebPluginContainer* container) OVERRIDE; 158 virtual bool initialize(WebKit::WebPluginContainer* container) OVERRIDE;
145 virtual void destroy() OVERRIDE; 159 virtual void destroy() OVERRIDE;
146 virtual NPObject* scriptableObject() OVERRIDE; 160 virtual NPObject* scriptableObject() OVERRIDE;
147 virtual bool supportsKeyboardFocus() const OVERRIDE; 161 virtual bool supportsKeyboardFocus() const OVERRIDE;
148 virtual bool canProcessDrag() const OVERRIDE; 162 virtual bool canProcessDrag() const OVERRIDE;
149 virtual void paint( 163 virtual void paint(
150 WebKit::WebCanvas* canvas, 164 WebKit::WebCanvas* canvas,
151 const WebKit::WebRect& rect) OVERRIDE; 165 const WebKit::WebRect& rect) OVERRIDE;
(...skipping 19 matching lines...) Expand all
171 virtual void didFinishLoading() OVERRIDE; 185 virtual void didFinishLoading() OVERRIDE;
172 virtual void didFailLoading(const WebKit::WebURLError& error) OVERRIDE; 186 virtual void didFailLoading(const WebKit::WebURLError& error) OVERRIDE;
173 virtual void didFinishLoadingFrameRequest( 187 virtual void didFinishLoadingFrameRequest(
174 const WebKit::WebURL& url, 188 const WebKit::WebURL& url,
175 void* notify_data) OVERRIDE; 189 void* notify_data) OVERRIDE;
176 virtual void didFailLoadingFrameRequest( 190 virtual void didFailLoadingFrameRequest(
177 const WebKit::WebURL& url, 191 const WebKit::WebURL& url,
178 void* notify_data, 192 void* notify_data,
179 const WebKit::WebURLError& error) OVERRIDE; 193 const WebKit::WebURLError& error) OVERRIDE;
180 private: 194 private:
181 friend class base::DeleteHelper<BrowserPlugin>; 195 friend class base::DeleteHelper<BrowserPluginImpl>;
182 // Only the manager is allowed to create a BrowserPlugin. 196 // Only the manager is allowed to create a BrowserPlugin.
183 friend class BrowserPluginManagerImpl; 197 friend class BrowserPluginManagerImpl;
198 friend class BrowserPluginObserver;
184 friend class MockBrowserPluginManager; 199 friend class MockBrowserPluginManager;
185 200
186 // For unit/integration tests. 201 // For unit/integration tests.
187 friend class MockBrowserPlugin; 202 friend class MockBrowserPlugin;
188 203
189 // A BrowserPlugin object is a controller that represents an instance of a 204 // A BrowserPluginImpl object is a controller that represents an instance of a
190 // browser plugin within the embedder renderer process. Each BrowserPlugin 205 // browser plugin within the embedder renderer process. Each BrowserPlugin
191 // within a process has a unique instance_id that is used to route messages 206 // 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 207 // 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 208 // with the frame within which it lives and the initial attributes assigned
194 // to it on creation. 209 // to it on creation.
195 BrowserPlugin( 210 BrowserPluginImpl(
196 RenderViewImpl* render_view, 211 RenderViewImpl* render_view,
197 WebKit::WebFrame* frame, 212 WebKit::WebFrame* frame,
198 const WebKit::WebPluginParams& params); 213 const WebKit::WebPluginParams& params);
199 214
200 virtual ~BrowserPlugin(); 215 virtual ~BrowserPluginImpl();
216
217 // Add and remove observers for filtering IPC messages. Clients must be sure
218 // to remove the observer before they go away.
219 void AddObserver(BrowserPluginObserver* observer);
220 void RemoveObserver(BrowserPluginObserver* observer);
201 221
202 int width() const { return plugin_rect_.width(); } 222 int width() const { return plugin_rect_.width(); }
203 int height() const { return plugin_rect_.height(); } 223 int height() const { return plugin_rect_.height(); }
204 int instance_id() const { return instance_id_; } 224 int instance_id() const { return instance_id_; }
205 // Gets the Max Height value used for auto size. 225 // Gets the Max Height value used for auto size.
206 int GetAdjustedMaxHeight() const; 226 int GetAdjustedMaxHeight() const;
207 // Gets the Max Width value used for auto size. 227 // Gets the Max Width value used for auto size.
208 int GetAdjustedMaxWidth() const; 228 int GetAdjustedMaxWidth() const;
209 // Gets the Min Height value used for auto size. 229 // Gets the Min Height value used for auto size.
210 int GetAdjustedMinHeight() const; 230 int GetAdjustedMinHeight() const;
211 // Gets the Min Width value used for auto size. 231 // Gets the Min Width value used for auto size.
212 int GetAdjustedMinWidth() const; 232 int GetAdjustedMinWidth() const;
213 BrowserPluginManager* browser_plugin_manager() const { 233 BrowserPluginManager* browser_plugin_manager() const {
214 return browser_plugin_manager_; 234 return browser_plugin_manager_;
215 } 235 }
216 236
217 // Virtual to allow for mocking in tests. 237 // Virtual to allow for mocking in tests.
218 virtual float GetDeviceScaleFactor() const; 238 virtual float GetDeviceScaleFactor() const;
219 239
220 // Parses the attributes of the browser plugin from the element's attributes 240 // Parses the attributes of the browser plugin from the element's attributes
221 // and sets them appropriately. 241 // and sets them appropriately.
222 void ParseAttributes(); 242 void ParseAttributes();
223 243
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. 244 // Creates and maps a shared damage buffer.
230 virtual base::SharedMemory* CreateDamageBuffer( 245 virtual base::SharedMemory* CreateDamageBuffer(
231 const size_t size, 246 const size_t size,
232 base::SharedMemoryHandle* shared_memory_handle); 247 base::SharedMemoryHandle* shared_memory_handle);
233 // Swaps out the |current_damage_buffer_| with the |pending_damage_buffer_|. 248 // Swaps out the |current_damage_buffer_| with the |pending_damage_buffer_|.
234 void SwapDamageBuffers(); 249 void SwapDamageBuffers();
235 250
236 // Populates BrowserPluginHostMsg_ResizeGuest_Params with resize state and 251 // Populates BrowserPluginHostMsg_ResizeGuest_Params with resize state and
237 // allocates a new |pending_damage_buffer_| if in software rendering mode. 252 // allocates a new |pending_damage_buffer_| if in software rendering mode.
238 void PopulateResizeGuestParameters( 253 void PopulateResizeGuestParameters(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 void* param); 307 void* param);
293 308
294 // IPC message handlers. 309 // IPC message handlers.
295 // Please keep in alphabetical order. 310 // Please keep in alphabetical order.
296 void OnAdvanceFocus(int instance_id, bool reverse); 311 void OnAdvanceFocus(int instance_id, bool reverse);
297 void OnBuffersSwapped(int instance_id, 312 void OnBuffersSwapped(int instance_id,
298 const gfx::Size& size, 313 const gfx::Size& size,
299 std::string mailbox_name, 314 std::string mailbox_name,
300 int gpu_route_id, 315 int gpu_route_id,
301 int gpu_host_id); 316 int gpu_host_id);
317 void OnForwardMessage(int instance_id, const IPC::Message& msg);
302 void OnGuestContentWindowReady(int instance_id, 318 void OnGuestContentWindowReady(int instance_id,
303 int content_window_routing_id); 319 int content_window_routing_id);
304 void OnGuestGone(int instance_id, int process_id, int status); 320 void OnGuestGone(int instance_id, int process_id, int status);
305 void OnGuestResponsive(int instance_id, int process_id); 321 void OnGuestResponsive(int instance_id, int process_id);
306 void OnGuestUnresponsive(int instance_id, int process_id); 322 void OnGuestUnresponsive(int instance_id, int process_id);
307 void OnLoadAbort(int instance_id, 323 void OnLoadAbort(int instance_id,
308 const GURL& url, 324 const GURL& url,
309 bool is_top_level, 325 bool is_top_level,
310 const std::string& type); 326 const std::string& type);
311 void OnLoadCommit(int instance_id, 327 void OnLoadCommit(int instance_id,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 gfx::Size last_view_size_; 380 gfx::Size last_view_size_;
365 bool size_changed_in_flight_; 381 bool size_changed_in_flight_;
366 bool allocate_instance_id_sent_; 382 bool allocate_instance_id_sent_;
367 383
368 // Each permission request item in the map is a pair of request id and 384 // Each permission request item in the map is a pair of request id and
369 // permission type. 385 // permission type.
370 typedef std::map<int, std::pair<int, BrowserPluginPermissionType> > 386 typedef std::map<int, std::pair<int, BrowserPluginPermissionType> >
371 PendingPermissionRequests; 387 PendingPermissionRequests;
372 PendingPermissionRequests pending_permission_requests_; 388 PendingPermissionRequests pending_permission_requests_;
373 389
374 typedef std::pair<int, base::WeakPtr<BrowserPlugin> > 390 typedef std::pair<int, base::WeakPtr<BrowserPluginImpl> >
375 AliveV8PermissionRequestItem; 391 AliveV8PermissionRequestItem;
376 std::map<int, AliveV8PermissionRequestItem*> 392 std::map<int, AliveV8PermissionRequestItem*>
377 alive_v8_permission_request_objects_; 393 alive_v8_permission_request_objects_;
378 394
379 // BrowserPlugin outlives RenderViewImpl in Chrome Apps and so we need to 395 // BrowserPlugin outlives RenderViewImpl in Chrome Apps and so we need to
380 // store the BrowserPlugin's BrowserPluginManager in a member variable to 396 // store the BrowserPlugin's BrowserPluginManager in a member variable to
381 // avoid accessing the RenderViewImpl. 397 // avoid accessing the RenderViewImpl.
382 scoped_refptr<BrowserPluginManager> browser_plugin_manager_; 398 scoped_refptr<BrowserPluginManager> browser_plugin_manager_;
383 399
400 // A list of observers that filter messages. Weak references.
401 ObserverList<BrowserPluginObserver> observers_;
402
384 // Important: Do not add more history state here. 403 // Important: Do not add more history state here.
385 // We strongly discourage storing additional history state (such as page IDs) 404 // We strongly discourage storing additional history state (such as page IDs)
386 // in the embedder process, at the risk of having incorrect information that 405 // in the embedder process, at the risk of having incorrect information that
387 // can lead to broken back/forward logic in apps. 406 // 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 407 // 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 408 // 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 409 // 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 410 // 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 411 // the changes are not always obvious. For example, there is a maximum
393 // number of entries and earlier ones will automatically be pruned. 412 // number of entries and earlier ones will automatically be pruned.
394 int current_nav_entry_index_; 413 int current_nav_entry_index_;
395 int nav_entry_count_; 414 int nav_entry_count_;
396 415
397 // Used for HW compositing. 416 // Used for HW compositing.
398 bool compositing_enabled_; 417 bool compositing_enabled_;
399 scoped_refptr<BrowserPluginCompositingHelper> compositing_helper_; 418 scoped_refptr<BrowserPluginCompositingHelper> compositing_helper_;
400 419
401 // Weak factory used in v8 |MakeWeak| callback, since the v8 callback might 420 // Weak factory used in v8 |MakeWeak| callback, since the v8 callback might
402 // get called after BrowserPlugin has been destroyed. 421 // get called after BrowserPlugin has been destroyed.
403 base::WeakPtrFactory<BrowserPlugin> weak_ptr_factory_; 422 base::WeakPtrFactory<BrowserPluginImpl> weak_ptr_factory_;
404 423
405 DISALLOW_COPY_AND_ASSIGN(BrowserPlugin); 424 DISALLOW_COPY_AND_ASSIGN(BrowserPluginImpl);
406 }; 425 };
407 426
408 } // namespace content 427 } // namespace content
409 428
410 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ 429 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_IMPL_H_
OLDNEW
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin_browsertest.cc ('k') | content/renderer/browser_plugin/browser_plugin_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698