| 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" | |
| 32 #include "chrome/browser/google/google_util.h" | 31 #include "chrome/browser/google/google_util.h" |
| 33 #include "chrome/browser/history/history.h" | 32 #include "chrome/browser/history/history.h" |
| 34 #include "chrome/browser/history/history_types.h" | 33 #include "chrome/browser/history/history_types.h" |
| 35 #include "chrome/browser/load_from_memory_cache_details.h" | 34 #include "chrome/browser/load_from_memory_cache_details.h" |
| 36 #include "chrome/browser/load_notification_details.h" | 35 #include "chrome/browser/load_notification_details.h" |
| 37 #include "chrome/browser/metrics/metric_event_duration_details.h" | 36 #include "chrome/browser/metrics/metric_event_duration_details.h" |
| 38 #include "chrome/browser/metrics/user_metrics.h" | 37 #include "chrome/browser/metrics/user_metrics.h" |
| 39 #include "chrome/browser/omnibox_search_hint.h" | 38 #include "chrome/browser/omnibox_search_hint.h" |
| 40 #include "chrome/browser/pdf_unsupported_feature.h" | 39 #include "chrome/browser/pdf_unsupported_feature.h" |
| 41 #include "chrome/browser/platform_util.h" | 40 #include "chrome/browser/platform_util.h" |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 UMA_HISTOGRAM_TIMES("Tab.Close", | 369 UMA_HISTOGRAM_TIMES("Tab.Close", |
| 371 base::TimeTicks::Now() - tab_close_start_time_); | 370 base::TimeTicks::Now() - tab_close_start_time_); |
| 372 } | 371 } |
| 373 | 372 |
| 374 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed()); | 373 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed()); |
| 375 | 374 |
| 376 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); | 375 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); |
| 377 } | 376 } |
| 378 | 377 |
| 379 void TabContents::AddObservers() { | 378 void TabContents::AddObservers() { |
| 380 favicon_helper_.reset(new FaviconHelper(this)); | |
| 381 desktop_notification_handler_.reset( | 379 desktop_notification_handler_.reset( |
| 382 new DesktopNotificationHandlerForTC(this, GetRenderProcessHost())); | 380 new DesktopNotificationHandlerForTC(this, GetRenderProcessHost())); |
| 383 plugin_observer_.reset(new PluginObserver(this)); | 381 plugin_observer_.reset(new PluginObserver(this)); |
| 384 safebrowsing_detection_host_.reset(new safe_browsing::ClientSideDetectionHost( | 382 safebrowsing_detection_host_.reset(new safe_browsing::ClientSideDetectionHost( |
| 385 this)); | 383 this)); |
| 386 net::NetworkChangeNotifier::AddOnlineStateObserver(this); | 384 net::NetworkChangeNotifier::AddOnlineStateObserver(this); |
| 387 } | 385 } |
| 388 | 386 |
| 389 bool TabContents::OnMessageReceived(const IPC::Message& message) { | 387 bool TabContents::OnMessageReceived(const IPC::Message& message) { |
| 390 ObserverListBase<TabContentsObserver>::Iterator it(observers_); | 388 ObserverListBase<TabContentsObserver>::Iterator it(observers_); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 // We always display the URL for non-WebUI URLs to prevent spoofing. | 512 // We always display the URL for non-WebUI URLs to prevent spoofing. |
| 515 if (entry && !content::WebUIFactory::Get()->HasWebUIScheme(entry->url())) | 513 if (entry && !content::WebUIFactory::Get()->HasWebUIScheme(entry->url())) |
| 516 return true; | 514 return true; |
| 517 | 515 |
| 518 WebUI* web_ui = GetWebUIForCurrentState(); | 516 WebUI* web_ui = GetWebUIForCurrentState(); |
| 519 if (web_ui) | 517 if (web_ui) |
| 520 return !web_ui->should_hide_url(); | 518 return !web_ui->should_hide_url(); |
| 521 return true; | 519 return true; |
| 522 } | 520 } |
| 523 | 521 |
| 524 SkBitmap TabContents::GetFavicon() const { | |
| 525 // Like GetTitle(), we also want to use the favicon for the last committed | |
| 526 // entry rather than a pending navigation entry. | |
| 527 NavigationEntry* entry = controller_.GetTransientEntry(); | |
| 528 if (entry) | |
| 529 return entry->favicon().bitmap(); | |
| 530 | |
| 531 entry = controller_.GetLastCommittedEntry(); | |
| 532 if (entry) | |
| 533 return entry->favicon().bitmap(); | |
| 534 return SkBitmap(); | |
| 535 } | |
| 536 | |
| 537 bool TabContents::FaviconIsValid() const { | |
| 538 NavigationEntry* entry = controller_.GetTransientEntry(); | |
| 539 if (entry) | |
| 540 return entry->favicon().is_valid(); | |
| 541 | |
| 542 entry = controller_.GetLastCommittedEntry(); | |
| 543 if (entry) | |
| 544 return entry->favicon().is_valid(); | |
| 545 | |
| 546 return false; | |
| 547 } | |
| 548 | |
| 549 bool TabContents::ShouldDisplayFavicon() { | |
| 550 // Always display a throbber during pending loads. | |
| 551 if (controller_.GetLastCommittedEntry() && controller_.pending_entry()) | |
| 552 return true; | |
| 553 | |
| 554 WebUI* web_ui = GetWebUIForCurrentState(); | |
| 555 if (web_ui) | |
| 556 return !web_ui->hide_favicon(); | |
| 557 return true; | |
| 558 } | |
| 559 | |
| 560 void TabContents::AddObserver(TabContentsObserver* observer) { | 522 void TabContents::AddObserver(TabContentsObserver* observer) { |
| 561 observers_.AddObserver(observer); | 523 observers_.AddObserver(observer); |
| 562 } | 524 } |
| 563 | 525 |
| 564 void TabContents::RemoveObserver(TabContentsObserver* observer) { | 526 void TabContents::RemoveObserver(TabContentsObserver* observer) { |
| 565 observers_.RemoveObserver(observer); | 527 observers_.RemoveObserver(observer); |
| 566 } | 528 } |
| 567 | 529 |
| 568 void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) { | 530 void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) { |
| 569 if (status == crashed_status_) | 531 if (status == crashed_status_) |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 // HACK!! This code suppresses javascript: URLs from being added to | 663 // HACK!! This code suppresses javascript: URLs from being added to |
| 702 // session history, which is what we want to do for javascript: URLs that | 664 // session history, which is what we want to do for javascript: URLs that |
| 703 // do not generate content. What we really need is a message from the | 665 // do not generate content. What we really need is a message from the |
| 704 // renderer telling us that a new page was not created. The same message | 666 // renderer telling us that a new page was not created. The same message |
| 705 // could be used for mailto: URLs and the like. | 667 // could be used for mailto: URLs and the like. |
| 706 if (entry.url().SchemeIs(chrome::kJavaScriptScheme)) | 668 if (entry.url().SchemeIs(chrome::kJavaScriptScheme)) |
| 707 return false; | 669 return false; |
| 708 } | 670 } |
| 709 | 671 |
| 710 // Notify observers about navigation. | 672 // Notify observers about navigation. |
| 711 FOR_EACH_OBSERVER(TabContentsObserver, observers_, NavigateToPendingEntry()); | 673 FOR_EACH_OBSERVER(TabContentsObserver, observers_, |
| 712 | 674 NavigateToPendingEntry(entry.url(), reload_type)); |
| 713 if (reload_type != NavigationController::NO_RELOAD && | |
| 714 !profile()->IsOffTheRecord()) { | |
| 715 FaviconService* favicon_service = | |
| 716 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS); | |
| 717 if (favicon_service) | |
| 718 favicon_service->SetFaviconOutOfDateForPage(entry.url()); | |
| 719 } | |
| 720 | 675 |
| 721 return true; | 676 return true; |
| 722 } | 677 } |
| 723 | 678 |
| 724 void TabContents::Stop() { | 679 void TabContents::Stop() { |
| 725 render_manager_.Stop(); | 680 render_manager_.Stop(); |
| 726 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation()); | 681 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation()); |
| 727 } | 682 } |
| 728 | 683 |
| 729 void TabContents::DisassociateFromPopupCount() { | 684 void TabContents::DisassociateFromPopupCount() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 743 | 698 |
| 744 void TabContents::ShowPageInfo(const GURL& url, | 699 void TabContents::ShowPageInfo(const GURL& url, |
| 745 const NavigationEntry::SSLStatus& ssl, | 700 const NavigationEntry::SSLStatus& ssl, |
| 746 bool show_history) { | 701 bool show_history) { |
| 747 if (!delegate_) | 702 if (!delegate_) |
| 748 return; | 703 return; |
| 749 | 704 |
| 750 delegate_->ShowPageInfo(profile(), url, ssl, show_history); | 705 delegate_->ShowPageInfo(profile(), url, ssl, show_history); |
| 751 } | 706 } |
| 752 | 707 |
| 753 void TabContents::SaveFavicon() { | |
| 754 NavigationEntry* entry = controller_.GetActiveEntry(); | |
| 755 if (!entry || entry->url().is_empty()) | |
| 756 return; | |
| 757 | |
| 758 // Make sure the page is in history, otherwise adding the favicon does | |
| 759 // nothing. | |
| 760 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService( | |
| 761 Profile::IMPLICIT_ACCESS); | |
| 762 if (!history) | |
| 763 return; | |
| 764 history->AddPageNoVisitForBookmark(entry->url()); | |
| 765 | |
| 766 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService( | |
| 767 Profile::IMPLICIT_ACCESS); | |
| 768 if (!service) | |
| 769 return; | |
| 770 const NavigationEntry::FaviconStatus& favicon(entry->favicon()); | |
| 771 if (!favicon.is_valid() || favicon.url().is_empty() || | |
| 772 favicon.bitmap().empty()) { | |
| 773 return; | |
| 774 } | |
| 775 std::vector<unsigned char> image_data; | |
| 776 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data); | |
| 777 service->SetFavicon( | |
| 778 entry->url(), favicon.url(), image_data, history::FAVICON); | |
| 779 } | |
| 780 | |
| 781 ConstrainedWindow* TabContents::CreateConstrainedDialog( | 708 ConstrainedWindow* TabContents::CreateConstrainedDialog( |
| 782 ConstrainedWindowDelegate* delegate) { | 709 ConstrainedWindowDelegate* delegate) { |
| 783 ConstrainedWindow* window = | 710 ConstrainedWindow* window = |
| 784 ConstrainedWindow::CreateConstrainedDialog(this, delegate); | 711 ConstrainedWindow::CreateConstrainedDialog(this, delegate); |
| 785 AddConstrainedDialog(window); | 712 AddConstrainedDialog(window); |
| 786 return window; | 713 return window; |
| 787 } | 714 } |
| 788 | 715 |
| 789 void TabContents::AddConstrainedDialog(ConstrainedWindow* window) { | 716 void TabContents::AddConstrainedDialog(ConstrainedWindow* window) { |
| 790 child_windows_.push_back(window); | 717 child_windows_.push_back(window); |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1558 // transition (this is also why the mouse cursor remains as a hand after | 1485 // transition (this is also why the mouse cursor remains as a hand after |
| 1559 // clicking on a link); see bugs 1184641 and 980803. We don't want to | 1486 // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 1560 // clear the bubble when a user navigates to a named anchor in the same | 1487 // clear the bubble when a user navigates to a named anchor in the same |
| 1561 // page. | 1488 // page. |
| 1562 UpdateTargetURL(details.entry->page_id(), GURL()); | 1489 UpdateTargetURL(details.entry->page_id(), GURL()); |
| 1563 } | 1490 } |
| 1564 | 1491 |
| 1565 // Allow the new page to set the title again. | 1492 // Allow the new page to set the title again. |
| 1566 received_page_title_ = false; | 1493 received_page_title_ = false; |
| 1567 | 1494 |
| 1568 // Get the favicon, either from history or request it from the net. | |
| 1569 favicon_helper_->FetchFavicon(details.entry->url()); | |
| 1570 | |
| 1571 // Clear all page actions, blocked content notifications and browser actions | 1495 // Clear all page actions, blocked content notifications and browser actions |
| 1572 // for this tab, unless this is an in-page navigation. | 1496 // for this tab, unless this is an in-page navigation. |
| 1573 if (!details.is_in_page) { | 1497 if (!details.is_in_page) { |
| 1574 // Close blocked popups. | 1498 // Close blocked popups. |
| 1575 if (blocked_contents_) { | 1499 if (blocked_contents_) { |
| 1576 AutoReset<bool> auto_reset(&dont_notify_render_view_, true); | 1500 AutoReset<bool> auto_reset(&dont_notify_render_view_, true); |
| 1577 blocked_contents_->Destroy(); | 1501 blocked_contents_->Destroy(); |
| 1578 blocked_contents_ = NULL; | 1502 blocked_contents_ = NULL; |
| 1579 } | 1503 } |
| 1580 | 1504 |
| (...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2612 | 2536 |
| 2613 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2537 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 2614 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 2538 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 2615 rwh_view->SetSize(view()->GetContainerSize()); | 2539 rwh_view->SetSize(view()->GetContainerSize()); |
| 2616 } | 2540 } |
| 2617 | 2541 |
| 2618 void TabContents::OnOnlineStateChanged(bool online) { | 2542 void TabContents::OnOnlineStateChanged(bool online) { |
| 2619 render_view_host()->Send(new ViewMsg_NetworkStateChanged( | 2543 render_view_host()->Send(new ViewMsg_NetworkStateChanged( |
| 2620 render_view_host()->routing_id(), online)); | 2544 render_view_host()->routing_id(), online)); |
| 2621 } | 2545 } |
| OLD | NEW |