OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 5 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 namespace content { | 28 namespace content { |
29 | 29 |
30 // static | 30 // static |
31 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; | 31 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; |
32 | 32 |
33 BrowserPluginEmbedder::BrowserPluginEmbedder( | 33 BrowserPluginEmbedder::BrowserPluginEmbedder( |
34 WebContentsImpl* web_contents, | 34 WebContentsImpl* web_contents, |
35 RenderViewHost* render_view_host) | 35 RenderViewHost* render_view_host) |
36 : WebContentsObserver(web_contents), | 36 : WebContentsObserver(web_contents), |
37 render_view_host_(render_view_host) { | 37 render_view_host_(render_view_host), |
| 38 visible_(true) { |
38 // Listen to visibility changes so that an embedder hides its guests | 39 // Listen to visibility changes so that an embedder hides its guests |
39 // as well. | 40 // as well. |
40 registrar_.Add(this, | 41 registrar_.Add(this, |
41 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 42 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
42 Source<WebContents>(web_contents)); | 43 Source<WebContents>(web_contents)); |
43 | 44 |
44 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. | 45 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. |
45 new BrowserPluginEmbedderHelper(this, render_view_host); | 46 new BrowserPluginEmbedderHelper(this, render_view_host); |
46 } | 47 } |
47 | 48 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 void BrowserPluginEmbedder::RenderViewDeleted( | 243 void BrowserPluginEmbedder::RenderViewDeleted( |
243 RenderViewHost* render_view_host) { | 244 RenderViewHost* render_view_host) { |
244 DestroyGuests(); | 245 DestroyGuests(); |
245 } | 246 } |
246 | 247 |
247 void BrowserPluginEmbedder::RenderViewGone(base::TerminationStatus status) { | 248 void BrowserPluginEmbedder::RenderViewGone(base::TerminationStatus status) { |
248 DestroyGuests(); | 249 DestroyGuests(); |
249 } | 250 } |
250 | 251 |
251 void BrowserPluginEmbedder::WebContentsVisibilityChanged(bool visible) { | 252 void BrowserPluginEmbedder::WebContentsVisibilityChanged(bool visible) { |
| 253 visible_ = visible; |
252 // If the embedder is hidden we need to hide the guests as well. | 254 // If the embedder is hidden we need to hide the guests as well. |
253 for (ContainerInstanceMap::const_iterator it = | 255 for (ContainerInstanceMap::const_iterator it = |
254 guest_web_contents_by_instance_id_.begin(); | 256 guest_web_contents_by_instance_id_.begin(); |
255 it != guest_web_contents_by_instance_id_.end(); ++it) { | 257 it != guest_web_contents_by_instance_id_.end(); ++it) { |
256 WebContents* web_contents = it->second; | 258 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(it->second); |
257 if (visible) | 259 BrowserPluginGuest* guest = web_contents->GetBrowserPluginGuest(); |
258 web_contents->WasShown(); | 260 guest->SetVisibility(visible, guest->visible()); |
259 else | |
260 web_contents->WasHidden(); | |
261 } | 261 } |
262 } | 262 } |
263 | 263 |
264 void BrowserPluginEmbedder::PluginDestroyed(int instance_id) { | 264 void BrowserPluginEmbedder::PluginDestroyed(int instance_id) { |
265 DestroyGuestByInstanceID(instance_id); | 265 DestroyGuestByInstanceID(instance_id); |
266 } | 266 } |
267 | 267 |
| 268 void BrowserPluginEmbedder::SetGuestVisibility(int instance_id, |
| 269 bool guest_visible) { |
| 270 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
| 271 if (guest) |
| 272 guest->SetVisibility(visible_, guest_visible); |
| 273 } |
| 274 |
268 void BrowserPluginEmbedder::Go(int instance_id, int relative_index) { | 275 void BrowserPluginEmbedder::Go(int instance_id, int relative_index) { |
269 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); | 276 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
270 if (guest) | 277 if (guest) |
271 guest->Go(relative_index); | 278 guest->Go(relative_index); |
272 } | 279 } |
273 | 280 |
274 void BrowserPluginEmbedder::Stop(int instance_id) { | 281 void BrowserPluginEmbedder::Stop(int instance_id) { |
275 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); | 282 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
276 if (guest) | 283 if (guest) |
277 guest->Stop(); | 284 guest->Stop(); |
(...skipping 19 matching lines...) Expand all Loading... |
297 bool visible = *Details<bool>(details).ptr(); | 304 bool visible = *Details<bool>(details).ptr(); |
298 WebContentsVisibilityChanged(visible); | 305 WebContentsVisibilityChanged(visible); |
299 break; | 306 break; |
300 } | 307 } |
301 default: | 308 default: |
302 NOTREACHED() << "Unexpected notification type: " << type; | 309 NOTREACHED() << "Unexpected notification type: " << type; |
303 } | 310 } |
304 } | 311 } |
305 | 312 |
306 } // namespace content | 313 } // namespace content |
OLD | NEW |