| OLD | NEW |
| 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 "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/browser/frame_host/frame_tree_node.h" | 10 #include "content/browser/frame_host/frame_tree_node.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 210 |
| 211 Response NetworkHandler::ClearBrowserCookies() { | 211 Response NetworkHandler::ClearBrowserCookies() { |
| 212 if (host_) | 212 if (host_) |
| 213 GetContentClient()->browser()->ClearCookies(host_); | 213 GetContentClient()->browser()->ClearCookies(host_); |
| 214 return Response::OK(); | 214 return Response::OK(); |
| 215 } | 215 } |
| 216 | 216 |
| 217 Response NetworkHandler::GetCookies(DevToolsCommandId command_id) { | 217 Response NetworkHandler::GetCookies(DevToolsCommandId command_id) { |
| 218 if (!host_) | 218 if (!host_) |
| 219 return Response::InternalError("Could not connect to view"); | 219 return Response::InternalError("Could not connect to view"); |
| 220 new GetCookiesCommand( | 220 new GetCookiesCommand(host_, |
| 221 host_, | 221 base::Bind(&NetworkHandler::SendGetCookiesResponse, |
| 222 base::Bind(&NetworkHandler::SendGetCookiesResponse, | 222 weak_factory_.GetWeakPtr(), command_id)); |
| 223 weak_factory_.GetWeakPtr(), | |
| 224 command_id)); | |
| 225 return Response::OK(); | 223 return Response::OK(); |
| 226 } | 224 } |
| 227 | 225 |
| 228 void NetworkHandler::SendGetCookiesResponse( | 226 void NetworkHandler::SendGetCookiesResponse( |
| 229 DevToolsCommandId command_id, | 227 DevToolsCommandId command_id, |
| 230 const net::CookieList& cookie_list) { | 228 const net::CookieList& cookie_list) { |
| 231 std::vector<scoped_refptr<Cookie>> cookies; | 229 std::vector<scoped_refptr<Cookie>> cookies; |
| 232 for (size_t i = 0; i < cookie_list.size(); ++i) { | 230 for (size_t i = 0; i < cookie_list.size(); ++i) { |
| 233 const net::CanonicalCookie& cookie = cookie_list[i]; | 231 const net::CanonicalCookie& cookie = cookie_list[i]; |
| 234 cookies.push_back(Cookie::Create() | 232 cookies.push_back(Cookie::Create() |
| 235 ->set_name(cookie.Name()) | 233 ->set_name(cookie.Name()) |
| 236 ->set_value(cookie.Value()) | 234 ->set_value(cookie.Value()) |
| 237 ->set_domain(cookie.Domain()) | 235 ->set_domain(cookie.Domain()) |
| 238 ->set_path(cookie.Path()) | 236 ->set_path(cookie.Path()) |
| 239 ->set_expires(cookie.ExpiryDate().ToDoubleT() * 1000) | 237 ->set_expires(cookie.ExpiryDate().ToDoubleT() * 1000) |
| 240 ->set_size(cookie.Name().length() + cookie.Value().length()) | 238 ->set_size(cookie.Name().length() + cookie.Value().length()) |
| 241 ->set_http_only(cookie.IsHttpOnly()) | 239 ->set_http_only(cookie.IsHttpOnly()) |
| 242 ->set_secure(cookie.IsSecure()) | 240 ->set_secure(cookie.IsSecure()) |
| 243 ->set_session(!cookie.IsPersistent())); | 241 ->set_session(!cookie.IsPersistent())); |
| 244 } | 242 } |
| 245 client_->SendGetCookiesResponse(command_id, | 243 client_->SendGetCookiesResponse( |
| 246 GetCookiesResponse::Create()->set_cookies(cookies)); | 244 command_id, GetCookiesResponse::Create()->set_cookies(cookies)); |
| 247 } | 245 } |
| 248 | 246 |
| 249 Response NetworkHandler::DeleteCookie( | 247 Response NetworkHandler::DeleteCookie(DevToolsCommandId command_id, |
| 250 DevToolsCommandId command_id, | 248 const std::string& cookie_name, |
| 251 const std::string& cookie_name, | 249 const std::string& url) { |
| 252 const std::string& url) { | |
| 253 if (!host_) | 250 if (!host_) |
| 254 return Response::InternalError("Could not connect to view"); | 251 return Response::InternalError("Could not connect to view"); |
| 255 BrowserContext* browser_context = | 252 BrowserContext* browser_context = |
| 256 host_->GetSiteInstance()->GetBrowserContext(); | 253 host_->GetSiteInstance()->GetBrowserContext(); |
| 257 int process_id = host_->GetProcess()->GetID(); | 254 int process_id = host_->GetProcess()->GetID(); |
| 258 DeleteCookieOnUI( | 255 DeleteCookieOnUI( |
| 259 browser_context->GetResourceContext(), | 256 browser_context->GetResourceContext(), |
| 260 browser_context->GetRequestContextForRenderProcess(process_id), | 257 browser_context->GetRequestContextForRenderProcess(process_id), GURL(url), |
| 261 GURL(url), | 258 cookie_name, base::Bind(&NetworkHandler::SendDeleteCookieResponse, |
| 262 cookie_name, | 259 weak_factory_.GetWeakPtr(), command_id)); |
| 263 base::Bind(&NetworkHandler::SendDeleteCookieResponse, | |
| 264 weak_factory_.GetWeakPtr(), | |
| 265 command_id)); | |
| 266 return Response::OK(); | 260 return Response::OK(); |
| 267 } | 261 } |
| 268 | 262 |
| 269 void NetworkHandler::SendDeleteCookieResponse(DevToolsCommandId command_id) { | 263 void NetworkHandler::SendDeleteCookieResponse(DevToolsCommandId command_id) { |
| 270 client_->SendDeleteCookieResponse(command_id, | 264 client_->SendDeleteCookieResponse(command_id, DeleteCookieResponse::Create()); |
| 271 DeleteCookieResponse::Create()); | |
| 272 } | 265 } |
| 273 | 266 |
| 274 | 267 |
| 275 Response NetworkHandler::CanEmulateNetworkConditions(bool* result) { | 268 Response NetworkHandler::CanEmulateNetworkConditions(bool* result) { |
| 276 *result = false; | 269 *result = false; |
| 277 return Response::OK(); | 270 return Response::OK(); |
| 278 } | 271 } |
| 279 | 272 |
| 280 Response NetworkHandler::EmulateNetworkConditions(bool offline, | 273 Response NetworkHandler::EmulateNetworkConditions(bool offline, |
| 281 double latency, | 274 double latency, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 return Response::InternalError("Could not connect to view"); | 311 return Response::InternalError("Could not connect to view"); |
| 319 WebContents* web_contents = WebContents::FromRenderFrameHost(host_); | 312 WebContents* web_contents = WebContents::FromRenderFrameHost(host_); |
| 320 web_contents->GetDelegate()->ShowCertificateViewerInDevTools( | 313 web_contents->GetDelegate()->ShowCertificateViewerInDevTools( |
| 321 web_contents, certificate_id); | 314 web_contents, certificate_id); |
| 322 return Response::OK(); | 315 return Response::OK(); |
| 323 } | 316 } |
| 324 | 317 |
| 325 } // namespace dom | 318 } // namespace dom |
| 326 } // namespace devtools | 319 } // namespace devtools |
| 327 } // namespace content | 320 } // namespace content |
| OLD | NEW |