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