Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1014)

Side by Side Diff: chrome/browser/tab_contents/tab_contents.cc

Issue 523149: Revert 35735 - Relanding the language detection code.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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();
375 } 372 }
376 373
377 // static 374 // static
378 void TabContents::RegisterUserPrefs(PrefService* prefs) { 375 void TabContents::RegisterUserPrefs(PrefService* prefs) {
379 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true); 376 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
380 377
381 WebPreferences pref_defaults; 378 WebPreferences pref_defaults;
382 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled, 379 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
383 pref_defaults.javascript_enabled); 380 pref_defaults.javascript_enabled);
384 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled, 381 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 NotificationType::TAB_CONTENTS_HIDDEN, 630 NotificationType::TAB_CONTENTS_HIDDEN,
634 Source<TabContents>(this), 631 Source<TabContents>(this),
635 NotificationService::NoDetails()); 632 NotificationService::NoDetails());
636 } 633 }
637 634
638 void TabContents::Activate() { 635 void TabContents::Activate() {
639 if (delegate_) 636 if (delegate_)
640 delegate_->ActivateContents(this); 637 delegate_->ActivateContents(this);
641 } 638 }
642 639
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
661 void TabContents::ShowContents() { 640 void TabContents::ShowContents() {
662 if (render_widget_host_view()) 641 if (render_widget_host_view())
663 render_widget_host_view()->DidBecomeSelected(); 642 render_widget_host_view()->DidBecomeSelected();
664 } 643 }
665 644
666 void TabContents::HideContents() { 645 void TabContents::HideContents() {
667 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call 646 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
668 // our superclass HideContents(), because some callers want to be very picky 647 // our superclass HideContents(), because some callers want to be very picky
669 // about the order in which these get called. In addition to making the code 648 // about the order in which these get called. In addition to making the code
670 // here practically impossible to understand, this also means we end up 649 // here practically impossible to understand, this also means we end up
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 // by the user, but the UI has not been dismissed. 1069 // by the user, but the UI has not been dismissed.
1091 if (!clear_selection) 1070 if (!clear_selection)
1092 find_ui_active_ = false; 1071 find_ui_active_ = false;
1093 previous_find_text_ = find_text_; 1072 previous_find_text_ = find_text_;
1094 find_text_.clear(); 1073 find_text_.clear();
1095 find_op_aborted_ = true; 1074 find_op_aborted_ = true;
1096 last_search_result_ = FindNotificationDetails(); 1075 last_search_result_ = FindNotificationDetails();
1097 render_view_host()->StopFinding(clear_selection); 1076 render_view_host()->StopFinding(clear_selection);
1098 } 1077 }
1099 1078
1079 void TabContents::GetPageLanguage() {
1080 render_view_host()->GetPageLanguage();
1081 }
1082
1100 void TabContents::OnSavePage() { 1083 void TabContents::OnSavePage() {
1101 // If we can not save the page, try to download it. 1084 // If we can not save the page, try to download it.
1102 if (!SavePackage::IsSavableContents(contents_mime_type())) { 1085 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1103 DownloadManager* dlm = profile()->GetDownloadManager(); 1086 DownloadManager* dlm = profile()->GetDownloadManager();
1104 const GURL& current_page_url = GetURL(); 1087 const GURL& current_page_url = GetURL();
1105 if (dlm && current_page_url.is_valid()) 1088 if (dlm && current_page_url.is_valid())
1106 dlm->DownloadUrl(current_page_url, GURL(), "", this); 1089 dlm->DownloadUrl(current_page_url, GURL(), "", this);
1107 return; 1090 return;
1108 } 1091 }
1109 1092
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 1728
1746 void TabContents::OnDidGetApplicationInfo( 1729 void TabContents::OnDidGetApplicationInfo(
1747 int32 page_id, 1730 int32 page_id,
1748 const webkit_glue::WebApplicationInfo& info) { 1731 const webkit_glue::WebApplicationInfo& info) {
1749 web_app_info_ = info; 1732 web_app_info_ = info;
1750 1733
1751 if (delegate()) 1734 if (delegate())
1752 delegate()->OnDidGetApplicationInfo(this, page_id); 1735 delegate()->OnDidGetApplicationInfo(this, page_id);
1753 } 1736 }
1754 1737
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
1787 void TabContents::DidStartProvisionalLoadForFrame( 1738 void TabContents::DidStartProvisionalLoadForFrame(
1788 RenderViewHost* render_view_host, 1739 RenderViewHost* render_view_host,
1789 bool is_main_frame, 1740 bool is_main_frame,
1790 const GURL& url) { 1741 const GURL& url) {
1791 ProvisionalLoadDetails details(is_main_frame, 1742 ProvisionalLoadDetails details(is_main_frame,
1792 controller_.IsURLInPageNavigation(url), 1743 controller_.IsURLInPageNavigation(url),
1793 url, std::string(), false); 1744 url, std::string(), false);
1794 NotificationService::current()->Notify( 1745 NotificationService::current()->Notify(
1795 NotificationType::FRAME_PROVISIONAL_LOAD_START, 1746 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1796 Source<NavigationController>(&controller_), 1747 Source<NavigationController>(&controller_),
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after
2700 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt); 2651 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
2701 } 2652 }
2702 2653
2703 void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) { 2654 void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
2704 set_suppress_javascript_messages(suppress_message_boxes); 2655 set_suppress_javascript_messages(suppress_message_boxes);
2705 } 2656 }
2706 2657
2707 void TabContents::set_encoding(const std::string& encoding) { 2658 void TabContents::set_encoding(const std::string& encoding) {
2708 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); 2659 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2709 } 2660 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/tab_contents.h ('k') | chrome/browser/tab_contents/web_contents_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698