summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-16 20:43:01 +0000
committersidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-16 20:43:01 +0000
commit5bf3935ad9cc7c8c402c7c513fd7b32e749806f8 (patch)
tree2948a02595ab8f3013a58a295a998abbf0047e9e
parent3e4d3e73750b959d949d8d040ec71c7634cc11a8 (diff)
downloadchromium_src-5bf3935ad9cc7c8c402c7c513fd7b32e749806f8.zip
chromium_src-5bf3935ad9cc7c8c402c7c513fd7b32e749806f8.tar.gz
chromium_src-5bf3935ad9cc7c8c402c7c513fd7b32e749806f8.tar.bz2
Change getLanguage to detectLanguage, and incorporate corresponding changes, in tab extensions. Also, use ISO language (e.g. "fr" instead of "French") as return language.
BUG=none TEST=Enable extensions, add the given toolstrip as extension. For a page, the language of the page should be returned as ISO language (e.g., "french" as "fr") Review URL: http://codereview.chromium.org/149627 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20895 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc4
-rw-r--r--chrome/browser/extensions/extension_tabs_module.cc8
-rw-r--r--chrome/browser/extensions/extension_tabs_module.h4
-rw-r--r--chrome/browser/extensions/extension_tabs_module_constants.cc2
-rw-r--r--chrome/browser/extensions/extension_tabs_module_constants.h2
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc7
-rw-r--r--chrome/renderer/extensions/extension_api_client_unittest.cc12
-rw-r--r--chrome/renderer/renderer_resources.grd2
-rw-r--r--chrome/renderer/resources/extension_process_bindings.js8
-rw-r--r--chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip1.html4
-rw-r--r--chrome/test/data/extensions/samples/cld/toolstrip.html2
11 files changed, 28 insertions, 27 deletions
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index e486f89..971349b 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -99,8 +99,8 @@ void FactoryRegistry::ResetFunctions() {
&NewExtensionFunction<MoveTabFunction>;
factories_[tabs::kRemoveTabFunction] =
&NewExtensionFunction<RemoveTabFunction>;
- factories_[tabs::kGetTabLanguageFunction] =
- &NewExtensionFunction<GetTabLanguageFunction>;
+ factories_[tabs::kDetectTabLanguageFunction] =
+ &NewExtensionFunction<DetectTabLanguageFunction>;
// Page Actions.
factories_[page_actions::kEnablePageActionFunction] =
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index 57248d7..c43ae92 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -615,7 +615,7 @@ bool RemoveTabFunction::RunImpl() {
return true;
}
-bool GetTabLanguageFunction::RunImpl() {
+bool DetectTabLanguageFunction::RunImpl() {
int tab_id = 0;
Browser* browser = NULL;
TabContents* contents = NULL;
@@ -651,9 +651,9 @@ bool GetTabLanguageFunction::RunImpl() {
return true;
}
-void GetTabLanguageFunction::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
+void DetectTabLanguageFunction::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
DCHECK(type == NotificationType::TAB_LANGUAGE_DETERMINED);
std::string language(*Details<std::string>(details).ptr());
result_.reset(Value::CreateStringValue(language.c_str()));
diff --git a/chrome/browser/extensions/extension_tabs_module.h b/chrome/browser/extensions/extension_tabs_module.h
index 1b7c307..821ce89 100644
--- a/chrome/browser/extensions/extension_tabs_module.h
+++ b/chrome/browser/extensions/extension_tabs_module.h
@@ -88,8 +88,8 @@ class MoveTabFunction : public SyncExtensionFunction {
class RemoveTabFunction : public SyncExtensionFunction {
virtual bool RunImpl();
};
-class GetTabLanguageFunction : public AsyncExtensionFunction,
- public NotificationObserver {
+class DetectTabLanguageFunction : public AsyncExtensionFunction,
+ public NotificationObserver {
virtual bool RunImpl();
private:
diff --git a/chrome/browser/extensions/extension_tabs_module_constants.cc b/chrome/browser/extensions/extension_tabs_module_constants.cc
index 69676e7..d4d1cf8 100644
--- a/chrome/browser/extensions/extension_tabs_module_constants.cc
+++ b/chrome/browser/extensions/extension_tabs_module_constants.cc
@@ -56,6 +56,6 @@ const char kCreateTabFunction[] = "CreateTab";
const char kUpdateTabFunction[] = "UpdateTab";
const char kMoveTabFunction[] = "MoveTab";
const char kRemoveTabFunction[] = "RemoveTab";
-const char kGetTabLanguageFunction[] = "GetTabLanguage";
+const char kDetectTabLanguageFunction[] = "DetectTabLanguage";
} // namespace extension_tabs_module_constants
diff --git a/chrome/browser/extensions/extension_tabs_module_constants.h b/chrome/browser/extensions/extension_tabs_module_constants.h
index 4df84c8..f601c84 100644
--- a/chrome/browser/extensions/extension_tabs_module_constants.h
+++ b/chrome/browser/extensions/extension_tabs_module_constants.h
@@ -64,7 +64,7 @@ extern const char kCreateTabFunction[];
extern const char kUpdateTabFunction[];
extern const char kMoveTabFunction[];
extern const char kRemoveTabFunction[];
-extern const char kGetTabLanguageFunction[];
+extern const char kDetectTabLanguageFunction[];
}; // namespace extension_tabs_module_constants
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index 73a66fa..2f775a5 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -1074,9 +1074,10 @@ void RenderViewHost::OnDeterminePageTextReply(
#if defined(OS_WIN) // Only for windows.
int num_languages = 0;
bool is_reliable = false;
- const char* language_char = LanguageName(DetectLanguageOfUnicodeText(
- page_text.c_str(), true, &is_reliable, &num_languages, NULL));
- std::string language(language_char);
+ 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),
diff --git a/chrome/renderer/extensions/extension_api_client_unittest.cc b/chrome/renderer/extensions/extension_api_client_unittest.cc
index 0cb2876..05d631e 100644
--- a/chrome/renderer/extensions/extension_api_client_unittest.cc
+++ b/chrome/renderer/extensions/extension_api_client_unittest.cc
@@ -276,20 +276,20 @@ TEST_F(ExtensionAPIClientTest, GetTab) {
}
#if defined(OS_WIN)
-TEST_F(ExtensionAPIClientTest, GetTabLanguage) {
- ExpectJsFail("chrome.tabs.getLanguage(32, function(){}, 20);",
+TEST_F(ExtensionAPIClientTest, DetectTabLanguage) {
+ ExpectJsFail("chrome.tabs.detectLanguage(32, function(){}, 20);",
"Uncaught Error: Too many arguments.");
- ExpectJsFail("chrome.tabs.getLanguage('abc', function(){});",
+ ExpectJsFail("chrome.tabs.detectLanguage('abc', function(){});",
"Uncaught Error: Invalid value for argument 0. "
"Expected 'integer' but got 'string'.");
- ExpectJsFail("chrome.tabs.getLanguage(1, 1);",
+ ExpectJsFail("chrome.tabs.detectLanguage(1, 1);",
"Uncaught Error: Invalid value for argument 1. "
"Expected 'function' but got 'integer'.");
- ExpectJsPass("chrome.tabs.getLanguage(null, function(){})",
- "GetTabLanguage", "null");
+ ExpectJsPass("chrome.tabs.detectLanguage(null, function(){})",
+ "DetectTabLanguage", "null");
}
#endif
diff --git a/chrome/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd
index a48534c..3067b3e 100644
--- a/chrome/renderer/renderer_resources.grd
+++ b/chrome/renderer/renderer_resources.grd
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This comment is only here because changes to resources are not picked up
-without changes to the corresponding grd file. Zorglub2 -->
+without changes to the corresponding grd file. sidchat1 -->
<grit latest_public_release="0" current_release="1">
<outputs>
<output filename="grit/renderer_resources.h" type="rc_header">
diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js
index e0dba27..9423afe 100644
--- a/chrome/renderer/resources/extension_process_bindings.js
+++ b/chrome/renderer/resources/extension_process_bindings.js
@@ -27,7 +27,7 @@ var chrome = chrome || {};
native function UpdateTab();
native function MoveTab();
native function RemoveTab();
- native function GetTabLanguage();
+ native function DetectTabLanguage();
native function EnablePageAction();
native function DisablePageAction();
native function GetCurrentPageActions();
@@ -318,12 +318,12 @@ var chrome = chrome || {};
chrome.types.optFun
];
- chrome.tabs.getLanguage = function(tabId, callback) {
+ chrome.tabs.detectLanguage = function(tabId, callback) {
validate(arguments, arguments.callee.params);
- sendRequest(GetTabLanguage, tabId, callback);
+ sendRequest(DetectTabLanguage, tabId, callback);
};
- chrome.tabs.getLanguage.params = [
+ chrome.tabs.detectLanguage.params = [
chrome.types.optPInt,
chrome.types.optFun
];
diff --git a/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip1.html b/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip1.html
index cf87fe5..5d8d673 100644
--- a/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip1.html
+++ b/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip1.html
@@ -13,8 +13,8 @@ function testTabsAPI() {
// function to make sure it can be used as an extension API. This will pass if
// the browser navigates to a page in French language before this is called.
function testTabsLanguageAPI() {
- chrome.tabs.getLanguage(null, function(language) {
- window.domAutomationController.send(language == 'FRENCH');
+ chrome.tabs.detectLanguage(null, function(language) {
+ window.domAutomationController.send(language == 'fr');
});
}
diff --git a/chrome/test/data/extensions/samples/cld/toolstrip.html b/chrome/test/data/extensions/samples/cld/toolstrip.html
index 726a030..03851c2b 100644
--- a/chrome/test/data/extensions/samples/cld/toolstrip.html
+++ b/chrome/test/data/extensions/samples/cld/toolstrip.html
@@ -11,7 +11,7 @@ LICENSE file.
var selectedId = -1;
function refreshLanguage() {
console.log("refeshing...");
- chrome.tabs.getLanguage(null, function(language) {
+ chrome.tabs.detectLanguage(null, function(language) {
document.getElementById("languageDiv").innerHTML = language;
});
}