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