| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 void DidEnablePlugin(base::WeakPtr<AutomationProvider> automation, | 203 void DidEnablePlugin(base::WeakPtr<AutomationProvider> automation, |
| 204 IPC::Message* reply_message, | 204 IPC::Message* reply_message, |
| 205 const base::FilePath::StringType& path, | 205 const base::FilePath::StringType& path, |
| 206 const std::string& error_msg, | 206 const std::string& error_msg, |
| 207 bool did_enable) { | 207 bool did_enable) { |
| 208 if (did_enable) { | 208 if (did_enable) { |
| 209 SendSuccessReply(automation, reply_message); | 209 SendSuccessReply(automation, reply_message); |
| 210 } else { | 210 } else { |
| 211 if (automation) { | 211 if (automation) { |
| 212 AutomationJSONReply(automation.get(), reply_message).SendError( | 212 AutomationJSONReply(automation.get(), reply_message).SendError( |
| 213 StringPrintf(error_msg.c_str(), path.c_str())); | 213 base::StringPrintf(error_msg.c_str(), path.c_str())); |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 | 217 |
| 218 // Helper to resolve the overloading of PostTask. | 218 // Helper to resolve the overloading of PostTask. |
| 219 void PostTask(BrowserThread::ID id, const base::Closure& callback) { | 219 void PostTask(BrowserThread::ID id, const base::Closure& callback) { |
| 220 BrowserThread::PostTask(id, FROM_HERE, callback); | 220 BrowserThread::PostTask(id, FROM_HERE, callback); |
| 221 } | 221 } |
| 222 | 222 |
| 223 class AutomationInterstitialPage : public content::InterstitialPageDelegate { | 223 class AutomationInterstitialPage : public content::InterstitialPageDelegate { |
| (...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1153 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1153 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1154 base::FilePath::StringType path; | 1154 base::FilePath::StringType path; |
| 1155 if (!args->GetString("path", &path)) { | 1155 if (!args->GetString("path", &path)) { |
| 1156 AutomationJSONReply(this, reply_message).SendError( | 1156 AutomationJSONReply(this, reply_message).SendError( |
| 1157 "Invalid or missing arg: 'path'"); | 1157 "Invalid or missing arg: 'path'"); |
| 1158 return; | 1158 return; |
| 1159 } | 1159 } |
| 1160 Profile* profile = profile_manager->GetProfileByPath(base::FilePath(path)); | 1160 Profile* profile = profile_manager->GetProfileByPath(base::FilePath(path)); |
| 1161 if (!profile) { | 1161 if (!profile) { |
| 1162 AutomationJSONReply(this, reply_message).SendError( | 1162 AutomationJSONReply(this, reply_message).SendError( |
| 1163 StringPrintf("Invalid profile path: %s", path.c_str())); | 1163 base::StringPrintf("Invalid profile path: %s", path.c_str())); |
| 1164 return; | 1164 return; |
| 1165 } | 1165 } |
| 1166 int num_loads; | 1166 int num_loads; |
| 1167 if (!args->GetInteger("num_loads", &num_loads)) { | 1167 if (!args->GetInteger("num_loads", &num_loads)) { |
| 1168 AutomationJSONReply(this, reply_message).SendError( | 1168 AutomationJSONReply(this, reply_message).SendError( |
| 1169 "Invalid or missing arg: 'num_loads'"); | 1169 "Invalid or missing arg: 'num_loads'"); |
| 1170 return; | 1170 return; |
| 1171 } | 1171 } |
| 1172 new BrowserOpenedWithExistingProfileNotificationObserver( | 1172 new BrowserOpenedWithExistingProfileNotificationObserver( |
| 1173 this, reply_message, num_loads); | 1173 this, reply_message, num_loads); |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1984 "The browser window does not exist."); | 1984 "The browser window does not exist."); |
| 1985 } | 1985 } |
| 1986 } | 1986 } |
| 1987 | 1987 |
| 1988 void TestingAutomationProvider::SendJSONRequestWithBrowserIndex( | 1988 void TestingAutomationProvider::SendJSONRequestWithBrowserIndex( |
| 1989 int index, | 1989 int index, |
| 1990 const std::string& json_request, | 1990 const std::string& json_request, |
| 1991 IPC::Message* reply_message) { | 1991 IPC::Message* reply_message) { |
| 1992 Browser* browser = index < 0 ? NULL : automation_util::GetBrowserAt(index); | 1992 Browser* browser = index < 0 ? NULL : automation_util::GetBrowserAt(index); |
| 1993 if (!browser && index >= 0) { | 1993 if (!browser && index >= 0) { |
| 1994 AutomationJSONReply(this, reply_message).SendError( | 1994 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( |
| 1995 StringPrintf("Browser window with index=%d does not exist.", index)); | 1995 "Browser window with index=%d does not exist.", index)); |
| 1996 } else { | 1996 } else { |
| 1997 SendJSONRequest(browser, json_request, reply_message); | 1997 SendJSONRequest(browser, json_request, reply_message); |
| 1998 } | 1998 } |
| 1999 } | 1999 } |
| 2000 | 2000 |
| 2001 void TestingAutomationProvider::SendJSONRequest(Browser* browser, | 2001 void TestingAutomationProvider::SendJSONRequest(Browser* browser, |
| 2002 const std::string& json_request, | 2002 const std::string& json_request, |
| 2003 IPC::Message* reply_message) { | 2003 IPC::Message* reply_message) { |
| 2004 std::string command, error_string; | 2004 std::string command, error_string; |
| 2005 scoped_ptr<DictionaryValue> dict_value( | 2005 scoped_ptr<DictionaryValue> dict_value( |
| 2006 ParseJSONRequestCommand(json_request, &command, &error_string)); | 2006 ParseJSONRequestCommand(json_request, &command, &error_string)); |
| 2007 if (!dict_value.get() || command.empty()) { | 2007 if (!dict_value.get() || command.empty()) { |
| 2008 AutomationJSONReply(this, reply_message).SendError(error_string); | 2008 AutomationJSONReply(this, reply_message).SendError(error_string); |
| 2009 return; | 2009 return; |
| 2010 } | 2010 } |
| 2011 | 2011 |
| 2012 if (handler_map_.empty() || browser_handler_map_.empty()) | 2012 if (handler_map_.empty() || browser_handler_map_.empty()) |
| 2013 BuildJSONHandlerMaps(); | 2013 BuildJSONHandlerMaps(); |
| 2014 | 2014 |
| 2015 // Look for command in handlers that take a Browser. | 2015 // Look for command in handlers that take a Browser. |
| 2016 if (browser_handler_map_.find(std::string(command)) != | 2016 if (browser_handler_map_.find(std::string(command)) != |
| 2017 browser_handler_map_.end() && browser) { | 2017 browser_handler_map_.end() && browser) { |
| 2018 (this->*browser_handler_map_[command])(browser, dict_value.get(), | 2018 (this->*browser_handler_map_[command])(browser, dict_value.get(), |
| 2019 reply_message); | 2019 reply_message); |
| 2020 // Look for command in handlers that don't take a Browser. | 2020 // Look for command in handlers that don't take a Browser. |
| 2021 } else if (handler_map_.find(std::string(command)) != handler_map_.end()) { | 2021 } else if (handler_map_.find(std::string(command)) != handler_map_.end()) { |
| 2022 (this->*handler_map_[command])(dict_value.get(), reply_message); | 2022 (this->*handler_map_[command])(dict_value.get(), reply_message); |
| 2023 // Command has no handler. | 2023 // Command has no handler. |
| 2024 } else { | 2024 } else { |
| 2025 error_string = StringPrintf("Unknown command '%s'. Options: ", | 2025 error_string = base::StringPrintf("Unknown command '%s'. Options: ", |
| 2026 command.c_str()); | 2026 command.c_str()); |
| 2027 for (std::map<std::string, JsonHandler>::const_iterator it = | 2027 for (std::map<std::string, JsonHandler>::const_iterator it = |
| 2028 handler_map_.begin(); it != handler_map_.end(); ++it) { | 2028 handler_map_.begin(); it != handler_map_.end(); ++it) { |
| 2029 error_string += it->first + ", "; | 2029 error_string += it->first + ", "; |
| 2030 } | 2030 } |
| 2031 for (std::map<std::string, BrowserJsonHandler>::const_iterator it = | 2031 for (std::map<std::string, BrowserJsonHandler>::const_iterator it = |
| 2032 browser_handler_map_.begin(); it != browser_handler_map_.end(); ++it) { | 2032 browser_handler_map_.begin(); it != browser_handler_map_.end(); ++it) { |
| 2033 error_string += it->first + ", "; | 2033 error_string += it->first + ", "; |
| 2034 } | 2034 } |
| 2035 AutomationJSONReply(this, reply_message).SendError(error_string); | 2035 AutomationJSONReply(this, reply_message).SendError(error_string); |
| 2036 } | 2036 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2144 if (!args->GetInteger("tab_index", &tab_index) || | 2144 if (!args->GetInteger("tab_index", &tab_index) || |
| 2145 !args->GetInteger("infobar_index", &infobar_index_int) || | 2145 !args->GetInteger("infobar_index", &infobar_index_int) || |
| 2146 !args->GetString("action", &action)) { | 2146 !args->GetString("action", &action)) { |
| 2147 reply.SendError("Invalid or missing args"); | 2147 reply.SendError("Invalid or missing args"); |
| 2148 return; | 2148 return; |
| 2149 } | 2149 } |
| 2150 | 2150 |
| 2151 WebContents* web_contents = | 2151 WebContents* web_contents = |
| 2152 browser->tab_strip_model()->GetWebContentsAt(tab_index); | 2152 browser->tab_strip_model()->GetWebContentsAt(tab_index); |
| 2153 if (!web_contents) { | 2153 if (!web_contents) { |
| 2154 reply.SendError(StringPrintf("No such tab at index %d", tab_index)); | 2154 reply.SendError(base::StringPrintf("No such tab at index %d", tab_index)); |
| 2155 return; | 2155 return; |
| 2156 } | 2156 } |
| 2157 InfoBarService* infobar_service = | 2157 InfoBarService* infobar_service = |
| 2158 InfoBarService::FromWebContents(web_contents); | 2158 InfoBarService::FromWebContents(web_contents); |
| 2159 | 2159 |
| 2160 InfoBarDelegate* infobar = NULL; | 2160 InfoBarDelegate* infobar = NULL; |
| 2161 size_t infobar_index = static_cast<size_t>(infobar_index_int); | 2161 size_t infobar_index = static_cast<size_t>(infobar_index_int); |
| 2162 if (infobar_index >= infobar_service->GetInfoBarCount()) { | 2162 if (infobar_index >= infobar_service->GetInfoBarCount()) { |
| 2163 reply.SendError(StringPrintf("No such infobar at index %" PRIuS, | 2163 reply.SendError(base::StringPrintf("No such infobar at index %" PRIuS, |
| 2164 infobar_index)); | 2164 infobar_index)); |
| 2165 return; | 2165 return; |
| 2166 } | 2166 } |
| 2167 infobar = infobar_service->GetInfoBarDelegateAt(infobar_index); | 2167 infobar = infobar_service->GetInfoBarDelegateAt(infobar_index); |
| 2168 | 2168 |
| 2169 if ("dismiss" == action) { | 2169 if ("dismiss" == action) { |
| 2170 infobar->InfoBarDismissed(); | 2170 infobar->InfoBarDismissed(); |
| 2171 infobar_service->RemoveInfoBar(infobar); | 2171 infobar_service->RemoveInfoBar(infobar); |
| 2172 reply.SendSuccess(NULL); | 2172 reply.SendSuccess(NULL); |
| 2173 return; | 2173 return; |
| 2174 } | 2174 } |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2553 } | 2553 } |
| 2554 | 2554 |
| 2555 void TestingAutomationProvider::WaitForAllDownloadsToComplete( | 2555 void TestingAutomationProvider::WaitForAllDownloadsToComplete( |
| 2556 Browser* browser, | 2556 Browser* browser, |
| 2557 DictionaryValue* args, | 2557 DictionaryValue* args, |
| 2558 IPC::Message* reply_message) { | 2558 IPC::Message* reply_message) { |
| 2559 ListValue* pre_download_ids = NULL; | 2559 ListValue* pre_download_ids = NULL; |
| 2560 | 2560 |
| 2561 if (!args->GetList("pre_download_ids", &pre_download_ids)) { | 2561 if (!args->GetList("pre_download_ids", &pre_download_ids)) { |
| 2562 AutomationJSONReply(this, reply_message) | 2562 AutomationJSONReply(this, reply_message) |
| 2563 .SendError(StringPrintf("List of IDs of previous downloads required.")); | 2563 .SendError( |
| 2564 base::StringPrintf("List of IDs of previous downloads required.")); |
| 2564 return; | 2565 return; |
| 2565 } | 2566 } |
| 2566 | 2567 |
| 2567 DownloadService* download_service = | 2568 DownloadService* download_service = |
| 2568 DownloadServiceFactory::GetForProfile(browser->profile()); | 2569 DownloadServiceFactory::GetForProfile(browser->profile()); |
| 2569 if (!download_service->HasCreatedDownloadManager()) { | 2570 if (!download_service->HasCreatedDownloadManager()) { |
| 2570 // No download manager, so no downloads to wait for. | 2571 // No download manager, so no downloads to wait for. |
| 2571 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 2572 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 2572 return; | 2573 return; |
| 2573 } | 2574 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2598 AutomationJSONReply(this, reply_message) | 2599 AutomationJSONReply(this, reply_message) |
| 2599 .SendError("Must include int id and string action."); | 2600 .SendError("Must include int id and string action."); |
| 2600 return; | 2601 return; |
| 2601 } | 2602 } |
| 2602 | 2603 |
| 2603 DownloadManager* download_manager = | 2604 DownloadManager* download_manager = |
| 2604 BrowserContext::GetDownloadManager(browser->profile()); | 2605 BrowserContext::GetDownloadManager(browser->profile()); |
| 2605 DownloadItem* selected_item = download_manager->GetDownload(id); | 2606 DownloadItem* selected_item = download_manager->GetDownload(id); |
| 2606 if (!selected_item) { | 2607 if (!selected_item) { |
| 2607 AutomationJSONReply(this, reply_message) | 2608 AutomationJSONReply(this, reply_message) |
| 2608 .SendError(StringPrintf("No download with an id of %d\n", id)); | 2609 .SendError(base::StringPrintf("No download with an id of %d\n", id)); |
| 2609 return; | 2610 return; |
| 2610 } | 2611 } |
| 2611 | 2612 |
| 2612 // We need to be IN_PROGRESS for these actions. | 2613 // We need to be IN_PROGRESS for these actions. |
| 2613 if ((action == "pause" || action == "resume" || action == "cancel") && | 2614 if ((action == "pause" || action == "resume" || action == "cancel") && |
| 2614 !selected_item->IsInProgress()) { | 2615 !selected_item->IsInProgress()) { |
| 2615 AutomationJSONReply(this, reply_message) | 2616 AutomationJSONReply(this, reply_message) |
| 2616 .SendError("Selected DownloadItem is not in progress."); | 2617 .SendError("Selected DownloadItem is not in progress."); |
| 2617 } | 2618 } |
| 2618 | 2619 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2673 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( | 2674 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( |
| 2674 this, reply_message, false, browser->profile()->IsOffTheRecord())); | 2675 this, reply_message, false, browser->profile()->IsOffTheRecord())); |
| 2675 selected_item->Resume(); | 2676 selected_item->Resume(); |
| 2676 } | 2677 } |
| 2677 } else if (action == "cancel") { | 2678 } else if (action == "cancel") { |
| 2678 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( | 2679 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( |
| 2679 this, reply_message, false, browser->profile()->IsOffTheRecord())); | 2680 this, reply_message, false, browser->profile()->IsOffTheRecord())); |
| 2680 selected_item->Cancel(true); | 2681 selected_item->Cancel(true); |
| 2681 } else { | 2682 } else { |
| 2682 AutomationJSONReply(this, reply_message) | 2683 AutomationJSONReply(this, reply_message) |
| 2683 .SendError(StringPrintf("Invalid action '%s' given.", action.c_str())); | 2684 .SendError( |
| 2685 base::StringPrintf("Invalid action '%s' given.", action.c_str())); |
| 2684 } | 2686 } |
| 2685 } | 2687 } |
| 2686 | 2688 |
| 2687 void TestingAutomationProvider::SetDownloadShelfVisibleJSON( | 2689 void TestingAutomationProvider::SetDownloadShelfVisibleJSON( |
| 2688 DictionaryValue* args, | 2690 DictionaryValue* args, |
| 2689 IPC::Message* reply_message) { | 2691 IPC::Message* reply_message) { |
| 2690 AutomationJSONReply reply(this, reply_message); | 2692 AutomationJSONReply reply(this, reply_message); |
| 2691 Browser* browser; | 2693 Browser* browser; |
| 2692 std::string error_msg; | 2694 std::string error_msg; |
| 2693 bool is_visible; | 2695 bool is_visible; |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3450 std::string* error_message) { | 3452 std::string* error_message) { |
| 3451 int tab_index; | 3453 int tab_index; |
| 3452 if (!args->GetInteger("tab_index", &tab_index)) { | 3454 if (!args->GetInteger("tab_index", &tab_index)) { |
| 3453 *error_message = "Must include tab_index."; | 3455 *error_message = "Must include tab_index."; |
| 3454 return NULL; | 3456 return NULL; |
| 3455 } | 3457 } |
| 3456 | 3458 |
| 3457 WebContents* web_contents = | 3459 WebContents* web_contents = |
| 3458 browser->tab_strip_model()->GetWebContentsAt(tab_index); | 3460 browser->tab_strip_model()->GetWebContentsAt(tab_index); |
| 3459 if (!web_contents) { | 3461 if (!web_contents) { |
| 3460 *error_message = StringPrintf("No tab at index %d.", tab_index); | 3462 *error_message = base::StringPrintf("No tab at index %d.", tab_index); |
| 3461 return NULL; | 3463 return NULL; |
| 3462 } | 3464 } |
| 3463 return web_contents; | 3465 return web_contents; |
| 3464 } | 3466 } |
| 3465 | 3467 |
| 3466 } // namespace | 3468 } // namespace |
| 3467 | 3469 |
| 3468 void TestingAutomationProvider::FindInPage( | 3470 void TestingAutomationProvider::FindInPage( |
| 3469 Browser* browser, | 3471 Browser* browser, |
| 3470 DictionaryValue* args, | 3472 DictionaryValue* args, |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3897 for (int i = 0; i < num_browser_actions; ++i) { | 3899 for (int i = 0; i < num_browser_actions; ++i) { |
| 3898 if (extension->id() == browser_actions.GetExtensionId(i)) { | 3900 if (extension->id() == browser_actions.GetExtensionId(i)) { |
| 3899 action_index = i; | 3901 action_index = i; |
| 3900 break; | 3902 break; |
| 3901 } | 3903 } |
| 3902 } | 3904 } |
| 3903 #else | 3905 #else |
| 3904 // TODO(kkania): Implement the platform-specific GetExtensionId() in | 3906 // TODO(kkania): Implement the platform-specific GetExtensionId() in |
| 3905 // BrowserActionTestUtil. | 3907 // BrowserActionTestUtil. |
| 3906 if (num_browser_actions != 1) { | 3908 if (num_browser_actions != 1) { |
| 3907 AutomationJSONReply(this, reply_message).SendError(StringPrintf( | 3909 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( |
| 3908 "Found %d browser actions. Only one browser action must be active.", | 3910 "Found %d browser actions. Only one browser action must be active.", |
| 3909 num_browser_actions)); | 3911 num_browser_actions)); |
| 3910 return; | 3912 return; |
| 3911 } | 3913 } |
| 3912 // This extension has a browser action, and there's only one action, so this | 3914 // This extension has a browser action, and there's only one action, so this |
| 3913 // must be the first one. | 3915 // must be the first one. |
| 3914 action_index = 0; | 3916 action_index = 0; |
| 3915 #endif | 3917 #endif |
| 3916 if (action_index == -1) { | 3918 if (action_index == -1) { |
| 3917 AutomationJSONReply(this, reply_message).SendError( | 3919 AutomationJSONReply(this, reply_message).SendError( |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4143 .SendError("'index' missing or invalid."); | 4145 .SendError("'index' missing or invalid."); |
| 4144 return; | 4146 return; |
| 4145 } | 4147 } |
| 4146 BalloonNotificationUIManager* manager = | 4148 BalloonNotificationUIManager* manager = |
| 4147 BalloonNotificationUIManager::GetInstanceForTesting(); | 4149 BalloonNotificationUIManager::GetInstanceForTesting(); |
| 4148 BalloonCollection* collection = manager->balloon_collection(); | 4150 BalloonCollection* collection = manager->balloon_collection(); |
| 4149 const BalloonCollection::Balloons& balloons = collection->GetActiveBalloons(); | 4151 const BalloonCollection::Balloons& balloons = collection->GetActiveBalloons(); |
| 4150 int balloon_count = static_cast<int>(balloons.size()); | 4152 int balloon_count = static_cast<int>(balloons.size()); |
| 4151 if (index < 0 || index >= balloon_count) { | 4153 if (index < 0 || index >= balloon_count) { |
| 4152 AutomationJSONReply(this, reply_message) | 4154 AutomationJSONReply(this, reply_message) |
| 4153 .SendError(StringPrintf("No notification at index %d", index)); | 4155 .SendError(base::StringPrintf("No notification at index %d", index)); |
| 4154 return; | 4156 return; |
| 4155 } | 4157 } |
| 4156 std::vector<const Notification*> queued_notes; | 4158 std::vector<const Notification*> queued_notes; |
| 4157 manager->GetQueuedNotificationsForTesting(&queued_notes); | 4159 manager->GetQueuedNotificationsForTesting(&queued_notes); |
| 4158 if (queued_notes.empty()) { | 4160 if (queued_notes.empty()) { |
| 4159 new OnNotificationBalloonCountObserver( | 4161 new OnNotificationBalloonCountObserver( |
| 4160 this, reply_message, balloon_count - 1); | 4162 this, reply_message, balloon_count - 1); |
| 4161 } else { | 4163 } else { |
| 4162 new NewNotificationBalloonObserver(this, reply_message); | 4164 new NewNotificationBalloonObserver(this, reply_message); |
| 4163 } | 4165 } |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4593 if (!service) { | 4595 if (!service) { |
| 4594 AutomationJSONReply(this, reply_message).SendError( | 4596 AutomationJSONReply(this, reply_message).SendError( |
| 4595 "No extensions service."); | 4597 "No extensions service."); |
| 4596 return; | 4598 return; |
| 4597 } | 4599 } |
| 4598 | 4600 |
| 4599 const Extension* extension = service->GetExtensionById( | 4601 const Extension* extension = service->GetExtensionById( |
| 4600 id, false /* do not include disabled extensions */); | 4602 id, false /* do not include disabled extensions */); |
| 4601 if (!extension) { | 4603 if (!extension) { |
| 4602 AutomationJSONReply(this, reply_message).SendError( | 4604 AutomationJSONReply(this, reply_message).SendError( |
| 4603 StringPrintf("Extension with ID '%s' doesn't exist or is disabled.", | 4605 base::StringPrintf( |
| 4604 id.c_str())); | 4606 "Extension with ID '%s' doesn't exist or is disabled.", |
| 4607 id.c_str())); |
| 4605 return; | 4608 return; |
| 4606 } | 4609 } |
| 4607 | 4610 |
| 4608 WebContents* old_contents = | 4611 WebContents* old_contents = |
| 4609 browser->tab_strip_model()->GetActiveWebContents(); | 4612 browser->tab_strip_model()->GetActiveWebContents(); |
| 4610 if (!old_contents) { | 4613 if (!old_contents) { |
| 4611 AutomationJSONReply(this, reply_message).SendError( | 4614 AutomationJSONReply(this, reply_message).SendError( |
| 4612 "Cannot identify selected tab contents."); | 4615 "Cannot identify selected tab contents."); |
| 4613 return; | 4616 return; |
| 4614 } | 4617 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 4645 ExtensionService* service = extensions::ExtensionSystem::Get( | 4648 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 4646 browser->profile())->extension_service(); | 4649 browser->profile())->extension_service(); |
| 4647 if (!service) { | 4650 if (!service) { |
| 4648 reply.SendError("No extensions service."); | 4651 reply.SendError("No extensions service."); |
| 4649 return; | 4652 return; |
| 4650 } | 4653 } |
| 4651 | 4654 |
| 4652 const Extension* extension = service->GetExtensionById( | 4655 const Extension* extension = service->GetExtensionById( |
| 4653 id, true /* include disabled extensions */); | 4656 id, true /* include disabled extensions */); |
| 4654 if (!extension) { | 4657 if (!extension) { |
| 4655 reply.SendError( | 4658 reply.SendError(base::StringPrintf( |
| 4656 StringPrintf("Extension with ID '%s' doesn't exist.", id.c_str())); | 4659 "Extension with ID '%s' doesn't exist.", id.c_str())); |
| 4657 return; | 4660 return; |
| 4658 } | 4661 } |
| 4659 | 4662 |
| 4660 extensions::ExtensionPrefs::LaunchType launch_type; | 4663 extensions::ExtensionPrefs::LaunchType launch_type; |
| 4661 if (launch_type_str == "pinned") { | 4664 if (launch_type_str == "pinned") { |
| 4662 launch_type = extensions::ExtensionPrefs::LAUNCH_PINNED; | 4665 launch_type = extensions::ExtensionPrefs::LAUNCH_PINNED; |
| 4663 } else if (launch_type_str == "regular") { | 4666 } else if (launch_type_str == "regular") { |
| 4664 launch_type = extensions::ExtensionPrefs::LAUNCH_REGULAR; | 4667 launch_type = extensions::ExtensionPrefs::LAUNCH_REGULAR; |
| 4665 } else if (launch_type_str == "fullscreen") { | 4668 } else if (launch_type_str == "fullscreen") { |
| 4666 launch_type = extensions::ExtensionPrefs::LAUNCH_FULLSCREEN; | 4669 launch_type = extensions::ExtensionPrefs::LAUNCH_FULLSCREEN; |
| 4667 } else if (launch_type_str == "window") { | 4670 } else if (launch_type_str == "window") { |
| 4668 launch_type = extensions::ExtensionPrefs::LAUNCH_WINDOW; | 4671 launch_type = extensions::ExtensionPrefs::LAUNCH_WINDOW; |
| 4669 } else { | 4672 } else { |
| 4670 reply.SendError( | 4673 reply.SendError(base::StringPrintf( |
| 4671 StringPrintf("Unexpected launch type '%s'.", launch_type_str.c_str())); | 4674 "Unexpected launch type '%s'.", launch_type_str.c_str())); |
| 4672 return; | 4675 return; |
| 4673 } | 4676 } |
| 4674 | 4677 |
| 4675 service->extension_prefs()->SetLaunchType(extension->id(), launch_type); | 4678 service->extension_prefs()->SetLaunchType(extension->id(), launch_type); |
| 4676 reply.SendSuccess(NULL); | 4679 reply.SendSuccess(NULL); |
| 4677 } | 4680 } |
| 4678 | 4681 |
| 4679 // Sample json input: { "command": "GetV8HeapStats", | 4682 // Sample json input: { "command": "GetV8HeapStats", |
| 4680 // "tab_index": 0 } | 4683 // "tab_index": 0 } |
| 4681 // Refer to GetV8HeapStats() in chrome/test/pyautolib/pyauto.py for | 4684 // Refer to GetV8HeapStats() in chrome/test/pyautolib/pyauto.py for |
| 4682 // sample json output. | 4685 // sample json output. |
| 4683 void TestingAutomationProvider::GetV8HeapStats( | 4686 void TestingAutomationProvider::GetV8HeapStats( |
| 4684 Browser* browser, | 4687 Browser* browser, |
| 4685 DictionaryValue* args, | 4688 DictionaryValue* args, |
| 4686 IPC::Message* reply_message) { | 4689 IPC::Message* reply_message) { |
| 4687 WebContents* web_contents; | 4690 WebContents* web_contents; |
| 4688 int tab_index; | 4691 int tab_index; |
| 4689 std::string error; | 4692 std::string error; |
| 4690 | 4693 |
| 4691 if (!args->GetInteger("tab_index", &tab_index)) { | 4694 if (!args->GetInteger("tab_index", &tab_index)) { |
| 4692 AutomationJSONReply(this, reply_message).SendError( | 4695 AutomationJSONReply(this, reply_message).SendError( |
| 4693 "Missing 'tab_index' argument."); | 4696 "Missing 'tab_index' argument."); |
| 4694 return; | 4697 return; |
| 4695 } | 4698 } |
| 4696 | 4699 |
| 4697 web_contents = browser->tab_strip_model()->GetWebContentsAt(tab_index); | 4700 web_contents = browser->tab_strip_model()->GetWebContentsAt(tab_index); |
| 4698 if (!web_contents) { | 4701 if (!web_contents) { |
| 4699 AutomationJSONReply(this, reply_message).SendError( | 4702 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( |
| 4700 StringPrintf("Could not get WebContents at tab index %d", tab_index)); | 4703 "Could not get WebContents at tab index %d", tab_index)); |
| 4701 return; | 4704 return; |
| 4702 } | 4705 } |
| 4703 | 4706 |
| 4704 RenderViewHost* render_view = web_contents->GetRenderViewHost(); | 4707 RenderViewHost* render_view = web_contents->GetRenderViewHost(); |
| 4705 | 4708 |
| 4706 // This observer will delete itself. | 4709 // This observer will delete itself. |
| 4707 new V8HeapStatsObserver( | 4710 new V8HeapStatsObserver( |
| 4708 this, reply_message, | 4711 this, reply_message, |
| 4709 base::GetProcId(render_view->GetProcess()->GetHandle())); | 4712 base::GetProcId(render_view->GetProcess()->GetHandle())); |
| 4710 render_view->Send(new ChromeViewMsg_GetV8HeapStats); | 4713 render_view->Send(new ChromeViewMsg_GetV8HeapStats); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4723 std::string error; | 4726 std::string error; |
| 4724 | 4727 |
| 4725 if (!args->GetInteger("tab_index", &tab_index)) { | 4728 if (!args->GetInteger("tab_index", &tab_index)) { |
| 4726 AutomationJSONReply(this, reply_message).SendError( | 4729 AutomationJSONReply(this, reply_message).SendError( |
| 4727 "Missing 'tab_index' argument."); | 4730 "Missing 'tab_index' argument."); |
| 4728 return; | 4731 return; |
| 4729 } | 4732 } |
| 4730 | 4733 |
| 4731 web_contents = browser->tab_strip_model()->GetWebContentsAt(tab_index); | 4734 web_contents = browser->tab_strip_model()->GetWebContentsAt(tab_index); |
| 4732 if (!web_contents) { | 4735 if (!web_contents) { |
| 4733 AutomationJSONReply(this, reply_message).SendError( | 4736 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( |
| 4734 StringPrintf("Could not get WebContents at tab index %d", tab_index)); | 4737 "Could not get WebContents at tab index %d", tab_index)); |
| 4735 return; | 4738 return; |
| 4736 } | 4739 } |
| 4737 | 4740 |
| 4738 RenderViewHost* render_view = web_contents->GetRenderViewHost(); | 4741 RenderViewHost* render_view = web_contents->GetRenderViewHost(); |
| 4739 int routing_id = render_view->GetRoutingID(); | 4742 int routing_id = render_view->GetRoutingID(); |
| 4740 | 4743 |
| 4741 // This observer will delete itself. | 4744 // This observer will delete itself. |
| 4742 new FPSObserver( | 4745 new FPSObserver( |
| 4743 this, reply_message, | 4746 this, reply_message, |
| 4744 base::GetProcId(render_view->GetProcess()->GetHandle()), | 4747 base::GetProcId(render_view->GetProcess()->GetHandle()), |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5255 std::string error; | 5258 std::string error; |
| 5256 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | 5259 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { |
| 5257 reply.SendError(error); | 5260 reply.SendError(error); |
| 5258 return; | 5261 return; |
| 5259 } | 5262 } |
| 5260 if (!args->GetInteger("accelerator", &command)) { | 5263 if (!args->GetInteger("accelerator", &command)) { |
| 5261 reply.SendError("'accelerator' missing or invalid."); | 5264 reply.SendError("'accelerator' missing or invalid."); |
| 5262 return; | 5265 return; |
| 5263 } | 5266 } |
| 5264 if (!chrome::SupportsCommand(browser, command)) { | 5267 if (!chrome::SupportsCommand(browser, command)) { |
| 5265 reply.SendError(StringPrintf("Browser does not support command=%d.", | 5268 reply.SendError(base::StringPrintf("Browser does not support command=%d.", |
| 5266 command)); | 5269 command)); |
| 5267 return; | 5270 return; |
| 5268 } | 5271 } |
| 5269 if (!chrome::IsCommandEnabled(browser, command)) { | 5272 if (!chrome::IsCommandEnabled(browser, command)) { |
| 5270 reply.SendError(StringPrintf("Browser command=%d not enabled.", command)); | 5273 reply.SendError(base::StringPrintf( |
| 5274 "Browser command=%d not enabled.", command)); |
| 5271 return; | 5275 return; |
| 5272 } | 5276 } |
| 5273 chrome::ExecuteCommand(browser, command); | 5277 chrome::ExecuteCommand(browser, command); |
| 5274 reply.SendSuccess(NULL); | 5278 reply.SendSuccess(NULL); |
| 5275 } | 5279 } |
| 5276 | 5280 |
| 5277 void TestingAutomationProvider::ExecuteBrowserCommandJSON( | 5281 void TestingAutomationProvider::ExecuteBrowserCommandJSON( |
| 5278 DictionaryValue* args, | 5282 DictionaryValue* args, |
| 5279 IPC::Message* reply_message) { | 5283 IPC::Message* reply_message) { |
| 5280 int command; | 5284 int command; |
| 5281 Browser* browser; | 5285 Browser* browser; |
| 5282 std::string error; | 5286 std::string error; |
| 5283 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | 5287 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { |
| 5284 AutomationJSONReply(this, reply_message).SendError(error); | 5288 AutomationJSONReply(this, reply_message).SendError(error); |
| 5285 return; | 5289 return; |
| 5286 } | 5290 } |
| 5287 if (!args->GetInteger("accelerator", &command)) { | 5291 if (!args->GetInteger("accelerator", &command)) { |
| 5288 AutomationJSONReply(this, reply_message).SendError( | 5292 AutomationJSONReply(this, reply_message).SendError( |
| 5289 "'accelerator' missing or invalid."); | 5293 "'accelerator' missing or invalid."); |
| 5290 return; | 5294 return; |
| 5291 } | 5295 } |
| 5292 if (!chrome::SupportsCommand(browser, command)) { | 5296 if (!chrome::SupportsCommand(browser, command)) { |
| 5293 AutomationJSONReply(this, reply_message).SendError( | 5297 AutomationJSONReply(this, reply_message).SendError( |
| 5294 StringPrintf("Browser does not support command=%d.", command)); | 5298 base::StringPrintf("Browser does not support command=%d.", command)); |
| 5295 return; | 5299 return; |
| 5296 } | 5300 } |
| 5297 if (!chrome::IsCommandEnabled(browser, command)) { | 5301 if (!chrome::IsCommandEnabled(browser, command)) { |
| 5298 AutomationJSONReply(this, reply_message).SendError( | 5302 AutomationJSONReply(this, reply_message).SendError( |
| 5299 StringPrintf("Browser command=%d not enabled.", command)); | 5303 base::StringPrintf("Browser command=%d not enabled.", command)); |
| 5300 return; | 5304 return; |
| 5301 } | 5305 } |
| 5302 // First check if we can handle the command without using an observer. | 5306 // First check if we can handle the command without using an observer. |
| 5303 for (size_t i = 0; i < arraysize(kSynchronousCommands); i++) { | 5307 for (size_t i = 0; i < arraysize(kSynchronousCommands); i++) { |
| 5304 if (command == kSynchronousCommands[i]) { | 5308 if (command == kSynchronousCommands[i]) { |
| 5305 chrome::ExecuteCommand(browser, command); | 5309 chrome::ExecuteCommand(browser, command); |
| 5306 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 5310 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 5307 return; | 5311 return; |
| 5308 } | 5312 } |
| 5309 } | 5313 } |
| 5310 // Use an observer if we have one, otherwise fail. | 5314 // Use an observer if we have one, otherwise fail. |
| 5311 if (ExecuteBrowserCommandObserver::CreateAndRegisterObserver( | 5315 if (ExecuteBrowserCommandObserver::CreateAndRegisterObserver( |
| 5312 this, browser, command, reply_message, true)) { | 5316 this, browser, command, reply_message, true)) { |
| 5313 chrome::ExecuteCommand(browser, command); | 5317 chrome::ExecuteCommand(browser, command); |
| 5314 return; | 5318 return; |
| 5315 } | 5319 } |
| 5316 AutomationJSONReply(this, reply_message).SendError( | 5320 AutomationJSONReply(this, reply_message).SendError(base::StringPrintf( |
| 5317 StringPrintf("Unable to register observer for browser command=%d.", | 5321 "Unable to register observer for browser command=%d.", command)); |
| 5318 command)); | |
| 5319 } | 5322 } |
| 5320 | 5323 |
| 5321 void TestingAutomationProvider::IsMenuCommandEnabledJSON( | 5324 void TestingAutomationProvider::IsMenuCommandEnabledJSON( |
| 5322 DictionaryValue* args, | 5325 DictionaryValue* args, |
| 5323 IPC::Message* reply_message) { | 5326 IPC::Message* reply_message) { |
| 5324 int command; | 5327 int command; |
| 5325 Browser* browser; | 5328 Browser* browser; |
| 5326 std::string error; | 5329 std::string error; |
| 5327 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { | 5330 if (!GetBrowserFromJSONArgs(args, &browser, &error)) { |
| 5328 AutomationJSONReply(this, reply_message).SendError(error); | 5331 AutomationJSONReply(this, reply_message).SendError(error); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5487 return; | 5490 return; |
| 5488 } | 5491 } |
| 5489 GURL url(url_string); | 5492 GURL url(url_string); |
| 5490 if (!url.is_valid()) { | 5493 if (!url.is_valid()) { |
| 5491 reply.SendError("Invalid url."); | 5494 reply.SendError("Invalid url."); |
| 5492 return; | 5495 return; |
| 5493 } | 5496 } |
| 5494 automation_util::GetCookies(url, web_contents, &value_size, &value); | 5497 automation_util::GetCookies(url, web_contents, &value_size, &value); |
| 5495 if (value_size == -1) { | 5498 if (value_size == -1) { |
| 5496 reply.SendError( | 5499 reply.SendError( |
| 5497 StringPrintf("Unable to retrieve cookies for url=%s.", | 5500 base::StringPrintf("Unable to retrieve cookies for url=%s.", |
| 5498 url_string.c_str())); | 5501 url_string.c_str())); |
| 5499 return; | 5502 return; |
| 5500 } | 5503 } |
| 5501 DictionaryValue dict; | 5504 DictionaryValue dict; |
| 5502 dict.SetString("cookies", value); | 5505 dict.SetString("cookies", value); |
| 5503 reply.SendSuccess(&dict); | 5506 reply.SendSuccess(&dict); |
| 5504 } | 5507 } |
| 5505 | 5508 |
| 5506 void TestingAutomationProvider::DeleteCookieInBrowserContext( | 5509 void TestingAutomationProvider::DeleteCookieInBrowserContext( |
| 5507 DictionaryValue* args, | 5510 DictionaryValue* args, |
| 5508 IPC::Message* reply_message) { | 5511 IPC::Message* reply_message) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 5529 return; | 5532 return; |
| 5530 } | 5533 } |
| 5531 GURL url(url_string); | 5534 GURL url(url_string); |
| 5532 if (!url.is_valid()) { | 5535 if (!url.is_valid()) { |
| 5533 reply.SendError("Invalid url."); | 5536 reply.SendError("Invalid url."); |
| 5534 return; | 5537 return; |
| 5535 } | 5538 } |
| 5536 automation_util::DeleteCookie(url, cookie_name, web_contents, &success); | 5539 automation_util::DeleteCookie(url, cookie_name, web_contents, &success); |
| 5537 if (!success) { | 5540 if (!success) { |
| 5538 reply.SendError( | 5541 reply.SendError( |
| 5539 StringPrintf("Failed to delete cookie with name=%s for url=%s.", | 5542 base::StringPrintf("Failed to delete cookie with name=%s for url=%s.", |
| 5540 cookie_name.c_str(), url_string.c_str())); | 5543 cookie_name.c_str(), url_string.c_str())); |
| 5541 return; | 5544 return; |
| 5542 } | 5545 } |
| 5543 reply.SendSuccess(NULL); | 5546 reply.SendSuccess(NULL); |
| 5544 } | 5547 } |
| 5545 | 5548 |
| 5546 void TestingAutomationProvider::SetCookieInBrowserContext( | 5549 void TestingAutomationProvider::SetCookieInBrowserContext( |
| 5547 DictionaryValue* args, | 5550 DictionaryValue* args, |
| 5548 IPC::Message* reply_message) { | 5551 IPC::Message* reply_message) { |
| 5549 AutomationJSONReply reply(this, reply_message); | 5552 AutomationJSONReply reply(this, reply_message); |
| 5550 WebContents* web_contents; | 5553 WebContents* web_contents; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 5567 reply.SendError("'url' missing or invalid."); | 5570 reply.SendError("'url' missing or invalid."); |
| 5568 return; | 5571 return; |
| 5569 } | 5572 } |
| 5570 GURL url(url_string); | 5573 GURL url(url_string); |
| 5571 if (!url.is_valid()) { | 5574 if (!url.is_valid()) { |
| 5572 reply.SendError("Invalid url."); | 5575 reply.SendError("Invalid url."); |
| 5573 return; | 5576 return; |
| 5574 } | 5577 } |
| 5575 automation_util::SetCookie(url, value, web_contents, &response_value); | 5578 automation_util::SetCookie(url, value, web_contents, &response_value); |
| 5576 if (response_value != 1) { | 5579 if (response_value != 1) { |
| 5577 reply.SendError( | 5580 reply.SendError(base::StringPrintf( |
| 5578 StringPrintf("Unable set cookie for url=%s.", url_string.c_str())); | 5581 "Unable set cookie for url=%s.", url_string.c_str())); |
| 5579 return; | 5582 return; |
| 5580 } | 5583 } |
| 5581 reply.SendSuccess(NULL); | 5584 reply.SendSuccess(NULL); |
| 5582 } | 5585 } |
| 5583 | 5586 |
| 5584 void TestingAutomationProvider::GetTabIds( | 5587 void TestingAutomationProvider::GetTabIds( |
| 5585 DictionaryValue* args, IPC::Message* reply_message) { | 5588 DictionaryValue* args, IPC::Message* reply_message) { |
| 5586 ListValue* id_list = new ListValue(); | 5589 ListValue* id_list = new ListValue(); |
| 5587 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 5590 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| 5588 Browser* browser = *it; | 5591 Browser* browser = *it; |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5915 if (g_browser_process) | 5918 if (g_browser_process) |
| 5916 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 5919 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
| 5917 } | 5920 } |
| 5918 | 5921 |
| 5919 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 5922 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
| 5920 WebContents* tab) { | 5923 WebContents* tab) { |
| 5921 TabStripModel* tab_strip = browser->tab_strip_model(); | 5924 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 5922 if (tab_strip->GetActiveWebContents() != tab) | 5925 if (tab_strip->GetActiveWebContents() != tab) |
| 5923 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); | 5926 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); |
| 5924 } | 5927 } |
| OLD | NEW |