| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/tab_contents/interstitial_page.h" | 5 #include "chrome/browser/tab_contents/interstitial_page.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/thread.h" | 9 #include "base/thread.h" |
| 10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 // the tab was closed before that. | 274 // the tab was closed before that. |
| 275 Hide(); | 275 Hide(); |
| 276 // WARNING: we are now deleted! | 276 // WARNING: we are now deleted! |
| 277 } | 277 } |
| 278 break; | 278 break; |
| 279 default: | 279 default: |
| 280 NOTREACHED(); | 280 NOTREACHED(); |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 | 283 |
| 284 RenderViewHostDelegate::View* InterstitialPage::GetViewDelegate() const { |
| 285 return rvh_view_delegate_.get(); |
| 286 } |
| 287 |
| 288 const GURL& InterstitialPage::GetURL() const { |
| 289 return url_; |
| 290 } |
| 291 |
| 292 void InterstitialPage::RenderViewGone(RenderViewHost* render_view_host) { |
| 293 // Our renderer died. This should not happen in normal cases. |
| 294 // Just dismiss the interstitial. |
| 295 DontProceed(); |
| 296 } |
| 297 |
| 298 void InterstitialPage::DidNavigate( |
| 299 RenderViewHost* render_view_host, |
| 300 const ViewHostMsg_FrameNavigate_Params& params) { |
| 301 // A fast user could have navigated away from the page that triggered the |
| 302 // interstitial while the interstitial was loading, that would have disabled |
| 303 // us. In that case we can dismiss ourselves. |
| 304 if (!enabled_){ |
| 305 DontProceed(); |
| 306 return; |
| 307 } |
| 308 |
| 309 // The RenderViewHost has loaded its contents, we can show it now. |
| 310 render_view_host_->view()->Show(); |
| 311 tab_->set_interstitial_page(this); |
| 312 |
| 313 RenderWidgetHostView* rwh_view = tab_->render_view_host()->view(); |
| 314 |
| 315 // The RenderViewHost may already have crashed before we even get here. |
| 316 if (rwh_view) { |
| 317 // If the page has focus, focus the interstitial. |
| 318 if (rwh_view->HasFocus()) |
| 319 Focus(); |
| 320 |
| 321 // Hide the original RVH since we're showing the interstitial instead. |
| 322 rwh_view->Hide(); |
| 323 } |
| 324 |
| 325 // Notify the tab we are not loading so the throbber is stopped. It also |
| 326 // causes a NOTIFY_LOAD_STOP notification, that the AutomationProvider (used |
| 327 // by the UI tests) expects to consider a navigation as complete. Without |
| 328 // this, navigating in a UI test to a URL that triggers an interstitial would |
| 329 // hang. |
| 330 tab_->SetIsLoading(false, NULL); |
| 331 } |
| 332 |
| 333 void InterstitialPage::UpdateTitle(RenderViewHost* render_view_host, |
| 334 int32 page_id, |
| 335 const std::wstring& title) { |
| 336 DCHECK(render_view_host == render_view_host_); |
| 337 NavigationEntry* entry = tab_->controller().GetActiveEntry(); |
| 338 // If this interstitial is shown on an existing navigation entry, we'll need |
| 339 // to remember its title so we can revert to it when hidden. |
| 340 if (!new_navigation_ && !should_revert_tab_title_) { |
| 341 original_tab_title_ = UTF16ToWideHack(entry->title()); |
| 342 should_revert_tab_title_ = true; |
| 343 } |
| 344 entry->set_title(WideToUTF16Hack(title)); |
| 345 tab_->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB); |
| 346 } |
| 347 |
| 348 void InterstitialPage::DomOperationResponse(const std::string& json_string, |
| 349 int automation_id) { |
| 350 if (enabled_) |
| 351 CommandReceived(json_string); |
| 352 } |
| 353 |
| 354 GURL InterstitialPage::GetAlternateErrorPageURL() const { |
| 355 return GURL(); |
| 356 } |
| 357 |
| 358 RendererPreferences InterstitialPage::GetRendererPrefs() const { |
| 359 return RendererPreferences(); |
| 360 } |
| 361 |
| 362 WebPreferences InterstitialPage::GetWebkitPrefs() { |
| 363 return WebPreferences(); |
| 364 } |
| 365 |
| 366 gfx::Rect InterstitialPage::GetRootWindowResizerRect() const { |
| 367 return gfx::Rect(); |
| 368 } |
| 369 |
| 284 RenderViewHost* InterstitialPage::CreateRenderViewHost() { | 370 RenderViewHost* InterstitialPage::CreateRenderViewHost() { |
| 285 RenderViewHost* render_view_host = new RenderViewHost( | 371 RenderViewHost* render_view_host = new RenderViewHost( |
| 286 SiteInstance::CreateSiteInstance(tab()->profile()), | 372 SiteInstance::CreateSiteInstance(tab()->profile()), |
| 287 this, MSG_ROUTING_NONE, NULL); | 373 this, MSG_ROUTING_NONE, NULL); |
| 288 return render_view_host; | 374 return render_view_host; |
| 289 } | 375 } |
| 290 | 376 |
| 291 TabContentsView* InterstitialPage::CreateTabContentsView() { | 377 TabContentsView* InterstitialPage::CreateTabContentsView() { |
| 292 TabContentsView* tab_contents_view = tab()->view(); | 378 TabContentsView* tab_contents_view = tab()->view(); |
| 293 RenderWidgetHostView* view = | 379 RenderWidgetHostView* view = |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 459 |
| 374 void InterstitialPage::Focus() { | 460 void InterstitialPage::Focus() { |
| 375 // Focus the native window. | 461 // Focus the native window. |
| 376 render_view_host_->view()->Focus(); | 462 render_view_host_->view()->Focus(); |
| 377 } | 463 } |
| 378 | 464 |
| 379 void InterstitialPage::FocusThroughTabTraversal(bool reverse) { | 465 void InterstitialPage::FocusThroughTabTraversal(bool reverse) { |
| 380 render_view_host_->SetInitialFocus(reverse); | 466 render_view_host_->SetInitialFocus(reverse); |
| 381 } | 467 } |
| 382 | 468 |
| 383 void InterstitialPage::DidNavigate( | |
| 384 RenderViewHost* render_view_host, | |
| 385 const ViewHostMsg_FrameNavigate_Params& params) { | |
| 386 // A fast user could have navigated away from the page that triggered the | |
| 387 // interstitial while the interstitial was loading, that would have disabled | |
| 388 // us. In that case we can dismiss ourselves. | |
| 389 if (!enabled_){ | |
| 390 DontProceed(); | |
| 391 return; | |
| 392 } | |
| 393 | |
| 394 // The RenderViewHost has loaded its contents, we can show it now. | |
| 395 render_view_host_->view()->Show(); | |
| 396 tab_->set_interstitial_page(this); | |
| 397 | |
| 398 RenderWidgetHostView* rwh_view = tab_->render_view_host()->view(); | |
| 399 | |
| 400 // The RenderViewHost may already have crashed before we even get here. | |
| 401 if (rwh_view) { | |
| 402 // If the page has focus, focus the interstitial. | |
| 403 if (rwh_view->HasFocus()) | |
| 404 Focus(); | |
| 405 | |
| 406 // Hide the original RVH since we're showing the interstitial instead. | |
| 407 rwh_view->Hide(); | |
| 408 } | |
| 409 | |
| 410 // Notify the tab we are not loading so the throbber is stopped. It also | |
| 411 // causes a NOTIFY_LOAD_STOP notification, that the AutomationProvider (used | |
| 412 // by the UI tests) expects to consider a navigation as complete. Without | |
| 413 // this, navigating in a UI test to a URL that triggers an interstitial would | |
| 414 // hang. | |
| 415 tab_->SetIsLoading(false, NULL); | |
| 416 } | |
| 417 | |
| 418 void InterstitialPage::RenderViewGone(RenderViewHost* render_view_host) { | |
| 419 // Our renderer died. This should not happen in normal cases. | |
| 420 // Just dismiss the interstitial. | |
| 421 DontProceed(); | |
| 422 } | |
| 423 | |
| 424 void InterstitialPage::DomOperationResponse(const std::string& json_string, | |
| 425 int automation_id) { | |
| 426 if (enabled_) | |
| 427 CommandReceived(json_string); | |
| 428 } | |
| 429 | |
| 430 void InterstitialPage::UpdateTitle(RenderViewHost* render_view_host, | |
| 431 int32 page_id, | |
| 432 const std::wstring& title) { | |
| 433 DCHECK(render_view_host == render_view_host_); | |
| 434 NavigationEntry* entry = tab_->controller().GetActiveEntry(); | |
| 435 // If this interstitial is shown on an existing navigation entry, we'll need | |
| 436 // to remember its title so we can revert to it when hidden. | |
| 437 if (!new_navigation_ && !should_revert_tab_title_) { | |
| 438 original_tab_title_ = UTF16ToWideHack(entry->title()); | |
| 439 should_revert_tab_title_ = true; | |
| 440 } | |
| 441 entry->set_title(WideToUTF16Hack(title)); | |
| 442 tab_->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB); | |
| 443 } | |
| 444 | |
| 445 RenderViewHostDelegate::View* InterstitialPage::GetViewDelegate() const { | |
| 446 return rvh_view_delegate_.get(); | |
| 447 } | |
| 448 | |
| 449 void InterstitialPage::Disable() { | 469 void InterstitialPage::Disable() { |
| 450 enabled_ = false; | 470 enabled_ = false; |
| 451 } | 471 } |
| 452 | 472 |
| 453 void InterstitialPage::TakeActionOnResourceDispatcher( | 473 void InterstitialPage::TakeActionOnResourceDispatcher( |
| 454 ResourceRequestAction action) { | 474 ResourceRequestAction action) { |
| 455 DCHECK(MessageLoop::current() == ui_loop_) << | 475 DCHECK(MessageLoop::current() == ui_loop_) << |
| 456 "TakeActionOnResourceDispatcher should be called on the main thread."; | 476 "TakeActionOnResourceDispatcher should be called on the main thread."; |
| 457 | 477 |
| 458 if (action == CANCEL || action == RESUME) { | 478 if (action == CANCEL || action == RESUME) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 | 580 |
| 561 void InterstitialPage::InterstitialPageRVHViewDelegate::HandleMouseLeave() { | 581 void InterstitialPage::InterstitialPageRVHViewDelegate::HandleMouseLeave() { |
| 562 if (interstitial_page_->tab() && interstitial_page_->tab()->GetViewDelegate()) | 582 if (interstitial_page_->tab() && interstitial_page_->tab()->GetViewDelegate()) |
| 563 interstitial_page_->tab()->GetViewDelegate()->HandleMouseLeave(); | 583 interstitial_page_->tab()->GetViewDelegate()->HandleMouseLeave(); |
| 564 } | 584 } |
| 565 | 585 |
| 566 void InterstitialPage::InterstitialPageRVHViewDelegate::OnFindReply( | 586 void InterstitialPage::InterstitialPageRVHViewDelegate::OnFindReply( |
| 567 int request_id, int number_of_matches, const gfx::Rect& selection_rect, | 587 int request_id, int number_of_matches, const gfx::Rect& selection_rect, |
| 568 int active_match_ordinal, bool final_update) { | 588 int active_match_ordinal, bool final_update) { |
| 569 } | 589 } |
| OLD | NEW |