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

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

Issue 10038026: TabContents -> WebContentsImpl, part 12. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/web_contents/interstitial_page_impl.h" 5 #include "content/browser/web_contents/interstitial_page_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 private: 120 private:
121 InterstitialPageImpl* interstitial_page_; 121 InterstitialPageImpl* interstitial_page_;
122 122
123 DISALLOW_COPY_AND_ASSIGN(InterstitialPageRVHViewDelegate); 123 DISALLOW_COPY_AND_ASSIGN(InterstitialPageRVHViewDelegate);
124 }; 124 };
125 125
126 126
127 // We keep a map of the various blocking pages shown as the UI tests need to 127 // We keep a map of the various blocking pages shown as the UI tests need to
128 // be able to retrieve them. 128 // be able to retrieve them.
129 typedef std::map<WebContents*, InterstitialPageImpl*> InterstitialPageMap; 129 typedef std::map<WebContents*, InterstitialPageImpl*> InterstitialPageMap;
130 static InterstitialPageMap* g_tab_to_interstitial_page; 130 static InterstitialPageMap* g_contents_to_interstitial_page;
jam 2012/04/13 18:23:21 ditto
131 131
132 // Initializes g_tab_to_interstitial_page in a thread-safe manner. 132 // Initializes g_contents_to_interstitial_page in a thread-safe manner.
133 // Should be called before accessing g_tab_to_interstitial_page. 133 // Should be called before accessing g_contents_to_interstitial_page.
134 static void InitInterstitialPageMap() { 134 static void InitInterstitialPageMap() {
135 if (!g_tab_to_interstitial_page) 135 if (!g_contents_to_interstitial_page)
136 g_tab_to_interstitial_page = new InterstitialPageMap; 136 g_contents_to_interstitial_page = new InterstitialPageMap;
137 } 137 }
138 138
139 namespace content { 139 namespace content {
140 140
141 InterstitialPage* InterstitialPage::Create(WebContents* tab, 141 InterstitialPage* InterstitialPage::Create(WebContents* tab,
142 bool new_navigation, 142 bool new_navigation,
143 const GURL& url, 143 const GURL& url,
144 InterstitialPageDelegate* delegate) { 144 InterstitialPageDelegate* delegate) {
145 return new InterstitialPageImpl(tab, new_navigation, url, delegate); 145 return new InterstitialPageImpl(tab, new_navigation, url, delegate);
146 } 146 }
147 147
148 InterstitialPage* InterstitialPage::GetInterstitialPage( 148 InterstitialPage* InterstitialPage::GetInterstitialPage(
149 WebContents* web_contents) { 149 WebContents* web_contents) {
150 InitInterstitialPageMap(); 150 InitInterstitialPageMap();
151 InterstitialPageMap::const_iterator iter = 151 InterstitialPageMap::const_iterator iter =
152 g_tab_to_interstitial_page->find(web_contents); 152 g_contents_to_interstitial_page->find(web_contents);
153 if (iter == g_tab_to_interstitial_page->end()) 153 if (iter == g_contents_to_interstitial_page->end())
154 return NULL; 154 return NULL;
155 155
156 return iter->second; 156 return iter->second;
157 } 157 }
158 158
159 } // namespace content 159 } // namespace content
160 160
161 InterstitialPageImpl::InterstitialPageImpl(WebContents* tab, 161 InterstitialPageImpl::InterstitialPageImpl(WebContents* web_contents,
162 bool new_navigation, 162 bool new_navigation,
163 const GURL& url, 163 const GURL& url,
164 InterstitialPageDelegate* delegate) 164 InterstitialPageDelegate* delegate)
165 : tab_(static_cast<TabContents*>(tab)), 165 : web_contents_(static_cast<WebContentsImpl*>(web_contents)),
166 url_(url), 166 url_(url),
167 new_navigation_(new_navigation), 167 new_navigation_(new_navigation),
168 should_discard_pending_nav_entry_(new_navigation), 168 should_discard_pending_nav_entry_(new_navigation),
169 reload_on_dont_proceed_(false), 169 reload_on_dont_proceed_(false),
170 enabled_(true), 170 enabled_(true),
171 action_taken_(NO_ACTION), 171 action_taken_(NO_ACTION),
172 render_view_host_(NULL), 172 render_view_host_(NULL),
173 original_child_id_(tab->GetRenderProcessHost()->GetID()), 173 original_child_id_(web_contents->GetRenderProcessHost()->GetID()),
174 original_rvh_id_(tab->GetRenderViewHost()->GetRoutingID()), 174 original_rvh_id_(web_contents->GetRenderViewHost()->GetRoutingID()),
175 should_revert_tab_title_(false), 175 should_revert_contents_title_(false),
176 tab_was_loading_(false), 176 contents_was_loading_(false),
177 resource_dispatcher_host_notified_(false), 177 resource_dispatcher_host_notified_(false),
178 ALLOW_THIS_IN_INITIALIZER_LIST(rvh_view_delegate_( 178 ALLOW_THIS_IN_INITIALIZER_LIST(rvh_view_delegate_(
179 new InterstitialPageRVHViewDelegate(this))), 179 new InterstitialPageRVHViewDelegate(this))),
180 create_view_(true), 180 create_view_(true),
181 delegate_(delegate) { 181 delegate_(delegate) {
182 InitInterstitialPageMap(); 182 InitInterstitialPageMap();
183 // It would be inconsistent to create an interstitial with no new navigation 183 // It would be inconsistent to create an interstitial with no new navigation
184 // (which is the case when the interstitial was triggered by a sub-resource on 184 // (which is the case when the interstitial was triggered by a sub-resource on
185 // a page) when we have a pending entry (in the process of loading a new top 185 // a page) when we have a pending entry (in the process of loading a new top
186 // frame). 186 // frame).
187 DCHECK(new_navigation || !tab->GetController().GetPendingEntry()); 187 DCHECK(new_navigation || !web_contents->GetController().GetPendingEntry());
188 } 188 }
189 189
190 InterstitialPageImpl::~InterstitialPageImpl() { 190 InterstitialPageImpl::~InterstitialPageImpl() {
191 } 191 }
192 192
193 void InterstitialPageImpl::Show() { 193 void InterstitialPageImpl::Show() {
194 // If an interstitial is already showing or about to be shown, close it before 194 // If an interstitial is already showing or about to be shown, close it before
195 // showing the new one. 195 // showing the new one.
196 // Be careful not to take an action on the old interstitial more than once. 196 // Be careful not to take an action on the old interstitial more than once.
197 InterstitialPageMap::const_iterator iter = 197 InterstitialPageMap::const_iterator iter =
198 g_tab_to_interstitial_page->find(tab_); 198 g_contents_to_interstitial_page->find(web_contents_);
199 if (iter != g_tab_to_interstitial_page->end()) { 199 if (iter != g_contents_to_interstitial_page->end()) {
200 InterstitialPageImpl* interstitial = iter->second; 200 InterstitialPageImpl* interstitial = iter->second;
201 if (interstitial->action_taken_ != NO_ACTION) { 201 if (interstitial->action_taken_ != NO_ACTION) {
202 interstitial->Hide(); 202 interstitial->Hide();
203 delete interstitial; 203 delete interstitial;
204 } else { 204 } else {
205 // If we are currently showing an interstitial page for which we created 205 // If we are currently showing an interstitial page for which we created
206 // a transient entry and a new interstitial is shown as the result of a 206 // a transient entry and a new interstitial is shown as the result of a
207 // new browser initiated navigation, then that transient entry has already 207 // new browser initiated navigation, then that transient entry has already
208 // been discarded and a new pending navigation entry created. 208 // been discarded and a new pending navigation entry created.
209 // So we should not discard that new pending navigation entry. 209 // So we should not discard that new pending navigation entry.
210 // See http://crbug.com/9791 210 // See http://crbug.com/9791
211 if (new_navigation_ && interstitial->new_navigation_) 211 if (new_navigation_ && interstitial->new_navigation_)
212 interstitial->should_discard_pending_nav_entry_= false; 212 interstitial->should_discard_pending_nav_entry_= false;
213 interstitial->DontProceed(); 213 interstitial->DontProceed();
214 } 214 }
215 } 215 }
216 216
217 // Block the resource requests for the render view host while it is hidden. 217 // Block the resource requests for the render view host while it is hidden.
218 TakeActionOnResourceDispatcher(BLOCK); 218 TakeActionOnResourceDispatcher(BLOCK);
219 // We need to be notified when the RenderViewHost is destroyed so we can 219 // We need to be notified when the RenderViewHost is destroyed so we can
220 // cancel the blocked requests. We cannot do that on 220 // cancel the blocked requests. We cannot do that on
221 // NOTIFY_TAB_CONTENTS_DESTROYED as at that point the RenderViewHost has 221 // NOTIFY_WEB_CONTENTS_DESTROYED as at that point the RenderViewHost has
222 // already been destroyed. 222 // already been destroyed.
223 notification_registrar_.Add( 223 notification_registrar_.Add(
224 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, 224 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
225 content::Source<RenderWidgetHost>(tab_->GetRenderViewHost())); 225 content::Source<RenderWidgetHost>(web_contents_->GetRenderViewHost()));
226 226
227 // Update the g_tab_to_interstitial_page map. 227 // Update the g_contents_to_interstitial_page map.
228 iter = g_tab_to_interstitial_page->find(tab_); 228 iter = g_contents_to_interstitial_page->find(web_contents_);
229 DCHECK(iter == g_tab_to_interstitial_page->end()); 229 DCHECK(iter == g_contents_to_interstitial_page->end());
230 (*g_tab_to_interstitial_page)[tab_] = this; 230 (*g_contents_to_interstitial_page)[web_contents_] = this;
231 231
232 if (new_navigation_) { 232 if (new_navigation_) {
233 NavigationEntryImpl* entry = new NavigationEntryImpl; 233 NavigationEntryImpl* entry = new NavigationEntryImpl;
234 entry->SetURL(url_); 234 entry->SetURL(url_);
235 entry->SetVirtualURL(url_); 235 entry->SetVirtualURL(url_);
236 entry->set_page_type(content::PAGE_TYPE_INTERSTITIAL); 236 entry->set_page_type(content::PAGE_TYPE_INTERSTITIAL);
237 237
238 // Give delegates a chance to set some states on the navigation entry. 238 // Give delegates a chance to set some states on the navigation entry.
239 delegate_->OverrideEntry(entry); 239 delegate_->OverrideEntry(entry);
240 240
241 tab_->GetControllerImpl().AddTransientEntry(entry); 241 web_contents_->GetControllerImpl().AddTransientEntry(entry);
242 } 242 }
243 243
244 DCHECK(!render_view_host_); 244 DCHECK(!render_view_host_);
245 render_view_host_ = static_cast<RenderViewHostImpl*>(CreateRenderViewHost()); 245 render_view_host_ = static_cast<RenderViewHostImpl*>(CreateRenderViewHost());
246 CreateWebContentsView(); 246 CreateWebContentsView();
247 247
248 std::string data_url = "data:text/html;charset=utf-8," + 248 std::string data_url = "data:text/html;charset=utf-8," +
249 net::EscapePath(delegate_->GetHTMLContents()); 249 net::EscapePath(delegate_->GetHTMLContents());
250 render_view_host_->NavigateToURL(GURL(data_url)); 250 render_view_host_->NavigateToURL(GURL(data_url));
251 251
252 notification_registrar_.Add(this, 252 notification_registrar_.Add(this,
253 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 253 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
254 content::Source<WebContents>(tab_)); 254 content::Source<WebContents>(web_contents_));
255 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 255 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
256 content::Source<NavigationController>(&tab_->GetController())); 256 content::Source<NavigationController>(&web_contents_->GetController()));
257 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, 257 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
258 content::Source<NavigationController>(&tab_->GetController())); 258 content::Source<NavigationController>(&web_contents_->GetController()));
259 notification_registrar_.Add( 259 notification_registrar_.Add(
260 this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, 260 this, content::NOTIFICATION_DOM_OPERATION_RESPONSE,
261 content::Source<RenderViewHost>(render_view_host_)); 261 content::Source<RenderViewHost>(render_view_host_));
262 } 262 }
263 263
264 void InterstitialPageImpl::Hide() { 264 void InterstitialPageImpl::Hide() {
265 RenderWidgetHostView* old_view = tab_->GetRenderViewHost()->GetView(); 265 RenderWidgetHostView* old_view =
266 if (tab_->GetInterstitialPage() == this && 266 web_contents_->GetRenderViewHost()->GetView();
267 if (web_contents_->GetInterstitialPage() == this &&
267 old_view && !old_view->IsShowing()) { 268 old_view && !old_view->IsShowing()) {
268 // Show the original RVH since we're going away. Note it might not exist if 269 // Show the original RVH since we're going away. Note it might not exist if
269 // the renderer crashed while the interstitial was showing. 270 // the renderer crashed while the interstitial was showing.
270 // Note that it is important that we don't call Show() if the view is 271 // Note that it is important that we don't call Show() if the view is
271 // already showing. That would result in bad things (unparented HWND on 272 // already showing. That would result in bad things (unparented HWND on
272 // Windows for example) happening. 273 // Windows for example) happening.
273 old_view->Show(); 274 old_view->Show();
274 } 275 }
275 276
276 // If the focus was on the interstitial, let's keep it to the page. 277 // If the focus was on the interstitial, let's keep it to the page.
277 // (Note that in unit-tests the RVH may not have a view). 278 // (Note that in unit-tests the RVH may not have a view).
278 if (render_view_host_->GetView() && 279 if (render_view_host_->GetView() &&
279 render_view_host_->GetView()->HasFocus() && 280 render_view_host_->GetView()->HasFocus() &&
280 tab_->GetRenderViewHost()->GetView()) { 281 web_contents_->GetRenderViewHost()->GetView()) {
281 RenderWidgetHostViewPort::FromRWHV( 282 RenderWidgetHostViewPort::FromRWHV(
282 tab_->GetRenderViewHost()->GetView())->Focus(); 283 web_contents_->GetRenderViewHost()->GetView())->Focus();
283 } 284 }
284 285
285 render_view_host_->Shutdown(); 286 render_view_host_->Shutdown();
286 render_view_host_ = NULL; 287 render_view_host_ = NULL;
287 if (tab_->GetInterstitialPage()) 288 if (web_contents_->GetInterstitialPage())
288 tab_->remove_interstitial_page(); 289 web_contents_->remove_interstitial_page();
289 // Let's revert to the original title if necessary. 290 // Let's revert to the original title if necessary.
290 NavigationEntry* entry = tab_->GetController().GetActiveEntry(); 291 NavigationEntry* entry = web_contents_->GetController().GetActiveEntry();
291 if (!new_navigation_ && should_revert_tab_title_) { 292 if (!new_navigation_ && should_revert_contents_title_) {
292 entry->SetTitle(original_tab_title_); 293 entry->SetTitle(original_contents_title_);
293 tab_->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE); 294 web_contents_->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
294 } 295 }
295 296
296 content::NotificationService::current()->Notify( 297 content::NotificationService::current()->Notify(
297 content::NOTIFICATION_INTERSTITIAL_DETACHED, 298 content::NOTIFICATION_INTERSTITIAL_DETACHED,
298 content::Source<WebContents>(tab_), 299 content::Source<WebContents>(web_contents_),
299 content::NotificationService::NoDetails()); 300 content::NotificationService::NoDetails());
300 301
301 InterstitialPageMap::iterator iter = g_tab_to_interstitial_page->find(tab_); 302 InterstitialPageMap::iterator iter =
302 DCHECK(iter != g_tab_to_interstitial_page->end()); 303 g_contents_to_interstitial_page->find(web_contents_);
303 if (iter != g_tab_to_interstitial_page->end()) 304 DCHECK(iter != g_contents_to_interstitial_page->end());
304 g_tab_to_interstitial_page->erase(iter); 305 if (iter != g_contents_to_interstitial_page->end())
306 g_contents_to_interstitial_page->erase(iter);
305 } 307 }
306 308
307 void InterstitialPageImpl::Observe( 309 void InterstitialPageImpl::Observe(
308 int type, 310 int type,
309 const content::NotificationSource& source, 311 const content::NotificationSource& source,
310 const content::NotificationDetails& details) { 312 const content::NotificationDetails& details) {
311 switch (type) { 313 switch (type) {
312 case content::NOTIFICATION_NAV_ENTRY_PENDING: 314 case content::NOTIFICATION_NAV_ENTRY_PENDING:
313 // We are navigating away from the interstitial (the user has typed a URL 315 // We are navigating away from the interstitial (the user has typed a URL
314 // in the location bar or clicked a bookmark). Make sure clicking on the 316 // in the location bar or clicked a bookmark). Make sure clicking on the
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 DontProceed(); 390 DontProceed();
389 return; 391 return;
390 } 392 }
391 if (params.transition == content::PAGE_TRANSITION_AUTO_SUBFRAME) { 393 if (params.transition == content::PAGE_TRANSITION_AUTO_SUBFRAME) {
392 // No need to handle navigate message from iframe in the interstitial page. 394 // No need to handle navigate message from iframe in the interstitial page.
393 return; 395 return;
394 } 396 }
395 397
396 // The RenderViewHost has loaded its contents, we can show it now. 398 // The RenderViewHost has loaded its contents, we can show it now.
397 render_view_host_->GetView()->Show(); 399 render_view_host_->GetView()->Show();
398 tab_->set_interstitial_page(this); 400 web_contents_->set_interstitial_page(this);
399 401
400 // This notification hides the bookmark bar. Note that this has to happen 402 // This notification hides the bookmark bar. Note that this has to happen
401 // after the interstitial page was registered with |tab_|, since there will be 403 // after the interstitial page was registered with |contents_|, since there
402 // a callback to |tab_| testing if an interstitial page is showing before 404 // will be a callback to |contents_| testing if an interstitial page is
403 // hiding the bookmark bar. 405 // showing before hiding the bookmark bar.
404 content::NotificationService::current()->Notify( 406 content::NotificationService::current()->Notify(
405 content::NOTIFICATION_INTERSTITIAL_ATTACHED, 407 content::NOTIFICATION_INTERSTITIAL_ATTACHED,
406 content::Source<WebContents>(tab_), 408 content::Source<WebContents>(web_contents_),
407 content::NotificationService::NoDetails()); 409 content::NotificationService::NoDetails());
408 410
409 RenderWidgetHostView* rwh_view = tab_->GetRenderViewHost()->GetView(); 411 RenderWidgetHostView* rwh_view =
412 web_contents_->GetRenderViewHost()->GetView();
410 413
411 // The RenderViewHost may already have crashed before we even get here. 414 // The RenderViewHost may already have crashed before we even get here.
412 if (rwh_view) { 415 if (rwh_view) {
413 // If the page has focus, focus the interstitial. 416 // If the page has focus, focus the interstitial.
414 if (rwh_view->HasFocus()) 417 if (rwh_view->HasFocus())
415 Focus(); 418 Focus();
416 419
417 // Hide the original RVH since we're showing the interstitial instead. 420 // Hide the original RVH since we're showing the interstitial instead.
418 rwh_view->Hide(); 421 rwh_view->Hide();
419 } 422 }
420 423
421 // Notify the tab we are not loading so the throbber is stopped. It also 424 // Notify the tab we are not loading so the throbber is stopped. It also
422 // causes a NOTIFY_LOAD_STOP notification, that the AutomationProvider (used 425 // causes a NOTIFY_LOAD_STOP notification, that the AutomationProvider (used
423 // by the UI tests) expects to consider a navigation as complete. Without 426 // by the UI tests) expects to consider a navigation as complete. Without
424 // this, navigating in a UI test to a URL that triggers an interstitial would 427 // this, navigating in a UI test to a URL that triggers an interstitial would
425 // hang. 428 // hang.
426 tab_was_loading_ = tab_->IsLoading(); 429 contents_was_loading_ = web_contents_->IsLoading();
427 tab_->SetIsLoading(false, NULL); 430 web_contents_->SetIsLoading(false, NULL);
428 } 431 }
429 432
430 void InterstitialPageImpl::UpdateTitle( 433 void InterstitialPageImpl::UpdateTitle(
431 RenderViewHost* render_view_host, 434 RenderViewHost* render_view_host,
432 int32 page_id, 435 int32 page_id,
433 const string16& title, 436 const string16& title,
434 base::i18n::TextDirection title_direction) { 437 base::i18n::TextDirection title_direction) {
435 DCHECK(render_view_host == render_view_host_); 438 DCHECK(render_view_host == render_view_host_);
436 NavigationEntry* entry = tab_->GetController().GetActiveEntry(); 439 NavigationEntry* entry = web_contents_->GetController().GetActiveEntry();
437 if (!entry) { 440 if (!entry) {
438 // Crash reports from the field indicate this can be NULL. 441 // Crash reports from the field indicate this can be NULL.
439 // This is unexpected as InterstitialPages constructed with the 442 // This is unexpected as InterstitialPages constructed with the
440 // new_navigation flag set to true create a transient navigation entry 443 // new_navigation flag set to true create a transient navigation entry
441 // (that is returned as the active entry). And the only case so far of 444 // (that is returned as the active entry). And the only case so far of
442 // interstitial created with that flag set to false is with the 445 // interstitial created with that flag set to false is with the
443 // SafeBrowsingBlockingPage, when the resource triggering the interstitial 446 // SafeBrowsingBlockingPage, when the resource triggering the interstitial
444 // is a sub-resource, meaning the main page has already been loaded and a 447 // is a sub-resource, meaning the main page has already been loaded and a
445 // navigation entry should have been created. 448 // navigation entry should have been created.
446 NOTREACHED(); 449 NOTREACHED();
447 return; 450 return;
448 } 451 }
449 452
450 // If this interstitial is shown on an existing navigation entry, we'll need 453 // If this interstitial is shown on an existing navigation entry, we'll need
451 // to remember its title so we can revert to it when hidden. 454 // to remember its title so we can revert to it when hidden.
452 if (!new_navigation_ && !should_revert_tab_title_) { 455 if (!new_navigation_ && !should_revert_contents_title_) {
453 original_tab_title_ = entry->GetTitle(); 456 original_contents_title_ = entry->GetTitle();
454 should_revert_tab_title_ = true; 457 should_revert_contents_title_ = true;
455 } 458 }
456 // TODO(evan): make use of title_direction. 459 // TODO(evan): make use of title_direction.
457 // http://code.google.com/p/chromium/issues/detail?id=27094 460 // http://code.google.com/p/chromium/issues/detail?id=27094
458 entry->SetTitle(title); 461 entry->SetTitle(title);
459 tab_->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE); 462 web_contents_->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
460 } 463 }
461 464
462 content::RendererPreferences InterstitialPageImpl::GetRendererPrefs( 465 content::RendererPreferences InterstitialPageImpl::GetRendererPrefs(
463 content::BrowserContext* browser_context) const { 466 content::BrowserContext* browser_context) const {
464 delegate_->OverrideRendererPrefs(&renderer_preferences_); 467 delegate_->OverrideRendererPrefs(&renderer_preferences_);
465 return renderer_preferences_; 468 return renderer_preferences_;
466 } 469 }
467 470
468 WebPreferences InterstitialPageImpl::GetWebkitPrefs() { 471 WebPreferences InterstitialPageImpl::GetWebkitPrefs() {
469 return TabContents::GetWebkitPrefs(render_view_host_, url_); 472 return WebContentsImpl::GetWebkitPrefs(render_view_host_, url_);
470 } 473 }
471 474
472 bool InterstitialPageImpl::PreHandleKeyboardEvent( 475 bool InterstitialPageImpl::PreHandleKeyboardEvent(
473 const NativeWebKeyboardEvent& event, 476 const NativeWebKeyboardEvent& event,
474 bool* is_keyboard_shortcut) { 477 bool* is_keyboard_shortcut) {
475 return tab_->PreHandleKeyboardEvent(event, is_keyboard_shortcut); 478 return web_contents_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
476 } 479 }
477 480
478 void InterstitialPageImpl::HandleKeyboardEvent( 481 void InterstitialPageImpl::HandleKeyboardEvent(
479 const NativeWebKeyboardEvent& event) { 482 const NativeWebKeyboardEvent& event) {
480 return tab_->HandleKeyboardEvent(event); 483 return web_contents_->HandleKeyboardEvent(event);
481 } 484 }
482 485
483 WebContents* InterstitialPageImpl::tab() const { 486 WebContents* InterstitialPageImpl::web_contents() const {
484 return tab_; 487 return web_contents_;
485 } 488 }
486 489
487 RenderViewHost* InterstitialPageImpl::CreateRenderViewHost() { 490 RenderViewHost* InterstitialPageImpl::CreateRenderViewHost() {
488 RenderViewHostImpl* render_view_host = new RenderViewHostImpl( 491 RenderViewHostImpl* render_view_host = new RenderViewHostImpl(
489 SiteInstance::Create(tab()->GetBrowserContext()), 492 SiteInstance::Create(web_contents()->GetBrowserContext()),
490 this, MSG_ROUTING_NONE, kInvalidSessionStorageNamespaceId); 493 this, MSG_ROUTING_NONE, kInvalidSessionStorageNamespaceId);
491 return render_view_host; 494 return render_view_host;
492 } 495 }
493 496
494 WebContentsView* InterstitialPageImpl::CreateWebContentsView() { 497 WebContentsView* InterstitialPageImpl::CreateWebContentsView() {
495 if (!create_view_) 498 if (!create_view_)
496 return NULL; 499 return NULL;
497 WebContentsView* web_contents_view = tab()->GetView(); 500 WebContentsView* web_contents_view = web_contents()->GetView();
498 RenderWidgetHostView* view = 501 RenderWidgetHostView* view =
499 web_contents_view->CreateViewForWidget(render_view_host_); 502 web_contents_view->CreateViewForWidget(render_view_host_);
500 render_view_host_->SetView(view); 503 render_view_host_->SetView(view);
501 render_view_host_->AllowBindings(content::BINDINGS_POLICY_DOM_AUTOMATION); 504 render_view_host_->AllowBindings(content::BINDINGS_POLICY_DOM_AUTOMATION);
502 505
503 int32 max_page_id = 506 int32 max_page_id = web_contents()->
504 tab()->GetMaxPageIDForSiteInstance(render_view_host_->GetSiteInstance()); 507 GetMaxPageIDForSiteInstance(render_view_host_->GetSiteInstance());
505 render_view_host_->CreateRenderView(string16(), max_page_id); 508 render_view_host_->CreateRenderView(string16(), max_page_id);
506 view->SetSize(web_contents_view->GetContainerSize()); 509 view->SetSize(web_contents_view->GetContainerSize());
507 // Don't show the interstitial until we have navigated to it. 510 // Don't show the interstitial until we have navigated to it.
508 view->Hide(); 511 view->Hide();
509 return web_contents_view; 512 return web_contents_view;
510 } 513 }
511 514
512 void InterstitialPageImpl::Proceed() { 515 void InterstitialPageImpl::Proceed() {
513 if (action_taken_ != NO_ACTION) { 516 if (action_taken_ != NO_ACTION) {
514 NOTREACHED(); 517 NOTREACHED();
515 return; 518 return;
516 } 519 }
517 Disable(); 520 Disable();
518 action_taken_ = PROCEED_ACTION; 521 action_taken_ = PROCEED_ACTION;
519 522
520 // Resumes the throbber, if applicable. 523 // Resumes the throbber, if applicable.
521 if (tab_was_loading_) 524 if (contents_was_loading_)
522 tab_->SetIsLoading(true, NULL); 525 web_contents_->SetIsLoading(true, NULL);
523 526
524 // If this is a new navigation, the old page is going away, so we cancel any 527 // If this is a new navigation, the old page is going away, so we cancel any
525 // blocked requests for it. If it is not a new navigation, then it means the 528 // blocked requests for it. If it is not a new navigation, then it means the
526 // interstitial was shown as a result of a resource loading in the page. 529 // interstitial was shown as a result of a resource loading in the page.
527 // Since the user wants to proceed, we'll let any blocked request go through. 530 // Since the user wants to proceed, we'll let any blocked request go through.
528 if (new_navigation_) 531 if (new_navigation_)
529 TakeActionOnResourceDispatcher(CANCEL); 532 TakeActionOnResourceDispatcher(CANCEL);
530 else 533 else
531 TakeActionOnResourceDispatcher(RESUME); 534 TakeActionOnResourceDispatcher(RESUME);
532 535
(...skipping 23 matching lines...) Expand all
556 if (new_navigation_) 559 if (new_navigation_)
557 TakeActionOnResourceDispatcher(RESUME); 560 TakeActionOnResourceDispatcher(RESUME);
558 else 561 else
559 TakeActionOnResourceDispatcher(CANCEL); 562 TakeActionOnResourceDispatcher(CANCEL);
560 563
561 if (should_discard_pending_nav_entry_) { 564 if (should_discard_pending_nav_entry_) {
562 // Since no navigation happens we have to discard the transient entry 565 // Since no navigation happens we have to discard the transient entry
563 // explicitely. Note that by calling DiscardNonCommittedEntries() we also 566 // explicitely. Note that by calling DiscardNonCommittedEntries() we also
564 // discard the pending entry, which is what we want, since the navigation is 567 // discard the pending entry, which is what we want, since the navigation is
565 // cancelled. 568 // cancelled.
566 tab_->GetController().DiscardNonCommittedEntries(); 569 web_contents_->GetController().DiscardNonCommittedEntries();
567 } 570 }
568 571
569 if (reload_on_dont_proceed_) 572 if (reload_on_dont_proceed_)
570 tab_->GetController().Reload(true); 573 web_contents_->GetController().Reload(true);
571 574
572 Hide(); 575 Hide();
573 delegate_->OnDontProceed(); 576 delegate_->OnDontProceed();
574 delete this; 577 delete this;
575 } 578 }
576 579
577 void InterstitialPageImpl::CancelForNavigation() { 580 void InterstitialPageImpl::CancelForNavigation() {
578 // The user is trying to navigate away. We should unblock the renderer and 581 // The user is trying to navigate away. We should unblock the renderer and
579 // disable the interstitial, but keep it visible until the navigation 582 // disable the interstitial, but keep it visible until the navigation
580 // completes. 583 // completes.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 void InterstitialPageImpl::InterstitialPageRVHViewDelegate::UpdateDragCursor( 731 void InterstitialPageImpl::InterstitialPageRVHViewDelegate::UpdateDragCursor(
729 WebDragOperation) { 732 WebDragOperation) {
730 NOTREACHED() << "InterstitialPage does not support dragging yet."; 733 NOTREACHED() << "InterstitialPage does not support dragging yet.";
731 } 734 }
732 735
733 void InterstitialPageImpl::InterstitialPageRVHViewDelegate::GotFocus() { 736 void InterstitialPageImpl::InterstitialPageRVHViewDelegate::GotFocus() {
734 } 737 }
735 738
736 void InterstitialPageImpl::InterstitialPageRVHViewDelegate::TakeFocus( 739 void InterstitialPageImpl::InterstitialPageRVHViewDelegate::TakeFocus(
737 bool reverse) { 740 bool reverse) {
738 if (!interstitial_page_->tab()) 741 if (!interstitial_page_->web_contents())
739 return; 742 return;
740 TabContents* tab = static_cast<TabContents*>(interstitial_page_->tab()); 743 WebContentsImpl* web_contents =
741 if (!tab->GetViewDelegate()) 744 static_cast<WebContentsImpl*>(interstitial_page_->web_contents());
745 if (!web_contents->GetViewDelegate())
742 return; 746 return;
743 747
744 tab->GetViewDelegate()->TakeFocus(reverse); 748 web_contents->GetViewDelegate()->TakeFocus(reverse);
745 } 749 }
746 750
747 void InterstitialPageImpl::InterstitialPageRVHViewDelegate::OnFindReply( 751 void InterstitialPageImpl::InterstitialPageRVHViewDelegate::OnFindReply(
748 int request_id, int number_of_matches, const gfx::Rect& selection_rect, 752 int request_id, int number_of_matches, const gfx::Rect& selection_rect,
749 int active_match_ordinal, bool final_update) { 753 int active_match_ordinal, bool final_update) {
750 } 754 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698