summaryrefslogtreecommitdiffstats
path: root/chrome/browser/automation
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/automation')
-rw-r--r--chrome/browser/automation/automation_provider.cc37
-rw-r--r--chrome/browser/automation/automation_provider.h12
-rw-r--r--chrome/browser/automation/automation_provider_observers.cc57
-rw-r--r--chrome/browser/automation/automation_provider_observers.h3
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc60
-rw-r--r--chrome/browser/automation/testing_automation_provider.h14
6 files changed, 133 insertions, 50 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 87b50f1..501e074 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -455,7 +455,7 @@ void AutomationProvider::HandleFindRequest(
const AutomationMsg_Find_Params& params,
IPC::Message* reply_message) {
if (!tab_tracker_->ContainsHandle(handle)) {
- AutomationMsg_FindInPage::WriteReplyParams(reply_message, -1, -1);
+ AutomationMsg_Find::WriteReplyParams(reply_message, -1, -1);
Send(reply_message);
return;
}
@@ -463,15 +463,36 @@ void AutomationProvider::HandleFindRequest(
NavigationController* nav = tab_tracker_->GetResource(handle);
TabContents* tab_contents = nav->tab_contents();
- find_in_page_observer_.reset(new
- FindInPageNotificationObserver(this, tab_contents, reply_message));
-
- tab_contents->set_current_find_request_id(
- FindInPageNotificationObserver::kFindInPageRequestId);
+ SendFindRequest(tab_contents,
+ false,
+ params.search_string,
+ params.forward,
+ params.match_case,
+ params.find_next,
+ reply_message);
+}
+
+void AutomationProvider::SendFindRequest(
+ TabContents* tab_contents,
+ bool with_json,
+ const string16& search_string,
+ bool forward,
+ bool match_case,
+ bool find_next,
+ IPC::Message* reply_message) {
+ int request_id = FindInPageNotificationObserver::kFindInPageRequestId;
+ find_in_page_observer_.reset(
+ new FindInPageNotificationObserver(this,
+ tab_contents,
+ with_json,
+ reply_message));
+ tab_contents->set_current_find_request_id(request_id);
tab_contents->render_view_host()->StartFinding(
FindInPageNotificationObserver::kFindInPageRequestId,
- params.search_string, params.forward, params.match_case,
- params.find_next);
+ search_string,
+ forward,
+ match_case,
+ find_next);
}
class SetProxyConfigTask : public Task {
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index 838fcd6..595fad6 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -19,6 +19,7 @@
#include "base/basictypes.h"
#include "base/observer_list.h"
#include "base/scoped_ptr.h"
+#include "base/string16.h"
#include "chrome/browser/autofill/field_types.h"
#include "chrome/browser/cancelable_request.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
@@ -34,6 +35,7 @@
struct AutomationMsg_Find_Params;
class PopupMenuWaiter;
+class TabContents;
namespace IPC {
struct Reposition_Params;
@@ -197,6 +199,16 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
// Consumer for asynchronous history queries.
CancelableRequestConsumer consumer_;
+ // Sends a find request for a given query.
+ void SendFindRequest(
+ TabContents* tab_contents,
+ bool with_json,
+ const string16& search_string,
+ bool forward,
+ bool match_case,
+ bool find_next,
+ IPC::Message* reply_message);
+
private:
void OnUnhandledMessage();
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index c2873f3..af0cac0 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -6,7 +6,9 @@
#include "base/basictypes.h"
#include "base/json/json_writer.h"
+#include "base/scoped_ptr.h"
#include "base/string_util.h"
+#include "base/values.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/automation/automation_provider.h"
#include "chrome/browser/automation/automation_provider_json.h"
@@ -31,6 +33,7 @@
#include "chrome/common/extensions/extension.h"
#include "chrome/common/notification_service.h"
#include "chrome/test/automation/automation_constants.h"
+#include "gfx/rect.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/login/authentication_notification_details.h"
@@ -834,9 +837,10 @@ bool ExecuteBrowserCommandObserver::GetNotificationType(
FindInPageNotificationObserver::FindInPageNotificationObserver(
AutomationProvider* automation, TabContents* parent_tab,
- IPC::Message* reply_message)
+ bool reply_with_json, IPC::Message* reply_message)
: automation_(automation),
active_match_ordinal_(-1),
+ reply_with_json_(reply_with_json),
reply_message_(reply_message) {
registrar_.Add(this, NotificationType::FIND_RESULT_AVAILABLE,
Source<TabContents>(parent_tab));
@@ -848,28 +852,40 @@ FindInPageNotificationObserver::~FindInPageNotificationObserver() {
void FindInPageNotificationObserver::Observe(
NotificationType type, const NotificationSource& source,
const NotificationDetails& details) {
- if (type == NotificationType::FIND_RESULT_AVAILABLE) {
- Details<FindNotificationDetails> find_details(details);
- if (find_details->request_id() == kFindInPageRequestId) {
- // We get multiple responses and one of those will contain the ordinal.
- // This message comes to us before the final update is sent.
- if (find_details->active_match_ordinal() > -1)
+ Details<FindNotificationDetails> find_details(details);
+ if (!(find_details->final_update() && reply_message_ != NULL)) {
+ DLOG(INFO) << "Ignoring, since we only care about the final message";
+ return;
+ }
+ // We get multiple responses and one of those will contain the ordinal.
+ // This message comes to us before the final update is sent.
+ if (find_details->request_id() == kFindInPageRequestId) {
+ if (reply_with_json_) {
+ scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
+ return_value->SetInteger("match_count",
+ find_details->number_of_matches());
+ gfx::Rect rect = find_details->selection_rect();
+ // If MatchCount is > 0, then rect should not be Empty.
+ // We dont guard it here because we want to let the test
+ // code catch this invalid case if needed.
+ if (!rect.IsEmpty()) {
+ return_value->SetInteger("match_left", rect.x());
+ return_value->SetInteger("match_top", rect.y());
+ return_value->SetInteger("match_right", rect.right());
+ return_value->SetInteger("match_bottom", rect.bottom());
+ }
+ AutomationJSONReply(automation_, reply_message_)
+ .SendSuccess(return_value.get());
+ delete this;
+ } else {
+ if (find_details->active_match_ordinal() > -1) {
active_match_ordinal_ = find_details->active_match_ordinal();
- if (find_details->final_update()) {
- if (reply_message_ != NULL) {
- AutomationMsg_FindInPage::WriteReplyParams(reply_message_,
- active_match_ordinal_, find_details->number_of_matches());
- automation_->Send(reply_message_);
- reply_message_ = NULL;
- } else {
- DLOG(WARNING) << "Multiple final Find messages observed.";
- }
- } else {
- DLOG(INFO) << "Ignoring, since we only care about the final message";
+ AutomationMsg_Find::WriteReplyParams(reply_message_,
+ active_match_ordinal_, find_details->number_of_matches());
+ automation_->Send(reply_message_);
+ reply_message_ = NULL;
}
}
- } else {
- NOTREACHED();
}
}
@@ -1330,3 +1346,4 @@ void AutocompleteEditFocusedObserver::Observe(
automation_->Send(reply_message_);
delete this;
}
+
diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h
index 842092a..bc2fdb7 100644
--- a/chrome/browser/automation/automation_provider_observers.h
+++ b/chrome/browser/automation/automation_provider_observers.h
@@ -441,6 +441,7 @@ class FindInPageNotificationObserver : public NotificationObserver {
public:
FindInPageNotificationObserver(AutomationProvider* automation,
TabContents* parent_tab,
+ bool reply_with_json,
IPC::Message* reply_message);
~FindInPageNotificationObserver();
@@ -463,6 +464,8 @@ class FindInPageNotificationObserver : public NotificationObserver {
// We will at some point (before final update) be notified of the ordinal and
// we need to preserve it so we can send it later.
int active_match_ordinal_;
+ // Send reply using json automation interface.
+ bool reply_with_json_;
IPC::Message* reply_message_;
DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver);
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index e7ea515..14bc906 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -314,7 +314,6 @@ void TestingAutomationProvider::OnMessageReceived(
ExecuteJavascript)
IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedWindowCount,
GetConstrainedWindowCount)
- IPC_MESSAGE_HANDLER(AutomationMsg_FindInPage, HandleFindInPageRequest)
#if defined(TOOLKIT_VIEWS)
IPC_MESSAGE_HANDLER(AutomationMsg_GetFocusedViewID, GetFocusedViewID)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForFocusedViewIDToChange,
@@ -1217,18 +1216,6 @@ void TestingAutomationProvider::GetConstrainedWindowCount(int handle,
}
}
-void TestingAutomationProvider::HandleFindInPageRequest(
- int handle,
- const std::wstring& find_request,
- int forward,
- int match_case,
- int* active_ordinal,
- int* matches_found) {
- LOG(ERROR) << "HandleFindInPageRequest has been deprecated."
- << "Please use HandleFindRequest instead.";
- *matches_found = -1;
-}
-
void TestingAutomationProvider::HandleInspectElementRequest(
int handle, int x, int y, IPC::Message* reply_message) {
TabContents* tab_contents = GetTabContentsForHandle(handle, NULL);
@@ -2103,6 +2090,8 @@ void TestingAutomationProvider::SendJSONRequest(int handle,
handler_map["UninstallExtensionById"] =
&TestingAutomationProvider::UninstallExtensionById;
+ handler_map["FindInPage"] = &TestingAutomationProvider::FindInPage;
+
handler_map["SelectTranslateOption"] =
&TestingAutomationProvider::SelectTranslateOption;
handler_map["GetTranslateInfo"] =
@@ -3295,9 +3284,52 @@ namespace {
// No translate infobar.
return NULL;
}
-
} // namespace
+void TestingAutomationProvider::FindInPage(
+ Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message) {
+ std::string error_message;
+ TabContents* tab_contents = GetTabContentsFromDict(browser, args,
+ &error_message);
+ if (!tab_contents) {
+ AutomationJSONReply(this, reply_message).SendError(error_message);
+ return;
+ }
+ string16 search_string;
+ bool forward;
+ bool match_case;
+ bool find_next;
+ if (!args->GetString("search_string", &search_string)) {
+ AutomationJSONReply(this, reply_message).
+ SendError("Must include search_string string.");
+ return;
+ }
+ if (!args->GetBoolean("forward", &forward)) {
+ AutomationJSONReply(this, reply_message).
+ SendError("Must include forward boolean.");
+ return;
+ }
+ if (!args->GetBoolean("match_case", &match_case)) {
+ AutomationJSONReply(this, reply_message).
+ SendError("Must include match_case boolean.");
+ return;
+ }
+ if (!args->GetBoolean("find_next", &find_next)) {
+ AutomationJSONReply(this, reply_message).
+ SendError("Must include find_next boolean.");
+ return;
+ }
+ SendFindRequest(tab_contents,
+ true,
+ search_string,
+ forward,
+ match_case,
+ find_next,
+ reply_message);
+}
+
// See GetTranslateInfo() in chrome/test/pyautolib/pyauto.py for sample json
// input and output.
void TestingAutomationProvider::GetTranslateInfo(
diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h
index 07418a6..9449558 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -12,6 +12,7 @@
#include "chrome/browser/history/history.h"
#include "chrome/common/notification_registrar.h"
+class DictionaryValue;
class TemplateURLModel;
// This is an automation provider containing testing calls.
@@ -155,14 +156,6 @@ class TestingAutomationProvider : public AutomationProvider,
void GetConstrainedWindowCount(int handle, int* count);
- // This function has been deprecated, please use HandleFindRequest.
- void HandleFindInPageRequest(int handle,
- const std::wstring& find_request,
- int forward,
- int match_case,
- int* active_ordinal,
- int* matches_found);
-
#if defined(TOOLKIT_VIEWS)
void GetFocusedViewID(int handle, int* view_id);
@@ -564,6 +557,11 @@ class TestingAutomationProvider : public AutomationProvider,
DictionaryValue* args,
IPC::Message* reply_message);
+ // Responds to the Find request and returns the match count.
+ void FindInPage(Browser* browser,
+ DictionaryValue* args,
+ IPC::Message* reply_message);
+
// Returns information about translation for a given tab. Includes
// information about the translate bar if it is showing.
void GetTranslateInfo(Browser* browser,