Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: content/browser/browser_plugin/browser_plugin_embedder.h

Issue 10868012: Browser Plugin: New Implementation (Browser Side) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master-trial-obrowser
Patch Set: Rework tests to use timeouts instead of waiting indefinitely, not store any Guest* in embedder. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 // A BrowserPluginEmbedder has a list of guest it manages.
6 // In the beginning when a renderer sees one or more guests (BrowserPlugin
7 // instance(s)) and there is a request to navigate to them, the WebContents for
8 // that renderer creates a BrowserPluginEmbedder for itself. The
9 // BrowserPluginEmbedder, in turn, manages a set of BrowserPluginGuests -- one
10 // BrowserPluginGuest for each guest in the embedding WebContents.
11 // BrowserPluginEmbedder routes any messages directed to a guest from the
12 // renderer (BrowserPlugin) to the appropriate guest (identified by the guest's
13 // |instance_id|).
14 //
15 // BrowserPluginEmbedder is responsible for cleaning up the guests when the
16 // embedder frame navigates away to a different page.
17
18 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_
19 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_
20
21 #include <map>
22 #include <string>
23
24 #include "base/compiler_specific.h"
25 #include "content/browser/browser_plugin/browser_plugin_host_factory.h"
26 #include "content/public/browser/notification_observer.h"
27 #include "content/public/browser/notification_registrar.h"
28 #include "content/public/browser/render_view_host_observer.h"
29 #include "content/public/browser/web_contents_delegate.h"
30 #include "content/public/browser/web_contents_observer.h"
31 #include "ipc/ipc_channel_handle.h"
32 #include "ipc/ipc_sync_message.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
34 #include "ui/surface/transport_dib.h"
35 #include "webkit/glue/webcursor.h"
36
37 namespace gfx {
38 class Size;
39 }
40
41 class WebContentsImpl;
42
43 struct BrowserPluginHostMsg_ResizeGuest_Params;
44 struct ViewHostMsg_UpdateRect_Params;
45
46 namespace content {
47
48 class BrowserPluginGuest;
49 class BrowserPluginHostFactory;
50
51 // A browser plugin embedder provides functionality for WebContents to operate
52 // in the 'embedder' role. It manages list of guests inside the embedder.
53 //
54 // The embedder's WebContents manages the lifetime of the embedder. They are
55 // created when a renderer asks WebContents to navigate (for the first time) to
56 // some guest. It gets destroyed when either the WebContents goes away or there
57 // is a RenderViewHost swap in WebContents.
58 class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver,
59 public NotificationObserver {
60 public:
61 virtual ~BrowserPluginEmbedder();
62
63 static BrowserPluginEmbedder* Create(WebContentsImpl* web_contents,
64 RenderViewHost* render_view_host);
65
66 // Navigates in a guest (new or existing).
67 void NavigateGuest(RenderViewHost* render_view_host,
68 int instance_id,
69 int64 frame_id,
70 const std::string& src,
71 const gfx::Size& size);
72
73 // WebContentsObserver implementation.
74 // Used to monitor frame navigation to clean up guests when a frame navigates
75 // away from the browser plugin it's hosting.
76 virtual void DidCommitProvisionalLoadForFrame(
77 int64 frame_id,
78 bool is_main_frame,
79 const GURL& url,
80 PageTransition transition_type,
81 RenderViewHost* render_view_host) OVERRIDE;
82 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
83 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
84
85 // NotificationObserver method override.
86 virtual void Observe(int type,
87 const NotificationSource& source,
88 const NotificationDetails& details) OVERRIDE;
89
90 // Overrides factory for testing. Default (NULL) value indicates regular
91 // (non-test) environment.
92 static void set_factory_for_testing(BrowserPluginHostFactory* factory) {
93 factory_ = factory;
94 }
95
96 typedef std::map<int, WebContents*> ContainerInstanceMap;
awong 2012/09/10 23:57:32 nit: typedefs go at the top of the section. http:
lazyboy 2012/09/11 19:58:39 Done.
97
98 private:
99 friend class BrowserPluginEmbedderHelper;
100 friend class TestBrowserPluginEmbedder;
101
102 BrowserPluginEmbedder(WebContentsImpl* web_contents,
103 RenderViewHost* render_view_host);
104
105 // Returns a guest browser plugin delegate by its container ID specified
106 // in BrowserPlugin.
107 BrowserPluginGuest* GetGuestByInstanceID(int instance_id) const;
108 // Adds a new guest to the embedder (overridable in test).
109 virtual void AddGuest(int instance_id,
110 BrowserPluginGuest* guest,
111 int64 frame_id);
112 void DestroyGuestByInstanceID(int instance_id);
113 void DestroyGuests();
114
115 // Message handlers (direct/indirect via BrowserPluginEmbedderHelper).
116 // Routes update rect ack message to the appropriate guest.
117 void UpdateRectACK(int instance_id, int message_id, const gfx::Size& size);
118 void SetFocus(int instance_id, bool focused);
119 void ResizeGuest(int instance_id,
120 TransportDIB* damage_buffer,
121 int width,
122 int height,
123 bool resize_pending,
124 float scale_factor);
125 // Handles input events sent from the BrowserPlugin (embedder's renderer
126 // process) by passing them to appropriate guest's input handler.
127 void HandleInputEvent(int instance_id,
128 RenderViewHost* render_view_host,
129 const gfx::Rect& guest_rect,
130 const WebKit::WebInputEvent& event,
131 IPC::Message* reply_message);
132 void PluginDestroyed(int instance_id);
133
134 // Called when visiblity of web_contents changes, so the embedder will
135 // show/hide its guest.
136 void WebContentsVisibilityChanged(bool visible);
137
138 typedef std::map<WebContents*, int64> GuestWebContentsMap;
139
140 // Static factory instance (always NULL for non-test).
141 static BrowserPluginHostFactory* factory_;
142
143 // A scoped container for notification registries.
144 NotificationRegistrar registrar_;
145
146 // Contains guests' WebContents, mapping to their frame ids.
147 GuestWebContentsMap guest_web_contents_container_;
148 // Contains guests' WebContents, mapping from their instance ids.
149 ContainerInstanceMap guest_web_contents_by_instance_id_;
150 RenderViewHost* render_view_host_;
151
152 DISALLOW_COPY_AND_ASSIGN(BrowserPluginEmbedder);
153 };
154
155 } // namespace content
156
157 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698