OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/test/chromedriver/devtools_client.h" |
| 6 |
| 7 #include "base/json/json_writer.h" |
| 8 #include "base/values.h" |
| 9 #include "chrome/test/chromedriver/net/sync_websocket.h" |
| 10 #include "chrome/test/chromedriver/net/url_request_context_getter.h" |
| 11 #include "chrome/test/chromedriver/status.h" |
| 12 #include "googleurl/src/gurl.h" |
| 13 |
| 14 DevToolsClient::DevToolsClient( |
| 15 URLRequestContextGetter* context_getter, |
| 16 const std::string& url) |
| 17 : context_getter_(context_getter), |
| 18 url_(url), |
| 19 socket_(new SyncWebSocket(context_getter)), |
| 20 connected_(false) {} |
| 21 |
| 22 DevToolsClient::~DevToolsClient() {} |
| 23 |
| 24 Status DevToolsClient::SendCommand( |
| 25 const std::string& method, |
| 26 const base::DictionaryValue& params) { |
| 27 if (!connected_) { |
| 28 if (!socket_->Connect(GURL(url_))) |
| 29 return Status(kUnknownError, "unable to connect to renderer"); |
| 30 connected_ = true; |
| 31 } |
| 32 base::DictionaryValue command; |
| 33 command.SetInteger("id", 1); |
| 34 command.SetString("method", method); |
| 35 command.Set("params", params.DeepCopy()); |
| 36 std::string message; |
| 37 base::JSONWriter::Write(&command, &message); |
| 38 if (!socket_->Send(message)) |
| 39 return Status(kUnknownError, "unable to send message to renderer"); |
| 40 std::string response; |
| 41 if (!socket_->ReceiveNextMessage(&response)) |
| 42 return Status(kUnknownError, "unable to receive message from renderer"); |
| 43 return Status(kOk); |
| 44 } |
OLD | NEW |