| 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/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 #endif | 170 #endif |
| 171 | 171 |
| 172 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) | 172 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
| 173 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" | 173 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" |
| 174 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) | 174 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) |
| 175 | 175 |
| 176 using automation::Error; | 176 using automation::Error; |
| 177 using automation::ErrorCode; | 177 using automation::ErrorCode; |
| 178 using automation_util::SendErrorIfModalDialogActive; | 178 using automation_util::SendErrorIfModalDialogActive; |
| 179 using content::BrowserChildProcessHostIterator; | 179 using content::BrowserChildProcessHostIterator; |
| 180 using content::BrowserContext; |
| 180 using content::BrowserThread; | 181 using content::BrowserThread; |
| 181 using content::ChildProcessHost; | 182 using content::ChildProcessHost; |
| 182 using content::DownloadItem; | 183 using content::DownloadItem; |
| 183 using content::DownloadManager; | 184 using content::DownloadManager; |
| 184 using content::InterstitialPage; | 185 using content::InterstitialPage; |
| 185 using content::NativeWebKeyboardEvent; | 186 using content::NativeWebKeyboardEvent; |
| 186 using content::NavigationController; | 187 using content::NavigationController; |
| 187 using content::NavigationEntry; | 188 using content::NavigationEntry; |
| 188 using content::PluginService; | 189 using content::PluginService; |
| 189 using content::OpenURLParams; | 190 using content::OpenURLParams; |
| (...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 new DomOperationMessageSender(this, reply_message, false); | 1142 new DomOperationMessageSender(this, reply_message, false); |
| 1142 ExecuteJavascriptInRenderViewFrame(WideToUTF16Hack(frame_xpath), | 1143 ExecuteJavascriptInRenderViewFrame(WideToUTF16Hack(frame_xpath), |
| 1143 WideToUTF16Hack(script), reply_message, | 1144 WideToUTF16Hack(script), reply_message, |
| 1144 web_contents->GetRenderViewHost()); | 1145 web_contents->GetRenderViewHost()); |
| 1145 } | 1146 } |
| 1146 | 1147 |
| 1147 void TestingAutomationProvider::GetDownloadDirectory( | 1148 void TestingAutomationProvider::GetDownloadDirectory( |
| 1148 int handle, FilePath* download_directory) { | 1149 int handle, FilePath* download_directory) { |
| 1149 if (tab_tracker_->ContainsHandle(handle)) { | 1150 if (tab_tracker_->ContainsHandle(handle)) { |
| 1150 NavigationController* tab = tab_tracker_->GetResource(handle); | 1151 NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1151 DownloadManager* dlm = tab->GetBrowserContext()->GetDownloadManager(); | 1152 DownloadManager* dlm = |
| 1153 BrowserContext::GetDownloadManager(tab->GetBrowserContext()); |
| 1152 *download_directory = | 1154 *download_directory = |
| 1153 DownloadPrefs::FromDownloadManager(dlm)->download_path(); | 1155 DownloadPrefs::FromDownloadManager(dlm)->download_path(); |
| 1154 } | 1156 } |
| 1155 } | 1157 } |
| 1156 | 1158 |
| 1157 // Sample json input: { "command": "OpenNewBrowserWindowWithNewProfile" } | 1159 // Sample json input: { "command": "OpenNewBrowserWindowWithNewProfile" } |
| 1158 // Sample output: {} | 1160 // Sample output: {} |
| 1159 void TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile( | 1161 void TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile( |
| 1160 base::DictionaryValue* args, IPC::Message* reply_message) { | 1162 base::DictionaryValue* args, IPC::Message* reply_message) { |
| 1161 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1163 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| (...skipping 1459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2621 IPC::Message* reply_message) { | 2623 IPC::Message* reply_message) { |
| 2622 AutomationJSONReply reply(this, reply_message); | 2624 AutomationJSONReply reply(this, reply_message); |
| 2623 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 2625 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2624 ListValue* list_of_downloads = new ListValue; | 2626 ListValue* list_of_downloads = new ListValue; |
| 2625 | 2627 |
| 2626 DownloadService* download_service( | 2628 DownloadService* download_service( |
| 2627 DownloadServiceFactory::GetForProfile(browser->profile())); | 2629 DownloadServiceFactory::GetForProfile(browser->profile())); |
| 2628 | 2630 |
| 2629 if (download_service->HasCreatedDownloadManager()) { | 2631 if (download_service->HasCreatedDownloadManager()) { |
| 2630 std::vector<DownloadItem*> downloads; | 2632 std::vector<DownloadItem*> downloads; |
| 2631 download_service->GetDownloadManager()-> | 2633 BrowserContext::GetDownloadManager(browser->profile())-> |
| 2632 GetAllDownloads(FilePath(), &downloads); | 2634 GetAllDownloads(FilePath(), &downloads); |
| 2633 | 2635 |
| 2634 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | 2636 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
| 2635 it != downloads.end(); | 2637 it != downloads.end(); |
| 2636 it++) { // Fill info about each download item. | 2638 it++) { // Fill info about each download item. |
| 2637 list_of_downloads->Append(GetDictionaryFromDownloadItem(*it)); | 2639 list_of_downloads->Append(GetDictionaryFromDownloadItem(*it)); |
| 2638 } | 2640 } |
| 2639 } | 2641 } |
| 2640 return_value->Set("downloads", list_of_downloads); | 2642 return_value->Set("downloads", list_of_downloads); |
| 2641 reply.SendSuccess(return_value.get()); | 2643 reply.SendSuccess(return_value.get()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2656 DownloadService* download_service = | 2658 DownloadService* download_service = |
| 2657 DownloadServiceFactory::GetForProfile(browser->profile()); | 2659 DownloadServiceFactory::GetForProfile(browser->profile()); |
| 2658 if (!download_service->HasCreatedDownloadManager()) { | 2660 if (!download_service->HasCreatedDownloadManager()) { |
| 2659 // No download manager, so no downloads to wait for. | 2661 // No download manager, so no downloads to wait for. |
| 2660 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 2662 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 2661 return; | 2663 return; |
| 2662 } | 2664 } |
| 2663 | 2665 |
| 2664 // This observer will delete itself. | 2666 // This observer will delete itself. |
| 2665 new AllDownloadsCompleteObserver( | 2667 new AllDownloadsCompleteObserver( |
| 2666 this, reply_message, download_service->GetDownloadManager(), | 2668 this, reply_message, |
| 2669 BrowserContext::GetDownloadManager(browser->profile()), |
| 2667 pre_download_ids); | 2670 pre_download_ids); |
| 2668 } | 2671 } |
| 2669 | 2672 |
| 2670 namespace { | 2673 namespace { |
| 2671 | 2674 |
| 2672 DownloadItem* GetDownloadItemFromId(int id, DownloadManager* download_manager) { | 2675 DownloadItem* GetDownloadItemFromId(int id, DownloadManager* download_manager) { |
| 2673 std::vector<DownloadItem*> downloads; | 2676 std::vector<DownloadItem*> downloads; |
| 2674 download_manager->GetAllDownloads(FilePath(), &downloads); | 2677 download_manager->GetAllDownloads(FilePath(), &downloads); |
| 2675 DownloadItem* selected_item = NULL; | 2678 DownloadItem* selected_item = NULL; |
| 2676 | 2679 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2702 if (!download_service->HasCreatedDownloadManager()) { | 2705 if (!download_service->HasCreatedDownloadManager()) { |
| 2703 AutomationJSONReply(this, reply_message).SendError("No download manager."); | 2706 AutomationJSONReply(this, reply_message).SendError("No download manager."); |
| 2704 return; | 2707 return; |
| 2705 } | 2708 } |
| 2706 if (!args->GetInteger("id", &id) || !args->GetString("action", &action)) { | 2709 if (!args->GetInteger("id", &id) || !args->GetString("action", &action)) { |
| 2707 AutomationJSONReply(this, reply_message) | 2710 AutomationJSONReply(this, reply_message) |
| 2708 .SendError("Must include int id and string action."); | 2711 .SendError("Must include int id and string action."); |
| 2709 return; | 2712 return; |
| 2710 } | 2713 } |
| 2711 | 2714 |
| 2712 DownloadManager* download_manager = download_service->GetDownloadManager(); | 2715 DownloadManager* download_manager = |
| 2716 BrowserContext::GetDownloadManager(browser->profile()); |
| 2713 DownloadItem* selected_item = GetDownloadItemFromId(id, download_manager); | 2717 DownloadItem* selected_item = GetDownloadItemFromId(id, download_manager); |
| 2714 if (!selected_item) { | 2718 if (!selected_item) { |
| 2715 AutomationJSONReply(this, reply_message) | 2719 AutomationJSONReply(this, reply_message) |
| 2716 .SendError(StringPrintf("No download with an id of %d\n", id)); | 2720 .SendError(StringPrintf("No download with an id of %d\n", id)); |
| 2717 return; | 2721 return; |
| 2718 } | 2722 } |
| 2719 | 2723 |
| 2720 // We need to be IN_PROGRESS for these actions. | 2724 // We need to be IN_PROGRESS for these actions. |
| 2721 if ((action == "toggle_pause" || action == "cancel") && | 2725 if ((action == "toggle_pause" || action == "cancel") && |
| 2722 !selected_item->IsInProgress()) { | 2726 !selected_item->IsInProgress()) { |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3323 if (!web_contents->SavePage( | 3327 if (!web_contents->SavePage( |
| 3324 FilePath(filename), | 3328 FilePath(filename), |
| 3325 FilePath(parent_directory), | 3329 FilePath(parent_directory), |
| 3326 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)) { | 3330 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)) { |
| 3327 AutomationJSONReply(this, reply_message).SendError( | 3331 AutomationJSONReply(this, reply_message).SendError( |
| 3328 "Could not initiate SavePage"); | 3332 "Could not initiate SavePage"); |
| 3329 return; | 3333 return; |
| 3330 } | 3334 } |
| 3331 // The observer will delete itself when done. | 3335 // The observer will delete itself when done. |
| 3332 new SavePackageNotificationObserver( | 3336 new SavePackageNotificationObserver( |
| 3333 DownloadServiceFactory::GetForProfile( | 3337 BrowserContext::GetDownloadManager(browser->profile()), |
| 3334 browser->profile())->GetDownloadManager(), | |
| 3335 this, reply_message); | 3338 this, reply_message); |
| 3336 } | 3339 } |
| 3337 | 3340 |
| 3338 // Refer to ImportSettings() in chrome/test/pyautolib/pyauto.py for sample | 3341 // Refer to ImportSettings() in chrome/test/pyautolib/pyauto.py for sample |
| 3339 // json input. | 3342 // json input. |
| 3340 // Sample json output: "{}" | 3343 // Sample json output: "{}" |
| 3341 void TestingAutomationProvider::ImportSettings(Browser* browser, | 3344 void TestingAutomationProvider::ImportSettings(Browser* browser, |
| 3342 DictionaryValue* args, | 3345 DictionaryValue* args, |
| 3343 IPC::Message* reply_message) { | 3346 IPC::Message* reply_message) { |
| 3344 // Map from the json string passed over to the import item masks. | 3347 // Map from the json string passed over to the import item masks. |
| (...skipping 3311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6656 } | 6659 } |
| 6657 | 6660 |
| 6658 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 6661 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
| 6659 WebContents* tab) { | 6662 WebContents* tab) { |
| 6660 if (browser->GetSelectedWebContents() != tab || | 6663 if (browser->GetSelectedWebContents() != tab || |
| 6661 browser != BrowserList::GetLastActive()) { | 6664 browser != BrowserList::GetLastActive()) { |
| 6662 browser->ActivateTabAt(browser->GetIndexOfController(&tab->GetController()), | 6665 browser->ActivateTabAt(browser->GetIndexOfController(&tab->GetController()), |
| 6663 true /* user_gesture */); | 6666 true /* user_gesture */); |
| 6664 } | 6667 } |
| 6665 } | 6668 } |
| OLD | NEW |