diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-16 18:35:52 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-16 18:35:52 +0000 |
commit | 47c5103a4c932bd88ed0a623d30cd6ff5cab0b44 (patch) | |
tree | b1cc5329401dfb157f977dc68a7b0844836cabef /chrome/browser/tab_contents | |
parent | e6dd571eecc5b3bbcf1151a805ff2fadcf02f979 (diff) | |
download | chromium_src-47c5103a4c932bd88ed0a623d30cd6ff5cab0b44.zip chromium_src-47c5103a4c932bd88ed0a623d30cd6ff5cab0b44.tar.gz chromium_src-47c5103a4c932bd88ed0a623d30cd6ff5cab0b44.tar.bz2 |
Makes the language detection happen with every page load
as we do with the page indexing. (The language detection was
previously done on demand when the extension related API was querying it.)
Once detected the language is stored on the navigation entry.
It'll be used for the upcoming translation feature.
Also I moved the existing language detection from the UI to
the file thread.
The change required few changes for the
chrome.tabs.detectLanguage extension API to still work.
BUG=None
TEST=Run the browser tests and unit-tests.
Review URL: http://codereview.chromium.org/492024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34728 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r-- | chrome/browser/tab_contents/navigation_entry.h | 10 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 48 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.h | 10 |
3 files changed, 61 insertions, 7 deletions
diff --git a/chrome/browser/tab_contents/navigation_entry.h b/chrome/browser/tab_contents/navigation_entry.h index 555edfc..a6ee1dc 100644 --- a/chrome/browser/tab_contents/navigation_entry.h +++ b/chrome/browser/tab_contents/navigation_entry.h @@ -382,6 +382,15 @@ class NavigationEntry { return restore_type_; } + // The ISO 639-1 language code (ex: en, fr, zh...) for the page. + // Can be empty if the language was not detected yet or is unknown. + void set_language(const std::string& language) { + language_ = language; + } + std::string language() const { + return language_; + } + private: // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING // Session/Tab restore save portions of this class so that it can be recreated @@ -405,6 +414,7 @@ class NavigationEntry { GURL user_typed_url_; bool has_post_data_; RestoreType restore_type_; + std::string language_; // ISO 639-1 language code. // This is a cached version of the result of GetTitleForDisplay. It prevents // us from having to do URL formatting on the URL evey time the title is diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index fd97827..aba37d7 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -1070,10 +1070,6 @@ void TabContents::StopFinding(bool clear_selection) { render_view_host()->StopFinding(clear_selection); } -void TabContents::GetPageLanguage() { - render_view_host()->GetPageLanguage(); -} - void TabContents::OnSavePage() { // If we can not save the page, try to download it. if (!SavePackage::IsSavableContents(contents_mime_type())) { @@ -1729,6 +1725,36 @@ void TabContents::OnDidGetApplicationInfo( delegate()->OnDidGetApplicationInfo(this, page_id); } +void TabContents::OnPageContents(const GURL& url, + int32 page_id, + const std::wstring& contents) { + // Don't index any https pages. People generally don't want their bank + // accounts, etc. indexed on their computer, especially since some of these + // things are not marked cachable. + // TODO(brettw) we may want to consider more elaborate heuristics such as + // the cachability of the page. We may also want to consider subframes (this + // test will still index subframes if the subframe is SSL). + if (!url.SchemeIsSecure()) { + Profile* p = profile(); + if (!p || p->IsOffTheRecord()) + return; + + HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS); + if (hs) + hs->SetPageContents(url, contents); + } + + // Detect the page language. The detection happens on the file thread. + // We get the TAB_LANGUAGE_DETERMINED notification when the language has been + // detected. + registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, + Source<RenderViewHost>(render_view_host())); + cld_helper_ = new CLDHelper(render_view_host()->process()->id(), + render_view_host()->routing_id(), + page_id, contents); + cld_helper_->DetectLanguage(); +} + void TabContents::DidStartProvisionalLoadForFrame( RenderViewHost* render_view_host, bool is_main_frame, @@ -2590,6 +2616,20 @@ void TabContents::Observe(NotificationType type, } #endif + case NotificationType::TAB_LANGUAGE_DETERMINED: { + DCHECK(cld_helper_.get()); + DCHECK(cld_helper_->language() == *Details<std::string>(details).ptr()); + + registrar_.Remove(this, NotificationType::TAB_LANGUAGE_DETERMINED, + Source<RenderViewHost>(source)); + + NavigationEntry* entry = controller_.GetActiveEntry(); + if (entry && entry->page_id() == cld_helper_->page_id()) + entry->set_language(cld_helper_->language()); + cld_helper_.release(); + break; + } + default: NOTREACHED(); } diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 2a84b8c..bd74602 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -18,6 +18,7 @@ #include "base/scoped_ptr.h" #include "chrome/browser/autocomplete/autocomplete_edit.h" #include "chrome/browser/cancelable_request.h" +#include "chrome/browser/cld_helper.h" #include "chrome/browser/dom_ui/dom_ui_factory.h" #include "chrome/browser/download/save_package.h" #include "chrome/browser/fav_icon_helper.h" @@ -536,9 +537,6 @@ class TabContents : public PageNavigator, return last_search_result_; } - // Get the most probable language of the text content in the tab. - void GetPageLanguage(); - // Misc state & callbacks ---------------------------------------------------- // Set whether the contents should block javascript message boxes or not. @@ -812,6 +810,9 @@ class TabContents : public PageNavigator, virtual void OnDidGetApplicationInfo( int32 page_id, const webkit_glue::WebApplicationInfo& info); + virtual void OnPageContents(const GURL& url, + int32 page_id, + const std::wstring& contents); // RenderViewHostDelegate::Resource implementation. virtual void DidStartProvisionalLoadForFrame(RenderViewHost* render_view_host, @@ -1176,6 +1177,9 @@ class TabContents : public PageNavigator, // profile scoped_refptr<URLRequestContextGetter> request_context_; + // Used to retrieve the language of the current page. + scoped_refptr<CLDHelper> cld_helper_; + // --------------------------------------------------------------------------- DISALLOW_COPY_AND_ASSIGN(TabContents); |