2018-11-09 03:42:34 +00:00
|
|
|
// Copyright (c) 2018 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_BROWSER_PRINTING_PRINT_PREVIEW_MESSAGE_HANDLER_H_
|
|
|
|
#define SHELL_BROWSER_PRINTING_PRINT_PREVIEW_MESSAGE_HANDLER_H_
|
2018-11-09 03:42:34 +00:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "base/memory/ref_counted_memory.h"
|
|
|
|
#include "base/memory/weak_ptr.h"
|
2019-07-24 22:58:51 +00:00
|
|
|
#include "components/services/pdf_compositor/public/mojom/pdf_compositor.mojom.h"
|
2018-11-09 03:42:34 +00:00
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
|
|
|
#include "content/public/browser/web_contents_user_data.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/promise_util.h"
|
2018-11-09 03:42:34 +00:00
|
|
|
#include "v8/include/v8.h"
|
|
|
|
|
|
|
|
struct PrintHostMsg_DidPreviewDocument_Params;
|
|
|
|
struct PrintHostMsg_PreviewIds;
|
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class RenderFrameHost;
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2018-11-09 03:42:34 +00:00
|
|
|
|
|
|
|
// Manages the print preview handling for a WebContents.
|
|
|
|
class PrintPreviewMessageHandler
|
|
|
|
: public content::WebContentsObserver,
|
|
|
|
public content::WebContentsUserData<PrintPreviewMessageHandler> {
|
|
|
|
public:
|
|
|
|
~PrintPreviewMessageHandler() override;
|
|
|
|
|
2019-10-30 05:30:59 +00:00
|
|
|
void PrintToPDF(base::DictionaryValue options,
|
2019-08-23 00:03:28 +00:00
|
|
|
util::Promise<v8::Local<v8::Value>> promise);
|
2018-11-09 03:42:34 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// content::WebContentsObserver implementation.
|
|
|
|
bool OnMessageReceived(const IPC::Message& message,
|
|
|
|
content::RenderFrameHost* render_frame_host) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class content::WebContentsUserData<PrintPreviewMessageHandler>;
|
|
|
|
|
|
|
|
explicit PrintPreviewMessageHandler(content::WebContents* web_contents);
|
|
|
|
|
|
|
|
void OnMetafileReadyForPrinting(
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
const PrintHostMsg_DidPreviewDocument_Params& params,
|
|
|
|
const PrintHostMsg_PreviewIds& ids);
|
2018-11-09 07:16:43 +00:00
|
|
|
void OnCompositePdfDocumentDone(const PrintHostMsg_PreviewIds& ids,
|
2018-11-09 03:42:34 +00:00
|
|
|
printing::mojom::PdfCompositor::Status status,
|
|
|
|
base::ReadOnlySharedMemoryRegion region);
|
|
|
|
void OnPrintPreviewFailed(int document_cookie,
|
|
|
|
const PrintHostMsg_PreviewIds& ids);
|
|
|
|
void OnPrintPreviewCancelled(int document_cookie,
|
|
|
|
const PrintHostMsg_PreviewIds& ids);
|
|
|
|
|
2019-08-23 00:03:28 +00:00
|
|
|
util::Promise<v8::Local<v8::Value>> GetPromise(int request_id);
|
2019-02-11 19:20:04 +00:00
|
|
|
|
|
|
|
void ResolvePromise(int request_id,
|
|
|
|
scoped_refptr<base::RefCountedMemory> data_bytes);
|
|
|
|
void RejectPromise(int request_id);
|
|
|
|
|
2019-08-23 00:03:28 +00:00
|
|
|
using PromiseMap =
|
|
|
|
std::map<int, electron::util::Promise<v8::Local<v8::Value>>>;
|
2019-02-11 19:20:04 +00:00
|
|
|
PromiseMap promise_map_;
|
2018-11-09 03:42:34 +00:00
|
|
|
|
|
|
|
base::WeakPtrFactory<PrintPreviewMessageHandler> weak_ptr_factory_;
|
|
|
|
|
2019-01-21 16:56:54 +00:00
|
|
|
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
|
|
|
|
2018-11-09 03:42:34 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(PrintPreviewMessageHandler);
|
|
|
|
};
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2018-11-09 03:42:34 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_PRINTING_PRINT_PREVIEW_MESSAGE_HANDLER_H_
|