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

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: Sync + fix test target. 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 typedef std::map<int, BrowserPluginGuest*> ContainerInstanceMap;
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 virtual ~BrowserPluginEmbedder();
64
65 static BrowserPluginEmbedder* Create(WebContentsImpl* web_contents,
66 RenderViewHost* render_view_host);
67
68 // Navigates in a guest (new or existing).
69 void NavigateGuest(RenderViewHost* render_view_host,
70 int instance_id,
71 int64 frame_id,
72 const std::string& src,
73 const gfx::Size& size);
74
75 // WebContentsObserver implementation.
76 // Used to monitor frame navigation to clean up guests when a frame navigates
77 // away from the browser plugin it's hosting.
78 virtual void DidCommitProvisionalLoadForFrame(
79 int64 frame_id,
80 bool is_main_frame,
81 const GURL& url,
82 PageTransition transition_type,
83 RenderViewHost* render_view_host) OVERRIDE;
84 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
85 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
86
87 // NotificationObserver method override.
88 virtual void Observe(int type,
89 const NotificationSource& source,
90 const NotificationDetails& details) OVERRIDE;
91
92 // Overrides factory for testing. Default (NULL) value indicates regular
93 // (non-test) environment.
94 static void set_factory_for_testing(BrowserPluginHostFactory* factory) {
95 factory_ = factory;
96 }
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 ContainerInstanceMap guests_by_instance_id_;
149 RenderViewHost* render_view_host_;
150
151 DISALLOW_COPY_AND_ASSIGN(BrowserPluginEmbedder);
152 };
153
154 } // namespace content
155
156 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698