OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/automation/automation_util.h" | 5 #include "chrome/browser/automation/automation_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_delegate.h" | 10 #include "ash/shell_delegate.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "chrome/browser/ui/host_desktop.h" | 31 #include "chrome/browser/ui/host_desktop.h" |
32 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
33 #include "chrome/common/automation_id.h" | 33 #include "chrome/common/automation_id.h" |
34 #include "chrome/common/extensions/extension.h" | 34 #include "chrome/common/extensions/extension.h" |
35 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
36 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
37 #include "content/public/browser/render_view_host.h" | 37 #include "content/public/browser/render_view_host.h" |
38 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
39 #include "extensions/browser/view_type_utils.h" | 39 #include "extensions/browser/view_type_utils.h" |
40 #include "net/cookies/canonical_cookie.h" | 40 #include "net/cookies/canonical_cookie.h" |
| 41 #include "net/cookies/cookie_constants.h" |
41 #include "net/cookies/cookie_monster.h" | 42 #include "net/cookies/cookie_monster.h" |
42 #include "net/cookies/cookie_store.h" | 43 #include "net/cookies/cookie_store.h" |
43 #include "net/url_request/url_request_context.h" | 44 #include "net/url_request/url_request_context.h" |
44 #include "net/url_request/url_request_context_getter.h" | 45 #include "net/url_request/url_request_context_getter.h" |
45 | 46 |
46 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
47 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 48 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
48 #include "chrome/browser/chromeos/login/login_display.h" | 49 #include "chrome/browser/chromeos/login/login_display.h" |
49 #include "chrome/browser/chromeos/login/login_display_host.h" | 50 #include "chrome/browser/chromeos/login/login_display_host.h" |
50 #include "chrome/browser/chromeos/login/webui_login_display.h" | 51 #include "chrome/browser/chromeos/login/webui_login_display.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 const std::string& original_domain, | 126 const std::string& original_domain, |
126 const scoped_refptr<net::URLRequestContextGetter>& context_getter, | 127 const scoped_refptr<net::URLRequestContextGetter>& context_getter, |
127 base::WaitableEvent* event, | 128 base::WaitableEvent* event, |
128 bool* success) { | 129 bool* success) { |
129 net::CookieMonster* cookie_monster = | 130 net::CookieMonster* cookie_monster = |
130 context_getter->GetURLRequestContext()->cookie_store()-> | 131 context_getter->GetURLRequestContext()->cookie_store()-> |
131 GetCookieMonster(); | 132 GetCookieMonster(); |
132 cookie_monster->SetCookieWithDetailsAsync( | 133 cookie_monster->SetCookieWithDetailsAsync( |
133 url, cookie.Name(), cookie.Value(), original_domain, | 134 url, cookie.Name(), cookie.Value(), original_domain, |
134 cookie.Path(), cookie.ExpiryDate(), cookie.IsSecure(), | 135 cookie.Path(), cookie.ExpiryDate(), cookie.IsSecure(), |
135 cookie.IsHttpOnly(), | 136 cookie.IsHttpOnly(), cookie.Priority(), |
136 base::Bind(&SetCookieCallback, event, success)); | 137 base::Bind(&SetCookieCallback, event, success)); |
137 } | 138 } |
138 | 139 |
139 void DeleteCookieCallback(base::WaitableEvent* event) { | 140 void DeleteCookieCallback(base::WaitableEvent* event) { |
140 event->Signal(); | 141 event->Signal(); |
141 } | 142 } |
142 | 143 |
143 void DeleteCookieOnIOThread( | 144 void DeleteCookieOnIOThread( |
144 const GURL& url, | 145 const GURL& url, |
145 const std::string& name, | 146 const std::string& name, |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 const net::CanonicalCookie& cookie = cookie_list[i]; | 319 const net::CanonicalCookie& cookie = cookie_list[i]; |
319 DictionaryValue* cookie_dict = new DictionaryValue(); | 320 DictionaryValue* cookie_dict = new DictionaryValue(); |
320 cookie_dict->SetString("name", cookie.Name()); | 321 cookie_dict->SetString("name", cookie.Name()); |
321 cookie_dict->SetString("value", cookie.Value()); | 322 cookie_dict->SetString("value", cookie.Value()); |
322 cookie_dict->SetString("path", cookie.Path()); | 323 cookie_dict->SetString("path", cookie.Path()); |
323 cookie_dict->SetString("domain", cookie.Domain()); | 324 cookie_dict->SetString("domain", cookie.Domain()); |
324 cookie_dict->SetBoolean("secure", cookie.IsSecure()); | 325 cookie_dict->SetBoolean("secure", cookie.IsSecure()); |
325 cookie_dict->SetBoolean("http_only", cookie.IsHttpOnly()); | 326 cookie_dict->SetBoolean("http_only", cookie.IsHttpOnly()); |
326 if (cookie.IsPersistent()) | 327 if (cookie.IsPersistent()) |
327 cookie_dict->SetDouble("expiry", cookie.ExpiryDate().ToDoubleT()); | 328 cookie_dict->SetDouble("expiry", cookie.ExpiryDate().ToDoubleT()); |
| 329 if (cookie.Priority() != net::COOKIE_PRIORITY_DEFAULT) { |
| 330 cookie_dict->SetString("priority", |
| 331 net::CookiePriorityToString(cookie.Priority())); |
| 332 } |
328 list->Append(cookie_dict); | 333 list->Append(cookie_dict); |
329 } | 334 } |
330 DictionaryValue dict; | 335 DictionaryValue dict; |
331 dict.Set("cookies", list); | 336 dict.Set("cookies", list); |
332 reply.SendSuccess(&dict); | 337 reply.SendSuccess(&dict); |
333 } | 338 } |
334 | 339 |
335 void DeleteCookieJSON(AutomationProvider* provider, | 340 void DeleteCookieJSON(AutomationProvider* provider, |
336 DictionaryValue* args, | 341 DictionaryValue* args, |
337 IPC::Message* reply_message) { | 342 IPC::Message* reply_message) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 if (!args->GetDictionary("cookie", &cookie_dict)) { | 380 if (!args->GetDictionary("cookie", &cookie_dict)) { |
376 reply.SendError("'cookie' missing or invalid"); | 381 reply.SendError("'cookie' missing or invalid"); |
377 return; | 382 return; |
378 } | 383 } |
379 std::string name, value; | 384 std::string name, value; |
380 std::string domain; | 385 std::string domain; |
381 std::string path = "/"; | 386 std::string path = "/"; |
382 bool secure = false; | 387 bool secure = false; |
383 double expiry = 0; | 388 double expiry = 0; |
384 bool http_only = false; | 389 bool http_only = false; |
| 390 net::CookiePriority priority = net::COOKIE_PRIORITY_DEFAULT; |
| 391 |
385 if (!cookie_dict->GetString("name", &name)) { | 392 if (!cookie_dict->GetString("name", &name)) { |
386 reply.SendError("'name' missing or invalid"); | 393 reply.SendError("'name' missing or invalid"); |
387 return; | 394 return; |
388 } | 395 } |
389 if (!cookie_dict->GetString("value", &value)) { | 396 if (!cookie_dict->GetString("value", &value)) { |
390 reply.SendError("'value' missing or invalid"); | 397 reply.SendError("'value' missing or invalid"); |
391 return; | 398 return; |
392 } | 399 } |
393 if (cookie_dict->HasKey("domain") && | 400 if (cookie_dict->HasKey("domain") && |
394 !cookie_dict->GetString("domain", &domain)) { | 401 !cookie_dict->GetString("domain", &domain)) { |
(...skipping 14 matching lines...) Expand all Loading... |
409 if (!cookie_dict->GetDouble("expiry", &expiry)) { | 416 if (!cookie_dict->GetDouble("expiry", &expiry)) { |
410 reply.SendError("optional 'expiry' invalid"); | 417 reply.SendError("optional 'expiry' invalid"); |
411 return; | 418 return; |
412 } | 419 } |
413 } | 420 } |
414 if (cookie_dict->HasKey("http_only") && | 421 if (cookie_dict->HasKey("http_only") && |
415 !cookie_dict->GetBoolean("http_only", &http_only)) { | 422 !cookie_dict->GetBoolean("http_only", &http_only)) { |
416 reply.SendError("optional 'http_only' invalid"); | 423 reply.SendError("optional 'http_only' invalid"); |
417 return; | 424 return; |
418 } | 425 } |
| 426 if (cookie_dict->HasKey("priority")) { |
| 427 std::string priority_string; |
| 428 if (!cookie_dict->GetString("priority", &priority_string)) { |
| 429 reply.SendError("optional 'priority' invalid"); |
| 430 return; |
| 431 } |
| 432 priority = net::StringToCookiePriority(priority_string); |
| 433 } |
419 | 434 |
420 scoped_ptr<net::CanonicalCookie> cookie( | 435 scoped_ptr<net::CanonicalCookie> cookie( |
421 net::CanonicalCookie::Create( | 436 net::CanonicalCookie::Create( |
422 GURL(url), name, value, domain, path, base::Time(), | 437 GURL(url), name, value, domain, path, base::Time(), |
423 base::Time::FromDoubleT(expiry), secure, http_only)); | 438 base::Time::FromDoubleT(expiry), secure, http_only, priority)); |
424 if (!cookie.get()) { | 439 if (!cookie.get()) { |
425 reply.SendError("given 'cookie' parameters are invalid"); | 440 reply.SendError("given 'cookie' parameters are invalid"); |
426 return; | 441 return; |
427 } | 442 } |
428 | 443 |
429 // Since we may be on the UI thread don't call GetURLRequestContext(). | 444 // Since we may be on the UI thread don't call GetURLRequestContext(). |
430 scoped_refptr<net::URLRequestContextGetter> context_getter = | 445 scoped_refptr<net::URLRequestContextGetter> context_getter = |
431 provider->profile()->GetRequestContext(); | 446 provider->profile()->GetRequestContext(); |
432 | 447 |
433 base::WaitableEvent event(true /* manual reset */, | 448 base::WaitableEvent event(true /* manual reset */, |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 const extensions::Extension* extension; | 634 const extensions::Extension* extension; |
620 return GetExtensionForId(id, profile, &extension); | 635 return GetExtensionForId(id, profile, &extension); |
621 } | 636 } |
622 default: | 637 default: |
623 break; | 638 break; |
624 } | 639 } |
625 return false; | 640 return false; |
626 } | 641 } |
627 | 642 |
628 } // namespace automation_util | 643 } // namespace automation_util |
OLD | NEW |