| 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 <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "chrome/browser/automation/automation_util.h" | 39 #include "chrome/browser/automation/automation_util.h" |
| 40 #include "chrome/browser/automation/automation_window_tracker.h" | 40 #include "chrome/browser/automation/automation_window_tracker.h" |
| 41 #include "chrome/browser/automation/ui_controls.h" | 41 #include "chrome/browser/automation/ui_controls.h" |
| 42 #include "chrome/browser/bookmarks/bookmark_model.h" | 42 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 43 #include "chrome/browser/bookmarks/bookmark_storage.h" | 43 #include "chrome/browser/bookmarks/bookmark_storage.h" |
| 44 #include "chrome/browser/browser_process.h" | 44 #include "chrome/browser/browser_process.h" |
| 45 #include "chrome/browser/browser_shutdown.h" | 45 #include "chrome/browser/browser_shutdown.h" |
| 46 #include "chrome/browser/content_settings/host_content_settings_map.h" | 46 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 47 #include "chrome/browser/debugger/devtools_window.h" | 47 #include "chrome/browser/debugger/devtools_window.h" |
| 48 #include "chrome/browser/download/download_prefs.h" | 48 #include "chrome/browser/download/download_prefs.h" |
| 49 #include "chrome/browser/download/download_service.h" |
| 50 #include "chrome/browser/download/download_service_factory.h" |
| 49 #include "chrome/browser/download/save_package_file_picker.h" | 51 #include "chrome/browser/download/save_package_file_picker.h" |
| 50 #include "chrome/browser/extensions/extension_browser_event_router.h" | 52 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 51 #include "chrome/browser/extensions/extension_host.h" | 53 #include "chrome/browser/extensions/extension_host.h" |
| 52 #include "chrome/browser/extensions/extension_process_manager.h" | 54 #include "chrome/browser/extensions/extension_process_manager.h" |
| 53 #include "chrome/browser/extensions/extension_service.h" | 55 #include "chrome/browser/extensions/extension_service.h" |
| 54 #include "chrome/browser/extensions/extension_updater.h" | 56 #include "chrome/browser/extensions/extension_updater.h" |
| 55 #include "chrome/browser/history/top_sites.h" | 57 #include "chrome/browser/history/top_sites.h" |
| 56 #include "chrome/browser/importer/importer_host.h" | 58 #include "chrome/browser/importer/importer_host.h" |
| 57 #include "chrome/browser/importer/importer_list.h" | 59 #include "chrome/browser/importer/importer_list.h" |
| 58 #include "chrome/browser/infobars/infobar_tab_helper.h" | 60 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| (...skipping 3016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3075 | 3077 |
| 3076 // Sample json input: { "command": "GetDownloadsInfo" } | 3078 // Sample json input: { "command": "GetDownloadsInfo" } |
| 3077 // Refer chrome/test/pyautolib/download_info.py for sample json output. | 3079 // Refer chrome/test/pyautolib/download_info.py for sample json output. |
| 3078 void TestingAutomationProvider::GetDownloadsInfo(Browser* browser, | 3080 void TestingAutomationProvider::GetDownloadsInfo(Browser* browser, |
| 3079 DictionaryValue* args, | 3081 DictionaryValue* args, |
| 3080 IPC::Message* reply_message) { | 3082 IPC::Message* reply_message) { |
| 3081 AutomationJSONReply reply(this, reply_message); | 3083 AutomationJSONReply reply(this, reply_message); |
| 3082 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 3084 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 3083 ListValue* list_of_downloads = new ListValue; | 3085 ListValue* list_of_downloads = new ListValue; |
| 3084 | 3086 |
| 3085 if (browser->profile()->HasCreatedDownloadManager()) { | 3087 DownloadService* download_service( |
| 3088 DownloadServiceFactory::GetForProfile(browser->profile())); |
| 3089 |
| 3090 if (download_service->HasCreatedDownloadManager()) { |
| 3086 std::vector<DownloadItem*> downloads; | 3091 std::vector<DownloadItem*> downloads; |
| 3087 browser->profile()->GetDownloadManager()-> | 3092 download_service->GetDownloadManager()-> |
| 3088 GetAllDownloads(FilePath(), &downloads); | 3093 GetAllDownloads(FilePath(), &downloads); |
| 3089 | 3094 |
| 3090 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | 3095 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
| 3091 it != downloads.end(); | 3096 it != downloads.end(); |
| 3092 it++) { // Fill info about each download item. | 3097 it++) { // Fill info about each download item. |
| 3093 list_of_downloads->Append(GetDictionaryFromDownloadItem(*it)); | 3098 list_of_downloads->Append(GetDictionaryFromDownloadItem(*it)); |
| 3094 } | 3099 } |
| 3095 } | 3100 } |
| 3096 return_value->Set("downloads", list_of_downloads); | 3101 return_value->Set("downloads", list_of_downloads); |
| 3097 reply.SendSuccess(return_value.get()); | 3102 reply.SendSuccess(return_value.get()); |
| 3098 } | 3103 } |
| 3099 | 3104 |
| 3100 void TestingAutomationProvider::WaitForAllDownloadsToComplete( | 3105 void TestingAutomationProvider::WaitForAllDownloadsToComplete( |
| 3101 Browser* browser, | 3106 Browser* browser, |
| 3102 DictionaryValue* args, | 3107 DictionaryValue* args, |
| 3103 IPC::Message* reply_message) { | 3108 IPC::Message* reply_message) { |
| 3104 ListValue* pre_download_ids = NULL; | 3109 ListValue* pre_download_ids = NULL; |
| 3105 | 3110 |
| 3106 if (!args->GetList("pre_download_ids", &pre_download_ids)) { | 3111 if (!args->GetList("pre_download_ids", &pre_download_ids)) { |
| 3107 AutomationJSONReply(this, reply_message) | 3112 AutomationJSONReply(this, reply_message) |
| 3108 .SendError(StringPrintf("List of IDs of previous downloads required.")); | 3113 .SendError(StringPrintf("List of IDs of previous downloads required.")); |
| 3109 return; | 3114 return; |
| 3110 } | 3115 } |
| 3111 if (!browser->profile()->HasCreatedDownloadManager()) { | 3116 |
| 3117 DownloadService* download_service = |
| 3118 DownloadServiceFactory::GetForProfile(browser->profile()); |
| 3119 if (!download_service->HasCreatedDownloadManager()) { |
| 3112 // No download manager, so no downloads to wait for. | 3120 // No download manager, so no downloads to wait for. |
| 3113 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 3121 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 3114 return; | 3122 return; |
| 3115 } | 3123 } |
| 3116 | 3124 |
| 3117 // This observer will delete itself. | 3125 // This observer will delete itself. |
| 3118 new AllDownloadsCompleteObserver( | 3126 new AllDownloadsCompleteObserver( |
| 3119 this, reply_message, browser->profile()->GetDownloadManager(), | 3127 this, reply_message, download_service->GetDownloadManager(), |
| 3120 pre_download_ids); | 3128 pre_download_ids); |
| 3121 } | 3129 } |
| 3122 | 3130 |
| 3123 namespace { | 3131 namespace { |
| 3124 | 3132 |
| 3125 DownloadItem* GetDownloadItemFromId(int id, DownloadManager* download_manager) { | 3133 DownloadItem* GetDownloadItemFromId(int id, DownloadManager* download_manager) { |
| 3126 std::vector<DownloadItem*> downloads; | 3134 std::vector<DownloadItem*> downloads; |
| 3127 download_manager->GetAllDownloads(FilePath(), &downloads); | 3135 download_manager->GetAllDownloads(FilePath(), &downloads); |
| 3128 DownloadItem* selected_item = NULL; | 3136 DownloadItem* selected_item = NULL; |
| 3129 | 3137 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3143 | 3151 |
| 3144 // See PerformActionOnDownload() in chrome/test/pyautolib/pyauto.py for sample | 3152 // See PerformActionOnDownload() in chrome/test/pyautolib/pyauto.py for sample |
| 3145 // json input and output. | 3153 // json input and output. |
| 3146 void TestingAutomationProvider::PerformActionOnDownload( | 3154 void TestingAutomationProvider::PerformActionOnDownload( |
| 3147 Browser* browser, | 3155 Browser* browser, |
| 3148 DictionaryValue* args, | 3156 DictionaryValue* args, |
| 3149 IPC::Message* reply_message) { | 3157 IPC::Message* reply_message) { |
| 3150 int id; | 3158 int id; |
| 3151 std::string action; | 3159 std::string action; |
| 3152 | 3160 |
| 3153 if (!browser->profile()->HasCreatedDownloadManager()) { | 3161 DownloadService* download_service = |
| 3162 DownloadServiceFactory::GetForProfile(browser->profile()); |
| 3163 if (!download_service->HasCreatedDownloadManager()) { |
| 3154 AutomationJSONReply(this, reply_message).SendError("No download manager."); | 3164 AutomationJSONReply(this, reply_message).SendError("No download manager."); |
| 3155 return; | 3165 return; |
| 3156 } | 3166 } |
| 3157 if (!args->GetInteger("id", &id) || !args->GetString("action", &action)) { | 3167 if (!args->GetInteger("id", &id) || !args->GetString("action", &action)) { |
| 3158 AutomationJSONReply(this, reply_message) | 3168 AutomationJSONReply(this, reply_message) |
| 3159 .SendError("Must include int id and string action."); | 3169 .SendError("Must include int id and string action."); |
| 3160 return; | 3170 return; |
| 3161 } | 3171 } |
| 3162 | 3172 |
| 3163 DownloadManager* download_manager = browser->profile()->GetDownloadManager(); | 3173 DownloadManager* download_manager = download_service->GetDownloadManager(); |
| 3164 DownloadItem* selected_item = GetDownloadItemFromId(id, download_manager); | 3174 DownloadItem* selected_item = GetDownloadItemFromId(id, download_manager); |
| 3165 if (!selected_item) { | 3175 if (!selected_item) { |
| 3166 AutomationJSONReply(this, reply_message) | 3176 AutomationJSONReply(this, reply_message) |
| 3167 .SendError(StringPrintf("No download with an id of %d\n", id)); | 3177 .SendError(StringPrintf("No download with an id of %d\n", id)); |
| 3168 return; | 3178 return; |
| 3169 } | 3179 } |
| 3170 | 3180 |
| 3171 if (action == "open") { | 3181 if (action == "open") { |
| 3172 selected_item->AddObserver( | 3182 selected_item->AddObserver( |
| 3173 new AutomationProviderDownloadUpdatedObserver( | 3183 new AutomationProviderDownloadUpdatedObserver( |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3682 if (!tab_contents->SavePage( | 3692 if (!tab_contents->SavePage( |
| 3683 FilePath(filename), | 3693 FilePath(filename), |
| 3684 FilePath(parent_directory), | 3694 FilePath(parent_directory), |
| 3685 SavePackage::SAVE_AS_ONLY_HTML)) { | 3695 SavePackage::SAVE_AS_ONLY_HTML)) { |
| 3686 AutomationJSONReply(this, reply_message).SendError( | 3696 AutomationJSONReply(this, reply_message).SendError( |
| 3687 "Could not initiate SavePage"); | 3697 "Could not initiate SavePage"); |
| 3688 return; | 3698 return; |
| 3689 } | 3699 } |
| 3690 // The observer will delete itself when done. | 3700 // The observer will delete itself when done. |
| 3691 new SavePackageNotificationObserver( | 3701 new SavePackageNotificationObserver( |
| 3692 browser->profile()->GetDownloadManager(), this, reply_message); | 3702 DownloadServiceFactory::GetForProfile( |
| 3703 browser->profile())->GetDownloadManager(), |
| 3704 this, reply_message); |
| 3693 } | 3705 } |
| 3694 | 3706 |
| 3695 // Refer to ImportSettings() in chrome/test/pyautolib/pyauto.py for sample | 3707 // Refer to ImportSettings() in chrome/test/pyautolib/pyauto.py for sample |
| 3696 // json input. | 3708 // json input. |
| 3697 // Sample json output: "{}" | 3709 // Sample json output: "{}" |
| 3698 void TestingAutomationProvider::ImportSettings(Browser* browser, | 3710 void TestingAutomationProvider::ImportSettings(Browser* browser, |
| 3699 DictionaryValue* args, | 3711 DictionaryValue* args, |
| 3700 IPC::Message* reply_message) { | 3712 IPC::Message* reply_message) { |
| 3701 // Map from the json string passed over to the import item masks. | 3713 // Map from the json string passed over to the import item masks. |
| 3702 std::map<std::string, importer::ImportItem> string_to_import_item; | 3714 std::map<std::string, importer::ImportItem> string_to_import_item; |
| (...skipping 2804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6507 | 6519 |
| 6508 Send(reply_message_); | 6520 Send(reply_message_); |
| 6509 redirect_query_ = 0; | 6521 redirect_query_ = 0; |
| 6510 reply_message_ = NULL; | 6522 reply_message_ = NULL; |
| 6511 } | 6523 } |
| 6512 | 6524 |
| 6513 void TestingAutomationProvider::OnRemoveProvider() { | 6525 void TestingAutomationProvider::OnRemoveProvider() { |
| 6514 if (g_browser_process) | 6526 if (g_browser_process) |
| 6515 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6527 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
| 6516 } | 6528 } |
| OLD | NEW |