Commit ae170e10 authored by noamsml@chromium.org's avatar noamsml@chromium.org

Modify devices page to match the latest mocks

Incorporate printer list from cloudprint and modify cloud print page to match
mocks, adding necessary functionality along the way.

BUG=286157

Review URL: https://chromiumcodereview.appspot.com/23903011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221887 0039d316-1c4b-4281-b951-d872f2087c98
parent 8438889b
...@@ -15021,7 +15021,7 @@ Do you accept? ...@@ -15021,7 +15021,7 @@ Do you accept?
Devices Devices
</message> </message>
<message name="IDS_LOCAL_DISCOVERY_REGISTER_CONFIRMATION" desc="Confirmation for registering a printer to Google Cloud Print"> <message name="IDS_LOCAL_DISCOVERY_REGISTER_CONFIRMATION" desc="Confirmation for registering a printer to Google Cloud Print">
Do you want to add <ph name="PRINTER_NAME">$1</ph> to Google Cloud Print? The following printers can be added to Google Cloud Print from your local network:
</message> </message>
<message name="IDS_LOCAL_DISCOVERY_REGISTER_USER" desc="Label for user picker in registration dialog"> <message name="IDS_LOCAL_DISCOVERY_REGISTER_USER" desc="Label for user picker in registration dialog">
User: User:
...@@ -15050,6 +15050,27 @@ Do you accept? ...@@ -15050,6 +15050,27 @@ Do you accept?
<message name="IDS_LOCAL_DISCOVERY_UNREGISTERED_DEVICES_TITLE" desc="Title for unregistered devices"> <message name="IDS_LOCAL_DISCOVERY_UNREGISTERED_DEVICES_TITLE" desc="Title for unregistered devices">
Unregistered devices Unregistered devices
</message> </message>
<message name="IDS_LOCAL_DISCOVERY_NO_DESCRIPTION" desc="Description for devices with an empty description">
Printer on Google Cloud Print
</message>
<message name="IDS_LOCAL_DISCOVERY_PRINTERS_ON_NETWORK_ZERO" desc="'Zero' case for number indicator for locally discoverable printers">
No other available printers.
</message>
<message name="IDS_LOCAL_DISCOVERY_PRINTERS_ON_NETWORK_ONE" desc="'One' case for number indicator for locally discoverable printers">
One other available printer.
</message>
<message name="IDS_LOCAL_DISCOVERY_PRINTERS_ON_NETWORK_MULTIPLE" desc="General case for number indicator for locally discoverable printers">
<ph name="NUM_PRINTERS">$1</ph> other available printers.
</message>
<message name="IDS_LOCAL_DISCOVERY_LOADING" desc="Loading for local discovery screens">
Loading
</message>
<message name="IDS_LOCAL_DISCOVERY_ADD_PRINTERS" desc="Text on button to add printers to cloud print">
Add Printers
</message>
<message name="IDS_LOCAL_DISCOVERY_NO_PRINTERS_ON_NETWORK_EXPLANATION" desc="Explanatory text in case there are no printers to register on the network">
Looks like there are no printers available to register on the network. If your printer is on and connected to the internet, try registering it using instructions in its instruction manual.
</message>
</messages> </messages>
<structures fallback_to_english="true"> <structures fallback_to_english="true">
......
...@@ -2,26 +2,36 @@ ...@@ -2,26 +2,36 @@
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. */ * found in the LICENSE file. */
.device-info { .device {
-webkit-box-flex: 1; margin: 23px 0;
-webkit-padding-start: 55px; max-width: 695px;
overflow: hidden;
} }
.device { .device .device-info {
display: -webkit-box; float: left;
max-width: 738px; }
html[dir='rtl'] .device .device-info {
float: right;
}
.device button {
float: right;
}
html[dir='rtl'] .device button {
float: left;
} }
.device .button-container { .subline,
-webkit-padding-end: 10px; .device-subline {
display: inline-block; color: #999;
width: 70px; margin: 5px 0;
} }
.device .button-container button { h3.device-name {
margin-top: 0.5em; margin: 0;
padding-bottom: 10px;
padding-top: 10px;
} }
.register-page { .register-page {
...@@ -36,4 +46,18 @@ ...@@ -36,4 +46,18 @@
html[dir='rtl'] .register-page .button-list { html[dir='rtl'] .register-page .button-list {
text-align: left; text-align: left;
} }
\ No newline at end of file
.controls {
border-bottom: 1px solid #eee;
max-width: 711px;
padding: 13px 3px 7px 4px;
}
html[dir='rtl'] .controls {
padding: 13px 4px 7px 3px;
}
.controls .subline {
-webkit-margin-start: 10px;
}
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<title i18n-content="devicesTitle"></title> <title i18n-content="devicesTitle"></title>
<link rel="stylesheet" href="chrome://resources/css/chrome_shared.css"> <link rel="stylesheet" href="chrome://resources/css/chrome_shared.css">
<link rel="stylesheet" href="chrome://resources/css/overlay.css"> <link rel="stylesheet" href="chrome://resources/css/overlay.css">
<link rel="stylesheet" href="chrome://resources/css/spinner.css">
<link rel="stylesheet" href="local_discovery.css"> <link rel="stylesheet" href="local_discovery.css">
<link rel="stylesheet" href="../uber/uber_shared.css"> <link rel="stylesheet" href="../uber/uber_shared.css">
...@@ -25,17 +26,16 @@ ...@@ -25,17 +26,16 @@
<div id="register-page-choose" class="register-page"> <div id="register-page-choose" class="register-page">
<h1 i18n-content="confirmRegistration"></h1> <h1 i18n-content="confirmRegistration"></h1>
<div id="register-message"> <div id="register-message"
i18n-content="noPrintersOnNetworkExplanation">
</div> </div>
<div id="register-picker"> <div id="register-device-picker">
<label i18n-content="registerUser" for="register-user-list"></label> <div class="devices" id="register-device-list">
<select id="register-user-list"></select> </div>
</div> </div>
<div class="button-list"> <div class="button-list">
<button class="register-cancel">Cancel</button> <button class="register-cancel" i18n-content="cancel"></button>
<button class="register-continue"
id="register-confirmation-continue">Continue</button>
</div> </div>
</div> </div>
...@@ -43,15 +43,16 @@ ...@@ -43,15 +43,16 @@
<h1 i18n-content="addingPrinter"></h1> <h1 i18n-content="addingPrinter"></h1>
<div i18n-content="addingMessage1"></div> <div i18n-content="addingMessage1"></div>
<div class="button-list"> <div class="button-list">
<button class="register-cancel">Cancel</button> <button class="register-cancel" i18n-content="cancel"></button>
</div> </div>
</div> </div>
<div id="register-page-adding2" class="register-page"> <div id="register-page-adding2" class="register-page">
<h1 i18n-content="addingPrinter"></h1> <h1 i18n-content="addingPrinter"></h1>
<div i18n-content="addingMessage2"></div> <div class="inline-spinner"> </div>
<span i18n-content="addingMessage2"></span>
<div class="button-list"> <div class="button-list">
<button class="register-cancel">Cancel</button> <button class="register-cancel" i18n-content="cancel"></button>
</div> </div>
</div> </div>
...@@ -59,7 +60,7 @@ ...@@ -59,7 +60,7 @@
<h1 i18n-content="addingError"></h1> <h1 i18n-content="addingError"></h1>
<div i18n-content="addingErrorMessage"></div> <div i18n-content="addingErrorMessage"></div>
<div class="button-list"> <div class="button-list">
<button id="register-error-exit">OK</button> <button id="register-error-exit" i18n-content="ok"></button>
</div> </div>
</div> </div>
</div> </div>
...@@ -69,13 +70,20 @@ ...@@ -69,13 +70,20 @@
<h1 i18n-content="devicesTitle"></h1> <h1 i18n-content="devicesTitle"></h1>
</header> </header>
<h2 i18n-content="registeredDevicesTitle"></h2> <div class="controls">
<div id="registered-devices" class="device-list"> <button id="add-printers-button" i18n-content="addPrinters"></button>
<span id="printer-num" class="subline"
i18n-content="printersOnNetworkZero">
</span>
</div> </div>
<h2 i18n-content="unregisteredDevicesTitle"></h2> <div id="cloud-devices-loading">
<div id="unregistered-devices" class="device-list"> <div class="inline-spinner"> </div> <span i18n-content="loading"></span>
</div> </div>
<div id="cloud-devices">
</div>
</div> </div>
<script src="chrome://resources/js/i18n_template2.js"></script> <script src="chrome://resources/js/i18n_template2.js"></script>
......
...@@ -48,6 +48,22 @@ content::WebUIDataSource* CreateLocalDiscoveryHTMLSource() { ...@@ -48,6 +48,22 @@ content::WebUIDataSource* CreateLocalDiscoveryHTMLSource() {
IDS_LOCAL_DISCOVERY_UNREGISTERED_DEVICES_TITLE); IDS_LOCAL_DISCOVERY_UNREGISTERED_DEVICES_TITLE);
source->AddLocalizedString("devicesTitle", source->AddLocalizedString("devicesTitle",
IDS_LOCAL_DISCOVERY_DEVICES_PAGE_TITLE); IDS_LOCAL_DISCOVERY_DEVICES_PAGE_TITLE);
source->AddLocalizedString("noDescription",
IDS_LOCAL_DISCOVERY_NO_DESCRIPTION);
source->AddLocalizedString("printersOnNetworkZero",
IDS_LOCAL_DISCOVERY_PRINTERS_ON_NETWORK_ZERO);
source->AddLocalizedString("printersOnNetworkOne",
IDS_LOCAL_DISCOVERY_PRINTERS_ON_NETWORK_ONE);
source->AddLocalizedString("printersOnNetworkMultiple",
IDS_LOCAL_DISCOVERY_PRINTERS_ON_NETWORK_MULTIPLE);
source->AddLocalizedString("cancel", IDS_CANCEL);
source->AddLocalizedString("ok", IDS_OK);
source->AddLocalizedString("loading", IDS_LOCAL_DISCOVERY_LOADING);
source->AddLocalizedString("addPrinters", IDS_LOCAL_DISCOVERY_ADD_PRINTERS);
source->AddLocalizedString(
"noPrintersOnNetworkExplanation",
IDS_LOCAL_DISCOVERY_NO_PRINTERS_ON_NETWORK_EXPLANATION);
source->SetJsonPath("strings.js"); source->SetJsonPath("strings.js");
......
...@@ -170,7 +170,6 @@ IN_PROC_BROWSER_TEST_F(LocalDiscoveryUITest, AddRowTest) { ...@@ -170,7 +170,6 @@ IN_PROC_BROWSER_TEST_F(LocalDiscoveryUITest, AddRowTest) {
condition_devices_listed().Wait(); condition_devices_listed().Wait();
DeviceDescription description; DeviceDescription description;
description.id = kSampleDeviceID;
description.name = "Sample device"; description.name = "Sample device";
description.description = "Sample device description"; description.description = "Sample device description";
......
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/cancelable_callback.h"
#include "chrome/browser/local_discovery/cloud_print_account_manager.h" #include "chrome/browser/local_discovery/cloud_print_account_manager.h"
#include "chrome/browser/local_discovery/cloud_print_printer_list.h"
#include "chrome/browser/local_discovery/privet_confirm_api_flow.h" #include "chrome/browser/local_discovery/privet_confirm_api_flow.h"
#include "chrome/browser/local_discovery/privet_constants.h" #include "chrome/browser/local_discovery/privet_constants.h"
#include "chrome/browser/local_discovery/privet_device_lister.h" #include "chrome/browser/local_discovery/privet_device_lister.h"
...@@ -28,7 +30,8 @@ namespace local_discovery { ...@@ -28,7 +30,8 @@ namespace local_discovery {
// into the Javascript to update the page. // into the Javascript to update the page.
class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
public PrivetRegisterOperation::Delegate, public PrivetRegisterOperation::Delegate,
public PrivetDeviceLister::Delegate { public PrivetDeviceLister::Delegate,
public CloudPrintPrinterList::Delegate {
public: public:
class Factory { class Factory {
public: public:
...@@ -73,11 +76,15 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, ...@@ -73,11 +76,15 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
const DeviceDescription& description) OVERRIDE; const DeviceDescription& description) OVERRIDE;
virtual void DeviceRemoved(const std::string& name) OVERRIDE; virtual void DeviceRemoved(const std::string& name) OVERRIDE;
// CloudPrintPrinterList::Delegate implementation.
virtual void OnCloudPrintPrinterListReady() OVERRIDE;
virtual void OnCloudPrintPrinterListUnavailable() OVERRIDE;
private: private:
// Message handlers: typedef std::map<std::string, DeviceDescription> DeviceDescriptionMap;
// For registering a device.
void HandleRegisterDevice(const base::ListValue* args);
// Message handlers:
// For when the page is ready to recieve device notifications. // For when the page is ready to recieve device notifications.
void HandleStart(const base::ListValue* args); void HandleStart(const base::ListValue* args);
...@@ -85,30 +92,26 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, ...@@ -85,30 +92,26 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
void HandleIsVisible(const base::ListValue* args); void HandleIsVisible(const base::ListValue* args);
// For when a user choice is made. // For when a user choice is made.
void HandleChooseUser(const base::ListValue* args); void HandleRegisterDevice(const base::ListValue* args);
// For when a cancelation is made. // For when a cancelation is made.
void HandleCancelRegistration(const base::ListValue* args); void HandleCancelRegistration(const base::ListValue* args);
// For requesting the printer list.
void HandleRequestPrinterList(const base::ListValue* args);
// For opening URLs (relative to the Google Cloud Print base URL) in a new
// tab.
void HandleOpenCloudPrintURL(const base::ListValue* args);
// For when the IP address of the printer has been resolved for registration. // For when the IP address of the printer has been resolved for registration.
void StartRegisterHTTP( void StartRegisterHTTP(
const std::string& user,
scoped_ptr<PrivetHTTPClient> http_client); scoped_ptr<PrivetHTTPClient> http_client);
// For when the confirm operation on the cloudprint server has finished // For when the confirm operation on the cloudprint server has finished
// executing. // executing.
void OnConfirmDone(CloudPrintBaseApiFlow::Status status); void OnConfirmDone(CloudPrintBaseApiFlow::Status status);
// For when the cloud print account list is resolved.
void OnCloudPrintAccountsResolved(const std::vector<std::string>& accounts,
const std::string& xsrf_token);
// For when XSRF token is received for a secondary account.
void OnXSRFTokenForSecondaryAccount(
const GURL& automated_claim_url,
const std::vector<std::string>& accounts,
const std::string& xsrf_token);
// Signal to the web interface an error has ocurred while registering. // Signal to the web interface an error has ocurred while registering.
void SendRegisterError(); void SendRegisterError();
...@@ -121,24 +124,23 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, ...@@ -121,24 +124,23 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
// Get the sync account email. // Get the sync account email.
std::string GetSyncAccount(); std::string GetSyncAccount();
// Get the base cloud print URL for a given device. // Get the base cloud print URL.
const std::string& GetCloudPrintBaseUrl(const std::string& device_name); std::string GetCloudPrintBaseUrl();
// Start the confirm flow for a cookie based authentication.
void StartCookieConfirmFlow(
int user_index,
const std::string& xsrf_token,
const GURL& automatic_claim_url);
// Reset and cancel the current registration. // Reset and cancel the current registration.
void ResetCurrentRegistration(); void ResetCurrentRegistration();
scoped_ptr<base::DictionaryValue> CreatePrinterInfo(
const CloudPrintPrinterList::PrinterDetails& description);
// Announcement hasn't been sent for a certain time after registration
// finished. Consider it failed.
// TODO(noamsml): Re-resolve service first.
void OnAnnouncementTimeoutReached();
// The current HTTP client (used for the current operation). // The current HTTP client (used for the current operation).
scoped_ptr<PrivetHTTPClient> current_http_client_; scoped_ptr<PrivetHTTPClient> current_http_client_;
// Device currently registering.
std::string current_register_device_;
// The current register operation. Only one allowed at any time. // The current register operation. Only one allowed at any time.
scoped_ptr<PrivetRegisterOperation> current_register_operation_; scoped_ptr<PrivetRegisterOperation> current_register_operation_;
...@@ -158,20 +160,20 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, ...@@ -158,20 +160,20 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
scoped_ptr<PrivetHTTPAsynchronousFactory::Resolution> privet_resolution_; scoped_ptr<PrivetHTTPAsynchronousFactory::Resolution> privet_resolution_;
// A map of current device descriptions provided by the PrivetDeviceLister. // A map of current device descriptions provided by the PrivetDeviceLister.
std::map<std::string, DeviceDescription> device_descriptions_; DeviceDescriptionMap device_descriptions_;
// Whether or not the page is marked as visible. // Whether or not the page is marked as visible.
bool is_visible_; bool is_visible_;
// Cloud print account manager to enumerate accounts and get XSRF token. // Device whose state must be updated to "registered" to complete
scoped_ptr<CloudPrintAccountManager> cloud_print_account_manager_; // registration.
std::string new_register_device_;
// XSRF token. // List of printers from cloud print.
std::string xsrf_token_for_primary_user_; scoped_ptr<CloudPrintPrinterList> cloud_print_printer_list_;
// Current user index (for multi-login), or kAccountIndexUseOAuth2 for sync // Announcement timeout for registration.
// credentials. base::CancelableCallback<void()> registration_announce_timeout_;
int current_register_user_index_;
DISALLOW_COPY_AND_ASSIGN(LocalDiscoveryUIHandler); DISALLOW_COPY_AND_ASSIGN(LocalDiscoveryUIHandler);
}; };
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
var $ = document.getElementById.bind(document); var $ = document.getElementById.bind(document);
function checkOneDevice() { function checkOneDevice() {
var devices = $('registered-devices').children; var devices = $('register-device-list').children;
assertEquals(1, devices.length); assertEquals(1, devices.length);
var firstDevice = devices[0]; var firstDevice = devices[0];
...@@ -13,14 +13,13 @@ function checkOneDevice() { ...@@ -13,14 +13,13 @@ function checkOneDevice() {
assertEquals('Sample device', deviceName); assertEquals('Sample device', deviceName);
var deviceDescription = var deviceDescription =
firstDevice.querySelector('.device-description').textContent; firstDevice.querySelector('.device-subline').textContent;
assertEquals('Sample device description', deviceDescription); assertEquals('Sample device description', deviceDescription);
var button = firstDevice.querySelector('button'); var button = firstDevice.querySelector('button');
assertEquals(true, button.disabled); assertEquals(false, button.disabled);
} }
function checkNoDevices() { function checkNoDevices() {
assertEquals(0, $('unregistered-devices').children.length); assertEquals(0, $('register-device-list').children.length);
assertEquals(0, $('registered-devices').children.length);
} }
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