Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/extensions/gfx_utils.h" | |
| 6 | |
| 7 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | |
| 8 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | |
| 11 #include "chrome/common/pref_names.h" | |
| 12 #include "components/prefs/pref_service.h" | |
| 13 #include "extensions/browser/extension_registry.h" | |
| 14 #include "ui/base/resource/resource_bundle.h" | |
| 15 #include "ui/chromeos/resources/grit/ui_chromeos_resources.h" | |
| 16 #include "ui/gfx/image/image_skia.h" | |
| 17 #include "ui/gfx/image/image_skia_operations.h" | |
| 18 | |
| 19 namespace extensions { | |
| 20 namespace util { | |
| 21 | |
| 22 bool MaybeApplyChromeBadge(content::BrowserContext* context, | |
| 23 const std::string& extension_id, | |
| 24 gfx::ImageSkia* icon) { | |
|
oshima
2016/06/16 17:55:56
nit: icon_out
| |
| 25 DCHECK(context); | |
| 26 DCHECK(icon); | |
| 27 | |
| 28 Profile* profile = Profile::FromBrowserContext(context); | |
| 29 // Only apply Chrome badge for the primary profile. | |
| 30 if (!chromeos::ProfileHelper::IsPrimaryProfile(profile) || | |
| 31 !multi_user_util::IsProfileFromActiveUser(profile)) { | |
| 32 return false; | |
| 33 } | |
| 34 | |
| 35 arc::ArcAuthService* arc_auth_service = arc::ArcAuthService::Get(); | |
| 36 if (!arc_auth_service || | |
| 37 arc_auth_service->state() != arc::ArcAuthService::State::ACTIVE) { | |
| 38 return false; | |
| 39 } | |
| 40 | |
| 41 const ExtensionRegistry* registry = ExtensionRegistry::Get(context); | |
| 42 if (!registry) | |
| 43 return false; | |
| 44 | |
| 45 const Extension* extension = registry->GetInstalledExtension(extension_id); | |
| 46 if (!extension || !extension->is_hosted_app()) | |
| 47 return false; | |
| 48 | |
| 49 const gfx::ImageSkia* badge_image = | |
| 50 ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 51 IDR_ARC_DUAL_ICON_BADGE); | |
| 52 DCHECK(badge_image); | |
| 53 | |
| 54 if (badge_image->size() == icon->size()) { | |
|
oshima
2016/06/16 17:55:56
if (badge_image->size() != icon->size())
badge_i
| |
| 55 *icon = | |
| 56 gfx::ImageSkiaOperations::CreateSuperimposedImage(*icon, *badge_image); | |
| 57 } else { | |
| 58 *icon = gfx::ImageSkiaOperations::CreateSuperimposedImage( | |
| 59 *icon, | |
| 60 gfx::ImageSkiaOperations::CreateResizedImage( | |
| 61 *badge_image, skia::ImageOperations::RESIZE_BEST, icon->size())); | |
| 62 } | |
| 63 return true; | |
| 64 } | |
| 65 | |
| 66 } // namespace util | |
| 67 } // namespace extensions | |
| OLD | NEW |