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 #include "content/renderer/dom_automation_controller.h" | 5 #include "content/renderer/dom_automation_controller.h" |
6 | 6 |
7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "content/child/v8_value_converter_impl.h" | 9 #include "content/child/v8_value_converter_impl.h" |
10 #include "content/common/child_process_messages.h" | 10 #include "content/common/child_process_messages.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 return gin::Wrappable<DomAutomationController>::GetObjectTemplateBuilder( | 51 return gin::Wrappable<DomAutomationController>::GetObjectTemplateBuilder( |
52 isolate) | 52 isolate) |
53 .SetMethod("send", &DomAutomationController::SendMsg) | 53 .SetMethod("send", &DomAutomationController::SendMsg) |
54 .SetMethod("setAutomationId", &DomAutomationController::SetAutomationId) | 54 .SetMethod("setAutomationId", &DomAutomationController::SetAutomationId) |
55 .SetMethod("sendJSON", &DomAutomationController::SendJSON) | 55 .SetMethod("sendJSON", &DomAutomationController::SendJSON) |
56 .SetMethod("sendWithId", &DomAutomationController::SendWithId); | 56 .SetMethod("sendWithId", &DomAutomationController::SendWithId); |
57 } | 57 } |
58 | 58 |
59 void DomAutomationController::OnDestruct() {} | 59 void DomAutomationController::OnDestruct() {} |
60 | 60 |
| 61 void DomAutomationController::DidCreateScriptContext( |
| 62 v8::Local<v8::Context> context, |
| 63 int extension_group, |
| 64 int world_id) { |
| 65 // Add the domAutomationController to isolated worlds as well. |
| 66 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 67 v8::HandleScope handle_scope(isolate); |
| 68 if (context.IsEmpty()) |
| 69 return; |
| 70 |
| 71 v8::Context::Scope context_scope(context); |
| 72 |
| 73 // Resuse this object instead of creating others. |
| 74 gin::Handle<DomAutomationController> controller = |
| 75 gin::CreateHandle(isolate, this); |
| 76 if (controller.IsEmpty()) |
| 77 return; |
| 78 |
| 79 v8::Local<v8::Object> global = context->Global(); |
| 80 global->Set(gin::StringToV8(isolate, "domAutomationController"), |
| 81 controller.ToV8()); |
| 82 } |
| 83 |
61 bool DomAutomationController::SendMsg(const gin::Arguments& args) { | 84 bool DomAutomationController::SendMsg(const gin::Arguments& args) { |
62 if (!render_frame()) | 85 if (!render_frame()) |
63 return false; | 86 return false; |
64 | 87 |
65 if (automation_id_ == MSG_ROUTING_NONE) | 88 if (automation_id_ == MSG_ROUTING_NONE) |
66 return false; | 89 return false; |
67 | 90 |
68 std::string json; | 91 std::string json; |
69 JSONStringValueSerializer serializer(&json); | 92 JSONStringValueSerializer serializer(&json); |
70 scoped_ptr<base::Value> value; | 93 scoped_ptr<base::Value> value; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 return Send( | 138 return Send( |
116 new FrameHostMsg_DomOperationResponse(routing_id(), str, automation_id)); | 139 new FrameHostMsg_DomOperationResponse(routing_id(), str, automation_id)); |
117 } | 140 } |
118 | 141 |
119 bool DomAutomationController::SetAutomationId(int automation_id) { | 142 bool DomAutomationController::SetAutomationId(int automation_id) { |
120 automation_id_ = automation_id; | 143 automation_id_ = automation_id; |
121 return true; | 144 return true; |
122 } | 145 } |
123 | 146 |
124 } // namespace content | 147 } // namespace content |
OLD | NEW |