| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/html_viewer/devtools_agent_impl.h" | 5 #include "components/html_viewer/devtools_agent_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "third_party/WebKit/public/platform/WebString.h" | 9 #include "third_party/WebKit/public/platform/WebString.h" |
| 10 #include "third_party/WebKit/public/web/WebDevToolsAgent.h" | 10 #include "third_party/WebKit/public/web/WebDevToolsAgent.h" |
| 11 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 11 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 12 | 12 |
| 13 namespace html_viewer { | 13 namespace html_viewer { |
| 14 | 14 |
| 15 DevToolsAgentImpl::DevToolsAgentImpl(blink::WebLocalFrame* frame, | 15 DevToolsAgentImpl::DevToolsAgentImpl(blink::WebLocalFrame* frame, |
| 16 const std::string& id, | 16 const std::string& id, |
| 17 const std::string* state) | 17 const std::string* state) |
| 18 : frame_(frame), id_(id), binding_(this), cache_until_client_ready_(false) { | 18 : frame_(frame), id_(id), binding_(this), cache_until_client_ready_(false) { |
| 19 DCHECK(frame); | 19 DCHECK(frame); |
| 20 frame_->setDevToolsAgentClient(this); | 20 frame_->setDevToolsAgentClient(this); |
| 21 | 21 |
| 22 if (state) { | 22 if (state) { |
| 23 cache_until_client_ready_ = true; | 23 cache_until_client_ready_ = true; |
| 24 frame_->devToolsAgent()->reattach(blink::WebString::fromUTF8(id_), | 24 frame_->devToolsAgent()->reattach(blink::WebString::fromUTF8(id_), 0, |
| 25 blink::WebString::fromUTF8(*state)); | 25 blink::WebString::fromUTF8(*state)); |
| 26 } | 26 } |
| 27 } | 27 } |
| 28 | 28 |
| 29 DevToolsAgentImpl::~DevToolsAgentImpl() { | 29 DevToolsAgentImpl::~DevToolsAgentImpl() { |
| 30 if (cache_until_client_ready_ || client_) | 30 if (cache_until_client_ready_ || client_) |
| 31 frame_->devToolsAgent()->detach(); | 31 frame_->devToolsAgent()->detach(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void DevToolsAgentImpl::BindToRequest( | 34 void DevToolsAgentImpl::BindToRequest( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 45 client_.set_connection_error_handler(base::Bind( | 45 client_.set_connection_error_handler(base::Bind( |
| 46 &DevToolsAgentImpl::OnConnectionError, base::Unretained(this))); | 46 &DevToolsAgentImpl::OnConnectionError, base::Unretained(this))); |
| 47 | 47 |
| 48 if (cache_until_client_ready_) { | 48 if (cache_until_client_ready_) { |
| 49 cache_until_client_ready_ = false; | 49 cache_until_client_ready_ = false; |
| 50 for (const auto& message : cached_client_messages_) | 50 for (const auto& message : cached_client_messages_) |
| 51 client_->DispatchProtocolMessage(message.call_id, message.response, | 51 client_->DispatchProtocolMessage(message.call_id, message.response, |
| 52 message.state); | 52 message.state); |
| 53 cached_client_messages_.clear(); | 53 cached_client_messages_.clear(); |
| 54 } else { | 54 } else { |
| 55 frame_->devToolsAgent()->attach(blink::WebString::fromUTF8(id_)); | 55 frame_->devToolsAgent()->attach(blink::WebString::fromUTF8(id_), 0); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 void DevToolsAgentImpl::DispatchProtocolMessage(const mojo::String& message) { | 59 void DevToolsAgentImpl::DispatchProtocolMessage(const mojo::String& message) { |
| 60 frame_->devToolsAgent()->dispatchOnInspectorBackend( | 60 frame_->devToolsAgent()->dispatchOnInspectorBackend( |
| 61 blink::WebString::fromUTF8(message)); | 61 0, blink::WebString::fromUTF8(message)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void DevToolsAgentImpl::sendProtocolMessage(int call_id, | 64 void DevToolsAgentImpl::sendProtocolMessage(int session_id, |
| 65 int call_id, |
| 65 const blink::WebString& response, | 66 const blink::WebString& response, |
| 66 const blink::WebString& state) { | 67 const blink::WebString& state) { |
| 67 DCHECK(!response.isNull()); | 68 DCHECK(!response.isNull()); |
| 68 | 69 |
| 69 mojo::String response_str = response.utf8(); | 70 mojo::String response_str = response.utf8(); |
| 70 mojo::String state_str; | 71 mojo::String state_str; |
| 71 if (!state.isNull()) | 72 if (!state.isNull()) |
| 72 state_str = state.utf8(); | 73 state_str = state.utf8(); |
| 73 | 74 |
| 74 if (client_) { | 75 if (client_) { |
| 75 client_->DispatchProtocolMessage(call_id, response_str, state_str); | 76 client_->DispatchProtocolMessage(call_id, response_str, state_str); |
| 76 } else if (cache_until_client_ready_) { | 77 } else if (cache_until_client_ready_) { |
| 77 cached_client_messages_.resize(cached_client_messages_.size() + 1); | 78 cached_client_messages_.resize(cached_client_messages_.size() + 1); |
| 78 CachedClientMessage& message = cached_client_messages_.back(); | 79 CachedClientMessage& message = cached_client_messages_.back(); |
| 79 message.call_id = call_id; | 80 message.call_id = call_id; |
| 80 message.response.Swap(&response_str); | 81 message.response.Swap(&response_str); |
| 81 message.state.Swap(&state_str); | 82 message.state.Swap(&state_str); |
| 82 } | 83 } |
| 83 } | 84 } |
| 84 | 85 |
| 85 void DevToolsAgentImpl::OnConnectionError() { | 86 void DevToolsAgentImpl::OnConnectionError() { |
| 86 client_.reset(); | 87 client_.reset(); |
| 87 frame_->devToolsAgent()->detach(); | 88 frame_->devToolsAgent()->detach(); |
| 88 } | 89 } |
| 89 | 90 |
| 90 } // namespace html_viewer | 91 } // namespace html_viewer |
| OLD | NEW |