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

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: Converted PluginPref#CanEnablePlugin to use PluginFinder's 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 bool enable,
213 const FilePath::StringType& path,
214 const std::string& error_msg,
215 scoped_refptr<PluginPrefs> prefs,
216 bool can_enable) {
217 if (!can_enable) {
218 if (automation)
Bernhard Bauer 2012/08/24 08:15:34 Nit: braces please.
ibraaaa 2012/08/24 15:51:29 Done.
219 AutomationJSONReply(automation.get(), reply_message).SendError(
220 StringPrintf(error_msg.c_str(), path.c_str()));
221 return;
222 }
223
224 prefs->EnablePlugin(enable, FilePath(path),
225 base::Bind(SendSuccessReply, automation, reply_message));
226 }
227
209 // Helper to resolve the overloading of PostTask. 228 // Helper to resolve the overloading of PostTask.
210 void PostTask(BrowserThread::ID id, const base::Closure& callback) { 229 void PostTask(BrowserThread::ID id, const base::Closure& callback) {
211 BrowserThread::PostTask(id, FROM_HERE, callback); 230 BrowserThread::PostTask(id, FROM_HERE, callback);
212 } 231 }
213 232
214 void SendMouseClick(int flags) { 233 void SendMouseClick(int flags) {
215 ui_controls::MouseButton button = ui_controls::LEFT; 234 ui_controls::MouseButton button = ui_controls::LEFT;
216 if ((flags & ui::EF_LEFT_MOUSE_BUTTON) == 235 if ((flags & ui::EF_LEFT_MOUSE_BUTTON) ==
217 ui::EF_LEFT_MOUSE_BUTTON) { 236 ui::EF_LEFT_MOUSE_BUTTON) {
218 button = ui_controls::LEFT; 237 button = ui_controls::LEFT;
(...skipping 3158 matching lines...) Expand 10 before | Expand all | Expand 10 after
3377 // { "command": "EnablePlugin", 3396 // { "command": "EnablePlugin",
3378 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } 3397 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" }
3379 void TestingAutomationProvider::EnablePlugin(Browser* browser, 3398 void TestingAutomationProvider::EnablePlugin(Browser* browser,
3380 DictionaryValue* args, 3399 DictionaryValue* args,
3381 IPC::Message* reply_message) { 3400 IPC::Message* reply_message) {
3382 FilePath::StringType path; 3401 FilePath::StringType path;
3383 if (!args->GetString("path", &path)) { 3402 if (!args->GetString("path", &path)) {
3384 AutomationJSONReply(this, reply_message).SendError("path not specified."); 3403 AutomationJSONReply(this, reply_message).SendError("path not specified.");
3385 return; 3404 return;
3386 } 3405 }
3387 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); 3406 scoped_refptr<PluginPrefs> plugin_prefs(
3388 if (!plugin_prefs->CanEnablePlugin(true, FilePath(path))) { 3407 PluginPrefs::GetForProfile(browser->profile()));
3389 AutomationJSONReply(this, reply_message).SendError( 3408 plugin_prefs->CanEnablePlugin(true, FilePath(path),
3390 StringPrintf("Could not enable plugin for path %s.", path.c_str())); 3409 base::Bind(&CanEnablePluginCallback, AsWeakPtr(), reply_message, true,
3391 return; 3410 path, "Could not enable plugin for path %s.", plugin_prefs));
3392 }
3393 plugin_prefs->EnablePlugin(
3394 true, FilePath(path),
3395 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message));
3396 } 3411 }
3397 3412
3398 // Sample json input: 3413 // Sample json input:
3399 // { "command": "DisablePlugin", 3414 // { "command": "DisablePlugin",
3400 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } 3415 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" }
3401 void TestingAutomationProvider::DisablePlugin(Browser* browser, 3416 void TestingAutomationProvider::DisablePlugin(Browser* browser,
3402 DictionaryValue* args, 3417 DictionaryValue* args,
3403 IPC::Message* reply_message) { 3418 IPC::Message* reply_message) {
3404 FilePath::StringType path; 3419 FilePath::StringType path;
3405 if (!args->GetString("path", &path)) { 3420 if (!args->GetString("path", &path)) {
3406 AutomationJSONReply(this, reply_message).SendError("path not specified."); 3421 AutomationJSONReply(this, reply_message).SendError("path not specified.");
3407 return; 3422 return;
3408 } 3423 }
3409 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); 3424 scoped_refptr<PluginPrefs> plugin_prefs(
3410 if (!plugin_prefs->CanEnablePlugin(false, FilePath(path))) { 3425 PluginPrefs::GetForProfile(browser->profile()));
3411 AutomationJSONReply(this, reply_message).SendError( 3426 plugin_prefs->CanEnablePlugin(false, FilePath(path),
3412 StringPrintf("Could not disable plugin for path %s.", path.c_str())); 3427 base::Bind(&CanEnablePluginCallback, AsWeakPtr(), reply_message, false,
3413 return; 3428 path, "Could not disable plugin for path %s.", plugin_prefs));
3414 }
3415 plugin_prefs->EnablePlugin(
3416 false, FilePath(path),
3417 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message));
3418 } 3429 }
3419 3430
3420 // Sample json input: 3431 // Sample json input:
3421 // { "command": "SaveTabContents", 3432 // { "command": "SaveTabContents",
3422 // "tab_index": 0, 3433 // "tab_index": 0,
3423 // "filename": <a full pathname> } 3434 // "filename": <a full pathname> }
3424 // Sample json output: 3435 // Sample json output:
3425 // {} 3436 // {}
3426 void TestingAutomationProvider::SaveTabContents( 3437 void TestingAutomationProvider::SaveTabContents(
3427 Browser* browser, 3438 Browser* browser,
(...skipping 3308 matching lines...) Expand 10 before | Expand all | Expand 10 after
6736 void TestingAutomationProvider::OnRemoveProvider() { 6747 void TestingAutomationProvider::OnRemoveProvider() {
6737 if (g_browser_process) 6748 if (g_browser_process)
6738 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 6749 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6739 } 6750 }
6740 6751
6741 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, 6752 void TestingAutomationProvider::EnsureTabSelected(Browser* browser,
6742 WebContents* tab) { 6753 WebContents* tab) {
6743 if (chrome::GetActiveWebContents(browser) != tab) 6754 if (chrome::GetActiveWebContents(browser) != tab)
6744 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); 6755 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true);
6745 } 6756 }
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