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

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

Issue 8649004: Allow chromedriver to install an extension and get all installed extension IDs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "chrome/browser/bookmarks/bookmark_model.h" 42 #include "chrome/browser/bookmarks/bookmark_model.h"
43 #include "chrome/browser/bookmarks/bookmark_storage.h" 43 #include "chrome/browser/bookmarks/bookmark_storage.h"
44 #include "chrome/browser/browser_process.h" 44 #include "chrome/browser/browser_process.h"
45 #include "chrome/browser/browser_shutdown.h" 45 #include "chrome/browser/browser_shutdown.h"
46 #include "chrome/browser/content_settings/host_content_settings_map.h" 46 #include "chrome/browser/content_settings/host_content_settings_map.h"
47 #include "chrome/browser/debugger/devtools_window.h" 47 #include "chrome/browser/debugger/devtools_window.h"
48 #include "chrome/browser/download/download_prefs.h" 48 #include "chrome/browser/download/download_prefs.h"
49 #include "chrome/browser/download/download_service.h" 49 #include "chrome/browser/download/download_service.h"
50 #include "chrome/browser/download/download_service_factory.h" 50 #include "chrome/browser/download/download_service_factory.h"
51 #include "chrome/browser/download/save_package_file_picker.h" 51 #include "chrome/browser/download/save_package_file_picker.h"
52 #include "chrome/browser/extensions/crx_installer.h"
52 #include "chrome/browser/extensions/extension_browser_event_router.h" 53 #include "chrome/browser/extensions/extension_browser_event_router.h"
53 #include "chrome/browser/extensions/extension_host.h" 54 #include "chrome/browser/extensions/extension_host.h"
54 #include "chrome/browser/extensions/extension_process_manager.h" 55 #include "chrome/browser/extensions/extension_process_manager.h"
55 #include "chrome/browser/extensions/extension_service.h" 56 #include "chrome/browser/extensions/extension_service.h"
56 #include "chrome/browser/extensions/extension_updater.h" 57 #include "chrome/browser/extensions/extension_updater.h"
58 #include "chrome/browser/extensions/unpacked_installer.h"
57 #include "chrome/browser/history/top_sites.h" 59 #include "chrome/browser/history/top_sites.h"
58 #include "chrome/browser/importer/importer_host.h" 60 #include "chrome/browser/importer/importer_host.h"
59 #include "chrome/browser/importer/importer_list.h" 61 #include "chrome/browser/importer/importer_list.h"
60 #include "chrome/browser/infobars/infobar_tab_helper.h" 62 #include "chrome/browser/infobars/infobar_tab_helper.h"
61 #include "chrome/browser/instant/instant_controller.h" 63 #include "chrome/browser/instant/instant_controller.h"
62 #include "chrome/browser/notifications/balloon.h" 64 #include "chrome/browser/notifications/balloon.h"
63 #include "chrome/browser/notifications/balloon_collection.h" 65 #include "chrome/browser/notifications/balloon_collection.h"
64 #include "chrome/browser/notifications/notification.h" 66 #include "chrome/browser/notifications/notification.h"
65 #include "chrome/browser/notifications/notification_ui_manager.h" 67 #include "chrome/browser/notifications/notification_ui_manager.h"
66 #include "chrome/browser/password_manager/password_store.h" 68 #include "chrome/browser/password_manager/password_store.h"
(...skipping 2259 matching lines...) Expand 10 before | Expand all | Expand 10 after
2326 handler_map["OpenNewBrowserWindowWithNewProfile"] = 2328 handler_map["OpenNewBrowserWindowWithNewProfile"] =
2327 &TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile; 2329 &TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile;
2328 handler_map["GetMultiProfileInfo"] = 2330 handler_map["GetMultiProfileInfo"] =
2329 &TestingAutomationProvider::GetMultiProfileInfo; 2331 &TestingAutomationProvider::GetMultiProfileInfo;
2330 handler_map["GetProcessInfo"] = 2332 handler_map["GetProcessInfo"] =
2331 &TestingAutomationProvider::GetProcessInfo; 2333 &TestingAutomationProvider::GetProcessInfo;
2332 handler_map["SetPolicies"] = 2334 handler_map["SetPolicies"] =
2333 &TestingAutomationProvider::SetPolicies; 2335 &TestingAutomationProvider::SetPolicies;
2334 handler_map["GetPolicyDefinitionList"] = 2336 handler_map["GetPolicyDefinitionList"] =
2335 &TestingAutomationProvider::GetPolicyDefinitionList; 2337 &TestingAutomationProvider::GetPolicyDefinitionList;
2338 handler_map["InstallExtension"] =
2339 &TestingAutomationProvider::InstallExtension;
2340 handler_map["GetExtensionsInfo"] =
2341 &TestingAutomationProvider::GetExtensionsInfo;
2336 #if defined(OS_CHROMEOS) 2342 #if defined(OS_CHROMEOS)
2337 handler_map["GetLoginInfo"] = &TestingAutomationProvider::GetLoginInfo; 2343 handler_map["GetLoginInfo"] = &TestingAutomationProvider::GetLoginInfo;
2338 handler_map["ShowCreateAccountUI"] = 2344 handler_map["ShowCreateAccountUI"] =
2339 &TestingAutomationProvider::ShowCreateAccountUI; 2345 &TestingAutomationProvider::ShowCreateAccountUI;
2340 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; 2346 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest;
2341 handler_map["Login"] = &TestingAutomationProvider::Login; 2347 handler_map["Login"] = &TestingAutomationProvider::Login;
2342 2348
2343 handler_map["LockScreen"] = &TestingAutomationProvider::LockScreen; 2349 handler_map["LockScreen"] = &TestingAutomationProvider::LockScreen;
2344 handler_map["UnlockScreen"] = &TestingAutomationProvider::UnlockScreen; 2350 handler_map["UnlockScreen"] = &TestingAutomationProvider::UnlockScreen;
2345 handler_map["SignoutInScreenLocker"] = 2351 handler_map["SignoutInScreenLocker"] =
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2470 2476
2471 browser_handler_map["GetBlockedPopupsInfo"] = 2477 browser_handler_map["GetBlockedPopupsInfo"] =
2472 &TestingAutomationProvider::GetBlockedPopupsInfo; 2478 &TestingAutomationProvider::GetBlockedPopupsInfo;
2473 browser_handler_map["UnblockAndLaunchBlockedPopup"] = 2479 browser_handler_map["UnblockAndLaunchBlockedPopup"] =
2474 &TestingAutomationProvider::UnblockAndLaunchBlockedPopup; 2480 &TestingAutomationProvider::UnblockAndLaunchBlockedPopup;
2475 2481
2476 // SetTheme() implemented using InstallExtension(). 2482 // SetTheme() implemented using InstallExtension().
2477 browser_handler_map["GetThemeInfo"] = 2483 browser_handler_map["GetThemeInfo"] =
2478 &TestingAutomationProvider::GetThemeInfo; 2484 &TestingAutomationProvider::GetThemeInfo;
2479 2485
2480 // InstallExtension() present in pyauto.py. 2486 // InstallExtension() present in pyauto.py.
dennis_jeffrey 2011/11/22 23:32:16 Maybe remove this comment or update it, since Inst
kkania 2011/11/23 17:31:23 Done.
2481 browser_handler_map["GetExtensionsInfo"] =
2482 &TestingAutomationProvider::GetExtensionsInfo;
2483 browser_handler_map["UninstallExtensionById"] = 2487 browser_handler_map["UninstallExtensionById"] =
2484 &TestingAutomationProvider::UninstallExtensionById; 2488 &TestingAutomationProvider::UninstallExtensionById;
2485 2489
2486 browser_handler_map["SetExtensionStateById"] = 2490 browser_handler_map["SetExtensionStateById"] =
2487 &TestingAutomationProvider::SetExtensionStateById; 2491 &TestingAutomationProvider::SetExtensionStateById;
2488 2492
2489 browser_handler_map["FindInPage"] = &TestingAutomationProvider::FindInPage; 2493 browser_handler_map["FindInPage"] = &TestingAutomationProvider::FindInPage;
2490 2494
2491 browser_handler_map["SelectTranslateOption"] = 2495 browser_handler_map["SelectTranslateOption"] =
2492 &TestingAutomationProvider::SelectTranslateOption; 2496 &TestingAutomationProvider::SelectTranslateOption;
(...skipping 1785 matching lines...) Expand 10 before | Expand all | Expand 10 after
4278 const Extension* theme = ThemeServiceFactory::GetThemeForProfile(profile()); 4282 const Extension* theme = ThemeServiceFactory::GetThemeForProfile(profile());
4279 if (theme) { 4283 if (theme) {
4280 return_value->SetString("name", theme->name()); 4284 return_value->SetString("name", theme->name());
4281 return_value->Set("images", theme->GetThemeImages()->DeepCopy()); 4285 return_value->Set("images", theme->GetThemeImages()->DeepCopy());
4282 return_value->Set("colors", theme->GetThemeColors()->DeepCopy()); 4286 return_value->Set("colors", theme->GetThemeColors()->DeepCopy());
4283 return_value->Set("tints", theme->GetThemeTints()->DeepCopy()); 4287 return_value->Set("tints", theme->GetThemeTints()->DeepCopy());
4284 } 4288 }
4285 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); 4289 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
4286 } 4290 }
4287 4291
4292 void TestingAutomationProvider::InstallExtension(
4293 DictionaryValue* args, IPC::Message* reply_message) {
4294 FilePath::StringType path_string;
4295 if (!args->GetString("path", &path_string)) {
4296 AutomationJSONReply(this, reply_message).SendError(
4297 "Missing or invalid 'path'");
4298 return;
4299 }
4300 ExtensionService* service = profile()->GetExtensionService();
4301 ExtensionProcessManager* manager = profile()->GetExtensionProcessManager();
4302 if (service && manager) {
4303 // The observer will delete itself when done.
4304 new ExtensionReadyNotificationObserver(
4305 manager,
4306 service,
4307 this,
4308 reply_message);
4309
4310 FilePath extension_path(path_string);
4311 if (extension_path.MatchesExtension(FILE_PATH_LITERAL(".crx"))) {
dennis_jeffrey 2011/11/22 23:32:16 Please add a comment to describe what's happening
kkania 2011/11/23 17:31:23 Done.
4312 scoped_refptr<CrxInstaller> installer(
4313 CrxInstaller::Create(service, NULL));
4314 installer->set_allow_silent_install(true);
4315 installer->set_install_cause(extension_misc::INSTALL_CAUSE_AUTOMATION);
4316 installer->InstallCrx(extension_path);
4317 } else {
4318 scoped_refptr<extensions::UnpackedInstaller> installer(
4319 extensions::UnpackedInstaller::Create(service));
4320 installer->set_prompt_for_plugins(false);
4321 installer->Load(extension_path);
4322 }
4323 } else {
4324 AutomationMsg_InstallExtension::WriteReplyParams(reply_message, 0);
4325 Send(reply_message);
dennis_jeffrey 2011/11/22 23:32:16 What's the reason you're replying this way as comp
kkania 2011/11/23 17:31:23 oops, meant to delete that...
4326 }
4327 }
4328
4288 namespace { 4329 namespace {
4289 4330
4290 ListValue* GetHostPermissions(const Extension* ext, bool effective_perm) { 4331 ListValue* GetHostPermissions(const Extension* ext, bool effective_perm) {
4291 URLPatternSet pattern_set; 4332 URLPatternSet pattern_set;
4292 if (effective_perm) 4333 if (effective_perm)
4293 pattern_set = ext->GetEffectiveHostPermissions(); 4334 pattern_set = ext->GetEffectiveHostPermissions();
4294 else 4335 else
4295 pattern_set = ext->GetActivePermissions()->explicit_hosts(); 4336 pattern_set = ext->GetActivePermissions()->explicit_hosts();
4296 4337
4297 ListValue* permissions = new ListValue; 4338 ListValue* permissions = new ListValue;
(...skipping 15 matching lines...) Expand all
4313 } 4354 }
4314 return permissions; 4355 return permissions;
4315 } 4356 }
4316 4357
4317 } // namespace 4358 } // namespace
4318 4359
4319 // Sample json input: { "command": "GetExtensionsInfo" } 4360 // Sample json input: { "command": "GetExtensionsInfo" }
4320 // See GetExtensionsInfo() in chrome/test/pyautolib/pyauto.py for sample json 4361 // See GetExtensionsInfo() in chrome/test/pyautolib/pyauto.py for sample json
4321 // output. 4362 // output.
4322 void TestingAutomationProvider::GetExtensionsInfo( 4363 void TestingAutomationProvider::GetExtensionsInfo(
4323 Browser* browser,
4324 DictionaryValue* args, 4364 DictionaryValue* args,
4325 IPC::Message* reply_message) { 4365 IPC::Message* reply_message) {
4326 AutomationJSONReply reply(this, reply_message); 4366 AutomationJSONReply reply(this, reply_message);
4327 ExtensionService* service = profile()->GetExtensionService(); 4367 ExtensionService* service = profile()->GetExtensionService();
4328 if (!service) { 4368 if (!service) {
4329 reply.SendError("No extensions service."); 4369 reply.SendError("No extensions service.");
4330 return; 4370 return;
4331 } 4371 }
4332 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); 4372 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
4333 ListValue* extensions_values = new ListValue; 4373 ListValue* extensions_values = new ListValue;
(...skipping 20 matching lines...) Expand all
4354 extension->background_url().spec()); 4394 extension->background_url().spec());
4355 extension_value->SetString("options_url", 4395 extension_value->SetString("options_url",
4356 extension->options_url().spec()); 4396 extension->options_url().spec());
4357 extension_value->Set("host_permissions", 4397 extension_value->Set("host_permissions",
4358 GetHostPermissions(extension, false)); 4398 GetHostPermissions(extension, false));
4359 extension_value->Set("effective_host_permissions", 4399 extension_value->Set("effective_host_permissions",
4360 GetHostPermissions(extension, true)); 4400 GetHostPermissions(extension, true));
4361 extension_value->Set("api_permissions", GetAPIPermissions(extension)); 4401 extension_value->Set("api_permissions", GetAPIPermissions(extension));
4362 extension_value->SetBoolean("is_component_extension", 4402 extension_value->SetBoolean("is_component_extension",
4363 extension->location() == Extension::COMPONENT); 4403 extension->location() == Extension::COMPONENT);
4404 extension_value->SetBoolean("is_internal_extension",
4405 extension->location() == Extension::INTERNAL);
4364 extension_value->SetBoolean("is_enabled", service->IsExtensionEnabled(id)); 4406 extension_value->SetBoolean("is_enabled", service->IsExtensionEnabled(id));
4365 extension_value->SetBoolean("allowed_in_incognito", 4407 extension_value->SetBoolean("allowed_in_incognito",
4366 service->IsIncognitoEnabled(id)); 4408 service->IsIncognitoEnabled(id));
4367 extensions_values->Append(extension_value); 4409 extensions_values->Append(extension_value);
4368 } 4410 }
4369 return_value->Set("extensions", extensions_values); 4411 return_value->Set("extensions", extensions_values);
4370 reply.SendSuccess(return_value.get()); 4412 reply.SendSuccess(return_value.get());
4371 } 4413 }
4372 4414
4373 // See UninstallExtensionById() in chrome/test/pyautolib/pyauto.py for sample 4415 // See UninstallExtensionById() in chrome/test/pyautolib/pyauto.py for sample
(...skipping 2014 matching lines...) Expand 10 before | Expand all | Expand 10 after
6388 6430
6389 Send(reply_message_); 6431 Send(reply_message_);
6390 redirect_query_ = 0; 6432 redirect_query_ = 0;
6391 reply_message_ = NULL; 6433 reply_message_ = NULL;
6392 } 6434 }
6393 6435
6394 void TestingAutomationProvider::OnRemoveProvider() { 6436 void TestingAutomationProvider::OnRemoveProvider() {
6395 if (g_browser_process) 6437 if (g_browser_process)
6396 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 6438 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6397 } 6439 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698