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

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

Issue 10868012: Browser Plugin: New Implementation (Browser Side) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master-trial-obrowser
Patch Set: Remove TestTimeoutTracker and wait indefinitely in tests instead, fix one include. 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 #include "content/browser/browser_plugin/browser_plugin_embedder.h"
6
7 #include <set>
8
9 #include "base/logging.h"
10 #include "base/stl_util.h"
11 #include "base/time.h"
12 #include "content/browser/browser_plugin/browser_plugin_embedder_helper.h"
13 #include "content/browser/browser_plugin/browser_plugin_guest.h"
14 #include "content/browser/browser_plugin/browser_plugin_host_factory.h"
15 #include "content/browser/renderer_host/render_view_host_impl.h"
16 #include "content/browser/web_contents/web_contents_impl.h"
17 #include "content/public/browser/notification_details.h"
18 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/notification_source.h"
20 #include "content/public/browser/notification_types.h"
21 #include "content/public/browser/web_contents_view.h"
22 #include "content/public/common/url_constants.h"
23 #include "ipc/ipc_sync_message.h"
jam 2012/09/17 22:13:36 are you sure you need this? it's very rare that so
lazyboy 2012/09/17 22:37:48 Don't seem to need this. Done.
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
25 #include "ui/gfx/size.h"
26 #include "ui/surface/transport_dib.h"
27
28 namespace content {
29
30 // static
31 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL;
32
33 BrowserPluginEmbedder::BrowserPluginEmbedder(
34 WebContentsImpl* web_contents,
35 RenderViewHost* render_view_host)
36 : WebContentsObserver(web_contents),
37 render_view_host_(render_view_host) {
38 // Listen to visibility changes so that an embedder hides its guests
39 // as well.
40 registrar_.Add(this,
41 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
42 Source<WebContents>(web_contents));
43
44 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper.
45 new BrowserPluginEmbedderHelper(this, render_view_host);
46 }
47
48 BrowserPluginEmbedder::~BrowserPluginEmbedder() {
49 // Destroy guests that are managed by the current embedder.
50 DestroyGuests();
51 }
52
53 // static
54 BrowserPluginEmbedder* BrowserPluginEmbedder::Create(
55 WebContentsImpl* web_contents,
56 content::RenderViewHost* render_view_host) {
57 if (factory_) {
58 return factory_->CreateBrowserPluginEmbedder(web_contents,
59 render_view_host);
60 }
61 return new BrowserPluginEmbedder(web_contents, render_view_host);
62 }
63
64 BrowserPluginGuest* BrowserPluginEmbedder::GetGuestByInstanceID(
65 int instance_id) const {
66 ContainerInstanceMap::const_iterator it =
67 guest_web_contents_by_instance_id_.find(instance_id);
68 if (it != guest_web_contents_by_instance_id_.end())
69 return static_cast<WebContentsImpl*>(it->second)->GetBrowserPluginGuest();
70 return NULL;
71 }
72
73 void BrowserPluginEmbedder::AddGuest(int instance_id,
74 WebContents* guest_web_contents,
75 int64 frame_id) {
76 DCHECK(guest_web_contents_by_instance_id_.find(instance_id) ==
77 guest_web_contents_by_instance_id_.end());
78 guest_web_contents_by_instance_id_[instance_id] = guest_web_contents;
79 }
80
81 void BrowserPluginEmbedder::NavigateGuest(RenderViewHost* render_view_host,
82 int instance_id,
83 int64 frame_id,
84 const std::string& src,
85 const gfx::Size& size) {
86 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
87 WebContentsImpl* guest_web_contents = NULL;
88 GURL url(src);
89 if (!guest) {
90 const std::string& host =
91 render_view_host->GetSiteInstance()->GetSite().host();
92 guest_web_contents = WebContentsImpl::CreateGuest(
93 web_contents()->GetBrowserContext(),
94 host,
95 instance_id);
96
97 guest = guest_web_contents->GetBrowserPluginGuest();
98 guest->set_embedder_render_process_host(
99 render_view_host->GetProcess());
100
101 guest_web_contents->GetMutableRendererPrefs()->
102 throttle_input_events = false;
103 AddGuest(instance_id, guest_web_contents, frame_id);
104 guest_web_contents->SetDelegate(guest);
105 } else {
106 guest_web_contents = static_cast<WebContentsImpl*>(guest->web_contents());
107 }
108
109 // We ignore loading empty urls in web_contents.
110 // If a guest sets empty src attribute after it has navigated to some
111 // non-empty page, the action is considered no-op.
112 // TODO(lazyboy): The js shim for browser-plugin might need to reflect empty
113 // src ignoring in the shadow DOM element: http://crbug.com/149001.
114 if (!src.empty()) {
115 guest_web_contents->GetController().LoadURL(url,
116 Referrer(),
117 PAGE_TRANSITION_AUTO_SUBFRAME,
118 std::string());
119 }
120
121 if (!size.IsEmpty())
122 guest_web_contents->GetView()->SizeContents(size);
123 }
124
125 void BrowserPluginEmbedder::UpdateRectACK(int instance_id,
126 int message_id,
127 const gfx::Size& size) {
128 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
129 if (guest)
130 guest->UpdateRectACK(message_id, size);
131 }
132
133 void BrowserPluginEmbedder::ResizeGuest(int instance_id,
134 TransportDIB* damage_buffer,
135 #if defined(OS_WIN)
136 int damage_buffer_size,
137 #endif
138 int width,
139 int height,
140 bool resize_pending,
141 float scale_factor) {
142 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
143 if (!guest)
144 return;
145 WebContentsImpl* guest_web_contents =
146 static_cast<WebContentsImpl*>(guest->web_contents());
147 guest->SetDamageBuffer(damage_buffer,
148 #if defined(OS_WIN)
149 damage_buffer_size,
150 #endif
151 gfx::Size(width, height),
152 scale_factor);
153 if (!resize_pending)
154 guest_web_contents->GetView()->SizeContents(gfx::Size(width, height));
155 }
156
157 void BrowserPluginEmbedder::SetFocus(int instance_id,
158 bool focused) {
159 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
160 if (guest)
161 guest->SetFocus(focused);
162 }
163
164 void BrowserPluginEmbedder::DestroyGuests() {
165 STLDeleteContainerPairSecondPointers(
166 guest_web_contents_by_instance_id_.begin(),
167 guest_web_contents_by_instance_id_.end());
168 guest_web_contents_by_instance_id_.clear();
169 }
170
171 void BrowserPluginEmbedder::HandleInputEvent(int instance_id,
172 RenderViewHost* render_view_host,
173 const gfx::Rect& guest_rect,
174 const WebKit::WebInputEvent& event,
175 IPC::Message* reply_message) {
176 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
177 if (guest)
178 guest->HandleInputEvent(render_view_host, guest_rect, event, reply_message);
179 }
180
181 void BrowserPluginEmbedder::DestroyGuestByInstanceID(int instance_id) {
182 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id);
183 if (guest) {
184 WebContents* guest_web_contents = guest->web_contents();
185
186 // Destroy the guest's web_contents.
187 delete guest_web_contents;
188 guest_web_contents_by_instance_id_.erase(instance_id);
189 }
190 }
191
192 void BrowserPluginEmbedder::RenderViewDeleted(
193 RenderViewHost* render_view_host) {
194 DestroyGuests();
195 }
196
197 void BrowserPluginEmbedder::RenderViewGone(base::TerminationStatus status) {
198 DestroyGuests();
199 }
200
201 void BrowserPluginEmbedder::WebContentsVisibilityChanged(bool visible) {
202 // If the embedder is hidden we need to hide the guests as well.
203 for (ContainerInstanceMap::const_iterator it =
204 guest_web_contents_by_instance_id_.begin();
205 it != guest_web_contents_by_instance_id_.end(); ++it) {
206 WebContents* web_contents = it->second;
207 if (visible)
208 web_contents->WasShown();
209 else
210 web_contents->WasHidden();
211 }
212 }
213
214 void BrowserPluginEmbedder::PluginDestroyed(int instance_id) {
215 DestroyGuestByInstanceID(instance_id);
216 }
217
218 void BrowserPluginEmbedder::Observe(int type,
219 const NotificationSource& source,
220 const NotificationDetails& details) {
221 switch (type) {
222 case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: {
223 bool visible = *Details<bool>(details).ptr();
224 WebContentsVisibilityChanged(visible);
225 break;
226 }
227 default:
228 NOTREACHED() << "Unexpected notification type: " << type;
229 }
230 }
231
232 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698