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

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

Issue 10082021: TabContents -> WebContentsImpl, part 13. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, fix references 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
« no previous file with comments | « no previous file | content/browser/renderer_host/render_view_host_manager_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_web_contents_observer.h" 5 #include "content/browser/browser_plugin/browser_plugin_web_contents_observer.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h" 8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/browser/web_contents/web_contents_impl.h" 9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/common/browser_plugin_messages.h" 10 #include "content/common/browser_plugin_messages.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/notification_details.h" 12 #include "content/public/browser/notification_details.h"
13 #include "content/public/browser/notification_source.h" 13 #include "content/public/browser/notification_source.h"
14 #include "content/public/browser/notification_types.h" 14 #include "content/public/browser/notification_types.h"
15 #include "content/public/browser/render_process_host.h" 15 #include "content/public/browser/render_process_host.h"
16 #include "content/public/browser/render_widget_host.h" 16 #include "content/public/browser/render_widget_host.h"
17 #include "content/public/browser/render_widget_host_view.h" 17 #include "content/public/browser/render_widget_host_view.h"
18 #include "content/public/browser/render_view_host.h" 18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/site_instance.h" 19 #include "content/public/browser/site_instance.h"
20 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 #include "ppapi/proxy/ppapi_messages.h" 21 #include "ppapi/proxy/ppapi_messages.h"
22 22
23 namespace content { 23 namespace content {
24 24
25 BrowserPluginWebContentsObserver::BrowserPluginWebContentsObserver( 25 BrowserPluginWebContentsObserver::BrowserPluginWebContentsObserver(
26 TabContents* tab_contents) 26 WebContentsImpl* web_contents)
27 : WebContentsObserver(tab_contents), 27 : WebContentsObserver(web_contents),
28 host_(NULL), 28 host_(NULL),
29 instance_id_(0) { 29 instance_id_(0) {
30 registrar_.Add(this, 30 registrar_.Add(this,
31 NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, 31 NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
32 Source<RenderViewHost>( 32 Source<RenderViewHost>(
33 tab_contents->GetRenderViewHost())); 33 web_contents->GetRenderViewHost()));
34 } 34 }
35 35
36 BrowserPluginWebContentsObserver::~BrowserPluginWebContentsObserver() { 36 BrowserPluginWebContentsObserver::~BrowserPluginWebContentsObserver() {
37 } 37 }
38 38
39 bool BrowserPluginWebContentsObserver::OnMessageReceived( 39 bool BrowserPluginWebContentsObserver::OnMessageReceived(
40 const IPC::Message& message) { 40 const IPC::Message& message) {
41 bool handled = true; 41 bool handled = true;
42 IPC_BEGIN_MESSAGE_MAP(BrowserPluginWebContentsObserver, message) 42 IPC_BEGIN_MESSAGE_MAP(BrowserPluginWebContentsObserver, message)
43 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ChannelCreated, 43 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ChannelCreated,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 const std::string& src, 82 const std::string& src,
83 const gfx::Size& size) { 83 const gfx::Size& size) {
84 BrowserContext* browser_context = 84 BrowserContext* browser_context =
85 web_contents()->GetRenderViewHost()->GetProcess()->GetBrowserContext(); 85 web_contents()->GetRenderViewHost()->GetProcess()->GetBrowserContext();
86 DCHECK(browser_context); 86 DCHECK(browser_context);
87 87
88 GURL url(src); 88 GURL url(src);
89 SiteInstance* site_instance = 89 SiteInstance* site_instance =
90 SiteInstance::CreateForURL( 90 SiteInstance::CreateForURL(
91 browser_context, url); 91 browser_context, url);
92 TabContents* guest_tab_contents = 92 WebContentsImpl* guest_web_contents =
93 static_cast<TabContents*>( 93 static_cast<WebContentsImpl*>(
94 WebContents::Create( 94 WebContents::Create(
95 browser_context, 95 browser_context,
96 site_instance, 96 site_instance,
97 MSG_ROUTING_NONE, 97 MSG_ROUTING_NONE,
98 NULL, // base tab contents 98 NULL, // base tab contents
99 NULL // session storage namespace 99 NULL // session storage namespace
100 )); 100 ));
101 // TODO(fsamuel): Set the WebContentsDelegate here. 101 // TODO(fsamuel): Set the WebContentsDelegate here.
102 RenderViewHostImpl* guest_render_view_host = 102 RenderViewHostImpl* guest_render_view_host =
103 static_cast<RenderViewHostImpl*>( 103 static_cast<RenderViewHostImpl*>(
104 guest_tab_contents->GetRenderViewHost()); 104 guest_web_contents->GetRenderViewHost());
105 105
106 // We need to make sure that the RenderViewHost knows that it's 106 // We need to make sure that the RenderViewHost knows that it's
107 // hosting a guest RenderView so that it informs the RenderView 107 // hosting a guest RenderView so that it informs the RenderView
108 // on a ViewMsg_New. Guest RenderViews will avoid compositing 108 // on a ViewMsg_New. Guest RenderViews will avoid compositing
109 // until a guest-to-host channel has been initialized. 109 // until a guest-to-host channel has been initialized.
110 guest_render_view_host->set_guest(true); 110 guest_render_view_host->set_guest(true);
111 111
112 guest_tab_contents->GetController().LoadURL( 112 guest_web_contents->GetController().LoadURL(
113 url, 113 url,
114 Referrer(), 114 Referrer(),
115 PAGE_TRANSITION_HOME_PAGE, 115 PAGE_TRANSITION_HOME_PAGE,
116 std::string()); 116 std::string());
117 117
118 guest_render_view_host->GetView()->SetSize(size); 118 guest_render_view_host->GetView()->SetSize(size);
119 BrowserPluginWebContentsObserver* guest_observer = 119 BrowserPluginWebContentsObserver* guest_observer =
120 guest_tab_contents->browser_plugin_web_contents_observer(); 120 guest_web_contents->browser_plugin_web_contents_observer();
121 guest_observer->set_host(static_cast<TabContents*>(web_contents())); 121 guest_observer->set_host(static_cast<WebContentsImpl*>(web_contents()));
122 guest_observer->set_instance_id(instance_id); 122 guest_observer->set_instance_id(instance_id);
123 123
124 AddGuest(guest_tab_contents, frame_id); 124 AddGuest(guest_web_contents, frame_id);
125 } 125 }
126 126
127 void BrowserPluginWebContentsObserver::OnRendererPluginChannelCreated( 127 void BrowserPluginWebContentsObserver::OnRendererPluginChannelCreated(
128 const IPC::ChannelHandle& channel_handle) { 128 const IPC::ChannelHandle& channel_handle) {
129 DCHECK(host()); 129 DCHECK(host());
130 // Prepare the handle to send to the renderer. 130 // Prepare the handle to send to the renderer.
131 base::ProcessHandle plugin_process = 131 base::ProcessHandle plugin_process =
132 web_contents()->GetRenderProcessHost()->GetHandle(); 132 web_contents()->GetRenderProcessHost()->GetHandle();
133 #if defined(OS_WIN) 133 #if defined(OS_WIN)
134 base::ProcessHandle renderer_process = 134 base::ProcessHandle renderer_process =
(...skipping 11 matching lines...) Expand all
146 // Tell the BrowserPLuginPlaceholder in the host that we're done 146 // Tell the BrowserPLuginPlaceholder in the host that we're done
147 // and that it can begin using the guest renderer. 147 // and that it can begin using the guest renderer.
148 host()->GetRenderProcessHost()->Send( 148 host()->GetRenderProcessHost()->Send(
149 new BrowserPluginMsg_GuestReady_ACK( 149 new BrowserPluginMsg_GuestReady_ACK(
150 host()->GetRenderViewHost()->GetRoutingID(), 150 host()->GetRenderViewHost()->GetRoutingID(),
151 instance_id(), 151 instance_id(),
152 renderers_plugin_handle, 152 renderers_plugin_handle,
153 channel_handle)); 153 channel_handle));
154 } 154 }
155 155
156 void BrowserPluginWebContentsObserver::AddGuest( 156 void BrowserPluginWebContentsObserver::AddGuest(WebContentsImpl* guest,
157 TabContents* guest, 157 int64 frame_id) {
158 int64 frame_id) {
159 guests_[guest] = frame_id; 158 guests_[guest] = frame_id;
160 } 159 }
161 160
162 void BrowserPluginWebContentsObserver::RemoveGuest(TabContents* guest) { 161 void BrowserPluginWebContentsObserver::RemoveGuest(WebContentsImpl* guest) {
163 guests_.erase(guest); 162 guests_.erase(guest);
164 } 163 }
165 164
166 void BrowserPluginWebContentsObserver::DestroyGuests() { 165 void BrowserPluginWebContentsObserver::DestroyGuests() {
167 for (GuestMap::const_iterator it = guests_.begin(); 166 for (GuestMap::const_iterator it = guests_.begin();
168 it != guests_.end(); ++it) { 167 it != guests_.end(); ++it) {
169 const TabContents* contents = it->first; 168 const WebContentsImpl* web_contents = it->first;
170 delete contents; 169 delete web_contents;
171 } 170 }
172 guests_.clear(); 171 guests_.clear();
173 } 172 }
174 173
175 void BrowserPluginWebContentsObserver::DidCommitProvisionalLoadForFrame( 174 void BrowserPluginWebContentsObserver::DidCommitProvisionalLoadForFrame(
176 int64 frame_id, 175 int64 frame_id,
177 bool is_main_frame, 176 bool is_main_frame,
178 const GURL& url, 177 const GURL& url,
179 PageTransition transition_type) { 178 PageTransition transition_type) {
180 typedef std::set<TabContents*> GuestSet; 179 typedef std::set<WebContentsImpl*> GuestSet;
181 GuestSet guests_to_delete; 180 GuestSet guests_to_delete;
182 for (GuestMap::const_iterator it = guests_.begin(); 181 for (GuestMap::const_iterator it = guests_.begin();
183 it != guests_.end(); ++it) { 182 it != guests_.end(); ++it) {
184 TabContents* contents = it->first; 183 WebContentsImpl* web_contents = it->first;
185 if (it->second == frame_id) { 184 if (it->second == frame_id) {
186 guests_to_delete.insert(contents); 185 guests_to_delete.insert(web_contents);
187 } 186 }
188 } 187 }
189 for (GuestSet::const_iterator it = guests_to_delete.begin(); 188 for (GuestSet::const_iterator it = guests_to_delete.begin();
190 it != guests_to_delete.end(); ++it) { 189 it != guests_to_delete.end(); ++it) {
191 delete *it; 190 delete *it;
192 guests_.erase(*it); 191 guests_.erase(*it);
193 } 192 }
194 } 193 }
195 194
196 void BrowserPluginWebContentsObserver::RenderViewDeleted( 195 void BrowserPluginWebContentsObserver::RenderViewDeleted(
(...skipping 14 matching lines...) Expand all
211 void BrowserPluginWebContentsObserver::Observe( 210 void BrowserPluginWebContentsObserver::Observe(
212 int type, 211 int type,
213 const NotificationSource& source, 212 const NotificationSource& source,
214 const NotificationDetails& details) { 213 const NotificationDetails& details) {
215 DCHECK(type == NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED); 214 DCHECK(type == NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED);
216 bool visible = *Details<bool>(details).ptr(); 215 bool visible = *Details<bool>(details).ptr();
217 216
218 // If the host is hidden we need to hide the guests as well. 217 // If the host is hidden we need to hide the guests as well.
219 for (GuestMap::const_iterator it = guests_.begin(); 218 for (GuestMap::const_iterator it = guests_.begin();
220 it != guests_.end(); ++it) { 219 it != guests_.end(); ++it) {
221 TabContents* contents = it->first; 220 WebContentsImpl* web_contents = it->first;
222 if (visible) 221 if (visible)
223 contents->ShowContents(); 222 web_contents->ShowContents();
224 else 223 else
225 contents->HideContents(); 224 web_contents->HideContents();
226 } 225 }
227 } 226 }
228 227
229 } // namespace content 228 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/render_view_host_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698