| 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 2625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2636 IPC::Message* reply_message) { | 2636 IPC::Message* reply_message) { |
| 2637 AutomationJSONReply reply(this, reply_message); | 2637 AutomationJSONReply reply(this, reply_message); |
| 2638 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 2638 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2639 ListValue* list_of_downloads = new ListValue; | 2639 ListValue* list_of_downloads = new ListValue; |
| 2640 | 2640 |
| 2641 DownloadService* download_service( | 2641 DownloadService* download_service( |
| 2642 DownloadServiceFactory::GetForProfile(browser->profile())); | 2642 DownloadServiceFactory::GetForProfile(browser->profile())); |
| 2643 | 2643 |
| 2644 if (download_service->HasCreatedDownloadManager()) { | 2644 if (download_service->HasCreatedDownloadManager()) { |
| 2645 std::vector<DownloadItem*> downloads; | 2645 std::vector<DownloadItem*> downloads; |
| 2646 BrowserContext::GetDownloadManager(browser->profile())-> | 2646 BrowserContext::GetDownloadManager(browser->profile())->GetAllDownloads( |
| 2647 GetAllDownloads(FilePath(), &downloads); | 2647 &downloads); |
| 2648 | 2648 |
| 2649 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | 2649 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
| 2650 it != downloads.end(); | 2650 it != downloads.end(); |
| 2651 it++) { // Fill info about each download item. | 2651 it++) { // Fill info about each download item. |
| 2652 list_of_downloads->Append(GetDictionaryFromDownloadItem( | 2652 list_of_downloads->Append(GetDictionaryFromDownloadItem( |
| 2653 *it, browser->profile()->IsOffTheRecord())); | 2653 *it, browser->profile()->IsOffTheRecord())); |
| 2654 } | 2654 } |
| 2655 } | 2655 } |
| 2656 return_value->Set("downloads", list_of_downloads); | 2656 return_value->Set("downloads", list_of_downloads); |
| 2657 reply.SendSuccess(return_value.get()); | 2657 reply.SendSuccess(return_value.get()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2677 return; | 2677 return; |
| 2678 } | 2678 } |
| 2679 | 2679 |
| 2680 // This observer will delete itself. | 2680 // This observer will delete itself. |
| 2681 new AllDownloadsCompleteObserver( | 2681 new AllDownloadsCompleteObserver( |
| 2682 this, reply_message, | 2682 this, reply_message, |
| 2683 BrowserContext::GetDownloadManager(browser->profile()), | 2683 BrowserContext::GetDownloadManager(browser->profile()), |
| 2684 pre_download_ids); | 2684 pre_download_ids); |
| 2685 } | 2685 } |
| 2686 | 2686 |
| 2687 namespace { | |
| 2688 | |
| 2689 DownloadItem* GetDownloadItemFromId(int id, DownloadManager* download_manager) { | |
| 2690 std::vector<DownloadItem*> downloads; | |
| 2691 download_manager->GetAllDownloads(FilePath(), &downloads); | |
| 2692 DownloadItem* selected_item = NULL; | |
| 2693 | |
| 2694 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | |
| 2695 it != downloads.end(); | |
| 2696 it++) { | |
| 2697 DownloadItem* curr_item = *it; | |
| 2698 if (curr_item->GetId() == id) { | |
| 2699 selected_item = curr_item; | |
| 2700 break; | |
| 2701 } | |
| 2702 } | |
| 2703 return selected_item; | |
| 2704 } | |
| 2705 | |
| 2706 } // namespace | |
| 2707 | |
| 2708 // See PerformActionOnDownload() in chrome/test/pyautolib/pyauto.py for sample | 2687 // See PerformActionOnDownload() in chrome/test/pyautolib/pyauto.py for sample |
| 2709 // json input and output. | 2688 // json input and output. |
| 2710 void TestingAutomationProvider::PerformActionOnDownload( | 2689 void TestingAutomationProvider::PerformActionOnDownload( |
| 2711 Browser* browser, | 2690 Browser* browser, |
| 2712 DictionaryValue* args, | 2691 DictionaryValue* args, |
| 2713 IPC::Message* reply_message) { | 2692 IPC::Message* reply_message) { |
| 2714 int id; | 2693 int id; |
| 2715 std::string action; | 2694 std::string action; |
| 2716 | 2695 |
| 2717 DownloadService* download_service = | 2696 DownloadService* download_service = |
| 2718 DownloadServiceFactory::GetForProfile(browser->profile()); | 2697 DownloadServiceFactory::GetForProfile(browser->profile()); |
| 2719 if (!download_service->HasCreatedDownloadManager()) { | 2698 if (!download_service->HasCreatedDownloadManager()) { |
| 2720 AutomationJSONReply(this, reply_message).SendError("No download manager."); | 2699 AutomationJSONReply(this, reply_message).SendError("No download manager."); |
| 2721 return; | 2700 return; |
| 2722 } | 2701 } |
| 2723 if (!args->GetInteger("id", &id) || !args->GetString("action", &action)) { | 2702 if (!args->GetInteger("id", &id) || !args->GetString("action", &action)) { |
| 2724 AutomationJSONReply(this, reply_message) | 2703 AutomationJSONReply(this, reply_message) |
| 2725 .SendError("Must include int id and string action."); | 2704 .SendError("Must include int id and string action."); |
| 2726 return; | 2705 return; |
| 2727 } | 2706 } |
| 2728 | 2707 |
| 2729 DownloadManager* download_manager = | 2708 DownloadManager* download_manager = |
| 2730 BrowserContext::GetDownloadManager(browser->profile()); | 2709 BrowserContext::GetDownloadManager(browser->profile()); |
| 2731 DownloadItem* selected_item = GetDownloadItemFromId(id, download_manager); | 2710 DownloadItem* selected_item = download_manager->GetDownload(id); |
| 2732 if (!selected_item) { | 2711 if (!selected_item) { |
| 2733 AutomationJSONReply(this, reply_message) | 2712 AutomationJSONReply(this, reply_message) |
| 2734 .SendError(StringPrintf("No download with an id of %d\n", id)); | 2713 .SendError(StringPrintf("No download with an id of %d\n", id)); |
| 2735 return; | 2714 return; |
| 2736 } | 2715 } |
| 2737 | 2716 |
| 2738 // We need to be IN_PROGRESS for these actions. | 2717 // We need to be IN_PROGRESS for these actions. |
| 2739 if ((action == "toggle_pause" || action == "cancel") && | 2718 if ((action == "toggle_pause" || action == "cancel") && |
| 2740 !selected_item->IsInProgress()) { | 2719 !selected_item->IsInProgress()) { |
| 2741 AutomationJSONReply(this, reply_message) | 2720 AutomationJSONReply(this, reply_message) |
| (...skipping 3699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6441 void TestingAutomationProvider::OnRemoveProvider() { | 6420 void TestingAutomationProvider::OnRemoveProvider() { |
| 6442 if (g_browser_process) | 6421 if (g_browser_process) |
| 6443 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6422 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
| 6444 } | 6423 } |
| 6445 | 6424 |
| 6446 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 6425 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
| 6447 WebContents* tab) { | 6426 WebContents* tab) { |
| 6448 if (chrome::GetActiveWebContents(browser) != tab) | 6427 if (chrome::GetActiveWebContents(browser) != tab) |
| 6449 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); | 6428 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); |
| 6450 } | 6429 } |
| OLD | NEW |