blob: 01efefdf08f237a11aac1e317036db05024b749f [file] [log] [blame]
[email protected]766a7082012-02-03 23:39:151// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]766a7082012-02-03 23:39:155#ifndef CONTENT_RENDERER_DOM_AUTOMATION_CONTROLLER_H_
6#define CONTENT_RENDERER_DOM_AUTOMATION_CONTROLLER_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]caa8dc042014-01-13 12:07:588#include "base/basictypes.h"
[email protected]cfa856d62014-02-22 07:58:409#include "content/public/renderer/render_frame_observer.h"
[email protected]caa8dc042014-01-13 12:07:5810#include "gin/wrappable.h"
initial.commit09911bf2008-07-26 23:55:2911
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]770005b2012-04-16 15:58:1344 |-------|WebContentsImpl|<--------|
initial.commit09911bf2008-07-26 23:55:2945
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]caa8dc042014-01-13 12:07:5854 routing message in (5).
initial.commit09911bf2008-07-26 23:55:2955 (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]caa8dc042014-01-13 12:07:5865 stored automation_id_ as an IPC message. The frame_'s RenderFrameImpl is
66 used to route the message. (IPC messages, ViewHostMsg_*DomAutomation* )
initial.commit09911bf2008-07-26 23:55:2967 (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]caa8dc042014-01-13 12:07:5874namespace blink {
75class WebFrame;
76}
77
78namespace gin {
79class Arguments;
80}
81
[email protected]9a292e22012-10-22 15:19:3182namespace content {
83
[email protected]cfa856d62014-02-22 07:58:4084class RenderFrame;
[email protected]480116e7c2014-01-13 12:10:0485
86class DomAutomationController : public gin::Wrappable<DomAutomationController>,
[email protected]cfa856d62014-02-22 07:58:4087 public RenderFrameObserver {
initial.commit09911bf2008-07-26 23:55:2988 public:
[email protected]caa8dc042014-01-13 12:07:5889 static gin::WrapperInfo kWrapperInfo;
90
[email protected]cfa856d62014-02-22 07:58:4091 static void Install(RenderFrame* render_frame, blink::WebFrame* frame);
initial.commit09911bf2008-07-26 23:55:2992
93 // Makes the renderer send a javascript value to the app.
[email protected]caa8dc042014-01-13 12:07:5894 // 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]480116e7c2014-01-13 12:10:0497 bool SendMsg(const gin::Arguments& args);
initial.commit09911bf2008-07-26 23:55:2998
[email protected]a9602de2010-03-18 23:43:1199 // Makes the renderer send a javascript value to the app.
[email protected]caa8dc042014-01-13 12:07:58100 // The value should be properly formed JSON.
101 bool SendJSON(const std::string& json);
[email protected]a9602de2010-03-18 23:43:11102
[email protected]09f37072012-03-26 19:36:23103 // Sends a string with a provided Automation Id.
[email protected]caa8dc042014-01-13 12:07:58104 bool SendWithId(int automation_id, const std::string& str);
[email protected]09f37072012-03-26 19:36:23105
[email protected]caa8dc042014-01-13 12:07:58106 bool SetAutomationId(int automation_id);
initial.commit09911bf2008-07-26 23:55:29107
108 private:
[email protected]cfa856d62014-02-22 07:58:40109 explicit DomAutomationController(RenderFrame* render_view);
dcheng6d18e402014-10-21 12:32:52110 ~DomAutomationController() override;
initial.commit09911bf2008-07-26 23:55:29111
[email protected]caa8dc042014-01-13 12:07:58112 // gin::WrappableBase
dcheng6d18e402014-10-21 12:32:52113 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
mohan.reddyee0b42a2014-10-08 04:53:14114 v8::Isolate* isolate) override;
[email protected]caa8dc042014-01-13 12:07:58115
[email protected]480116e7c2014-01-13 12:10:04116 // RenderViewObserver
dcheng6d18e402014-10-21 12:32:52117 void OnDestruct() override;
mdjones28f36942015-09-24 00:48:22118 void DidCreateScriptContext(v8::Local<v8::Context> context,
119 int extension_group,
120 int world_id) override;
[email protected]caa8dc042014-01-13 12:07:58121
[email protected]766a7082012-02-03 23:39:15122 int automation_id_; // routing id to be used by the next channel.
[email protected]caa8dc042014-01-13 12:07:58123
124 DISALLOW_COPY_AND_ASSIGN(DomAutomationController);
initial.commit09911bf2008-07-26 23:55:29125};
126
[email protected]9a292e22012-10-22 15:19:31127} // namespace content
128
[email protected]766a7082012-02-03 23:39:15129#endif // CONTENT_RENDERER_DOM_AUTOMATION_CONTROLLER_H_