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_out) { |
| 25 DCHECK(context); |
| 26 DCHECK(icon_out); |
| 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 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_out->size()) { |
| 55 *badge_image = gfx::ImageSkiaOperations::CreateResizedImage( |
| 56 *badge_image, skia::ImageOperations::RESIZE_BEST, icon_out->size()); |
| 57 } |
| 58 *icon_out = gfx::ImageSkiaOperations::CreateSuperimposedImage(*icon_out, |
| 59 *badge_image); |
| 60 return true; |
| 61 } |
| 62 |
| 63 } // namespace util |
| 64 } // namespace extensions |
OLD | NEW |