| 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/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 Loading... |
| 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_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_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_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 4428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5010 reply.SendError(error); | 4939 reply.SendError(error); |
| 5011 return; | 4940 return; |
| 5012 } | 4941 } |
| 5013 DictionaryValue dict; | 4942 DictionaryValue dict; |
| 5014 dict.SetString("title", tab_contents->GetTitle()); | 4943 dict.SetString("title", tab_contents->GetTitle()); |
| 5015 reply.SendSuccess(&dict); | 4944 reply.SendSuccess(&dict); |
| 5016 } | 4945 } |
| 5017 | 4946 |
| 5018 void TestingAutomationProvider::GetCookiesJSON( | 4947 void TestingAutomationProvider::GetCookiesJSON( |
| 5019 DictionaryValue* args, IPC::Message* reply_message) { | 4948 DictionaryValue* args, IPC::Message* reply_message) { |
| 5020 AutomationJSONReply reply(this, reply_message); | 4949 automation_util::GetCookiesJSON(this, args, reply_message); |
| 5021 Browser* browser; | |
| 5022 std::string error; | |
| 5023 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | |
| 5024 reply.SendError(error); | |
| 5025 return; | |
| 5026 } | |
| 5027 std::string url; | |
| 5028 if (!args->GetString("url", &url)) { | |
| 5029 reply.SendError("'url' missing or invalid"); | |
| 5030 return; | |
| 5031 } | |
| 5032 | |
| 5033 // Since we are running on the UI thread don't call GetURLRequestContext(). | |
| 5034 scoped_refptr<URLRequestContextGetter> context_getter = | |
| 5035 browser->profile()->GetRequestContext(); | |
| 5036 | |
| 5037 std::string cookies; | |
| 5038 base::WaitableEvent event(true /* manual reset */, | |
| 5039 false /* not initially signaled */); | |
| 5040 Task* task = NewRunnableFunction( | |
| 5041 &GetCookiesOnIOThread, | |
| 5042 GURL(url), context_getter, &event, &cookies); | |
| 5043 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { | |
| 5044 reply.SendError("Couldn't post task to get the cookies"); | |
| 5045 return; | |
| 5046 } | |
| 5047 event.Wait(); | |
| 5048 | |
| 5049 DictionaryValue dict; | |
| 5050 dict.SetString("cookies", cookies); | |
| 5051 reply.SendSuccess(&dict); | |
| 5052 } | 4950 } |
| 5053 | 4951 |
| 5054 void TestingAutomationProvider::DeleteCookieJSON( | 4952 void TestingAutomationProvider::DeleteCookieJSON( |
| 5055 DictionaryValue* args, IPC::Message* reply_message) { | 4953 DictionaryValue* args, IPC::Message* reply_message) { |
| 5056 AutomationJSONReply reply(this, reply_message); | 4954 automation_util::DeleteCookieJSON(this, args, reply_message); |
| 5057 Browser* browser; | |
| 5058 std::string error; | |
| 5059 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | |
| 5060 reply.SendError(error); | |
| 5061 return; | |
| 5062 } | |
| 5063 std::string url, name; | |
| 5064 if (!args->GetString("url", &url)) { | |
| 5065 reply.SendError("'url' missing or invalid"); | |
| 5066 return; | |
| 5067 } | |
| 5068 if (!args->GetString("name", &name)) { | |
| 5069 reply.SendError("'name' missing or invalid"); | |
| 5070 return; | |
| 5071 } | |
| 5072 | |
| 5073 // Since we are running on the UI thread don't call GetURLRequestContext(). | |
| 5074 scoped_refptr<URLRequestContextGetter> context_getter = | |
| 5075 browser->profile()->GetRequestContext(); | |
| 5076 | |
| 5077 base::WaitableEvent event(true /* manual reset */, | |
| 5078 false /* not initially signaled */); | |
| 5079 Task* task = NewRunnableFunction( | |
| 5080 &DeleteCookieOnIOThread, | |
| 5081 GURL(url), name, context_getter, &event); | |
| 5082 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { | |
| 5083 reply.SendError("Couldn't post task to delete the cookie"); | |
| 5084 return; | |
| 5085 } | |
| 5086 event.Wait(); | |
| 5087 reply.SendSuccess(NULL); | |
| 5088 } | 4955 } |
| 5089 | 4956 |
| 5090 void TestingAutomationProvider::SetCookieJSON( | 4957 void TestingAutomationProvider::SetCookieJSON( |
| 5091 DictionaryValue* args, IPC::Message* reply_message) { | 4958 DictionaryValue* args, IPC::Message* reply_message) { |
| 5092 AutomationJSONReply reply(this, reply_message); | 4959 automation_util::SetCookieJSON(this, args, reply_message); |
| 5093 Browser* browser; | |
| 5094 std::string error; | |
| 5095 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | |
| 5096 reply.SendError(error); | |
| 5097 return; | |
| 5098 } | |
| 5099 std::string url, cookie; | |
| 5100 if (!args->GetString("url", &url)) { | |
| 5101 reply.SendError("'url' missing or invalid"); | |
| 5102 return; | |
| 5103 } | |
| 5104 if (!args->GetString("cookie", &cookie)) { | |
| 5105 reply.SendError("'cookie' missing or invalid"); | |
| 5106 return; | |
| 5107 } | |
| 5108 | |
| 5109 // Since we are running on the UI thread don't call GetURLRequestContext(). | |
| 5110 scoped_refptr<URLRequestContextGetter> context_getter = | |
| 5111 browser->profile()->GetRequestContext(); | |
| 5112 | |
| 5113 base::WaitableEvent event(true /* manual reset */, | |
| 5114 false /* not initially signaled */); | |
| 5115 bool success = false; | |
| 5116 Task* task = NewRunnableFunction( | |
| 5117 &SetCookieOnIOThread, | |
| 5118 GURL(url), cookie, context_getter, &event, &success); | |
| 5119 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { | |
| 5120 reply.SendError("Couldn't post task to set the cookie"); | |
| 5121 return; | |
| 5122 } | |
| 5123 event.Wait(); | |
| 5124 | |
| 5125 if (!success) { | |
| 5126 reply.SendError("Could not set the cookie"); | |
| 5127 return; | |
| 5128 } | |
| 5129 reply.SendSuccess(NULL); | |
| 5130 } | 4960 } |
| 5131 | 4961 |
| 5132 void TestingAutomationProvider::GetTabIds( | 4962 void TestingAutomationProvider::GetTabIds( |
| 5133 DictionaryValue* args, IPC::Message* reply_message) { | 4963 DictionaryValue* args, IPC::Message* reply_message) { |
| 5134 ListValue* id_list = new ListValue(); | 4964 ListValue* id_list = new ListValue(); |
| 5135 BrowserList::const_iterator iter = BrowserList::begin(); | 4965 BrowserList::const_iterator iter = BrowserList::begin(); |
| 5136 for (; iter != BrowserList::end(); ++iter) { | 4966 for (; iter != BrowserList::end(); ++iter) { |
| 5137 Browser* browser = *iter; | 4967 Browser* browser = *iter; |
| 5138 for (int i = 0; i < browser->tab_count(); ++i) { | 4968 for (int i = 0; i < browser->tab_count(); ++i) { |
| 5139 int id = browser->GetTabContentsAt(i)->controller().session_id().id(); | 4969 int id = browser->GetTabContentsAt(i)->controller().session_id().id(); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5358 // If you change this, update Observer for NotificationType::SESSION_END | 5188 // If you change this, update Observer for NotificationType::SESSION_END |
| 5359 // below. | 5189 // below. |
| 5360 MessageLoop::current()->PostTask(FROM_HERE, | 5190 MessageLoop::current()->PostTask(FROM_HERE, |
| 5361 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 5191 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
| 5362 } | 5192 } |
| 5363 } | 5193 } |
| 5364 | 5194 |
| 5365 void TestingAutomationProvider::OnRemoveProvider() { | 5195 void TestingAutomationProvider::OnRemoveProvider() { |
| 5366 AutomationProviderList::GetInstance()->RemoveProvider(this); | 5196 AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 5367 } | 5197 } |
| OLD | NEW |