summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorsidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-10 16:41:27 +0000
committersidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-10 16:41:27 +0000
commit5c4266928220b850dc96474953f0b3a29739e0d3 (patch)
tree0981198815b7d83ab1ccdb0fc358db8637618c05 /chrome/renderer
parent479d5bc48969f6de924471de27638409db848229 (diff)
downloadchromium_src-5c4266928220b850dc96474953f0b3a29739e0d3.zip
chromium_src-5c4266928220b850dc96474953f0b3a29739e0d3.tar.gz
chromium_src-5c4266928220b850dc96474953f0b3a29739e0d3.tar.bz2
Add getLanguage function to tab extension.
BUG=none TEST=enable extensions using the toolstip.html code (added with this CL) and load pages in different languages. The corresponding language should appear in the bottom left after the page is loadedm or when the button is clicked, or when you navigate back to that tab after visiting some other tab. Review URL: http://codereview.chromium.org/150062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20378 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/extensions/extension_api_client_unittest.cc18
-rw-r--r--chrome/renderer/render_view.cc27
-rw-r--r--chrome/renderer/render_view.h4
-rw-r--r--chrome/renderer/renderer_resources.grd2
-rw-r--r--chrome/renderer/resources/extension_process_bindings.js11
5 files changed, 60 insertions, 2 deletions
diff --git a/chrome/renderer/extensions/extension_api_client_unittest.cc b/chrome/renderer/extensions/extension_api_client_unittest.cc
index 663a892..0cb2876 100644
--- a/chrome/renderer/extensions/extension_api_client_unittest.cc
+++ b/chrome/renderer/extensions/extension_api_client_unittest.cc
@@ -275,6 +275,24 @@ TEST_F(ExtensionAPIClientTest, GetTab) {
"GetTab", "2");
}
+#if defined(OS_WIN)
+TEST_F(ExtensionAPIClientTest, GetTabLanguage) {
+ ExpectJsFail("chrome.tabs.getLanguage(32, function(){}, 20);",
+ "Uncaught Error: Too many arguments.");
+
+ ExpectJsFail("chrome.tabs.getLanguage('abc', function(){});",
+ "Uncaught Error: Invalid value for argument 0. "
+ "Expected 'integer' but got 'string'.");
+
+ ExpectJsFail("chrome.tabs.getLanguage(1, 1);",
+ "Uncaught Error: Invalid value for argument 1. "
+ "Expected 'function' but got 'integer'.");
+
+ ExpectJsPass("chrome.tabs.getLanguage(null, function(){})",
+ "GetTabLanguage", "null");
+}
+#endif
+
TEST_F(ExtensionAPIClientTest, GetSelectedTab) {
ExpectJsFail("chrome.tabs.getSelected(32, function(){}, 20);",
"Uncaught Error: Too many arguments.");
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 5f72843..f08ad79e 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -192,7 +192,8 @@ RenderView::RenderView(RenderThreadBase* render_thread)
popup_notification_visible_(false),
delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync),
preferred_width_(0),
- send_preferred_width_changes_(false) {
+ send_preferred_width_changes_(false),
+ determine_page_text_after_loading_stops_(false) {
}
RenderView::~RenderView() {
@@ -355,6 +356,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_InsertText, OnInsertText)
IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
@@ -497,6 +499,12 @@ void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
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
SendThumbnail();
}
@@ -2199,6 +2207,23 @@ void RenderView::OnFind(int request_id,
}
}
+void RenderView::OnDeterminePageText() {
+ if (!is_loading_) {
+ if (!webview())
+ return;
+ WebFrame* main_frame = webview()->GetMainFrame();
+ 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::ReportFindInPageMatchCount(int count, int request_id,
bool final_update) {
// If we have a message that has been queued up, then we should just replace
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index bc44ac9..24621a4 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -478,6 +478,7 @@ class RenderView : public RenderWidget,
void OnSetupDevToolsClient();
void OnCancelDownload(int32 download_id);
void OnFind(int request_id, const string16&, const WebKit::WebFindOptions&);
+ void OnDeterminePageText();
void OnZoom(int function);
void OnInsertText(const string16& text);
void OnSetPageEncoding(const std::wstring& encoding_name);
@@ -778,6 +779,9 @@ class RenderView : public RenderWidget,
// The text selection the last time DidChangeSelection got called.
std::string last_selection_;
+ // 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/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd
index ed66407..8acec84 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. mp12 -->
+without changes to the corresponding grd file. mp13 -->
<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 f3893fb..51756d0 100644
--- a/chrome/renderer/resources/extension_process_bindings.js
+++ b/chrome/renderer/resources/extension_process_bindings.js
@@ -24,6 +24,7 @@ var chrome = chrome || {};
native function UpdateTab();
native function MoveTab();
native function RemoveTab();
+ native function GetTabLanguage();
native function EnablePageAction();
native function DisablePageAction();
native function GetBookmarks();
@@ -313,6 +314,16 @@ var chrome = chrome || {};
chrome.types.optFun
];
+ chrome.tabs.getLanguage = function(tabId, callback) {
+ validate(arguments, arguments.callee.params);
+ sendRequest(GetTabLanguage, tabId, callback);
+ };
+
+ chrome.tabs.getLanguage.params = [
+ chrome.types.optPInt,
+ chrome.types.optFun
+ ];
+
// Sends ({Tab}).
// Will *NOT* be followed by tab-attached - it is implied.
// *MAY* be followed by tab-selection-changed.