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/ui/extensions/extension_installed_notification.h" |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/extensions/extension_util.h" |
| 10 #include "chrome/browser/notifications/notification.h" |
| 11 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 12 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 13 #include "chrome/browser/ui/extensions/application_launch.h" |
| 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "extensions/browser/extension_registry.h" |
| 16 #include "extensions/common/extension.h" |
| 17 #include "extensions/common/extension_urls.h" |
| 18 #include "grit/generated_resources.h" |
| 19 #include "grit/theme_resources.h" |
| 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/base/resource/resource_bundle.h" |
| 22 |
| 23 namespace { |
| 24 const char* kNotifierId = "app.downloaded-notification"; |
| 25 const char* kNotificationId = "EXTENSION_INSTALLED_NOTIFICATION"; |
| 26 } // anonymous namespace |
| 27 |
| 28 using content::BrowserThread; |
| 29 |
| 30 // static |
| 31 void ExtensionInstalledNotification::Show( |
| 32 const extensions::Extension* extension, Profile* profile) { |
| 33 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 34 DCHECK(g_browser_process->notification_ui_manager()); |
| 35 |
| 36 // It's lifetime is managed by the parent class NotificationDelegate. |
| 37 new ExtensionInstalledNotification(extension, profile); |
| 38 } |
| 39 |
| 40 ExtensionInstalledNotification::ExtensionInstalledNotification( |
| 41 const extensions::Extension* extension, Profile* profile) |
| 42 : extension_id_(extension->id()), profile_(profile) { |
| 43 |
| 44 message_center::RichNotificationData optional_field; |
| 45 std::unique_ptr<Notification> notification(new Notification( |
| 46 message_center::NOTIFICATION_TYPE_SIMPLE, |
| 47 base::UTF8ToUTF16(extension->name()), |
| 48 l10n_util::GetStringUTF16(IDS_EXTENSION_NOTIFICATION_INSTALLED), |
| 49 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 50 IDR_NOTIFICATION_EXTENSION_INSTALLED), |
| 51 message_center::NotifierId( |
| 52 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId), |
| 53 base::string16() /* display_source */, |
| 54 GURL(extension_urls::kChromeWebstoreBaseURL) /* origin_url */, |
| 55 kNotificationId, optional_field, this)); |
| 56 g_browser_process->notification_ui_manager()->Add(*notification, profile_); |
| 57 } |
| 58 |
| 59 ExtensionInstalledNotification::~ExtensionInstalledNotification() {} |
| 60 |
| 61 void ExtensionInstalledNotification::Click() { |
| 62 if (!extensions::util::IsAppLaunchable(extension_id_, profile_)) |
| 63 return; |
| 64 |
| 65 const extensions::Extension* extension = |
| 66 extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( |
| 67 extension_id_, extensions::ExtensionRegistry::EVERYTHING); |
| 68 if (!extension) |
| 69 return; |
| 70 |
| 71 AppLaunchParams params = CreateAppLaunchParamsUserContainer( |
| 72 profile_, extension, NEW_FOREGROUND_TAB, |
| 73 extensions::SOURCE_INSTALLED_NOTIFICATION); |
| 74 OpenApplication(params); |
| 75 } |
| 76 |
| 77 std::string ExtensionInstalledNotification::id() const { |
| 78 return kNotificationId; |
| 79 } |
OLD | NEW |