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

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 6201005: Initial support for partitioning cookies for isolated apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge conflicts in TestingAutomationProvider. Created 9 years, 9 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/json/json_reader.h" 12 #include "base/json/json_reader.h"
13 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
14 #include "base/json/string_escape.h" 14 #include "base/json/string_escape.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/process.h" 16 #include "base/process.h"
17 #include "base/process_util.h" 17 #include "base/process_util.h"
18 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
19 #include "base/threading/thread_restrictions.h" 19 #include "base/threading/thread_restrictions.h"
20 #include "base/time.h" 20 #include "base/time.h"
21 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
22 #include "chrome/app/chrome_command_ids.h" 22 #include "chrome/app/chrome_command_ids.h"
23 #include "chrome/browser/autocomplete/autocomplete.h" 23 #include "chrome/browser/autocomplete/autocomplete.h"
24 #include "chrome/browser/autocomplete/autocomplete_edit.h" 24 #include "chrome/browser/autocomplete/autocomplete_edit.h"
25 #include "chrome/browser/autocomplete/autocomplete_match.h" 25 #include "chrome/browser/autocomplete/autocomplete_match.h"
26 #include "chrome/browser/autofill/autofill_manager.h" 26 #include "chrome/browser/autofill/autofill_manager.h"
27 #include "chrome/browser/automation/automation_autocomplete_edit_tracker.h" 27 #include "chrome/browser/automation/automation_autocomplete_edit_tracker.h"
28 #include "chrome/browser/automation/automation_browser_tracker.h" 28 #include "chrome/browser/automation/automation_browser_tracker.h"
29 #include "chrome/browser/automation/automation_cookie_util.h"
29 #include "chrome/browser/automation/automation_provider_json.h" 30 #include "chrome/browser/automation/automation_provider_json.h"
30 #include "chrome/browser/automation/automation_provider_list.h" 31 #include "chrome/browser/automation/automation_provider_list.h"
31 #include "chrome/browser/automation/automation_provider_observers.h" 32 #include "chrome/browser/automation/automation_provider_observers.h"
32 #include "chrome/browser/automation/automation_tab_tracker.h" 33 #include "chrome/browser/automation/automation_tab_tracker.h"
33 #include "chrome/browser/automation/automation_window_tracker.h" 34 #include "chrome/browser/automation/automation_window_tracker.h"
34 #include "chrome/browser/automation/ui_controls.h" 35 #include "chrome/browser/automation/ui_controls.h"
35 #include "chrome/browser/blocked_content_container.h" 36 #include "chrome/browser/blocked_content_container.h"
36 #include "chrome/browser/bookmarks/bookmark_model.h" 37 #include "chrome/browser/bookmarks/bookmark_model.h"
37 #include "chrome/browser/bookmarks/bookmark_storage.h" 38 #include "chrome/browser/bookmarks/bookmark_storage.h"
38 #include "chrome/browser/browser_process.h" 39 #include "chrome/browser/browser_process.h"
(...skipping 26 matching lines...) Expand all
65 #include "chrome/browser/ui/find_bar/find_bar.h" 66 #include "chrome/browser/ui/find_bar/find_bar.h"
66 #include "chrome/browser/ui/login/login_prompt.h" 67 #include "chrome/browser/ui/login/login_prompt.h"
67 #include "chrome/browser/ui/omnibox/location_bar.h" 68 #include "chrome/browser/ui/omnibox/location_bar.h"
68 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" 69 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h"
69 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 70 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
70 #include "chrome/browser/ui/webui/shown_sections_handler.h" 71 #include "chrome/browser/ui/webui/shown_sections_handler.h"
71 #include "chrome/common/automation_messages.h" 72 #include "chrome/common/automation_messages.h"
72 #include "chrome/common/chrome_constants.h" 73 #include "chrome/common/chrome_constants.h"
73 #include "chrome/common/chrome_paths.h" 74 #include "chrome/common/chrome_paths.h"
74 #include "chrome/common/chrome_switches.h" 75 #include "chrome/common/chrome_switches.h"
75 #include "chrome/common/net/url_request_context_getter.h"
76 #include "chrome/common/notification_service.h" 76 #include "chrome/common/notification_service.h"
77 #include "chrome/common/pref_names.h" 77 #include "chrome/common/pref_names.h"
78 #include "chrome/common/url_constants.h" 78 #include "chrome/common/url_constants.h"
79 #include "content/browser/renderer_host/render_process_host.h" 79 #include "content/browser/renderer_host/render_process_host.h"
80 #include "content/browser/renderer_host/render_view_host.h" 80 #include "content/browser/renderer_host/render_view_host.h"
81 #include "content/browser/tab_contents/interstitial_page.h" 81 #include "content/browser/tab_contents/interstitial_page.h"
82 #include "content/common/common_param_traits.h" 82 #include "content/common/common_param_traits.h"
83 #include "net/base/cookie_store.h"
84 #include "net/url_request/url_request_context.h"
85 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 83 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
86 #include "ui/base/events.h" 84 #include "ui/base/events.h"
87 #include "ui/base/message_box_flags.h" 85 #include "ui/base/message_box_flags.h"
88 #include "webkit/plugins/npapi/plugin_list.h" 86 #include "webkit/plugins/npapi/plugin_list.h"
89 87
90 namespace { 88 namespace {
91 89
92 void GetCookiesOnIOThread(
93 const GURL& url,
94 const scoped_refptr<URLRequestContextGetter>& context_getter,
95 base::WaitableEvent* event,
96 std::string* cookies) {
97 *cookies = context_getter->GetCookieStore()->GetCookies(url);
98 event->Signal();
99 }
100
101 void SetCookieOnIOThread(
102 const GURL& url,
103 const std::string& value,
104 const scoped_refptr<URLRequestContextGetter>& context_getter,
105 base::WaitableEvent* event,
106 bool* success) {
107 *success = context_getter->GetCookieStore()->SetCookie(url, value);
108 event->Signal();
109 }
110
111 void DeleteCookieOnIOThread(
112 const GURL& url,
113 const std::string& name,
114 const scoped_refptr<URLRequestContextGetter>& context_getter,
115 base::WaitableEvent* event) {
116 context_getter->GetCookieStore()->DeleteCookie(url, name);
117 event->Signal();
118 }
119
120 void SendMouseClick(int flags) { 90 void SendMouseClick(int flags) {
121 ui_controls::MouseButton button = ui_controls::LEFT; 91 ui_controls::MouseButton button = ui_controls::LEFT;
122 if ((flags & ui::EF_LEFT_BUTTON_DOWN) == 92 if ((flags & ui::EF_LEFT_BUTTON_DOWN) ==
123 ui::EF_LEFT_BUTTON_DOWN) { 93 ui::EF_LEFT_BUTTON_DOWN) {
124 button = ui_controls::LEFT; 94 button = ui_controls::LEFT;
125 } else if ((flags & ui::EF_RIGHT_BUTTON_DOWN) == 95 } else if ((flags & ui::EF_RIGHT_BUTTON_DOWN) ==
126 ui::EF_RIGHT_BUTTON_DOWN) { 96 ui::EF_RIGHT_BUTTON_DOWN) {
127 button = ui_controls::RIGHT; 97 button = ui_controls::RIGHT;
128 } else if ((flags & ui::EF_MIDDLE_BUTTON_DOWN) == 98 } else if ((flags & ui::EF_MIDDLE_BUTTON_DOWN) ==
129 ui::EF_MIDDLE_BUTTON_DOWN) { 99 ui::EF_MIDDLE_BUTTON_DOWN) {
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 return; 471 return;
502 } 472 }
503 473
504 AutomationMsg_CloseTab::WriteReplyParams(reply_message, false); 474 AutomationMsg_CloseTab::WriteReplyParams(reply_message, false);
505 Send(reply_message); 475 Send(reply_message);
506 } 476 }
507 477
508 void TestingAutomationProvider::GetCookies(const GURL& url, int handle, 478 void TestingAutomationProvider::GetCookies(const GURL& url, int handle,
509 int* value_size, 479 int* value_size,
510 std::string* value) { 480 std::string* value) {
511 *value_size = -1; 481 TabContents *contents = tab_tracker_->ContainsHandle(handle) ?
512 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { 482 tab_tracker_->GetResource(handle)->tab_contents() : NULL;
513 // Since we are running on the UI thread don't call GetURLRequestContext(). 483 automation_cookie_util::GetCookies(url, contents, value_size, value);
514 scoped_refptr<URLRequestContextGetter> context_getter =
515 tab_tracker_->GetResource(handle)->profile()->GetRequestContext();
516
517 base::WaitableEvent event(true /* manual reset */,
518 false /* not initially signaled */);
519 CHECK(BrowserThread::PostTask(
520 BrowserThread::IO, FROM_HERE,
521 NewRunnableFunction(&GetCookiesOnIOThread,
522 url, context_getter, &event, value)));
523 event.Wait();
524
525 *value_size = static_cast<int>(value->size());
526 }
527 } 484 }
528 485
529 void TestingAutomationProvider::SetCookie(const GURL& url, 486 void TestingAutomationProvider::SetCookie(const GURL& url,
530 const std::string value, 487 const std::string value,
531 int handle, 488 int handle,
532 int* response_value) { 489 int* response_value) {
533 *response_value = -1; 490 TabContents *contents = tab_tracker_->ContainsHandle(handle) ?
534 491 tab_tracker_->GetResource(handle)->tab_contents() : NULL;
535 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { 492 automation_cookie_util::SetCookie(url, value, contents, response_value);
536 // Since we are running on the UI thread don't call GetURLRequestContext().
537 scoped_refptr<URLRequestContextGetter> context_getter =
538 tab_tracker_->GetResource(handle)->profile()->GetRequestContext();
539
540 base::WaitableEvent event(true /* manual reset */,
541 false /* not initially signaled */);
542 bool success = false;
543 CHECK(BrowserThread::PostTask(
544 BrowserThread::IO, FROM_HERE,
545 NewRunnableFunction(&SetCookieOnIOThread,
546 url, value, context_getter, &event,
547 &success)));
548 event.Wait();
549 if (success)
550 *response_value = 1;
551 }
552 } 493 }
553 494
554 void TestingAutomationProvider::DeleteCookie(const GURL& url, 495 void TestingAutomationProvider::DeleteCookie(const GURL& url,
555 const std::string& cookie_name, 496 const std::string& cookie_name,
556 int handle, bool* success) { 497 int handle, bool* success) {
557 *success = false; 498 TabContents *contents = tab_tracker_->ContainsHandle(handle) ?
558 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { 499 tab_tracker_->GetResource(handle)->tab_contents() : NULL;
559 // Since we are running on the UI thread don't call GetURLRequestContext(). 500 automation_cookie_util::DeleteCookie(url, cookie_name, contents, success);
560 scoped_refptr<URLRequestContextGetter> context_getter =
561 tab_tracker_->GetResource(handle)->profile()->GetRequestContext();
562
563 base::WaitableEvent event(true /* manual reset */,
564 false /* not initially signaled */);
565 CHECK(BrowserThread::PostTask(
566 BrowserThread::IO, FROM_HERE,
567 NewRunnableFunction(&DeleteCookieOnIOThread,
568 url, cookie_name, context_getter, &event)));
569 event.Wait();
570 *success = true;
571 }
572 } 501 }
573 502
574 void TestingAutomationProvider::ShowCollectedCookiesDialog( 503 void TestingAutomationProvider::ShowCollectedCookiesDialog(
575 int handle, bool* success) { 504 int handle, bool* success) {
576 *success = false; 505 *success = false;
577 if (tab_tracker_->ContainsHandle(handle)) { 506 if (tab_tracker_->ContainsHandle(handle)) {
578 TabContents* tab_contents = 507 TabContents* tab_contents =
579 tab_tracker_->GetResource(handle)->tab_contents(); 508 tab_tracker_->GetResource(handle)->tab_contents();
580 tab_contents->delegate()->ShowCollectedCookiesDialog(tab_contents); 509 tab_contents->delegate()->ShowCollectedCookiesDialog(tab_contents);
581 *success = true; 510 *success = true;
(...skipping 4449 matching lines...) Expand 10 before | Expand all | Expand 10 after
5031 } 4960 }
5032 4961
5033 // Since we are running on the UI thread don't call GetURLRequestContext(). 4962 // Since we are running on the UI thread don't call GetURLRequestContext().
5034 scoped_refptr<URLRequestContextGetter> context_getter = 4963 scoped_refptr<URLRequestContextGetter> context_getter =
5035 browser->profile()->GetRequestContext(); 4964 browser->profile()->GetRequestContext();
5036 4965
5037 std::string cookies; 4966 std::string cookies;
5038 base::WaitableEvent event(true /* manual reset */, 4967 base::WaitableEvent event(true /* manual reset */,
5039 false /* not initially signaled */); 4968 false /* not initially signaled */);
5040 Task* task = NewRunnableFunction( 4969 Task* task = NewRunnableFunction(
5041 &GetCookiesOnIOThread, 4970 &automation_cookie_util::GetCookiesOnIOThread,
5042 GURL(url), context_getter, &event, &cookies); 4971 GURL(url), context_getter, &event, &cookies);
5043 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { 4972 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) {
5044 reply.SendError("Couldn't post task to get the cookies"); 4973 reply.SendError("Couldn't post task to get the cookies");
5045 return; 4974 return;
5046 } 4975 }
5047 event.Wait(); 4976 event.Wait();
5048 4977
5049 DictionaryValue dict; 4978 DictionaryValue dict;
5050 dict.SetString("cookies", cookies); 4979 dict.SetString("cookies", cookies);
5051 reply.SendSuccess(&dict); 4980 reply.SendSuccess(&dict);
(...skipping 18 matching lines...) Expand all
5070 return; 4999 return;
5071 } 5000 }
5072 5001
5073 // Since we are running on the UI thread don't call GetURLRequestContext(). 5002 // Since we are running on the UI thread don't call GetURLRequestContext().
5074 scoped_refptr<URLRequestContextGetter> context_getter = 5003 scoped_refptr<URLRequestContextGetter> context_getter =
5075 browser->profile()->GetRequestContext(); 5004 browser->profile()->GetRequestContext();
5076 5005
5077 base::WaitableEvent event(true /* manual reset */, 5006 base::WaitableEvent event(true /* manual reset */,
5078 false /* not initially signaled */); 5007 false /* not initially signaled */);
5079 Task* task = NewRunnableFunction( 5008 Task* task = NewRunnableFunction(
5080 &DeleteCookieOnIOThread, 5009 &automation_cookie_util::DeleteCookieOnIOThread,
5081 GURL(url), name, context_getter, &event); 5010 GURL(url), name, context_getter, &event);
5082 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { 5011 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) {
5083 reply.SendError("Couldn't post task to delete the cookie"); 5012 reply.SendError("Couldn't post task to delete the cookie");
5084 return; 5013 return;
5085 } 5014 }
5086 event.Wait(); 5015 event.Wait();
5087 reply.SendSuccess(NULL); 5016 reply.SendSuccess(NULL);
5088 } 5017 }
5089 5018
5090 void TestingAutomationProvider::SetCookieJSON( 5019 void TestingAutomationProvider::SetCookieJSON(
(...skipping 16 matching lines...) Expand all
5107 } 5036 }
5108 5037
5109 // Since we are running on the UI thread don't call GetURLRequestContext(). 5038 // Since we are running on the UI thread don't call GetURLRequestContext().
5110 scoped_refptr<URLRequestContextGetter> context_getter = 5039 scoped_refptr<URLRequestContextGetter> context_getter =
5111 browser->profile()->GetRequestContext(); 5040 browser->profile()->GetRequestContext();
5112 5041
5113 base::WaitableEvent event(true /* manual reset */, 5042 base::WaitableEvent event(true /* manual reset */,
5114 false /* not initially signaled */); 5043 false /* not initially signaled */);
5115 bool success = false; 5044 bool success = false;
5116 Task* task = NewRunnableFunction( 5045 Task* task = NewRunnableFunction(
5117 &SetCookieOnIOThread, 5046 &automation_cookie_util::SetCookieOnIOThread,
5118 GURL(url), cookie, context_getter, &event, &success); 5047 GURL(url), cookie, context_getter, &event, &success);
5119 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { 5048 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) {
5120 reply.SendError("Couldn't post task to set the cookie"); 5049 reply.SendError("Couldn't post task to set the cookie");
5121 return; 5050 return;
5122 } 5051 }
5123 event.Wait(); 5052 event.Wait();
5124 5053
5125 if (!success) { 5054 if (!success) {
5126 reply.SendError("Could not set the cookie"); 5055 reply.SendError("Could not set the cookie");
5127 return; 5056 return;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
5358 // If you change this, update Observer for NotificationType::SESSION_END 5287 // If you change this, update Observer for NotificationType::SESSION_END
5359 // below. 5288 // below.
5360 MessageLoop::current()->PostTask(FROM_HERE, 5289 MessageLoop::current()->PostTask(FROM_HERE,
5361 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); 5290 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider));
5362 } 5291 }
5363 } 5292 }
5364 5293
5365 void TestingAutomationProvider::OnRemoveProvider() { 5294 void TestingAutomationProvider::OnRemoveProvider() {
5366 AutomationProviderList::GetInstance()->RemoveProvider(this); 5295 AutomationProviderList::GetInstance()->RemoveProvider(this);
5367 } 5296 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698