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?
Devices
</message>
<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 name="IDS_LOCAL_DISCOVERY_REGISTER_USER" desc="Label for user picker in registration dialog">
User:
......@@ -15050,6 +15050,27 @@ Do you accept?
<message name="IDS_LOCAL_DISCOVERY_UNREGISTERED_DEVICES_TITLE" desc="Title for unregistered devices">
Unregistered devices
</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>
<structures fallback_to_english="true">
......
......@@ -2,26 +2,36 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. */
.device-info {
-webkit-box-flex: 1;
-webkit-padding-start: 55px;
.device {
margin: 23px 0;
max-width: 695px;
overflow: hidden;
}
.device {
display: -webkit-box;
max-width: 738px;
.device .device-info {
float: left;
}
html[dir='rtl'] .device .device-info {
float: right;
}
.device button {
float: right;
}
html[dir='rtl'] .device button {
float: left;
}
.device .button-container {
-webkit-padding-end: 10px;
display: inline-block;
width: 70px;
.subline,
.device-subline {
color: #999;
margin: 5px 0;
}
.device .button-container button {
margin-top: 0.5em;
padding-bottom: 10px;
padding-top: 10px;
h3.device-name {
margin: 0;
}
.register-page {
......@@ -36,4 +46,18 @@
html[dir='rtl'] .register-page .button-list {
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 @@
<title i18n-content="devicesTitle"></title>
<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/spinner.css">
<link rel="stylesheet" href="local_discovery.css">
<link rel="stylesheet" href="../uber/uber_shared.css">
......@@ -25,17 +26,16 @@
<div id="register-page-choose" class="register-page">
<h1 i18n-content="confirmRegistration"></h1>
<div id="register-message">
<div id="register-message"
i18n-content="noPrintersOnNetworkExplanation">
</div>
<div id="register-picker">
<label i18n-content="registerUser" for="register-user-list"></label>
<select id="register-user-list"></select>
<div id="register-device-picker">
<div class="devices" id="register-device-list">
</div>
</div>
<div class="button-list">
<button class="register-cancel">Cancel</button>
<button class="register-continue"
id="register-confirmation-continue">Continue</button>
<button class="register-cancel" i18n-content="cancel"></button>
</div>
</div>
......@@ -43,15 +43,16 @@
<h1 i18n-content="addingPrinter"></h1>
<div i18n-content="addingMessage1"></div>
<div class="button-list">
<button class="register-cancel">Cancel</button>
<button class="register-cancel" i18n-content="cancel"></button>
</div>
</div>
<div id="register-page-adding2" class="register-page">
<h1 i18n-content="addingPrinter"></h1>
<div i18n-content="addingMessage2"></div>
<div class="inline-spinner"> </div>
<span i18n-content="addingMessage2"></span>
<div class="button-list">
<button class="register-cancel">Cancel</button>
<button class="register-cancel" i18n-content="cancel"></button>
</div>
</div>
......@@ -59,7 +60,7 @@
<h1 i18n-content="addingError"></h1>
<div i18n-content="addingErrorMessage"></div>
<div class="button-list">
<button id="register-error-exit">OK</button>
<button id="register-error-exit" i18n-content="ok"></button>
</div>
</div>
</div>
......@@ -69,13 +70,20 @@
<h1 i18n-content="devicesTitle"></h1>
</header>
<h2 i18n-content="registeredDevicesTitle"></h2>
<div id="registered-devices" class="device-list">
<div class="controls">
<button id="add-printers-button" i18n-content="addPrinters"></button>
<span id="printer-num" class="subline"
i18n-content="printersOnNetworkZero">
</span>
</div>
<h2 i18n-content="unregisteredDevicesTitle"></h2>
<div id="unregistered-devices" class="device-list">
<div id="cloud-devices-loading">
<div class="inline-spinner"> </div> <span i18n-content="loading"></span>
</div>
<div id="cloud-devices">
</div>
</div>
<script src="chrome://resources/js/i18n_template2.js"></script>
......
......@@ -48,6 +48,22 @@ content::WebUIDataSource* CreateLocalDiscoveryHTMLSource() {
IDS_LOCAL_DISCOVERY_UNREGISTERED_DEVICES_TITLE);
source->AddLocalizedString("devicesTitle",
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");
......
......@@ -170,7 +170,6 @@ IN_PROC_BROWSER_TEST_F(LocalDiscoveryUITest, AddRowTest) {
condition_devices_listed().Wait();
DeviceDescription description;
description.id = kSampleDeviceID;
description.name = "Sample device";
description.description = "Sample device description";
......
......@@ -9,7 +9,9 @@
#include <string>
#include <vector>
#include "base/cancelable_callback.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_constants.h"
#include "chrome/browser/local_discovery/privet_device_lister.h"
......@@ -28,7 +30,8 @@ namespace local_discovery {
// into the Javascript to update the page.
class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
public PrivetRegisterOperation::Delegate,
public PrivetDeviceLister::Delegate {
public PrivetDeviceLister::Delegate,
public CloudPrintPrinterList::Delegate {
public:
class Factory {
public:
......@@ -73,11 +76,15 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
const DeviceDescription& description) OVERRIDE;
virtual void DeviceRemoved(const std::string& name) OVERRIDE;
// CloudPrintPrinterList::Delegate implementation.
virtual void OnCloudPrintPrinterListReady() OVERRIDE;
virtual void OnCloudPrintPrinterListUnavailable() OVERRIDE;
private:
// Message handlers:
// For registering a device.
void HandleRegisterDevice(const base::ListValue* args);
typedef std::map<std::string, DeviceDescription> DeviceDescriptionMap;
// Message handlers:
// For when the page is ready to recieve device notifications.
void HandleStart(const base::ListValue* args);
......@@ -85,30 +92,26 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
void HandleIsVisible(const base::ListValue* args);
// 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.
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.
void StartRegisterHTTP(
const std::string& user,
scoped_ptr<PrivetHTTPClient> http_client);
// For when the confirm operation on the cloudprint server has finished
// executing.
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.
void SendRegisterError();
......@@ -121,24 +124,23 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
// Get the sync account email.
std::string GetSyncAccount();
// Get the base cloud print URL for a given device.
const std::string& GetCloudPrintBaseUrl(const std::string& device_name);
// Start the confirm flow for a cookie based authentication.
void StartCookieConfirmFlow(
int user_index,
const std::string& xsrf_token,
const GURL& automatic_claim_url);
// Get the base cloud print URL.
std::string GetCloudPrintBaseUrl();
// Reset and cancel the current registration.
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).
scoped_ptr<PrivetHTTPClient> current_http_client_;
// Device currently registering.
std::string current_register_device_;
// The current register operation. Only one allowed at any time.
scoped_ptr<PrivetRegisterOperation> current_register_operation_;
......@@ -158,20 +160,20 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
scoped_ptr<PrivetHTTPAsynchronousFactory::Resolution> privet_resolution_;
// 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.
bool is_visible_;
// Cloud print account manager to enumerate accounts and get XSRF token.
scoped_ptr<CloudPrintAccountManager> cloud_print_account_manager_;
// Device whose state must be updated to "registered" to complete
// registration.
std::string new_register_device_;
// XSRF token.
std::string xsrf_token_for_primary_user_;
// List of printers from cloud print.
scoped_ptr<CloudPrintPrinterList> cloud_print_printer_list_;
// Current user index (for multi-login), or kAccountIndexUseOAuth2 for sync
// credentials.
int current_register_user_index_;
// Announcement timeout for registration.
base::CancelableCallback<void()> registration_announce_timeout_;
DISALLOW_COPY_AND_ASSIGN(LocalDiscoveryUIHandler);
};
......
......@@ -5,7 +5,7 @@
var $ = document.getElementById.bind(document);
function checkOneDevice() {
var devices = $('registered-devices').children;
var devices = $('register-device-list').children;
assertEquals(1, devices.length);
var firstDevice = devices[0];
......@@ -13,14 +13,13 @@ function checkOneDevice() {
assertEquals('Sample device', deviceName);
var deviceDescription =
firstDevice.querySelector('.device-description').textContent;
firstDevice.querySelector('.device-subline').textContent;
assertEquals('Sample device description', deviceDescription);
var button = firstDevice.querySelector('button');
assertEquals(true, button.disabled);
assertEquals(false, button.disabled);
}
function checkNoDevices() {
assertEquals(0, $('unregistered-devices').children.length);
assertEquals(0, $('registered-devices').children.length);
assertEquals(0, $('register-device-list').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