Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: components/web_view/frame_devtools_agent.cc

Issue 1548203002: Convert Pass()→std::move() in //components/[n-z]* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bad headers Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/web_view/frame_connection.cc ('k') | components/web_view/frame_tree.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/web_view/frame_devtools_agent.h" 5 #include "components/web_view/frame_devtools_agent.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/guid.h" 12 #include "base/guid.h"
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "components/web_view/frame_devtools_agent_delegate.h" 17 #include "components/web_view/frame_devtools_agent_delegate.h"
18 #include "mojo/application/public/cpp/application_impl.h" 18 #include "mojo/application/public/cpp/application_impl.h"
(...skipping 18 matching lines...) Expand all
37 37
38 } // namespace 38 } // namespace
39 39
40 // This class is used by FrameDevToolsAgent to relay client messages from the 40 // This class is used by FrameDevToolsAgent to relay client messages from the
41 // frame to the DevTools service. 41 // frame to the DevTools service.
42 class FrameDevToolsAgent::FrameDevToolsAgentClient 42 class FrameDevToolsAgent::FrameDevToolsAgentClient
43 : public devtools_service::DevToolsAgentClient { 43 : public devtools_service::DevToolsAgentClient {
44 public: 44 public:
45 FrameDevToolsAgentClient(FrameDevToolsAgent* owner, 45 FrameDevToolsAgentClient(FrameDevToolsAgent* owner,
46 DevToolsAgentClientPtr forward_client) 46 DevToolsAgentClientPtr forward_client)
47 : owner_(owner), binding_(this), forward_client_(forward_client.Pass()) { 47 : owner_(owner),
48 binding_(this),
49 forward_client_(std::move(forward_client)) {
48 forward_client_.set_connection_error_handler(base::Bind( 50 forward_client_.set_connection_error_handler(base::Bind(
49 &FrameDevToolsAgent::OnForwardClientClosed, base::Unretained(owner_))); 51 &FrameDevToolsAgent::OnForwardClientClosed, base::Unretained(owner_)));
50 if (owner_->forward_agent_) 52 if (owner_->forward_agent_)
51 OnAttachedFrame(); 53 OnAttachedFrame();
52 } 54 }
53 55
54 ~FrameDevToolsAgentClient() override {} 56 ~FrameDevToolsAgentClient() override {}
55 57
56 void OnAttachedFrame() { 58 void OnAttachedFrame() {
57 DCHECK(owner_->forward_agent_); 59 DCHECK(owner_->forward_agent_);
58 60
59 if (binding_.is_bound()) 61 if (binding_.is_bound())
60 binding_.Close(); 62 binding_.Close();
61 63
62 DevToolsAgentClientPtr client; 64 DevToolsAgentClientPtr client;
63 binding_.Bind(&client); 65 binding_.Bind(&client);
64 owner_->forward_agent_->SetClient(client.Pass()); 66 owner_->forward_agent_->SetClient(std::move(client));
65 } 67 }
66 68
67 private: 69 private:
68 // DevToolsAgentClient implementation. 70 // DevToolsAgentClient implementation.
69 void DispatchProtocolMessage(int32_t call_id, 71 void DispatchProtocolMessage(int32_t call_id,
70 const String& message, 72 const String& message,
71 const String& state) override { 73 const String& state) override {
72 DCHECK(forward_client_); 74 DCHECK(forward_client_);
73 owner_->OnReceivedClientMessage(call_id, message, state); 75 owner_->OnReceivedClientMessage(call_id, message, state);
74 // The state is used to persist state across frame navigations. There is no 76 // The state is used to persist state across frame navigations. There is no
(...skipping 20 matching lines...) Expand all
95 DCHECK(app_); 97 DCHECK(app_);
96 DCHECK(delegate_); 98 DCHECK(delegate_);
97 } 99 }
98 100
99 FrameDevToolsAgent::~FrameDevToolsAgent() {} 101 FrameDevToolsAgent::~FrameDevToolsAgent() {}
100 102
101 void FrameDevToolsAgent::AttachFrame( 103 void FrameDevToolsAgent::AttachFrame(
102 DevToolsAgentPtr forward_agent, 104 DevToolsAgentPtr forward_agent,
103 Frame::ClientPropertyMap* devtools_properties) { 105 Frame::ClientPropertyMap* devtools_properties) {
104 RegisterAgentIfNecessary(); 106 RegisterAgentIfNecessary();
105 forward_agent_ = forward_agent.Pass(); 107 forward_agent_ = std::move(forward_agent);
106 108
107 StringToVector(id_, &(*devtools_properties)["devtools-id"]); 109 StringToVector(id_, &(*devtools_properties)["devtools-id"]);
108 if (client_impl_) { 110 if (client_impl_) {
109 StringToVector(state_, &(*devtools_properties)["devtools-state"]); 111 StringToVector(state_, &(*devtools_properties)["devtools-state"]);
110 client_impl_->OnAttachedFrame(); 112 client_impl_->OnAttachedFrame();
111 } 113 }
112 114
113 // This follows Chrome's logic and relies on the fact that call IDs increase 115 // This follows Chrome's logic and relies on the fact that call IDs increase
114 // monotonously so iterating over |pending_messages_| preserves the order in 116 // monotonously so iterating over |pending_messages_| preserves the order in
115 // which they were received. 117 // which they were received.
116 for (const auto& item : pending_messages_) 118 for (const auto& item : pending_messages_)
117 forward_agent_->DispatchProtocolMessage(item.second); 119 forward_agent_->DispatchProtocolMessage(item.second);
118 } 120 }
119 121
120 void FrameDevToolsAgent::RegisterAgentIfNecessary() { 122 void FrameDevToolsAgent::RegisterAgentIfNecessary() {
121 if (binding_.is_bound()) 123 if (binding_.is_bound())
122 return; 124 return;
123 125
124 DevToolsRegistryPtr devtools_registry; 126 DevToolsRegistryPtr devtools_registry;
125 app_->ConnectToService("mojo:devtools_service", &devtools_registry); 127 app_->ConnectToService("mojo:devtools_service", &devtools_registry);
126 128
127 DevToolsAgentPtr agent; 129 DevToolsAgentPtr agent;
128 binding_.Bind(&agent); 130 binding_.Bind(&agent);
129 devtools_registry->RegisterAgent(id_, agent.Pass()); 131 devtools_registry->RegisterAgent(id_, std::move(agent));
130 } 132 }
131 133
132 void FrameDevToolsAgent::HandlePageNavigateRequest( 134 void FrameDevToolsAgent::HandlePageNavigateRequest(
133 const base::DictionaryValue* request) { 135 const base::DictionaryValue* request) {
134 std::string method; 136 std::string method;
135 if (!request->GetString("method", &method) || method != "Page.navigate") 137 if (!request->GetString("method", &method) || method != "Page.navigate")
136 return; 138 return;
137 139
138 std::string url_string; 140 std::string url_string;
139 if (!request->GetString("params.url", &url_string)) 141 if (!request->GetString("params.url", &url_string))
140 return; 142 return;
141 143
142 GURL url(url_string); 144 GURL url(url_string);
143 if (!url.is_valid()) 145 if (!url.is_valid())
144 return; 146 return;
145 147
146 // Stop sending messages to the old frame which will be navigated away soon. 148 // Stop sending messages to the old frame which will be navigated away soon.
147 // However, we don't reset |client_impl_| because we want to receive responses 149 // However, we don't reset |client_impl_| because we want to receive responses
148 // and events from the old frame in the meantime. 150 // and events from the old frame in the meantime.
149 forward_agent_.reset(); 151 forward_agent_.reset();
150 152
151 delegate_->HandlePageNavigateRequest(url); 153 delegate_->HandlePageNavigateRequest(url);
152 } 154 }
153 155
154 void FrameDevToolsAgent::SetClient(DevToolsAgentClientPtr client) { 156 void FrameDevToolsAgent::SetClient(DevToolsAgentClientPtr client) {
155 client_impl_.reset(new FrameDevToolsAgentClient(this, client.Pass())); 157 client_impl_.reset(new FrameDevToolsAgentClient(this, std::move(client)));
156 } 158 }
157 159
158 void FrameDevToolsAgent::DispatchProtocolMessage(const String& message) { 160 void FrameDevToolsAgent::DispatchProtocolMessage(const String& message) {
159 // TODO(yzshen): Consider refactoring and reusing the existing DevTools 161 // TODO(yzshen): Consider refactoring and reusing the existing DevTools
160 // protocol parsing code. 162 // protocol parsing code.
161 163
162 scoped_ptr<base::Value> value = base::JSONReader::Read(message.get()); 164 scoped_ptr<base::Value> value = base::JSONReader::Read(message.get());
163 base::DictionaryValue* command = nullptr; 165 base::DictionaryValue* command = nullptr;
164 if (!value || !value->GetAsDictionary(&command)) { 166 if (!value || !value->GetAsDictionary(&command)) {
165 VLOG(1) << "Unable to parse DevTools message: " << message; 167 VLOG(1) << "Unable to parse DevTools message: " << message;
(...skipping 23 matching lines...) Expand all
189 pending_messages_.erase(call_id); 191 pending_messages_.erase(call_id);
190 } 192 }
191 193
192 void FrameDevToolsAgent::OnForwardClientClosed() { 194 void FrameDevToolsAgent::OnForwardClientClosed() {
193 client_impl_.reset(); 195 client_impl_.reset();
194 state_.clear(); 196 state_.clear();
195 pending_messages_.clear(); 197 pending_messages_.clear();
196 } 198 }
197 199
198 } // namespace web_view 200 } // namespace web_view
OLDNEW
« no previous file with comments | « components/web_view/frame_connection.cc ('k') | components/web_view/frame_tree.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698