| 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 2688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2699 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 2699 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2700 ListValue* list_of_downloads = new ListValue; | 2700 ListValue* list_of_downloads = new ListValue; |
| 2701 | 2701 |
| 2702 DownloadService* download_service( | 2702 DownloadService* download_service( |
| 2703 DownloadServiceFactory::GetForProfile(browser->profile())); | 2703 DownloadServiceFactory::GetForProfile(browser->profile())); |
| 2704 | 2704 |
| 2705 if (download_service->HasCreatedDownloadManager()) { | 2705 if (download_service->HasCreatedDownloadManager()) { |
| 2706 std::vector<DownloadItem*> downloads; | 2706 std::vector<DownloadItem*> downloads; |
| 2707 BrowserContext::GetDownloadManager(browser->profile())-> | 2707 BrowserContext::GetDownloadManager(browser->profile())-> |
| 2708 GetAllDownloads(FilePath(), &downloads); | 2708 GetAllDownloads(FilePath(), &downloads); |
| 2709 bool incognito = browser->profile()->HasOffTheRecordProfile() && |
| 2710 (browser->profile() == browser->profile()->GetOffTheRecordProfile()); |
| 2709 | 2711 |
| 2710 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | 2712 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
| 2711 it != downloads.end(); | 2713 it != downloads.end(); |
| 2712 it++) { // Fill info about each download item. | 2714 it++) { // Fill info about each download item. |
| 2713 list_of_downloads->Append(GetDictionaryFromDownloadItem(*it)); | 2715 list_of_downloads->Append(GetDictionaryFromDownloadItem(*it, incognito)); |
| 2714 } | 2716 } |
| 2715 } | 2717 } |
| 2716 return_value->Set("downloads", list_of_downloads); | 2718 return_value->Set("downloads", list_of_downloads); |
| 2717 reply.SendSuccess(return_value.get()); | 2719 reply.SendSuccess(return_value.get()); |
| 2718 } | 2720 } |
| 2719 | 2721 |
| 2720 void TestingAutomationProvider::WaitForAllDownloadsToComplete( | 2722 void TestingAutomationProvider::WaitForAllDownloadsToComplete( |
| 2721 Browser* browser, | 2723 Browser* browser, |
| 2722 DictionaryValue* args, | 2724 DictionaryValue* args, |
| 2723 IPC::Message* reply_message) { | 2725 IPC::Message* reply_message) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2795 return; | 2797 return; |
| 2796 } | 2798 } |
| 2797 | 2799 |
| 2798 // We need to be IN_PROGRESS for these actions. | 2800 // We need to be IN_PROGRESS for these actions. |
| 2799 if ((action == "toggle_pause" || action == "cancel") && | 2801 if ((action == "toggle_pause" || action == "cancel") && |
| 2800 !selected_item->IsInProgress()) { | 2802 !selected_item->IsInProgress()) { |
| 2801 AutomationJSONReply(this, reply_message) | 2803 AutomationJSONReply(this, reply_message) |
| 2802 .SendError("Selected DownloadItem is not in progress."); | 2804 .SendError("Selected DownloadItem is not in progress."); |
| 2803 } | 2805 } |
| 2804 | 2806 |
| 2807 bool incognito = browser->profile()->HasOffTheRecordProfile() && |
| 2808 (browser->profile() == browser->profile()->GetOffTheRecordProfile()); |
| 2805 if (action == "open") { | 2809 if (action == "open") { |
| 2806 selected_item->AddObserver( | 2810 selected_item->AddObserver( |
| 2807 new AutomationProviderDownloadUpdatedObserver( | 2811 new AutomationProviderDownloadUpdatedObserver( |
| 2808 this, reply_message, true)); | 2812 this, reply_message, true, incognito)); |
| 2809 selected_item->OpenDownload(); | 2813 selected_item->OpenDownload(); |
| 2810 } else if (action == "toggle_open_files_like_this") { | 2814 } else if (action == "toggle_open_files_like_this") { |
| 2811 DownloadPrefs* prefs = | 2815 DownloadPrefs* prefs = |
| 2812 DownloadPrefs::FromBrowserContext(selected_item->GetBrowserContext()); | 2816 DownloadPrefs::FromBrowserContext(selected_item->GetBrowserContext()); |
| 2813 FilePath path = selected_item->GetUserVerifiedFilePath(); | 2817 FilePath path = selected_item->GetUserVerifiedFilePath(); |
| 2814 if (!selected_item->ShouldOpenFileBasedOnExtension()) | 2818 if (!selected_item->ShouldOpenFileBasedOnExtension()) |
| 2815 prefs->EnableAutoOpenBasedOnExtension(path); | 2819 prefs->EnableAutoOpenBasedOnExtension(path); |
| 2816 else | 2820 else |
| 2817 prefs->DisableAutoOpenBasedOnExtension(path); | 2821 prefs->DisableAutoOpenBasedOnExtension(path); |
| 2818 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 2822 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 2819 } else if (action == "remove") { | 2823 } else if (action == "remove") { |
| 2820 download_manager->AddObserver( | 2824 download_manager->AddObserver( |
| 2821 new AutomationProviderDownloadModelChangedObserver( | 2825 new AutomationProviderDownloadModelChangedObserver( |
| 2822 this, reply_message, download_manager)); | 2826 this, reply_message, download_manager)); |
| 2823 selected_item->Remove(); | 2827 selected_item->Remove(); |
| 2824 } else if (action == "decline_dangerous_download") { | 2828 } else if (action == "decline_dangerous_download") { |
| 2825 download_manager->AddObserver( | 2829 download_manager->AddObserver( |
| 2826 new AutomationProviderDownloadModelChangedObserver( | 2830 new AutomationProviderDownloadModelChangedObserver( |
| 2827 this, reply_message, download_manager)); | 2831 this, reply_message, download_manager)); |
| 2828 selected_item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 2832 selected_item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
| 2829 } else if (action == "save_dangerous_download") { | 2833 } else if (action == "save_dangerous_download") { |
| 2830 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( | 2834 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( |
| 2831 this, reply_message, false)); | 2835 this, reply_message, false, incognito)); |
| 2832 selected_item->DangerousDownloadValidated(); | 2836 selected_item->DangerousDownloadValidated(); |
| 2833 } else if (action == "toggle_pause") { | 2837 } else if (action == "toggle_pause") { |
| 2834 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( | 2838 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( |
| 2835 this, reply_message, false)); | 2839 this, reply_message, false, incognito)); |
| 2836 // This will still return if download has already completed. | 2840 // This will still return if download has already completed. |
| 2837 selected_item->TogglePause(); | 2841 selected_item->TogglePause(); |
| 2838 } else if (action == "cancel") { | 2842 } else if (action == "cancel") { |
| 2839 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( | 2843 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( |
| 2840 this, reply_message, false)); | 2844 this, reply_message, false, incognito)); |
| 2841 selected_item->Cancel(true); | 2845 selected_item->Cancel(true); |
| 2842 } else { | 2846 } else { |
| 2843 AutomationJSONReply(this, reply_message) | 2847 AutomationJSONReply(this, reply_message) |
| 2844 .SendError(StringPrintf("Invalid action '%s' given.", action.c_str())); | 2848 .SendError(StringPrintf("Invalid action '%s' given.", action.c_str())); |
| 2845 } | 2849 } |
| 2846 } | 2850 } |
| 2847 | 2851 |
| 2848 // Sample JSON input { "command": "LoadSearchEngineInfo" } | 2852 // Sample JSON input { "command": "LoadSearchEngineInfo" } |
| 2849 void TestingAutomationProvider::LoadSearchEngineInfo( | 2853 void TestingAutomationProvider::LoadSearchEngineInfo( |
| 2850 Browser* browser, | 2854 Browser* browser, |
| (...skipping 4053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6904 void TestingAutomationProvider::OnRemoveProvider() { | 6908 void TestingAutomationProvider::OnRemoveProvider() { |
| 6905 if (g_browser_process) | 6909 if (g_browser_process) |
| 6906 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6910 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
| 6907 } | 6911 } |
| 6908 | 6912 |
| 6909 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 6913 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
| 6910 WebContents* tab) { | 6914 WebContents* tab) { |
| 6911 if (chrome::GetActiveWebContents(browser) != tab) | 6915 if (chrome::GetActiveWebContents(browser) != tab) |
| 6912 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); | 6916 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); |
| 6913 } | 6917 } |
| OLD | NEW |