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

Side by Side Diff: chrome/browser/chromeos/dbus/printer_service_provider.cc

Issue 1123373003: Launch webstore widget app when unsupported printer is plugged in (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_cws_widget_scripts
Patch Set: bump app version Created 5 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chromeos/dbus/printer_service_provider.h" 5 #include "chrome/browser/chromeos/dbus/printer_service_provider.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/notifications/notification_delegate.h" 27 #include "chrome/browser/notifications/notification_delegate.h"
28 #include "chrome/browser/notifications/notification_ui_manager.h" 28 #include "chrome/browser/notifications/notification_ui_manager.h"
29 #include "chrome/browser/profiles/profile_manager.h" 29 #include "chrome/browser/profiles/profile_manager.h"
30 #include "chrome/browser/ui/browser.h" 30 #include "chrome/browser/ui/browser.h"
31 #include "chrome/browser/ui/browser_tabstrip.h" 31 #include "chrome/browser/ui/browser_tabstrip.h"
32 #include "chrome/browser/ui/browser_window.h" 32 #include "chrome/browser/ui/browser_window.h"
33 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 33 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
34 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" 34 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
35 #include "chrome/browser/ui/tabs/tab_strip_model.h" 35 #include "chrome/browser/ui/tabs/tab_strip_model.h"
36 #include "chrome/common/chrome_version_info.h" 36 #include "chrome/common/chrome_version_info.h"
37 #include "chrome/common/extensions/api/webstore_widget_private.h"
38 #include "chrome/common/extensions/extension_constants.h"
37 #include "chrome/grit/generated_resources.h" 39 #include "chrome/grit/generated_resources.h"
38 #include "chromeos/chromeos_switches.h" 40 #include "chromeos/chromeos_switches.h"
39 #include "components/user_manager/user.h" 41 #include "components/user_manager/user.h"
40 #include "components/user_manager/user_manager.h" 42 #include "components/user_manager/user_manager.h"
41 #include "content/public/browser/browser_thread.h" 43 #include "content/public/browser/browser_thread.h"
42 #include "content/public/browser/web_contents.h" 44 #include "content/public/browser/web_contents.h"
43 #include "dbus/bus.h" 45 #include "dbus/bus.h"
44 #include "dbus/exported_object.h" 46 #include "dbus/exported_object.h"
45 #include "dbus/message.h" 47 #include "dbus/message.h"
46 #include "device/usb/usb_ids.h" 48 #include "device/usb/usb_ids.h"
49 #include "extensions/browser/event_router.h"
47 #include "extensions/browser/extension_registry.h" 50 #include "extensions/browser/extension_registry.h"
48 #include "extensions/common/extension.h" 51 #include "extensions/common/extension.h"
49 #include "extensions/common/extension_set.h" 52 #include "extensions/common/extension_set.h"
50 #include "extensions/common/permissions/api_permission.h" 53 #include "extensions/common/permissions/api_permission.h"
51 #include "extensions/common/permissions/permissions_data.h" 54 #include "extensions/common/permissions/permissions_data.h"
52 #include "extensions/common/permissions/usb_device_permission.h" 55 #include "extensions/common/permissions/usb_device_permission.h"
53 #include "grit/theme_resources.h" 56 #include "grit/theme_resources.h"
54 #include "net/base/escape.h" 57 #include "net/base/escape.h"
55 #include "third_party/cros_system_api/dbus/service_constants.h" 58 #include "third_party/cros_system_api/dbus/service_constants.h"
56 #include "ui/aura/window.h" 59 #include "ui/aura/window.h"
57 #include "ui/base/l10n/l10n_util.h" 60 #include "ui/base/l10n/l10n_util.h"
58 #include "ui/base/resource/resource_bundle.h" 61 #include "ui/base/resource/resource_bundle.h"
59 62
63 namespace webstore_widget_private_api =
64 extensions::api::webstore_widget_private;
65
60 namespace { 66 namespace {
61 67
62 const char kPrinterAdded[] = "PrinterAdded"; 68 const char kPrinterAdded[] = "PrinterAdded";
63 69
64 const char kPrinterProviderFoundNotificationID[] = 70 const char kPrinterProviderFoundNotificationID[] =
65 "chrome://settings/printer/printer_app_found"; 71 "chrome://settings/printer/printer_app_found";
66 72
67 const char kNoPrinterProviderNotificationID[] = 73 const char kNoPrinterProviderNotificationID[] =
68 "chrome://settings/printer/no_printer_app"; 74 "chrome://settings/printer/no_printer_app";
69 75
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 DISALLOW_COPY_AND_ASSIGN(PrinterProviderExistsNotificationDelegate); 198 DISALLOW_COPY_AND_ASSIGN(PrinterProviderExistsNotificationDelegate);
193 }; 199 };
194 200
195 // Delegate for notification shown when there are no printer provider apps that 201 // Delegate for notification shown when there are no printer provider apps that
196 // support the plugged in printer found. 202 // support the plugged in printer found.
197 // The notification is clickable, and clicking it is supposed to launch 203 // The notification is clickable, and clicking it is supposed to launch
198 // Chrome Web Store widget listing apps that can support the plugged in printer. 204 // Chrome Web Store widget listing apps that can support the plugged in printer.
199 // (not implemented yet). 205 // (not implemented yet).
200 class SearchPrinterAppNotificationDelegate : public NotificationDelegate { 206 class SearchPrinterAppNotificationDelegate : public NotificationDelegate {
201 public: 207 public:
202 SearchPrinterAppNotificationDelegate(const std::string& vendor_id, 208 SearchPrinterAppNotificationDelegate(content::BrowserContext* browser_context,
203 const std::string& product_id) 209 uint16 vendor_id,
204 : vendor_id_(vendor_id), product_id_(product_id) {} 210 const std::string& vendor_id_str,
211 uint16 product_id,
212 const std::string& product_id_str)
213 : browser_context_(browser_context),
214 vendor_id_(vendor_id),
215 vendor_id_str_(vendor_id_str),
216 product_id_(product_id),
217 product_id_str_(product_id_str) {}
205 218
206 std::string id() const override { 219 std::string id() const override {
207 return "system.printer.no_printer_provider_found/" + 220 return "system.printer.no_printer_provider_found/" +
208 GetNotificationTag(vendor_id_, product_id_); 221 GetNotificationTag(vendor_id_str_, product_id_str_);
209 } 222 }
210 bool HasClickedListener() override { return true; } 223 bool HasClickedListener() override { return true; }
211 224
212 void Click() override { 225 void Click() override {
213 // TODO(tbarzic): Implement this (http://crbug.com/439448). 226 webstore_widget_private_api::Options options;
227 options.type = webstore_widget_private_api::TYPE_PRINTER_PROVIDER;
228 options.usb_id.reset(new webstore_widget_private_api::UsbId());
229 options.usb_id->vendor_id = vendor_id_;
230 options.usb_id->product_id = product_id_;
231
232 extensions::EventRouter* event_router =
233 extensions::EventRouter::Get(browser_context_);
234 scoped_ptr<extensions::Event> event(new extensions::Event(
235 webstore_widget_private_api::OnShowWidget::kEventName,
236 webstore_widget_private_api::OnShowWidget::Create(options)));
237 event_router->DispatchEventToExtension(extension_misc::kWebstoreWidgetAppId,
238 event.Pass());
214 } 239 }
215 240
216 private: 241 private:
217 ~SearchPrinterAppNotificationDelegate() override = default; 242 ~SearchPrinterAppNotificationDelegate() override = default;
218 243
219 std::string vendor_id_; 244 content::BrowserContext* browser_context_;
220 std::string product_id_; 245 uint16 vendor_id_;
246 std::string vendor_id_str_;
247 uint16 product_id_;
248 std::string product_id_str_;
221 249
222 DISALLOW_COPY_AND_ASSIGN(SearchPrinterAppNotificationDelegate); 250 DISALLOW_COPY_AND_ASSIGN(SearchPrinterAppNotificationDelegate);
223 }; 251 };
224 252
225 // Shows a notification for a plugged in printer. 253 // Shows a notification for a plugged in printer.
226 // If there is a printerProvider app that handles the printer's USB (vendor_id, 254 // If there is a printerProvider app that handles the printer's USB (vendor_id,
227 // product_id) pair, the notification informs the user that the printer is ready 255 // product_id) pair, the notification informs the user that the printer is ready
228 // to be used, otherwise it offers the user to search the Chrome Web Store for 256 // to be used, otherwise it offers the user to search the Chrome Web Store for
229 // an app that can handle the printer. 257 // an app that can handle the printer.
230 void ShowPrinterPluggedNotification( 258 void ShowPrinterPluggedNotification(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 notification.reset(new Notification( 301 notification.reset(new Notification(
274 message_center::NOTIFICATION_TYPE_SIMPLE, 302 message_center::NOTIFICATION_TYPE_SIMPLE,
275 GURL(kNoPrinterProviderNotificationID), 303 GURL(kNoPrinterProviderNotificationID),
276 GetNotificationTitle(vendor_id, product_id), 304 GetNotificationTitle(vendor_id, product_id),
277 l10n_util::GetStringUTF16( 305 l10n_util::GetStringUTF16(
278 IDS_PRINTER_DETECTED_NOTIFICATION_NO_PRINT_APP_BODY), 306 IDS_PRINTER_DETECTED_NOTIFICATION_NO_PRINT_APP_BODY),
279 bundle.GetImageNamed(IDR_PRINTER_NOTIFICATION), 307 bundle.GetImageNamed(IDR_PRINTER_NOTIFICATION),
280 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, 308 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
281 kNoPrinterProviderNotificationID), 309 kNoPrinterProviderNotificationID),
282 base::string16(), GetNotificationTag(vendor_id_str, product_id_str), 310 base::string16(), GetNotificationTag(vendor_id_str, product_id_str),
283 options, new SearchPrinterAppNotificationDelegate(vendor_id_str, 311 options,
284 product_id_str))); 312 new SearchPrinterAppNotificationDelegate(
313 profile, vendor_id, vendor_id_str, product_id, product_id_str)));
285 } 314 }
286 315
287 notification->SetSystemPriority(); 316 notification->SetSystemPriority();
288 notification_ui_manager->Add(*notification, profile); 317 notification_ui_manager->Add(*notification, profile);
289 } 318 }
290 319
291 } // namespace 320 } // namespace
292 321
293 namespace chromeos { 322 namespace chromeos {
294 323
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 const std::string& product) { 362 const std::string& product) {
334 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 363 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
335 base::Bind(&FindOrOpenCloudPrintPage, vendor, 364 base::Bind(&FindOrOpenCloudPrintPage, vendor,
336 product)); 365 product));
337 } 366 }
338 367
339 void PrinterServiceProvider::PrinterAdded( 368 void PrinterServiceProvider::PrinterAdded(
340 dbus::MethodCall* method_call, 369 dbus::MethodCall* method_call,
341 dbus::ExportedObject::ResponseSender response_sender) { 370 dbus::ExportedObject::ResponseSender response_sender) {
342 DVLOG(1) << "PrinterAdded " << method_call->ToString(); 371 DVLOG(1) << "PrinterAdded " << method_call->ToString();
343
344 dbus::MessageReader reader(method_call); 372 dbus::MessageReader reader(method_call);
345 373
346 std::string vendor_id; 374 std::string vendor_id;
347 reader.PopString(&vendor_id); 375 reader.PopString(&vendor_id);
348 StringToUpperASCII(&vendor_id); 376 StringToUpperASCII(&vendor_id);
349 377
350 std::string product_id; 378 std::string product_id;
351 reader.PopString(&product_id); 379 reader.PopString(&product_id);
352 StringToUpperASCII(&product_id); 380 StringToUpperASCII(&product_id);
353 381
(...skipping 16 matching lines...) Expand all
370 // detected by this service. http://crbug.com/439448 398 // detected by this service. http://crbug.com/439448
371 if (base::SysInfo::IsRunningOnChromeOS() && 399 if (base::SysInfo::IsRunningOnChromeOS() &&
372 chrome::VersionInfo::GetChannel() <= chrome::VersionInfo::CHANNEL_DEV) 400 chrome::VersionInfo::GetChannel() <= chrome::VersionInfo::CHANNEL_DEV)
373 return; 401 return;
374 402
375 ShowCloudPrintHelp(vendor_id, product_id); 403 ShowCloudPrintHelp(vendor_id, product_id);
376 } 404 }
377 405
378 } // namespace chromeos 406 } // namespace chromeos
379 407
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698