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

Unified Diff: content/browser/browser_plugin/browser_plugin_web_contents_observer.cc

Issue 9924026: Browser side implementation of browser plugin (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Updated RenderProcessHostImpl Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/browser_plugin/browser_plugin_web_contents_observer.cc
diff --git a/content/browser/browser_plugin/browser_plugin_web_contents_observer.cc b/content/browser/browser_plugin/browser_plugin_web_contents_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..219289ab175e5ab2727a032d4246a7d07d3e1dbd
--- /dev/null
+++ b/content/browser/browser_plugin/browser_plugin_web_contents_observer.cc
@@ -0,0 +1,104 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/browser_plugin/browser_plugin_web_contents_observer.h"
+
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_source.h"
+#include "content/public/browser/notification_types.h"
+#include "content/public/browser/render_widget_host.h"
+#include "content/public/browser/web_contents.h"
+
+// static
+BrowserPluginWebContentsObserver*
+BrowserPluginWebContentsObserver::Create(
+ content::WebContents* web_contents) {
+ return new BrowserPluginWebContentsObserver(web_contents);
+}
+
+BrowserPluginWebContentsObserver::BrowserPluginWebContentsObserver(
+ content::WebContents* web_contents)
+ : WebContentsObserver(web_contents) {
+ registrar_.Add(this,
+ content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
+ content::Source<content::RenderViewHost>(
+ web_contents->GetRenderViewHost()));
+}
+
+BrowserPluginWebContentsObserver::~BrowserPluginWebContentsObserver() {
+}
+
+void BrowserPluginWebContentsObserver::AddGuest(
+ content::WebContents* guest,
+ int64 frame_id) {
+ guests_[guest] = frame_id;
+}
+
+void BrowserPluginWebContentsObserver::RemoveGuest(
+ content::WebContents* guest) {
+ guests_.erase(guest);
+}
+
+void BrowserPluginWebContentsObserver::DestroyGuests() {
+ for (GuestMap::const_iterator it = guests_.begin();
+ it != guests_.end(); ++it) {
+ const content::WebContents* contents = it->first;
+ delete contents;
+ }
+ guests_.clear();
+}
+
+void BrowserPluginWebContentsObserver::DidCommitProvisionalLoadForFrame(
+ int64 frame_id,
+ bool is_main_frame,
+ const GURL& url,
+ content::PageTransition transition_type) {
+ GuestSet guests_to_delete;
+ for (GuestMap::const_iterator it = guests_.begin();
+ it != guests_.end(); ++it) {
+ content::WebContents* contents = it->first;
+ if (it->second == frame_id) {
+ guests_to_delete.insert(contents);
+ }
+ }
+ for (GuestSet::const_iterator it = guests_to_delete.begin();
+ it != guests_to_delete.end(); ++it) {
+ delete *it;
+ guests_.erase(*it);
+ }
+}
+
+void BrowserPluginWebContentsObserver::RenderViewDeleted(
+ content::RenderViewHost* render_view_host) {
+ DestroyGuests();
+}
+
+void BrowserPluginWebContentsObserver::RenderViewGone(
+ base::TerminationStatus status) {
+ DestroyGuests();
+}
+
+void BrowserPluginWebContentsObserver::WebContentsDestroyed(
+ content::WebContents* web_contents) {
+ DestroyGuests();
+}
+
+void BrowserPluginWebContentsObserver::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK(type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED);
+ bool visible = *content::Details<bool>(details).ptr();
+
+ // If the host is hidden we need to hide the guests as well.
+ for (GuestMap::const_iterator it = guests_.begin();
+ it != guests_.end(); ++it) {
+ content::WebContents* contents = it->first;
+ if (visible)
+ contents->ShowContents();
+ else
+ contents->HideContents();
+ }
+}
+

Powered by Google App Engine
This is Rietveld 408576698