| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/tab_contents.h" | 5 #include "chrome/browser/tab_contents/tab_contents.h" |
| 6 | 6 |
| 7 #include "app/gfx/text_elider.h" | 7 #include "app/gfx/text_elider.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "base/file_version_info.h" | 10 #include "base/file_version_info.h" |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 // NULL if this contents was part of a window that closed. | 362 // NULL if this contents was part of a window that closed. |
| 363 if (GetNativeView()) | 363 if (GetNativeView()) |
| 364 ::DestroyWindow(GetNativeView()); | 364 ::DestroyWindow(GetNativeView()); |
| 365 #endif | 365 #endif |
| 366 | 366 |
| 367 // OnCloseStarted isn't called in unit tests. | 367 // OnCloseStarted isn't called in unit tests. |
| 368 if (!tab_close_start_time_.is_null()) { | 368 if (!tab_close_start_time_.is_null()) { |
| 369 UMA_HISTOGRAM_TIMES("Tab.Close", | 369 UMA_HISTOGRAM_TIMES("Tab.Close", |
| 370 base::TimeTicks::Now() - tab_close_start_time_); | 370 base::TimeTicks::Now() - tab_close_start_time_); |
| 371 } | 371 } |
| 372 |
| 373 if (cld_helper_.get()) |
| 374 cld_helper_->CancelLanguageDetection(); |
| 372 } | 375 } |
| 373 | 376 |
| 374 // static | 377 // static |
| 375 void TabContents::RegisterUserPrefs(PrefService* prefs) { | 378 void TabContents::RegisterUserPrefs(PrefService* prefs) { |
| 376 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true); | 379 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true); |
| 377 | 380 |
| 378 WebPreferences pref_defaults; | 381 WebPreferences pref_defaults; |
| 379 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled, | 382 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled, |
| 380 pref_defaults.javascript_enabled); | 383 pref_defaults.javascript_enabled); |
| 381 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled, | 384 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled, |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 NotificationType::TAB_CONTENTS_HIDDEN, | 633 NotificationType::TAB_CONTENTS_HIDDEN, |
| 631 Source<TabContents>(this), | 634 Source<TabContents>(this), |
| 632 NotificationService::NoDetails()); | 635 NotificationService::NoDetails()); |
| 633 } | 636 } |
| 634 | 637 |
| 635 void TabContents::Activate() { | 638 void TabContents::Activate() { |
| 636 if (delegate_) | 639 if (delegate_) |
| 637 delegate_->ActivateContents(this); | 640 delegate_->ActivateContents(this); |
| 638 } | 641 } |
| 639 | 642 |
| 643 void TabContents::PageLanguageDetected() { |
| 644 DCHECK(cld_helper_.get()); |
| 645 |
| 646 NavigationEntry* entry = controller_.GetActiveEntry(); |
| 647 if (process()->id() == cld_helper_->renderer_process_id() && |
| 648 entry && entry->page_id() == cld_helper_->page_id()) { |
| 649 entry->set_language(cld_helper_->language()); |
| 650 } |
| 651 |
| 652 std::string lang = cld_helper_->language(); |
| 653 NotificationService::current()->Notify( |
| 654 NotificationType::TAB_LANGUAGE_DETERMINED, |
| 655 Source<RenderViewHost>(render_view_host()), |
| 656 Details<std::string>(&lang)); |
| 657 |
| 658 cld_helper_ = NULL; // Release the CLD helper. |
| 659 } |
| 660 |
| 640 void TabContents::ShowContents() { | 661 void TabContents::ShowContents() { |
| 641 if (render_widget_host_view()) | 662 if (render_widget_host_view()) |
| 642 render_widget_host_view()->DidBecomeSelected(); | 663 render_widget_host_view()->DidBecomeSelected(); |
| 643 } | 664 } |
| 644 | 665 |
| 645 void TabContents::HideContents() { | 666 void TabContents::HideContents() { |
| 646 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call | 667 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call |
| 647 // our superclass HideContents(), because some callers want to be very picky | 668 // our superclass HideContents(), because some callers want to be very picky |
| 648 // about the order in which these get called. In addition to making the code | 669 // about the order in which these get called. In addition to making the code |
| 649 // here practically impossible to understand, this also means we end up | 670 // here practically impossible to understand, this also means we end up |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 // by the user, but the UI has not been dismissed. | 1090 // by the user, but the UI has not been dismissed. |
| 1070 if (!clear_selection) | 1091 if (!clear_selection) |
| 1071 find_ui_active_ = false; | 1092 find_ui_active_ = false; |
| 1072 previous_find_text_ = find_text_; | 1093 previous_find_text_ = find_text_; |
| 1073 find_text_.clear(); | 1094 find_text_.clear(); |
| 1074 find_op_aborted_ = true; | 1095 find_op_aborted_ = true; |
| 1075 last_search_result_ = FindNotificationDetails(); | 1096 last_search_result_ = FindNotificationDetails(); |
| 1076 render_view_host()->StopFinding(clear_selection); | 1097 render_view_host()->StopFinding(clear_selection); |
| 1077 } | 1098 } |
| 1078 | 1099 |
| 1079 void TabContents::GetPageLanguage() { | |
| 1080 render_view_host()->GetPageLanguage(); | |
| 1081 } | |
| 1082 | |
| 1083 void TabContents::OnSavePage() { | 1100 void TabContents::OnSavePage() { |
| 1084 // If we can not save the page, try to download it. | 1101 // If we can not save the page, try to download it. |
| 1085 if (!SavePackage::IsSavableContents(contents_mime_type())) { | 1102 if (!SavePackage::IsSavableContents(contents_mime_type())) { |
| 1086 DownloadManager* dlm = profile()->GetDownloadManager(); | 1103 DownloadManager* dlm = profile()->GetDownloadManager(); |
| 1087 const GURL& current_page_url = GetURL(); | 1104 const GURL& current_page_url = GetURL(); |
| 1088 if (dlm && current_page_url.is_valid()) | 1105 if (dlm && current_page_url.is_valid()) |
| 1089 dlm->DownloadUrl(current_page_url, GURL(), "", this); | 1106 dlm->DownloadUrl(current_page_url, GURL(), "", this); |
| 1090 return; | 1107 return; |
| 1091 } | 1108 } |
| 1092 | 1109 |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 | 1745 |
| 1729 void TabContents::OnDidGetApplicationInfo( | 1746 void TabContents::OnDidGetApplicationInfo( |
| 1730 int32 page_id, | 1747 int32 page_id, |
| 1731 const webkit_glue::WebApplicationInfo& info) { | 1748 const webkit_glue::WebApplicationInfo& info) { |
| 1732 web_app_info_ = info; | 1749 web_app_info_ = info; |
| 1733 | 1750 |
| 1734 if (delegate()) | 1751 if (delegate()) |
| 1735 delegate()->OnDidGetApplicationInfo(this, page_id); | 1752 delegate()->OnDidGetApplicationInfo(this, page_id); |
| 1736 } | 1753 } |
| 1737 | 1754 |
| 1755 void TabContents::OnPageContents(const GURL& url, |
| 1756 int renderer_process_id, |
| 1757 int32 page_id, |
| 1758 const std::wstring& contents) { |
| 1759 // Don't index any https pages. People generally don't want their bank |
| 1760 // accounts, etc. indexed on their computer, especially since some of these |
| 1761 // things are not marked cachable. |
| 1762 // TODO(brettw) we may want to consider more elaborate heuristics such as |
| 1763 // the cachability of the page. We may also want to consider subframes (this |
| 1764 // test will still index subframes if the subframe is SSL). |
| 1765 if (!url.SchemeIsSecure()) { |
| 1766 Profile* p = profile(); |
| 1767 if (p && !p->IsOffTheRecord()) { |
| 1768 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS); |
| 1769 if (hs) |
| 1770 hs->SetPageContents(url, contents); |
| 1771 } |
| 1772 } |
| 1773 |
| 1774 // Detect the page language. The detection happens on the file thread. |
| 1775 // PageLanguageDetected() is called when the language has been detected. |
| 1776 if (cld_helper_.get()) { |
| 1777 // There is already a language detection in flight, cancel it to avoid |
| 1778 // having multiple PageLanguageDetected() notifications on this tab. (They |
| 1779 // would cause a crasher as cld_helper_ would be NULLed on the 1st |
| 1780 // notification). |
| 1781 cld_helper_->CancelLanguageDetection(); |
| 1782 } |
| 1783 cld_helper_ = new CLDHelper(this, renderer_process_id, page_id, contents); |
| 1784 cld_helper_->DetectLanguage(); |
| 1785 } |
| 1786 |
| 1738 void TabContents::DidStartProvisionalLoadForFrame( | 1787 void TabContents::DidStartProvisionalLoadForFrame( |
| 1739 RenderViewHost* render_view_host, | 1788 RenderViewHost* render_view_host, |
| 1740 bool is_main_frame, | 1789 bool is_main_frame, |
| 1741 const GURL& url) { | 1790 const GURL& url) { |
| 1742 ProvisionalLoadDetails details(is_main_frame, | 1791 ProvisionalLoadDetails details(is_main_frame, |
| 1743 controller_.IsURLInPageNavigation(url), | 1792 controller_.IsURLInPageNavigation(url), |
| 1744 url, std::string(), false); | 1793 url, std::string(), false); |
| 1745 NotificationService::current()->Notify( | 1794 NotificationService::current()->Notify( |
| 1746 NotificationType::FRAME_PROVISIONAL_LOAD_START, | 1795 NotificationType::FRAME_PROVISIONAL_LOAD_START, |
| 1747 Source<NavigationController>(&controller_), | 1796 Source<NavigationController>(&controller_), |
| (...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2651 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt); | 2700 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt); |
| 2652 } | 2701 } |
| 2653 | 2702 |
| 2654 void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) { | 2703 void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) { |
| 2655 set_suppress_javascript_messages(suppress_message_boxes); | 2704 set_suppress_javascript_messages(suppress_message_boxes); |
| 2656 } | 2705 } |
| 2657 | 2706 |
| 2658 void TabContents::set_encoding(const std::string& encoding) { | 2707 void TabContents::set_encoding(const std::string& encoding) { |
| 2659 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); | 2708 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); |
| 2660 } | 2709 } |
| OLD | NEW |