OLD | NEW |
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 |
| 16 #include "content/public/renderer/browser_plugin/browser_plugin.h" |
17 #include "content/renderer/browser_plugin/browser_plugin_backing_store.h" | 17 #include "content/renderer/browser_plugin/browser_plugin_backing_store.h" |
18 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | 18 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
19 #include "content/renderer/render_view_impl.h" | 19 #include "content/renderer/render_view_impl.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" |
21 | 22 |
22 struct BrowserPluginHostMsg_AutoSize_Params; | 23 struct BrowserPluginHostMsg_AutoSize_Params; |
23 struct BrowserPluginHostMsg_ResizeGuest_Params; | 24 struct BrowserPluginHostMsg_ResizeGuest_Params; |
24 struct BrowserPluginMsg_LoadCommit_Params; | 25 struct BrowserPluginMsg_LoadCommit_Params; |
25 struct BrowserPluginMsg_UpdateRect_Params; | 26 struct BrowserPluginMsg_UpdateRect_Params; |
26 | 27 |
27 namespace content { | 28 namespace content { |
28 | 29 |
29 class BrowserPluginCompositingHelper; | 30 class BrowserPluginCompositingHelper; |
30 class BrowserPluginManager; | 31 class BrowserPluginManager; |
| 32 class BrowserPluginObserver; |
31 class MockBrowserPlugin; | 33 class MockBrowserPlugin; |
32 | 34 |
33 class CONTENT_EXPORT BrowserPlugin : | 35 class CONTENT_EXPORT BrowserPluginImpl : |
34 NON_EXPORTED_BASE(public WebKit::WebPlugin) { | 36 NON_EXPORTED_BASE(public WebKit::WebPlugin), |
| 37 public BrowserPlugin { |
35 public: | 38 public: |
36 RenderViewImpl* render_view() const { return render_view_.get(); } | 39 RenderViewImpl* render_view() const { return render_view_.get(); } |
37 int render_view_routing_id() const { return render_view_routing_id_; } | 40 int render_view_routing_id() const { return render_view_routing_id_; } |
38 | 41 |
39 bool OnMessageReceived(const IPC::Message& msg); | 42 bool OnMessageReceived(const IPC::Message& msg); |
40 | 43 |
41 // Update Browser Plugin's DOM Node attribute |attribute_name| with the value | |
42 // |attribute_value|. | |
43 void UpdateDOMAttribute(const std::string& attribute_name, | |
44 const std::string& attribute_value); | |
45 // Remove the DOM Node attribute with the name |attribute_name|. | |
46 void RemoveDOMAttribute(const std::string& attribute_name); | |
47 // Get Browser Plugin's DOM Node attribute |attribute_name|'s value. | |
48 std::string GetDOMAttributeValue(const std::string& attribute_name) const; | |
49 // Checks if the attribute |attribute_name| exists in the DOM. | |
50 bool HasDOMAttribute(const std::string& attribute_name) const; | |
51 | |
52 // Get the name attribute value. | 44 // Get the name attribute value. |
53 std::string GetNameAttribute() const; | 45 std::string GetNameAttribute() const; |
54 // Parse the name attribute value. | 46 // Parse the name attribute value. |
55 void ParseNameAttribute(); | 47 void ParseNameAttribute(); |
56 // Get the src attribute value of the BrowserPlugin instance. | 48 // Get the src attribute value of the BrowserPlugin instance. |
57 std::string GetSrcAttribute() const; | 49 std::string GetSrcAttribute() const; |
58 // Parse the src attribute value of the BrowserPlugin instance. | 50 // Parse the src attribute value of the BrowserPlugin instance. |
59 bool ParseSrcAttribute(std::string* error_message); | 51 bool ParseSrcAttribute(std::string* error_message); |
60 // Get the autosize attribute value. | 52 // Get the autosize attribute value. |
61 bool GetAutoSizeAttribute() const; | 53 bool GetAutoSizeAttribute() const; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 void EnableCompositing(bool enable); | 114 void EnableCompositing(bool enable); |
123 | 115 |
124 // Returns true if |point| lies within the bounds of the plugin rectangle. | 116 // Returns true if |point| lies within the bounds of the plugin rectangle. |
125 // Not OK to use this function for making security-sensitive decision since it | 117 // Not OK to use this function for making security-sensitive decision since it |
126 // can return false positives when the plugin has rotation transformation | 118 // can return false positives when the plugin has rotation transformation |
127 // applied. | 119 // applied. |
128 bool InBounds(const gfx::Point& point) const; | 120 bool InBounds(const gfx::Point& point) const; |
129 | 121 |
130 gfx::Point ToLocalCoordinates(const gfx::Point& point) const; | 122 gfx::Point ToLocalCoordinates(const gfx::Point& point) const; |
131 | 123 |
| 124 // BrowserPlugin implementation. |
| 125 virtual void AddMethodBinding( |
| 126 BrowserPluginMethodBinding* method_binding) OVERRIDE; |
| 127 virtual void AddPropertyBinding( |
| 128 BrowserPluginPropertyBinding* method_binding) OVERRIDE; |
| 129 virtual RenderView* GetRenderView() const OVERRIDE; |
| 130 virtual WebKit::WebPluginContainer* GetContainer() const OVERRIDE; |
| 131 virtual void TriggerEvent( |
| 132 const std::string& event_name, |
| 133 std::map<std::string, base::Value*>* props) OVERRIDE; |
| 134 virtual void UpdateDOMAttribute(const std::string& attribute_name, |
| 135 const std::string& attribute_value) OVERRIDE; |
| 136 virtual void RemoveDOMAttribute(const std::string& attribute_name) OVERRIDE; |
| 137 virtual std::string GetDOMAttributeValue( |
| 138 const std::string& attribute_name) const OVERRIDE; |
| 139 virtual bool HasDOMAttribute( |
| 140 const std::string& attribute_name) const OVERRIDE; |
| 141 virtual bool HasNavigated() const OVERRIDE; |
| 142 |
| 143 // IPC::Sender implementation. |
| 144 virtual bool Send(IPC::Message* message) OVERRIDE; |
| 145 |
132 // WebKit::WebPlugin implementation. | 146 // WebKit::WebPlugin implementation. |
133 virtual WebKit::WebPluginContainer* container() const OVERRIDE; | 147 virtual WebKit::WebPluginContainer* container() const OVERRIDE; |
134 virtual bool initialize(WebKit::WebPluginContainer* container) OVERRIDE; | 148 virtual bool initialize(WebKit::WebPluginContainer* container) OVERRIDE; |
135 virtual void destroy() OVERRIDE; | 149 virtual void destroy() OVERRIDE; |
136 virtual NPObject* scriptableObject() OVERRIDE; | 150 virtual NPObject* scriptableObject() OVERRIDE; |
137 virtual bool supportsKeyboardFocus() const OVERRIDE; | 151 virtual bool supportsKeyboardFocus() const OVERRIDE; |
138 virtual bool canProcessDrag() const OVERRIDE; | 152 virtual bool canProcessDrag() const OVERRIDE; |
139 virtual void paint( | 153 virtual void paint( |
140 WebKit::WebCanvas* canvas, | 154 WebKit::WebCanvas* canvas, |
141 const WebKit::WebRect& rect) OVERRIDE; | 155 const WebKit::WebRect& rect) OVERRIDE; |
(...skipping 19 matching lines...) Expand all Loading... |
161 virtual void didFinishLoading() OVERRIDE; | 175 virtual void didFinishLoading() OVERRIDE; |
162 virtual void didFailLoading(const WebKit::WebURLError& error) OVERRIDE; | 176 virtual void didFailLoading(const WebKit::WebURLError& error) OVERRIDE; |
163 virtual void didFinishLoadingFrameRequest( | 177 virtual void didFinishLoadingFrameRequest( |
164 const WebKit::WebURL& url, | 178 const WebKit::WebURL& url, |
165 void* notify_data) OVERRIDE; | 179 void* notify_data) OVERRIDE; |
166 virtual void didFailLoadingFrameRequest( | 180 virtual void didFailLoadingFrameRequest( |
167 const WebKit::WebURL& url, | 181 const WebKit::WebURL& url, |
168 void* notify_data, | 182 void* notify_data, |
169 const WebKit::WebURLError& error) OVERRIDE; | 183 const WebKit::WebURLError& error) OVERRIDE; |
170 private: | 184 private: |
171 friend class base::DeleteHelper<BrowserPlugin>; | 185 friend class base::DeleteHelper<BrowserPluginImpl>; |
172 // Only the manager is allowed to create a BrowserPlugin. | 186 // Only the manager is allowed to create a BrowserPlugin. |
173 friend class BrowserPluginManagerImpl; | 187 friend class BrowserPluginManagerImpl; |
| 188 friend class BrowserPluginObserver; |
174 friend class MockBrowserPluginManager; | 189 friend class MockBrowserPluginManager; |
175 | 190 |
176 // For unit/integration tests. | 191 // For unit/integration tests. |
177 friend class MockBrowserPlugin; | 192 friend class MockBrowserPlugin; |
178 | 193 |
179 // A BrowserPlugin object is a controller that represents an instance of a | 194 // A BrowserPluginImpl object is a controller that represents an instance of a |
180 // browser plugin within the embedder renderer process. Each BrowserPlugin | 195 // browser plugin within the embedder renderer process. Each BrowserPlugin |
181 // within a process has a unique instance_id that is used to route messages | 196 // within a process has a unique |instance_id| that is used to route messages |
182 // to it. It takes in a RenderViewImpl that it's associated with along | 197 // to it. It takes in a RenderViewImpl that it's associated with along |
183 // with the frame within which it lives and the initial attributes assigned | 198 // with the frame within which it lives and the initial attributes assigned |
184 // to it on creation. | 199 // to it on creation. |
185 BrowserPlugin( | 200 BrowserPluginImpl( |
186 RenderViewImpl* render_view, | 201 RenderViewImpl* render_view, |
187 WebKit::WebFrame* frame, | 202 WebKit::WebFrame* frame, |
188 const WebKit::WebPluginParams& params); | 203 const WebKit::WebPluginParams& params); |
189 | 204 |
190 virtual ~BrowserPlugin(); | 205 virtual ~BrowserPluginImpl(); |
| 206 |
| 207 // Add and remove observers for filtering IPC messages. Clients must be sure |
| 208 // to remove the observer before they go away. |
| 209 void AddObserver(BrowserPluginObserver* observer); |
| 210 void RemoveObserver(BrowserPluginObserver* observer); |
191 | 211 |
192 int width() const { return plugin_rect_.width(); } | 212 int width() const { return plugin_rect_.width(); } |
193 int height() const { return plugin_rect_.height(); } | 213 int height() const { return plugin_rect_.height(); } |
194 int instance_id() const { return instance_id_; } | 214 int instance_id() const { return instance_id_; } |
195 // Gets the Max Height value used for auto size. | 215 // Gets the Max Height value used for auto size. |
196 int GetAdjustedMaxHeight() const; | 216 int GetAdjustedMaxHeight() const; |
197 // Gets the Max Width value used for auto size. | 217 // Gets the Max Width value used for auto size. |
198 int GetAdjustedMaxWidth() const; | 218 int GetAdjustedMaxWidth() const; |
199 // Gets the Min Height value used for auto size. | 219 // Gets the Min Height value used for auto size. |
200 int GetAdjustedMinHeight() const; | 220 int GetAdjustedMinHeight() const; |
201 // Gets the Min Width value used for auto size. | 221 // Gets the Min Width value used for auto size. |
202 int GetAdjustedMinWidth() const; | 222 int GetAdjustedMinWidth() const; |
203 BrowserPluginManager* browser_plugin_manager() const { | 223 BrowserPluginManager* browser_plugin_manager() const { |
204 return browser_plugin_manager_; | 224 return browser_plugin_manager_; |
205 } | 225 } |
206 | 226 |
207 // Virtual to allow for mocking in tests. | 227 // Virtual to allow for mocking in tests. |
208 virtual float GetDeviceScaleFactor() const; | 228 virtual float GetDeviceScaleFactor() const; |
209 | 229 |
210 // Parses the attributes of the browser plugin from the element's attributes | 230 // Parses the attributes of the browser plugin from the element's attributes |
211 // and sets them appropriately. | 231 // and sets them appropriately. |
212 void ParseAttributes(); | 232 void ParseAttributes(); |
213 | 233 |
214 // Triggers the event-listeners for |event_name|. Note that the function | |
215 // frees all the values in |props|. | |
216 void TriggerEvent(const std::string& event_name, | |
217 std::map<std::string, base::Value*>* props); | |
218 | |
219 // Creates and maps a shared damage buffer. | 234 // Creates and maps a shared damage buffer. |
220 virtual base::SharedMemory* CreateDamageBuffer( | 235 virtual base::SharedMemory* CreateDamageBuffer( |
221 const size_t size, | 236 const size_t size, |
222 base::SharedMemoryHandle* shared_memory_handle); | 237 base::SharedMemoryHandle* shared_memory_handle); |
223 // Swaps out the |current_damage_buffer_| with the |pending_damage_buffer_|. | 238 // Swaps out the |current_damage_buffer_| with the |pending_damage_buffer_|. |
224 void SwapDamageBuffers(); | 239 void SwapDamageBuffers(); |
225 | 240 |
226 // Populates BrowserPluginHostMsg_ResizeGuest_Params with resize state and | 241 // Populates BrowserPluginHostMsg_ResizeGuest_Params with resize state and |
227 // allocates a new |pending_damage_buffer_| if in software rendering mode. | 242 // allocates a new |pending_damage_buffer_| if in software rendering mode. |
228 void PopulateResizeGuestParameters( | 243 void PopulateResizeGuestParameters( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 void SetInstanceID(int instance_id); | 275 void SetInstanceID(int instance_id); |
261 | 276 |
262 // IPC message handlers. | 277 // IPC message handlers. |
263 // Please keep in alphabetical order. | 278 // Please keep in alphabetical order. |
264 void OnAdvanceFocus(int instance_id, bool reverse); | 279 void OnAdvanceFocus(int instance_id, bool reverse); |
265 void OnBuffersSwapped(int instance_id, | 280 void OnBuffersSwapped(int instance_id, |
266 const gfx::Size& size, | 281 const gfx::Size& size, |
267 std::string mailbox_name, | 282 std::string mailbox_name, |
268 int gpu_route_id, | 283 int gpu_route_id, |
269 int gpu_host_id); | 284 int gpu_host_id); |
| 285 void OnForwardMessage(int instance_id, const IPC::Message& msg); |
270 void OnGuestContentWindowReady(int instance_id, | 286 void OnGuestContentWindowReady(int instance_id, |
271 int content_window_routing_id); | 287 int content_window_routing_id); |
272 void OnGuestGone(int instance_id, int process_id, int status); | 288 void OnGuestGone(int instance_id, int process_id, int status); |
273 void OnGuestResponsive(int instance_id, int process_id); | 289 void OnGuestResponsive(int instance_id, int process_id); |
274 void OnGuestUnresponsive(int instance_id, int process_id); | 290 void OnGuestUnresponsive(int instance_id, int process_id); |
275 void OnLoadAbort(int instance_id, | 291 void OnLoadAbort(int instance_id, |
276 const GURL& url, | 292 const GURL& url, |
277 bool is_top_level, | 293 bool is_top_level, |
278 const std::string& type); | 294 const std::string& type); |
279 void OnLoadCommit(int instance_id, | 295 void OnLoadCommit(int instance_id, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 | 342 |
327 gfx::Size last_view_size_; | 343 gfx::Size last_view_size_; |
328 bool size_changed_in_flight_; | 344 bool size_changed_in_flight_; |
329 bool allocate_instance_id_sent_; | 345 bool allocate_instance_id_sent_; |
330 | 346 |
331 // BrowserPlugin outlives RenderViewImpl in Chrome Apps and so we need to | 347 // BrowserPlugin outlives RenderViewImpl in Chrome Apps and so we need to |
332 // store the BrowserPlugin's BrowserPluginManager in a member variable to | 348 // store the BrowserPlugin's BrowserPluginManager in a member variable to |
333 // avoid accessing the RenderViewImpl. | 349 // avoid accessing the RenderViewImpl. |
334 scoped_refptr<BrowserPluginManager> browser_plugin_manager_; | 350 scoped_refptr<BrowserPluginManager> browser_plugin_manager_; |
335 | 351 |
| 352 // A list of observers that filter messages. Weak references. |
| 353 ObserverList<BrowserPluginObserver> observers_; |
| 354 |
336 // Important: Do not add more history state here. | 355 // Important: Do not add more history state here. |
337 // We strongly discourage storing additional history state (such as page IDs) | 356 // We strongly discourage storing additional history state (such as page IDs) |
338 // in the embedder process, at the risk of having incorrect information that | 357 // in the embedder process, at the risk of having incorrect information that |
339 // can lead to broken back/forward logic in apps. | 358 // can lead to broken back/forward logic in apps. |
340 // It's also important that this state does not get modified by any logic in | 359 // It's also important that this state does not get modified by any logic in |
341 // the embedder process. It should only be updated in response to navigation | 360 // the embedder process. It should only be updated in response to navigation |
342 // events in the guest. No assumptions should be made about how the index | 361 // events in the guest. No assumptions should be made about how the index |
343 // will change after a navigation (e.g., for back, forward, or go), because | 362 // will change after a navigation (e.g., for back, forward, or go), because |
344 // the changes are not always obvious. For example, there is a maximum | 363 // the changes are not always obvious. For example, there is a maximum |
345 // number of entries and earlier ones will automatically be pruned. | 364 // number of entries and earlier ones will automatically be pruned. |
346 int current_nav_entry_index_; | 365 int current_nav_entry_index_; |
347 int nav_entry_count_; | 366 int nav_entry_count_; |
348 | 367 |
349 // Used for HW compositing. | 368 // Used for HW compositing. |
350 bool compositing_enabled_; | 369 bool compositing_enabled_; |
351 scoped_refptr<BrowserPluginCompositingHelper> compositing_helper_; | 370 scoped_refptr<BrowserPluginCompositingHelper> compositing_helper_; |
352 | 371 |
353 DISALLOW_COPY_AND_ASSIGN(BrowserPlugin); | 372 DISALLOW_COPY_AND_ASSIGN(BrowserPluginImpl); |
354 }; | 373 }; |
355 | 374 |
356 } // namespace content | 375 } // namespace content |
357 | 376 |
358 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ | 377 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_IMPL_H_ |
OLD | NEW |