[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 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 | |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 5 | #ifndef CONTENT_RENDERER_DOM_AUTOMATION_CONTROLLER_H_ |
| 6 | #define CONTENT_RENDERER_DOM_AUTOMATION_CONTROLLER_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 8 | #include "base/basictypes.h" |
[email protected] | cfa856d6 | 2014-02-22 07:58:40 | [diff] [blame] | 9 | #include "content/public/renderer/render_frame_observer.h" |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 10 | #include "gin/wrappable.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 11 | |
| 12 | /* DomAutomationController class: |
| 13 | Bound to Javascript window.domAutomationController object. |
| 14 | At the very basic, this object makes any native value (string, numbers, |
| 15 | boolean) from javascript available to the automation host in Cpp. |
| 16 | Any renderer implementation that is built with this binding will allow the |
| 17 | above facility. |
| 18 | The intended use of this object is to expose the DOM Objects and their |
| 19 | attributes to the automation host. |
| 20 | |
| 21 | A typical usage would be like following (JS code): |
| 22 | |
| 23 | var object = document.getElementById('some_id'); |
| 24 | window.domAutomationController.send(object.nodeName); // get the tag name |
| 25 | |
| 26 | For the exact mode of usage, |
| 27 | refer AutomationProxyTest.*DomAutomationController tests. |
| 28 | |
| 29 | The class provides a single send method that can send variety of native |
| 30 | javascript values. (NPString, Number(double), Boolean) |
| 31 | |
| 32 | The actual communication occurs in the following manner: |
| 33 | |
| 34 | TEST MASTER RENDERER |
| 35 | (1) (3) |
| 36 | |AProxy| ----->|AProvider|----->|RenderView|------| |
| 37 | /\ | | | |
| 38 | | | | | |
| 39 | |(6) |(2) |(0) |(4) |
| 40 | | | \/ | |
| 41 | | |-------->|DAController|<----| |
| 42 | | | |
| 43 | | |(5) |
[email protected] | 770005b | 2012-04-16 15:58:13 | [diff] [blame] | 44 | |-------|WebContentsImpl|<--------| |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 45 | |
| 46 | |
| 47 | Legends: |
| 48 | - AProxy = AutomationProxy |
| 49 | - AProvider = AutomationProvider |
| 50 | - DAController = DomAutomationController |
| 51 | |
| 52 | (0) Initialization step where DAController is bound to the renderer |
| 53 | and the view_id of the renderer is supplied to the DAController for |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 54 | routing message in (5). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 55 | (1) A 'javascript:' url is sent from the test process to master as an IPC |
| 56 | message. A unique routing id is generated at this stage (automation_id_) |
| 57 | (2) The automation_id_ of step (1) is supplied to DAController by calling |
| 58 | the bound method setAutomationId(). This is required for routing message |
| 59 | in (6). |
| 60 | (3) The 'javascript:' url is sent for execution by calling into |
| 61 | Browser::LoadURL() |
| 62 | (4) A callback is generated as a result of domAutomationController.send() |
| 63 | into Cpp. The supplied value is received as a result of this callback. |
| 64 | (5) The value received in (4) is sent to the master along with the |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 65 | stored automation_id_ as an IPC message. The frame_'s RenderFrameImpl is |
| 66 | used to route the message. (IPC messages, ViewHostMsg_*DomAutomation* ) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 67 | (6) The value and the automation_id_ is extracted out of the message received |
| 68 | in (5). This value is relayed to AProxy using another IPC message. |
| 69 | automation_id_ is used to route the message. |
| 70 | (IPC messages, AutomationMsg_Dom*Response) |
| 71 | |
| 72 | */ |
| 73 | |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 74 | namespace blink { |
| 75 | class WebFrame; |
| 76 | } |
| 77 | |
| 78 | namespace gin { |
| 79 | class Arguments; |
| 80 | } |
| 81 | |
[email protected] | 9a292e2 | 2012-10-22 15:19:31 | [diff] [blame] | 82 | namespace content { |
| 83 | |
[email protected] | cfa856d6 | 2014-02-22 07:58:40 | [diff] [blame] | 84 | class RenderFrame; |
[email protected] | 480116e7c | 2014-01-13 12:10:04 | [diff] [blame] | 85 | |
| 86 | class DomAutomationController : public gin::Wrappable<DomAutomationController>, |
[email protected] | cfa856d6 | 2014-02-22 07:58:40 | [diff] [blame] | 87 | public RenderFrameObserver { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 88 | public: |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 89 | static gin::WrapperInfo kWrapperInfo; |
| 90 | |
[email protected] | cfa856d6 | 2014-02-22 07:58:40 | [diff] [blame] | 91 | static void Install(RenderFrame* render_frame, blink::WebFrame* frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 92 | |
| 93 | // Makes the renderer send a javascript value to the app. |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 94 | // The value to be sent can be either of type String, |
| 95 | // Number (double casted to int32) or Boolean. Any other type or no |
| 96 | // argument at all is ignored. |
[email protected] | 480116e7c | 2014-01-13 12:10:04 | [diff] [blame] | 97 | bool SendMsg(const gin::Arguments& args); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 98 | |
[email protected] | a9602de | 2010-03-18 23:43:11 | [diff] [blame] | 99 | // Makes the renderer send a javascript value to the app. |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 100 | // The value should be properly formed JSON. |
| 101 | bool SendJSON(const std::string& json); |
[email protected] | a9602de | 2010-03-18 23:43:11 | [diff] [blame] | 102 | |
[email protected] | 09f3707 | 2012-03-26 19:36:23 | [diff] [blame] | 103 | // Sends a string with a provided Automation Id. |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 104 | bool SendWithId(int automation_id, const std::string& str); |
[email protected] | 09f3707 | 2012-03-26 19:36:23 | [diff] [blame] | 105 | |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 106 | bool SetAutomationId(int automation_id); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 107 | |
| 108 | private: |
[email protected] | cfa856d6 | 2014-02-22 07:58:40 | [diff] [blame] | 109 | explicit DomAutomationController(RenderFrame* render_view); |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 110 | ~DomAutomationController() override; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 111 | |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 112 | // gin::WrappableBase |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 113 | gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
mohan.reddy | ee0b42a | 2014-10-08 04:53:14 | [diff] [blame] | 114 | v8::Isolate* isolate) override; |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 115 | |
[email protected] | 480116e7c | 2014-01-13 12:10:04 | [diff] [blame] | 116 | // RenderViewObserver |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 117 | void OnDestruct() override; |
mdjones | 28f3694 | 2015-09-24 00:48:22 | [diff] [blame] | 118 | void DidCreateScriptContext(v8::Local<v8::Context> context, |
| 119 | int extension_group, |
| 120 | int world_id) override; |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 121 | |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 122 | int automation_id_; // routing id to be used by the next channel. |
[email protected] | caa8dc04 | 2014-01-13 12:07:58 | [diff] [blame] | 123 | |
| 124 | DISALLOW_COPY_AND_ASSIGN(DomAutomationController); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 125 | }; |
| 126 | |
[email protected] | 9a292e2 | 2012-10-22 15:19:31 | [diff] [blame] | 127 | } // namespace content |
| 128 | |
[email protected] | 766a708 | 2012-02-03 23:39:15 | [diff] [blame] | 129 | #endif // CONTENT_RENDERER_DOM_AUTOMATION_CONTROLLER_H_ |