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

Side by Side Diff: chrome/browser/chrome_webusb_browser_client.cc

Issue 1360873003: Fix WebUSB notification on Chrome OS with no windows open. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update expected strings. Created 5 years, 3 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
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/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/browser_finder.h"
12 #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"
13 #include "chrome/grit/generated_resources.h" 13 #include "chrome/grit/generated_resources.h"
14 #include "content/public/common/origin_util.h" 14 #include "content/public/common/origin_util.h"
15 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/page_transition_types.h" 16 #include "ui/base/page_transition_types.h"
17 #include "ui/base/window_open_disposition.h" 17 #include "ui/base/window_open_disposition.h"
18 #include "ui/gfx/image/image.h" 18 #include "ui/gfx/image/image.h"
19 #include "ui/message_center/message_center.h" 19 #include "ui/message_center/message_center.h"
20 #include "ui/message_center/notification.h" 20 #include "ui/message_center/notification.h"
21 #include "ui/message_center/notification_delegate.h" 21 #include "ui/message_center/notification_delegate.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 namespace { 24 namespace {
25 25
26 const char kWebUsbDetectorNotificationID[] = "webusb.detector"; 26 const char kWebUsbDetectorNotificationID[] = "webusb.detector";
27 27
28 Browser* GetBrowser() {
29 chrome::ScopedTabbedBrowserDisplayer browser_displayer(
30 ProfileManager::GetActiveUserProfile(), chrome::GetActiveDesktop());
31 DCHECK(browser_displayer.browser());
32 return browser_displayer.browser();
33 }
34
28 void OpenURL(const GURL& url) { 35 void OpenURL(const GURL& url) {
29 Browser* browser = chrome::FindBrowserWithProfile( 36 GetBrowser()->OpenURL(
30 ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_NATIVE); 37 content::OpenURLParams(url, content::Referrer(), NEW_FOREGROUND_TAB,
31 content::OpenURLParams params(url, content::Referrer(), NEW_FOREGROUND_TAB, 38 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, true));
32 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, true);
33 browser->OpenURL(params);
34 } 39 }
35 40
36 // Delegate for webusb notification 41 // Delegate for webusb notification
37 class WebUsbNotificationDelegate : public message_center::NotificationDelegate { 42 class WebUsbNotificationDelegate : public message_center::NotificationDelegate {
38 public: 43 public:
39 WebUsbNotificationDelegate(const GURL& landing_page, 44 WebUsbNotificationDelegate(const GURL& landing_page,
40 const std::string& notification_id) 45 const std::string& notification_id)
41 : landing_page_(landing_page), notification_id_(notification_id) {} 46 : landing_page_(landing_page), notification_id_(notification_id) {}
42 47
43 void Click() override { 48 void Click() override {
(...skipping 18 matching lines...) Expand all
62 ChromeWebUsbBrowserClient::~ChromeWebUsbBrowserClient() {} 67 ChromeWebUsbBrowserClient::~ChromeWebUsbBrowserClient() {}
63 68
64 void ChromeWebUsbBrowserClient::OnDeviceAdded( 69 void ChromeWebUsbBrowserClient::OnDeviceAdded(
65 const base::string16& product_name, 70 const base::string16& product_name,
66 const GURL& landing_page, 71 const GURL& landing_page,
67 const std::string& notification_id) { 72 const std::string& notification_id) {
68 if (!content::IsOriginSecure(landing_page)) { 73 if (!content::IsOriginSecure(landing_page)) {
69 return; 74 return;
70 } 75 }
71 76
72 scoped_ptr<message_center::Notification> notification;
73
74 message_center::RichNotificationData rich_notification_data; 77 message_center::RichNotificationData rich_notification_data;
75 rich_notification_data.context_message = 78 scoped_ptr<message_center::Notification> notification(
76 base::UTF8ToUTF16(landing_page.GetContent()); 79 new message_center::Notification(
77 80 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id,
78 notification.reset(new message_center::Notification( 81 l10n_util::GetStringFUTF16(
79 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, 82 IDS_WEBUSB_DEVICE_DETECTED_NOTIFICATION_TITLE, product_name),
80 l10n_util::GetStringFUTF16(IDS_WEBUSB_DEVICE_DETECTED_NOTIFICATION_TITLE, 83 l10n_util::GetStringFUTF16(
81 product_name), 84 IDS_WEBUSB_DEVICE_DETECTED_NOTIFICATION,
82 l10n_util::GetStringUTF16(IDS_WEBUSB_DEVICE_DETECTED_NOTIFICATION), 85 base::UTF8ToUTF16(landing_page.GetContent())),
83 // TODO(juncai): use generic USB device icon here. 86 // TODO(juncai): use generic USB device icon here.
84 gfx::Image(), base::string16(), GURL(), 87 gfx::Image(), base::string16(), GURL(),
85 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, 88 message_center::NotifierId(
86 kWebUsbDetectorNotificationID), 89 message_center::NotifierId::SYSTEM_COMPONENT,
87 rich_notification_data, 90 kWebUsbDetectorNotificationID),
88 new WebUsbNotificationDelegate(landing_page, notification_id))); 91 rich_notification_data,
92 new WebUsbNotificationDelegate(landing_page, notification_id)));
89 93
90 notification->SetSystemPriority(); 94 notification->SetSystemPriority();
91 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); 95 message_center::MessageCenter::Get()->AddNotification(notification.Pass());
92 } 96 }
93 97
94 void ChromeWebUsbBrowserClient::OnDeviceRemoved( 98 void ChromeWebUsbBrowserClient::OnDeviceRemoved(
95 const std::string& notification_id) { 99 const std::string& notification_id) {
96 message_center::MessageCenter* message_center = 100 message_center::MessageCenter* message_center =
97 message_center::MessageCenter::Get(); 101 message_center::MessageCenter::Get();
98 if (message_center->FindVisibleNotificationById(notification_id)) { 102 if (message_center->FindVisibleNotificationById(notification_id)) {
99 message_center->RemoveNotification(notification_id, false /* by_user */); 103 message_center->RemoveNotification(notification_id, false /* by_user */);
100 } 104 }
101 } 105 }
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/chrome_webusb_browser_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698