summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-07 21:27:34 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-07 21:27:34 +0000
commit7e3185a37ac1052e028d4de090a2a33c12e697bf (patch)
treec8d0f1bba4d982404737bff017a8ca5da7cce7e3 /chrome
parent96f7f2fc9d83dc862e3a0c98833226b297401ae4 (diff)
downloadchromium_src-7e3185a37ac1052e028d4de090a2a33c12e697bf.zip
chromium_src-7e3185a37ac1052e028d4de090a2a33c12e697bf.tar.gz
chromium_src-7e3185a37ac1052e028d4de090a2a33c12e697bf.tar.bz2
Revert r28293.
This reverts, "Change detectLanguage() API to now return the top three languages as well their percentages. Added suitable unit testing to test that top three languages are returned as expected." TBR=zork BUG=none TEST=none Review URL: http://codereview.chromium.org/270012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28311 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/extension_browsertests_misc.cc2
-rw-r--r--chrome/browser/extensions/extension_tabs_module.cc5
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc26
-rwxr-xr-xchrome/common/extensions/api/extension_api.json20
-rwxr-xr-xchrome/common/extensions/docs/tabs.html18
-rw-r--r--chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/three_languages.html22
-rw-r--r--chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/toolstrip1.html6
-rw-r--r--chrome/test/data/extensions/samples/cld/manifest.json5
-rw-r--r--chrome/test/data/extensions/samples/cld/toolstrip.html6
9 files changed, 21 insertions, 89 deletions
diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc
index c03f553..bab50d1 100644
--- a/chrome/browser/extensions/extension_browsertests_misc.cc
+++ b/chrome/browser/extensions/extension_browsertests_misc.cc
@@ -83,7 +83,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, Toolstrip) {
// 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(
- "three_languages.html");
+ "french_sentence.html");
ui_test_utils::NavigateToURL(
browser(),
GURL(language_url.ToWStringHack()));
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index 0e551df8..89cb48c 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -855,9 +855,8 @@ void DetectTabLanguageFunction::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
DCHECK(type == NotificationType::TAB_LANGUAGE_DETERMINED);
- ListValue* list = static_cast<ListValue*>(Details<ListValue>(details).
- ptr()->DeepCopy());
- result_.reset(list);
+ std::string language(*Details<std::string>(details).ptr());
+ result_.reset(Value::CreateStringValue(language.c_str()));
SendResponse(true);
Release(); // balanced in Run()
}
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index c87fb8a..fdc6d0e 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -13,7 +13,6 @@
#include "base/json_reader.h"
#include "base/string_util.h"
#include "base/time.h"
-#include "base/values.h"
#include "base/waitable_event.h"
#include "chrome/browser/child_process_security_policy.h"
#include "chrome/browser/cross_site_request_manager.h"
@@ -1122,29 +1121,14 @@ void RenderViewHost::OnDeterminePageTextReply(
#if defined(OS_WIN) // Only for windows.
int num_languages = 0;
bool is_reliable = false;
- Language language[3];
- int percent[3];
- int text_bytes;
- DetectLanguageSummaryOfUnicodeText(page_text.c_str(), true, language,
- percent, &text_bytes, &is_reliable);
-
- // The summary returns the top three languages. Put these languages and
- // their corresponding percentages as a list of DictionaryValues objects.
- scoped_ptr<ListValue> list_value(new ListValue());
- for (int i = 0; i < 3; i++) {
- DictionaryValue* language_summary = new DictionaryValue();
- std::string language_string(LanguageCodeISO639_1(language[i]));
- language_summary->Set(L"languageName",
- Value::CreateStringValue(language_string));
- language_summary->Set(L"percentUsed",
- Value::CreateIntegerValue(percent[i]));
- list_value->Append(language_summary);
- }
-
+ 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<ListValue>(list_value.get()));
+ Details<std::string>(&language));
#endif
}
diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json
index 45f1055..4ad7e46 100755
--- a/chrome/common/extensions/api/extension_api.json
+++ b/chrome/common/extensions/api/extension_api.json
@@ -551,23 +551,9 @@
"name": "callback",
"parameters": [
{
- "type": "array",
- "name": "topLanguages",
- "items": {
- "type": "object",
- "properties": {
- "languageName": {
- "type": "string",
- "description": "An ISO language code like <var>en</var> or <var>fr</var>. For the complete list of languages supported by this method, see 2nd column of kLanguageInfoTable in http://src.chromium.org/viewvc/chrome/trunk/src/third_party/cld/bar/toolbar/cld/i18n/languages/internal/languages.cc"
- },
- "percentUsed": {
- "type": "number",
- "description": "The percentage of the page that uses this language",
- "minimum": 0, "maximum": 100
- }
- }
- },
- "description": "The top three languages used in the document, in decreasing order of usage."
+ "type": "string",
+ "name": "language",
+ "description": "An ISO language code like <var>en</var> or <var>fr</var>. For the complete list of languages supported by this method, see 2nd column of kLanguageInfoTable in http://src.chromium.org/viewvc/chrome/trunk/src/third_party/cld/bar/toolbar/cld/i18n/languages/internal/languages.cc"
}
]
}
diff --git a/chrome/common/extensions/docs/tabs.html b/chrome/common/extensions/docs/tabs.html
index 9afab2f..c886b4c 100755
--- a/chrome/common/extensions/docs/tabs.html
+++ b/chrome/common/extensions/docs/tabs.html
@@ -1126,12 +1126,12 @@ For example:
</p>
<!-- Note: intentionally longer 80 columns -->
- <pre>function(<span>array of object topLanguages</span>) <span class="subdued">{...}</span>);</pre>
+ <pre>function(<span>string language</span>) <span class="subdued">{...}</span>);</pre>
<dl>
<div jsinstance="*0">
<div>
<dt>
- <var>topLanguages</var>
+ <var>language</var>
<em>
<!-- TYPE -->
@@ -1143,20 +1143,10 @@ For example:
<a> Type</a>
</span>
<span>
- <span>
- array of <span><span>
- <span style="display: none; ">
- <a> Type</a>
- </span>
- <span>
<span style="display: none; ">
array of <span><span></span></span>
</span>
- <span>object</span>
- </span>
- </span></span>
- </span>
- <span style="display: none; ">paramType</span>
+ <span>string</span>
</span>
</span>
)
@@ -1167,7 +1157,7 @@ For example:
<dd class="todo" style="display: none; ">
Undocumented.
</dd>
- <dd>The top three languages used in the document, in decreasing order of usage.</dd>
+ <dd>An ISO language code like <var>en</var> or <var>fr</var>. For the complete list of languages supported by this method, see 2nd column of kLanguageInfoTable in http://src.chromium.org/viewvc/chrome/trunk/src/third_party/cld/bar/toolbar/cld/i18n/languages/internal/languages.cc</dd>
<!-- OBJECT PROPERTIES -->
<dd style="display: none; ">
diff --git a/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/three_languages.html b/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/three_languages.html
index a4d4362..e69de29 100644
--- a/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/three_languages.html
+++ b/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/three_languages.html
@@ -1,22 +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.
--->
-<html>
-<body>
-<p>
-<!-- Sentence in French (Shortest) -->
-Il s'agit d'une courte phrase en français qui ne signifie pas grand chose.
-</p>
-<p>
-<!-- Sentence in English -->
-This is simple and short sentence in English which is being used simply to guess what language this is.
-</p>
-<p>
-<!-- Sentence in Italian (Longest) -->
-Questa è una frase molto lunga lingua tedesca, e anche se non ha alcun senso, lo fa ancora lo scopo di verificare se questa cosa funziona a tutti o no.
-</p>
-
-</body>
-</html>
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 f4746a4..8fb82aa 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
@@ -14,10 +14,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.detectLanguage(null, function(topLanguages) {
- window.domAutomationController.send(topLanguages[0].languageName == 'it' &&
- topLanguages[1].languageName == 'en' &&
- topLanguages[2].languageName == 'fr');
+ chrome.tabs.detectLanguage(null, function(language) {
+ window.domAutomationController.send(language == 'fr');
});
}
diff --git a/chrome/test/data/extensions/samples/cld/manifest.json b/chrome/test/data/extensions/samples/cld/manifest.json
index cb8bf3e..c0f20f2 100644
--- a/chrome/test/data/extensions/samples/cld/manifest.json
+++ b/chrome/test/data/extensions/samples/cld/manifest.json
@@ -1,7 +1,6 @@
{
"name": "CLD",
"description": "Returns language of a tab",
- "version": "1.0",
- "toolstrips": ["toolstrip.html"],
- "permissions": ["tabs"]
+ "version": "0.1",
+ "toolstrips": ["toolstrip.html"]
}
diff --git a/chrome/test/data/extensions/samples/cld/toolstrip.html b/chrome/test/data/extensions/samples/cld/toolstrip.html
index b71a1f8..03851c2b 100644
--- a/chrome/test/data/extensions/samples/cld/toolstrip.html
+++ b/chrome/test/data/extensions/samples/cld/toolstrip.html
@@ -11,10 +11,8 @@ LICENSE file.
var selectedId = -1;
function refreshLanguage() {
console.log("refeshing...");
- chrome.tabs.detectLanguage(null, function(topLanguages) {
- var dictionaryValue = topLanguages[0];
- document.getElementById("languageDiv").innerHTML =
- dictionaryValue.languageName;
+ chrome.tabs.detectLanguage(null, function(language) {
+ document.getElementById("languageDiv").innerHTML = language;
});
}