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() { | 372 const Extension* DeveloperPrivateAPIFunction::GetEnabledExtensionById( |
| 369 ExtensionUpdater* updater = GetExtensionUpdater(GetProfile()); | 373 const std::string& id) { |
| 370 if (updater) | 374 return ExtensionRegistry::Get(browser_context())->enabled_extensions(). |
| 371 updater->CheckNow(ExtensionUpdater::CheckParams()); | 375 GetByID(id); |
| 372 SetResult(new base::FundamentalValue(true)); | |
| 373 return true; | |
| 374 } | 376 } |
| 375 | 377 |
| 376 DeveloperPrivateAutoUpdateFunction::~DeveloperPrivateAutoUpdateFunction() {} | 378 DeveloperPrivateAutoUpdateFunction::~DeveloperPrivateAutoUpdateFunction() {} |
| 377 | 379 |
| 380 ExtensionFunction::ResponseAction DeveloperPrivateAutoUpdateFunction::Run() { | |
| 381 ExtensionUpdater* updater = | |
| 382 ExtensionSystem::Get(browser_context())->extension_service()->updater(); | |
| 383 if (updater) { | |
| 384 ExtensionUpdater::CheckParams params; | |
| 385 params.install_immediately = true; | |
| 386 updater->CheckNow(params); | |
| 387 } | |
| 388 return RespondNow(NoArguments()); | |
| 389 } | |
| 390 | |
| 378 DeveloperPrivateGetExtensionsInfoFunction:: | 391 DeveloperPrivateGetExtensionsInfoFunction:: |
| 379 ~DeveloperPrivateGetExtensionsInfoFunction() { | 392 ~DeveloperPrivateGetExtensionsInfoFunction() { |
| 380 } | 393 } |
| 381 | 394 |
| 382 ExtensionFunction::ResponseAction | 395 ExtensionFunction::ResponseAction |
| 383 DeveloperPrivateGetExtensionsInfoFunction::Run() { | 396 DeveloperPrivateGetExtensionsInfoFunction::Run() { |
| 384 scoped_ptr<developer::GetExtensionsInfo::Params> params( | 397 scoped_ptr<developer::GetExtensionsInfo::Params> params( |
| 385 developer::GetExtensionsInfo::Params::Create(*args_)); | 398 developer::GetExtensionsInfo::Params::Create(*args_)); |
| 386 EXTENSION_FUNCTION_VALIDATE(params); | 399 EXTENSION_FUNCTION_VALIDATE(params); |
| 387 | 400 |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1180 ExtensionFunction::ResponseAction | 1193 ExtensionFunction::ResponseAction |
| 1181 DeveloperPrivateOpenDevToolsFunction::Run() { | 1194 DeveloperPrivateOpenDevToolsFunction::Run() { |
| 1182 scoped_ptr<developer::OpenDevTools::Params> params( | 1195 scoped_ptr<developer::OpenDevTools::Params> params( |
| 1183 developer::OpenDevTools::Params::Create(*args_)); | 1196 developer::OpenDevTools::Params::Create(*args_)); |
| 1184 EXTENSION_FUNCTION_VALIDATE(params); | 1197 EXTENSION_FUNCTION_VALIDATE(params); |
| 1185 const developer::OpenDevToolsProperties& properties = params->properties; | 1198 const developer::OpenDevToolsProperties& properties = params->properties; |
| 1186 | 1199 |
| 1187 if (properties.render_process_id == -1) { | 1200 if (properties.render_process_id == -1) { |
| 1188 // This is a lazy background page. | 1201 // This is a lazy background page. |
| 1189 const Extension* extension = properties.extension_id ? | 1202 const Extension* extension = properties.extension_id ? |
| 1190 ExtensionRegistry::Get(browser_context())->enabled_extensions().GetByID( | 1203 GetEnabledExtensionById(*properties.extension_id) : nullptr; |
| 1191 *properties.extension_id) : nullptr; | |
| 1192 if (!extension) | 1204 if (!extension) |
| 1193 return RespondNow(Error(kNoSuchExtensionError)); | 1205 return RespondNow(Error(kNoSuchExtensionError)); |
| 1194 | 1206 |
| 1195 Profile* profile = GetProfile(); | 1207 Profile* profile = GetProfile(); |
| 1196 if (properties.incognito && *properties.incognito) | 1208 if (properties.incognito && *properties.incognito) |
| 1197 profile = profile->GetOffTheRecordProfile(); | 1209 profile = profile->GetOffTheRecordProfile(); |
| 1198 | 1210 |
| 1199 // Wakes up the background page and opens the inspect window. | 1211 // Wakes up the background page and opens the inspect window. |
| 1200 devtools_util::InspectBackgroundPage(extension, profile); | 1212 devtools_util::InspectBackgroundPage(extension, profile); |
| 1201 return RespondNow(NoArguments()); | 1213 return RespondNow(NoArguments()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1264 if (properties.error_ids) { | 1276 if (properties.error_ids) { |
| 1265 error_ids.insert(properties.error_ids->begin(), | 1277 error_ids.insert(properties.error_ids->begin(), |
| 1266 properties.error_ids->end()); | 1278 properties.error_ids->end()); |
| 1267 } | 1279 } |
| 1268 error_console->RemoveErrors(ErrorMap::Filter( | 1280 error_console->RemoveErrors(ErrorMap::Filter( |
| 1269 properties.extension_id, type, error_ids, false)); | 1281 properties.extension_id, type, error_ids, false)); |
| 1270 | 1282 |
| 1271 return RespondNow(NoArguments()); | 1283 return RespondNow(NoArguments()); |
| 1272 } | 1284 } |
| 1273 | 1285 |
| 1286 DeveloperPrivateRepairExtensionFunction:: | |
| 1287 ~DeveloperPrivateRepairExtensionFunction() {} | |
| 1288 | |
| 1289 ExtensionFunction::ResponseAction | |
| 1290 DeveloperPrivateRepairExtensionFunction::Run() { | |
| 1291 scoped_ptr<developer::RepairExtension::Params> params( | |
| 1292 developer::RepairExtension::Params::Create(*args_)); | |
| 1293 EXTENSION_FUNCTION_VALIDATE(params); | |
| 1294 const Extension* extension = GetExtensionById(params->extension_id); | |
| 1295 if (!extension) | |
| 1296 return RespondNow(Error(kNoSuchExtensionError)); | |
| 1297 | |
| 1298 content::WebContents* web_contents = GetSenderWebContents(); | |
| 1299 if (!web_contents) | |
| 1300 return RespondNow(Error(kCouldNotFindWebContentsError)); | |
| 1301 | |
| 1302 scoped_refptr<WebstoreReinstaller> reinstaller(new WebstoreReinstaller( | |
| 1303 web_contents, | |
| 1304 params->extension_id, | |
| 1305 base::Bind(&DeveloperPrivateRepairExtensionFunction::OnReinstallComplete, | |
| 1306 this))); | |
| 1307 reinstaller->BeginReinstall(); | |
| 1308 | |
| 1309 return RespondLater(); | |
| 1310 } | |
| 1311 | |
| 1312 void DeveloperPrivateRepairExtensionFunction::OnReinstallComplete( | |
| 1313 bool success, | |
| 1314 const std::string& error, | |
| 1315 webstore_install::Result result) { | |
| 1316 Respond(success ? NoArguments() : Error(error)); | |
| 1317 } | |
| 1318 | |
| 1319 DeveloperPrivateShowOptionsFunction::~DeveloperPrivateShowOptionsFunction() {} | |
| 1320 | |
| 1321 ExtensionFunction::ResponseAction DeveloperPrivateShowOptionsFunction::Run() { | |
| 1322 scoped_ptr<developer::ShowOptions::Params> params( | |
| 1323 developer::ShowOptions::Params::Create(*args_)); | |
| 1324 EXTENSION_FUNCTION_VALIDATE(params); | |
| 1325 const Extension* extension = GetEnabledExtensionById(params->extension_id); | |
| 1326 if (!extension) | |
| 1327 return RespondNow(Error(kNoSuchExtensionError)); | |
|
Dan Beam
2015/04/16 18:04:15
nit: \n
Devlin
2015/04/16 22:22:34
Done.
| |
| 1328 if (OptionsPageInfo::GetOptionsPage(extension).is_empty()) | |
| 1329 return RespondNow(Error(kNoOptionsPageForExtensionError)); | |
|
Dan Beam
2015/04/16 18:04:15
nit: \n
Devlin
2015/04/16 22:22:33
Done.
| |
| 1330 content::WebContents* web_contents = GetSenderWebContents(); | |
| 1331 if (!web_contents) | |
| 1332 return RespondNow(Error(kCouldNotFindWebContentsError)); | |
|
Dan Beam
2015/04/16 18:04:15
nit: \n
Devlin
2015/04/16 22:22:34
Done.
| |
| 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 |