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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 automation_id_(MSG_ROUTING_NONE) { | 24 automation_id_(MSG_ROUTING_NONE) { |
25 BindCallback("send", base::Bind(&DomAutomationController::Send, | 25 BindCallback("send", base::Bind(&DomAutomationController::Send, |
26 base::Unretained(this))); | 26 base::Unretained(this))); |
27 BindCallback("setAutomationId", | 27 BindCallback("setAutomationId", |
28 base::Bind(&DomAutomationController::SetAutomationId, | 28 base::Bind(&DomAutomationController::SetAutomationId, |
29 base::Unretained(this))); | 29 base::Unretained(this))); |
30 BindCallback("sendJSON", base::Bind(&DomAutomationController::SendJSON, | 30 BindCallback("sendJSON", base::Bind(&DomAutomationController::SendJSON, |
31 base::Unretained(this))); | 31 base::Unretained(this))); |
32 BindCallback("sendWithId", base::Bind(&DomAutomationController::SendWithId, | 32 BindCallback("sendWithId", base::Bind(&DomAutomationController::SendWithId, |
33 base::Unretained(this))); | 33 base::Unretained(this))); |
34 BindCallback("getHistogram", | |
35 base::Bind(&DomAutomationController::GetHistogram, | |
36 base::Unretained(this))); | |
37 BindCallback("getBrowserHistogram", | |
38 base::Bind(&DomAutomationController::GetBrowserHistogram, | |
39 base::Unretained(this))); | |
40 } | 34 } |
41 | 35 |
42 void DomAutomationController::Send(const CppArgumentList& args, | 36 void DomAutomationController::Send(const CppArgumentList& args, |
43 CppVariant* result) { | 37 CppVariant* result) { |
44 if (args.size() != 1) { | 38 if (args.size() != 1) { |
45 result->SetNull(); | 39 result->SetNull(); |
46 return; | 40 return; |
47 } | 41 } |
48 | 42 |
49 if (automation_id_ == MSG_ROUTING_NONE) { | 43 if (automation_id_ == MSG_ROUTING_NONE) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // KJS::JSType only defines a NumberType (no Int32) | 164 // KJS::JSType only defines a NumberType (no Int32) |
171 if (!args[0].isNumber()) { | 165 if (!args[0].isNumber()) { |
172 result->SetNull(); | 166 result->SetNull(); |
173 return; | 167 return; |
174 } | 168 } |
175 | 169 |
176 automation_id_ = args[0].ToInt32(); | 170 automation_id_ = args[0].ToInt32(); |
177 result->Set(true); | 171 result->Set(true); |
178 } | 172 } |
179 | 173 |
180 void DomAutomationController::GetHistogram(const CppArgumentList& args, | |
181 CppVariant* result) { | |
182 if (args.size() != 1) { | |
183 result->SetNull(); | |
184 return; | |
185 } | |
186 base::HistogramBase* histogram = | |
187 base::StatisticsRecorder::FindHistogram(args[0].ToString()); | |
188 std::string output; | |
189 if (!histogram) { | |
190 output = "{}"; | |
191 } else { | |
192 histogram->WriteJSON(&output); | |
193 } | |
194 result->Set(output); | |
195 } | |
196 | |
197 void DomAutomationController::GetBrowserHistogram(const CppArgumentList& args, | |
198 CppVariant* result) { | |
199 if (args.size() != 1) { | |
200 result->SetNull(); | |
201 return; | |
202 } | |
203 | |
204 if (!sender_) { | |
205 NOTREACHED(); | |
206 result->SetNull(); | |
207 return; | |
208 } | |
209 | |
210 std::string histogram_json; | |
211 sender_->Send(new ChildProcessHostMsg_GetBrowserHistogram( | |
212 args[0].ToString(), &histogram_json)); | |
213 result->Set(histogram_json); | |
214 } | |
215 | |
216 } // namespace content | 174 } // namespace content |
OLD | NEW |