license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 5 | #ifndef CHROME_RENDERER_AUTOMATION_DOM_AUTOMATION_CONTROLLER_H__ |
| 6 | #define CHROME_RENDERER_AUTOMATION_DOM_AUTOMATION_CONTROLLER_H__ |
| 7 | |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 8 | #include "ipc/ipc_message.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | #include "webkit/glue/cpp_bound_class.h" |
| 10 | |
| 11 | /* DomAutomationController class: |
| 12 | Bound to Javascript window.domAutomationController object. |
| 13 | At the very basic, this object makes any native value (string, numbers, |
| 14 | boolean) from javascript available to the automation host in Cpp. |
| 15 | Any renderer implementation that is built with this binding will allow the |
| 16 | above facility. |
| 17 | The intended use of this object is to expose the DOM Objects and their |
| 18 | attributes to the automation host. |
| 19 | |
| 20 | A typical usage would be like following (JS code): |
| 21 | |
| 22 | var object = document.getElementById('some_id'); |
| 23 | window.domAutomationController.send(object.nodeName); // get the tag name |
| 24 | |
| 25 | For the exact mode of usage, |
| 26 | refer AutomationProxyTest.*DomAutomationController tests. |
| 27 | |
| 28 | The class provides a single send method that can send variety of native |
| 29 | javascript values. (NPString, Number(double), Boolean) |
| 30 | |
| 31 | The actual communication occurs in the following manner: |
| 32 | |
| 33 | TEST MASTER RENDERER |
| 34 | (1) (3) |
| 35 | |AProxy| ----->|AProvider|----->|RenderView|------| |
| 36 | /\ | | | |
| 37 | | | | | |
| 38 | |(6) |(2) |(0) |(4) |
| 39 | | | \/ | |
| 40 | | |-------->|DAController|<----| |
| 41 | | | |
| 42 | | |(5) |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 43 | |---------|TabContents|<----------| |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 44 | |
| 45 | |
| 46 | Legends: |
| 47 | - AProxy = AutomationProxy |
| 48 | - AProvider = AutomationProvider |
| 49 | - DAController = DomAutomationController |
| 50 | |
| 51 | (0) Initialization step where DAController is bound to the renderer |
| 52 | and the view_id of the renderer is supplied to the DAController for |
| 53 | routing message in (5). (routing_id_) |
| 54 | (1) A 'javascript:' url is sent from the test process to master as an IPC |
| 55 | message. A unique routing id is generated at this stage (automation_id_) |
| 56 | (2) The automation_id_ of step (1) is supplied to DAController by calling |
| 57 | the bound method setAutomationId(). This is required for routing message |
| 58 | in (6). |
| 59 | (3) The 'javascript:' url is sent for execution by calling into |
| 60 | Browser::LoadURL() |
| 61 | (4) A callback is generated as a result of domAutomationController.send() |
| 62 | into Cpp. The supplied value is received as a result of this callback. |
| 63 | (5) The value received in (4) is sent to the master along with the |
| 64 | stored automation_id_ as an IPC message. routing_id_ is used to route |
| 65 | the message. (IPC messages, ViewHostMsg_*DomAutomation* ) |
| 66 | (6) The value and the automation_id_ is extracted out of the message received |
| 67 | in (5). This value is relayed to AProxy using another IPC message. |
| 68 | automation_id_ is used to route the message. |
| 69 | (IPC messages, AutomationMsg_Dom*Response) |
| 70 | |
| 71 | */ |
| 72 | |
| 73 | // TODO(vibhor): Add another method-pair like sendLater() and sendNow() |
| 74 | // sendLater() should keep building a json serializer |
| 75 | // sendNow() should send the above serializer as a string. |
| 76 | class DomAutomationController : public CppBoundClass { |
| 77 | public: |
| 78 | DomAutomationController(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 79 | |
| 80 | // Makes the renderer send a javascript value to the app. |
| 81 | // The value to be sent can be either of type NPString, |
| 82 | // Number (double casted to int32) or boolean. |
| 83 | // The function returns true/false based on the result of actual send over |
| 84 | // IPC. It sets the return value to null on unexpected errors or arguments. |
[email protected] | 2072f00b | 2009-02-18 20:34:46 | [diff] [blame] | 85 | void Send(const CppArgumentList& args, CppVariant* result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 86 | |
[email protected] | a9602de | 2010-03-18 23:43:11 | [diff] [blame^] | 87 | // Makes the renderer send a javascript value to the app. |
| 88 | // The value must be a NPString and should be properly formed JSON. |
| 89 | // This function does not modify/escape the returned string in any way. |
| 90 | void SendJSON(const CppArgumentList& args, CppVariant* result); |
| 91 | |
[email protected] | 2072f00b | 2009-02-18 20:34:46 | [diff] [blame] | 92 | void SetAutomationId(const CppArgumentList& args, CppVariant* result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 93 | |
| 94 | // TODO(vibhor): Implement later |
| 95 | // static CppBindingObjectMethod sendLater; |
| 96 | // static CppBindingObjectMethod sendNow; |
| 97 | |
[email protected] | 2072f00b | 2009-02-18 20:34:46 | [diff] [blame] | 98 | void set_routing_id(int routing_id) { routing_id_ = routing_id; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 99 | |
[email protected] | 2072f00b | 2009-02-18 20:34:46 | [diff] [blame] | 100 | void set_message_sender(IPC::Message::Sender* sender) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 101 | sender_ = sender; |
| 102 | } |
| 103 | |
| 104 | private: |
[email protected] | 2072f00b | 2009-02-18 20:34:46 | [diff] [blame] | 105 | IPC::Message::Sender* sender_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 106 | |
| 107 | // Refer to the comments at the top of the file for more details. |
[email protected] | 2072f00b | 2009-02-18 20:34:46 | [diff] [blame] | 108 | int routing_id_; // routing id to be used by first channel. |
| 109 | int automation_id_; // routing id to be used by the next channel. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | #endif // CHROME_RENDERER_AUTOMATION_DOM_AUTOMATION_CONTROLLER_H__ |