| OLD | NEW |
| (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/renderer/browser_plugin/browser_plugin_backing_store.h" | |
| 18 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | |
| 19 #include "content/renderer/render_view_impl.h" | |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h" | |
| 21 | |
| 22 struct BrowserPluginHostMsg_AutoSize_Params; | |
| 23 struct BrowserPluginHostMsg_ResizeGuest_Params; | |
| 24 struct BrowserPluginMsg_LoadCommit_Params; | |
| 25 struct BrowserPluginMsg_UpdateRect_Params; | |
| 26 | |
| 27 namespace content { | |
| 28 | |
| 29 class BrowserPluginCompositingHelper; | |
| 30 class BrowserPluginManager; | |
| 31 class MockBrowserPlugin; | |
| 32 | |
| 33 class CONTENT_EXPORT BrowserPlugin : | |
| 34 NON_EXPORTED_BASE(public WebKit::WebPlugin) { | |
| 35 public: | |
| 36 RenderViewImpl* render_view() const { return render_view_.get(); } | |
| 37 int render_view_routing_id() const { return render_view_routing_id_; } | |
| 38 | |
| 39 bool OnMessageReceived(const IPC::Message& msg); | |
| 40 | |
| 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. | |
| 53 std::string GetNameAttribute() const; | |
| 54 // Parse the name attribute value. | |
| 55 void ParseNameAttribute(); | |
| 56 // Get the src attribute value of the BrowserPlugin instance. | |
| 57 std::string GetSrcAttribute() const; | |
| 58 // Parse the src attribute value of the BrowserPlugin instance. | |
| 59 bool ParseSrcAttribute(std::string* error_message); | |
| 60 // Get the autosize attribute value. | |
| 61 bool GetAutoSizeAttribute() const; | |
| 62 // Parses the autosize attribute value. | |
| 63 void ParseAutoSizeAttribute(); | |
| 64 // Get the maxheight attribute value. | |
| 65 int GetMaxHeightAttribute() const; | |
| 66 // Get the maxwidth attribute value. | |
| 67 int GetMaxWidthAttribute() const; | |
| 68 // Get the minheight attribute value. | |
| 69 int GetMinHeightAttribute() const; | |
| 70 // Get the minwidth attribute value. | |
| 71 int GetMinWidthAttribute() const; | |
| 72 // Parse the minwidth, maxwidth, minheight, and maxheight attribute values. | |
| 73 void ParseSizeContraintsChanged(); | |
| 74 // The partition identifier string is stored as UTF-8. | |
| 75 std::string GetPartitionAttribute() const; | |
| 76 // This method can be successfully called only before the first navigation for | |
| 77 // this instance of BrowserPlugin. If an error occurs, the |error_message| is | |
| 78 // set appropriately to indicate the failure reason. | |
| 79 bool ParsePartitionAttribute(std::string* error_message); | |
| 80 // True if the partition attribute can be removed. | |
| 81 bool CanRemovePartitionAttribute(std::string* error_message); | |
| 82 | |
| 83 bool InAutoSizeBounds(const gfx::Size& size) const; | |
| 84 | |
| 85 // Get the guest's DOMWindow proxy. | |
| 86 NPObject* GetContentWindow() const; | |
| 87 | |
| 88 // Returns Chrome's process ID for the current guest. | |
| 89 int guest_process_id() const { return guest_process_id_; } | |
| 90 // Returns Chrome's route ID for the current guest. | |
| 91 int guest_route_id() const { return guest_route_id_; } | |
| 92 // Returns whether the guest process has crashed. | |
| 93 bool guest_crashed() const { return guest_crashed_; } | |
| 94 | |
| 95 // Query whether the guest can navigate back to the previous entry. | |
| 96 bool CanGoBack() const; | |
| 97 // Query whether the guest can navigation forward to the next entry. | |
| 98 bool CanGoForward() const; | |
| 99 | |
| 100 // Informs the guest of an updated focus state. | |
| 101 void UpdateGuestFocusState(); | |
| 102 // Indicates whether the guest should be focused. | |
| 103 bool ShouldGuestBeFocused() const; | |
| 104 | |
| 105 // Tells the BrowserPlugin to tell the guest to navigate to the previous | |
| 106 // navigation entry in the navigation history. | |
| 107 void Back(); | |
| 108 // Tells the BrowserPlugin to tell the guest to navigate to the next | |
| 109 // navigation entry in the navigation history. | |
| 110 void Forward(); | |
| 111 // Tells the BrowserPlugin to tell the guest to navigate to a position | |
| 112 // relative to the current index in its navigation history. | |
| 113 void Go(int relativeIndex); | |
| 114 // Tells the BrowserPlugin to terminate the guest process. | |
| 115 void TerminateGuest(); | |
| 116 | |
| 117 // A request from Javascript has been made to stop the loading of the page. | |
| 118 void Stop(); | |
| 119 // A request from Javascript has been made to reload the page. | |
| 120 void Reload(); | |
| 121 // A request to enable hardware compositing. | |
| 122 void EnableCompositing(bool enable); | |
| 123 | |
| 124 // 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 | |
| 126 // can return false positives when the plugin has rotation transformation | |
| 127 // applied. | |
| 128 bool InBounds(const gfx::Point& point) const; | |
| 129 | |
| 130 gfx::Point ToLocalCoordinates(const gfx::Point& point) const; | |
| 131 | |
| 132 // WebKit::WebPlugin implementation. | |
| 133 virtual WebKit::WebPluginContainer* container() const OVERRIDE; | |
| 134 virtual bool initialize(WebKit::WebPluginContainer* container) OVERRIDE; | |
| 135 virtual void destroy() OVERRIDE; | |
| 136 virtual NPObject* scriptableObject() OVERRIDE; | |
| 137 virtual bool supportsKeyboardFocus() const OVERRIDE; | |
| 138 virtual bool canProcessDrag() const OVERRIDE; | |
| 139 virtual void paint( | |
| 140 WebKit::WebCanvas* canvas, | |
| 141 const WebKit::WebRect& rect) OVERRIDE; | |
| 142 virtual void updateGeometry( | |
| 143 const WebKit::WebRect& frame_rect, | |
| 144 const WebKit::WebRect& clip_rect, | |
| 145 const WebKit::WebVector<WebKit::WebRect>& cut_outs_rects, | |
| 146 bool is_visible) OVERRIDE; | |
| 147 virtual void updateFocus(bool focused) OVERRIDE; | |
| 148 virtual void updateVisibility(bool visible) OVERRIDE; | |
| 149 virtual bool acceptsInputEvents() OVERRIDE; | |
| 150 virtual bool handleInputEvent( | |
| 151 const WebKit::WebInputEvent& event, | |
| 152 WebKit::WebCursorInfo& cursor_info) OVERRIDE; | |
| 153 virtual bool handleDragStatusUpdate(WebKit::WebDragStatus drag_status, | |
| 154 const WebKit::WebDragData& drag_data, | |
| 155 WebKit::WebDragOperationsMask mask, | |
| 156 const WebKit::WebPoint& position, | |
| 157 const WebKit::WebPoint& screen) OVERRIDE; | |
| 158 virtual void didReceiveResponse( | |
| 159 const WebKit::WebURLResponse& response) OVERRIDE; | |
| 160 virtual void didReceiveData(const char* data, int data_length) OVERRIDE; | |
| 161 virtual void didFinishLoading() OVERRIDE; | |
| 162 virtual void didFailLoading(const WebKit::WebURLError& error) OVERRIDE; | |
| 163 virtual void didFinishLoadingFrameRequest( | |
| 164 const WebKit::WebURL& url, | |
| 165 void* notify_data) OVERRIDE; | |
| 166 virtual void didFailLoadingFrameRequest( | |
| 167 const WebKit::WebURL& url, | |
| 168 void* notify_data, | |
| 169 const WebKit::WebURLError& error) OVERRIDE; | |
| 170 private: | |
| 171 friend class base::DeleteHelper<BrowserPlugin>; | |
| 172 // Only the manager is allowed to create a BrowserPlugin. | |
| 173 friend class BrowserPluginManagerImpl; | |
| 174 friend class MockBrowserPluginManager; | |
| 175 | |
| 176 // For unit/integration tests. | |
| 177 friend class MockBrowserPlugin; | |
| 178 | |
| 179 // A BrowserPlugin object is a controller that represents an instance of a | |
| 180 // browser plugin within the embedder renderer process. Each BrowserPlugin | |
| 181 // 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 | |
| 183 // with the frame within which it lives and the initial attributes assigned | |
| 184 // to it on creation. | |
| 185 BrowserPlugin( | |
| 186 RenderViewImpl* render_view, | |
| 187 WebKit::WebFrame* frame, | |
| 188 const WebKit::WebPluginParams& params); | |
| 189 | |
| 190 virtual ~BrowserPlugin(); | |
| 191 | |
| 192 int width() const { return plugin_rect_.width(); } | |
| 193 int height() const { return plugin_rect_.height(); } | |
| 194 int instance_id() const { return instance_id_; } | |
| 195 // Gets the Max Height value used for auto size. | |
| 196 int GetAdjustedMaxHeight() const; | |
| 197 // Gets the Max Width value used for auto size. | |
| 198 int GetAdjustedMaxWidth() const; | |
| 199 // Gets the Min Height value used for auto size. | |
| 200 int GetAdjustedMinHeight() const; | |
| 201 // Gets the Min Width value used for auto size. | |
| 202 int GetAdjustedMinWidth() const; | |
| 203 BrowserPluginManager* browser_plugin_manager() const { | |
| 204 return browser_plugin_manager_; | |
| 205 } | |
| 206 | |
| 207 // Virtual to allow for mocking in tests. | |
| 208 virtual float GetDeviceScaleFactor() const; | |
| 209 | |
| 210 // Parses the attributes of the browser plugin from the element's attributes | |
| 211 // and sets them appropriately. | |
| 212 void ParseAttributes(); | |
| 213 | |
| 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. | |
| 220 virtual base::SharedMemory* CreateDamageBuffer( | |
| 221 const size_t size, | |
| 222 base::SharedMemoryHandle* shared_memory_handle); | |
| 223 // Swaps out the |current_damage_buffer_| with the |pending_damage_buffer_|. | |
| 224 void SwapDamageBuffers(); | |
| 225 | |
| 226 // Populates BrowserPluginHostMsg_ResizeGuest_Params with resize state and | |
| 227 // allocates a new |pending_damage_buffer_| if in software rendering mode. | |
| 228 void PopulateResizeGuestParameters( | |
| 229 BrowserPluginHostMsg_ResizeGuest_Params* params, | |
| 230 const gfx::Size& view_size); | |
| 231 | |
| 232 // Populates BrowserPluginHostMsg_AutoSize_Params object with autosize state. | |
| 233 void PopulateAutoSizeParameters( | |
| 234 BrowserPluginHostMsg_AutoSize_Params* params, bool current_auto_size); | |
| 235 | |
| 236 // Populates both AutoSize and ResizeGuest parameters based on the current | |
| 237 // autosize state. | |
| 238 void GetDamageBufferWithSizeParams( | |
| 239 BrowserPluginHostMsg_AutoSize_Params* auto_size_params, | |
| 240 BrowserPluginHostMsg_ResizeGuest_Params* resize_guest_params); | |
| 241 | |
| 242 // Informs the guest of an updated autosize state. | |
| 243 void UpdateGuestAutoSizeState(bool current_auto_size); | |
| 244 | |
| 245 // Informs the BrowserPlugin that guest has changed its size in autosize mode. | |
| 246 void SizeChangedDueToAutoSize(const gfx::Size& old_view_size); | |
| 247 | |
| 248 // Indicates whether a damage buffer was used by the guest process for the | |
| 249 // provided |params|. | |
| 250 static bool UsesDamageBuffer( | |
| 251 const BrowserPluginMsg_UpdateRect_Params& params); | |
| 252 | |
| 253 // Indicates whether the |pending_damage_buffer_| was used to copy over pixels | |
| 254 // given the provided |params|. | |
| 255 bool UsesPendingDamageBuffer( | |
| 256 const BrowserPluginMsg_UpdateRect_Params& params); | |
| 257 | |
| 258 // Sets the instance ID of the BrowserPlugin and requests a guest from the | |
| 259 // browser process. | |
| 260 void SetInstanceID(int instance_id); | |
| 261 | |
| 262 // IPC message handlers. | |
| 263 // Please keep in alphabetical order. | |
| 264 void OnAdvanceFocus(int instance_id, bool reverse); | |
| 265 void OnBuffersSwapped(int instance_id, | |
| 266 const gfx::Size& size, | |
| 267 std::string mailbox_name, | |
| 268 int gpu_route_id, | |
| 269 int gpu_host_id); | |
| 270 void OnGuestContentWindowReady(int instance_id, | |
| 271 int content_window_routing_id); | |
| 272 void OnGuestGone(int instance_id, int process_id, int status); | |
| 273 void OnGuestResponsive(int instance_id, int process_id); | |
| 274 void OnGuestUnresponsive(int instance_id, int process_id); | |
| 275 void OnLoadAbort(int instance_id, | |
| 276 const GURL& url, | |
| 277 bool is_top_level, | |
| 278 const std::string& type); | |
| 279 void OnLoadCommit(int instance_id, | |
| 280 const BrowserPluginMsg_LoadCommit_Params& params); | |
| 281 void OnLoadRedirect(int instance_id, | |
| 282 const GURL& old_url, | |
| 283 const GURL& new_url, | |
| 284 bool is_top_level); | |
| 285 void OnLoadStart(int instance_id, const GURL& url, bool is_top_level); | |
| 286 void OnLoadStop(int instance_id); | |
| 287 void OnSetCursor(int instance_id, const WebCursor& cursor); | |
| 288 void OnShouldAcceptTouchEvents(int instance_id, bool accept); | |
| 289 void OnUpdatedName(int instance_id, const std::string& name); | |
| 290 void OnUpdateRect(int instance_id, | |
| 291 const BrowserPluginMsg_UpdateRect_Params& params); | |
| 292 | |
| 293 int instance_id_; | |
| 294 base::WeakPtr<RenderViewImpl> render_view_; | |
| 295 // We cache the |render_view_|'s routing ID because we need it on destruction. | |
| 296 // If the |render_view_| is destroyed before the BrowserPlugin is destroyed | |
| 297 // then we will attempt to access a NULL pointer. | |
| 298 int render_view_routing_id_; | |
| 299 WebKit::WebPluginContainer* container_; | |
| 300 scoped_ptr<BrowserPluginBindings> bindings_; | |
| 301 scoped_ptr<BrowserPluginBackingStore> backing_store_; | |
| 302 scoped_ptr<base::SharedMemory> current_damage_buffer_; | |
| 303 scoped_ptr<base::SharedMemory> pending_damage_buffer_; | |
| 304 uint32 damage_buffer_sequence_id_; | |
| 305 bool resize_ack_received_; | |
| 306 gfx::Rect plugin_rect_; | |
| 307 // Bitmap for crashed plugin. Lazily initialized, non-owning pointer. | |
| 308 SkBitmap* sad_guest_; | |
| 309 bool guest_crashed_; | |
| 310 scoped_ptr<BrowserPluginHostMsg_ResizeGuest_Params> pending_resize_params_; | |
| 311 // True if we have ever sent a NavigateGuest message to the embedder. | |
| 312 bool navigate_src_sent_; | |
| 313 bool auto_size_ack_pending_; | |
| 314 int guest_process_id_; | |
| 315 int guest_route_id_; | |
| 316 std::string storage_partition_id_; | |
| 317 bool persist_storage_; | |
| 318 bool valid_partition_id_; | |
| 319 int content_window_routing_id_; | |
| 320 bool plugin_focused_; | |
| 321 // Tracks the visibility of the browser plugin regardless of the whole | |
| 322 // embedder RenderView's visibility. | |
| 323 bool visible_; | |
| 324 | |
| 325 WebCursor cursor_; | |
| 326 | |
| 327 gfx::Size last_view_size_; | |
| 328 bool size_changed_in_flight_; | |
| 329 bool allocate_instance_id_sent_; | |
| 330 | |
| 331 // BrowserPlugin outlives RenderViewImpl in Chrome Apps and so we need to | |
| 332 // store the BrowserPlugin's BrowserPluginManager in a member variable to | |
| 333 // avoid accessing the RenderViewImpl. | |
| 334 scoped_refptr<BrowserPluginManager> browser_plugin_manager_; | |
| 335 | |
| 336 // Important: Do not add more history state here. | |
| 337 // We strongly discourage storing additional history state (such as page IDs) | |
| 338 // in the embedder process, at the risk of having incorrect information that | |
| 339 // 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 | |
| 341 // 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 | |
| 343 // 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 | |
| 345 // number of entries and earlier ones will automatically be pruned. | |
| 346 int current_nav_entry_index_; | |
| 347 int nav_entry_count_; | |
| 348 | |
| 349 // Used for HW compositing. | |
| 350 bool compositing_enabled_; | |
| 351 scoped_refptr<BrowserPluginCompositingHelper> compositing_helper_; | |
| 352 | |
| 353 DISALLOW_COPY_AND_ASSIGN(BrowserPlugin); | |
| 354 }; | |
| 355 | |
| 356 } // namespace content | |
| 357 | |
| 358 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ | |
| OLD | NEW |