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

Side by Side Diff: content/browser/devtools/protocol/network_handler.cc

Issue 2548263002: [DevTools] Migrate dom, emulation, inspector, network, page and schema handlers to new generator. (Closed)
Patch Set: works Created 4 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/devtools/protocol/network_handler.h" 5 #include "content/browser/devtools/protocol/network_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "content/browser/frame_host/frame_tree_node.h" 12 #include "content/browser/frame_host/frame_tree_node.h"
13 #include "content/browser/frame_host/render_frame_host_impl.h" 13 #include "content/browser/frame_host/render_frame_host_impl.h"
14 #include "content/public/browser/browser_context.h" 14 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/content_browser_client.h" 16 #include "content/public/browser/content_browser_client.h"
17 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/resource_context.h" 18 #include "content/public/browser/resource_context.h"
19 #include "content/public/browser/site_instance.h" 19 #include "content/public/browser/site_instance.h"
20 #include "content/public/browser/storage_partition.h" 20 #include "content/public/browser/storage_partition.h"
21 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/content_client.h" 22 #include "content/public/common/content_client.h"
23 #include "net/cookies/cookie_store.h" 23 #include "net/cookies/cookie_store.h"
24 #include "net/url_request/url_request_context.h" 24 #include "net/url_request/url_request_context.h"
25 #include "net/url_request/url_request_context_getter.h" 25 #include "net/url_request/url_request_context_getter.h"
26 26
27 namespace content { 27 namespace content {
28 namespace devtools { 28 namespace protocol {
29 namespace network { 29 namespace {
30 30
31 using Response = DevToolsProtocolClient::Response; 31 using GetCookiesCallback = protocol::Network::Backend::GetCookiesCallback;
32 using CookieListCallback = net::CookieStore::GetCookieListCallback; 32 using SetCookieCallback = protocol::Network::Backend::SetCookieCallback;
33 using SetCookieCallback = net::CookieStore::SetCookiesCallback; 33 using DeleteCookieCallback = protocol::Network::Backend::DeleteCookieCallback;
34
35 namespace {
36 34
37 net::URLRequestContext* GetRequestContextOnIO( 35 net::URLRequestContext* GetRequestContextOnIO(
38 ResourceContext* resource_context, 36 ResourceContext* resource_context,
39 net::URLRequestContextGetter* context_getter, 37 net::URLRequestContextGetter* context_getter,
40 const GURL& url) { 38 const GURL& url) {
41 DCHECK_CURRENTLY_ON(BrowserThread::IO); 39 DCHECK_CURRENTLY_ON(BrowserThread::IO);
42 net::URLRequestContext* context = 40 net::URLRequestContext* context =
43 GetContentClient()->browser()->OverrideRequestContextForURL( 41 GetContentClient()->browser()->OverrideRequestContextForURL(
44 url, resource_context); 42 url, resource_context);
45 if (!context) 43 if (!context)
46 context = context_getter->GetURLRequestContext(); 44 context = context_getter->GetURLRequestContext();
47 return context; 45 return context;
48 } 46 }
49 47
50 void GotCookiesForURLOnIO( 48 void GotCookiesForURLOnIO(
51 const CookieListCallback& callback, 49 const net::CookieStore::GetCookieListCallback& callback,
52 const net::CookieList& cookie_list) { 50 const net::CookieList& cookie_list) {
53 DCHECK_CURRENTLY_ON(BrowserThread::IO); 51 DCHECK_CURRENTLY_ON(BrowserThread::IO);
54 BrowserThread::PostTask( 52 BrowserThread::PostTask(
55 BrowserThread::UI, 53 BrowserThread::UI,
56 FROM_HERE, 54 FROM_HERE,
57 base::Bind(callback, cookie_list)); 55 base::Bind(callback, cookie_list));
58 } 56 }
59 57
60 void GetCookiesForURLOnIO( 58 void GetCookiesForURLOnIO(
61 ResourceContext* resource_context, 59 ResourceContext* resource_context,
62 net::URLRequestContextGetter* context_getter, 60 net::URLRequestContextGetter* context_getter,
63 const GURL& url, 61 const GURL& url,
64 const CookieListCallback& callback) { 62 const net::CookieStore::GetCookieListCallback& callback) {
65 DCHECK_CURRENTLY_ON(BrowserThread::IO); 63 DCHECK_CURRENTLY_ON(BrowserThread::IO);
66 net::URLRequestContext* request_context = 64 net::URLRequestContext* request_context =
67 GetRequestContextOnIO(resource_context, context_getter, url); 65 GetRequestContextOnIO(resource_context, context_getter, url);
68 request_context->cookie_store()->GetAllCookiesForURLAsync( 66 request_context->cookie_store()->GetAllCookiesForURLAsync(
69 url, base::Bind(&GotCookiesForURLOnIO, callback)); 67 url, base::Bind(&GotCookiesForURLOnIO, callback));
70 } 68 }
71 69
72 void GetCookiesForURLOnUI( 70 void GetCookiesForURLOnUI(
73 ResourceContext* resource_context, 71 ResourceContext* resource_context,
74 net::URLRequestContextGetter* context_getter, 72 net::URLRequestContextGetter* context_getter,
75 const GURL& url, 73 const GURL& url,
76 const CookieListCallback& callback) { 74 const net::CookieStore::GetCookieListCallback& callback) {
77 DCHECK_CURRENTLY_ON(BrowserThread::UI); 75 DCHECK_CURRENTLY_ON(BrowserThread::UI);
78 BrowserThread::PostTask( 76 BrowserThread::PostTask(
79 BrowserThread::IO, 77 BrowserThread::IO,
80 FROM_HERE, 78 FROM_HERE,
81 base::Bind(&GetCookiesForURLOnIO, 79 base::Bind(&GetCookiesForURLOnIO,
82 base::Unretained(resource_context), 80 base::Unretained(resource_context),
83 base::Unretained(context_getter), 81 base::Unretained(context_getter),
84 url, 82 url,
85 callback)); 83 callback));
86 } 84 }
87 85
88 void DeletedCookieOnIO(const base::Closure& callback) { 86 void DeletedCookieOnIO(std::unique_ptr<DeleteCookieCallback> callback) {
89 DCHECK_CURRENTLY_ON(BrowserThread::IO); 87 DCHECK_CURRENTLY_ON(BrowserThread::IO);
90 BrowserThread::PostTask( 88 BrowserThread::PostTask(
91 BrowserThread::UI, 89 BrowserThread::UI,
92 FROM_HERE, 90 FROM_HERE,
93 callback); 91 base::Bind(&DeleteCookieCallback::sendSuccess,
92 base::Passed(std::move(callback))));
94 } 93 }
95 94
96 void DeleteCookieOnIO( 95 void DeleteCookieOnIO(
97 ResourceContext* resource_context, 96 ResourceContext* resource_context,
98 net::URLRequestContextGetter* context_getter, 97 net::URLRequestContextGetter* context_getter,
99 const GURL& url, 98 const GURL& url,
100 const std::string& cookie_name, 99 const std::string& cookie_name,
101 const base::Closure& callback) { 100 std::unique_ptr<DeleteCookieCallback> callback) {
102 DCHECK_CURRENTLY_ON(BrowserThread::IO); 101 DCHECK_CURRENTLY_ON(BrowserThread::IO);
103 net::URLRequestContext* request_context = 102 net::URLRequestContext* request_context =
104 GetRequestContextOnIO(resource_context, context_getter, url); 103 GetRequestContextOnIO(resource_context, context_getter, url);
105 request_context->cookie_store()->DeleteCookieAsync( 104 request_context->cookie_store()->DeleteCookieAsync(
106 url, cookie_name, base::Bind(&DeletedCookieOnIO, callback)); 105 url, cookie_name, base::Bind(&DeletedCookieOnIO,
106 base::Passed(std::move(callback))));
107 } 107 }
108 108
109 void DeleteCookieOnUI( 109 void CookieSetOnIO(std::unique_ptr<SetCookieCallback> callback, bool success) {
110 ResourceContext* resource_context,
111 net::URLRequestContextGetter* context_getter,
112 const GURL& url,
113 const std::string& cookie_name,
114 const base::Closure& callback) {
115 DCHECK_CURRENTLY_ON(BrowserThread::UI);
116 BrowserThread::PostTask(
117 BrowserThread::IO,
118 FROM_HERE,
119 base::Bind(&DeleteCookieOnIO,
120 base::Unretained(resource_context),
121 base::Unretained(context_getter),
122 url,
123 cookie_name,
124 callback));
125 }
126
127 void CookieSetOnIO(const SetCookieCallback& callback, bool success) {
128 DCHECK_CURRENTLY_ON(BrowserThread::IO); 110 DCHECK_CURRENTLY_ON(BrowserThread::IO);
129 BrowserThread::PostTask( 111 BrowserThread::PostTask(
130 BrowserThread::UI, 112 BrowserThread::UI,
131 FROM_HERE, 113 FROM_HERE,
132 base::Bind(callback, success)); 114 base::Bind(&SetCookieCallback::sendSuccess,
115 base::Passed(std::move(callback)),
116 success));
133 } 117 }
134 118
135 void SetCookieOnIO( 119 void SetCookieOnIO(
136 ResourceContext* resource_context, 120 ResourceContext* resource_context,
137 net::URLRequestContextGetter* context_getter, 121 net::URLRequestContextGetter* context_getter,
138 const GURL& url, 122 const GURL& url,
139 const std::string& name, 123 const std::string& name,
140 const std::string& value, 124 const std::string& value,
141 const std::string& domain, 125 const std::string& domain,
142 const std::string& path, 126 const std::string& path,
143 bool secure, 127 bool secure,
144 bool http_only, 128 bool http_only,
145 net::CookieSameSite same_site, 129 net::CookieSameSite same_site,
146 base::Time expires, 130 base::Time expires,
147 const SetCookieCallback& callback) { 131 std::unique_ptr<SetCookieCallback> callback) {
148 DCHECK_CURRENTLY_ON(BrowserThread::IO); 132 DCHECK_CURRENTLY_ON(BrowserThread::IO);
149 net::URLRequestContext* request_context = 133 net::URLRequestContext* request_context =
150 GetRequestContextOnIO(resource_context, context_getter, url); 134 GetRequestContextOnIO(resource_context, context_getter, url);
151 135
152 bool are_experimental_cookie_features_enabled = 136 bool are_experimental_cookie_features_enabled =
153 request_context->network_delegate() 137 request_context->network_delegate()
154 ->AreExperimentalCookieFeaturesEnabled(); 138 ->AreExperimentalCookieFeaturesEnabled();
155 139
156 request_context->cookie_store()->SetCookieWithDetailsAsync( 140 request_context->cookie_store()->SetCookieWithDetailsAsync(
157 url, name, value, domain, path, 141 url, name, value, domain, path,
158 base::Time(), 142 base::Time(),
159 expires, 143 expires,
160 base::Time(), 144 base::Time(),
161 secure, 145 secure,
162 http_only, 146 http_only,
163 same_site, 147 same_site,
164 are_experimental_cookie_features_enabled, 148 are_experimental_cookie_features_enabled,
165 net::COOKIE_PRIORITY_DEFAULT, 149 net::COOKIE_PRIORITY_DEFAULT,
166 base::Bind(&CookieSetOnIO, callback)); 150 base::Bind(&CookieSetOnIO, base::Passed(std::move(callback))));
167 }
168
169 void SetCookieOnUI(
170 ResourceContext* resource_context,
171 net::URLRequestContextGetter* context_getter,
172 const GURL& url,
173 const std::string& name,
174 const std::string& value,
175 const std::string& domain,
176 const std::string& path,
177 bool secure,
178 bool http_only,
179 net::CookieSameSite same_site,
180 base::Time expires,
181 const SetCookieCallback& callback) {
182 DCHECK_CURRENTLY_ON(BrowserThread::UI);
183 BrowserThread::PostTask(
184 BrowserThread::IO,
185 FROM_HERE,
186 base::Bind(&SetCookieOnIO,
187 base::Unretained(resource_context),
188 base::Unretained(context_getter),
189 url, name, value, domain, path, secure, http_only,
190 same_site, expires, callback));
191 } 151 }
192 152
193 class GetCookiesCommand { 153 class GetCookiesCommand {
194 public: 154 public:
195 explicit GetCookiesCommand( 155 GetCookiesCommand(
196 RenderFrameHostImpl* frame_host, 156 RenderFrameHostImpl* frame_host,
197 const CookieListCallback& callback) 157 std::unique_ptr<GetCookiesCallback> callback)
198 : callback_(callback), 158 : callback_(std::move(callback)),
199 request_count_(0) { 159 request_count_(0) {
200 CookieListCallback got_cookies_callback = base::Bind( 160 net::CookieStore::GetCookieListCallback got_cookies_callback = base::Bind(
201 &GetCookiesCommand::GotCookiesForURL, base::Unretained(this)); 161 &GetCookiesCommand::GotCookiesForURL, base::Unretained(this));
202 162
203 std::queue<FrameTreeNode*> queue; 163 std::queue<FrameTreeNode*> queue;
204 queue.push(frame_host->frame_tree_node()); 164 queue.push(frame_host->frame_tree_node());
205 while (!queue.empty()) { 165 while (!queue.empty()) {
206 FrameTreeNode* node = queue.front(); 166 FrameTreeNode* node = queue.front();
207 queue.pop(); 167 queue.pop();
208 168
209 // Only traverse nodes with the same local root. 169 // Only traverse nodes with the same local root.
210 if (node->current_frame_host()->IsCrossProcessSubframe()) 170 if (node->current_frame_host()->IsCrossProcessSubframe())
(...skipping 19 matching lines...) Expand all
230 std::string key = base::StringPrintf( 190 std::string key = base::StringPrintf(
231 "%s::%s::%s::%d", 191 "%s::%s::%s::%d",
232 cookie.Name().c_str(), 192 cookie.Name().c_str(),
233 cookie.Domain().c_str(), 193 cookie.Domain().c_str(),
234 cookie.Path().c_str(), 194 cookie.Path().c_str(),
235 cookie.IsSecure()); 195 cookie.IsSecure());
236 cookies_[key] = cookie; 196 cookies_[key] = cookie;
237 } 197 }
238 --request_count_; 198 --request_count_;
239 if (!request_count_) { 199 if (!request_count_) {
240 net::CookieList list; 200 SendResponse();
241 list.reserve(cookies_.size());
242 for (const auto& pair : cookies_)
243 list.push_back(pair.second);
244 callback_.Run(list);
245 delete this; 201 delete this;
246 } 202 }
247 } 203 }
248 204
249 CookieListCallback callback_; 205 void SendResponse() {
206 std::unique_ptr<protocol::Array<Network::Cookie>> cookies =
207 protocol::Array<Network::Cookie>::create();
208 for (const auto& pair : cookies_) {
209 const net::CanonicalCookie& cookie = pair.second;
210 std::unique_ptr<Network::Cookie> devtools_cookie =
211 Network::Cookie::Create()
212 .SetName(cookie.Name())
213 .SetValue(cookie.Value())
214 .SetDomain(cookie.Domain())
215 .SetPath(cookie.Path())
216 .SetExpires(cookie.ExpiryDate().ToDoubleT() * 1000)
217 .SetSize(cookie.Name().length() + cookie.Value().length())
218 .SetHttpOnly(cookie.IsHttpOnly())
219 .SetSecure(cookie.IsSecure())
220 .SetSession(!cookie.IsPersistent())
221 .Build();
222
223 switch (cookie.SameSite()) {
224 case net::CookieSameSite::STRICT_MODE:
225 devtools_cookie->SetSameSite(Network::CookieSameSiteEnum::Strict);
226 break;
227 case net::CookieSameSite::LAX_MODE:
228 devtools_cookie->SetSameSite(Network::CookieSameSiteEnum::Lax);
229 break;
230 case net::CookieSameSite::NO_RESTRICTION:
231 break;
232 }
233 cookies->addItem(std::move(devtools_cookie));
234 }
235 callback_->sendSuccess(std::move(cookies));
236 }
237
238 std::unique_ptr<GetCookiesCallback> callback_;
250 int request_count_; 239 int request_count_;
251 base::hash_map<std::string, net::CanonicalCookie> cookies_; 240 base::hash_map<std::string, net::CanonicalCookie> cookies_;
252 }; 241 };
253 242
254 } // namespace 243 } // namespace
255 244
256 typedef DevToolsProtocolClient::Response Response;
257
258 NetworkHandler::NetworkHandler() 245 NetworkHandler::NetworkHandler()
259 : host_(nullptr), enabled_(false), weak_factory_(this) { 246 : host_(nullptr), enabled_(false) {
260 } 247 }
261 248
262 NetworkHandler::~NetworkHandler() { 249 NetworkHandler::~NetworkHandler() {
263 } 250 }
264 251
252 void NetworkHandler::Wire(UberDispatcher* dispatcher) {
253 Network::Dispatcher::wire(dispatcher, this);
254 }
255
265 void NetworkHandler::SetRenderFrameHost(RenderFrameHostImpl* host) { 256 void NetworkHandler::SetRenderFrameHost(RenderFrameHostImpl* host) {
266 host_ = host; 257 host_ = host;
267 } 258 }
268 259
269 void NetworkHandler::SetClient(std::unique_ptr<Client> client) { 260 Response NetworkHandler::Enable(Maybe<int> max_total_size,
270 client_.swap(client); 261 Maybe<int> max_resource_size) {
271 }
272
273 Response NetworkHandler::Enable(const int* max_total_size,
274 const int* max_resource_size) {
275 enabled_ = true; 262 enabled_ = true;
276 return Response::FallThrough(); 263 return Response::FallThrough();
277 } 264 }
278 265
279 Response NetworkHandler::Disable() { 266 Response NetworkHandler::Disable() {
280 enabled_ = false; 267 enabled_ = false;
281 return Response::FallThrough(); 268 return Response::FallThrough();
282 } 269 }
283 270
284 Response NetworkHandler::ClearBrowserCache() { 271 Response NetworkHandler::ClearBrowserCache() {
285 if (host_) 272 if (host_)
286 GetContentClient()->browser()->ClearCache(host_); 273 GetContentClient()->browser()->ClearCache(host_);
287 return Response::OK(); 274 return Response::OK();
288 } 275 }
289 276
290 Response NetworkHandler::ClearBrowserCookies() { 277 Response NetworkHandler::ClearBrowserCookies() {
291 if (host_) 278 if (host_)
292 GetContentClient()->browser()->ClearCookies(host_); 279 GetContentClient()->browser()->ClearCookies(host_);
293 return Response::OK(); 280 return Response::OK();
294 } 281 }
295 282
296 Response NetworkHandler::GetCookies(DevToolsCommandId command_id) { 283 void NetworkHandler::GetCookies(std::unique_ptr<GetCookiesCallback> callback) {
297 if (!host_) 284 if (!host_)
298 return Response::InternalError("Could not connect to view"); 285 callback->sendFailure(Response::InternalError());
299 new GetCookiesCommand( 286 else
300 host_, 287 new GetCookiesCommand(host_, std::move(callback));
301 base::Bind(&NetworkHandler::SendGetCookiesResponse,
302 weak_factory_.GetWeakPtr(),
303 command_id));
304 return Response::OK();
305 } 288 }
306 289
307 Response NetworkHandler::SetCookie(DevToolsCommandId command_id, 290 void NetworkHandler::SetCookie(
308 const std::string& url, 291 const std::string& url,
309 const std::string& name, 292 const std::string& name,
310 const std::string& value, 293 const std::string& value,
311 const std::string* domain, 294 Maybe<std::string> domain,
312 const std::string* path, 295 Maybe<std::string> path,
313 bool* secure, 296 Maybe<bool> secure,
314 bool* http_only, 297 Maybe<bool> http_only,
315 const std::string* same_site, 298 Maybe<std::string> same_site,
316 double* expires) { 299 Maybe<double> expires,
317 if (!host_) 300 std::unique_ptr<SetCookieCallback> callback) {
318 return Response::InternalError("Could not connect to view"); 301 if (!host_) {
302 callback->sendFailure(Response::InternalError());
303 return;
304 }
319 305
320 net::CookieSameSite same_site_enum = net::CookieSameSite::DEFAULT_MODE; 306 net::CookieSameSite same_site_enum = net::CookieSameSite::DEFAULT_MODE;
321 if (same_site && *same_site == kCookieSameSiteLax) 307 if (same_site.isJust()) {
322 same_site_enum = net::CookieSameSite::LAX_MODE; 308 if (same_site.fromJust() == Network::CookieSameSiteEnum::Lax)
323 else if (same_site && *same_site == kCookieSameSiteStrict) 309 same_site_enum = net::CookieSameSite::LAX_MODE;
324 same_site_enum = net::CookieSameSite::STRICT_MODE; 310 else if (same_site.fromJust() == Network::CookieSameSiteEnum::Strict)
311 same_site_enum = net::CookieSameSite::STRICT_MODE;
312 }
325 313
326 base::Time expiration_date; 314 base::Time expiration_date;
327 if (expires) 315 if (expires.isJust()) {
328 expiration_date = (*expires == 0) 316 expiration_date = expires.fromJust() == 0
329 ? base::Time::UnixEpoch() 317 ? base::Time::UnixEpoch()
330 : base::Time::FromDoubleT(*expires); 318 : base::Time::FromDoubleT(expires.fromJust());
319 }
331 320
332 SetCookieOnUI( 321 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(
333 host_->GetSiteInstance()->GetBrowserContext()->GetResourceContext(), 322 &SetCookieOnIO,
334 host_->GetProcess()->GetStoragePartition()->GetURLRequestContext(), 323 base::Unretained(host_->GetSiteInstance()->GetBrowserContext()->
335 GURL(url), name, value, 324 GetResourceContext()),
336 domain ? *domain : std::string(), path ? *path : std::string(), 325 base::Unretained(host_->GetProcess()->GetStoragePartition()->
337 secure ? *secure : false, http_only ? *http_only : false, 326 GetURLRequestContext()),
338 same_site_enum, expiration_date, 327 GURL(url), name, value, domain.fromMaybe(""), path.fromMaybe(""),
339 base::Bind(&NetworkHandler::SendSetCookieResponse, 328 secure.fromMaybe(false), http_only.fromMaybe(false), same_site_enum,
340 weak_factory_.GetWeakPtr(), 329 expiration_date, base::Passed(std::move(callback))));
341 command_id));
342 return Response::OK();
343 } 330 }
344 331
345 void NetworkHandler::SendSetCookieResponse(DevToolsCommandId command_id, 332 void NetworkHandler::DeleteCookie(
346 bool success) { 333 const std::string& cookie_name,
347 client_->SendSetCookieResponse(command_id, 334 const std::string& url,
348 SetCookieResponse::Create()->set_success(success)); 335 std::unique_ptr<DeleteCookieCallback> callback) {
349 } 336 if (!host_) {
350 337 callback->sendFailure(Response::InternalError());
351 void NetworkHandler::SendGetCookiesResponse( 338 return;
352 DevToolsCommandId command_id,
353 const net::CookieList& cookie_list) {
354 std::vector<scoped_refptr<Cookie>> cookies;
355 for (size_t i = 0; i < cookie_list.size(); ++i) {
356 const net::CanonicalCookie& cookie = cookie_list[i];
357 scoped_refptr<Cookie> devtools_cookie = Cookie::Create()
358 ->set_name(cookie.Name())
359 ->set_value(cookie.Value())
360 ->set_domain(cookie.Domain())
361 ->set_path(cookie.Path())
362 ->set_expires(cookie.ExpiryDate().ToDoubleT() * 1000)
363 ->set_size(cookie.Name().length() + cookie.Value().length())
364 ->set_http_only(cookie.IsHttpOnly())
365 ->set_secure(cookie.IsSecure())
366 ->set_session(!cookie.IsPersistent());
367
368 switch (cookie.SameSite()) {
369 case net::CookieSameSite::STRICT_MODE:
370 devtools_cookie->set_same_site(kCookieSameSiteStrict);
371 break;
372 case net::CookieSameSite::LAX_MODE:
373 devtools_cookie->set_same_site(kCookieSameSiteLax);
374 break;
375 case net::CookieSameSite::NO_RESTRICTION:
376 break;
377 }
378 cookies.push_back(devtools_cookie);
379 } 339 }
380 client_->SendGetCookiesResponse(command_id, 340 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(
381 GetCookiesResponse::Create()->set_cookies(cookies)); 341 &DeleteCookieOnIO,
382 } 342 base::Unretained(host_->GetSiteInstance()->GetBrowserContext()->
383 343 GetResourceContext()),
384 Response NetworkHandler::DeleteCookie( 344 base::Unretained(host_->GetProcess()->GetStoragePartition()->
385 DevToolsCommandId command_id, 345 GetURLRequestContext()),
386 const std::string& cookie_name,
387 const std::string& url) {
388 if (!host_)
389 return Response::InternalError("Could not connect to view");
390 DeleteCookieOnUI(
391 host_->GetSiteInstance()->GetBrowserContext()->GetResourceContext(),
392 host_->GetProcess()->GetStoragePartition()->GetURLRequestContext(),
393 GURL(url), 346 GURL(url),
394 cookie_name, 347 cookie_name,
395 base::Bind(&NetworkHandler::SendDeleteCookieResponse, 348 base::Passed(std::move(callback))));
396 weak_factory_.GetWeakPtr(),
397 command_id));
398 return Response::OK();
399 } 349 }
400 350
401 void NetworkHandler::SendDeleteCookieResponse(DevToolsCommandId command_id) {
402 client_->SendDeleteCookieResponse(command_id,
403 DeleteCookieResponse::Create());
404 }
405
406
407 Response NetworkHandler::CanEmulateNetworkConditions(bool* result) { 351 Response NetworkHandler::CanEmulateNetworkConditions(bool* result) {
408 *result = false; 352 *result = false;
409 return Response::OK(); 353 return Response::OK();
410 } 354 }
411 355
412 Response NetworkHandler::EmulateNetworkConditions( 356 } // namespace protocol
413 bool offline,
414 double latency,
415 double download_throughput,
416 double upload_throughput,
417 const std::string* connection_type) {
418 return Response::FallThrough();
419 }
420
421 } // namespace network
422 } // namespace devtools
423 } // namespace content 357 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698