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

Side by Side Diff: trunk/src/chrome/browser/extensions/api/developer_private/developer_private_api.cc

Issue 26511002: Revert 227477 "Refactored loading of applications / extensions i..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 2 months 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) 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"
31 #include "chrome/browser/extensions/management_policy.h" 30 #include "chrome/browser/extensions/management_policy.h"
32 #include "chrome/browser/extensions/unpacked_installer.h" 31 #include "chrome/browser/extensions/unpacked_installer.h"
33 #include "chrome/browser/extensions/updater/extension_updater.h" 32 #include "chrome/browser/extensions/updater/extension_updater.h"
34 #include "chrome/browser/platform_util.h" 33 #include "chrome/browser/platform_util.h"
35 #include "chrome/browser/profiles/profile.h" 34 #include "chrome/browser/profiles/profile.h"
36 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_servi ce.h" 35 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_servi ce.h"
37 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" 36 #include "chrome/browser/sync_file_system/syncable_file_system_util.h"
38 #include "chrome/browser/ui/chrome_select_file_policy.h" 37 #include "chrome/browser/ui/chrome_select_file_policy.h"
39 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 38 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
40 #include "chrome/common/extensions/api/developer_private.h" 39 #include "chrome/common/extensions/api/developer_private.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 78
80 namespace { 79 namespace {
81 80
82 const base::FilePath::CharType kUnpackedAppsFolder[] 81 const base::FilePath::CharType kUnpackedAppsFolder[]
83 = FILE_PATH_LITERAL("apps_target"); 82 = FILE_PATH_LITERAL("apps_target");
84 83
85 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { 84 ExtensionUpdater* GetExtensionUpdater(Profile* profile) {
86 return profile->GetExtensionService()->updater(); 85 return profile->GetExtensionService()->updater();
87 } 86 }
88 87
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
89 std::vector<base::FilePath> ListFolder(const base::FilePath path) { 127 std::vector<base::FilePath> ListFolder(const base::FilePath path) {
90 base::FileEnumerator files(path, false, 128 base::FileEnumerator files(path, false,
91 base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES); 129 base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES);
92 std::vector<base::FilePath> paths; 130 std::vector<base::FilePath> paths;
93 131
94 for (base::FilePath current_path = files.Next(); !current_path.empty(); 132 for (base::FilePath current_path = files.Next(); !current_path.empty();
95 current_path = files.Next()) { 133 current_path = files.Next()) {
96 paths.push_back(current_path); 134 paths.push_back(current_path);
97 } 135 }
98 return paths; 136 return paths;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 } 367 }
330 368
331 info->may_disable = system->management_policy()-> 369 info->may_disable = system->management_policy()->
332 UserMayModifySettings(&item, NULL); 370 UserMayModifySettings(&item, NULL);
333 info->is_app = item.is_app(); 371 info->is_app = item.is_app();
334 info->views = GetInspectablePagesForExtension(&item, item_is_enabled); 372 info->views = GetInspectablePagesForExtension(&item, item_is_enabled);
335 373
336 return info.Pass(); 374 return info.Pass();
337 } 375 }
338 376
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
339 void DeveloperPrivateGetItemsInfoFunction:: 398 void DeveloperPrivateGetItemsInfoFunction::
340 GetInspectablePagesForExtensionProcess( 399 GetInspectablePagesForExtensionProcess(
341 const Extension* extension, 400 const Extension* extension,
342 const std::set<content::RenderViewHost*>& views, 401 const std::set<content::RenderViewHost*>& views,
343 ItemInspectViewList* result) { 402 ItemInspectViewList* result) {
344 bool has_generated_background_page = 403 bool has_generated_background_page =
345 BackgroundInfo::HasGeneratedBackgroundPage(extension); 404 BackgroundInfo::HasGeneratedBackgroundPage(extension);
346 for (std::set<content::RenderViewHost*>::const_iterator iter = views.begin(); 405 for (std::set<content::RenderViewHost*>::const_iterator iter = views.begin();
347 iter != views.end(); ++iter) { 406 iter != views.end(); ++iter) {
348 content::RenderViewHost* host = *iter; 407 content::RenderViewHost* host = *iter;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 items.InsertAll(*service->extensions()); 547 items.InsertAll(*service->extensions());
489 548
490 if (include_disabled) { 549 if (include_disabled) {
491 items.InsertAll(*service->disabled_extensions()); 550 items.InsertAll(*service->disabled_extensions());
492 } 551 }
493 552
494 if (include_terminated) { 553 if (include_terminated) {
495 items.InsertAll(*service->terminated_extensions()); 554 items.InsertAll(*service->terminated_extensions());
496 } 555 }
497 556
557 std::map<std::string, ExtensionResource> id_to_icon;
558 ItemInfoList item_list;
559
498 for (ExtensionSet::const_iterator iter = items.begin(); 560 for (ExtensionSet::const_iterator iter = items.begin();
499 iter != items.end(); ++iter) { 561 iter != items.end(); ++iter) {
500 const Extension& item = *iter->get(); 562 const Extension& item = *iter->get();
501 563
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
502 // Don't show component extensions and invisible apps. 570 // Don't show component extensions and invisible apps.
503 if (item.ShouldNotBeVisible()) 571 if (item.ShouldNotBeVisible())
504 continue; 572 continue;
505 573
506 item_list_.push_back(make_linked_ptr<developer::ItemInfo>( 574 item_list.push_back(make_linked_ptr<developer::ItemInfo>(
507 CreateItemInfo( 575 CreateItemInfo(
508 item, service->IsExtensionEnabled(item.id())).release())); 576 item, service->IsExtensionEnabled(item.id())).release()));
509 } 577 }
510 578
511 // Iterate over |item_list_| to request all the icons. 579 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
512 RequestNextIcon(); 580 base::Bind(&DeveloperPrivateGetItemsInfoFunction::GetIconsOnFileThread,
581 this,
582 item_list,
583 id_to_icon));
513 584
514 return true; 585 return true;
515 } 586 }
516 587
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
547 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {} 588 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {}
548 589
549 bool DeveloperPrivateAllowFileAccessFunction::RunImpl() { 590 bool DeveloperPrivateAllowFileAccessFunction::RunImpl() {
550 scoped_ptr<AllowFileAccess::Params> params( 591 scoped_ptr<AllowFileAccess::Params> params(
551 AllowFileAccess::Params::Create(*args_)); 592 AllowFileAccess::Params::Create(*args_));
552 EXTENSION_FUNCTION_VALIDATE(params.get()); 593 EXTENSION_FUNCTION_VALIDATE(params.get());
553 594
554 EXTENSION_FUNCTION_VALIDATE(user_gesture_); 595 EXTENSION_FUNCTION_VALIDATE(user_gesture_);
555 596
556 ExtensionSystem* system = ExtensionSystem::Get(profile()); 597 ExtensionSystem* system = ExtensionSystem::Get(profile());
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 return true; 1341 return true;
1301 } 1342 }
1302 1343
1303 DeveloperPrivateIsProfileManagedFunction:: 1344 DeveloperPrivateIsProfileManagedFunction::
1304 ~DeveloperPrivateIsProfileManagedFunction() { 1345 ~DeveloperPrivateIsProfileManagedFunction() {
1305 } 1346 }
1306 1347
1307 } // namespace api 1348 } // namespace api
1308 1349
1309 } // namespace extensions 1350 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698