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

Side by Side Diff: content/browser/web_contents/web_contents_view_helper.cc

Issue 10031044: TabContents -> WebContentsImpl, part 5. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase (fixed) 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
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/tab_contents/tab_contents_view_helper.h" 5 #include "content/browser/web_contents/web_contents_view_helper.h"
6 6
7 #include "content/browser/renderer_host/render_view_host_impl.h" 7 #include "content/browser/renderer_host/render_view_host_impl.h"
8 #include "content/browser/tab_contents/tab_contents.h" 8 #include "content/browser/tab_contents/tab_contents.h"
9 #include "content/common/view_messages.h" 9 #include "content/common/view_messages.h"
10 #include "content/port/browser/render_widget_host_view_port.h" 10 #include "content/port/browser/render_widget_host_view_port.h"
11 #include "content/public/browser/notification_service.h" 11 #include "content/public/browser/notification_service.h"
12 #include "content/public/browser/notification_source.h" 12 #include "content/public/browser/notification_source.h"
13 #include "content/public/browser/notification_types.h" 13 #include "content/public/browser/notification_types.h"
14 #include "content/public/browser/site_instance.h" 14 #include "content/public/browser/site_instance.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_delegate.h" 16 #include "content/public/browser/web_contents_delegate.h"
17 #include "content/public/browser/web_contents_view.h" 17 #include "content/public/browser/web_contents_view.h"
18 18
19 using content::RenderViewHostImpl; 19 using content::RenderViewHostImpl;
20 using content::RenderWidgetHost; 20 using content::RenderWidgetHost;
21 using content::RenderWidgetHostImpl; 21 using content::RenderWidgetHostImpl;
22 using content::RenderWidgetHostView; 22 using content::RenderWidgetHostView;
23 using content::RenderWidgetHostViewPort; 23 using content::RenderWidgetHostViewPort;
24 using content::WebContents; 24 using content::WebContents;
25 25
26 TabContentsViewHelper::TabContentsViewHelper() { 26 WebContentsViewHelper::WebContentsViewHelper() {
27 registrar_.Add(this, 27 registrar_.Add(this,
28 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, 28 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
29 content::NotificationService::AllBrowserContextsAndSources()); 29 content::NotificationService::AllBrowserContextsAndSources());
30 } 30 }
31 31
32 TabContentsViewHelper::~TabContentsViewHelper() {} 32 WebContentsViewHelper::~WebContentsViewHelper() {}
33 33
34 void TabContentsViewHelper::Observe( 34 void WebContentsViewHelper::Observe(
35 int type, 35 int type,
36 const content::NotificationSource& source, 36 const content::NotificationSource& source,
37 const content::NotificationDetails& details) { 37 const content::NotificationDetails& details) {
38 DCHECK_EQ(type, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED); 38 DCHECK_EQ(type, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED);
39 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr(); 39 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
40 for (PendingWidgetViews::iterator i = pending_widget_views_.begin(); 40 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
41 i != pending_widget_views_.end(); ++i) { 41 i != pending_widget_views_.end(); ++i) {
42 if (host->GetView() == i->second) { 42 if (host->GetView() == i->second) {
43 pending_widget_views_.erase(i); 43 pending_widget_views_.erase(i);
44 break; 44 break;
45 } 45 }
46 } 46 }
47 } 47 }
48 48
49 TabContents* TabContentsViewHelper::CreateNewWindow( 49 TabContents* WebContentsViewHelper::CreateNewWindow(
50 WebContents* web_contents, 50 WebContents* web_contents,
51 int route_id, 51 int route_id,
52 const ViewHostMsg_CreateWindow_Params& params) { 52 const ViewHostMsg_CreateWindow_Params& params) {
53 bool should_create = true; 53 bool should_create = true;
54 if (web_contents->GetDelegate()) { 54 if (web_contents->GetDelegate()) {
55 should_create = web_contents->GetDelegate()->ShouldCreateWebContents( 55 should_create = web_contents->GetDelegate()->ShouldCreateWebContents(
56 web_contents, 56 web_contents,
57 route_id, 57 route_id,
58 params.window_container_type, 58 params.window_container_type,
59 params.frame_name, 59 params.frame_name,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 content::OpenURLParams open_params(params.target_url, content::Referrer(), 115 content::OpenURLParams open_params(params.target_url, content::Referrer(),
116 CURRENT_TAB, 116 CURRENT_TAB,
117 content::PAGE_TRANSITION_LINK, 117 content::PAGE_TRANSITION_LINK,
118 true /* is_renderer_initiated */); 118 true /* is_renderer_initiated */);
119 new_contents->OpenURL(open_params); 119 new_contents->OpenURL(open_params);
120 } 120 }
121 121
122 return new_contents; 122 return new_contents;
123 } 123 }
124 124
125 RenderWidgetHostView* TabContentsViewHelper::CreateNewWidget( 125 RenderWidgetHostView* WebContentsViewHelper::CreateNewWidget(
126 WebContents* web_contents, 126 WebContents* web_contents,
127 int route_id, 127 int route_id,
128 bool is_fullscreen, 128 bool is_fullscreen,
129 WebKit::WebPopupType popup_type) { 129 WebKit::WebPopupType popup_type) {
130 content::RenderProcessHost* process = web_contents->GetRenderProcessHost(); 130 content::RenderProcessHost* process = web_contents->GetRenderProcessHost();
131 RenderWidgetHostImpl* widget_host = 131 RenderWidgetHostImpl* widget_host =
132 new RenderWidgetHostImpl(process, route_id); 132 new RenderWidgetHostImpl(process, route_id);
133 RenderWidgetHostViewPort* widget_view = 133 RenderWidgetHostViewPort* widget_view =
134 RenderWidgetHostViewPort::CreateViewForWidget(widget_host); 134 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
135 if (!is_fullscreen) { 135 if (!is_fullscreen) {
136 // Popups should not get activated. 136 // Popups should not get activated.
137 widget_view->SetPopupType(popup_type); 137 widget_view->SetPopupType(popup_type);
138 } 138 }
139 // Save the created widget associated with the route so we can show it later. 139 // Save the created widget associated with the route so we can show it later.
140 pending_widget_views_[route_id] = widget_view; 140 pending_widget_views_[route_id] = widget_view;
141 return widget_view; 141 return widget_view;
142 } 142 }
143 143
144 TabContents* TabContentsViewHelper::GetCreatedWindow(int route_id) { 144 TabContents* WebContentsViewHelper::GetCreatedWindow(int route_id) {
145 PendingContents::iterator iter = pending_contents_.find(route_id); 145 PendingContents::iterator iter = pending_contents_.find(route_id);
146 146
147 // Certain systems can block the creation of new windows. If we didn't succeed 147 // Certain systems can block the creation of new windows. If we didn't succeed
148 // in creating one, just return NULL. 148 // in creating one, just return NULL.
149 if (iter == pending_contents_.end()) { 149 if (iter == pending_contents_.end()) {
150 return NULL; 150 return NULL;
151 } 151 }
152 152
153 TabContents* new_contents = iter->second; 153 TabContents* new_contents = iter->second;
154 pending_contents_.erase(route_id); 154 pending_contents_.erase(route_id);
155 155
156 if (!new_contents->GetRenderProcessHost()->HasConnection() || 156 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
157 !new_contents->GetRenderViewHost()->GetView()) 157 !new_contents->GetRenderViewHost()->GetView())
158 return NULL; 158 return NULL;
159 159
160 // TODO(brettw): It seems bogus to reach into here and initialize the host. 160 // TODO(brettw): It seems bogus to reach into here and initialize the host.
161 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init(); 161 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
162 return new_contents; 162 return new_contents;
163 } 163 }
164 164
165 RenderWidgetHostView* TabContentsViewHelper::GetCreatedWidget(int route_id) { 165 RenderWidgetHostView* WebContentsViewHelper::GetCreatedWidget(int route_id) {
166 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id); 166 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
167 if (iter == pending_widget_views_.end()) { 167 if (iter == pending_widget_views_.end()) {
168 DCHECK(false); 168 DCHECK(false);
169 return NULL; 169 return NULL;
170 } 170 }
171 171
172 RenderWidgetHostView* widget_host_view = iter->second; 172 RenderWidgetHostView* widget_host_view = iter->second;
173 pending_widget_views_.erase(route_id); 173 pending_widget_views_.erase(route_id);
174 174
175 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost(); 175 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
176 if (!widget_host->GetProcess()->HasConnection()) { 176 if (!widget_host->GetProcess()->HasConnection()) {
177 // The view has gone away or the renderer crashed. Nothing to do. 177 // The view has gone away or the renderer crashed. Nothing to do.
178 return NULL; 178 return NULL;
179 } 179 }
180 180
181 return widget_host_view; 181 return widget_host_view;
182 } 182 }
183 183
184 TabContents* TabContentsViewHelper::ShowCreatedWindow( 184 TabContents* WebContentsViewHelper::ShowCreatedWindow(
185 WebContents* web_contents, 185 WebContents* web_contents,
186 int route_id, 186 int route_id,
187 WindowOpenDisposition disposition, 187 WindowOpenDisposition disposition,
188 const gfx::Rect& initial_pos, 188 const gfx::Rect& initial_pos,
189 bool user_gesture) { 189 bool user_gesture) {
190 TabContents* contents = GetCreatedWindow(route_id); 190 TabContents* contents = GetCreatedWindow(route_id);
191 if (contents) { 191 if (contents) {
192 web_contents->AddNewContents(contents, 192 web_contents->AddNewContents(contents,
193 disposition, 193 disposition,
194 initial_pos, 194 initial_pos,
195 user_gesture); 195 user_gesture);
196 } 196 }
197 return contents; 197 return contents;
198 } 198 }
199 199
200 RenderWidgetHostView* TabContentsViewHelper::ShowCreatedWidget( 200 RenderWidgetHostView* WebContentsViewHelper::ShowCreatedWidget(
201 WebContents* web_contents, 201 WebContents* web_contents,
202 int route_id, 202 int route_id,
203 bool is_fullscreen, 203 bool is_fullscreen,
204 const gfx::Rect& initial_pos) { 204 const gfx::Rect& initial_pos) {
205 if (web_contents->GetDelegate()) 205 if (web_contents->GetDelegate())
206 web_contents->GetDelegate()->RenderWidgetShowing(); 206 web_contents->GetDelegate()->RenderWidgetShowing();
207 207
208 RenderWidgetHostViewPort* widget_host_view = 208 RenderWidgetHostViewPort* widget_host_view =
209 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id)); 209 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
210 if (is_fullscreen) { 210 if (is_fullscreen) {
211 widget_host_view->InitAsFullscreen(web_contents->GetRenderWidgetHostView()); 211 widget_host_view->InitAsFullscreen(web_contents->GetRenderWidgetHostView());
212 } else { 212 } else {
213 widget_host_view->InitAsPopup(web_contents->GetRenderWidgetHostView(), 213 widget_host_view->InitAsPopup(web_contents->GetRenderWidgetHostView(),
214 initial_pos); 214 initial_pos);
215 } 215 }
216 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost())->Init(); 216 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost())->Init();
217 return widget_host_view; 217 return widget_host_view;
218 } 218 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698