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

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

Powered by Google App Engine
This is Rietveld 408576698