OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 2639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2650 DownloadManager* download_manager = | 2650 DownloadManager* download_manager = |
2651 BrowserContext::GetDownloadManager(browser->profile()); | 2651 BrowserContext::GetDownloadManager(browser->profile()); |
2652 DownloadItem* selected_item = download_manager->GetDownload(id); | 2652 DownloadItem* selected_item = download_manager->GetDownload(id); |
2653 if (!selected_item) { | 2653 if (!selected_item) { |
2654 AutomationJSONReply(this, reply_message) | 2654 AutomationJSONReply(this, reply_message) |
2655 .SendError(StringPrintf("No download with an id of %d\n", id)); | 2655 .SendError(StringPrintf("No download with an id of %d\n", id)); |
2656 return; | 2656 return; |
2657 } | 2657 } |
2658 | 2658 |
2659 // We need to be IN_PROGRESS for these actions. | 2659 // We need to be IN_PROGRESS for these actions. |
2660 if ((action == "toggle_pause" || action == "cancel") && | 2660 if ((action == "pause" || action == "resume" || action == "cancel") && |
2661 !selected_item->IsInProgress()) { | 2661 !selected_item->IsInProgress()) { |
2662 AutomationJSONReply(this, reply_message) | 2662 AutomationJSONReply(this, reply_message) |
2663 .SendError("Selected DownloadItem is not in progress."); | 2663 .SendError("Selected DownloadItem is not in progress."); |
2664 } | 2664 } |
2665 | 2665 |
2666 if (action == "open") { | 2666 if (action == "open") { |
2667 selected_item->AddObserver( | 2667 selected_item->AddObserver( |
2668 new AutomationProviderDownloadUpdatedObserver( | 2668 new AutomationProviderDownloadUpdatedObserver( |
2669 this, reply_message, true, browser->profile()->IsOffTheRecord())); | 2669 this, reply_message, true, browser->profile()->IsOffTheRecord())); |
2670 selected_item->OpenDownload(); | 2670 selected_item->OpenDownload(); |
(...skipping 11 matching lines...) Expand all Loading... | |
2682 this, reply_message, download_manager); | 2682 this, reply_message, download_manager); |
2683 selected_item->Remove(); | 2683 selected_item->Remove(); |
2684 } else if (action == "decline_dangerous_download") { | 2684 } else if (action == "decline_dangerous_download") { |
2685 new AutomationProviderDownloadModelChangedObserver( | 2685 new AutomationProviderDownloadModelChangedObserver( |
2686 this, reply_message, download_manager); | 2686 this, reply_message, download_manager); |
2687 selected_item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 2687 selected_item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
2688 } else if (action == "save_dangerous_download") { | 2688 } else if (action == "save_dangerous_download") { |
2689 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( | 2689 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( |
2690 this, reply_message, false, browser->profile()->IsOffTheRecord())); | 2690 this, reply_message, false, browser->profile()->IsOffTheRecord())); |
2691 selected_item->DangerousDownloadValidated(); | 2691 selected_item->DangerousDownloadValidated(); |
2692 } else if (action == "toggle_pause") { | 2692 } else if (action == "pause") { |
2693 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( | 2693 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( |
2694 this, reply_message, false, browser->profile()->IsOffTheRecord())); | 2694 this, reply_message, false, browser->profile()->IsOffTheRecord())); |
2695 // This will still return if download has already completed. | 2695 // This will still return if download has already completed. |
2696 selected_item->TogglePause(); | 2696 selected_item->Pause(); |
2697 } else if (action == "resume") { | |
2698 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( | |
2699 this, reply_message, false, browser->profile()->IsOffTheRecord())); | |
2700 // This will still return if download has already completed. | |
asanka
2013/01/02 16:44:50
I'm not very familiar with the automation interfac
Randy Smith (Not in Mondays)
2013/01/02 20:16:02
You are quite correct. I had originally thought t
| |
2701 selected_item->Resume(); | |
2697 } else if (action == "cancel") { | 2702 } else if (action == "cancel") { |
2698 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( | 2703 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( |
2699 this, reply_message, false, browser->profile()->IsOffTheRecord())); | 2704 this, reply_message, false, browser->profile()->IsOffTheRecord())); |
2700 selected_item->Cancel(true); | 2705 selected_item->Cancel(true); |
2701 } else { | 2706 } else { |
2702 AutomationJSONReply(this, reply_message) | 2707 AutomationJSONReply(this, reply_message) |
2703 .SendError(StringPrintf("Invalid action '%s' given.", action.c_str())); | 2708 .SendError(StringPrintf("Invalid action '%s' given.", action.c_str())); |
2704 } | 2709 } |
2705 } | 2710 } |
2706 | 2711 |
(...skipping 3569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6276 if (g_browser_process) | 6281 if (g_browser_process) |
6277 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6282 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6278 } | 6283 } |
6279 | 6284 |
6280 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 6285 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
6281 WebContents* tab) { | 6286 WebContents* tab) { |
6282 TabStripModel* tab_strip = browser->tab_strip_model(); | 6287 TabStripModel* tab_strip = browser->tab_strip_model(); |
6283 if (tab_strip->GetActiveWebContents() != tab) | 6288 if (tab_strip->GetActiveWebContents() != tab) |
6284 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); | 6289 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); |
6285 } | 6290 } |
OLD | NEW |