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/ui/extensions/extension_installed_notification.h" | |
| 6 | |
| 7 #include "ash/shell.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "chrome/browser/browser_process.h" | |
| 10 #include "chrome/browser/extensions/extension_util.h" | |
| 11 #include "chrome/browser/notifications/notification.h" | |
| 12 #include "chrome/browser/notifications/notification_ui_manager.h" | |
| 13 #include "chrome/browser/notifications/notifier_state_tracker.h" | |
| 14 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" | |
| 15 #include "chrome/browser/ui/extensions/app_launch_params.h" | |
| 16 #include "chrome/browser/ui/extensions/application_launch.h" | |
| 17 #include "content/public/browser/browser_thread.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 #include "ui/message_center/notification.h" | |
|
benwells
2016/05/25 05:31:31
Nit: This is a lot of includes, are these all need
yoshiki
2016/05/30 06:56:01
I checked the includes and removed/replaced unnece
| |
| 23 | |
| 24 namespace { | |
| 25 const char* kNotifierId = "app.downloaded-notification"; | |
| 26 const char* kNotificationId = "EXTENSION_INSTALLED_NOTIFICATION"; | |
| 27 } // anonymouse namespace | |
|
benwells
2016/05/25 05:31:31
Nit: no rodents please!
yoshiki
2016/05/30 06:56:01
Ahh, Fixed.
| |
| 28 | |
| 29 using content::BrowserThread; | |
| 30 | |
| 31 // static | |
| 32 void ExtensionInstalledNotification::Show( | |
| 33 const extensions::Extension* extension, Profile* profile) { | |
| 34 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 35 DCHECK(g_browser_process->notification_ui_manager()); | |
| 36 | |
| 37 // The instance is self-owned (and ref-counted). It's lifetime is managed by | |
| 38 // itself (ancestor NotificationDelegate actually). | |
|
benwells
2016/05/25 05:31:31
Nit: Please rephrase this as: "It's lifetime is ma
yoshiki
2016/05/30 06:56:01
Thank you for guidance. Done.
| |
| 39 new ExtensionInstalledNotification(extension, profile); | |
| 40 } | |
| 41 | |
| 42 ExtensionInstalledNotification::ExtensionInstalledNotification( | |
| 43 const extensions::Extension* extension, Profile* profile) | |
| 44 : extension_id_(extension->id()), profile_(profile) { | |
| 45 | |
| 46 message_center::RichNotificationData optional_field; | |
| 47 std::unique_ptr<Notification> notification(new Notification( | |
| 48 message_center::NOTIFICATION_TYPE_SIMPLE, | |
| 49 base::UTF8ToUTF16(extension->name()), | |
| 50 l10n_util::GetStringUTF16(IDS_EXTENSION_NOTIFICATION_INSTALLED), | |
| 51 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 52 IDR_NOTIFICATION_EXTENSION_INSTALLED), | |
| 53 message_center::NotifierId( | |
| 54 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId), | |
| 55 base::string16() /* display_source */, GURL() /* origin_url */, | |
| 56 kNotificationId, optional_field, this)); | |
| 57 g_browser_process->notification_ui_manager()->Add(*notification, profile_); | |
| 58 } | |
| 59 | |
| 60 ExtensionInstalledNotification::~ExtensionInstalledNotification() {} | |
| 61 | |
| 62 void ExtensionInstalledNotification::Click() { | |
| 63 if (!extensions::util::IsAppLaunchable(extension_id_, profile_)) | |
| 64 return; | |
| 65 | |
| 66 const extensions::Extension* extension = | |
|
benwells
2016/05/25 05:31:31
Nit: IWYU, please add relevant headers for this.
yoshiki
2016/05/30 06:56:01
Done.
| |
| 67 extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( | |
| 68 extension_id_, extensions::ExtensionRegistry::EVERYTHING); | |
| 69 if (!extension) | |
| 70 return; | |
| 71 | |
| 72 AppLaunchParams params = CreateAppLaunchParamsUserContainer( | |
| 73 profile_, extension, NEW_FOREGROUND_TAB, | |
| 74 extensions::SOURCE_INSTALLED_NOTIFICATION); | |
| 75 OpenApplication(params); | |
| 76 } | |
| 77 | |
| 78 std::string ExtensionInstalledNotification::id() const { | |
| 79 return kNotificationId; | |
| 80 } | |
| OLD | NEW |