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

Side by Side 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, 8 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 | Annotate | Revision Log
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_web_contents_observer.h"
6
7 #include "content/public/browser/notification_details.h"
8 #include "content/public/browser/notification_source.h"
9 #include "content/public/browser/notification_types.h"
10 #include "content/public/browser/render_widget_host.h"
11 #include "content/public/browser/web_contents.h"
12
13 // static
14 BrowserPluginWebContentsObserver*
15 BrowserPluginWebContentsObserver::Create(
16 content::WebContents* web_contents) {
17 return new BrowserPluginWebContentsObserver(web_contents);
18 }
19
20 BrowserPluginWebContentsObserver::BrowserPluginWebContentsObserver(
21 content::WebContents* web_contents)
22 : WebContentsObserver(web_contents) {
23 registrar_.Add(this,
24 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
25 content::Source<content::RenderViewHost>(
26 web_contents->GetRenderViewHost()));
27 }
28
29 BrowserPluginWebContentsObserver::~BrowserPluginWebContentsObserver() {
30 }
31
32 void BrowserPluginWebContentsObserver::AddGuest(
33 content::WebContents* guest,
34 int64 frame_id) {
35 guests_[guest] = frame_id;
36 }
37
38 void BrowserPluginWebContentsObserver::RemoveGuest(
39 content::WebContents* guest) {
40 guests_.erase(guest);
41 }
42
43 void BrowserPluginWebContentsObserver::DestroyGuests() {
44 for (GuestMap::const_iterator it = guests_.begin();
45 it != guests_.end(); ++it) {
46 const content::WebContents* contents = it->first;
47 delete contents;
48 }
49 guests_.clear();
50 }
51
52 void BrowserPluginWebContentsObserver::DidCommitProvisionalLoadForFrame(
53 int64 frame_id,
54 bool is_main_frame,
55 const GURL& url,
56 content::PageTransition transition_type) {
57 GuestSet guests_to_delete;
58 for (GuestMap::const_iterator it = guests_.begin();
59 it != guests_.end(); ++it) {
60 content::WebContents* contents = it->first;
61 if (it->second == frame_id) {
62 guests_to_delete.insert(contents);
63 }
64 }
65 for (GuestSet::const_iterator it = guests_to_delete.begin();
66 it != guests_to_delete.end(); ++it) {
67 delete *it;
68 guests_.erase(*it);
69 }
70 }
71
72 void BrowserPluginWebContentsObserver::RenderViewDeleted(
73 content::RenderViewHost* render_view_host) {
74 DestroyGuests();
75 }
76
77 void BrowserPluginWebContentsObserver::RenderViewGone(
78 base::TerminationStatus status) {
79 DestroyGuests();
80 }
81
82 void BrowserPluginWebContentsObserver::WebContentsDestroyed(
83 content::WebContents* web_contents) {
84 DestroyGuests();
85 }
86
87 void BrowserPluginWebContentsObserver::Observe(
88 int type,
89 const content::NotificationSource& source,
90 const content::NotificationDetails& details) {
91 DCHECK(type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED);
92 bool visible = *content::Details<bool>(details).ptr();
93
94 // If the host is hidden we need to hide the guests as well.
95 for (GuestMap::const_iterator it = guests_.begin();
96 it != guests_.end(); ++it) {
97 content::WebContents* contents = it->first;
98 if (visible)
99 contents->ShowContents();
100 else
101 contents->HideContents();
102 }
103 }
104
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698