Chromium Code Reviews| Index: chrome/browser/ui/extensions/extension_installed_notification.cc |
| diff --git a/chrome/browser/ui/extensions/extension_installed_notification.cc b/chrome/browser/ui/extensions/extension_installed_notification.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..facf9d271cd68f816ca924a3ab2b90db7301b1b0 |
| --- /dev/null |
| +++ b/chrome/browser/ui/extensions/extension_installed_notification.cc |
| @@ -0,0 +1,80 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/extensions/extension_installed_notification.h" |
| + |
| +#include "ash/shell.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/extensions/extension_util.h" |
| +#include "chrome/browser/notifications/notification.h" |
| +#include "chrome/browser/notifications/notification_ui_manager.h" |
| +#include "chrome/browser/notifications/notifier_state_tracker.h" |
| +#include "chrome/browser/notifications/notifier_state_tracker_factory.h" |
| +#include "chrome/browser/ui/extensions/app_launch_params.h" |
| +#include "chrome/browser/ui/extensions/application_launch.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "grit/generated_resources.h" |
| +#include "grit/theme_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| +#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
|
| + |
| +namespace { |
| +const char* kNotifierId = "app.downloaded-notification"; |
| +const char* kNotificationId = "EXTENSION_INSTALLED_NOTIFICATION"; |
| +} // anonymouse namespace |
|
benwells
2016/05/25 05:31:31
Nit: no rodents please!
yoshiki
2016/05/30 06:56:01
Ahh, Fixed.
|
| + |
| +using content::BrowserThread; |
| + |
| +// static |
| +void ExtensionInstalledNotification::Show( |
| + const extensions::Extension* extension, Profile* profile) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + DCHECK(g_browser_process->notification_ui_manager()); |
| + |
| + // The instance is self-owned (and ref-counted). It's lifetime is managed by |
| + // 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.
|
| + new ExtensionInstalledNotification(extension, profile); |
| +} |
| + |
| +ExtensionInstalledNotification::ExtensionInstalledNotification( |
| + const extensions::Extension* extension, Profile* profile) |
| + : extension_id_(extension->id()), profile_(profile) { |
| + |
| + message_center::RichNotificationData optional_field; |
| + std::unique_ptr<Notification> notification(new Notification( |
| + message_center::NOTIFICATION_TYPE_SIMPLE, |
| + base::UTF8ToUTF16(extension->name()), |
| + l10n_util::GetStringUTF16(IDS_EXTENSION_NOTIFICATION_INSTALLED), |
| + ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| + IDR_NOTIFICATION_EXTENSION_INSTALLED), |
| + message_center::NotifierId( |
| + message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId), |
| + base::string16() /* display_source */, GURL() /* origin_url */, |
| + kNotificationId, optional_field, this)); |
| + g_browser_process->notification_ui_manager()->Add(*notification, profile_); |
| +} |
| + |
| +ExtensionInstalledNotification::~ExtensionInstalledNotification() {} |
| + |
| +void ExtensionInstalledNotification::Click() { |
| + if (!extensions::util::IsAppLaunchable(extension_id_, profile_)) |
| + return; |
| + |
| + 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.
|
| + extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( |
| + extension_id_, extensions::ExtensionRegistry::EVERYTHING); |
| + if (!extension) |
| + return; |
| + |
| + AppLaunchParams params = CreateAppLaunchParamsUserContainer( |
| + profile_, extension, NEW_FOREGROUND_TAB, |
| + extensions::SOURCE_INSTALLED_NOTIFICATION); |
| + OpenApplication(params); |
| +} |
| + |
| +std::string ExtensionInstalledNotification::id() const { |
| + return kNotificationId; |
| +} |