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_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_ |
| 6 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/compiler_specific.h" |
| 11 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 12 #include "content/public/browser/notification_observer.h" |
| 13 #include "content/public/browser/notification_registrar.h" |
| 14 #include "content/public/browser/render_view_host_observer.h" |
| 15 #include "content/public/browser/web_contents_delegate.h" |
| 16 #include "content/public/browser/web_contents_observer.h" |
| 17 #include "ipc/ipc_channel_handle.h" |
| 18 #include "ipc/ipc_sync_message.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 20 #include "ui/surface/transport_dib.h" |
| 21 #include "webkit/glue/webcursor.h" |
| 22 |
| 23 namespace gfx { |
| 24 class Size; |
| 25 } |
| 26 |
| 27 class WebContentsImpl; |
| 28 |
| 29 struct BrowserPluginHostMsg_ResizeGuest_Params; |
| 30 struct ViewHostMsg_UpdateRect_Params; |
| 31 |
| 32 namespace content { |
| 33 |
| 34 class BrowserPluginGuest; |
| 35 class BrowserPluginHostFactory; |
| 36 |
| 37 typedef std::map<WebContents*, int64> GuestWebContentsMap; |
| 38 typedef std::map<int, BrowserPluginGuest*> ContainerInstanceMap; |
| 39 |
| 40 // A browser plugin embedder provides functionality for WebContents to operate |
| 41 // in the 'embedder' role. It manages list of guests inside the embedder. |
| 42 class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver, |
| 43 public NotificationObserver { |
| 44 public: |
| 45 virtual ~BrowserPluginEmbedder(); |
| 46 |
| 47 static BrowserPluginEmbedder* Create(WebContentsImpl* web_contents, |
| 48 RenderViewHost* render_view_host); |
| 49 |
| 50 // Navigates in a guest (new or existing). |
| 51 void NavigateGuest(RenderViewHost* render_view_host, |
| 52 int instance_id, |
| 53 int64 frame_id, |
| 54 const std::string& src, |
| 55 const gfx::Size& size); |
| 56 |
| 57 // Overrides factory for testing. Default (NULL) value indicates regular |
| 58 // (non-test) environment. |
| 59 static void set_factory_for_testing(BrowserPluginHostFactory* factory) { |
| 60 factory_ = factory; |
| 61 } |
| 62 |
| 63 // Returns true if this Embedder is associated with the RenderViewHost. |
| 64 bool IsForRenderViewHost(RenderViewHost* rvh); |
| 65 |
| 66 private: |
| 67 friend class BrowserPluginEmbedderHelper; |
| 68 friend class TestBrowserPluginEmbedder; |
| 69 |
| 70 BrowserPluginEmbedder(WebContentsImpl* web_contents, |
| 71 RenderViewHost* render_view_host); |
| 72 |
| 73 // Returns a guest browser plugin delegate by its container ID specified |
| 74 // in BrowserPlugin. |
| 75 BrowserPluginGuest* GetGuestByInstanceID(int instance_id) const; |
| 76 // Adds a new guest to the embedder (overridable in test). |
| 77 virtual void AddGuest(int instance_id, |
| 78 BrowserPluginGuest* guest, |
| 79 int64 frame_id); |
| 80 void DestroyGuestByInstanceID(int instance_id); |
| 81 void DestroyGuests(); |
| 82 |
| 83 // Message handlers (direct/indirect via BrowserPluginEmbedderHelper). |
| 84 // Routes update rect ack message to the appropriate guest. |
| 85 void UpdateRectACK(int instance_id, int message_id, const gfx::Size& size); |
| 86 void SetFocus(int instance_id, bool focused); |
| 87 void ResizeGuest(int instance_id, |
| 88 TransportDIB* damage_buffer, |
| 89 int width, |
| 90 int height, |
| 91 bool resize_pending, |
| 92 float scale_factor); |
| 93 // Handles input events sent from the BrowserPlugin (embedder's renderer |
| 94 // process) by passing them to appropriate guest's input handler. |
| 95 void HandleInputEvent(int instance_id, |
| 96 RenderViewHost* render_view_host, |
| 97 const gfx::Rect& guest_rect, |
| 98 const WebKit::WebInputEvent& event, |
| 99 IPC::Message* reply_message); |
| 100 void PluginDestroyed(int instance_id); |
| 101 |
| 102 // WebContentsObserver implementation. |
| 103 // Used to monitor frame navigation to clean up guests when a frame navigates |
| 104 // away from the browser plugin it's hosting. |
| 105 virtual void DidCommitProvisionalLoadForFrame( |
| 106 int64 frame_id, |
| 107 bool is_main_frame, |
| 108 const GURL& url, |
| 109 PageTransition transition_type, |
| 110 RenderViewHost* render_view_host) OVERRIDE; |
| 111 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE; |
| 112 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; |
| 113 |
| 114 // NotificationObserver method override. |
| 115 virtual void Observe(int type, |
| 116 const NotificationSource& source, |
| 117 const NotificationDetails& details) OVERRIDE; |
| 118 |
| 119 // Called when visiblity of web_contents changes, so the embedder will |
| 120 // show/hide its guest. |
| 121 void WebContentsVisibilityChanged(bool visible); |
| 122 |
| 123 // Static factory instance (always NULL for non-test). |
| 124 static BrowserPluginHostFactory* factory_; |
| 125 |
| 126 // A scoped container for notification registries. |
| 127 NotificationRegistrar registrar_; |
| 128 |
| 129 // Contains guests' WebContents, mapping to their frame ids. |
| 130 GuestWebContentsMap guest_web_contents_container_; |
| 131 ContainerInstanceMap guests_by_instance_id_; |
| 132 RenderViewHost* render_view_host_; |
| 133 |
| 134 DISALLOW_COPY_AND_ASSIGN(BrowserPluginEmbedder); |
| 135 }; |
| 136 |
| 137 } // namespace content |
| 138 |
| 139 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_ |
OLD | NEW |