Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(993)

Side by Side Diff: chrome/browser/usb/web_usb_detector.cc

Issue 2146663002: Move //components/webusb/ to //chrome/browser/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merged web_usb_browser_client.* to web_usb_detector.* Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/usb/web_usb_detector.h ('k') | chrome/browser/usb/web_usb_detector_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/usb/web_usb_detector.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/common/system/system_notifier.h" 9 #include "ash/common/system/system_notifier.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/net/referrer.h" 13 #include "chrome/browser/net/referrer.h"
14 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 16 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
17 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
18 #include "chrome/grit/theme_resources.h" 18 #include "chrome/grit/theme_resources.h"
19 #include "content/public/common/origin_util.h" 19 #include "content/public/common/origin_util.h"
20 #include "device/core/device_client.h"
21 #include "device/usb/usb_device.h"
22 #include "device/usb/usb_ids.h"
20 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/page_transition_types.h" 24 #include "ui/base/page_transition_types.h"
22 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/base/window_open_disposition.h" 26 #include "ui/base/window_open_disposition.h"
24 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
25 #include "ui/message_center/message_center.h" 28 #include "ui/message_center/message_center.h"
26 #include "ui/message_center/notification.h" 29 #include "ui/message_center/notification.h"
27 #include "ui/message_center/notification_delegate.h" 30 #include "ui/message_center/notification_delegate.h"
28 #include "url/gurl.h" 31 #include "url/gurl.h"
29 32
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 103
101 GURL landing_page_; 104 GURL landing_page_;
102 std::string notification_id_; 105 std::string notification_id_;
103 bool clicked_ = false; 106 bool clicked_ = false;
104 107
105 DISALLOW_COPY_AND_ASSIGN(WebUsbNotificationDelegate); 108 DISALLOW_COPY_AND_ASSIGN(WebUsbNotificationDelegate);
106 }; 109 };
107 110
108 } // namespace 111 } // namespace
109 112
110 ChromeWebUsbBrowserClient::ChromeWebUsbBrowserClient() {} 113 WebUsbDetector::WebUsbDetector() : observer_(this) {
114 Initialize();
115 }
111 116
112 ChromeWebUsbBrowserClient::~ChromeWebUsbBrowserClient() {} 117 WebUsbDetector::~WebUsbDetector() {}
113 118
114 void ChromeWebUsbBrowserClient::OnDeviceAdded( 119 void WebUsbDetector::Initialize() {
115 const base::string16& product_name, 120 device::UsbService* usb_service =
116 const GURL& landing_page, 121 device::DeviceClient::Get()->GetUsbService();
117 const std::string& notification_id) { 122 if (!usb_service)
118 if (!content::IsOriginSecure(landing_page)) { 123 return;
124
125 observer_.Add(usb_service);
126 }
127
128 void WebUsbDetector::OnDeviceAdded(scoped_refptr<device::UsbDevice> device) {
129 const base::string16& product_name = device->product_string();
130 if (product_name.empty()) {
119 return; 131 return;
120 } 132 }
121 133
134 const GURL& landing_page = device->webusb_landing_page();
135 if (!landing_page.is_valid() || !content::IsOriginSecure(landing_page)) {
136 return;
137 }
138
139 std::string notification_id = device->guid();
140
122 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 141 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
123 message_center::RichNotificationData rich_notification_data; 142 message_center::RichNotificationData rich_notification_data;
124 std::unique_ptr<message_center::Notification> notification( 143 std::unique_ptr<message_center::Notification> notification(
125 new message_center::Notification( 144 new message_center::Notification(
126 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, 145 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id,
127 l10n_util::GetStringFUTF16( 146 l10n_util::GetStringFUTF16(
128 IDS_WEBUSB_DEVICE_DETECTED_NOTIFICATION_TITLE, product_name), 147 IDS_WEBUSB_DEVICE_DETECTED_NOTIFICATION_TITLE, product_name),
129 l10n_util::GetStringFUTF16( 148 l10n_util::GetStringFUTF16(
130 IDS_WEBUSB_DEVICE_DETECTED_NOTIFICATION, 149 IDS_WEBUSB_DEVICE_DETECTED_NOTIFICATION,
131 base::UTF8ToUTF16(landing_page.GetContent())), 150 base::UTF8ToUTF16(landing_page.GetContent())),
132 rb.GetNativeImageNamed(IDR_USB_NOTIFICATION_ICON), base::string16(), 151 rb.GetNativeImageNamed(IDR_USB_NOTIFICATION_ICON), base::string16(),
133 GURL(), 152 GURL(),
134 message_center::NotifierId( 153 message_center::NotifierId(
135 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierWebUsb), 154 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierWebUsb),
136 rich_notification_data, 155 rich_notification_data,
137 new WebUsbNotificationDelegate(landing_page, notification_id))); 156 new WebUsbNotificationDelegate(landing_page, notification_id)));
138 157
139 notification->SetSystemPriority(); 158 notification->SetSystemPriority();
140 message_center::MessageCenter::Get()->AddNotification( 159 message_center::MessageCenter::Get()->AddNotification(
141 std::move(notification)); 160 std::move(notification));
142 } 161 }
143 162
144 void ChromeWebUsbBrowserClient::OnDeviceRemoved( 163 void WebUsbDetector::OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) {
145 const std::string& notification_id) { 164 std::string notification_id = device->guid();
146 message_center::MessageCenter* message_center = 165 message_center::MessageCenter* message_center =
147 message_center::MessageCenter::Get(); 166 message_center::MessageCenter::Get();
148 if (message_center->FindVisibleNotificationById(notification_id)) { 167 if (message_center->FindVisibleNotificationById(notification_id)) {
149 message_center->RemoveNotification(notification_id, false /* by_user */); 168 message_center->RemoveNotification(notification_id, false /* by_user */);
150 } 169 }
151 } 170 }
OLDNEW
« no previous file with comments | « chrome/browser/usb/web_usb_detector.h ('k') | chrome/browser/usb/web_usb_detector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698