OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_DOM_AUTOMATION_CONTROLLER_H_ | 5 #ifndef CONTENT_RENDERER_DOM_AUTOMATION_CONTROLLER_H_ |
6 #define CONTENT_RENDERER_DOM_AUTOMATION_CONTROLLER_H_ | 6 #define CONTENT_RENDERER_DOM_AUTOMATION_CONTROLLER_H_ |
7 | 7 |
8 #include "ipc/ipc_sender.h" | 8 #include "base/basictypes.h" |
9 #include "webkit/renderer/cpp_bound_class.h" | 9 #include "gin/wrappable.h" |
10 | 10 |
11 /* DomAutomationController class: | 11 /* DomAutomationController class: |
12 Bound to Javascript window.domAutomationController object. | 12 Bound to Javascript window.domAutomationController object. |
13 At the very basic, this object makes any native value (string, numbers, | 13 At the very basic, this object makes any native value (string, numbers, |
14 boolean) from javascript available to the automation host in Cpp. | 14 boolean) from javascript available to the automation host in Cpp. |
15 Any renderer implementation that is built with this binding will allow the | 15 Any renderer implementation that is built with this binding will allow the |
16 above facility. | 16 above facility. |
17 The intended use of this object is to expose the DOM Objects and their | 17 The intended use of this object is to expose the DOM Objects and their |
18 attributes to the automation host. | 18 attributes to the automation host. |
19 | 19 |
(...skipping 23 matching lines...) Expand all Loading... |
43 |-------|WebContentsImpl|<--------| | 43 |-------|WebContentsImpl|<--------| |
44 | 44 |
45 | 45 |
46 Legends: | 46 Legends: |
47 - AProxy = AutomationProxy | 47 - AProxy = AutomationProxy |
48 - AProvider = AutomationProvider | 48 - AProvider = AutomationProvider |
49 - DAController = DomAutomationController | 49 - DAController = DomAutomationController |
50 | 50 |
51 (0) Initialization step where DAController is bound to the renderer | 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 | 52 and the view_id of the renderer is supplied to the DAController for |
53 routing message in (5). (routing_id_) | 53 routing message in (5). |
54 (1) A 'javascript:' url is sent from the test process to master as an IPC | 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_) | 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 | 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 | 57 the bound method setAutomationId(). This is required for routing message |
58 in (6). | 58 in (6). |
59 (3) The 'javascript:' url is sent for execution by calling into | 59 (3) The 'javascript:' url is sent for execution by calling into |
60 Browser::LoadURL() | 60 Browser::LoadURL() |
61 (4) A callback is generated as a result of domAutomationController.send() | 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. | 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 | 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 | 64 stored automation_id_ as an IPC message. The frame_'s RenderFrameImpl is |
65 the message. (IPC messages, ViewHostMsg_*DomAutomation* ) | 65 used to route the message. (IPC messages, ViewHostMsg_*DomAutomation* ) |
66 (6) The value and the automation_id_ is extracted out of the message received | 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. | 67 in (5). This value is relayed to AProxy using another IPC message. |
68 automation_id_ is used to route the message. | 68 automation_id_ is used to route the message. |
69 (IPC messages, AutomationMsg_Dom*Response) | 69 (IPC messages, AutomationMsg_Dom*Response) |
70 | 70 |
71 */ | 71 */ |
72 | 72 |
| 73 namespace blink { |
| 74 class WebFrame; |
| 75 } |
| 76 |
| 77 namespace gin { |
| 78 class Arguments; |
| 79 } |
| 80 |
73 namespace content { | 81 namespace content { |
74 | 82 |
75 // TODO(vibhor): Add another method-pair like sendLater() and sendNow() | 83 class DomAutomationController : public gin::Wrappable<DomAutomationController> { |
76 // sendLater() should keep building a json serializer | |
77 // sendNow() should send the above serializer as a string. | |
78 class DomAutomationController : public webkit_glue::CppBoundClass { | |
79 public: | 84 public: |
80 DomAutomationController(); | 85 static gin::WrapperInfo kWrapperInfo; |
| 86 |
| 87 static void Install(blink::WebFrame* frame); |
81 | 88 |
82 // Makes the renderer send a javascript value to the app. | 89 // Makes the renderer send a javascript value to the app. |
83 // The value to be sent can be either of type NPString, | 90 // The value to be sent can be either of type String, |
84 // Number (double casted to int32) or boolean. | 91 // Number (double casted to int32) or Boolean. Any other type or no |
85 // The function returns true/false based on the result of actual send over | 92 // argument at all is ignored. |
86 // IPC. It sets the return value to null on unexpected errors or arguments. | 93 bool Send(const gin::Arguments& args); |
87 void Send(const webkit_glue::CppArgumentList& args, | |
88 webkit_glue::CppVariant* result); | |
89 | 94 |
90 // Makes the renderer send a javascript value to the app. | 95 // Makes the renderer send a javascript value to the app. |
91 // The value must be a NPString and should be properly formed JSON. | 96 // The value should be properly formed JSON. |
92 // This function does not modify/escape the returned string in any way. | 97 bool SendJSON(const std::string& json); |
93 void SendJSON(const webkit_glue::CppArgumentList& args, | |
94 webkit_glue::CppVariant* result); | |
95 | 98 |
96 // Sends a string with a provided Automation Id. | 99 // Sends a string with a provided Automation Id. |
97 // Expects two javascript values; the first must be a number type and will be | 100 bool SendWithId(int automation_id, const std::string& str); |
98 // used as the Automation Id, the second must be of type NPString. | |
99 // The function returns true/false to the javascript based on the success | |
100 // of the send over IPC. It sets the javascript return value to null on | |
101 // unexpected errors or arguments. | |
102 void SendWithId(const webkit_glue::CppArgumentList& args, | |
103 webkit_glue::CppVariant* result); | |
104 | 101 |
105 void SetAutomationId(const webkit_glue::CppArgumentList& args, | 102 bool SetAutomationId(int automation_id); |
106 webkit_glue::CppVariant* result); | |
107 | |
108 // TODO(vibhor): Implement later | |
109 // static CppBindingObjectMethod sendLater; | |
110 // static CppBindingObjectMethod sendNow; | |
111 | |
112 void set_routing_id(int routing_id) { routing_id_ = routing_id; } | |
113 | |
114 void set_message_sender(IPC::Sender* sender) { | |
115 sender_ = sender; | |
116 } | |
117 | 103 |
118 private: | 104 private: |
119 IPC::Sender* sender_; | 105 explicit DomAutomationController(blink::WebFrame* frame); |
| 106 virtual ~DomAutomationController(); |
120 | 107 |
121 // Refer to the comments at the top of the file for more details. | 108 // gin::WrappableBase |
122 int routing_id_; // routing id to be used by first channel. | 109 virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
| 110 v8::Isolate* isolate) OVERRIDE; |
| 111 |
| 112 blink::WebFrame* frame_; |
| 113 |
123 int automation_id_; // routing id to be used by the next channel. | 114 int automation_id_; // routing id to be used by the next channel. |
| 115 |
| 116 DISALLOW_COPY_AND_ASSIGN(DomAutomationController); |
124 }; | 117 }; |
125 | 118 |
126 } // namespace content | 119 } // namespace content |
127 | 120 |
128 #endif // CONTENT_RENDERER_DOM_AUTOMATION_CONTROLLER_H_ | 121 #endif // CONTENT_RENDERER_DOM_AUTOMATION_CONTROLLER_H_ |
OLD | NEW |