Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/extensions/api/developer_private/developer_private_api. h" | 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api. h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/devtools/devtools_window.h" | 15 #include "chrome/browser/devtools/devtools_window.h" |
| 16 #include "chrome/browser/extensions/api/developer_private/developer_private_mang le.h" | 16 #include "chrome/browser/extensions/api/developer_private/developer_private_mang le.h" |
| 17 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" | 17 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" |
| 18 #include "chrome/browser/extensions/api/developer_private/extension_info_generat or.h" | 18 #include "chrome/browser/extensions/api/developer_private/extension_info_generat or.h" |
| 19 #include "chrome/browser/extensions/api/developer_private/show_permissions_dialo g_helper.h" | 19 #include "chrome/browser/extensions/api/developer_private/show_permissions_dialo g_helper.h" |
| 20 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 20 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 21 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" | 21 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
| 22 #include "chrome/browser/extensions/devtools_util.h" | 22 #include "chrome/browser/extensions/devtools_util.h" |
| 23 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 24 #include "chrome/browser/extensions/extension_tab_util.h" | |
| 24 #include "chrome/browser/extensions/extension_ui_util.h" | 25 #include "chrome/browser/extensions/extension_ui_util.h" |
| 25 #include "chrome/browser/extensions/extension_util.h" | 26 #include "chrome/browser/extensions/extension_util.h" |
| 26 #include "chrome/browser/extensions/install_verifier.h" | 27 #include "chrome/browser/extensions/install_verifier.h" |
| 27 #include "chrome/browser/extensions/shared_module_service.h" | 28 #include "chrome/browser/extensions/shared_module_service.h" |
| 28 #include "chrome/browser/extensions/unpacked_installer.h" | 29 #include "chrome/browser/extensions/unpacked_installer.h" |
| 29 #include "chrome/browser/extensions/updater/extension_updater.h" | 30 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 31 #include "chrome/browser/extensions/webstore_reinstaller.h" | |
| 32 #include "chrome/browser/platform_util.h" | |
| 30 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 33 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 31 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
| 32 #include "chrome/browser/ui/apps/app_info_dialog.h" | 35 #include "chrome/browser/ui/apps/app_info_dialog.h" |
| 33 #include "chrome/browser/ui/browser_finder.h" | 36 #include "chrome/browser/ui/browser_finder.h" |
| 37 #include "chrome/browser/ui/extensions/app_launch_params.h" | |
| 38 #include "chrome/browser/ui/extensions/application_launch.h" | |
| 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 39 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 35 #include "chrome/common/extensions/api/developer_private.h" | 40 #include "chrome/common/extensions/api/developer_private.h" |
| 36 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 41 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 37 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
| 38 #include "chrome/common/url_constants.h" | 43 #include "chrome/common/url_constants.h" |
| 39 #include "chrome/grit/generated_resources.h" | 44 #include "chrome/grit/generated_resources.h" |
| 40 #include "content/public/browser/browser_thread.h" | 45 #include "content/public/browser/browser_thread.h" |
| 41 #include "content/public/browser/notification_service.h" | 46 #include "content/public/browser/notification_service.h" |
| 42 #include "content/public/browser/render_process_host.h" | 47 #include "content/public/browser/render_process_host.h" |
| 43 #include "content/public/browser/render_view_host.h" | 48 #include "content/public/browser/render_view_host.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 55 #include "extensions/browser/management_policy.h" | 60 #include "extensions/browser/management_policy.h" |
| 56 #include "extensions/browser/notification_types.h" | 61 #include "extensions/browser/notification_types.h" |
| 57 #include "extensions/browser/warning_service.h" | 62 #include "extensions/browser/warning_service.h" |
| 58 #include "extensions/common/constants.h" | 63 #include "extensions/common/constants.h" |
| 59 #include "extensions/common/extension_resource.h" | 64 #include "extensions/common/extension_resource.h" |
| 60 #include "extensions/common/extension_set.h" | 65 #include "extensions/common/extension_set.h" |
| 61 #include "extensions/common/feature_switch.h" | 66 #include "extensions/common/feature_switch.h" |
| 62 #include "extensions/common/install_warning.h" | 67 #include "extensions/common/install_warning.h" |
| 63 #include "extensions/common/manifest.h" | 68 #include "extensions/common/manifest.h" |
| 64 #include "extensions/common/manifest_handlers/icons_handler.h" | 69 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 70 #include "extensions/common/manifest_handlers/options_page_info.h" | |
| 65 #include "extensions/common/permissions/permissions_data.h" | 71 #include "extensions/common/permissions/permissions_data.h" |
| 66 #include "extensions/grit/extensions_browser_resources.h" | 72 #include "extensions/grit/extensions_browser_resources.h" |
| 67 #include "storage/browser/fileapi/external_mount_points.h" | 73 #include "storage/browser/fileapi/external_mount_points.h" |
| 68 #include "storage/browser/fileapi/file_system_context.h" | 74 #include "storage/browser/fileapi/file_system_context.h" |
| 69 #include "storage/browser/fileapi/file_system_operation.h" | 75 #include "storage/browser/fileapi/file_system_operation.h" |
| 70 #include "storage/browser/fileapi/file_system_operation_runner.h" | 76 #include "storage/browser/fileapi/file_system_operation_runner.h" |
| 71 #include "storage/browser/fileapi/isolated_context.h" | 77 #include "storage/browser/fileapi/isolated_context.h" |
| 72 #include "ui/base/l10n/l10n_util.h" | 78 #include "ui/base/l10n/l10n_util.h" |
| 73 #include "ui/base/resource/resource_bundle.h" | 79 #include "ui/base/resource/resource_bundle.h" |
| 74 | 80 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 88 const char kFileSelectionCanceled[] = | 94 const char kFileSelectionCanceled[] = |
| 89 "File selection was canceled."; | 95 "File selection was canceled."; |
| 90 const char kNoSuchRendererError[] = "No such renderer."; | 96 const char kNoSuchRendererError[] = "No such renderer."; |
| 91 const char kInvalidPathError[] = "Invalid path."; | 97 const char kInvalidPathError[] = "Invalid path."; |
| 92 const char kManifestKeyIsRequiredError[] = | 98 const char kManifestKeyIsRequiredError[] = |
| 93 "The 'manifestKey' argument is required for manifest files."; | 99 "The 'manifestKey' argument is required for manifest files."; |
| 94 const char kCouldNotFindWebContentsError[] = | 100 const char kCouldNotFindWebContentsError[] = |
| 95 "Could not find a valid web contents."; | 101 "Could not find a valid web contents."; |
| 96 const char kCannotUpdateSupervisedProfileSettingsError[] = | 102 const char kCannotUpdateSupervisedProfileSettingsError[] = |
| 97 "Cannot change settings for a supervised profile."; | 103 "Cannot change settings for a supervised profile."; |
| 104 const char kNoOptionsPageForExtensionError[] = | |
| 105 "Extension does not have an options page."; | |
| 98 | 106 |
| 99 const char kUnpackedAppsFolder[] = "apps_target"; | 107 const char kUnpackedAppsFolder[] = "apps_target"; |
| 100 const char kManifestFile[] = "manifest.json"; | 108 const char kManifestFile[] = "manifest.json"; |
| 101 | 109 |
| 102 ExtensionService* GetExtensionService(content::BrowserContext* context) { | 110 ExtensionService* GetExtensionService(content::BrowserContext* context) { |
| 103 return ExtensionSystem::Get(context)->extension_service(); | 111 return ExtensionSystem::Get(context)->extension_service(); |
| 104 } | 112 } |
| 105 | 113 |
| 106 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { | |
| 107 return GetExtensionService(profile)->updater(); | |
| 108 } | |
| 109 | |
| 110 GURL GetImageURLFromData(const std::string& contents) { | 114 GURL GetImageURLFromData(const std::string& contents) { |
| 111 std::string contents_base64; | 115 std::string contents_base64; |
| 112 base::Base64Encode(contents, &contents_base64); | 116 base::Base64Encode(contents, &contents_base64); |
| 113 | 117 |
| 114 // TODO(dvh): make use of content::kDataScheme. Filed as crbug/297301. | 118 // TODO(dvh): make use of content::kDataScheme. Filed as crbug/297301. |
| 115 const char kDataURLPrefix[] = "data:;base64,"; | 119 const char kDataURLPrefix[] = "data:;base64,"; |
| 116 return GURL(kDataURLPrefix + contents_base64); | 120 return GURL(kDataURLPrefix + contents_base64); |
| 117 } | 121 } |
| 118 | 122 |
| 119 GURL GetDefaultImageURL(developer_private::ItemType type) { | 123 GURL GetDefaultImageURL(developer_private::ItemType type) { |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 | 362 |
| 359 DeveloperPrivateAPIFunction::~DeveloperPrivateAPIFunction() { | 363 DeveloperPrivateAPIFunction::~DeveloperPrivateAPIFunction() { |
| 360 } | 364 } |
| 361 | 365 |
| 362 const Extension* DeveloperPrivateAPIFunction::GetExtensionById( | 366 const Extension* DeveloperPrivateAPIFunction::GetExtensionById( |
| 363 const std::string& id) { | 367 const std::string& id) { |
| 364 return ExtensionRegistry::Get(browser_context())->GetExtensionById( | 368 return ExtensionRegistry::Get(browser_context())->GetExtensionById( |
| 365 id, ExtensionRegistry::EVERYTHING); | 369 id, ExtensionRegistry::EVERYTHING); |
| 366 } | 370 } |
| 367 | 371 |
| 368 bool DeveloperPrivateAutoUpdateFunction::RunSync() { | |
| 369 ExtensionUpdater* updater = GetExtensionUpdater(GetProfile()); | |
| 370 if (updater) | |
| 371 updater->CheckNow(ExtensionUpdater::CheckParams()); | |
| 372 SetResult(new base::FundamentalValue(true)); | |
| 373 return true; | |
| 374 } | |
| 375 | |
| 376 DeveloperPrivateAutoUpdateFunction::~DeveloperPrivateAutoUpdateFunction() {} | 372 DeveloperPrivateAutoUpdateFunction::~DeveloperPrivateAutoUpdateFunction() {} |
| 377 | 373 |
| 374 ExtensionFunction::ResponseAction DeveloperPrivateAutoUpdateFunction::Run() { | |
| 375 ExtensionUpdater* updater = | |
| 376 ExtensionSystem::Get(browser_context())->extension_service()->updater(); | |
| 377 if (updater) { | |
| 378 ExtensionUpdater::CheckParams params; | |
| 379 params.install_immediately = true; | |
| 380 updater->CheckNow(params); | |
| 381 } | |
| 382 return RespondNow(NoArguments()); | |
| 383 } | |
| 384 | |
| 378 DeveloperPrivateGetExtensionsInfoFunction:: | 385 DeveloperPrivateGetExtensionsInfoFunction:: |
| 379 ~DeveloperPrivateGetExtensionsInfoFunction() { | 386 ~DeveloperPrivateGetExtensionsInfoFunction() { |
| 380 } | 387 } |
| 381 | 388 |
| 382 ExtensionFunction::ResponseAction | 389 ExtensionFunction::ResponseAction |
| 383 DeveloperPrivateGetExtensionsInfoFunction::Run() { | 390 DeveloperPrivateGetExtensionsInfoFunction::Run() { |
| 384 scoped_ptr<developer::GetExtensionsInfo::Params> params( | 391 scoped_ptr<developer::GetExtensionsInfo::Params> params( |
| 385 developer::GetExtensionsInfo::Params::Create(*args_)); | 392 developer::GetExtensionsInfo::Params::Create(*args_)); |
| 386 EXTENSION_FUNCTION_VALIDATE(params); | 393 EXTENSION_FUNCTION_VALIDATE(params); |
| 387 | 394 |
| (...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1264 if (properties.error_ids) { | 1271 if (properties.error_ids) { |
| 1265 error_ids.insert(properties.error_ids->begin(), | 1272 error_ids.insert(properties.error_ids->begin(), |
| 1266 properties.error_ids->end()); | 1273 properties.error_ids->end()); |
| 1267 } | 1274 } |
| 1268 error_console->RemoveErrors(ErrorMap::Filter( | 1275 error_console->RemoveErrors(ErrorMap::Filter( |
| 1269 properties.extension_id, type, error_ids, false)); | 1276 properties.extension_id, type, error_ids, false)); |
| 1270 | 1277 |
| 1271 return RespondNow(NoArguments()); | 1278 return RespondNow(NoArguments()); |
| 1272 } | 1279 } |
| 1273 | 1280 |
| 1281 DeveloperPrivateRepairExtensionFunction:: | |
| 1282 ~DeveloperPrivateRepairExtensionFunction() {} | |
| 1283 | |
| 1284 ExtensionFunction::ResponseAction | |
| 1285 DeveloperPrivateRepairExtensionFunction::Run() { | |
| 1286 scoped_ptr<developer::RepairExtension::Params> params( | |
| 1287 developer::RepairExtension::Params::Create(*args_)); | |
| 1288 EXTENSION_FUNCTION_VALIDATE(params); | |
| 1289 const Extension* extension = GetExtensionById(params->extension_id); | |
| 1290 if (!extension) | |
| 1291 return RespondNow(Error(kNoSuchExtensionError)); | |
| 1292 | |
| 1293 content::WebContents* web_contents = GetSenderWebContents(); | |
| 1294 if (!web_contents) | |
| 1295 return RespondNow(Error(kCouldNotFindWebContentsError)); | |
| 1296 | |
| 1297 scoped_refptr<WebstoreReinstaller> reinstaller(new WebstoreReinstaller( | |
| 1298 web_contents, | |
| 1299 params->extension_id, | |
| 1300 base::Bind(&DeveloperPrivateRepairExtensionFunction::OnReinstallComplete, | |
| 1301 this))); | |
| 1302 reinstaller->BeginReinstall(); | |
| 1303 | |
| 1304 return RespondLater(); | |
| 1305 } | |
| 1306 | |
| 1307 void DeveloperPrivateRepairExtensionFunction::OnReinstallComplete( | |
| 1308 bool success, | |
| 1309 const std::string& error, | |
| 1310 webstore_install::Result result) { | |
| 1311 if (!success) | |
| 1312 Respond(Error(error)); | |
| 1313 else | |
| 1314 Respond(NoArguments()); | |
|
not at google - send to devlin
2015/04/16 17:33:25
There is a single precedent in this file to do Res
Devlin
2015/04/16 17:59:12
Done.
| |
| 1315 } | |
| 1316 | |
| 1317 DeveloperPrivateShowOptionsFunction::~DeveloperPrivateShowOptionsFunction() {} | |
| 1318 | |
| 1319 ExtensionFunction::ResponseAction DeveloperPrivateShowOptionsFunction::Run() { | |
| 1320 scoped_ptr<developer::ShowOptions::Params> params( | |
| 1321 developer::ShowOptions::Params::Create(*args_)); | |
| 1322 EXTENSION_FUNCTION_VALIDATE(params); | |
| 1323 const Extension* extension = | |
| 1324 ExtensionRegistry::Get(browser_context())->enabled_extensions().GetByID( | |
| 1325 params->extension_id); | |
|
not at google - send to devlin
2015/04/16 17:33:25
Use GetExtensionById?
Devlin
2015/04/16 17:59:12
Well, we only want enabled extensions. But maybe t
| |
| 1326 if (!extension) | |
| 1327 return RespondNow(Error(kNoSuchExtensionError)); | |
| 1328 if (OptionsPageInfo::GetOptionsPage(extension).is_empty()) | |
| 1329 return RespondNow(Error(kNoOptionsPageForExtensionError)); | |
| 1330 content::WebContents* web_contents = GetSenderWebContents(); | |
| 1331 if (!web_contents) | |
| 1332 return RespondNow(Error(kCouldNotFindWebContentsError)); | |
| 1333 ExtensionTabUtil::OpenOptionsPage( | |
| 1334 extension, | |
| 1335 chrome::FindBrowserWithWebContents(web_contents)); | |
| 1336 return RespondNow(NoArguments()); | |
| 1337 } | |
| 1338 | |
| 1339 DeveloperPrivateShowPathFunction::~DeveloperPrivateShowPathFunction() {} | |
| 1340 | |
| 1341 ExtensionFunction::ResponseAction DeveloperPrivateShowPathFunction::Run() { | |
| 1342 scoped_ptr<developer::ShowPath::Params> params( | |
| 1343 developer::ShowPath::Params::Create(*args_)); | |
| 1344 EXTENSION_FUNCTION_VALIDATE(params); | |
| 1345 const Extension* extension = GetExtensionById(params->extension_id); | |
| 1346 if (!extension) | |
| 1347 return RespondNow(Error(kNoSuchExtensionError)); | |
| 1348 | |
| 1349 // We explicitly show manifest.json in order to work around an issue in OSX | |
| 1350 // where opening the directory doesn't focus the Finder. | |
| 1351 platform_util::ShowItemInFolder(GetProfile(), | |
| 1352 extension->path().Append(kManifestFilename)); | |
| 1353 return RespondNow(NoArguments()); | |
| 1354 } | |
| 1355 | |
| 1274 } // namespace api | 1356 } // namespace api |
| 1275 | 1357 |
| 1276 } // namespace extensions | 1358 } // namespace extensions |
| OLD | NEW |