| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "content/browser/tab_contents/tab_contents.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/content_settings/content_settings_details.h" | 21 #include "chrome/browser/content_settings/content_settings_details.h" |
| 22 #include "chrome/browser/content_settings/host_content_settings_map.h" | 22 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 23 #include "chrome/browser/debugger/devtools_manager.h" | 23 #include "chrome/browser/debugger/devtools_manager.h" |
| 24 #include "chrome/browser/defaults.h" | 24 #include "chrome/browser/defaults.h" |
| 25 #include "chrome/browser/desktop_notification_handler.h" | 25 #include "chrome/browser/desktop_notification_handler.h" |
| 26 #include "chrome/browser/dom_operation_notification_details.h" | 26 #include "chrome/browser/dom_operation_notification_details.h" |
| 27 #include "chrome/browser/download/download_item_model.h" | 27 #include "chrome/browser/download/download_item_model.h" |
| 28 #include "chrome/browser/download/download_manager.h" | 28 #include "chrome/browser/download/download_manager.h" |
| 29 #include "chrome/browser/download/download_request_limiter.h" | 29 #include "chrome/browser/download/download_request_limiter.h" |
| 30 #include "chrome/browser/external_protocol_handler.h" | 30 #include "chrome/browser/external_protocol_handler.h" |
| 31 #include "chrome/browser/favicon_service.h" |
| 31 #include "chrome/browser/google/google_util.h" | 32 #include "chrome/browser/google/google_util.h" |
| 32 #include "chrome/browser/history/history.h" | 33 #include "chrome/browser/history/history.h" |
| 33 #include "chrome/browser/history/history_types.h" | 34 #include "chrome/browser/history/history_types.h" |
| 34 #include "chrome/browser/load_from_memory_cache_details.h" | 35 #include "chrome/browser/load_from_memory_cache_details.h" |
| 35 #include "chrome/browser/load_notification_details.h" | 36 #include "chrome/browser/load_notification_details.h" |
| 36 #include "chrome/browser/metrics/metric_event_duration_details.h" | 37 #include "chrome/browser/metrics/metric_event_duration_details.h" |
| 37 #include "chrome/browser/metrics/user_metrics.h" | 38 #include "chrome/browser/metrics/user_metrics.h" |
| 38 #include "chrome/browser/omnibox_search_hint.h" | 39 #include "chrome/browser/omnibox_search_hint.h" |
| 39 #include "chrome/browser/pdf_unsupported_feature.h" | 40 #include "chrome/browser/pdf_unsupported_feature.h" |
| 40 #include "chrome/browser/platform_util.h" | 41 #include "chrome/browser/platform_util.h" |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 UMA_HISTOGRAM_TIMES("Tab.Close", | 364 UMA_HISTOGRAM_TIMES("Tab.Close", |
| 364 base::TimeTicks::Now() - tab_close_start_time_); | 365 base::TimeTicks::Now() - tab_close_start_time_); |
| 365 } | 366 } |
| 366 | 367 |
| 367 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed()); | 368 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed()); |
| 368 | 369 |
| 369 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); | 370 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); |
| 370 } | 371 } |
| 371 | 372 |
| 372 void TabContents::AddObservers() { | 373 void TabContents::AddObservers() { |
| 374 favicon_helper_.reset(new FaviconHelper(this)); |
| 373 desktop_notification_handler_.reset( | 375 desktop_notification_handler_.reset( |
| 374 new DesktopNotificationHandlerForTC(this, GetRenderProcessHost())); | 376 new DesktopNotificationHandlerForTC(this, GetRenderProcessHost())); |
| 375 plugin_observer_.reset(new PluginObserver(this)); | 377 plugin_observer_.reset(new PluginObserver(this)); |
| 376 safebrowsing_detection_host_.reset(new safe_browsing::ClientSideDetectionHost( | 378 safebrowsing_detection_host_.reset(new safe_browsing::ClientSideDetectionHost( |
| 377 this)); | 379 this)); |
| 378 net::NetworkChangeNotifier::AddOnlineStateObserver(this); | 380 net::NetworkChangeNotifier::AddOnlineStateObserver(this); |
| 379 } | 381 } |
| 380 | 382 |
| 381 bool TabContents::OnMessageReceived(const IPC::Message& message) { | 383 bool TabContents::OnMessageReceived(const IPC::Message& message) { |
| 382 ObserverListBase<TabContentsObserver>::Iterator it(observers_); | 384 ObserverListBase<TabContentsObserver>::Iterator it(observers_); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 // We always display the URL for non-WebUI URLs to prevent spoofing. | 508 // We always display the URL for non-WebUI URLs to prevent spoofing. |
| 507 if (entry && !content::WebUIFactory::Get()->HasWebUIScheme(entry->url())) | 509 if (entry && !content::WebUIFactory::Get()->HasWebUIScheme(entry->url())) |
| 508 return true; | 510 return true; |
| 509 | 511 |
| 510 WebUI* web_ui = GetWebUIForCurrentState(); | 512 WebUI* web_ui = GetWebUIForCurrentState(); |
| 511 if (web_ui) | 513 if (web_ui) |
| 512 return !web_ui->should_hide_url(); | 514 return !web_ui->should_hide_url(); |
| 513 return true; | 515 return true; |
| 514 } | 516 } |
| 515 | 517 |
| 518 SkBitmap TabContents::GetFavicon() const { |
| 519 // Like GetTitle(), we also want to use the favicon for the last committed |
| 520 // entry rather than a pending navigation entry. |
| 521 NavigationEntry* entry = controller_.GetTransientEntry(); |
| 522 if (entry) |
| 523 return entry->favicon().bitmap(); |
| 524 |
| 525 entry = controller_.GetLastCommittedEntry(); |
| 526 if (entry) |
| 527 return entry->favicon().bitmap(); |
| 528 return SkBitmap(); |
| 529 } |
| 530 |
| 531 bool TabContents::FaviconIsValid() const { |
| 532 NavigationEntry* entry = controller_.GetTransientEntry(); |
| 533 if (entry) |
| 534 return entry->favicon().is_valid(); |
| 535 |
| 536 entry = controller_.GetLastCommittedEntry(); |
| 537 if (entry) |
| 538 return entry->favicon().is_valid(); |
| 539 |
| 540 return false; |
| 541 } |
| 542 |
| 543 bool TabContents::ShouldDisplayFavicon() { |
| 544 // Always display a throbber during pending loads. |
| 545 if (controller_.GetLastCommittedEntry() && controller_.pending_entry()) |
| 546 return true; |
| 547 |
| 548 WebUI* web_ui = GetWebUIForCurrentState(); |
| 549 if (web_ui) |
| 550 return !web_ui->hide_favicon(); |
| 551 return true; |
| 552 } |
| 553 |
| 516 void TabContents::AddObserver(TabContentsObserver* observer) { | 554 void TabContents::AddObserver(TabContentsObserver* observer) { |
| 517 observers_.AddObserver(observer); | 555 observers_.AddObserver(observer); |
| 518 } | 556 } |
| 519 | 557 |
| 520 void TabContents::RemoveObserver(TabContentsObserver* observer) { | 558 void TabContents::RemoveObserver(TabContentsObserver* observer) { |
| 521 observers_.RemoveObserver(observer); | 559 observers_.RemoveObserver(observer); |
| 522 } | 560 } |
| 523 | 561 |
| 524 void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) { | 562 void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) { |
| 525 if (status == crashed_status_) | 563 if (status == crashed_status_) |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 // HACK!! This code suppresses javascript: URLs from being added to | 695 // HACK!! This code suppresses javascript: URLs from being added to |
| 658 // session history, which is what we want to do for javascript: URLs that | 696 // session history, which is what we want to do for javascript: URLs that |
| 659 // do not generate content. What we really need is a message from the | 697 // do not generate content. What we really need is a message from the |
| 660 // renderer telling us that a new page was not created. The same message | 698 // renderer telling us that a new page was not created. The same message |
| 661 // could be used for mailto: URLs and the like. | 699 // could be used for mailto: URLs and the like. |
| 662 if (entry.url().SchemeIs(chrome::kJavaScriptScheme)) | 700 if (entry.url().SchemeIs(chrome::kJavaScriptScheme)) |
| 663 return false; | 701 return false; |
| 664 } | 702 } |
| 665 | 703 |
| 666 // Notify observers about navigation. | 704 // Notify observers about navigation. |
| 667 FOR_EACH_OBSERVER(TabContentsObserver, observers_, | 705 FOR_EACH_OBSERVER(TabContentsObserver, observers_, NavigateToPendingEntry()); |
| 668 NavigateToPendingEntry(entry.url(), reload_type)); | 706 |
| 707 if (reload_type != NavigationController::NO_RELOAD && |
| 708 !profile()->IsOffTheRecord()) { |
| 709 FaviconService* favicon_service = |
| 710 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS); |
| 711 if (favicon_service) |
| 712 favicon_service->SetFaviconOutOfDateForPage(entry.url()); |
| 713 } |
| 669 | 714 |
| 670 return true; | 715 return true; |
| 671 } | 716 } |
| 672 | 717 |
| 673 void TabContents::Stop() { | 718 void TabContents::Stop() { |
| 674 render_manager_.Stop(); | 719 render_manager_.Stop(); |
| 675 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation()); | 720 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation()); |
| 676 } | 721 } |
| 677 | 722 |
| 678 void TabContents::DisassociateFromPopupCount() { | 723 void TabContents::DisassociateFromPopupCount() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 692 | 737 |
| 693 void TabContents::ShowPageInfo(const GURL& url, | 738 void TabContents::ShowPageInfo(const GURL& url, |
| 694 const NavigationEntry::SSLStatus& ssl, | 739 const NavigationEntry::SSLStatus& ssl, |
| 695 bool show_history) { | 740 bool show_history) { |
| 696 if (!delegate_) | 741 if (!delegate_) |
| 697 return; | 742 return; |
| 698 | 743 |
| 699 delegate_->ShowPageInfo(profile(), url, ssl, show_history); | 744 delegate_->ShowPageInfo(profile(), url, ssl, show_history); |
| 700 } | 745 } |
| 701 | 746 |
| 747 void TabContents::SaveFavicon() { |
| 748 NavigationEntry* entry = controller_.GetActiveEntry(); |
| 749 if (!entry || entry->url().is_empty()) |
| 750 return; |
| 751 |
| 752 // Make sure the page is in history, otherwise adding the favicon does |
| 753 // nothing. |
| 754 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService( |
| 755 Profile::IMPLICIT_ACCESS); |
| 756 if (!history) |
| 757 return; |
| 758 history->AddPageNoVisitForBookmark(entry->url()); |
| 759 |
| 760 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService( |
| 761 Profile::IMPLICIT_ACCESS); |
| 762 if (!service) |
| 763 return; |
| 764 const NavigationEntry::FaviconStatus& favicon(entry->favicon()); |
| 765 if (!favicon.is_valid() || favicon.url().is_empty() || |
| 766 favicon.bitmap().empty()) { |
| 767 return; |
| 768 } |
| 769 std::vector<unsigned char> image_data; |
| 770 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data); |
| 771 service->SetFavicon( |
| 772 entry->url(), favicon.url(), image_data, history::FAVICON); |
| 773 } |
| 774 |
| 702 ConstrainedWindow* TabContents::CreateConstrainedDialog( | 775 ConstrainedWindow* TabContents::CreateConstrainedDialog( |
| 703 ConstrainedWindowDelegate* delegate) { | 776 ConstrainedWindowDelegate* delegate) { |
| 704 ConstrainedWindow* window = | 777 ConstrainedWindow* window = |
| 705 ConstrainedWindow::CreateConstrainedDialog(this, delegate); | 778 ConstrainedWindow::CreateConstrainedDialog(this, delegate); |
| 706 AddConstrainedDialog(window); | 779 AddConstrainedDialog(window); |
| 707 return window; | 780 return window; |
| 708 } | 781 } |
| 709 | 782 |
| 710 void TabContents::AddConstrainedDialog(ConstrainedWindow* window) { | 783 void TabContents::AddConstrainedDialog(ConstrainedWindow* window) { |
| 711 child_windows_.push_back(window); | 784 child_windows_.push_back(window); |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 // transition (this is also why the mouse cursor remains as a hand after | 1554 // transition (this is also why the mouse cursor remains as a hand after |
| 1482 // clicking on a link); see bugs 1184641 and 980803. We don't want to | 1555 // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 1483 // clear the bubble when a user navigates to a named anchor in the same | 1556 // clear the bubble when a user navigates to a named anchor in the same |
| 1484 // page. | 1557 // page. |
| 1485 UpdateTargetURL(details.entry->page_id(), GURL()); | 1558 UpdateTargetURL(details.entry->page_id(), GURL()); |
| 1486 } | 1559 } |
| 1487 | 1560 |
| 1488 // Allow the new page to set the title again. | 1561 // Allow the new page to set the title again. |
| 1489 received_page_title_ = false; | 1562 received_page_title_ = false; |
| 1490 | 1563 |
| 1564 // Get the favicon, either from history or request it from the net. |
| 1565 favicon_helper_->FetchFavicon(details.entry->url()); |
| 1566 |
| 1491 // Clear all page actions, blocked content notifications and browser actions | 1567 // Clear all page actions, blocked content notifications and browser actions |
| 1492 // for this tab, unless this is an in-page navigation. | 1568 // for this tab, unless this is an in-page navigation. |
| 1493 if (!details.is_in_page) { | 1569 if (!details.is_in_page) { |
| 1494 // Close blocked popups. | 1570 // Close blocked popups. |
| 1495 if (blocked_contents_) { | 1571 if (blocked_contents_) { |
| 1496 AutoReset<bool> auto_reset(&dont_notify_render_view_, true); | 1572 AutoReset<bool> auto_reset(&dont_notify_render_view_, true); |
| 1497 blocked_contents_->Destroy(); | 1573 blocked_contents_->Destroy(); |
| 1498 blocked_contents_ = NULL; | 1574 blocked_contents_ = NULL; |
| 1499 } | 1575 } |
| 1500 | 1576 |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2521 | 2597 |
| 2522 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2598 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 2523 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 2599 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 2524 rwh_view->SetSize(view()->GetContainerSize()); | 2600 rwh_view->SetSize(view()->GetContainerSize()); |
| 2525 } | 2601 } |
| 2526 | 2602 |
| 2527 void TabContents::OnOnlineStateChanged(bool online) { | 2603 void TabContents::OnOnlineStateChanged(bool online) { |
| 2528 render_view_host()->Send(new ViewMsg_NetworkStateChanged( | 2604 render_view_host()->Send(new ViewMsg_NetworkStateChanged( |
| 2529 render_view_host()->routing_id(), online)); | 2605 render_view_host()->routing_id(), online)); |
| 2530 } | 2606 } |
| OLD | NEW |