Chromium Code Reviews| 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_H_ |
| 6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ | 6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ |
| 7 | 7 |
| 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" | 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 void Go(int relativeIndex); | 111 void Go(int relativeIndex); |
| 112 // Tells the BrowserPlugin to terminate the guest process. | 112 // Tells the BrowserPlugin to terminate the guest process. |
| 113 void TerminateGuest(); | 113 void TerminateGuest(); |
| 114 | 114 |
| 115 // A request from Javascript has been made to stop the loading of the page. | 115 // A request from Javascript has been made to stop the loading of the page. |
| 116 void Stop(); | 116 void Stop(); |
| 117 // A request from Javascript has been made to reload the page. | 117 // A request from Javascript has been made to reload the page. |
| 118 void Reload(); | 118 void Reload(); |
| 119 // A request to enable hardware compositing. | 119 // A request to enable hardware compositing. |
| 120 void EnableCompositing(bool enable); | 120 void EnableCompositing(bool enable); |
| 121 // A request from content client to track lifetime of a Javascript object | |
| 122 // related to a permission request object. | |
| 123 // This is used to clean up hanging permission request objects. | |
| 124 void PersistRequestObject(const NPVariant* request, | |
| 125 const std::string& type, | |
| 126 int id); | |
| 121 | 127 |
| 122 // Returns true if |point| lies within the bounds of the plugin rectangle. | 128 // Returns true if |point| lies within the bounds of the plugin rectangle. |
| 123 // Not OK to use this function for making security-sensitive decision since it | 129 // Not OK to use this function for making security-sensitive decision since it |
| 124 // can return false positives when the plugin has rotation transformation | 130 // can return false positives when the plugin has rotation transformation |
| 125 // applied. | 131 // applied. |
| 126 bool InBounds(const gfx::Point& point) const; | 132 bool InBounds(const gfx::Point& point) const; |
| 127 | 133 |
| 128 gfx::Point ToLocalCoordinates(const gfx::Point& point) const; | 134 gfx::Point ToLocalCoordinates(const gfx::Point& point) const; |
| 135 // Called by browser plugin binding. | |
| 136 void OnEmbedderDecidedPermission(int request_id, bool allow); | |
| 137 | |
| 129 | 138 |
| 130 // WebKit::WebPlugin implementation. | 139 // WebKit::WebPlugin implementation. |
| 131 virtual WebKit::WebPluginContainer* container() const OVERRIDE; | 140 virtual WebKit::WebPluginContainer* container() const OVERRIDE; |
| 132 virtual bool initialize(WebKit::WebPluginContainer* container) OVERRIDE; | 141 virtual bool initialize(WebKit::WebPluginContainer* container) OVERRIDE; |
| 133 virtual void destroy() OVERRIDE; | 142 virtual void destroy() OVERRIDE; |
| 134 virtual NPObject* scriptableObject() OVERRIDE; | 143 virtual NPObject* scriptableObject() OVERRIDE; |
| 135 virtual bool supportsKeyboardFocus() const OVERRIDE; | 144 virtual bool supportsKeyboardFocus() const OVERRIDE; |
| 136 virtual bool canProcessDrag() const OVERRIDE; | 145 virtual bool canProcessDrag() const OVERRIDE; |
| 137 virtual void paint( | 146 virtual void paint( |
| 138 WebKit::WebCanvas* canvas, | 147 WebKit::WebCanvas* canvas, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 167 const WebKit::WebURLError& error) OVERRIDE; | 176 const WebKit::WebURLError& error) OVERRIDE; |
| 168 private: | 177 private: |
| 169 friend class base::DeleteHelper<BrowserPlugin>; | 178 friend class base::DeleteHelper<BrowserPlugin>; |
| 170 // Only the manager is allowed to create a BrowserPlugin. | 179 // Only the manager is allowed to create a BrowserPlugin. |
| 171 friend class BrowserPluginManagerImpl; | 180 friend class BrowserPluginManagerImpl; |
| 172 friend class MockBrowserPluginManager; | 181 friend class MockBrowserPluginManager; |
| 173 | 182 |
| 174 // For unit/integration tests. | 183 // For unit/integration tests. |
| 175 friend class MockBrowserPlugin; | 184 friend class MockBrowserPlugin; |
| 176 | 185 |
| 186 enum PermissionRequestType { | |
| 187 INVALID = -1, | |
| 188 MEDIA | |
| 189 }; | |
| 190 | |
| 177 // A BrowserPlugin object is a controller that represents an instance of a | 191 // A BrowserPlugin object is a controller that represents an instance of a |
| 178 // browser plugin within the embedder renderer process. Each BrowserPlugin | 192 // browser plugin within the embedder renderer process. Each BrowserPlugin |
| 179 // within a process has a unique instance_id that is used to route messages | 193 // within a process has a unique instance_id that is used to route messages |
| 180 // to it. It takes in a RenderViewImpl that it's associated with along | 194 // to it. It takes in a RenderViewImpl that it's associated with along |
| 181 // with the frame within which it lives and the initial attributes assigned | 195 // with the frame within which it lives and the initial attributes assigned |
| 182 // to it on creation. | 196 // to it on creation. |
| 183 BrowserPlugin( | 197 BrowserPlugin( |
| 184 RenderViewImpl* render_view, | 198 RenderViewImpl* render_view, |
| 185 WebKit::WebFrame* frame, | 199 WebKit::WebFrame* frame, |
| 186 const WebKit::WebPluginParams& params); | 200 const WebKit::WebPluginParams& params); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 void GetDamageBufferWithSizeParams( | 250 void GetDamageBufferWithSizeParams( |
| 237 BrowserPluginHostMsg_AutoSize_Params* auto_size_params, | 251 BrowserPluginHostMsg_AutoSize_Params* auto_size_params, |
| 238 BrowserPluginHostMsg_ResizeGuest_Params* resize_guest_params); | 252 BrowserPluginHostMsg_ResizeGuest_Params* resize_guest_params); |
| 239 | 253 |
| 240 // Informs the guest of an updated autosize state. | 254 // Informs the guest of an updated autosize state. |
| 241 void UpdateGuestAutoSizeState(bool current_auto_size); | 255 void UpdateGuestAutoSizeState(bool current_auto_size); |
| 242 | 256 |
| 243 // Informs the BrowserPlugin that guest has changed its size in autosize mode. | 257 // Informs the BrowserPlugin that guest has changed its size in autosize mode. |
| 244 void SizeChangedDueToAutoSize(const gfx::Size& old_view_size); | 258 void SizeChangedDueToAutoSize(const gfx::Size& old_view_size); |
| 245 | 259 |
| 260 bool HasEventListeners(const std::string& event_name); | |
| 261 | |
| 246 // Indicates whether a damage buffer was used by the guest process for the | 262 // Indicates whether a damage buffer was used by the guest process for the |
| 247 // provided |params|. | 263 // provided |params|. |
| 248 static bool UsesDamageBuffer( | 264 static bool UsesDamageBuffer( |
| 249 const BrowserPluginMsg_UpdateRect_Params& params); | 265 const BrowserPluginMsg_UpdateRect_Params& params); |
| 250 | 266 |
| 251 // Indicates whether the |pending_damage_buffer_| was used to copy over pixels | 267 // Indicates whether the |pending_damage_buffer_| was used to copy over pixels |
| 252 // given the provided |params|. | 268 // given the provided |params|. |
| 253 bool UsesPendingDamageBuffer( | 269 bool UsesPendingDamageBuffer( |
| 254 const BrowserPluginMsg_UpdateRect_Params& params); | 270 const BrowserPluginMsg_UpdateRect_Params& params); |
| 255 | 271 |
| 256 // Sets the instance ID of the BrowserPlugin and requests a guest from the | 272 // Sets the instance ID of the BrowserPlugin and requests a guest from the |
| 257 // browser process. | 273 // browser process. |
| 258 void SetInstanceID(int instance_id); | 274 void SetInstanceID(int instance_id); |
| 259 | 275 |
| 276 // Populates the ancestor set with the ancestors of the BrowserPlugin. A new | |
| 277 // BrowserPlugin gets created when we reparent the <object> node, so this | |
| 278 // set should always be valid. | |
| 279 void PopulateAncestorList(); | |
| 280 | |
| 281 // Requests media access permission from the embedder. | |
| 282 void RequestMediaPermission(int request_id, | |
| 283 const base::DictionaryValue& request_info); | |
| 284 // Informs the BrowserPlugin that the guest's permission request has been | |
| 285 // allowed or denied by the embedder. | |
| 286 void AllowPermission(PermissionRequestType type, | |
| 287 int request_id, | |
| 288 bool allow); | |
| 289 | |
| 290 void AllowPermissionIfRequestIsPending(int request_id, bool allow); | |
|
Charlie Reis
2013/02/13 21:08:05
Please add comments for these three.
lazyboy
2013/02/13 22:17:34
Done.
| |
| 291 void OnRequestObjectGarbageCollected(int request_id); | |
| 292 static void WeakCallbackForPersistObject(v8::Persistent<v8::Value> object, | |
| 293 void* param); | |
| 294 | |
| 260 // IPC message handlers. | 295 // IPC message handlers. |
| 261 // Please keep in alphabetical order. | 296 // Please keep in alphabetical order. |
| 262 void OnAdvanceFocus(int instance_id, bool reverse); | 297 void OnAdvanceFocus(int instance_id, bool reverse); |
| 263 void OnBuffersSwapped(int instance_id, | 298 void OnBuffersSwapped(int instance_id, |
| 264 const gfx::Size& size, | 299 const gfx::Size& size, |
| 265 std::string mailbox_name, | 300 std::string mailbox_name, |
| 266 int gpu_route_id, | 301 int gpu_route_id, |
| 267 int gpu_host_id); | 302 int gpu_host_id); |
| 268 void OnGuestContentWindowReady(int instance_id, | 303 void OnGuestContentWindowReady(int instance_id, |
| 269 int content_window_routing_id); | 304 int content_window_routing_id); |
| 270 void OnGuestGone(int instance_id, int process_id, int status); | 305 void OnGuestGone(int instance_id, int process_id, int status); |
| 271 void OnGuestResponsive(int instance_id, int process_id); | 306 void OnGuestResponsive(int instance_id, int process_id); |
| 272 void OnGuestUnresponsive(int instance_id, int process_id); | 307 void OnGuestUnresponsive(int instance_id, int process_id); |
| 273 void OnLoadAbort(int instance_id, | 308 void OnLoadAbort(int instance_id, |
| 274 const GURL& url, | 309 const GURL& url, |
| 275 bool is_top_level, | 310 bool is_top_level, |
| 276 const std::string& type); | 311 const std::string& type); |
| 277 void OnLoadCommit(int instance_id, | 312 void OnLoadCommit(int instance_id, |
| 278 const BrowserPluginMsg_LoadCommit_Params& params); | 313 const BrowserPluginMsg_LoadCommit_Params& params); |
| 279 void OnLoadRedirect(int instance_id, | 314 void OnLoadRedirect(int instance_id, |
| 280 const GURL& old_url, | 315 const GURL& old_url, |
| 281 const GURL& new_url, | 316 const GURL& new_url, |
| 282 bool is_top_level); | 317 bool is_top_level); |
| 283 void OnLoadStart(int instance_id, const GURL& url, bool is_top_level); | 318 void OnLoadStart(int instance_id, const GURL& url, bool is_top_level); |
| 284 void OnLoadStop(int instance_id); | 319 void OnLoadStop(int instance_id); |
| 320 // Requests permission from the embedder. | |
| 321 void OnRequestPermission(int instance_id, | |
| 322 const std::string& permission_type, | |
| 323 int request_id, | |
| 324 const base::DictionaryValue& request_info); | |
| 285 void OnSetCursor(int instance_id, const WebCursor& cursor); | 325 void OnSetCursor(int instance_id, const WebCursor& cursor); |
| 286 void OnShouldAcceptTouchEvents(int instance_id, bool accept); | 326 void OnShouldAcceptTouchEvents(int instance_id, bool accept); |
| 287 void OnUpdatedName(int instance_id, const std::string& name); | 327 void OnUpdatedName(int instance_id, const std::string& name); |
| 288 void OnUpdateRect(int instance_id, | 328 void OnUpdateRect(int instance_id, |
| 289 const BrowserPluginMsg_UpdateRect_Params& params); | 329 const BrowserPluginMsg_UpdateRect_Params& params); |
| 290 | 330 |
| 291 int instance_id_; | 331 int instance_id_; |
| 292 base::WeakPtr<RenderViewImpl> render_view_; | 332 base::WeakPtr<RenderViewImpl> render_view_; |
| 293 // We cache the |render_view_|'s routing ID because we need it on destruction. | 333 // We cache the |render_view_|'s routing ID because we need it on destruction. |
| 294 // If the |render_view_| is destroyed before the BrowserPlugin is destroyed | 334 // If the |render_view_| is destroyed before the BrowserPlugin is destroyed |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 319 // Tracks the visibility of the browser plugin regardless of the whole | 359 // Tracks the visibility of the browser plugin regardless of the whole |
| 320 // embedder RenderView's visibility. | 360 // embedder RenderView's visibility. |
| 321 bool visible_; | 361 bool visible_; |
| 322 | 362 |
| 323 WebCursor cursor_; | 363 WebCursor cursor_; |
| 324 | 364 |
| 325 gfx::Size last_view_size_; | 365 gfx::Size last_view_size_; |
| 326 bool size_changed_in_flight_; | 366 bool size_changed_in_flight_; |
| 327 bool allocate_instance_id_sent_; | 367 bool allocate_instance_id_sent_; |
| 328 | 368 |
| 369 typedef std::map<int, std::pair<int, PermissionRequestType> > | |
| 370 PendingPermissionRequests; | |
| 371 PendingPermissionRequests pending_permission_requests_; | |
| 372 | |
| 373 typedef std::pair<int, base::WeakPtr<BrowserPlugin> > | |
| 374 AliveV8PermissionRequestItem; | |
| 375 std::map<int, AliveV8PermissionRequestItem*> | |
| 376 alive_v8_permission_request_objects; | |
| 377 | |
| 329 // BrowserPlugin outlives RenderViewImpl in Chrome Apps and so we need to | 378 // BrowserPlugin outlives RenderViewImpl in Chrome Apps and so we need to |
| 330 // store the BrowserPlugin's BrowserPluginManager in a member variable to | 379 // store the BrowserPlugin's BrowserPluginManager in a member variable to |
| 331 // avoid accessing the RenderViewImpl. | 380 // avoid accessing the RenderViewImpl. |
| 332 scoped_refptr<BrowserPluginManager> browser_plugin_manager_; | 381 scoped_refptr<BrowserPluginManager> browser_plugin_manager_; |
| 333 | 382 |
| 334 // Important: Do not add more history state here. | 383 // Important: Do not add more history state here. |
| 335 // We strongly discourage storing additional history state (such as page IDs) | 384 // We strongly discourage storing additional history state (such as page IDs) |
| 336 // in the embedder process, at the risk of having incorrect information that | 385 // in the embedder process, at the risk of having incorrect information that |
| 337 // can lead to broken back/forward logic in apps. | 386 // can lead to broken back/forward logic in apps. |
| 338 // It's also important that this state does not get modified by any logic in | 387 // It's also important that this state does not get modified by any logic in |
| 339 // the embedder process. It should only be updated in response to navigation | 388 // the embedder process. It should only be updated in response to navigation |
| 340 // events in the guest. No assumptions should be made about how the index | 389 // events in the guest. No assumptions should be made about how the index |
| 341 // will change after a navigation (e.g., for back, forward, or go), because | 390 // will change after a navigation (e.g., for back, forward, or go), because |
| 342 // the changes are not always obvious. For example, there is a maximum | 391 // the changes are not always obvious. For example, there is a maximum |
| 343 // number of entries and earlier ones will automatically be pruned. | 392 // number of entries and earlier ones will automatically be pruned. |
| 344 int current_nav_entry_index_; | 393 int current_nav_entry_index_; |
| 345 int nav_entry_count_; | 394 int nav_entry_count_; |
| 346 | 395 |
| 347 // Used for HW compositing. | 396 // Used for HW compositing. |
| 348 bool compositing_enabled_; | 397 bool compositing_enabled_; |
| 349 scoped_refptr<BrowserPluginCompositingHelper> compositing_helper_; | 398 scoped_refptr<BrowserPluginCompositingHelper> compositing_helper_; |
| 350 | 399 |
| 400 // Weak factory used in v8 |MakeWeak| callback, since the v8 callback might | |
| 401 // get called after BrowserPlugin has been destroyed. | |
| 402 base::WeakPtrFactory<BrowserPlugin> weak_ptr_factory_; | |
| 403 | |
| 404 // Set of ancestor nodes. | |
| 405 std::vector<WebKit::WebNode> ancestors_; | |
| 406 | |
| 351 DISALLOW_COPY_AND_ASSIGN(BrowserPlugin); | 407 DISALLOW_COPY_AND_ASSIGN(BrowserPlugin); |
| 352 }; | 408 }; |
| 353 | 409 |
| 354 } // namespace content | 410 } // namespace content |
| 355 | 411 |
| 356 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ | 412 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ |
| OLD | NEW |