| 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 "base/basictypes.h" | 8 #include "ipc/ipc_sender.h" |
| 9 #include "gin/wrappable.h" | 9 #include "webkit/renderer/cpp_bound_class.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). | 53 routing message in (5). (routing_id_) |
| 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. The frame_'s RenderFrameImpl is | 64 stored automation_id_ as an IPC message. routing_id_ is used to route |
| 65 used to route the message. (IPC messages, ViewHostMsg_*DomAutomation* ) | 65 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 | |
| 81 namespace content { | 73 namespace content { |
| 82 | 74 |
| 83 class DomAutomationController : public gin::Wrappable<DomAutomationController> { | 75 // TODO(vibhor): Add another method-pair like sendLater() and sendNow() |
| 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 { |
| 84 public: | 79 public: |
| 85 static gin::WrapperInfo kWrapperInfo; | 80 DomAutomationController(); |
| 86 | |
| 87 static void Install(blink::WebFrame* frame); | |
| 88 | 81 |
| 89 // Makes the renderer send a javascript value to the app. | 82 // Makes the renderer send a javascript value to the app. |
| 90 // The value to be sent can be either of type String, | 83 // The value to be sent can be either of type NPString, |
| 91 // Number (double casted to int32) or Boolean. Any other type or no | 84 // Number (double casted to int32) or boolean. |
| 92 // argument at all is ignored. | 85 // The function returns true/false based on the result of actual send over |
| 93 bool Send(const gin::Arguments& args); | 86 // IPC. It sets the return value to null on unexpected errors or arguments. |
| 87 void Send(const webkit_glue::CppArgumentList& args, |
| 88 webkit_glue::CppVariant* result); |
| 94 | 89 |
| 95 // Makes the renderer send a javascript value to the app. | 90 // Makes the renderer send a javascript value to the app. |
| 96 // The value should be properly formed JSON. | 91 // The value must be a NPString and should be properly formed JSON. |
| 97 bool SendJSON(const std::string& json); | 92 // This function does not modify/escape the returned string in any way. |
| 93 void SendJSON(const webkit_glue::CppArgumentList& args, |
| 94 webkit_glue::CppVariant* result); |
| 98 | 95 |
| 99 // Sends a string with a provided Automation Id. | 96 // Sends a string with a provided Automation Id. |
| 100 bool SendWithId(int automation_id, const std::string& str); | 97 // Expects two javascript values; the first must be a number type and will be |
| 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); |
| 101 | 104 |
| 102 bool SetAutomationId(int automation_id); | 105 void SetAutomationId(const webkit_glue::CppArgumentList& args, |
| 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 } |
| 103 | 117 |
| 104 private: | 118 private: |
| 105 explicit DomAutomationController(blink::WebFrame* frame); | 119 IPC::Sender* sender_; |
| 106 virtual ~DomAutomationController(); | |
| 107 | 120 |
| 108 // gin::WrappableBase | 121 // Refer to the comments at the top of the file for more details. |
| 109 virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | 122 int routing_id_; // routing id to be used by first channel. |
| 110 v8::Isolate* isolate) OVERRIDE; | |
| 111 | |
| 112 blink::WebFrame* frame_; | |
| 113 | |
| 114 int automation_id_; // routing id to be used by the next channel. | 123 int automation_id_; // routing id to be used by the next channel. |
| 115 | |
| 116 DISALLOW_COPY_AND_ASSIGN(DomAutomationController); | |
| 117 }; | 124 }; |
| 118 | 125 |
| 119 } // namespace content | 126 } // namespace content |
| 120 | 127 |
| 121 #endif // CONTENT_RENDERER_DOM_AUTOMATION_CONTROLLER_H_ | 128 #endif // CONTENT_RENDERER_DOM_AUTOMATION_CONTROLLER_H_ |
| OLD | NEW |