OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chrome_webusb_browser_client.h" | 5 #include "chrome/browser/chrome_webusb_browser_client.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/net/referrer.h" | 8 #include "chrome/browser/net/referrer.h" |
9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/host_desktop.h" | 11 #include "chrome/browser/ui/host_desktop.h" |
12 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 12 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
| 14 #include "chrome/grit/theme_resources.h" |
14 #include "content/public/common/origin_util.h" | 15 #include "content/public/common/origin_util.h" |
15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/base/page_transition_types.h" | 17 #include "ui/base/page_transition_types.h" |
| 18 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/base/window_open_disposition.h" | 19 #include "ui/base/window_open_disposition.h" |
18 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
19 #include "ui/message_center/message_center.h" | 21 #include "ui/message_center/message_center.h" |
20 #include "ui/message_center/notification.h" | 22 #include "ui/message_center/notification.h" |
21 #include "ui/message_center/notification_delegate.h" | 23 #include "ui/message_center/notification_delegate.h" |
22 #include "url/gurl.h" | 24 #include "url/gurl.h" |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 const char kWebUsbDetectorNotificationID[] = "webusb.detector"; | 28 const char kWebUsbDetectorNotificationID[] = "webusb.detector"; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 ChromeWebUsbBrowserClient::~ChromeWebUsbBrowserClient() {} | 69 ChromeWebUsbBrowserClient::~ChromeWebUsbBrowserClient() {} |
68 | 70 |
69 void ChromeWebUsbBrowserClient::OnDeviceAdded( | 71 void ChromeWebUsbBrowserClient::OnDeviceAdded( |
70 const base::string16& product_name, | 72 const base::string16& product_name, |
71 const GURL& landing_page, | 73 const GURL& landing_page, |
72 const std::string& notification_id) { | 74 const std::string& notification_id) { |
73 if (!content::IsOriginSecure(landing_page)) { | 75 if (!content::IsOriginSecure(landing_page)) { |
74 return; | 76 return; |
75 } | 77 } |
76 | 78 |
| 79 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
77 message_center::RichNotificationData rich_notification_data; | 80 message_center::RichNotificationData rich_notification_data; |
78 scoped_ptr<message_center::Notification> notification( | 81 scoped_ptr<message_center::Notification> notification( |
79 new message_center::Notification( | 82 new message_center::Notification( |
80 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, | 83 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, |
81 l10n_util::GetStringFUTF16( | 84 l10n_util::GetStringFUTF16( |
82 IDS_WEBUSB_DEVICE_DETECTED_NOTIFICATION_TITLE, product_name), | 85 IDS_WEBUSB_DEVICE_DETECTED_NOTIFICATION_TITLE, product_name), |
83 l10n_util::GetStringFUTF16( | 86 l10n_util::GetStringFUTF16( |
84 IDS_WEBUSB_DEVICE_DETECTED_NOTIFICATION, | 87 IDS_WEBUSB_DEVICE_DETECTED_NOTIFICATION, |
85 base::UTF8ToUTF16(landing_page.GetContent())), | 88 base::UTF8ToUTF16(landing_page.GetContent())), |
86 // TODO(juncai): use generic USB device icon here. | 89 rb.GetNativeImageNamed(IDR_USB_NOTIFICATION_ICON), |
87 gfx::Image(), base::string16(), GURL(), | 90 base::string16(), GURL(), |
88 message_center::NotifierId( | 91 message_center::NotifierId( |
89 message_center::NotifierId::SYSTEM_COMPONENT, | 92 message_center::NotifierId::SYSTEM_COMPONENT, |
90 kWebUsbDetectorNotificationID), | 93 kWebUsbDetectorNotificationID), |
91 rich_notification_data, | 94 rich_notification_data, |
92 new WebUsbNotificationDelegate(landing_page, notification_id))); | 95 new WebUsbNotificationDelegate(landing_page, notification_id))); |
93 | 96 |
94 notification->SetSystemPriority(); | 97 notification->SetSystemPriority(); |
95 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); | 98 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); |
96 } | 99 } |
97 | 100 |
98 void ChromeWebUsbBrowserClient::OnDeviceRemoved( | 101 void ChromeWebUsbBrowserClient::OnDeviceRemoved( |
99 const std::string& notification_id) { | 102 const std::string& notification_id) { |
100 message_center::MessageCenter* message_center = | 103 message_center::MessageCenter* message_center = |
101 message_center::MessageCenter::Get(); | 104 message_center::MessageCenter::Get(); |
102 if (message_center->FindVisibleNotificationById(notification_id)) { | 105 if (message_center->FindVisibleNotificationById(notification_id)) { |
103 message_center->RemoveNotification(notification_id, false /* by_user */); | 106 message_center->RemoveNotification(notification_id, false /* by_user */); |
104 } | 107 } |
105 } | 108 } |
OLD | NEW |