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 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 } | 1279 } |
1280 BookmarkModel* bookmark_model = | 1280 BookmarkModel* bookmark_model = |
1281 BookmarkModelFactory::GetForProfile(browser->profile()); | 1281 BookmarkModelFactory::GetForProfile(browser->profile()); |
1282 if (!bookmark_model->loaded()) { | 1282 if (!bookmark_model->loaded()) { |
1283 reply.SendError("Bookmark model is not loaded"); | 1283 reply.SendError("Bookmark model is not loaded"); |
1284 return; | 1284 return; |
1285 } | 1285 } |
1286 scoped_refptr<BookmarkStorage> storage( | 1286 scoped_refptr<BookmarkStorage> storage( |
1287 new BookmarkStorage(browser->profile(), | 1287 new BookmarkStorage(browser->profile(), |
1288 bookmark_model, | 1288 bookmark_model, |
1289 browser->profile()->GetIOTaskRunner())); | 1289 browser->profile()->GetIOTaskRunner().get())); |
1290 if (!storage->SerializeData(&bookmarks_as_json)) { | 1290 if (!storage->SerializeData(&bookmarks_as_json)) { |
1291 reply.SendError("Failed to serialize bookmarks"); | 1291 reply.SendError("Failed to serialize bookmarks"); |
1292 return; | 1292 return; |
1293 } | 1293 } |
1294 DictionaryValue dict; | 1294 DictionaryValue dict; |
1295 dict.SetString("bookmarks_as_json", bookmarks_as_json); | 1295 dict.SetString("bookmarks_as_json", bookmarks_as_json); |
1296 reply.SendSuccess(&dict); | 1296 reply.SendSuccess(&dict); |
1297 } | 1297 } |
1298 | 1298 |
1299 void TestingAutomationProvider::WaitForBookmarkModelToLoad( | 1299 void TestingAutomationProvider::WaitForBookmarkModelToLoad( |
(...skipping 1802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3102 PluginService::GetInstance()->GetPlugins( | 3102 PluginService::GetInstance()->GetPlugins( |
3103 base::Bind(&TestingAutomationProvider::GetPluginsInfoCallback, | 3103 base::Bind(&TestingAutomationProvider::GetPluginsInfoCallback, |
3104 this, browser, args, reply_message)); | 3104 this, browser, args, reply_message)); |
3105 } | 3105 } |
3106 | 3106 |
3107 void TestingAutomationProvider::GetPluginsInfoCallback( | 3107 void TestingAutomationProvider::GetPluginsInfoCallback( |
3108 Browser* browser, | 3108 Browser* browser, |
3109 DictionaryValue* args, | 3109 DictionaryValue* args, |
3110 IPC::Message* reply_message, | 3110 IPC::Message* reply_message, |
3111 const std::vector<webkit::WebPluginInfo>& plugins) { | 3111 const std::vector<webkit::WebPluginInfo>& plugins) { |
3112 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); | 3112 PluginPrefs* plugin_prefs = |
| 3113 PluginPrefs::GetForProfile(browser->profile()).get(); |
3113 ListValue* items = new ListValue; | 3114 ListValue* items = new ListValue; |
3114 for (std::vector<webkit::WebPluginInfo>::const_iterator it = | 3115 for (std::vector<webkit::WebPluginInfo>::const_iterator it = |
3115 plugins.begin(); | 3116 plugins.begin(); |
3116 it != plugins.end(); | 3117 it != plugins.end(); |
3117 ++it) { | 3118 ++it) { |
3118 DictionaryValue* item = new DictionaryValue; | 3119 DictionaryValue* item = new DictionaryValue; |
3119 item->SetString("name", it->name); | 3120 item->SetString("name", it->name); |
3120 item->SetString("path", it->path.value()); | 3121 item->SetString("path", it->path.value()); |
3121 item->SetString("version", it->version); | 3122 item->SetString("version", it->version); |
3122 item->SetString("desc", it->desc); | 3123 item->SetString("desc", it->desc); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3155 // { "command": "EnablePlugin", | 3156 // { "command": "EnablePlugin", |
3156 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } | 3157 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } |
3157 void TestingAutomationProvider::EnablePlugin(Browser* browser, | 3158 void TestingAutomationProvider::EnablePlugin(Browser* browser, |
3158 DictionaryValue* args, | 3159 DictionaryValue* args, |
3159 IPC::Message* reply_message) { | 3160 IPC::Message* reply_message) { |
3160 base::FilePath::StringType path; | 3161 base::FilePath::StringType path; |
3161 if (!args->GetString("path", &path)) { | 3162 if (!args->GetString("path", &path)) { |
3162 AutomationJSONReply(this, reply_message).SendError("path not specified."); | 3163 AutomationJSONReply(this, reply_message).SendError("path not specified."); |
3163 return; | 3164 return; |
3164 } | 3165 } |
3165 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); | 3166 PluginPrefs* plugin_prefs = |
3166 plugin_prefs->EnablePlugin(true, base::FilePath(path), | 3167 PluginPrefs::GetForProfile(browser->profile()).get(); |
3167 base::Bind(&DidEnablePlugin, AsWeakPtr(), reply_message, | 3168 plugin_prefs->EnablePlugin( |
3168 path, "Could not enable plugin for path %s.")); | 3169 true, |
| 3170 base::FilePath(path), |
| 3171 base::Bind(&DidEnablePlugin, |
| 3172 AsWeakPtr(), |
| 3173 reply_message, |
| 3174 path, |
| 3175 "Could not enable plugin for path %s.")); |
3169 } | 3176 } |
3170 | 3177 |
3171 // Sample json input: | 3178 // Sample json input: |
3172 // { "command": "DisablePlugin", | 3179 // { "command": "DisablePlugin", |
3173 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } | 3180 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } |
3174 void TestingAutomationProvider::DisablePlugin(Browser* browser, | 3181 void TestingAutomationProvider::DisablePlugin(Browser* browser, |
3175 DictionaryValue* args, | 3182 DictionaryValue* args, |
3176 IPC::Message* reply_message) { | 3183 IPC::Message* reply_message) { |
3177 base::FilePath::StringType path; | 3184 base::FilePath::StringType path; |
3178 if (!args->GetString("path", &path)) { | 3185 if (!args->GetString("path", &path)) { |
3179 AutomationJSONReply(this, reply_message).SendError("path not specified."); | 3186 AutomationJSONReply(this, reply_message).SendError("path not specified."); |
3180 return; | 3187 return; |
3181 } | 3188 } |
3182 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); | 3189 PluginPrefs* plugin_prefs = |
3183 plugin_prefs->EnablePlugin(false, base::FilePath(path), | 3190 PluginPrefs::GetForProfile(browser->profile()).get(); |
3184 base::Bind(&DidEnablePlugin, AsWeakPtr(), reply_message, | 3191 plugin_prefs->EnablePlugin( |
3185 path, "Could not disable plugin for path %s.")); | 3192 false, |
| 3193 base::FilePath(path), |
| 3194 base::Bind(&DidEnablePlugin, |
| 3195 AsWeakPtr(), |
| 3196 reply_message, |
| 3197 path, |
| 3198 "Could not disable plugin for path %s.")); |
3186 } | 3199 } |
3187 | 3200 |
3188 // Sample json input: | 3201 // Sample json input: |
3189 // { "command": "SaveTabContents", | 3202 // { "command": "SaveTabContents", |
3190 // "tab_index": 0, | 3203 // "tab_index": 0, |
3191 // "filename": <a full pathname> } | 3204 // "filename": <a full pathname> } |
3192 // Sample json output: | 3205 // Sample json output: |
3193 // {} | 3206 // {} |
3194 void TestingAutomationProvider::SaveTabContents( | 3207 void TestingAutomationProvider::SaveTabContents( |
3195 Browser* browser, | 3208 Browser* browser, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3354 AutomationJSONReply(this, reply_message).SendError( | 3367 AutomationJSONReply(this, reply_message).SendError( |
3355 "Password must include a value for 'signon_realm.'"); | 3368 "Password must include a value for 'signon_realm.'"); |
3356 return; | 3369 return; |
3357 } | 3370 } |
3358 | 3371 |
3359 content::PasswordForm new_password = | 3372 content::PasswordForm new_password = |
3360 GetPasswordFormFromDict(*password_dict); | 3373 GetPasswordFormFromDict(*password_dict); |
3361 | 3374 |
3362 // Use IMPLICIT_ACCESS since new passwords aren't added in incognito mode. | 3375 // Use IMPLICIT_ACCESS since new passwords aren't added in incognito mode. |
3363 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( | 3376 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
3364 browser->profile(), Profile::IMPLICIT_ACCESS); | 3377 browser->profile(), Profile::IMPLICIT_ACCESS).get(); |
3365 | 3378 |
3366 // The password store does not exist for an incognito window. | 3379 // The password store does not exist for an incognito window. |
3367 if (password_store == NULL) { | 3380 if (password_store == NULL) { |
3368 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 3381 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
3369 return_value->SetBoolean("password_added", false); | 3382 return_value->SetBoolean("password_added", false); |
3370 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 3383 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
3371 return; | 3384 return; |
3372 } | 3385 } |
3373 | 3386 |
3374 // This observer will delete itself. | 3387 // This observer will delete itself. |
(...skipping 25 matching lines...) Expand all Loading... |
3400 if (!password_dict->HasKey("signon_realm")) { | 3413 if (!password_dict->HasKey("signon_realm")) { |
3401 AutomationJSONReply(this, reply_message).SendError( | 3414 AutomationJSONReply(this, reply_message).SendError( |
3402 "Password must include a value for 'signon_realm.'"); | 3415 "Password must include a value for 'signon_realm.'"); |
3403 return; | 3416 return; |
3404 } | 3417 } |
3405 content::PasswordForm to_remove = | 3418 content::PasswordForm to_remove = |
3406 GetPasswordFormFromDict(*password_dict); | 3419 GetPasswordFormFromDict(*password_dict); |
3407 | 3420 |
3408 // Use EXPLICIT_ACCESS since passwords can be removed in incognito mode. | 3421 // Use EXPLICIT_ACCESS since passwords can be removed in incognito mode. |
3409 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( | 3422 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
3410 browser->profile(), Profile::EXPLICIT_ACCESS); | 3423 browser->profile(), Profile::EXPLICIT_ACCESS).get(); |
3411 if (password_store == NULL) { | 3424 if (password_store == NULL) { |
3412 AutomationJSONReply(this, reply_message).SendError( | 3425 AutomationJSONReply(this, reply_message).SendError( |
3413 "Unable to get password store."); | 3426 "Unable to get password store."); |
3414 return; | 3427 return; |
3415 } | 3428 } |
3416 | 3429 |
3417 // This observer will delete itself. | 3430 // This observer will delete itself. |
3418 PasswordStoreLoginsChangedObserver* observer = | 3431 PasswordStoreLoginsChangedObserver* observer = |
3419 new PasswordStoreLoginsChangedObserver( | 3432 new PasswordStoreLoginsChangedObserver( |
3420 this, reply_message, PasswordStoreChange::REMOVE, std::string()); | 3433 this, reply_message, PasswordStoreChange::REMOVE, std::string()); |
3421 observer->Init(); | 3434 observer->Init(); |
3422 | 3435 |
3423 password_store->RemoveLogin(to_remove); | 3436 password_store->RemoveLogin(to_remove); |
3424 } | 3437 } |
3425 | 3438 |
3426 // Sample json input: { "command": "GetSavedPasswords" } | 3439 // Sample json input: { "command": "GetSavedPasswords" } |
3427 // Refer to GetSavedPasswords() in chrome/test/pyautolib/pyauto.py for sample | 3440 // Refer to GetSavedPasswords() in chrome/test/pyautolib/pyauto.py for sample |
3428 // json output. | 3441 // json output. |
3429 void TestingAutomationProvider::GetSavedPasswords( | 3442 void TestingAutomationProvider::GetSavedPasswords( |
3430 Browser* browser, | 3443 Browser* browser, |
3431 DictionaryValue* args, | 3444 DictionaryValue* args, |
3432 IPC::Message* reply_message) { | 3445 IPC::Message* reply_message) { |
3433 // Use EXPLICIT_ACCESS since saved passwords can be retrieved in | 3446 // Use EXPLICIT_ACCESS since saved passwords can be retrieved in |
3434 // incognito mode. | 3447 // incognito mode. |
3435 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( | 3448 PasswordStore* password_store = PasswordStoreFactory::GetForProfile( |
3436 browser->profile(), Profile::EXPLICIT_ACCESS); | 3449 browser->profile(), Profile::EXPLICIT_ACCESS).get(); |
3437 | 3450 |
3438 if (password_store == NULL) { | 3451 if (password_store == NULL) { |
3439 AutomationJSONReply reply(this, reply_message); | 3452 AutomationJSONReply reply(this, reply_message); |
3440 reply.SendError("Unable to get password store."); | 3453 reply.SendError("Unable to get password store."); |
3441 return; | 3454 return; |
3442 } | 3455 } |
3443 password_store->GetAutofillableLogins( | 3456 password_store->GetAutofillableLogins( |
3444 new AutomationProviderGetPasswordsObserver(this, reply_message)); | 3457 new AutomationProviderGetPasswordsObserver(this, reply_message)); |
3445 // Observer deletes itself after sending the result. | 3458 // Observer deletes itself after sending the result. |
3446 } | 3459 } |
(...skipping 2238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5685 if (g_browser_process) | 5698 if (g_browser_process) |
5686 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 5699 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
5687 } | 5700 } |
5688 | 5701 |
5689 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 5702 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
5690 WebContents* tab) { | 5703 WebContents* tab) { |
5691 TabStripModel* tab_strip = browser->tab_strip_model(); | 5704 TabStripModel* tab_strip = browser->tab_strip_model(); |
5692 if (tab_strip->GetActiveWebContents() != tab) | 5705 if (tab_strip->GetActiveWebContents() != tab) |
5693 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); | 5706 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); |
5694 } | 5707 } |
OLD | NEW |