diff options
author | jshin@chromium.org <jshin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-19 21:23:27 +0000 |
---|---|---|
committer | jshin@chromium.org <jshin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-19 21:23:27 +0000 |
commit | fd2a9927ec151327e710f1fca66f5620e24f98dd (patch) | |
tree | a279b0d43bbde75c84f3eb5c3d449be63ea56628 /chrome | |
parent | 225c5084d41efb256a2876180306d5484c7d0668 (diff) | |
download | chromium_src-fd2a9927ec151327e710f1fca66f5620e24f98dd.zip chromium_src-fd2a9927ec151327e710f1fca66f5620e24f98dd.tar.gz chromium_src-fd2a9927ec151327e710f1fca66f5620e24f98dd.tar.bz2 |
Revert 36541 (which went in without any commit log by some black magic).
Reland it with the commit log for the record.
Review URL: http://codereview.chromium.org/545123
TBR=jshin@chromium.org
Review URL: http://codereview.chromium.org/551070
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36550 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/extensions/extension_browsertests_misc.cc | 8 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_tabs_module.cc | 5 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 2 | ||||
-rwxr-xr-x | chrome/chrome_renderer.gypi | 6 | ||||
-rwxr-xr-x | chrome/chrome_tests.gypi | 6 | ||||
-rw-r--r-- | chrome/renderer/extensions/extension_api_client_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 23 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 12 | ||||
-rw-r--r-- | chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/french_sentence.html | 1 |
9 files changed, 42 insertions, 23 deletions
diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc index d0409aa..ee5935c 100644 --- a/chrome/browser/extensions/extension_browsertests_misc.cc +++ b/chrome/browser/extensions/extension_browsertests_misc.cc @@ -89,17 +89,23 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, Toolstrip) { host->render_view_host(), L"", L"testTabsAPI()", &result); EXPECT_TRUE(result); +#if defined(OS_WIN) + // http://crbug.com/29896 - tabs.detectLanguage is Windows only + // Test for compact language detection API. First navigate to a (static) html // file with a French sentence. Then, run the test API in toolstrip1.html to // actually call the language detection API through the existing extension, // and verify that the language returned is indeed French. FilePath language_url = extension_test_data_dir.AppendASCII( "french_sentence.html"); - ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(language_url)); + ui_test_utils::NavigateToURL( + browser(), + GURL(language_url.ToWStringHack())); ui_test_utils::ExecuteJavaScriptAndExtractBool( host->render_view_host(), L"", L"testTabsLanguageAPI()", &result); EXPECT_TRUE(result); +#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 8e6bf2f..19d2687 100644 --- a/chrome/browser/extensions/extension_tabs_module.cc +++ b/chrome/browser/extensions/extension_tabs_module.cc @@ -832,6 +832,11 @@ void CaptureVisibleTabFunction::SendResultFromBitmap( } bool DetectTabLanguageFunction::RunImpl() { + #if !defined(OS_WIN) + error_ = keys::kSupportedInWindowsOnlyError; + return false; + #endif + int tab_id = 0; Browser* browser = NULL; TabContents* contents = NULL; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 666ecf8..fb7d2de 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2124,10 +2124,12 @@ ], 'include_dirs': [ 'third_party/wtl/include', + '../third_party/cld', ], 'dependencies': [ '../gears/gears.gyp:gears', '../google_update/google_update.gyp:google_update', + '../third_party/cld/cld.gyp:cld', '../views/views.gyp:views', 'installer/installer.gyp:installer_util', '<(allocator_target)', diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index ea95478..baac651 100755 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -16,7 +16,6 @@ '../printing/printing.gyp:printing', '../skia/skia.gyp:skia', '../third_party/hunspell/hunspell.gyp:hunspell', - '../third_party/cld/cld.gyp:cld', '../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icuuc', '../third_party/npapi/npapi.gyp:npapi', @@ -28,7 +27,6 @@ ], 'include_dirs': [ '..', - '../third_party/cld', ], 'defines': [ '<@(nacl_defines)', @@ -170,8 +168,12 @@ # Windows-specific rules. ['OS=="win"', { 'include_dirs': [ + '../third_party/cld', 'third_party/wtl/include', ], + 'dependencies': [ + '../third_party/cld/cld.gyp:cld', + ], 'conditions': [ ['win_use_allocator_shim==1', { 'dependencies': [ diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 7ed6e6a..b56840a 100755 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -492,7 +492,6 @@ '../testing/gmock.gyp:gmock', '../testing/gtest.gyp:gtest', '../third_party/bzip2/bzip2.gyp:bzip2', - '../third_party/cld/cld.gyp:cld', '../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icuuc', '../third_party/libxml/libxml.gyp:libxml', @@ -897,6 +896,8 @@ ], 'sources!': [ 'browser/views/bookmark_context_menu_test.cc', + # Compact Language Detection (cld) is not supported in linux yet. + '../third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/compact_lang_det_unittest_small.cc', ], }], ['OS=="linux" and (toolkit_views==1 or chromeos==1)', { @@ -946,6 +947,9 @@ 'browser/tab_contents/navigation_controller_unittest.cc', 'browser/task_manager_unittest.cc', '../third_party/hunspell/google/hunspell_tests.cc', + + # Compact Language Detection (cld) is not supported in mac yet. + '../third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/compact_lang_det_unittest_small.cc', ], # TODO(mark): We really want this for all non-static library targets, # but when we tried to pull it up to the common.gypi level, it broke diff --git a/chrome/renderer/extensions/extension_api_client_unittest.cc b/chrome/renderer/extensions/extension_api_client_unittest.cc index 39d275f..05c2ddf 100644 --- a/chrome/renderer/extensions/extension_api_client_unittest.cc +++ b/chrome/renderer/extensions/extension_api_client_unittest.cc @@ -290,6 +290,7 @@ TEST_F(ExtensionAPIClientTest, GetTab) { "tabs.get", "2"); } +#if defined(OS_WIN) TEST_F(ExtensionAPIClientTest, DetectTabLanguage) { ExpectJsFail("chrome.tabs.detectLanguage(32, function(){}, 20);", "Uncaught Error: Too many arguments."); @@ -305,6 +306,7 @@ TEST_F(ExtensionAPIClientTest, DetectTabLanguage) { ExpectJsPass("chrome.tabs.detectLanguage(null, function(){})", "tabs.detectLanguage", "null"); } +#endif TEST_F(ExtensionAPIClientTest, GetSelectedTab) { ExpectJsFail("chrome.tabs.getSelected(32, function(){}, 20);", diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index dcbda82..5b1ee82 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -67,7 +67,10 @@ #include "net/base/net_errors.h" #include "skia/ext/bitmap_platform_device.h" #include "skia/ext/image_operations.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 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" @@ -220,7 +223,7 @@ static const char* const kUnreachableWebDataURL = static const char* const kBackForwardNavigationScheme = "history"; // The string returned in DetectLanguage if we failed to detect the language. -static const char* const kUnknownLanguageCode = "und"; +static const char* const kUnknownLanguageCode = "unknown"; static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { WebVector<WebURL> urls; @@ -3079,29 +3082,31 @@ std::string RenderView::DetectLanguage() { if (!webview() || is_loading_) return kUnknownLanguageCode; + std::string language = kUnknownLanguageCode; +#if defined(OS_WIN) // CLD is only available on Windows at this time. WebFrame* main_frame = webview()->mainFrame(); std::wstring contents; CaptureText(main_frame, &contents); - return DetermineTextLanguage(contents); + language = DetermineTextLanguage(contents); +#endif + + return language; } // static std::string RenderView::DetermineTextLanguage(const std::wstring& text) { std::string language = kUnknownLanguageCode; +#if defined(OS_WIN) // CLD is only available on Windows at this time. int num_languages = 0; bool is_reliable = false; - string16 input = WideToUTF16(text); Language cld_language = - DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable, + DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable, &num_languages, NULL); if (cld_language != NUM_LANGUAGES && cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) { - // We should not use LanguageCode_ISO_639_1 because it does not cover all the - // languages CLD can detect. As a result, it'll return the invalid language - // code for tradtional Chinese among others. |LanguageCode| will go through - // ISO 639-1, ISO-639-2 and 'other' tables to do the 'right' thing. - language = LanguageCode(cld_language); + language = LanguageCodeISO639_1(cld_language); } +#endif return language; } diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 036cb0b..4d3a4e9 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -436,15 +436,9 @@ class RenderView : public RenderWidget, PageTranslator* page_translator() const { return page_translator_.get(); } - // Returns the ISO 639 language code of the current page (e.g. en, fr, zh). - // If ISO 639-1 code is not available for the language, ISO 639-2 3-letter code - // will be returned (e.g. kha for Khasi and und for undtermined). For traditional - // Chinse, 'zh-TW' will be returned while for simplified Chinse, 'zh' will be - // returned. - // TODO(jungshik): Make it return 'he' (the correct ISO 639 code for Hebrew) - // instead of the obsolete 'iw'. Perhaps, it's also better to return 'zh-Hans' - // (or 'zh-CN') for Simplified Chinese instead of 'zh' to be aligned with - // 'zh-TW' for Traditional Chinse. + // Returns the ISO 639_1 language code of the current page + // (ex: en, fr, zh...). Returns 'unknown' if the language could not be + // determined. std::string DetectLanguage(); protected: diff --git a/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/french_sentence.html b/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/french_sentence.html index a7607f2..3d3c2e8 100644 --- a/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/french_sentence.html +++ b/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/french_sentence.html @@ -4,7 +4,6 @@ source code is governed by a BSD-style license that can be found in the LICENSE file. --> <html> -<meta charset="ISO-8859-1"> <body> <p> Ceci est une phrase complète est en français, rédigé en anglais puis traduits |