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