summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-15 17:05:46 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-15 17:05:46 +0000
commitba9daa6c087fb6320f32f47561b2d06a4c04c41b (patch)
tree6a6abd8e2ba2e0f91a1fe0f0656ed7c2639eb140 /chrome/browser/tab_contents
parent01938c95315cec08d8bfed833e02374626ee9961 (diff)
downloadchromium_src-ba9daa6c087fb6320f32f47561b2d06a4c04c41b.zip
chromium_src-ba9daa6c087fb6320f32f47561b2d06a4c04c41b.tar.gz
chromium_src-ba9daa6c087fb6320f32f47561b2d06a4c04c41b.tar.bz2
3rd attempt at landing the language detection on page load.
A memory error has been fixed in the CLD library in the meantime. This should hopefully fixes the crashers in the reliability tests. Note that this version is actually simpler than the original review since the detection is now performed in the renderer. (So the CLD code runs sandboxed.) Original review: http://codereview.chromium.org/492024/show BUG=30662 TEST=Run the unit-tests. Review URL: http://codereview.chromium.org/518075 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36362 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r--chrome/browser/tab_contents/navigation_entry.h10
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc37
-rw-r--r--chrome/browser/tab_contents/tab_contents.h8
3 files changed, 48 insertions, 7 deletions
diff --git a/chrome/browser/tab_contents/navigation_entry.h b/chrome/browser/tab_contents/navigation_entry.h
index e679c10..df6ad06 100644
--- a/chrome/browser/tab_contents/navigation_entry.h
+++ b/chrome/browser/tab_contents/navigation_entry.h
@@ -389,6 +389,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
@@ -413,6 +422,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 10efa22..bf0bd56 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -1076,10 +1076,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())) {
@@ -1735,6 +1731,39 @@ void TabContents::OnDidGetApplicationInfo(
delegate()->OnDidGetApplicationInfo(this, page_id);
}
+void TabContents::OnPageContents(const GURL& url,
+ int renderer_process_id,
+ int32 page_id,
+ const std::wstring& contents,
+ const std::string& language) {
+ // 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()) {
+ HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
+ if (hs)
+ hs->SetPageContents(url, contents);
+ }
+ }
+
+ NavigationEntry* entry = controller_.GetActiveEntry();
+ if (process()->id() == renderer_process_id &&
+ entry && entry->page_id() == page_id) {
+ entry->set_language(language);
+ }
+
+ std::string lang = language;
+ NotificationService::current()->Notify(
+ NotificationType::TAB_LANGUAGE_DETERMINED,
+ Source<RenderViewHost>(render_view_host()),
+ Details<std::string>(&lang));
+}
+
void TabContents::DidStartProvisionalLoadForFrame(
RenderViewHost* render_view_host,
bool is_main_frame,
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index 112675d..6333b59 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -538,9 +538,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.
@@ -814,6 +811,11 @@ class TabContents : public PageNavigator,
virtual void OnDidGetApplicationInfo(
int32 page_id,
const webkit_glue::WebApplicationInfo& info);
+ virtual void OnPageContents(const GURL& url,
+ int renderer_process_id,
+ int32 page_id,
+ const std::wstring& contents,
+ const std::string& language);
// RenderViewHostDelegate::Resource implementation.
virtual void DidStartProvisionalLoadForFrame(RenderViewHost* render_view_host,