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

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 bauerb's More Nits Created 8 years, 3 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
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 DidEnablePlugin(base::WeakPtr<AutomationProvider> automation,
211 IPC::Message* reply_message,
212 const FilePath::StringType& path,
213 const std::string& error_msg,
214 bool can_enable) {
Bernhard Bauer 2012/09/03 08:57:12 Nit: |did_enable| :)
ibraaaa 2012/09/03 09:10:28 Done.
215 if (can_enable) {
216 SendSuccessReply(automation, reply_message);
217 } else {
218 if (automation) {
219 AutomationJSONReply(automation.get(), reply_message).SendError(
220 StringPrintf(error_msg.c_str(), path.c_str()));
221 }
222 }
223 }
224
209 // Helper to resolve the overloading of PostTask. 225 // Helper to resolve the overloading of PostTask.
210 void PostTask(BrowserThread::ID id, const base::Closure& callback) { 226 void PostTask(BrowserThread::ID id, const base::Closure& callback) {
211 BrowserThread::PostTask(id, FROM_HERE, callback); 227 BrowserThread::PostTask(id, FROM_HERE, callback);
212 } 228 }
213 229
214 void SendMouseClick(int flags) { 230 void SendMouseClick(int flags) {
215 ui_controls::MouseButton button = ui_controls::LEFT; 231 ui_controls::MouseButton button = ui_controls::LEFT;
216 if ((flags & ui::EF_LEFT_MOUSE_BUTTON) == 232 if ((flags & ui::EF_LEFT_MOUSE_BUTTON) ==
217 ui::EF_LEFT_MOUSE_BUTTON) { 233 ui::EF_LEFT_MOUSE_BUTTON) {
218 button = ui_controls::LEFT; 234 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" } 3394 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" }
3379 void TestingAutomationProvider::EnablePlugin(Browser* browser, 3395 void TestingAutomationProvider::EnablePlugin(Browser* browser,
3380 DictionaryValue* args, 3396 DictionaryValue* args,
3381 IPC::Message* reply_message) { 3397 IPC::Message* reply_message) {
3382 FilePath::StringType path; 3398 FilePath::StringType path;
3383 if (!args->GetString("path", &path)) { 3399 if (!args->GetString("path", &path)) {
3384 AutomationJSONReply(this, reply_message).SendError("path not specified."); 3400 AutomationJSONReply(this, reply_message).SendError("path not specified.");
3385 return; 3401 return;
3386 } 3402 }
3387 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); 3403 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile());
3388 if (!plugin_prefs->CanEnablePlugin(true, FilePath(path))) { 3404 plugin_prefs->EnablePlugin(true, FilePath(path),
3389 AutomationJSONReply(this, reply_message).SendError( 3405 base::Bind(&DidEnablePlugin, AsWeakPtr(), reply_message,
3390 StringPrintf("Could not enable plugin for path %s.", path.c_str())); 3406 path, "Could not enable plugin for path %s."));
3391 return;
3392 }
3393 plugin_prefs->EnablePlugin(
3394 true, FilePath(path),
3395 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message));
3396 } 3407 }
3397 3408
3398 // Sample json input: 3409 // Sample json input:
3399 // { "command": "DisablePlugin", 3410 // { "command": "DisablePlugin",
3400 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } 3411 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" }
3401 void TestingAutomationProvider::DisablePlugin(Browser* browser, 3412 void TestingAutomationProvider::DisablePlugin(Browser* browser,
3402 DictionaryValue* args, 3413 DictionaryValue* args,
3403 IPC::Message* reply_message) { 3414 IPC::Message* reply_message) {
3404 FilePath::StringType path; 3415 FilePath::StringType path;
3405 if (!args->GetString("path", &path)) { 3416 if (!args->GetString("path", &path)) {
3406 AutomationJSONReply(this, reply_message).SendError("path not specified."); 3417 AutomationJSONReply(this, reply_message).SendError("path not specified.");
3407 return; 3418 return;
3408 } 3419 }
3409 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); 3420 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile());
3410 if (!plugin_prefs->CanEnablePlugin(false, FilePath(path))) { 3421 plugin_prefs->EnablePlugin(false, FilePath(path),
3411 AutomationJSONReply(this, reply_message).SendError( 3422 base::Bind(&DidEnablePlugin, AsWeakPtr(), reply_message,
3412 StringPrintf("Could not disable plugin for path %s.", path.c_str())); 3423 path, "Could not disable plugin for path %s."));
3413 return;
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

Powered by Google App Engine
This is Rietveld 408576698