Chromium Code Reviews| 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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "chrome/browser/content_settings/host_content_settings_map.h" | 23 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 24 #include "chrome/browser/debugger/devtools_manager.h" | 24 #include "chrome/browser/debugger/devtools_manager.h" |
| 25 #include "chrome/browser/defaults.h" | 25 #include "chrome/browser/defaults.h" |
| 26 #include "chrome/browser/desktop_notification_handler.h" | 26 #include "chrome/browser/desktop_notification_handler.h" |
| 27 #include "chrome/browser/dom_operation_notification_details.h" | 27 #include "chrome/browser/dom_operation_notification_details.h" |
| 28 #include "chrome/browser/download/download_item_model.h" | 28 #include "chrome/browser/download/download_item_model.h" |
| 29 #include "chrome/browser/download/download_manager.h" | 29 #include "chrome/browser/download/download_manager.h" |
| 30 #include "chrome/browser/download/download_request_limiter.h" | 30 #include "chrome/browser/download/download_request_limiter.h" |
| 31 #include "chrome/browser/extensions/extension_service.h" | 31 #include "chrome/browser/extensions/extension_service.h" |
| 32 #include "chrome/browser/external_protocol_handler.h" | 32 #include "chrome/browser/external_protocol_handler.h" |
| 33 #include "chrome/browser/favicon_delegate.h" | |
| 33 #include "chrome/browser/favicon_service.h" | 34 #include "chrome/browser/favicon_service.h" |
| 34 #include "chrome/browser/google/google_util.h" | 35 #include "chrome/browser/google/google_util.h" |
| 35 #include "chrome/browser/history/history.h" | 36 #include "chrome/browser/history/history.h" |
| 36 #include "chrome/browser/history/history_types.h" | 37 #include "chrome/browser/history/history_types.h" |
| 37 #include "chrome/browser/history/top_sites.h" | 38 #include "chrome/browser/history/top_sites.h" |
| 38 #include "chrome/browser/load_from_memory_cache_details.h" | 39 #include "chrome/browser/load_from_memory_cache_details.h" |
| 39 #include "chrome/browser/load_notification_details.h" | 40 #include "chrome/browser/load_notification_details.h" |
| 40 #include "chrome/browser/metrics/metric_event_duration_details.h" | 41 #include "chrome/browser/metrics/metric_event_duration_details.h" |
| 41 #include "chrome/browser/metrics/user_metrics.h" | 42 #include "chrome/browser/metrics/user_metrics.h" |
| 42 #include "chrome/browser/omnibox_search_hint.h" | 43 #include "chrome/browser/omnibox_search_hint.h" |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 } | 383 } |
| 383 | 384 |
| 384 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed()); | 385 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed()); |
| 385 | 386 |
| 386 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); | 387 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); |
| 387 } | 388 } |
| 388 | 389 |
| 389 void TabContents::AddObservers() { | 390 void TabContents::AddObservers() { |
| 390 printing_.reset(new printing::PrintViewManager(this)); | 391 printing_.reset(new printing::PrintViewManager(this)); |
| 391 print_preview_.reset(new printing::PrintPreviewMessageHandler(this)); | 392 print_preview_.reset(new printing::PrintPreviewMessageHandler(this)); |
| 392 favicon_helper_.reset(new FaviconHelper(this)); | 393 favicon_helper_.reset(new FaviconHelper(this, history::FAVICON, |
| 394 new FaviconDelegate(this))); | |
| 395 touch_icon_helper_.reset(new FaviconHelper(this, | |
|
sky
2011/03/18 17:33:37
You'll want to define a constant in chrome/browser
michaelbai
2011/03/22 18:14:13
Done.
| |
| 396 history::TOUCH_ICON | history::TOUCH_PRECOMPOSED_ICON, NULL)); | |
| 393 autofill_manager_.reset(new AutofillManager(this)); | 397 autofill_manager_.reset(new AutofillManager(this)); |
| 394 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this)); | 398 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this)); |
| 395 desktop_notification_handler_.reset( | 399 desktop_notification_handler_.reset( |
| 396 new DesktopNotificationHandlerForTC(this, GetRenderProcessHost())); | 400 new DesktopNotificationHandlerForTC(this, GetRenderProcessHost())); |
| 397 plugin_observer_.reset(new PluginObserver(this)); | 401 plugin_observer_.reset(new PluginObserver(this)); |
| 398 safebrowsing_detection_host_.reset(new safe_browsing::ClientSideDetectionHost( | 402 safebrowsing_detection_host_.reset(new safe_browsing::ClientSideDetectionHost( |
| 399 this)); | 403 this)); |
| 400 net::NetworkChangeNotifier::AddOnlineStateObserver(this); | 404 net::NetworkChangeNotifier::AddOnlineStateObserver(this); |
| 401 } | 405 } |
| 402 | 406 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 if (web_ui) | 577 if (web_ui) |
| 574 return !web_ui->should_hide_url(); | 578 return !web_ui->should_hide_url(); |
| 575 return true; | 579 return true; |
| 576 } | 580 } |
| 577 | 581 |
| 578 SkBitmap TabContents::GetFavicon() const { | 582 SkBitmap TabContents::GetFavicon() const { |
| 579 // Like GetTitle(), we also want to use the favicon for the last committed | 583 // Like GetTitle(), we also want to use the favicon for the last committed |
| 580 // entry rather than a pending navigation entry. | 584 // entry rather than a pending navigation entry. |
| 581 NavigationEntry* entry = controller_.GetTransientEntry(); | 585 NavigationEntry* entry = controller_.GetTransientEntry(); |
| 582 if (entry) | 586 if (entry) |
| 583 return entry->favicon().bitmap(); | 587 return entry->GetFavicon(history::FAVICON).bitmap(); |
| 584 | 588 |
| 585 entry = controller_.GetLastCommittedEntry(); | 589 entry = controller_.GetLastCommittedEntry(); |
| 586 if (entry) | 590 if (entry) |
| 587 return entry->favicon().bitmap(); | 591 return entry->GetFavicon(history::FAVICON).bitmap(); |
| 588 return SkBitmap(); | 592 return SkBitmap(); |
| 589 } | 593 } |
| 590 | 594 |
| 591 bool TabContents::FaviconIsValid() const { | 595 bool TabContents::FaviconIsValid() const { |
| 592 NavigationEntry* entry = controller_.GetTransientEntry(); | 596 NavigationEntry* entry = controller_.GetTransientEntry(); |
| 593 if (entry) | 597 if (entry) |
| 594 return entry->favicon().is_valid(); | 598 return entry->GetFavicon(history::FAVICON).is_valid(); |
| 595 | 599 |
| 596 entry = controller_.GetLastCommittedEntry(); | 600 entry = controller_.GetLastCommittedEntry(); |
| 597 if (entry) | 601 if (entry) |
| 598 return entry->favicon().is_valid(); | 602 return entry->GetFavicon(history::FAVICON).is_valid(); |
| 599 | 603 |
| 600 return false; | 604 return false; |
| 601 } | 605 } |
| 602 | 606 |
| 603 bool TabContents::ShouldDisplayFavicon() { | 607 bool TabContents::ShouldDisplayFavicon() { |
| 604 // Always display a throbber during pending loads. | 608 // Always display a throbber during pending loads. |
| 605 if (controller_.GetLastCommittedEntry() && controller_.pending_entry()) | 609 if (controller_.GetLastCommittedEntry() && controller_.pending_entry()) |
| 606 return true; | 610 return true; |
| 607 | 611 |
| 608 WebUI* web_ui = GetWebUIForCurrentState(); | 612 WebUI* web_ui = GetWebUIForCurrentState(); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 832 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService( | 836 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService( |
| 833 Profile::IMPLICIT_ACCESS); | 837 Profile::IMPLICIT_ACCESS); |
| 834 if (!history) | 838 if (!history) |
| 835 return; | 839 return; |
| 836 history->AddPageNoVisitForBookmark(entry->url()); | 840 history->AddPageNoVisitForBookmark(entry->url()); |
| 837 | 841 |
| 838 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService( | 842 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService( |
| 839 Profile::IMPLICIT_ACCESS); | 843 Profile::IMPLICIT_ACCESS); |
| 840 if (!service) | 844 if (!service) |
| 841 return; | 845 return; |
| 842 const NavigationEntry::FaviconStatus& favicon(entry->favicon()); | 846 const NavigationEntry::FaviconStatus& favicon( |
| 847 entry->GetFavicon(history::FAVICON)); | |
| 843 if (!favicon.is_valid() || favicon.url().is_empty() || | 848 if (!favicon.is_valid() || favicon.url().is_empty() || |
| 844 favicon.bitmap().empty()) { | 849 favicon.bitmap().empty()) { |
| 845 return; | 850 return; |
| 846 } | 851 } |
| 847 std::vector<unsigned char> image_data; | 852 std::vector<unsigned char> image_data; |
| 848 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data); | 853 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data); |
| 849 service->SetFavicon( | 854 service->SetFavicon( |
| 850 entry->url(), favicon.url(), image_data, history::FAVICON); | 855 entry->url(), favicon.url(), image_data, history::FAVICON); |
| 851 } | 856 } |
| 852 | 857 |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1661 // clicking on a link); see bugs 1184641 and 980803. We don't want to | 1666 // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 1662 // clear the bubble when a user navigates to a named anchor in the same | 1667 // clear the bubble when a user navigates to a named anchor in the same |
| 1663 // page. | 1668 // page. |
| 1664 UpdateTargetURL(details.entry->page_id(), GURL()); | 1669 UpdateTargetURL(details.entry->page_id(), GURL()); |
| 1665 } | 1670 } |
| 1666 | 1671 |
| 1667 // Allow the new page to set the title again. | 1672 // Allow the new page to set the title again. |
| 1668 received_page_title_ = false; | 1673 received_page_title_ = false; |
| 1669 | 1674 |
| 1670 // Get the favicon, either from history or request it from the net. | 1675 // Get the favicon, either from history or request it from the net. |
| 1671 favicon_helper_->FetchFavicon(details.entry->url()); | 1676 favicon_helper_->FetchFavicon(details.entry->url(), history::FAVICON); |
| 1677 | |
| 1678 // We might totally disable fetching touch icon by using | |
| 1679 // '#if define(SUPPORT_TOUCH_ICON)' | |
| 1680 touch_icon_helper_->FetchFavicon(details.entry->url(), | |
| 1681 history::TOUCH_ICON | history::TOUCH_PRECOMPOSED_ICON); | |
| 1672 | 1682 |
| 1673 // Clear all page actions, blocked content notifications and browser actions | 1683 // Clear all page actions, blocked content notifications and browser actions |
| 1674 // for this tab, unless this is an in-page navigation. | 1684 // for this tab, unless this is an in-page navigation. |
| 1675 if (!details.is_in_page) { | 1685 if (!details.is_in_page) { |
| 1676 ExtensionService* service = profile()->GetExtensionService(); | 1686 ExtensionService* service = profile()->GetExtensionService(); |
| 1677 if (service) { | 1687 if (service) { |
| 1678 for (size_t i = 0; i < service->extensions()->size(); ++i) { | 1688 for (size_t i = 0; i < service->extensions()->size(); ++i) { |
| 1679 ExtensionAction* browser_action = | 1689 ExtensionAction* browser_action = |
| 1680 service->extensions()->at(i)->browser_action(); | 1690 service->extensions()->at(i)->browser_action(); |
| 1681 if (browser_action) { | 1691 if (browser_action) { |
| (...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2818 | 2828 |
| 2819 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2829 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 2820 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 2830 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 2821 rwh_view->SetSize(view()->GetContainerSize()); | 2831 rwh_view->SetSize(view()->GetContainerSize()); |
| 2822 } | 2832 } |
| 2823 | 2833 |
| 2824 void TabContents::OnOnlineStateChanged(bool online) { | 2834 void TabContents::OnOnlineStateChanged(bool online) { |
| 2825 render_view_host()->Send(new ViewMsg_NetworkStateChanged( | 2835 render_view_host()->Send(new ViewMsg_NetworkStateChanged( |
| 2826 render_view_host()->routing_id(), online)); | 2836 render_view_host()->routing_id(), online)); |
| 2827 } | 2837 } |
| OLD | NEW |