Commit ac4eb30f authored by Bailey Berro's avatar Bailey Berro Committed by Commit Bot

Add USB printer notification for configuration required message

This change introduces a notification that will be displayed when a
user plugs in a USB printer that requires manual configuration. Clicking
the notification will open CrOS settings so the user can manually
configure the printer.
- Subsequent CL will call ShowConfigurationNotification() to show the
notification.

Bug: 951139
Change-Id: Ibff4d415de9c3ccf8eda45f470cfa30513468bb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1606193Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Auto-Submit: Bailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661038}
parent 96cc746f
......@@ -3258,6 +3258,12 @@
<message name="IDS_USB_PRINTER_NOTIFICATION_CONNECTED_MESSAGE" desc="Message displayed when the USB printer is connected successfully.">
<ph name="PRINTER_NAME">$1<ex> Google InkJet 1234</ex></ph> is connected and ready
</message>
<message name="IDS_USB_PRINTER_NOTIFICATION_CONFIGURATION_REQUIRED_TITLE" desc="Title of the USB printer needs configuration notification.">
USB printer needs configuration
</message>
<message name="IDS_USB_PRINTER_NOTIFICATION_CONFIGURATION_REQUIRED_MESSAGE" desc="Message displayed when the USB printer is connected but needs configuration.">
<ph name="PRINTER_NAME">$1<ex> Google InkJet 1234</ex></ph> is connected but needs configuration
</message>
<!-- RequestPin dialog messages -->
<message name="IDS_REQUEST_PIN_DIALOG_HEADER" desc="The text displayed in the certificate provider PIN request dialog.">
......
......@@ -142,6 +142,10 @@ class FakeUsbPrinterNotificationController
NOTIMPLEMENTED();
}
void ShowConfigurationNotification(const Printer& printer) override {
NOTIMPLEMENTED();
}
void RemoveNotification(const std::string& printer_id) override {
open_notifications_.erase(printer_id);
}
......
......@@ -306,6 +306,9 @@ class FakeUsbPrinterNotificationController
void ShowEphemeralNotification(const Printer& printer) override {
NOTIMPLEMENTED();
}
void ShowConfigurationNotification(const Printer& printer) override {
NOTIMPLEMENTED();
}
void ShowSavedNotification(const Printer& printer) override {
open_notifications_.insert(printer.id());
}
......
......@@ -11,6 +11,9 @@
#include "chrome/browser/notifications/notification_display_service.h"
#include "chrome/browser/notifications/notification_handler.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/settings_window_manager_chromeos.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image.h"
......@@ -77,6 +80,13 @@ void UsbPrinterNotification::Click(
if (!button_index) {
// Body of notification clicked.
visible_ = false;
if (type_ == Type::kConfigurationRequired) {
auto* const settings_manager =
chrome::SettingsWindowManager::GetInstance();
settings_manager->ShowChromePageForProfile(
profile_,
chrome::GetSettingsUrl(chrome::kNativePrintingSettingsSubPage));
}
return;
}
......@@ -101,6 +111,13 @@ void UsbPrinterNotification::UpdateContents() {
IDS_USB_PRINTER_NOTIFICATION_CONNECTED_MESSAGE,
base::UTF8ToUTF16(printer_.display_name())));
return;
case Type::kConfigurationRequired:
notification_->set_title(l10n_util::GetStringUTF16(
IDS_USB_PRINTER_NOTIFICATION_CONFIGURATION_REQUIRED_TITLE));
notification_->set_message(l10n_util::GetStringFUTF16(
IDS_USB_PRINTER_NOTIFICATION_CONFIGURATION_REQUIRED_MESSAGE,
base::UTF8ToUTF16(printer_.display_name())));
return;
}
NOTREACHED();
}
......
......@@ -26,7 +26,7 @@ namespace chromeos {
// according to its state and respond to the user's action.
class UsbPrinterNotification : public message_center::NotificationObserver {
public:
enum class Type { kEphemeral, kSaved };
enum class Type { kEphemeral, kSaved, kConfigurationRequired };
UsbPrinterNotification(const Printer& printer,
const std::string& notification_id,
......
......@@ -19,17 +19,7 @@ class UsbPrinterNotificationControllerImpl
~UsbPrinterNotificationControllerImpl() override = default;
void ShowEphemeralNotification(const Printer& printer) override {
if (!base::FeatureList::IsEnabled(features::kStreamlinedUsbPrinterSetup)) {
return;
}
if (base::ContainsKey(notifications_, printer.id())) {
return;
}
notifications_[printer.id()] = std::make_unique<UsbPrinterNotification>(
printer, GetUniqueNotificationId(),
UsbPrinterNotification::Type::kEphemeral, profile_);
ShowNotification(printer, UsbPrinterNotification::Type::kEphemeral);
}
void RemoveNotification(const std::string& printer_id) override {
......@@ -45,6 +35,17 @@ class UsbPrinterNotificationControllerImpl
}
void ShowSavedNotification(const Printer& printer) override {
ShowNotification(printer, UsbPrinterNotification::Type::kSaved);
}
void ShowConfigurationNotification(const Printer& printer) override {
ShowNotification(printer,
UsbPrinterNotification::Type::kConfigurationRequired);
}
private:
void ShowNotification(const Printer& printer,
UsbPrinterNotification::Type type) {
if (!base::FeatureList::IsEnabled(features::kStreamlinedUsbPrinterSetup)) {
return;
}
......@@ -54,11 +55,9 @@ class UsbPrinterNotificationControllerImpl
}
notifications_[printer.id()] = std::make_unique<UsbPrinterNotification>(
printer, GetUniqueNotificationId(),
UsbPrinterNotification::Type::kSaved, profile_);
printer, GetUniqueNotificationId(), type, profile_);
}
private:
std::string GetUniqueNotificationId() {
return base::StringPrintf("usb_printer_notification_%d",
next_notification_id_++);
......
......@@ -33,6 +33,10 @@ class UsbPrinterNotificationController {
// is already an existing notification for |printer|.
virtual void ShowSavedNotification(const Printer& printer) = 0;
// Creates a notification for a printer that needs configuration. This is a
// no-op if there is already an existing notification for |printer|.
virtual void ShowConfigurationNotification(const Printer& printer) = 0;
// Closes the notification for |printer_id|. This is a no-op if the
// notification has already been closed by the user.
virtual void RemoveNotification(const std::string& printer_id) = 0;
......
......@@ -364,6 +364,7 @@ const char kInternetSubPage[] = "internet";
// 'multidevice/features' is a child of the 'multidevice' route
const char kConnectedDevicesSubPage[] = "multidevice/features";
const char kLockScreenSubPage[] = "lockScreen";
const char kNativePrintingSettingsSubPage[] = "cupsPrinters";
const char kNetworkDetailSubPage[] = "networkDetail";
const char kPluginVmDetailsSubPage[] = "pluginVm/details";
const char kPluginVmSharedPathSubPage[] = "pluginVm/sharedPath";
......
......@@ -326,6 +326,7 @@ extern const char kHelpSubPage[];
extern const char kInternetSubPage[];
extern const char kConnectedDevicesSubPage[];
extern const char kLockScreenSubPage[];
extern const char kNativePrintingSettingsSubPage[];
extern const char kNetworkDetailSubPage[];
extern const char kPluginVmDetailsSubPage[];
extern const char kPluginVmSharedPathSubPage[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment