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 "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 CHECK(BrowserThread::PostTask( | 273 CHECK(BrowserThread::PostTask( |
274 BrowserThread::IO, FROM_HERE, | 274 BrowserThread::IO, FROM_HERE, |
275 base::Bind(&DeleteCookieOnIOThread, url, cookie_name, context_getter, | 275 base::Bind(&DeleteCookieOnIOThread, url, cookie_name, context_getter, |
276 &event))); | 276 &event))); |
277 event.Wait(); | 277 event.Wait(); |
278 *success = true; | 278 *success = true; |
279 } | 279 } |
280 } | 280 } |
281 | 281 |
282 void GetCookiesJSON(AutomationProvider* provider, | 282 void GetCookiesJSON(AutomationProvider* provider, |
283 DictionaryValue* args, | 283 base::DictionaryValue* args, |
284 IPC::Message* reply_message) { | 284 IPC::Message* reply_message) { |
285 AutomationJSONReply reply(provider, reply_message); | 285 AutomationJSONReply reply(provider, reply_message); |
286 std::string url; | 286 std::string url; |
287 if (!args->GetString("url", &url)) { | 287 if (!args->GetString("url", &url)) { |
288 reply.SendError("'url' missing or invalid"); | 288 reply.SendError("'url' missing or invalid"); |
289 return; | 289 return; |
290 } | 290 } |
291 | 291 |
292 // Since we may be on the UI thread don't call GetURLRequestContext(). | 292 // Since we may be on the UI thread don't call GetURLRequestContext(). |
293 scoped_refptr<net::URLRequestContextGetter> context_getter = | 293 scoped_refptr<net::URLRequestContextGetter> context_getter = |
294 provider->profile()->GetRequestContext(); | 294 provider->profile()->GetRequestContext(); |
295 | 295 |
296 net::CookieList cookie_list; | 296 net::CookieList cookie_list; |
297 base::WaitableEvent event(true /* manual reset */, | 297 base::WaitableEvent event(true /* manual reset */, |
298 false /* not initially signaled */); | 298 false /* not initially signaled */); |
299 base::Closure task = base::Bind(&GetCanonicalCookiesOnIOThread, GURL(url), | 299 base::Closure task = base::Bind(&GetCanonicalCookiesOnIOThread, GURL(url), |
300 context_getter, &event, &cookie_list); | 300 context_getter, &event, &cookie_list); |
301 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { | 301 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { |
302 reply.SendError("Couldn't post task to get the cookies"); | 302 reply.SendError("Couldn't post task to get the cookies"); |
303 return; | 303 return; |
304 } | 304 } |
305 event.Wait(); | 305 event.Wait(); |
306 | 306 |
307 ListValue* list = new ListValue(); | 307 base::ListValue* list = new base::ListValue(); |
308 for (size_t i = 0; i < cookie_list.size(); ++i) { | 308 for (size_t i = 0; i < cookie_list.size(); ++i) { |
309 const net::CanonicalCookie& cookie = cookie_list[i]; | 309 const net::CanonicalCookie& cookie = cookie_list[i]; |
310 DictionaryValue* cookie_dict = new DictionaryValue(); | 310 base::DictionaryValue* cookie_dict = new base::DictionaryValue(); |
311 cookie_dict->SetString("name", cookie.Name()); | 311 cookie_dict->SetString("name", cookie.Name()); |
312 cookie_dict->SetString("value", cookie.Value()); | 312 cookie_dict->SetString("value", cookie.Value()); |
313 cookie_dict->SetString("path", cookie.Path()); | 313 cookie_dict->SetString("path", cookie.Path()); |
314 cookie_dict->SetString("domain", cookie.Domain()); | 314 cookie_dict->SetString("domain", cookie.Domain()); |
315 cookie_dict->SetBoolean("secure", cookie.IsSecure()); | 315 cookie_dict->SetBoolean("secure", cookie.IsSecure()); |
316 cookie_dict->SetBoolean("http_only", cookie.IsHttpOnly()); | 316 cookie_dict->SetBoolean("http_only", cookie.IsHttpOnly()); |
317 if (cookie.IsPersistent()) | 317 if (cookie.IsPersistent()) |
318 cookie_dict->SetDouble("expiry", cookie.ExpiryDate().ToDoubleT()); | 318 cookie_dict->SetDouble("expiry", cookie.ExpiryDate().ToDoubleT()); |
319 if (cookie.Priority() != net::COOKIE_PRIORITY_DEFAULT) { | 319 if (cookie.Priority() != net::COOKIE_PRIORITY_DEFAULT) { |
320 cookie_dict->SetString("priority", | 320 cookie_dict->SetString("priority", |
321 net::CookiePriorityToString(cookie.Priority())); | 321 net::CookiePriorityToString(cookie.Priority())); |
322 } | 322 } |
323 list->Append(cookie_dict); | 323 list->Append(cookie_dict); |
324 } | 324 } |
325 DictionaryValue dict; | 325 base::DictionaryValue dict; |
326 dict.Set("cookies", list); | 326 dict.Set("cookies", list); |
327 reply.SendSuccess(&dict); | 327 reply.SendSuccess(&dict); |
328 } | 328 } |
329 | 329 |
330 void DeleteCookieJSON(AutomationProvider* provider, | 330 void DeleteCookieJSON(AutomationProvider* provider, |
331 DictionaryValue* args, | 331 base::DictionaryValue* args, |
332 IPC::Message* reply_message) { | 332 IPC::Message* reply_message) { |
333 AutomationJSONReply reply(provider, reply_message); | 333 AutomationJSONReply reply(provider, reply_message); |
334 std::string url, name; | 334 std::string url, name; |
335 if (!args->GetString("url", &url)) { | 335 if (!args->GetString("url", &url)) { |
336 reply.SendError("'url' missing or invalid"); | 336 reply.SendError("'url' missing or invalid"); |
337 return; | 337 return; |
338 } | 338 } |
339 if (!args->GetString("name", &name)) { | 339 if (!args->GetString("name", &name)) { |
340 reply.SendError("'name' missing or invalid"); | 340 reply.SendError("'name' missing or invalid"); |
341 return; | 341 return; |
342 } | 342 } |
343 | 343 |
344 // Since we may be on the UI thread don't call GetURLRequestContext(). | 344 // Since we may be on the UI thread don't call GetURLRequestContext(). |
345 scoped_refptr<net::URLRequestContextGetter> context_getter = | 345 scoped_refptr<net::URLRequestContextGetter> context_getter = |
346 provider->profile()->GetRequestContext(); | 346 provider->profile()->GetRequestContext(); |
347 | 347 |
348 base::WaitableEvent event(true /* manual reset */, | 348 base::WaitableEvent event(true /* manual reset */, |
349 false /* not initially signaled */); | 349 false /* not initially signaled */); |
350 base::Closure task = base::Bind(&DeleteCookieOnIOThread, GURL(url), name, | 350 base::Closure task = base::Bind(&DeleteCookieOnIOThread, GURL(url), name, |
351 context_getter, &event); | 351 context_getter, &event); |
352 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { | 352 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { |
353 reply.SendError("Couldn't post task to delete the cookie"); | 353 reply.SendError("Couldn't post task to delete the cookie"); |
354 return; | 354 return; |
355 } | 355 } |
356 event.Wait(); | 356 event.Wait(); |
357 reply.SendSuccess(NULL); | 357 reply.SendSuccess(NULL); |
358 } | 358 } |
359 | 359 |
360 void SetCookieJSON(AutomationProvider* provider, | 360 void SetCookieJSON(AutomationProvider* provider, |
361 DictionaryValue* args, | 361 base::DictionaryValue* args, |
362 IPC::Message* reply_message) { | 362 IPC::Message* reply_message) { |
363 AutomationJSONReply reply(provider, reply_message); | 363 AutomationJSONReply reply(provider, reply_message); |
364 std::string url; | 364 std::string url; |
365 if (!args->GetString("url", &url)) { | 365 if (!args->GetString("url", &url)) { |
366 reply.SendError("'url' missing or invalid"); | 366 reply.SendError("'url' missing or invalid"); |
367 return; | 367 return; |
368 } | 368 } |
369 DictionaryValue* cookie_dict; | 369 base::DictionaryValue* cookie_dict; |
370 if (!args->GetDictionary("cookie", &cookie_dict)) { | 370 if (!args->GetDictionary("cookie", &cookie_dict)) { |
371 reply.SendError("'cookie' missing or invalid"); | 371 reply.SendError("'cookie' missing or invalid"); |
372 return; | 372 return; |
373 } | 373 } |
374 std::string name, value; | 374 std::string name, value; |
375 std::string domain; | 375 std::string domain; |
376 std::string path = "/"; | 376 std::string path = "/"; |
377 bool secure = false; | 377 bool secure = false; |
378 double expiry = 0; | 378 double expiry = 0; |
379 bool http_only = false; | 379 bool http_only = false; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 | 456 |
457 bool SendErrorIfModalDialogActive(AutomationProvider* provider, | 457 bool SendErrorIfModalDialogActive(AutomationProvider* provider, |
458 IPC::Message* message) { | 458 IPC::Message* message) { |
459 bool active = AppModalDialogQueue::GetInstance()->HasActiveDialog(); | 459 bool active = AppModalDialogQueue::GetInstance()->HasActiveDialog(); |
460 if (active) | 460 if (active) |
461 AutomationJSONReply(provider, message).SendError("Blocked by modal dialog"); | 461 AutomationJSONReply(provider, message).SendError("Blocked by modal dialog"); |
462 return active; | 462 return active; |
463 } | 463 } |
464 | 464 |
465 } // namespace automation_util | 465 } // namespace automation_util |
OLD | NEW |