diff options
author | craigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-26 19:36:23 +0000 |
---|---|---|
committer | craigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-26 19:36:23 +0000 |
commit | 09f3707c586fb1a1fe4c46765509953d6d6f4871 (patch) | |
tree | 01ef25b5b608bed3a86d58d676b044f3433e5913 /content | |
parent | 00577aabd2f626429649e374ac9583f1eb47e862 (diff) | |
download | chromium_src-09f3707c586fb1a1fe4c46765509953d6d6f4871.zip chromium_src-09f3707c586fb1a1fe4c46765509953d6d6f4871.tar.gz chromium_src-09f3707c586fb1a1fe4c46765509953d6d6f4871.tar.bz2 |
Modified DomAutomationController to expose a new Javascript method sendWithId() and updated the event queue tests to use it.
All DomAutomationController messages need to be coupled with an automation
routing id. This was previously done by setting the id through
a separate javascript functional call. However, events introduce a race
condition where an event raised between the call to set the automation id
and actually sending the message would leave the DomAutomationController
with a cleared Automation Id and the send() message would fail. A new
method sendWithId() allows events to send a message with an automation id
in an atomic fashion, without disrupting the automation id held by the
DomAutomationController.
Change-Id: Ia6be9108ce881ee1a063fc6ff1844587bf122f50
BUG=
TEST=functional/apptest.py
Review URL: http://codereview.chromium.org/9655002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128971 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/renderer/dom_automation_controller.cc | 25 | ||||
-rw-r--r-- | content/renderer/dom_automation_controller.h | 8 |
2 files changed, 33 insertions, 0 deletions
diff --git a/content/renderer/dom_automation_controller.cc b/content/renderer/dom_automation_controller.cc index 0955a6a..85e2fcd 100644 --- a/content/renderer/dom_automation_controller.cc +++ b/content/renderer/dom_automation_controller.cc @@ -21,6 +21,8 @@ DomAutomationController::DomAutomationController() base::Unretained(this))); BindCallback("sendJSON", base::Bind(&DomAutomationController::SendJSON, base::Unretained(this))); + BindCallback("sendWithId", base::Bind(&DomAutomationController::SendWithId, + base::Unretained(this))); } void DomAutomationController::Send(const CppArgumentList& args, @@ -121,6 +123,29 @@ void DomAutomationController::SendJSON(const CppArgumentList& args, automation_id_ = MSG_ROUTING_NONE; } +void DomAutomationController::SendWithId(const CppArgumentList& args, + CppVariant* result) { + if (args.size() != 2) { + result->SetNull(); + return; + } + + if (!sender_) { + NOTREACHED(); + result->SetNull(); + return; + } + + if (!args[0].isNumber() || args[1].type != NPVariantType_String) { + result->SetNull(); + return; + } + + result->Set(sender_->Send( + new ViewHostMsg_DomOperationResponse(routing_id_, args[1].ToString(), + args[0].ToInt32()))); +} + void DomAutomationController::SetAutomationId( const CppArgumentList& args, CppVariant* result) { if (args.size() != 1) { diff --git a/content/renderer/dom_automation_controller.h b/content/renderer/dom_automation_controller.h index 576e09d..f1b06f4 100644 --- a/content/renderer/dom_automation_controller.h +++ b/content/renderer/dom_automation_controller.h @@ -90,6 +90,14 @@ class DomAutomationController : public CppBoundClass { // This function does not modify/escape the returned string in any way. void SendJSON(const CppArgumentList& args, CppVariant* result); + // Sends a string with a provided Automation Id. + // Expects two javascript values; the first must be a number type and will be + // used as the Automation Id, the second must be of type NPString. + // The function returns true/false to the javascript based on the success + // of the send over IPC. It sets the javascript return value to null on + // unexpected errors or arguments. + void SendWithId(const CppArgumentList& args, CppVariant* result); + void SetAutomationId(const CppArgumentList& args, CppVariant* result); // TODO(vibhor): Implement later |