summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/automation
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-03 23:39:15 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-03 23:39:15 +0000
commit766a7086b0ac46dd7a7bd676da47813e5a1790bf (patch)
treeeedca5078840d057ba5a0738ca827b7379a22cf1 /chrome/renderer/automation
parent74368115e55ca8ae0b0799fd2bedcd7e8688882d (diff)
downloadchromium_src-766a7086b0ac46dd7a7bd676da47813e5a1790bf.zip
chromium_src-766a7086b0ac46dd7a7bd676da47813e5a1790bf.tar.gz
chromium_src-766a7086b0ac46dd7a7bd676da47813e5a1790bf.tar.bz2
Move DOMAutomationController code from chrome to content. This is needed by interstitial pages which are in content, and also browser tests in content.
In followup changes, I'll make interstitial pages not have to derive from a concrete class, and instead implement some sort of delegate interface like we did with WebUI. BUG=98716 Review URL: https://chromiumcodereview.appspot.com/9310094 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120441 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/automation')
-rw-r--r--chrome/renderer/automation/dom_automation_controller.cc144
-rw-r--r--chrome/renderer/automation/dom_automation_controller.h113
2 files changed, 0 insertions, 257 deletions
diff --git a/chrome/renderer/automation/dom_automation_controller.cc b/chrome/renderer/automation/dom_automation_controller.cc
deleted file mode 100644
index 81b2be6..0000000
--- a/chrome/renderer/automation/dom_automation_controller.cc
+++ /dev/null
@@ -1,144 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include "chrome/renderer/automation/dom_automation_controller.h"
-
-#include "base/bind.h"
-#include "base/bind_helpers.h"
-#include "base/json/json_value_serializer.h"
-#include "base/string_util.h"
-#include "chrome/common/render_messages.h"
-
-DomAutomationController::DomAutomationController()
- : sender_(NULL),
- routing_id_(MSG_ROUTING_NONE),
- automation_id_(MSG_ROUTING_NONE) {
- BindCallback("send", base::Bind(&DomAutomationController::Send,
- base::Unretained(this)));
- BindCallback("setAutomationId",
- base::Bind(&DomAutomationController::SetAutomationId,
- base::Unretained(this)));
- BindCallback("sendJSON", base::Bind(&DomAutomationController::SendJSON,
- base::Unretained(this)));
-}
-
-void DomAutomationController::Send(const CppArgumentList& args,
- CppVariant* result) {
- if (args.size() != 1) {
- result->SetNull();
- return;
- }
-
- if (automation_id_ == MSG_ROUTING_NONE) {
- result->SetNull();
- return;
- }
-
- if (!sender_) {
- NOTREACHED();
- result->SetNull();
- return;
- }
-
- std::string json;
- JSONStringValueSerializer serializer(&json);
- scoped_ptr<Value> value;
-
- // Warning: note that JSON officially requires the root-level object to be
- // an object (e.g. {foo:3}) or an array, while here we're serializing
- // strings, bools, etc. to "JSON". This only works because (a) the JSON
- // writer is lenient, and (b) on the receiving side we wrap the JSON string
- // in square brackets, converting it to an array, then parsing it and
- // grabbing the 0th element to get the value out.
- switch (args[0].type) {
- case NPVariantType_String: {
- value.reset(Value::CreateStringValue(args[0].ToString()));
- break;
- }
- case NPVariantType_Bool: {
- value.reset(Value::CreateBooleanValue(args[0].ToBoolean()));
- break;
- }
- case NPVariantType_Int32: {
- value.reset(Value::CreateIntegerValue(args[0].ToInt32()));
- break;
- }
- case NPVariantType_Double: {
- // The value that is sent back is an integer while it is treated
- // as a double in this binding. The reason being that KJS treats
- // any number value as a double. Refer for more details,
- // chrome/third_party/webkit/src/JavaScriptCore/bindings/c/c_utility.cpp
- value.reset(Value::CreateIntegerValue(args[0].ToInt32()));
- break;
- }
- default: {
- result->SetNull();
- return;
- }
- }
-
- if (!serializer.Serialize(*value)) {
- result->SetNull();
- return;
- }
-
- bool succeeded = sender_->Send(
- new ChromeViewHostMsg_DomOperationResponse(routing_id_,
- json,
- automation_id_));
- result->Set(succeeded);
-
- automation_id_ = MSG_ROUTING_NONE;
-
-}
-
-void DomAutomationController::SendJSON(const CppArgumentList& args,
- CppVariant* result) {
- if (args.size() != 1) {
- result->SetNull();
- return;
- }
-
- if (automation_id_ == MSG_ROUTING_NONE) {
- result->SetNull();
- return;
- }
-
- if (!sender_) {
- NOTREACHED();
- result->SetNull();
- return;
- }
-
- if (args[0].type != NPVariantType_String) {
- result->SetNull();
- return;
- }
-
- std::string json = args[0].ToString();
- result->Set(sender_->Send(
- new ChromeViewHostMsg_DomOperationResponse(routing_id_,
- json,
- automation_id_)));
-
- automation_id_ = MSG_ROUTING_NONE;
-}
-
-void DomAutomationController::SetAutomationId(
- const CppArgumentList& args, CppVariant* result) {
- if (args.size() != 1) {
- result->SetNull();
- return;
- }
-
- // The check here is for NumberType and not Int32 as
- // KJS::JSType only defines a NumberType (no Int32)
- if (!args[0].isNumber()) {
- result->SetNull();
- return;
- }
-
- automation_id_ = args[0].ToInt32();
- result->Set(true);
-}
diff --git a/chrome/renderer/automation/dom_automation_controller.h b/chrome/renderer/automation/dom_automation_controller.h
deleted file mode 100644
index d6cb8f3..0000000
--- a/chrome/renderer/automation/dom_automation_controller.h
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright (c) 2006-2008 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.
-
-#ifndef CHROME_RENDERER_AUTOMATION_DOM_AUTOMATION_CONTROLLER_H__
-#define CHROME_RENDERER_AUTOMATION_DOM_AUTOMATION_CONTROLLER_H__
-#pragma once
-
-#include "ipc/ipc_message.h"
-#include "webkit/glue/cpp_bound_class.h"
-
-/* DomAutomationController class:
- Bound to Javascript window.domAutomationController object.
- At the very basic, this object makes any native value (string, numbers,
- boolean) from javascript available to the automation host in Cpp.
- Any renderer implementation that is built with this binding will allow the
- above facility.
- The intended use of this object is to expose the DOM Objects and their
- attributes to the automation host.
-
- A typical usage would be like following (JS code):
-
- var object = document.getElementById('some_id');
- window.domAutomationController.send(object.nodeName); // get the tag name
-
- For the exact mode of usage,
- refer AutomationProxyTest.*DomAutomationController tests.
-
- The class provides a single send method that can send variety of native
- javascript values. (NPString, Number(double), Boolean)
-
- The actual communication occurs in the following manner:
-
- TEST MASTER RENDERER
- (1) (3)
- |AProxy| ----->|AProvider|----->|RenderView|------|
- /\ | | |
- | | | |
- |(6) |(2) |(0) |(4)
- | | \/ |
- | |-------->|DAController|<----|
- | |
- | |(5)
- |---------|TabContents|<----------|
-
-
- Legends:
- - AProxy = AutomationProxy
- - AProvider = AutomationProvider
- - DAController = DomAutomationController
-
- (0) Initialization step where DAController is bound to the renderer
- and the view_id of the renderer is supplied to the DAController for
- routing message in (5). (routing_id_)
- (1) A 'javascript:' url is sent from the test process to master as an IPC
- message. A unique routing id is generated at this stage (automation_id_)
- (2) The automation_id_ of step (1) is supplied to DAController by calling
- the bound method setAutomationId(). This is required for routing message
- in (6).
- (3) The 'javascript:' url is sent for execution by calling into
- Browser::LoadURL()
- (4) A callback is generated as a result of domAutomationController.send()
- into Cpp. The supplied value is received as a result of this callback.
- (5) The value received in (4) is sent to the master along with the
- stored automation_id_ as an IPC message. routing_id_ is used to route
- the message. (IPC messages, ViewHostMsg_*DomAutomation* )
- (6) The value and the automation_id_ is extracted out of the message received
- in (5). This value is relayed to AProxy using another IPC message.
- automation_id_ is used to route the message.
- (IPC messages, AutomationMsg_Dom*Response)
-
-*/
-
-// TODO(vibhor): Add another method-pair like sendLater() and sendNow()
-// sendLater() should keep building a json serializer
-// sendNow() should send the above serializer as a string.
-class DomAutomationController : public CppBoundClass {
- public:
- DomAutomationController();
-
- // Makes the renderer send a javascript value to the app.
- // The value to be sent can be either of type NPString,
- // Number (double casted to int32) or boolean.
- // The function returns true/false based on the result of actual send over
- // IPC. It sets the return value to null on unexpected errors or arguments.
- void Send(const CppArgumentList& args, CppVariant* result);
-
- // Makes the renderer send a javascript value to the app.
- // The value must be a NPString and should be properly formed JSON.
- // This function does not modify/escape the returned string in any way.
- void SendJSON(const CppArgumentList& args, CppVariant* result);
-
- void SetAutomationId(const CppArgumentList& args, CppVariant* result);
-
- // TODO(vibhor): Implement later
- // static CppBindingObjectMethod sendLater;
- // static CppBindingObjectMethod sendNow;
-
- void set_routing_id(int routing_id) { routing_id_ = routing_id; }
-
- void set_message_sender(IPC::Message::Sender* sender) {
- sender_ = sender;
- }
-
- private:
- IPC::Message::Sender* sender_;
-
- // Refer to the comments at the top of the file for more details.
- int routing_id_; // routing id to be used by first channel.
- int automation_id_; // routing id to be used by the next channel.
-};
-
-#endif // CHROME_RENDERER_AUTOMATION_DOM_AUTOMATION_CONTROLLER_H__