Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1516)

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 10872034: Changing PluginPrefs to use PluginFinder's async interface. (Closed) Base URL: http://git.chromium.org/chromium/src.git@test_async
Patch Set: "Fixed review comments and added support for other methods in PluginPrefs to use async interface" Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/plugin_prefs.h » ('j') | chrome/browser/plugin_prefs.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 199
200 namespace { 200 namespace {
201 201
202 // Helper to reply asynchronously if |automation| is still valid. 202 // Helper to reply asynchronously if |automation| is still valid.
203 void SendSuccessReply(base::WeakPtr<AutomationProvider> automation, 203 void SendSuccessReply(base::WeakPtr<AutomationProvider> automation,
204 IPC::Message* reply_message) { 204 IPC::Message* reply_message) {
205 if (automation) 205 if (automation)
206 AutomationJSONReply(automation.get(), reply_message).SendSuccess(NULL); 206 AutomationJSONReply(automation.get(), reply_message).SendSuccess(NULL);
207 } 207 }
208 208
209 // Helper to process the result of CanEnablePlugin.
210 void CanEnablePluginCallback(base::WeakPtr<AutomationProvider> automation,
211 IPC::Message* reply_message,
212 const FilePath::StringType& path,
213 const std::string& error_msg,
214 bool can_enable) {
215 if (!can_enable) {
216 if (automation) {
217 AutomationJSONReply(automation.get(), reply_message).SendError(
218 StringPrintf(error_msg.c_str(), path.c_str()));
219 }
220 }
221 }
222
209 // Helper to resolve the overloading of PostTask. 223 // Helper to resolve the overloading of PostTask.
210 void PostTask(BrowserThread::ID id, const base::Closure& callback) { 224 void PostTask(BrowserThread::ID id, const base::Closure& callback) {
211 BrowserThread::PostTask(id, FROM_HERE, callback); 225 BrowserThread::PostTask(id, FROM_HERE, callback);
212 } 226 }
213 227
214 void SendMouseClick(int flags) { 228 void SendMouseClick(int flags) {
215 ui_controls::MouseButton button = ui_controls::LEFT; 229 ui_controls::MouseButton button = ui_controls::LEFT;
216 if ((flags & ui::EF_LEFT_MOUSE_BUTTON) == 230 if ((flags & ui::EF_LEFT_MOUSE_BUTTON) ==
217 ui::EF_LEFT_MOUSE_BUTTON) { 231 ui::EF_LEFT_MOUSE_BUTTON) {
218 button = ui_controls::LEFT; 232 button = ui_controls::LEFT;
(...skipping 3159 matching lines...) Expand 10 before | Expand all | Expand 10 after
3378 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } 3392 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" }
3379 void TestingAutomationProvider::EnablePlugin(Browser* browser, 3393 void TestingAutomationProvider::EnablePlugin(Browser* browser,
3380 DictionaryValue* args, 3394 DictionaryValue* args,
3381 IPC::Message* reply_message) { 3395 IPC::Message* reply_message) {
3382 FilePath::StringType path; 3396 FilePath::StringType path;
3383 if (!args->GetString("path", &path)) { 3397 if (!args->GetString("path", &path)) {
3384 AutomationJSONReply(this, reply_message).SendError("path not specified."); 3398 AutomationJSONReply(this, reply_message).SendError("path not specified.");
3385 return; 3399 return;
3386 } 3400 }
3387 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); 3401 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile());
3388 if (!plugin_prefs->CanEnablePlugin(true, FilePath(path))) { 3402 plugin_prefs->EnablePlugin(true, FilePath(path),
3389 AutomationJSONReply(this, reply_message).SendError( 3403 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message),
3390 StringPrintf("Could not enable plugin for path %s.", path.c_str())); 3404 base::Bind(&CanEnablePluginCallback, AsWeakPtr(), reply_message,
3391 return; 3405 path, "Could not enable plugin for path %s."));
3392 }
3393 plugin_prefs->EnablePlugin(
3394 true, FilePath(path),
3395 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message));
3396 } 3406 }
3397 3407
3398 // Sample json input: 3408 // Sample json input:
3399 // { "command": "DisablePlugin", 3409 // { "command": "DisablePlugin",
3400 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } 3410 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" }
3401 void TestingAutomationProvider::DisablePlugin(Browser* browser, 3411 void TestingAutomationProvider::DisablePlugin(Browser* browser,
3402 DictionaryValue* args, 3412 DictionaryValue* args,
3403 IPC::Message* reply_message) { 3413 IPC::Message* reply_message) {
3404 FilePath::StringType path; 3414 FilePath::StringType path;
3405 if (!args->GetString("path", &path)) { 3415 if (!args->GetString("path", &path)) {
3406 AutomationJSONReply(this, reply_message).SendError("path not specified."); 3416 AutomationJSONReply(this, reply_message).SendError("path not specified.");
3407 return; 3417 return;
3408 } 3418 }
3409 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); 3419 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile());
3410 if (!plugin_prefs->CanEnablePlugin(false, FilePath(path))) { 3420 plugin_prefs->EnablePlugin(false, FilePath(path),
3411 AutomationJSONReply(this, reply_message).SendError( 3421 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message),
3412 StringPrintf("Could not disable plugin for path %s.", path.c_str())); 3422 base::Bind(&CanEnablePluginCallback, AsWeakPtr(), reply_message,
3413 return; 3423 path, "Could not disable plugin for path %s."));
3414 }
3415 plugin_prefs->EnablePlugin(
3416 false, FilePath(path),
3417 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message));
3418 } 3424 }
3419 3425
3420 // Sample json input: 3426 // Sample json input:
3421 // { "command": "SaveTabContents", 3427 // { "command": "SaveTabContents",
3422 // "tab_index": 0, 3428 // "tab_index": 0,
3423 // "filename": <a full pathname> } 3429 // "filename": <a full pathname> }
3424 // Sample json output: 3430 // Sample json output:
3425 // {} 3431 // {}
3426 void TestingAutomationProvider::SaveTabContents( 3432 void TestingAutomationProvider::SaveTabContents(
3427 Browser* browser, 3433 Browser* browser,
(...skipping 3308 matching lines...) Expand 10 before | Expand all | Expand 10 after
6736 void TestingAutomationProvider::OnRemoveProvider() { 6742 void TestingAutomationProvider::OnRemoveProvider() {
6737 if (g_browser_process) 6743 if (g_browser_process)
6738 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 6744 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6739 } 6745 }
6740 6746
6741 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, 6747 void TestingAutomationProvider::EnsureTabSelected(Browser* browser,
6742 WebContents* tab) { 6748 WebContents* tab) {
6743 if (chrome::GetActiveWebContents(browser) != tab) 6749 if (chrome::GetActiveWebContents(browser) != tab)
6744 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); 6750 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true);
6745 } 6751 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/plugin_prefs.h » ('j') | chrome/browser/plugin_prefs.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698