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 @@ ...@@ -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."> <message name="IDS_SETTINGS_PRINTING_CUPS_PRINTER_MANUFACTURER" desc="Label for the dropdown menu to select a manufacturer for the printer.">
Manufacturer Manufacturer
</message> </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> </if>
<message name="IDS_SETTINGS_PRINTING_CLOUD_PRINTERS" desc="In Printing Settings, the title of the google cloud printers setting section."> <message name="IDS_SETTINGS_PRINTING_CLOUD_PRINTERS" desc="In Printing Settings, the title of the google cloud printers setting section.">
Google Cloud Print Google Cloud Print
......
...@@ -206,9 +206,33 @@ ...@@ -206,9 +206,33 @@
color: var(--google-grey-700); 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 { #manuallyAddPrinterButton {
-webkit-margin-end: 210px; -webkit-margin-end: 210px;
} }
#browseButton {
color: black;
font-size: inherit;
}
</style> </style>
<add-printer-dialog> <add-printer-dialog>
<div class="dialog-body"> <div class="dialog-body">
...@@ -235,6 +259,18 @@ ...@@ -235,6 +259,18 @@
</div> </div>
</div> </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>
<div class="dialog-buttons"> <div class="dialog-buttons">
<paper-button id="manuallyAddPrinterButton" <paper-button id="manuallyAddPrinterButton"
......
...@@ -75,15 +75,16 @@ Polymer({ ...@@ -75,15 +75,16 @@ Polymer({
notify: true, notify: true,
value: function() { value: function() {
return { return {
printerAddress: '', printerAddress: '',
printerDescription: '', printerDescription: '',
printerId: '', printerId: '',
printerManufacturer: '', printerManufacturer: '',
printerModel: '', printerModel: '',
printerName: '', printerName: '',
printerProtocol: 'ipp', printerPPDPath: '',
printerQueue: '', printerProtocol: 'ipp',
printerStatus: '', printerQueue: '',
printerStatus: '',
}; };
}, },
}, },
...@@ -186,6 +187,21 @@ Polymer({ ...@@ -186,6 +187,21 @@ Polymer({
// the API is ready. // 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 */ /** @private */
switchToManualAddDialog_: function() { switchToManualAddDialog_: function() {
this.$$('add-printer-dialog').close(); this.$$('add-printer-dialog').close();
...@@ -202,6 +218,15 @@ Polymer({ ...@@ -202,6 +218,15 @@ Polymer({
this.$$('add-printer-dialog').close(); this.$$('add-printer-dialog').close();
this.fire('open-configuring-printer-dialog'); 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({ Polymer({
......
...@@ -9,15 +9,16 @@ ...@@ -9,15 +9,16 @@
/** /**
* @typedef {{ * @typedef {{
* printerId: string, * printerAddress: string,
* printerName: string,
* printerDescription: string, * printerDescription: string,
* printerId: string,
* printerManufacturer: string, * printerManufacturer: string,
* printerModel: string, * printerModel: string,
* printerStatus: string, * printerName: string,
* printerAddress: string, * printerPPDPath: string,
* printerProtocol: string, * printerProtocol: string,
* printerQueue: string * printerQueue: string,
* printerStatus: string
* }} * }}
*/ */
var CupsPrinterInfo; var CupsPrinterInfo;
...@@ -51,6 +52,10 @@ cr.define('settings', function() { ...@@ -51,6 +52,10 @@ cr.define('settings', function() {
*/ */
removeCupsPrinter: function(printerId) {}, removeCupsPrinter: function(printerId) {},
/**
* @return {!Promise<string>} The full path of the printer PPD file.
*/
getCupsPrinterPPDPath: function() {},
}; };
/** /**
...@@ -61,20 +66,25 @@ cr.define('settings', function() { ...@@ -61,20 +66,25 @@ cr.define('settings', function() {
cr.addSingletonGetter(CupsPrintersBrowserProxyImpl); cr.addSingletonGetter(CupsPrintersBrowserProxyImpl);
CupsPrintersBrowserProxyImpl.prototype = { CupsPrintersBrowserProxyImpl.prototype = {
/** override */ /** @override */
getCupsPrintersList: function() { getCupsPrintersList: function() {
return cr.sendWithPromise('getCupsPrintersList'); return cr.sendWithPromise('getCupsPrintersList');
}, },
/** override */ /** @override */
updateCupsPrinter: function(printerId, printerName) { updateCupsPrinter: function(printerId, printerName) {
chrome.send('updateCupsPrinter', [printerId, printerName]); chrome.send('updateCupsPrinter', [printerId, printerName]);
}, },
/** override */ /** @override */
removeCupsPrinter: function(printerId) { removeCupsPrinter: function(printerId) {
chrome.send('removeCupsPrinter', [printerId]); chrome.send('removeCupsPrinter', [printerId]);
}, },
/** @override */
getCupsPrinterPPDPath: function() {
return cr.sendWithPromise('selectPPDFile');
},
}; };
return { return {
......
...@@ -11,7 +11,12 @@ ...@@ -11,7 +11,12 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chromeos/printing/printer_pref_manager_factory.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/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/browser_thread.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
#include "printing/backend/print_backend.h" #include "printing/backend/print_backend.h"
...@@ -38,6 +43,9 @@ void CupsPrintersHandler::RegisterMessages() { ...@@ -38,6 +43,9 @@ void CupsPrintersHandler::RegisterMessages() {
"removeCupsPrinter", "removeCupsPrinter",
base::Bind(&CupsPrintersHandler::HandleRemoveCupsPrinter, base::Bind(&CupsPrintersHandler::HandleRemoveCupsPrinter,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"selectPPDFile", base::Bind(&CupsPrintersHandler::HandleSelectPPDFile,
base::Unretained(this)));
} }
void CupsPrintersHandler::HandleGetCupsPrintersList( void CupsPrintersHandler::HandleGetCupsPrintersList(
...@@ -109,5 +117,32 @@ void CupsPrintersHandler::HandleRemoveCupsPrinter(const base::ListValue* args) { ...@@ -109,5 +117,32 @@ void CupsPrintersHandler::HandleRemoveCupsPrinter(const base::ListValue* args) {
printer_id); 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 settings
} // namespace chromeos } // namespace chromeos
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" #include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
#include "ui/shell_dialogs/select_file_dialog.h"
namespace base { namespace base {
class ListValue; class ListValue;
...@@ -18,7 +19,8 @@ namespace chromeos { ...@@ -18,7 +19,8 @@ namespace chromeos {
namespace settings { namespace settings {
// Chrome OS CUPS printing settings page UI handler. // Chrome OS CUPS printing settings page UI handler.
class CupsPrintersHandler : public ::settings::SettingsPageUIHandler { class CupsPrintersHandler : public ::settings::SettingsPageUIHandler,
public ui::SelectFileDialog::Listener {
public: public:
explicit CupsPrintersHandler(content::WebUI* webui); explicit CupsPrintersHandler(content::WebUI* webui);
~CupsPrintersHandler() override; ~CupsPrintersHandler() override;
...@@ -31,11 +33,19 @@ class CupsPrintersHandler : public ::settings::SettingsPageUIHandler { ...@@ -31,11 +33,19 @@ class CupsPrintersHandler : public ::settings::SettingsPageUIHandler {
private: private:
// Gets all CUPS printers and return it to WebUI. // Gets all CUPS printers and return it to WebUI.
void HandleGetCupsPrintersList(const base::ListValue* args); void HandleGetCupsPrintersList(const base::ListValue* args);
void HandleUpdateCupsPrinter(const base::ListValue* args); void HandleUpdateCupsPrinter(const base::ListValue* args);
void HandleRemoveCupsPrinter(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_; Profile* profile_;
scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
std::string webui_callback_id_;
base::WeakPtrFactory<CupsPrintersHandler> weak_factory_; base::WeakPtrFactory<CupsPrintersHandler> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(CupsPrintersHandler); DISALLOW_COPY_AND_ASSIGN(CupsPrintersHandler);
......
...@@ -1096,6 +1096,9 @@ void AddPrintingStrings(content::WebUIDataSource* html_source) { ...@@ -1096,6 +1096,9 @@ void AddPrintingStrings(content::WebUIDataSource* html_source) {
{"selectManufacturerModelMessage", {"selectManufacturerModelMessage",
IDS_SETTINGS_PRINTING_CUPS_PRINTER_SELECT_MANUFACTURER_MODEL}, IDS_SETTINGS_PRINTING_CUPS_PRINTER_SELECT_MANUFACTURER_MODEL},
{"printerManufacturer", IDS_SETTINGS_PRINTING_CUPS_PRINTER_MANUFACTURER}, {"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 #endif
}; };
AddLocalizedStringsBulk(html_source, localized_strings, 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