| 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 2667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2678 DownloadServiceFactory::GetForProfile(browser->profile())); | 2678 DownloadServiceFactory::GetForProfile(browser->profile())); |
| 2679 | 2679 |
| 2680 if (download_service->HasCreatedDownloadManager()) { | 2680 if (download_service->HasCreatedDownloadManager()) { |
| 2681 std::vector<DownloadItem*> downloads; | 2681 std::vector<DownloadItem*> downloads; |
| 2682 BrowserContext::GetDownloadManager(browser->profile())-> | 2682 BrowserContext::GetDownloadManager(browser->profile())-> |
| 2683 GetAllDownloads(FilePath(), &downloads); | 2683 GetAllDownloads(FilePath(), &downloads); |
| 2684 | 2684 |
| 2685 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | 2685 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
| 2686 it != downloads.end(); | 2686 it != downloads.end(); |
| 2687 it++) { // Fill info about each download item. | 2687 it++) { // Fill info about each download item. |
| 2688 list_of_downloads->Append(GetDictionaryFromDownloadItem(*it)); | 2688 list_of_downloads->Append(GetDictionaryFromDownloadItem( |
| 2689 *it, browser->profile())); |
| 2689 } | 2690 } |
| 2690 } | 2691 } |
| 2691 return_value->Set("downloads", list_of_downloads); | 2692 return_value->Set("downloads", list_of_downloads); |
| 2692 reply.SendSuccess(return_value.get()); | 2693 reply.SendSuccess(return_value.get()); |
| 2693 } | 2694 } |
| 2694 | 2695 |
| 2695 void TestingAutomationProvider::WaitForAllDownloadsToComplete( | 2696 void TestingAutomationProvider::WaitForAllDownloadsToComplete( |
| 2696 Browser* browser, | 2697 Browser* browser, |
| 2697 DictionaryValue* args, | 2698 DictionaryValue* args, |
| 2698 IPC::Message* reply_message) { | 2699 IPC::Message* reply_message) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2773 // We need to be IN_PROGRESS for these actions. | 2774 // We need to be IN_PROGRESS for these actions. |
| 2774 if ((action == "toggle_pause" || action == "cancel") && | 2775 if ((action == "toggle_pause" || action == "cancel") && |
| 2775 !selected_item->IsInProgress()) { | 2776 !selected_item->IsInProgress()) { |
| 2776 AutomationJSONReply(this, reply_message) | 2777 AutomationJSONReply(this, reply_message) |
| 2777 .SendError("Selected DownloadItem is not in progress."); | 2778 .SendError("Selected DownloadItem is not in progress."); |
| 2778 } | 2779 } |
| 2779 | 2780 |
| 2780 if (action == "open") { | 2781 if (action == "open") { |
| 2781 selected_item->AddObserver( | 2782 selected_item->AddObserver( |
| 2782 new AutomationProviderDownloadUpdatedObserver( | 2783 new AutomationProviderDownloadUpdatedObserver( |
| 2783 this, reply_message, true)); | 2784 this, reply_message, true, browser->profile())); |
| 2784 selected_item->OpenDownload(); | 2785 selected_item->OpenDownload(); |
| 2785 } else if (action == "toggle_open_files_like_this") { | 2786 } else if (action == "toggle_open_files_like_this") { |
| 2786 DownloadPrefs* prefs = | 2787 DownloadPrefs* prefs = |
| 2787 DownloadPrefs::FromBrowserContext(selected_item->GetBrowserContext()); | 2788 DownloadPrefs::FromBrowserContext(selected_item->GetBrowserContext()); |
| 2788 FilePath path = selected_item->GetUserVerifiedFilePath(); | 2789 FilePath path = selected_item->GetUserVerifiedFilePath(); |
| 2789 if (!selected_item->ShouldOpenFileBasedOnExtension()) | 2790 if (!selected_item->ShouldOpenFileBasedOnExtension()) |
| 2790 prefs->EnableAutoOpenBasedOnExtension(path); | 2791 prefs->EnableAutoOpenBasedOnExtension(path); |
| 2791 else | 2792 else |
| 2792 prefs->DisableAutoOpenBasedOnExtension(path); | 2793 prefs->DisableAutoOpenBasedOnExtension(path); |
| 2793 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 2794 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 2794 } else if (action == "remove") { | 2795 } else if (action == "remove") { |
| 2795 download_manager->AddObserver( | 2796 download_manager->AddObserver( |
| 2796 new AutomationProviderDownloadModelChangedObserver( | 2797 new AutomationProviderDownloadModelChangedObserver( |
| 2797 this, reply_message, download_manager)); | 2798 this, reply_message, download_manager)); |
| 2798 selected_item->Remove(); | 2799 selected_item->Remove(); |
| 2799 } else if (action == "decline_dangerous_download") { | 2800 } else if (action == "decline_dangerous_download") { |
| 2800 download_manager->AddObserver( | 2801 download_manager->AddObserver( |
| 2801 new AutomationProviderDownloadModelChangedObserver( | 2802 new AutomationProviderDownloadModelChangedObserver( |
| 2802 this, reply_message, download_manager)); | 2803 this, reply_message, download_manager)); |
| 2803 selected_item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 2804 selected_item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
| 2804 } else if (action == "save_dangerous_download") { | 2805 } else if (action == "save_dangerous_download") { |
| 2805 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( | 2806 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( |
| 2806 this, reply_message, false)); | 2807 this, reply_message, false, browser->profile())); |
| 2807 selected_item->DangerousDownloadValidated(); | 2808 selected_item->DangerousDownloadValidated(); |
| 2808 } else if (action == "toggle_pause") { | 2809 } else if (action == "toggle_pause") { |
| 2809 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( | 2810 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( |
| 2810 this, reply_message, false)); | 2811 this, reply_message, false, browser->profile())); |
| 2811 // This will still return if download has already completed. | 2812 // This will still return if download has already completed. |
| 2812 selected_item->TogglePause(); | 2813 selected_item->TogglePause(); |
| 2813 } else if (action == "cancel") { | 2814 } else if (action == "cancel") { |
| 2814 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( | 2815 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( |
| 2815 this, reply_message, false)); | 2816 this, reply_message, false, browser->profile())); |
| 2816 selected_item->Cancel(true); | 2817 selected_item->Cancel(true); |
| 2817 } else { | 2818 } else { |
| 2818 AutomationJSONReply(this, reply_message) | 2819 AutomationJSONReply(this, reply_message) |
| 2819 .SendError(StringPrintf("Invalid action '%s' given.", action.c_str())); | 2820 .SendError(StringPrintf("Invalid action '%s' given.", action.c_str())); |
| 2820 } | 2821 } |
| 2821 } | 2822 } |
| 2822 | 2823 |
| 2823 void TestingAutomationProvider::SetDownloadShelfVisibleJSON( | 2824 void TestingAutomationProvider::SetDownloadShelfVisibleJSON( |
| 2824 DictionaryValue* args, | 2825 DictionaryValue* args, |
| 2825 IPC::Message* reply_message) { | 2826 IPC::Message* reply_message) { |
| (...skipping 4258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7084 void TestingAutomationProvider::OnRemoveProvider() { | 7085 void TestingAutomationProvider::OnRemoveProvider() { |
| 7085 if (g_browser_process) | 7086 if (g_browser_process) |
| 7086 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 7087 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
| 7087 } | 7088 } |
| 7088 | 7089 |
| 7089 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 7090 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
| 7090 WebContents* tab) { | 7091 WebContents* tab) { |
| 7091 if (chrome::GetActiveWebContents(browser) != tab) | 7092 if (chrome::GetActiveWebContents(browser) != tab) |
| 7092 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); | 7093 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); |
| 7093 } | 7094 } |
| OLD | NEW |