Commit 9e0f12bd authored by xdai's avatar xdai Committed by Commit bot

[CUPS] Implement the CUPS printer PPD file picker in the manufacturer and model dialog.

BUG=626752
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2332483002
Cr-Commit-Position: refs/heads/master@{#419352}
parent 2b52c862
......@@ -831,6 +831,12 @@
<message name="IDS_SETTINGS_PRINTING_CUPS_PRINTER_MANUFACTURER" desc="Label for the dropdown menu to select a manufacturer for the printer.">
Manufacturer
</message>
<message name="IDS_SETTINGS_PRINTING_CUPS_PRINTER_SELECT_DRIVER" desc="Label for the file selector to manually select a PPD file from the user's file system.">
Or specify your own driver:
</message>
<message name="IDS_SETTINGS_PRINTING_CUPS_PRINTER_BUTTON_SELECT_DRIVER" desc="Text for the button which allows user to select a PPD file from the file system.">
Browse
</message>
</if>
<message name="IDS_SETTINGS_PRINTING_CLOUD_PRINTERS" desc="In Printing Settings, the title of the google cloud printers setting section.">
Google Cloud Print
......
......@@ -206,9 +206,33 @@
color: var(--google-grey-700);
}
.last {
margin-top: 20px;
}
paper-input {
--paper-input-container-color: var(--google-grey-500);
--paper-input-container-input: {
font-size: inherit;
border: 1px solid lightgray;
};
--paper-input-container-underline: {
display: none;
};
--paper-input-container-underline-focus: {
display: none;
};
width: 340px;
}
#manuallyAddPrinterButton {
-webkit-margin-end: 210px;
}
#browseButton {
color: black;
font-size: inherit;
}
</style>
<add-printer-dialog>
<div class="dialog-body">
......@@ -235,6 +259,18 @@
</div>
</div>
</div>
<div class="settings-box two-line last">
<div class="start">
<div class="label">$i18n{selectDriver}</div>
<div class="secondary">
<paper-input no-label-float readonly>
<paper-button suffix id="browseButton" on-tap="onBrowseFile_">
$i18n{selectDriverButtonText}
</paper-button>
</paper-input>
</div>
</div>
</div>
</div>
<div class="dialog-buttons">
<paper-button id="manuallyAddPrinterButton"
......
......@@ -75,15 +75,16 @@ Polymer({
notify: true,
value: function() {
return {
printerAddress: '',
printerDescription: '',
printerId: '',
printerManufacturer: '',
printerModel: '',
printerName: '',
printerProtocol: 'ipp',
printerQueue: '',
printerStatus: '',
printerAddress: '',
printerDescription: '',
printerId: '',
printerManufacturer: '',
printerModel: '',
printerName: '',
printerPPDPath: '',
printerProtocol: 'ipp',
printerQueue: '',
printerStatus: '',
};
},
},
......@@ -186,6 +187,21 @@ Polymer({
// the API is ready.
},
/** @private */
onBrowseFile_: function() {
settings.CupsPrintersBrowserProxyImpl.getInstance().
getCupsPrinterPPDPath().then(this.printerPPDPathChanged_.bind(this));
},
/**
* @param {string} path
* @private
*/
printerPPDPathChanged_: function(path) {
this.newPrinter.printerPPDPath = path;
this.$$('paper-input').value = this.getBaseName_(path);
},
/** @private */
switchToManualAddDialog_: function() {
this.$$('add-printer-dialog').close();
......@@ -202,6 +218,15 @@ Polymer({
this.$$('add-printer-dialog').close();
this.fire('open-configuring-printer-dialog');
},
/**
* @param {string} path The full path of the file
* @return {string} The base name of the file
* @private
*/
getBaseName_: function(path) {
return path.substring(path.lastIndexOf('/') + 1);
},
});
Polymer({
......
......@@ -9,15 +9,16 @@
/**
* @typedef {{
* printerId: string,
* printerName: string,
* printerAddress: string,
* printerDescription: string,
* printerId: string,
* printerManufacturer: string,
* printerModel: string,
* printerStatus: string,
* printerAddress: string,
* printerName: string,
* printerPPDPath: string,
* printerProtocol: string,
* printerQueue: string
* printerQueue: string,
* printerStatus: string
* }}
*/
var CupsPrinterInfo;
......@@ -51,6 +52,10 @@ cr.define('settings', function() {
*/
removeCupsPrinter: function(printerId) {},
/**
* @return {!Promise<string>} The full path of the printer PPD file.
*/
getCupsPrinterPPDPath: function() {},
};
/**
......@@ -61,20 +66,25 @@ cr.define('settings', function() {
cr.addSingletonGetter(CupsPrintersBrowserProxyImpl);
CupsPrintersBrowserProxyImpl.prototype = {
/** override */
/** @override */
getCupsPrintersList: function() {
return cr.sendWithPromise('getCupsPrintersList');
},
/** override */
/** @override */
updateCupsPrinter: function(printerId, printerName) {
chrome.send('updateCupsPrinter', [printerId, printerName]);
},
/** override */
/** @override */
removeCupsPrinter: function(printerId) {
chrome.send('removeCupsPrinter', [printerId]);
},
/** @override */
getCupsPrinterPPDPath: function() {
return cr.sendWithPromise('selectPPDFile');
},
};
return {
......
......@@ -11,7 +11,12 @@
#include "base/strings/string_util.h"
#include "base/values.h"
#include "chrome/browser/chromeos/printing/printer_pref_manager_factory.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_select_file_policy.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_ui.h"
#include "printing/backend/print_backend.h"
......@@ -38,6 +43,9 @@ void CupsPrintersHandler::RegisterMessages() {
"removeCupsPrinter",
base::Bind(&CupsPrintersHandler::HandleRemoveCupsPrinter,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"selectPPDFile", base::Bind(&CupsPrintersHandler::HandleSelectPPDFile,
base::Unretained(this)));
}
void CupsPrintersHandler::HandleGetCupsPrintersList(
......@@ -109,5 +117,32 @@ void CupsPrintersHandler::HandleRemoveCupsPrinter(const base::ListValue* args) {
printer_id);
}
void CupsPrintersHandler::HandleSelectPPDFile(const base::ListValue* args) {
CHECK_EQ(1U, args->GetSize());
CHECK(args->GetString(0, &webui_callback_id_));
base::FilePath downloads_path = DownloadPrefs::FromDownloadManager(
content::BrowserContext::GetDownloadManager(profile_))->DownloadPath();
select_file_dialog_ = ui::SelectFileDialog::Create(
this, new ChromeSelectFilePolicy(web_ui()->GetWebContents()));
gfx::NativeWindow owning_window =
chrome::FindBrowserWithWebContents(web_ui()->GetWebContents())
->window()
->GetNativeWindow();
select_file_dialog_->SelectFile(
ui::SelectFileDialog::SELECT_OPEN_FILE, base::string16(), downloads_path,
nullptr, 0, FILE_PATH_LITERAL(""), owning_window, nullptr);
}
void CupsPrintersHandler::FileSelected(const base::FilePath& path,
int index,
void* params) {
DCHECK(!webui_callback_id_.empty());
ResolveJavascriptCallback(base::StringValue(webui_callback_id_),
base::StringValue(path.value()));
webui_callback_id_.clear();
}
} // namespace settings
} // namespace chromeos
......@@ -7,6 +7,7 @@
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
#include "ui/shell_dialogs/select_file_dialog.h"
namespace base {
class ListValue;
......@@ -18,7 +19,8 @@ namespace chromeos {
namespace settings {
// Chrome OS CUPS printing settings page UI handler.
class CupsPrintersHandler : public ::settings::SettingsPageUIHandler {
class CupsPrintersHandler : public ::settings::SettingsPageUIHandler,
public ui::SelectFileDialog::Listener {
public:
explicit CupsPrintersHandler(content::WebUI* webui);
~CupsPrintersHandler() override;
......@@ -31,11 +33,19 @@ class CupsPrintersHandler : public ::settings::SettingsPageUIHandler {
private:
// Gets all CUPS printers and return it to WebUI.
void HandleGetCupsPrintersList(const base::ListValue* args);
void HandleUpdateCupsPrinter(const base::ListValue* args);
void HandleRemoveCupsPrinter(const base::ListValue* args);
void HandleSelectPPDFile(const base::ListValue* args);
// ui::SelectFileDialog::Listener override:
void FileSelected(const base::FilePath& path,
int index,
void* params) override;
Profile* profile_;
scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
std::string webui_callback_id_;
base::WeakPtrFactory<CupsPrintersHandler> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(CupsPrintersHandler);
......
......@@ -1096,6 +1096,9 @@ void AddPrintingStrings(content::WebUIDataSource* html_source) {
{"selectManufacturerModelMessage",
IDS_SETTINGS_PRINTING_CUPS_PRINTER_SELECT_MANUFACTURER_MODEL},
{"printerManufacturer", IDS_SETTINGS_PRINTING_CUPS_PRINTER_MANUFACTURER},
{"selectDriver", IDS_SETTINGS_PRINTING_CUPS_PRINTER_SELECT_DRIVER},
{"selectDriverButtonText",
IDS_SETTINGS_PRINTING_CUPS_PRINTER_BUTTON_SELECT_DRIVER},
#endif
};
AddLocalizedStringsBulk(html_source, localized_strings,
......
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