diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-17 20:17:00 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-17 20:17:00 +0000 |
commit | f345876ca7aac5ff6f4e08242891b800c48cedcd (patch) | |
tree | d8096238c5a3acad0f08a69f45744d5c843875f5 | |
parent | f7b7ffe4267e517b99c24391a51622f29c0476f0 (diff) | |
download | chromium_src-f345876ca7aac5ff6f4e08242891b800c48cedcd.zip chromium_src-f345876ca7aac5ff6f4e08242891b800c48cedcd.tar.gz chromium_src-f345876ca7aac5ff6f4e08242891b800c48cedcd.tar.bz2 |
Reverting the CLD CL altogether, the reliability bot is still red.
BUG=30681
TEST=None
TBR=brettw
Review URL: http://codereview.chromium.org/504048
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34867 0039d316-1c4b-4281-b951-d872f2087c98
25 files changed, 704 insertions, 353 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 52eedad..83ec198 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1189,8 +1189,8 @@ void Browser::OpenCreateShortcutsDialog() { DCHECK(pending_web_app_action_ == NONE); pending_web_app_action_ = CREATE_SHORTCUT; - // Start fetching web app info for CreateApplicationShortcut dialog and show - // the dialog when the data is available in OnDidGetApplicationInfo. + // Start fetching web app info for CreateApplicatoinShortcut dialog and + // show the dialog when the data is available in OnDidGetApplicationInfo. current_tab->render_view_host()->GetApplicationInfo(entry->page_id()); #else NOTIMPLEMENTED(); diff --git a/chrome/browser/browser_browsertest.cc b/chrome/browser/browser_browsertest.cc index 62d3a51..756b7dc 100644 --- a/chrome/browser/browser_browsertest.cc +++ b/chrome/browser/browser_browsertest.cc @@ -288,38 +288,3 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, FaviconOfOnloadRedirectToAnchorPage) { controller().GetActiveEntry(); EXPECT_EQ(expected_favicon_url.spec(), entry->favicon().url().spec()); } - -// The CLD library only works on Windows at this point. -#if defined(OS_WIN) -// Tests that the CLD (Compact Language Detection) works properly. -// TODO(jcampan): http://crbug.com/30662 the language detection has been -// temporarily disabled. -IN_PROC_BROWSER_TEST_F(BrowserTest, DISABLED_PageLanguageDetection) { - static const wchar_t kDocRoot[] = L"chrome/test/data"; - scoped_refptr<HTTPTestServer> server( - HTTPTestServer::CreateServer(kDocRoot, NULL)); - ASSERT_TRUE(NULL != server.get()); - - TabContents* current_tab = browser()->GetSelectedTabContents(); - - // Navigate to a page in English. - ui_test_utils::NavigateToURL( - browser(), GURL(server->TestServerPage("files/english_page.html"))); - NavigationEntry* entry = current_tab->controller().GetActiveEntry(); - ASSERT_TRUE(NULL != entry); - EXPECT_TRUE(entry->language().empty()); - std::string lang = ui_test_utils::WaitForLanguageDetection(current_tab); - EXPECT_EQ("en", lang); - EXPECT_EQ("en", entry->language()); - - // Now navigate to a page in French. - ui_test_utils::NavigateToURL( - browser(), GURL(server->TestServerPage("files/french_page.html"))); - entry = current_tab->controller().GetActiveEntry(); - ASSERT_TRUE(NULL != entry); - EXPECT_TRUE(entry->language().empty()); - lang = ui_test_utils::WaitForLanguageDetection(current_tab); - EXPECT_EQ("fr", lang); - EXPECT_EQ("fr", entry->language()); -} -#endif diff --git a/chrome/browser/cld_helper.cc b/chrome/browser/cld_helper.cc deleted file mode 100644 index 4bed10e..0000000 --- a/chrome/browser/cld_helper.cc +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/cld_helper.h" - -#include "chrome/browser/chrome_thread.h" -#include "chrome/browser/renderer_host/render_view_host.h" -#include "chrome/common/notification_service.h" - -#if defined(OS_WIN) -// TODO(port): The compact language detection library works only for Windows. -#include "third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/win/cld_unicodetext.h" -#endif - -CLDHelper::CLDHelper(int process_id, int routing_id, int page_id, - const std::wstring& page_content) - : process_id_(process_id), - routing_id_(routing_id), - page_id_(page_id), - page_content_(page_content) { -} - -void CLDHelper::DetectLanguage() { - // Balanced in DetectionDone. - AddRef(); - - // Do the actual work on the file thread. - ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, - NewRunnableMethod(this, &CLDHelper::DoDetectLanguage)); -} - -void CLDHelper::DoDetectLanguage() { -#if defined(OS_WIN) // Only for windows. -// TODO(jcampan): http://crbug.com/30662 the detection language library crashes -// on some sites and has been temporarily disabled. -#if 0 - int num_languages = 0; - bool is_reliable = false; - const char* language_iso_code = LanguageCodeISO639_1( - DetectLanguageOfUnicodeText(page_content_.c_str(), true, &is_reliable, - &num_languages, NULL)); - language_ = language_iso_code; -#endif -#else - // TODO(jcampan): port the compact language detection library. - NOTIMPLEMENTED(); -#endif - - // Work is done, notify the RenderViewHost on the UI thread. - ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, - NewRunnableMethod(this, &CLDHelper::DetectionDone)); -} - -void CLDHelper::DetectionDone() { - RenderViewHost* rvh = RenderViewHost::FromID(process_id_, routing_id_); - // The RenderViewHost might be gone (tab closed for example) while we were - // performing the detection. - if (rvh) { - NotificationService::current()->Notify( - NotificationType::TAB_LANGUAGE_DETERMINED, - Source<RenderViewHost>(rvh), - Details<std::string>(&language_)); - } - - // Remove the ref we added to ourself in DetectLanguage(). - Release(); -} diff --git a/chrome/browser/cld_helper.h b/chrome/browser/cld_helper.h deleted file mode 100644 index 0251145..0000000 --- a/chrome/browser/cld_helper.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CLD_HELPER_H_ -#define CHROME_BROWSER_CLD_HELPER_H_ - -#include <string> - -#include "base/ref_counted.h" - -// The CLDHelper class detects the language of a page, using the toolbar CLD -// detection library. (CLD stands for Compact Language Detection.) -// It should be created and the detection process started on the same thread. -// The detection happens on the file thread and a TAB_LANGUAGE_DETERMINED -// notification is sent (on the UI thread) when the language has been detected. -class CLDHelper : public base::RefCountedThreadSafe<CLDHelper> { - public: - // |process_id| and |routing_id| should reference the RenderViewHost this page - // is related to. |page_id| is the id of the page for the specified - // |page_contents|. - CLDHelper(int process_id, - int routing_id, - int page_id, - const std::wstring& page_content); - - // Starts the process of detecting the language of the page. - void DetectLanguage(); - - int page_id() const { return page_id_; } - - std::string language() const { return language_; } - - private: - // Private because the class is ref counted. - friend class base::RefCountedThreadSafe<CLDHelper>; - ~CLDHelper() {} - - // Performs the actual work of detecting the language. - void DoDetectLanguage(); - - // Invoked on the UI thread once the language has been detected. - void DetectionDone(); - - // The process id and routing id of the RenderViewHost for which the language - // is being detected. - int process_id_; - int routing_id_; - - // The id and content of the page for which the language is being detected. - int page_id_; - std::wstring page_content_; - - // The language that was detected. - std::string language_; - - DISALLOW_COPY_AND_ASSIGN(CLDHelper); -}; - -#endif // CHROME_BROWSER_CLD_HELPER_H_ - diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc index cd68b1a..97ef316 100644 --- a/chrome/browser/extensions/extension_browsertests_misc.cc +++ b/chrome/browser/extensions/extension_browsertests_misc.cc @@ -89,9 +89,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, Toolstrip) { EXPECT_TRUE(result); #if defined(OS_WIN) -// TODO(jcampan): http://crbug.com/30662 the language detection has been -// temporarily disabled. -#if 0 // http://crbug.com/29896 - tabs.detectLanguage is Windows only // Test for compact language detection API. First navigate to a (static) html @@ -108,7 +105,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, Toolstrip) { host->render_view_host(), L"", L"testTabsLanguageAPI()", &result); EXPECT_TRUE(result); #endif -#endif } IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ExtensionViews) { diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc index a97e098..64ee348 100644 --- a/chrome/browser/extensions/extension_tabs_module.cc +++ b/chrome/browser/extensions/extension_tabs_module.cc @@ -839,24 +839,15 @@ bool DetectTabLanguageFunction::RunImpl() { return false; } - AddRef(); // Balanced in GotLanguage() - - NavigationEntry* entry = contents->controller().GetActiveEntry(); - if (entry) { - std::string language = entry->language(); - if (!language.empty()) { - // Delay the callback invocation until after the current JS call has - // returned. - MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( - this, &DetectTabLanguageFunction::GotLanguage, language)); - return true; - } - } - // The tab contents does not know its language yet. Let's wait until it - // receives it. + // Figure out what language |contents| contains. This sends an async call via + // the browser to the renderer to determine the language of the tab the + // renderer has. The renderer sends back the language of the tab after the + // tab loads (it may be delayed) to the browser, which in turn notifies this + // object that the language has been received. + contents->GetPageLanguage(); registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, - Source<RenderViewHost>(contents->render_view_host())); - + NotificationService::AllSources()); + AddRef(); // balanced in Observe() return true; } @@ -865,16 +856,9 @@ void DetectTabLanguageFunction::Observe(NotificationType type, const NotificationDetails& details) { DCHECK(type == NotificationType::TAB_LANGUAGE_DETERMINED); std::string language(*Details<std::string>(details).ptr()); - registrar_.Remove(this, NotificationType::TAB_LANGUAGE_DETERMINED, source); - - GotLanguage(language); -} - -void DetectTabLanguageFunction::GotLanguage(const std::string& language) { result_.reset(Value::CreateStringValue(language.c_str())); SendResponse(true); - - Release(); // Balanced in Run() + Release(); // balanced in Run() } // static helpers diff --git a/chrome/browser/extensions/extension_tabs_module.h b/chrome/browser/extensions/extension_tabs_module.h index 4a0ec45..1fa7f21 100644 --- a/chrome/browser/extensions/extension_tabs_module.h +++ b/chrome/browser/extensions/extension_tabs_module.h @@ -131,7 +131,6 @@ class DetectTabLanguageFunction : public AsyncExtensionFunction, virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details); - void GotLanguage(const std::string& language); NotificationRegistrar registrar_; DECLARE_EXTENSION_FUNCTION_NAME("tabs.detectLanguage") }; diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index c164fb8..bb7e99d 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -733,9 +733,10 @@ bool BrowserRenderProcessHost::Send(IPC::Message* msg) { void BrowserRenderProcessHost::OnMessageReceived(const IPC::Message& msg) { mark_child_process_activity_time(); if (msg.routing_id() == MSG_ROUTING_CONTROL) { - // Dispatch control messages. + // dispatch control messages bool msg_is_ok = true; IPC_BEGIN_MESSAGE_MAP_EX(BrowserRenderProcessHost, msg, msg_is_ok) + IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents) IPC_MESSAGE_HANDLER(ViewHostMsg_UpdatedCacheStats, OnUpdatedCacheStats) IPC_MESSAGE_HANDLER(ViewHostMsg_SuddenTerminationChanged, @@ -759,7 +760,7 @@ void BrowserRenderProcessHost::OnMessageReceived(const IPC::Message& msg) { return; } - // Dispatch incoming messages to the appropriate TabContents. + // dispatch incoming messages to the appropriate TabContents IPC::Channel::Listener* listener = GetListenerByID(msg.routing_id()); if (!listener) { if (msg.is_sync()) { @@ -833,6 +834,18 @@ void BrowserRenderProcessHost::OnChannelError() { // TODO(darin): clean this up } +void BrowserRenderProcessHost::OnPageContents(const GURL& url, + int32 page_id, + const std::wstring& contents) { + Profile* p = profile(); + if (!p || p->IsOffTheRecord()) + return; + + HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS); + if (hs) + hs->SetPageContents(url, contents); +} + void BrowserRenderProcessHost::OnUpdatedCacheStats( const WebCache::UsageStats& stats) { WebCacheManager::GetInstance()->ObserveStats(id(), stats); diff --git a/chrome/browser/renderer_host/browser_render_process_host.h b/chrome/browser/renderer_host/browser_render_process_host.h index a5c536d..cd94bf5 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.h +++ b/chrome/browser/renderer_host/browser_render_process_host.h @@ -104,6 +104,8 @@ class BrowserRenderProcessHost : public RenderProcessHost, friend class VisitRelayingRenderProcessHost; // Control message handlers. + void OnPageContents(const GURL& url, int32 page_id, + const std::wstring& contents); void OnUpdatedCacheStats(const WebKit::WebCache::UsageStats& stats); void SuddenTerminationChanged(bool enabled); void OnExtensionAddListener(const std::string& event_name); diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 136ad7a..d67fda3 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -46,6 +46,8 @@ #if defined(OS_WIN) // TODO(port): accessibility not yet implemented. See http://crbug.com/8288. #include "chrome/browser/browser_accessibility_manager.h" +// TODO(port): The compact language detection library works only for Windows. +#include "third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/win/cld_unicodetext.h" #endif using base::TimeDelta; @@ -421,6 +423,10 @@ void RenderViewHost::StopFinding(bool clear_selection) { Send(new ViewMsg_StopFinding(routing_id(), clear_selection)); } +void RenderViewHost::GetPageLanguage() { + Send(new ViewMsg_DeterminePageText(routing_id())); +} + void RenderViewHost::Zoom(PageZoom::Function function) { Send(new ViewMsg_Zoom(routing_id(), function)); } @@ -753,6 +759,8 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError, OnMsgDidFailProvisionalLoadWithError) IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnMsgFindReply) + IPC_MESSAGE_HANDLER(ViewMsg_DeterminePageText_Reply, + OnDeterminePageTextReply) IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCodeFinished, OnExecuteCodeFinished) IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFavIconURL, OnMsgUpdateFavIconURL) @@ -836,7 +844,6 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_AccessibilityFocusChange, OnAccessibilityFocusChange) IPC_MESSAGE_HANDLER(ViewHostMsg_OnCSSInserted, OnCSSInserted) - IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents) // Have the super handle all other messages. IPC_MESSAGE_UNHANDLED(RenderWidgetHost::OnMessageReceived(msg)) IPC_END_MESSAGE_MAP_EX() @@ -1140,6 +1147,22 @@ void RenderViewHost::OnMsgFindReply(int request_id, Send(new ViewMsg_FindReplyACK(routing_id())); } +void RenderViewHost::OnDeterminePageTextReply( + const std::wstring& page_text) { +#if defined(OS_WIN) // Only for windows. + int num_languages = 0; + bool is_reliable = false; + const char* language_iso_code = LanguageCodeISO639_1( + DetectLanguageOfUnicodeText(page_text.c_str(), true, &is_reliable, + &num_languages, NULL)); + std::string language(language_iso_code); + NotificationService::current()->Notify( + NotificationType::TAB_LANGUAGE_DETERMINED, + Source<RenderViewHost>(this), + Details<std::string>(&language)); +#endif +} + void RenderViewHost::OnExecuteCodeFinished(int request_id, bool success) { std::pair<int, bool> result_details(request_id, success); NotificationService::current()->Notify( @@ -1760,13 +1783,3 @@ void RenderViewHost::OnAccessibilityFocusChange(int acc_obj_id) { void RenderViewHost::OnCSSInserted() { delegate_->DidInsertCSS(); } - -void RenderViewHost::OnPageContents(const GURL& url, - int32 page_id, - const std::wstring& contents) { - RenderViewHostDelegate::BrowserIntegration* integration_delegate = - delegate_->GetBrowserIntegrationDelegate(); - if (!integration_delegate) - return; - integration_delegate->OnPageContents(url, page_id, contents); -} diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index f3b1a32..0d923ca 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -212,6 +212,12 @@ class RenderViewHost : public RenderWidgetHost, // clear the selection on the focused frame. void StopFinding(bool clear_selection); + // Get the most probable language of the text content in the tab. This sends + // a message to the render view to get the content of the page as text. The + // caller gets the language via the NotificationService by registering to the + // NotificationType TAB_LANGUAGE_DETERMINED. + void GetPageLanguage(); + // Change the zoom level of a page. void Zoom(PageZoom::Function function); @@ -417,22 +423,22 @@ class RenderViewHost : public RenderWidgetHost, // Creates a new RenderWidget with the given route id. void CreateNewWidget(int route_id, bool activatable); - // Sends the response to an extension api call. + // Send the response to an extension api call. void SendExtensionResponse(int request_id, bool success, const std::string& response, const std::string& error); - // Sends a response to an extension api call that it was blocked for lack of + // Send a response to an extension api call that it was blocked for lack of // permission. void BlockExtensionRequest(int request_id); - // Notifies the renderer that its view type has changed. + // Notify the renderer that its view type has changed. void ViewTypeChanged(ViewType::Type type); - // Tells the renderer which browser window it is being attached to. + // Tell renderer which browser window it is being attached to. void UpdateBrowserWindowId(int window_id); - // Tells the render view that a custom context action has been selected. + // Tell render view that custom context action has been selected. void PerformCustomContextMenuAction(unsigned action); protected: @@ -489,6 +495,7 @@ class RenderViewHost : public RenderWidgetHost, const gfx::Rect& selection_rect, int active_match_ordinal, bool final_update); + void OnDeterminePageTextReply(const std::wstring& tab_text); void OnExecuteCodeFinished(int request_id, bool success); void OnMsgUpdateFavIconURL(int32 page_id, const GURL& icon_url); void OnMsgDidDownloadFavIcon(int id, @@ -586,9 +593,6 @@ class RenderViewHost : public RenderWidgetHost, void OnExtensionPostMessage(int port_id, const std::string& message); void OnAccessibilityFocusChange(int acc_obj_id); void OnCSSInserted(); - void OnPageContents(const GURL& url, - int32 page_id, - const std::wstring& contents); private: friend class TestRenderViewHost; diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index cf426f6..c3df62d 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -217,11 +217,6 @@ class RenderViewHostDelegate { virtual void OnDidGetApplicationInfo( int32 page_id, const webkit_glue::WebApplicationInfo& app_info) = 0; - - // Notification that the contents of the page has been loaded. - virtual void OnPageContents(const GURL& url, - int32 page_id, - const std::wstring& contents) = 0; }; // Resource ------------------------------------------------------------------ diff --git a/chrome/browser/tab_contents/navigation_entry.h b/chrome/browser/tab_contents/navigation_entry.h index df6ad06..e679c10 100644 --- a/chrome/browser/tab_contents/navigation_entry.h +++ b/chrome/browser/tab_contents/navigation_entry.h @@ -389,15 +389,6 @@ 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 @@ -422,7 +413,6 @@ 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 b4acc38..fd97827 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -1070,6 +1070,10 @@ 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())) { @@ -1725,40 +1729,6 @@ 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); - } - - -// TODO(port): Port detection language to Mac and Linux. -#if defined(OS_WIN) - // 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(); -#endif -} - void TabContents::DidStartProvisionalLoadForFrame( RenderViewHost* render_view_host, bool is_main_frame, @@ -2620,20 +2590,6 @@ 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 bd74602..2a84b8c 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -18,7 +18,6 @@ #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" @@ -537,6 +536,9 @@ 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. @@ -810,9 +812,6 @@ 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, @@ -1177,9 +1176,6 @@ 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); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 7779dd1..13e6383 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -295,8 +295,6 @@ 'browser/chromeos/usb_mount_observer.h', 'browser/chromeos/version_loader.cc', 'browser/chromeos/version_loader.h', - 'browser/cld_helper.cc', - 'browser/cld_helper.h', 'browser/cocoa/about_ipc_bridge.h', 'browser/cocoa/about_ipc_bridge.mm', 'browser/cocoa/about_ipc_controller.h', diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index dfd87f3..97a28f3 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -223,9 +223,8 @@ class NotificationType { // is the InfoBubble. INFO_BUBBLE_CREATED, - // Sent when the language (English, French...) for a page has been detected. - // The details Details<std::string> contain the ISO 639-1 language code and - // the source is Source<RenderViewHost>. + // Sent after a call to RenderViewHost::DeterminePageLanguage. The details + // are Details<std::string> and the source is Source<RenderViewHost>. TAB_LANGUAGE_DETERMINED, // Send after the code is run in specified tab. diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 5772159..3f9a1f1 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -257,6 +257,14 @@ IPC_BEGIN_MESSAGES(View) string16 /* search_text */, WebKit::WebFindOptions) + // Send from the browser to the rendered to get the text content of the page. + IPC_MESSAGE_ROUTED0(ViewMsg_DeterminePageText) + + // Send from the renderer to the browser to return the text content of the + // page. + IPC_MESSAGE_ROUTED1(ViewMsg_DeterminePageText_Reply, + std::wstring /* the language */) + // Send from the renderer to the browser to return the script running result. IPC_MESSAGE_ROUTED2(ViewMsg_ExecuteCodeFinished, int, /* request id */ @@ -1113,7 +1121,7 @@ IPC_BEGIN_MESSAGES(ViewHost) IPC_MESSAGE_ROUTED1(ViewHostMsg_UpdateSpellingPanelWithMisspelledWord, string16 /* the word to update the panel with */) - // Initiates a download based on user actions like 'ALT+click'. + // Initiate a download based on user actions like 'ALT+click'. IPC_MESSAGE_ROUTED2(ViewHostMsg_DownloadUrl, GURL /* url */, GURL /* referrer */) @@ -1131,11 +1139,9 @@ IPC_BEGIN_MESSAGES(ViewHost) bool /* out - success */, std::wstring /* out - prompt field */) - // Provides the contents for the given page that was loaded recently. - IPC_MESSAGE_ROUTED3(ViewHostMsg_PageContents, - GURL /* URL of the page */, - int32 /* page id */, - std::wstring /*page contents */) + // Sets the contents for the given page (URL and page ID are the first two + // arguments) given the contents that is the 3rd. + IPC_MESSAGE_CONTROL3(ViewHostMsg_PageContents, GURL, int32, std::wstring) // Used to get the extension message bundle. IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_GetExtensionMessageBundle, @@ -1160,13 +1166,13 @@ IPC_BEGIN_MESSAGES(ViewHost) // user right clicked. IPC_MESSAGE_ROUTED1(ViewHostMsg_ContextMenu, ContextMenuParams) - // Requests that the given URL be opened in the specified manner. + // Request that the given URL be opened in the specified manner. IPC_MESSAGE_ROUTED3(ViewHostMsg_OpenURL, GURL /* url */, GURL /* referrer */, WindowOpenDisposition /* disposition */) - // Notifies that the preferred size of the content changed. + // Notify that the preferred size of the content changed. IPC_MESSAGE_ROUTED1(ViewHostMsg_DidContentsPreferredSizeChange, gfx::Size /* pref_size */) diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index c27fb1c..baac373 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -245,6 +245,7 @@ RenderView::RenderView(RenderThreadBase* render_thread, send_preferred_size_changes_(false), ALLOW_THIS_IN_INITIALIZER_LIST( notification_provider_(new NotificationProvider(this))), + determine_page_text_after_loading_stops_(false), view_type_(ViewType::INVALID), browser_window_id_(-1), last_top_level_navigation_page_id_(-1), @@ -429,6 +430,7 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) + IPC_MESSAGE_HANDLER(ViewMsg_DeterminePageText, OnDeterminePageText) IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingHost, OnSetZoomLevelForLoadingHost) @@ -580,18 +582,23 @@ void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) { if (!preliminary_capture) last_indexed_page_id_ = load_id; - // Get the URL for this page. + // get the URL for this page GURL url(main_frame->url()); if (url.is_empty()) return; - // Retrieve the frame's full text. + // full text std::wstring contents; CaptureText(main_frame, &contents); if (contents.size()) { - // Send the text to the browser for indexing (the browser might decide not - // to index, if the URL is HTTPS for instance) and language discovery. - Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents)); + // Send the text to the browser for indexing. + Send(new ViewHostMsg_PageContents(url, load_id, contents)); + } + + // Send over text content of this page to the browser. + if (determine_page_text_after_loading_stops_) { + determine_page_text_after_loading_stops_ = false; + Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents)); } // thumbnail @@ -603,6 +610,15 @@ void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) { if (!frame) return; + // 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 (GURL(frame->url()).SchemeIsSecure()) + return; + #ifdef TIME_TEXT_RETRIEVAL double begin = time_util::GetHighResolutionTimeNow(); #endif @@ -2948,6 +2964,23 @@ void RenderView::OnFind(int request_id, const string16& search_text, } } +void RenderView::OnDeterminePageText() { + if (!is_loading_) { + if (!webview()) + return; + WebFrame* main_frame = webview()->mainFrame(); + std::wstring contents; + CaptureText(main_frame, &contents); + Send(new ViewMsg_DeterminePageText_Reply(routing_id_, contents)); + determine_page_text_after_loading_stops_ = false; + return; + } + + // We set |determine_page_text_after_loading_stops_| true here so that, + // after page has been loaded completely, the text in the page is captured. + determine_page_text_after_loading_stops_ = true; +} + void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) { Send(new ViewHostMsg_DnsPrefetch(host_names)); } diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 4ae9e38..c69a601 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -939,6 +939,9 @@ class RenderView : public RenderWidget, // Hopds a reference to the service which provides desktop notifications. scoped_ptr<NotificationProvider> notification_provider_; + // Set to true if request for capturing page text has been made. + bool determine_page_text_after_loading_stops_; + // Holds state pertaining to a navigation that we initiated. This is held by // the WebDataSource::ExtraData attribute. We use pending_navigation_state_ // as a temporary holder for the state until the WebDataSource corresponding diff --git a/chrome/test/data/english_page.html b/chrome/test/data/english_page.html deleted file mode 100644 index 539920d..0000000 --- a/chrome/test/data/english_page.html +++ /dev/null @@ -1,6 +0,0 @@ -<html> -<head><title>This page is in English</title></head> -<body> -No joke! This is a page written in English. Awesome don't you think? -</body> -</html> diff --git a/chrome/test/data/extensions/api_test/tabs/test.js b/chrome/test/data/extensions/api_test/tabs/test.js new file mode 100644 index 0000000..ba02f033 --- /dev/null +++ b/chrome/test/data/extensions/api_test/tabs/test.js @@ -0,0 +1,576 @@ +// tabs api test +// browser_tests.exe --gtest_filter=ExtensionApiTest.Tabs + +// We have a bunch of places where we need to remember some state from one +// test (or setup code) to subsequent tests. +var firstWindowId = null; +var secondWindowId = null; +var firstTabIndex = null; +var testTabId = null; + +var windowEventsWindow = null; +var moveTabIds = {}; + +var pass = chrome.test.callbackPass; +var assertEq = chrome.test.assertEq; +var assertTrue = chrome.test.assertTrue; + +function pageUrl(letter) { + return chrome.extension.getURL(letter + ".html"); +} + +chrome.test.runTests([ + function getSelected() { + chrome.tabs.getSelected(null, pass(function(tab) { + assertEq("about:blank", tab.url); + assertEq("about:blank", tab.title); + firstWindowId = tab.windowId; + firstTabIndex = tab.index; + })); + }, + + function create() { + chrome.tabs.create({"windowId" : firstWindowId, "selected" : false}, + pass(function(tab){ + assertTrue(tab.index > firstTabIndex); + assertEq(firstWindowId, tab.windowId); + assertEq(false, tab.selected); + assertEq("chrome://newtab/", tab.url); + })); + }, + + function createInOtherWindow() { + chrome.windows.create({}, pass(function(win) { + // The newly created window is now the currentWindow. + // Create a tab in the older window. + chrome.tabs.create({"windowId" : firstWindowId, "selected" : false}, + pass(function(tab) { + assertEq(firstWindowId, tab.windowId); + })); + // Create a tab in this new window. + chrome.tabs.create({"windowId" : win.id}, pass(function(tab) { + assertEq(win.id, tab.windowId); + })); + })); + }, + + function createAtIndex() { + chrome.tabs.create({"windowId" : firstWindowId, "index" : 1}, + pass(function(tab) { + assertEq(1, tab.index); + })); + }, + + function createSelected() { + chrome.tabs.create({"windowId" : firstWindowId, "selected" : true}, + pass(function(tab) { + assertTrue(tab.selected); + chrome.tabs.getSelected(firstWindowId, pass(function(selectedTab) { + assertEq(tab.id, selectedTab.id); + })); + })); + }, + + function setupTwoWindows() { + setupWindow(["about:blank", "chrome://newtab/", pageUrl("a")], + pass(function(winId, tabIds) { + firstWindowId = winId; + testTabId = tabIds[2]; + + createWindow(["chrome://newtab/", pageUrl("b")], + pass(function(winId, tabIds) { + secondWindowId = winId; + })); + })); + }, + + function getAllInWindow() { + chrome.tabs.getAllInWindow(firstWindowId, + pass(function(tabs) { + assertEq(3, tabs.length); + for (var i = 0; i < tabs.length; i++) { + assertEq(firstWindowId, tabs[i].windowId); + assertEq(i, tabs[i].index); + + // The most recent tab should be selected + assertEq((i == 2), tabs[i].selected); + } + assertEq("about:blank", tabs[0].url); + assertEq("chrome://newtab/", tabs[1].url); + assertEq(pageUrl("a"), tabs[2].url); + })); + + chrome.tabs.getAllInWindow(secondWindowId, + pass(function(tabs) { + assertEq(2, tabs.length); + for (var i = 0; i < tabs.length; i++) { + assertEq(secondWindowId, tabs[i].windowId); + assertEq(i, tabs[i].index); + } + assertEq("chrome://newtab/", tabs[0].url); + assertEq(pageUrl("b"), tabs[1].url); + })); + }, + + /* TODO: Enable this test when crbug.com/28055 is fixed. This bug causes a + newly created window not to be set as the current window, if + Chrome was not the foreground window when the create call was made. + function getAllInWindowNullArg() { + chrome.tabs.getAllInWindow(null, pass(function(tabs) { + assertEq(2, tabs.length); + assertEq(secondWindowId, tabs[0].windowId); + })); + }, */ + + function update() { + chrome.tabs.get(testTabId, pass(function(tab) { + assertEq(pageUrl("a"), tab.url); + // Update url. + chrome.tabs.update(testTabId, {"url": pageUrl("c")}, + pass(function(tab){ + chrome.test.assertEq(pageUrl("c"), tab.url); + // Check url. + chrome.tabs.get(testTabId, pass(function(tab) { + assertEq(pageUrl("c"), tab.url); + })); + })); + })); + }, + + function updateSelect() { + chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) { + assertEq(false, tabs[1].selected); + assertEq(true, tabs[2].selected); + // Select tab[1]. + chrome.tabs.update(tabs[1].id, {selected: true}, + pass(function(tab1){ + // Check update of tab[1]. + chrome.test.assertEq(true, tab1.selected); + chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) { + assertEq(true, tabs[1].selected); + assertEq(false, tabs[2].selected); + // Select tab[2]. + chrome.tabs.update(tabs[2].id, {selected: true}, + pass(function(tab2){ + // Check update of tab[2]. + chrome.test.assertEq(true, tab2.selected); + chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) { + assertEq(false, tabs[1].selected); + assertEq(true, tabs[2].selected); + })); + })); + })); + })); + })); + }, + + // Do a series of moves so that we get the following + // + // Before: + // Window1: (newtab),a,b,c,d,e + // Window2: (newtab) + // + // After: + // Window1: (newtab),a,e,c + // Window2: b,(newtab),d + function setupLetterPages() { + var pages = ["chrome://newtab/", pageUrl('a'), pageUrl('b'), + pageUrl('c'), pageUrl('d'), pageUrl('e')]; + setupWindow(pages, pass(function(winId, tabIds) { + firstWindowId = winId; + moveTabIds['a'] = tabIds[1]; + moveTabIds['b'] = tabIds[2]; + moveTabIds['c'] = tabIds[3]; + moveTabIds['d'] = tabIds[4]; + moveTabIds['e'] = tabIds[5]; + createWindow(["chrome://newtab/"], pass(function(winId, tabIds) { + secondWindowId = winId; + })); + chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) { + assertEq(pages.length, tabs.length); + for (var i in tabs) { + assertEq(pages[i], tabs[i].url); + } + })); + })); + }, + + function move() { + // Check that the tab/window state is what we expect after doing moves. + function checkMoveResults() + { + chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) { + assertEq(4, tabs.length); + assertEq("chrome://newtab/", tabs[0].url); + assertEq(pageUrl("a"), tabs[1].url); + assertEq(pageUrl("e"), tabs[2].url); + assertEq(pageUrl("c"), tabs[3].url); + + chrome.tabs.getAllInWindow(secondWindowId, pass(function(tabs) { + assertEq(3, tabs.length); + assertEq(pageUrl("b"), tabs[0].url); + assertEq("chrome://newtab/", tabs[1].url); + assertEq(pageUrl("d"), tabs[2].url); + })); + })); + } + + chrome.tabs.move(moveTabIds['b'], {"windowId": secondWindowId, "index": 0}, + pass(function(tabB) { + chrome.test.assertEq(0, tabB.index); + chrome.tabs.move(moveTabIds['e'], {"index": 2}, + pass(function(tabE) { + chrome.test.assertEq(2, tabE.index); + chrome.tabs.move(moveTabIds['d'], {"windowId": secondWindowId, + "index": 2}, pass(function(tabD) { + chrome.test.assertEq(2, tabD.index); + checkMoveResults(); + })); + })); + })); + }, + + function remove() { + chrome.tabs.remove(moveTabIds["d"], pass(function() { + chrome.tabs.getAllInWindow(secondWindowId, + pass(function(tabs) { + assertEq(2, tabs.length); + assertEq(pageUrl("b"), tabs[0].url); + assertEq("chrome://newtab/", tabs[1].url); + })); + })); + }, + + function detectLanguage() { + chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) { + chrome.tabs.detectLanguage(tabs[0].id, pass(function(lang) { + assertEq("en", lang); + })); + })); + }, + + /* TODO(rafaelw): Ideally, this test would include a page with known content, + it'd take a capture and compare it to some expected output. + TODO(rafaelw): This test fails in at least three distinct ways. One where + the function actually fails to get anything and logs a "Internal error + while trying to capture visible region of the current tab" error from the + browser process. + function captureVisibleTab() { + // Take First Capture + chrome.tabs.captureVisibleTab(firstWindowId, + pass(function(window1Url) { + assertEq("string", typeof(window1Url)); + assertTrue(window1Url.length > 0); + + // Take Second Capture + chrome.tabs.captureVisibleTab(secondWindowId, + pass(function(window2Url) { + assertEq("string", typeof(window2Url)); + assertTrue(window2Url.length > 0); + assertTrue(window1Url != window2Url); + + // Now pass null for windowId - it should come back with something + // equal to either the first or second window. This is nondeterministic + // depending on whether you let chrome stay focused, or click + // focus away (or are running on the try/build servers). + chrome.tabs.captureVisibleTab(null, pass(function(url) { + assertEq("string", typeof(url)); + assertTrue(url.length > 0); + assertTrue(url == window1Url || url == window2Url); + })); + })); + })); + }, */ + + function tabsOnCreated() { + chrome.test.listenOnce(chrome.tabs.onCreated, function(tab) { + assertEq(pageUrl("f"), tab.url); + }); + + chrome.tabs.create({"windowId": firstWindowId, "url": pageUrl("f"), + "selected": true}, pass(function(tab) {})); + }, + + function tabsOnUpdatedIgnoreTabArg() { + // A third argument was added to the onUpdated event callback. + // Test that an event handler which ignores this argument works. + var onUpdatedCompleted = chrome.test.listenForever(chrome.tabs.onUpdated, + function(tabid, changeInfo) { + if (tabid == moveTabIds['a'] && changeInfo.status == "complete") { + onUpdatedCompleted(); + } + } + ); + + chrome.tabs.update(moveTabIds['a'], {"url": pageUrl("f")}, pass()); + }, + + function tabsOnUpdated() { + var onUpdatedCompleted = chrome.test.listenForever( + chrome.tabs.onUpdated, + function(tabid, changeInfo, tab) { + // |tab| contains the id of the tab it describes. + // Test that |tabid| matches this id. + assertEq(tabid, tab.id); + + // If |changeInfo| has a status property, than + // it should match the status of the tab in |tab|. + if (changeInfo.status) { + assertEq(changeInfo.status, tab.status); + } + + if (tabid == moveTabIds['a'] && changeInfo.status == "complete") { + onUpdatedCompleted(); + } + } + ); + + chrome.tabs.update(moveTabIds['a'], {"url": pageUrl("f")}, pass()); + }, + + function tabsOnMoved() { + chrome.test.listenOnce(chrome.tabs.onMoved, function(tabid, info) { + assertEq(moveTabIds['a'], tabid); + }); + + chrome.tabs.move(moveTabIds['a'], {"index": 0}, pass()); + }, + + function tabsOnSelectionChanged() { + chrome.test.listenOnce(chrome.tabs.onSelectionChanged, + function(tabid, info) { + assertEq(moveTabIds['c'], tabid); + } + ); + + chrome.tabs.update(moveTabIds['c'], {"selected": true}, + pass()); + }, + + function tabsOnRemoved() { + chrome.test.listenOnce(chrome.tabs.onRemoved, function(tabid) { + assertEq(moveTabIds['c'], tabid); + }); + + chrome.tabs.remove(moveTabIds['c'], pass()); + }, + + function setupTabsOnAttachDetach() + { + setupWindow(["", ""], pass(function(winId, tabIds) { + firstWindowId = winId; + testTabId = tabIds[1]; + createWindow([""], pass(function(winId, tabIds) { + secondWindowId = winId; + })); + })); + }, + + function tabsOnAttached() { + function moveAndListen(tabId, properties, callback) { + chrome.test.listenOnce(chrome.tabs.onAttached, + function(testTabId, info) { + // Ensure notification is correct. + assertEq(testTabId, tabId); + assertEq(properties.windowId, info.newWindowId); + assertEq(properties.index, info.newPosition); + if (callback) + callback(); + }); + chrome.tabs.move(tabId, properties); + }; + + // Move tab to second window, then back to first. + // The original tab/window configuration should be restored. + // tabsOnDetached() depends on it. + moveAndListen(testTabId, {"windowId": secondWindowId, "index": 0}, + pass(function() { + moveAndListen(testTabId, {"windowId": firstWindowId, "index": 1}); + })); + }, + + function tabsOnDetached() { + function moveAndListen(tabId, oldWindowId, oldIndex, properties, + callback) { + chrome.test.listenOnce(chrome.tabs.onDetached, + function(detachedTabId, info) { + // Ensure notification is correct. + assertEq(detachedTabId, tabId); + assertEq(oldWindowId, info.oldWindowId); + assertEq(oldIndex, info.oldPosition); + if (callback) + callback(); + }); + chrome.tabs.move(tabId, properties); + }; + + // Move tab to second window, then back to first. + moveAndListen(testTabId, firstWindowId, 1, + {"windowId": secondWindowId, "index": 0}, pass(function() { + moveAndListen(testTabId, secondWindowId, 0, + {"windowId": firstWindowId, "index": 1}); + })); + }, + + function setupRelativeUrlTests() { + setupWindow(["about:blank"], pass(function(winId, tabIds) { + firstWindowId = winId; + })); + }, + + function relativeUrlTestsTabsCreate() { + // Will be called from relative.html + window.relativePageLoaded = chrome.test.callbackAdded(); + var createCompleted = chrome.test.callbackAdded(); + + chrome.tabs.create({windowId: firstWindowId, url: 'relative.html'}, + function(tab){ + testTabId = tab.id; + createCompleted(); + } + ); + }, + + function relativeUrlTestsTabsUpdate() { + // Will be called from relative.html + window.relativePageLoaded = chrome.test.callbackAdded(); + + chrome.tabs.update(testTabId, {url: pageUrl("a")}, function(tab) { + chrome.test.assertEq(pageUrl("a"), tab.url); + chrome.tabs.update(tab.id, {url: "relative.html"}, function(tab) { + }); + }); + }, + + function relativeUrlTestsWindowCreate() { + // Will be called from relative.html + window.relativePageLoaded = chrome.test.callbackAdded(); + + chrome.windows.create({url: "relative.html"}); + }, + + function windowsOnCreated() { + chrome.test.listenOnce(chrome.windows.onCreated, function(window) { + chrome.test.assertTrue(window.width > 0); + chrome.test.assertTrue(window.height > 0); + windowEventsWindow = window; + chrome.tabs.getAllInWindow(window.id, pass(function(tabs) { + assertEq(pageUrl("a"), tabs[0].url); + })); + }); + + chrome.windows.create({"url": pageUrl("a")}, pass(function(tab) {})); + }, + + /* TODO: Enable this test when crbug.com/28055 is fixed. This bug causes a + newly created window not to be set as the current window, if + Chrome was not the foreground window when the create call was made. + function windowsOnFocusChanged() { + chrome.windows.create({}, pass(function(window) { + chrome.test.listenOnce(chrome.windows.onFocusChanged, + function(windowId) { + assertEq(windowEventsWindow.id, windowId); + }); + chrome.windows.remove(window.id); + })); + }, */ + + function windowsOnRemoved() { + chrome.test.listenOnce(chrome.windows.onRemoved, function(windowId) { + assertEq(windowEventsWindow.id, windowId); + }); + + chrome.windows.remove(windowEventsWindow.id, pass()); + }, + + function setupConnect() { + // The web page that our content script will be injected into. + var relativePath = '/files/extensions/api_test/tabs/relative.html'; + var testUrl = 'http://localhost:1337' + relativePath; + + setupWindow([testUrl], pass(function(winId, tabIds) { + testTabId = tabIds[0]; + waitForAllTabs(pass()); + })); + }, + + function connectMultipleConnects() { + var connectCount = 0; + function connect10() { + var port = chrome.tabs.connect(testTabId); + chrome.test.listenOnce(port.onMessage, function(msg) { + assertEq(++connectCount, msg.connections); + if (connectCount < 10) + connect10(); + }); + port.postMessage("GET"); + } + connect10(); + }, + + function connectName() { + var name = "akln3901n12la"; + var port = chrome.tabs.connect(testTabId, {"name": name}); + chrome.test.listenOnce(port.onMessage, function(msg) { + assertEq(name, msg.name); + + var port = chrome.tabs.connect(testTabId); + chrome.test.listenOnce(port.onMessage, function(msg) { + assertEq('', msg.name); + }); + port.postMessage("GET"); + }); + port.postMessage("GET"); + }, + + function connectPostMessageTypes() { + var port = chrome.tabs.connect(testTabId); + // Test the content script echoes the message back. + var echoMsg = {"num": 10, "string": "hi", "array": [1,2,3,4,5], + "obj":{"dec": 1.0}}; + chrome.test.listenOnce(port.onMessage, function(msg) { + assertEq(echoMsg.num, msg.num); + assertEq(echoMsg.string, msg.string); + assertEq(echoMsg.array[4], msg.array[4]); + assertEq(echoMsg.obj.dec, msg.obj.dec); + }); + port.postMessage(echoMsg); + }, + + function connectPostManyMessages() { + var port = chrome.tabs.connect(testTabId); + var count = 0; + var done = chrome.test.listenForever(port.onMessage, function(msg) { + assertEq(count++, msg); + if (count == 999) { + done(); + } + }); + for (var i = 0; i < 1000; i++) { + port.postMessage(i); + } + }, + + /* TODO: Enable this test once we do checking on the tab id for + chrome.tabs.connect (crbug.com/27565). + function connectNoTab() { + chrome.tabs.create({}, pass(function(tab) { + chrome.tabs.remove(tab.id, pass(function() { + var port = chrome.tabs.connect(tab.id); + assertEq(null, port); + })); + })); + }, */ + + function sendRequest() { + var request = "test"; + chrome.tabs.sendRequest(testTabId, request, pass(function(response) { + assertEq(request, response); + })); + }, + + // TODO(asargent) + // It would be an improvement to check the captureVisibleTab results + // against a known-good result. +]); + diff --git a/chrome/test/data/french_page.html b/chrome/test/data/french_page.html deleted file mode 100644 index 7fcf684..0000000 --- a/chrome/test/data/french_page.html +++ /dev/null @@ -1,6 +0,0 @@ -<html> -<head><title>Cette page est en Français</title></head> -<body> -Cette page a été rédigée en français. Saviez-vous que le Français est la langue officielle des jeux olympiques? Ça vous en bouche un coin, pas vrai? -</body> -</html> diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc index e4b5818..6723084 100644 --- a/chrome/test/ui_test_utils.cc +++ b/chrome/test/ui_test_utils.cc @@ -254,33 +254,6 @@ class SimpleNotificationObserver : public NotificationObserver { DISALLOW_COPY_AND_ASSIGN(SimpleNotificationObserver); }; -class LanguageDetectionNotificationObserver : public NotificationObserver { - public: - explicit LanguageDetectionNotificationObserver( - RenderViewHost* render_view_host) { - registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, - Source<RenderViewHost>(render_view_host)); - ui_test_utils::RunMessageLoop(); - } - - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - language_ = *(Details<std::string>(details).ptr()); - MessageLoopForUI::current()->Quit(); - } - - std::string language() const { - return language_; - } - - private: - NotificationRegistrar registrar_; - std::string language_; - - DISALLOW_COPY_AND_ASSIGN(LanguageDetectionNotificationObserver); -}; - class FindInPageNotificationObserver : public NotificationObserver { public: explicit FindInPageNotificationObserver(TabContents* parent_tab) @@ -511,11 +484,6 @@ void WaitForFocusInBrowser(Browser* browser) { browser); } -std::string WaitForLanguageDetection(TabContents* tab) { - LanguageDetectionNotificationObserver observer(tab->render_view_host()); - return observer.language(); -} - int FindInPage(TabContents* tab_contents, const string16& search_string, bool forward, bool match_case, int* ordinal) { tab_contents->StartFinding(search_string, forward, match_case); diff --git a/chrome/test/ui_test_utils.h b/chrome/test/ui_test_utils.h index 2c4cd95..89dc8fc 100644 --- a/chrome/test/ui_test_utils.h +++ b/chrome/test/ui_test_utils.h @@ -115,10 +115,6 @@ void WaitForFocusChange(RenderViewHost* rvh); // traversal). void WaitForFocusInBrowser(Browser* browser); -// Waits for the language of the page to have been detected and returns it. -// This should be called right after a navigation notification was received. -std::string WaitForLanguageDetection(TabContents* tab_contents); - // Performs a find in the page of the specified tab. Returns the number of // matches found. |ordinal| is an optional parameter which is set to the index // of the current match. |