| 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 "apps/app_load_service.h" | 7 #include "apps/app_load_service.h" |
| 8 #include "apps/app_restore_service.h" | 8 #include "apps/app_restore_service.h" |
| 9 #include "apps/saved_files_service.h" | 9 #include "apps/saved_files_service.h" |
| 10 #include "apps/shell_window.h" | 10 #include "apps/shell_window.h" |
| 11 #include "apps/shell_window_registry.h" | 11 #include "apps/shell_window_registry.h" |
| 12 #include "base/base64.h" | 12 #include "base/base64.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/files/file_enumerator.h" | 15 #include "base/files/file_enumerator.h" |
| 16 #include "base/i18n/file_util_icu.h" | 16 #include "base/i18n/file_util_icu.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 21 #include "chrome/browser/devtools/devtools_window.h" | 21 #include "chrome/browser/devtools/devtools_window.h" |
| 22 #include "chrome/browser/extensions/api/developer_private/developer_private_api_
factory.h" | 22 #include "chrome/browser/extensions/api/developer_private/developer_private_api_
factory.h" |
| 23 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" | 23 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" |
| 24 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 24 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 25 #include "chrome/browser/extensions/devtools_util.h" | 25 #include "chrome/browser/extensions/devtools_util.h" |
| 26 #include "chrome/browser/extensions/extension_disabled_ui.h" | 26 #include "chrome/browser/extensions/extension_disabled_ui.h" |
| 27 #include "chrome/browser/extensions/extension_error_reporter.h" | 27 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 28 #include "chrome/browser/extensions/extension_service.h" | 28 #include "chrome/browser/extensions/extension_service.h" |
| 29 #include "chrome/browser/extensions/extension_system.h" | 29 #include "chrome/browser/extensions/extension_system.h" |
| 30 #include "chrome/browser/extensions/image_loader.h" |
| 30 #include "chrome/browser/extensions/management_policy.h" | 31 #include "chrome/browser/extensions/management_policy.h" |
| 31 #include "chrome/browser/extensions/unpacked_installer.h" | 32 #include "chrome/browser/extensions/unpacked_installer.h" |
| 32 #include "chrome/browser/extensions/updater/extension_updater.h" | 33 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 33 #include "chrome/browser/platform_util.h" | 34 #include "chrome/browser/platform_util.h" |
| 34 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
| 35 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_servi
ce.h" | 36 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_servi
ce.h" |
| 36 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 37 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
| 37 #include "chrome/browser/ui/chrome_select_file_policy.h" | 38 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 38 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 39 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 39 #include "chrome/common/extensions/api/developer_private.h" | 40 #include "chrome/common/extensions/api/developer_private.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 79 |
| 79 namespace { | 80 namespace { |
| 80 | 81 |
| 81 const base::FilePath::CharType kUnpackedAppsFolder[] | 82 const base::FilePath::CharType kUnpackedAppsFolder[] |
| 82 = FILE_PATH_LITERAL("apps_target"); | 83 = FILE_PATH_LITERAL("apps_target"); |
| 83 | 84 |
| 84 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { | 85 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { |
| 85 return profile->GetExtensionService()->updater(); | 86 return profile->GetExtensionService()->updater(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 GURL GetImageURLFromData(std::string contents) { | |
| 89 std::string contents_base64; | |
| 90 if (!base::Base64Encode(contents, &contents_base64)) | |
| 91 return GURL(); | |
| 92 | |
| 93 // TODO(dvh): make use of chrome::kDataScheme. Filed as crbug/297301. | |
| 94 const char kDataURLPrefix[] = "data:image;base64,"; | |
| 95 return GURL(kDataURLPrefix + contents_base64); | |
| 96 } | |
| 97 | |
| 98 GURL GetDefaultImageURL(developer_private::ItemType type) { | |
| 99 int icon_resource_id; | |
| 100 switch (type) { | |
| 101 case developer::ITEM_TYPE_LEGACY_PACKAGED_APP: | |
| 102 case developer::ITEM_TYPE_HOSTED_APP: | |
| 103 case developer::ITEM_TYPE_PACKAGED_APP: | |
| 104 icon_resource_id = IDR_APP_DEFAULT_ICON; | |
| 105 break; | |
| 106 default: | |
| 107 icon_resource_id = IDR_EXTENSION_DEFAULT_ICON; | |
| 108 break; | |
| 109 } | |
| 110 | |
| 111 return GetImageURLFromData( | |
| 112 ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( | |
| 113 icon_resource_id, ui::SCALE_FACTOR_100P).as_string()); | |
| 114 } | |
| 115 | |
| 116 // TODO(dvh): This code should be refactored and moved to | |
| 117 // extensions::ImageLoader. Also a resize should be performed to avoid | |
| 118 // potential huge URLs: crbug/297298. | |
| 119 GURL ToDataURL(const base::FilePath& path, developer_private::ItemType type) { | |
| 120 std::string contents; | |
| 121 if (path.empty() || !base::ReadFileToString(path, &contents)) | |
| 122 return GetDefaultImageURL(type); | |
| 123 | |
| 124 return GetImageURLFromData(contents); | |
| 125 } | |
| 126 | |
| 127 std::vector<base::FilePath> ListFolder(const base::FilePath path) { | 89 std::vector<base::FilePath> ListFolder(const base::FilePath path) { |
| 128 base::FileEnumerator files(path, false, | 90 base::FileEnumerator files(path, false, |
| 129 base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES); | 91 base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES); |
| 130 std::vector<base::FilePath> paths; | 92 std::vector<base::FilePath> paths; |
| 131 | 93 |
| 132 for (base::FilePath current_path = files.Next(); !current_path.empty(); | 94 for (base::FilePath current_path = files.Next(); !current_path.empty(); |
| 133 current_path = files.Next()) { | 95 current_path = files.Next()) { |
| 134 paths.push_back(current_path); | 96 paths.push_back(current_path); |
| 135 } | 97 } |
| 136 return paths; | 98 return paths; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } | 329 } |
| 368 | 330 |
| 369 info->may_disable = system->management_policy()-> | 331 info->may_disable = system->management_policy()-> |
| 370 UserMayModifySettings(&item, NULL); | 332 UserMayModifySettings(&item, NULL); |
| 371 info->is_app = item.is_app(); | 333 info->is_app = item.is_app(); |
| 372 info->views = GetInspectablePagesForExtension(&item, item_is_enabled); | 334 info->views = GetInspectablePagesForExtension(&item, item_is_enabled); |
| 373 | 335 |
| 374 return info.Pass(); | 336 return info.Pass(); |
| 375 } | 337 } |
| 376 | 338 |
| 377 void DeveloperPrivateGetItemsInfoFunction::GetIconsOnFileThread( | |
| 378 ItemInfoList item_list, | |
| 379 const std::map<std::string, ExtensionResource> idToIcon) { | |
| 380 for (ItemInfoList::iterator iter = item_list.begin(); | |
| 381 iter != item_list.end(); ++iter) { | |
| 382 developer_private::ItemInfo* info = iter->get(); | |
| 383 std::map<std::string, ExtensionResource>::const_iterator resource_ptr | |
| 384 = idToIcon.find(info->id); | |
| 385 if (resource_ptr != idToIcon.end()) { | |
| 386 info->icon_url = | |
| 387 ToDataURL(resource_ptr->second.GetFilePath(), info->type).spec(); | |
| 388 } | |
| 389 } | |
| 390 | |
| 391 results_ = developer::GetItemsInfo::Results::Create(item_list); | |
| 392 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
| 393 base::Bind(&DeveloperPrivateGetItemsInfoFunction::SendResponse, | |
| 394 this, | |
| 395 true)); | |
| 396 } | |
| 397 | |
| 398 void DeveloperPrivateGetItemsInfoFunction:: | 339 void DeveloperPrivateGetItemsInfoFunction:: |
| 399 GetInspectablePagesForExtensionProcess( | 340 GetInspectablePagesForExtensionProcess( |
| 400 const Extension* extension, | 341 const Extension* extension, |
| 401 const std::set<content::RenderViewHost*>& views, | 342 const std::set<content::RenderViewHost*>& views, |
| 402 ItemInspectViewList* result) { | 343 ItemInspectViewList* result) { |
| 403 bool has_generated_background_page = | 344 bool has_generated_background_page = |
| 404 BackgroundInfo::HasGeneratedBackgroundPage(extension); | 345 BackgroundInfo::HasGeneratedBackgroundPage(extension); |
| 405 for (std::set<content::RenderViewHost*>::const_iterator iter = views.begin(); | 346 for (std::set<content::RenderViewHost*>::const_iterator iter = views.begin(); |
| 406 iter != views.end(); ++iter) { | 347 iter != views.end(); ++iter) { |
| 407 content::RenderViewHost* host = *iter; | 348 content::RenderViewHost* host = *iter; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 items.InsertAll(*service->extensions()); | 488 items.InsertAll(*service->extensions()); |
| 548 | 489 |
| 549 if (include_disabled) { | 490 if (include_disabled) { |
| 550 items.InsertAll(*service->disabled_extensions()); | 491 items.InsertAll(*service->disabled_extensions()); |
| 551 } | 492 } |
| 552 | 493 |
| 553 if (include_terminated) { | 494 if (include_terminated) { |
| 554 items.InsertAll(*service->terminated_extensions()); | 495 items.InsertAll(*service->terminated_extensions()); |
| 555 } | 496 } |
| 556 | 497 |
| 557 std::map<std::string, ExtensionResource> id_to_icon; | |
| 558 ItemInfoList item_list; | |
| 559 | |
| 560 for (ExtensionSet::const_iterator iter = items.begin(); | 498 for (ExtensionSet::const_iterator iter = items.begin(); |
| 561 iter != items.end(); ++iter) { | 499 iter != items.end(); ++iter) { |
| 562 const Extension& item = *iter->get(); | 500 const Extension& item = *iter->get(); |
| 563 | 501 |
| 564 ExtensionResource item_resource = | |
| 565 IconsInfo::GetIconResource(&item, | |
| 566 extension_misc::EXTENSION_ICON_MEDIUM, | |
| 567 ExtensionIconSet::MATCH_BIGGER); | |
| 568 id_to_icon[item.id()] = item_resource; | |
| 569 | |
| 570 // Don't show component extensions and invisible apps. | 502 // Don't show component extensions and invisible apps. |
| 571 if (item.ShouldNotBeVisible()) | 503 if (item.ShouldNotBeVisible()) |
| 572 continue; | 504 continue; |
| 573 | 505 |
| 574 item_list.push_back(make_linked_ptr<developer::ItemInfo>( | 506 item_list_.push_back(make_linked_ptr<developer::ItemInfo>( |
| 575 CreateItemInfo( | 507 CreateItemInfo( |
| 576 item, service->IsExtensionEnabled(item.id())).release())); | 508 item, service->IsExtensionEnabled(item.id())).release())); |
| 577 } | 509 } |
| 578 | 510 |
| 579 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | 511 // Iterate over |item_list_| to request all the icons. |
| 580 base::Bind(&DeveloperPrivateGetItemsInfoFunction::GetIconsOnFileThread, | 512 RequestNextIcon(); |
| 581 this, | |
| 582 item_list, | |
| 583 id_to_icon)); | |
| 584 | 513 |
| 585 return true; | 514 return true; |
| 586 } | 515 } |
| 587 | 516 |
| 517 void DeveloperPrivateGetItemsInfoFunction::RequestNextIcon() { |
| 518 developer::ItemInfo* info = item_list_[icon_to_load_].get(); |
| 519 ExtensionService* service = profile()->GetExtensionService(); |
| 520 ImageLoader::Get(profile())->LoadExtensionIconDataURLAsync( |
| 521 service->GetExtensionById(info->id, true), |
| 522 extension_misc::EXTENSION_ICON_MEDIUM, |
| 523 ExtensionIconSet::MATCH_BIGGER, |
| 524 false, |
| 525 base::Bind(&DeveloperPrivateGetItemsInfoFunction::LoadIconFinished, |
| 526 this)); |
| 527 } |
| 528 |
| 529 void DeveloperPrivateGetItemsInfoFunction::LoadIconFinished(const GURL& url) { |
| 530 // Store the result. |
| 531 developer::ItemInfo* info = item_list_[icon_to_load_].get(); |
| 532 info->icon_url = url.spec(); |
| 533 ++icon_to_load_; |
| 534 if (icon_to_load_ < static_cast<int>(item_list_.size())) { |
| 535 RequestNextIcon(); |
| 536 } else { |
| 537 // All icons have been loaded: send the result. |
| 538 results_ = developer::GetItemsInfo::Results::Create(item_list_); |
| 539 SendResponse(true); |
| 540 } |
| 541 } |
| 542 |
| 543 DeveloperPrivateGetItemsInfoFunction::DeveloperPrivateGetItemsInfoFunction() |
| 544 : icon_to_load_(0) { |
| 545 } |
| 546 |
| 588 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {} | 547 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {} |
| 589 | 548 |
| 590 bool DeveloperPrivateAllowFileAccessFunction::RunImpl() { | 549 bool DeveloperPrivateAllowFileAccessFunction::RunImpl() { |
| 591 scoped_ptr<AllowFileAccess::Params> params( | 550 scoped_ptr<AllowFileAccess::Params> params( |
| 592 AllowFileAccess::Params::Create(*args_)); | 551 AllowFileAccess::Params::Create(*args_)); |
| 593 EXTENSION_FUNCTION_VALIDATE(params.get()); | 552 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 594 | 553 |
| 595 EXTENSION_FUNCTION_VALIDATE(user_gesture_); | 554 EXTENSION_FUNCTION_VALIDATE(user_gesture_); |
| 596 | 555 |
| 597 ExtensionSystem* system = ExtensionSystem::Get(profile()); | 556 ExtensionSystem* system = ExtensionSystem::Get(profile()); |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1341 return true; | 1300 return true; |
| 1342 } | 1301 } |
| 1343 | 1302 |
| 1344 DeveloperPrivateIsProfileManagedFunction:: | 1303 DeveloperPrivateIsProfileManagedFunction:: |
| 1345 ~DeveloperPrivateIsProfileManagedFunction() { | 1304 ~DeveloperPrivateIsProfileManagedFunction() { |
| 1346 } | 1305 } |
| 1347 | 1306 |
| 1348 } // namespace api | 1307 } // namespace api |
| 1349 | 1308 |
| 1350 } // namespace extensions | 1309 } // namespace extensions |
| OLD | NEW |