OLD | NEW |
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 |
(...skipping 12 matching lines...) Expand all Loading... |
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_provider_json.h" | 29 #include "chrome/browser/automation/automation_provider_json.h" |
30 #include "chrome/browser/automation/automation_provider_list.h" | 30 #include "chrome/browser/automation/automation_provider_list.h" |
31 #include "chrome/browser/automation/automation_provider_observers.h" | 31 #include "chrome/browser/automation/automation_provider_observers.h" |
32 #include "chrome/browser/automation/automation_tab_tracker.h" | 32 #include "chrome/browser/automation/automation_tab_tracker.h" |
| 33 #include "chrome/browser/automation/automation_util.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" |
39 #include "chrome/browser/browser_shutdown.h" | 40 #include "chrome/browser/browser_shutdown.h" |
40 #include "chrome/browser/browser_window.h" | 41 #include "chrome/browser/browser_window.h" |
41 #include "chrome/browser/debugger/devtools_manager.h" | 42 #include "chrome/browser/debugger/devtools_manager.h" |
42 #include "chrome/browser/download/download_prefs.h" | 43 #include "chrome/browser/download/download_prefs.h" |
(...skipping 22 matching lines...) Expand all Loading... |
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/pref_names.h" | 76 #include "chrome/common/pref_names.h" |
77 #include "chrome/common/url_constants.h" | 77 #include "chrome/common/url_constants.h" |
78 #include "content/browser/renderer_host/render_process_host.h" | 78 #include "content/browser/renderer_host/render_process_host.h" |
79 #include "content/browser/renderer_host/render_view_host.h" | 79 #include "content/browser/renderer_host/render_view_host.h" |
80 #include "content/browser/tab_contents/interstitial_page.h" | 80 #include "content/browser/tab_contents/interstitial_page.h" |
81 #include "content/common/common_param_traits.h" | 81 #include "content/common/common_param_traits.h" |
82 #include "content/common/notification_service.h" | 82 #include "content/common/notification_service.h" |
83 #include "net/base/cookie_store.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" | 84 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
86 #include "ui/base/events.h" | 85 #include "ui/base/events.h" |
87 #include "ui/base/message_box_flags.h" | 86 #include "ui/base/message_box_flags.h" |
88 #include "webkit/plugins/npapi/plugin_list.h" | 87 #include "webkit/plugins/npapi/plugin_list.h" |
89 | 88 |
90 namespace { | 89 namespace { |
91 | 90 |
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) { | 91 void SendMouseClick(int flags) { |
121 ui_controls::MouseButton button = ui_controls::LEFT; | 92 ui_controls::MouseButton button = ui_controls::LEFT; |
122 if ((flags & ui::EF_LEFT_BUTTON_DOWN) == | 93 if ((flags & ui::EF_LEFT_BUTTON_DOWN) == |
123 ui::EF_LEFT_BUTTON_DOWN) { | 94 ui::EF_LEFT_BUTTON_DOWN) { |
124 button = ui_controls::LEFT; | 95 button = ui_controls::LEFT; |
125 } else if ((flags & ui::EF_RIGHT_BUTTON_DOWN) == | 96 } else if ((flags & ui::EF_RIGHT_BUTTON_DOWN) == |
126 ui::EF_RIGHT_BUTTON_DOWN) { | 97 ui::EF_RIGHT_BUTTON_DOWN) { |
127 button = ui_controls::RIGHT; | 98 button = ui_controls::RIGHT; |
128 } else if ((flags & ui::EF_MIDDLE_BUTTON_DOWN) == | 99 } else if ((flags & ui::EF_MIDDLE_BUTTON_DOWN) == |
129 ui::EF_MIDDLE_BUTTON_DOWN) { | 100 ui::EF_MIDDLE_BUTTON_DOWN) { |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 return; | 472 return; |
502 } | 473 } |
503 | 474 |
504 AutomationMsg_CloseTab::WriteReplyParams(reply_message, false); | 475 AutomationMsg_CloseTab::WriteReplyParams(reply_message, false); |
505 Send(reply_message); | 476 Send(reply_message); |
506 } | 477 } |
507 | 478 |
508 void TestingAutomationProvider::GetCookies(const GURL& url, int handle, | 479 void TestingAutomationProvider::GetCookies(const GURL& url, int handle, |
509 int* value_size, | 480 int* value_size, |
510 std::string* value) { | 481 std::string* value) { |
511 *value_size = -1; | 482 TabContents *contents = tab_tracker_->ContainsHandle(handle) ? |
512 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { | 483 tab_tracker_->GetResource(handle)->tab_contents() : NULL; |
513 // Since we are running on the UI thread don't call GetURLRequestContext(). | 484 automation_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 } | 485 } |
528 | 486 |
529 void TestingAutomationProvider::SetCookie(const GURL& url, | 487 void TestingAutomationProvider::SetCookie(const GURL& url, |
530 const std::string value, | 488 const std::string value, |
531 int handle, | 489 int handle, |
532 int* response_value) { | 490 int* response_value) { |
533 *response_value = -1; | 491 TabContents *contents = tab_tracker_->ContainsHandle(handle) ? |
534 | 492 tab_tracker_->GetResource(handle)->tab_contents() : NULL; |
535 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { | 493 automation_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 } | 494 } |
553 | 495 |
554 void TestingAutomationProvider::DeleteCookie(const GURL& url, | 496 void TestingAutomationProvider::DeleteCookie(const GURL& url, |
555 const std::string& cookie_name, | 497 const std::string& cookie_name, |
556 int handle, bool* success) { | 498 int handle, bool* success) { |
557 *success = false; | 499 TabContents *contents = tab_tracker_->ContainsHandle(handle) ? |
558 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { | 500 tab_tracker_->GetResource(handle)->tab_contents() : NULL; |
559 // Since we are running on the UI thread don't call GetURLRequestContext(). | 501 automation_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 } | 502 } |
573 | 503 |
574 void TestingAutomationProvider::ShowCollectedCookiesDialog( | 504 void TestingAutomationProvider::ShowCollectedCookiesDialog( |
575 int handle, bool* success) { | 505 int handle, bool* success) { |
576 *success = false; | 506 *success = false; |
577 if (tab_tracker_->ContainsHandle(handle)) { | 507 if (tab_tracker_->ContainsHandle(handle)) { |
578 TabContents* tab_contents = | 508 TabContents* tab_contents = |
579 tab_tracker_->GetResource(handle)->tab_contents(); | 509 tab_tracker_->GetResource(handle)->tab_contents(); |
580 tab_contents->delegate()->ShowCollectedCookiesDialog(tab_contents); | 510 tab_contents->delegate()->ShowCollectedCookiesDialog(tab_contents); |
581 *success = true; | 511 *success = true; |
(...skipping 4435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5017 reply.SendError(error); | 4947 reply.SendError(error); |
5018 return; | 4948 return; |
5019 } | 4949 } |
5020 DictionaryValue dict; | 4950 DictionaryValue dict; |
5021 dict.SetString("title", tab_contents->GetTitle()); | 4951 dict.SetString("title", tab_contents->GetTitle()); |
5022 reply.SendSuccess(&dict); | 4952 reply.SendSuccess(&dict); |
5023 } | 4953 } |
5024 | 4954 |
5025 void TestingAutomationProvider::GetCookiesJSON( | 4955 void TestingAutomationProvider::GetCookiesJSON( |
5026 DictionaryValue* args, IPC::Message* reply_message) { | 4956 DictionaryValue* args, IPC::Message* reply_message) { |
5027 AutomationJSONReply reply(this, reply_message); | 4957 automation_util::GetCookiesJSON(this, args, reply_message); |
5028 Browser* browser; | |
5029 std::string error; | |
5030 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | |
5031 reply.SendError(error); | |
5032 return; | |
5033 } | |
5034 std::string url; | |
5035 if (!args->GetString("url", &url)) { | |
5036 reply.SendError("'url' missing or invalid"); | |
5037 return; | |
5038 } | |
5039 | |
5040 // Since we are running on the UI thread don't call GetURLRequestContext(). | |
5041 scoped_refptr<URLRequestContextGetter> context_getter = | |
5042 browser->profile()->GetRequestContext(); | |
5043 | |
5044 std::string cookies; | |
5045 base::WaitableEvent event(true /* manual reset */, | |
5046 false /* not initially signaled */); | |
5047 Task* task = NewRunnableFunction( | |
5048 &GetCookiesOnIOThread, | |
5049 GURL(url), context_getter, &event, &cookies); | |
5050 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { | |
5051 reply.SendError("Couldn't post task to get the cookies"); | |
5052 return; | |
5053 } | |
5054 event.Wait(); | |
5055 | |
5056 DictionaryValue dict; | |
5057 dict.SetString("cookies", cookies); | |
5058 reply.SendSuccess(&dict); | |
5059 } | 4958 } |
5060 | 4959 |
5061 void TestingAutomationProvider::DeleteCookieJSON( | 4960 void TestingAutomationProvider::DeleteCookieJSON( |
5062 DictionaryValue* args, IPC::Message* reply_message) { | 4961 DictionaryValue* args, IPC::Message* reply_message) { |
5063 AutomationJSONReply reply(this, reply_message); | 4962 automation_util::DeleteCookieJSON(this, args, reply_message); |
5064 Browser* browser; | |
5065 std::string error; | |
5066 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | |
5067 reply.SendError(error); | |
5068 return; | |
5069 } | |
5070 std::string url, name; | |
5071 if (!args->GetString("url", &url)) { | |
5072 reply.SendError("'url' missing or invalid"); | |
5073 return; | |
5074 } | |
5075 if (!args->GetString("name", &name)) { | |
5076 reply.SendError("'name' missing or invalid"); | |
5077 return; | |
5078 } | |
5079 | |
5080 // Since we are running on the UI thread don't call GetURLRequestContext(). | |
5081 scoped_refptr<URLRequestContextGetter> context_getter = | |
5082 browser->profile()->GetRequestContext(); | |
5083 | |
5084 base::WaitableEvent event(true /* manual reset */, | |
5085 false /* not initially signaled */); | |
5086 Task* task = NewRunnableFunction( | |
5087 &DeleteCookieOnIOThread, | |
5088 GURL(url), name, context_getter, &event); | |
5089 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { | |
5090 reply.SendError("Couldn't post task to delete the cookie"); | |
5091 return; | |
5092 } | |
5093 event.Wait(); | |
5094 reply.SendSuccess(NULL); | |
5095 } | 4963 } |
5096 | 4964 |
5097 void TestingAutomationProvider::SetCookieJSON( | 4965 void TestingAutomationProvider::SetCookieJSON( |
5098 DictionaryValue* args, IPC::Message* reply_message) { | 4966 DictionaryValue* args, IPC::Message* reply_message) { |
5099 AutomationJSONReply reply(this, reply_message); | 4967 automation_util::SetCookieJSON(this, args, reply_message); |
5100 Browser* browser; | |
5101 std::string error; | |
5102 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | |
5103 reply.SendError(error); | |
5104 return; | |
5105 } | |
5106 std::string url, cookie; | |
5107 if (!args->GetString("url", &url)) { | |
5108 reply.SendError("'url' missing or invalid"); | |
5109 return; | |
5110 } | |
5111 if (!args->GetString("cookie", &cookie)) { | |
5112 reply.SendError("'cookie' missing or invalid"); | |
5113 return; | |
5114 } | |
5115 | |
5116 // Since we are running on the UI thread don't call GetURLRequestContext(). | |
5117 scoped_refptr<URLRequestContextGetter> context_getter = | |
5118 browser->profile()->GetRequestContext(); | |
5119 | |
5120 base::WaitableEvent event(true /* manual reset */, | |
5121 false /* not initially signaled */); | |
5122 bool success = false; | |
5123 Task* task = NewRunnableFunction( | |
5124 &SetCookieOnIOThread, | |
5125 GURL(url), cookie, context_getter, &event, &success); | |
5126 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { | |
5127 reply.SendError("Couldn't post task to set the cookie"); | |
5128 return; | |
5129 } | |
5130 event.Wait(); | |
5131 | |
5132 if (!success) { | |
5133 reply.SendError("Could not set the cookie"); | |
5134 return; | |
5135 } | |
5136 reply.SendSuccess(NULL); | |
5137 } | 4968 } |
5138 | 4969 |
5139 void TestingAutomationProvider::GetTabIds( | 4970 void TestingAutomationProvider::GetTabIds( |
5140 DictionaryValue* args, IPC::Message* reply_message) { | 4971 DictionaryValue* args, IPC::Message* reply_message) { |
5141 ListValue* id_list = new ListValue(); | 4972 ListValue* id_list = new ListValue(); |
5142 BrowserList::const_iterator iter = BrowserList::begin(); | 4973 BrowserList::const_iterator iter = BrowserList::begin(); |
5143 for (; iter != BrowserList::end(); ++iter) { | 4974 for (; iter != BrowserList::end(); ++iter) { |
5144 Browser* browser = *iter; | 4975 Browser* browser = *iter; |
5145 for (int i = 0; i < browser->tab_count(); ++i) { | 4976 for (int i = 0; i < browser->tab_count(); ++i) { |
5146 int id = browser->GetTabContentsAt(i)->controller().session_id().id(); | 4977 int id = browser->GetTabContentsAt(i)->controller().session_id().id(); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5365 // If you change this, update Observer for NotificationType::SESSION_END | 5196 // If you change this, update Observer for NotificationType::SESSION_END |
5366 // below. | 5197 // below. |
5367 MessageLoop::current()->PostTask(FROM_HERE, | 5198 MessageLoop::current()->PostTask(FROM_HERE, |
5368 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 5199 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
5369 } | 5200 } |
5370 } | 5201 } |
5371 | 5202 |
5372 void TestingAutomationProvider::OnRemoveProvider() { | 5203 void TestingAutomationProvider::OnRemoveProvider() { |
5373 AutomationProviderList::GetInstance()->RemoveProvider(this); | 5204 AutomationProviderList::GetInstance()->RemoveProvider(this); |
5374 } | 5205 } |
OLD | NEW |