summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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, 89 insertions, 21 deletions
diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc
index bab50d1..c03f553 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(
- "french_sentence.html");
+ "three_languages.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 89cb48c..0e551df8 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -855,8 +855,9 @@ 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()));
+ ListValue* list = static_cast<ListValue*>(Details<ListValue>(details).
+ ptr()->DeepCopy());
+ result_.reset(list);
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 fdc6d0e..c87fb8a 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -13,6 +13,7 @@
#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"
@@ -1121,14 +1122,29 @@ void RenderViewHost::OnDeterminePageTextReply(
#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);
+ 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);
+ }
+
NotificationService::current()->Notify(
NotificationType::TAB_LANGUAGE_DETERMINED,
Source<RenderViewHost>(this),
- Details<std::string>(&language));
+ Details<ListValue>(list_value.get()));
#endif
}
diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json
index 4ad7e46..45f1055 100755
--- a/chrome/common/extensions/api/extension_api.json
+++ b/chrome/common/extensions/api/extension_api.json
@@ -551,9 +551,23 @@
"name": "callback",
"parameters": [
{
- "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"
+ "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."
}
]
}
diff --git a/chrome/common/extensions/docs/tabs.html b/chrome/common/extensions/docs/tabs.html
index c886b4c..9afab2f 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>string language</span>) <span class="subdued">{...}</span>);</pre>
+ <pre>function(<span>array of object topLanguages</span>) <span class="subdued">{...}</span>);</pre>
<dl>
<div jsinstance="*0">
<div>
<dt>
- <var>language</var>
+ <var>topLanguages</var>
<em>
<!-- TYPE -->
@@ -1143,10 +1143,20 @@ 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>string</span>
+ <span>object</span>
+ </span>
+ </span></span>
+ </span>
+ <span style="display: none; ">paramType</span>
</span>
</span>
)
@@ -1157,7 +1167,7 @@ For example:
<dd class="todo" style="display: none; ">
Undocumented.
</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>
+ <dd>The top three languages used in the document, in decreasing order of usage.</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
new file mode 100644
index 0000000..a4d4362
--- /dev/null
+++ b/chrome/test/data/extensions/good/Extensions/behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0/three_languages.html
@@ -0,0 +1,22 @@
+<!--
+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 8fb82aa..f4746a4 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,8 +14,10 @@ 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(language) {
- window.domAutomationController.send(language == 'fr');
+ chrome.tabs.detectLanguage(null, function(topLanguages) {
+ window.domAutomationController.send(topLanguages[0].languageName == 'it' &&
+ topLanguages[1].languageName == 'en' &&
+ topLanguages[2].languageName == 'fr');
});
}
diff --git a/chrome/test/data/extensions/samples/cld/manifest.json b/chrome/test/data/extensions/samples/cld/manifest.json
index c0f20f2..cb8bf3e 100644
--- a/chrome/test/data/extensions/samples/cld/manifest.json
+++ b/chrome/test/data/extensions/samples/cld/manifest.json
@@ -1,6 +1,7 @@
{
"name": "CLD",
"description": "Returns language of a tab",
- "version": "0.1",
- "toolstrips": ["toolstrip.html"]
+ "version": "1.0",
+ "toolstrips": ["toolstrip.html"],
+ "permissions": ["tabs"]
}
diff --git a/chrome/test/data/extensions/samples/cld/toolstrip.html b/chrome/test/data/extensions/samples/cld/toolstrip.html
index 03851c2b..b71a1f8 100644
--- a/chrome/test/data/extensions/samples/cld/toolstrip.html
+++ b/chrome/test/data/extensions/samples/cld/toolstrip.html
@@ -11,8 +11,10 @@ LICENSE file.
var selectedId = -1;
function refreshLanguage() {
console.log("refeshing...");
- chrome.tabs.detectLanguage(null, function(language) {
- document.getElementById("languageDiv").innerHTML = language;
+ chrome.tabs.detectLanguage(null, function(topLanguages) {
+ var dictionaryValue = topLanguages[0];
+ document.getElementById("languageDiv").innerHTML =
+ dictionaryValue.languageName;
});
}