Print enhancement: add webContents.printerList And a print option to select printer
This commit is contained in:
parent
093b844859
commit
023a3fd547
15 changed files with 290 additions and 27 deletions
|
@ -41,6 +41,7 @@
|
|||
#include "atom/common/options_switches.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "base/values.h"
|
||||
#include "brightray/browser/inspectable_web_contents.h"
|
||||
#include "brightray/browser/inspectable_web_contents_view.h"
|
||||
#include "chrome/browser/printing/print_preview_message_handler.h"
|
||||
|
@ -65,6 +66,7 @@
|
|||
#include "content/public/browser/storage_partition.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/common/context_menu_params.h"
|
||||
#include "native_mate/converter.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
|
@ -83,6 +85,7 @@ namespace {
|
|||
struct PrintSettings {
|
||||
bool silent;
|
||||
bool print_background;
|
||||
base::string16 device_name;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
@ -120,10 +123,25 @@ struct Converter<PrintSettings> {
|
|||
return false;
|
||||
dict.Get("silent", &(out->silent));
|
||||
dict.Get("printBackground", &(out->print_background));
|
||||
dict.Get("deviceName", &(out->device_name));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Converter<printing::PrinterBasicInfo> {
|
||||
static v8::Local<v8::Value>
|
||||
ToV8(v8::Isolate* isolate, const printing::PrinterBasicInfo& val) {
|
||||
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
||||
dict.Set("printerName", val.printer_name);
|
||||
dict.Set("printerDescription", val.printer_description);
|
||||
dict.Set("printerStatus", val.printer_status);
|
||||
dict.Set("isDefault", val.is_default);
|
||||
dict.Set("options", val.options);
|
||||
return dict.GetHandle();
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Converter<WindowOpenDisposition> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
|
@ -1114,14 +1132,24 @@ bool WebContents::IsAudioMuted() {
|
|||
}
|
||||
|
||||
void WebContents::Print(mate::Arguments* args) {
|
||||
PrintSettings settings = { false, false };
|
||||
PrintSettings settings = { false, false, base::string16() };
|
||||
if (args->Length() == 1 && !args->GetNext(&settings)) {
|
||||
args->ThrowError();
|
||||
return;
|
||||
}
|
||||
|
||||
printing::PrintViewManagerBasic::FromWebContents(web_contents())->
|
||||
PrintNow(settings.silent, settings.print_background);
|
||||
PrintNow(settings.silent,
|
||||
settings.print_background, settings.device_name);
|
||||
}
|
||||
|
||||
|
||||
std::vector<printing::PrinterBasicInfo> WebContents::GetPrinterList(
|
||||
mate::Arguments* args) {
|
||||
std::vector<printing::PrinterBasicInfo> printerList;
|
||||
auto printBackend = printing::PrintBackend::CreateInstance(nullptr);
|
||||
printBackend->EnumeratePrinters(&printerList);
|
||||
return printerList;
|
||||
}
|
||||
|
||||
void WebContents::PrintToPDF(const base::DictionaryValue& setting,
|
||||
|
@ -1616,6 +1644,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
|||
&WebContents::UnregisterServiceWorker)
|
||||
.SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker)
|
||||
.SetMethod("print", &WebContents::Print)
|
||||
.SetMethod("printerList", &WebContents::GetPrinterList)
|
||||
.SetMethod("_printToPDF", &WebContents::PrintToPDF)
|
||||
.SetMethod("addWorkSpace", &WebContents::AddWorkSpace)
|
||||
.SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "content/public/common/favicon_url.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "printing/backend/print_backend.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
|
||||
namespace blink {
|
||||
|
@ -109,6 +110,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
void SetAudioMuted(bool muted);
|
||||
bool IsAudioMuted();
|
||||
void Print(mate::Arguments* args);
|
||||
std::vector<printing::PrinterBasicInfo> GetPrinterList(mate::Arguments* args);
|
||||
void SetEmbedder(const WebContents* embedder);
|
||||
|
||||
// Print current page as PDF.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue