2013-10-23 21:30:47 +02:00
|
|
|
// Copyright 2013 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
#include "base/macros.h"
|
2013-10-23 21:30:47 +02:00
|
|
|
#include "base/memory/ref_counted.h"
|
|
|
|
#include "base/strings/string16.h"
|
2016-01-06 20:20:54 +01:00
|
|
|
#include "build/build_config.h"
|
2016-02-05 01:49:19 +01:00
|
|
|
#include "components/prefs/pref_member.h"
|
2015-08-14 16:41:08 +02:00
|
|
|
#include "components/printing/browser/print_manager.h"
|
2013-10-23 21:30:47 +02:00
|
|
|
#include "content/public/browser/notification_observer.h"
|
|
|
|
#include "content/public/browser/notification_registrar.h"
|
2016-11-23 21:54:29 +01:00
|
|
|
#include "printing/features/features.h"
|
2013-10-23 21:30:47 +02:00
|
|
|
#include "printing/printed_pages_source.h"
|
|
|
|
|
|
|
|
struct PrintHostMsg_DidPrintPage_Params;
|
|
|
|
|
|
|
|
namespace content {
|
2016-11-23 21:54:29 +01:00
|
|
|
class RenderFrameHost;
|
2013-10-23 21:30:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace printing {
|
|
|
|
|
|
|
|
class JobEventDetails;
|
2014-09-27 01:48:19 +02:00
|
|
|
class MetafilePlayer;
|
2013-10-23 21:30:47 +02:00
|
|
|
class PrintJob;
|
|
|
|
class PrintJobWorkerOwner;
|
|
|
|
class PrintQueriesQueue;
|
|
|
|
|
|
|
|
// Base class for managing the print commands for a WebContents.
|
2016-07-14 03:35:07 +02:00
|
|
|
class CefPrintViewManagerBase : public content::NotificationObserver,
|
|
|
|
public PrintedPagesSource,
|
|
|
|
public PrintManager {
|
2013-10-23 21:30:47 +02:00
|
|
|
public:
|
2016-07-14 03:35:07 +02:00
|
|
|
~CefPrintViewManagerBase() override;
|
2013-10-23 21:30:47 +02:00
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
|
2013-10-23 21:30:47 +02:00
|
|
|
// Prints the current document immediately. Since the rendering is
|
|
|
|
// asynchronous, the actual printing will not be completed on the return of
|
|
|
|
// this function. Returns false if printing is impossible at the moment.
|
2016-11-23 21:54:29 +01:00
|
|
|
virtual bool PrintNow(content::RenderFrameHost* rfh);
|
2014-11-12 20:25:15 +01:00
|
|
|
#endif // ENABLE_BASIC_PRINTING
|
2013-10-23 21:30:47 +02:00
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
// Whether printing is enabled or not.
|
|
|
|
void UpdatePrintingEnabled();
|
2013-10-23 21:30:47 +02:00
|
|
|
|
|
|
|
// PrintedPagesSource implementation.
|
2014-11-12 20:25:15 +01:00
|
|
|
base::string16 RenderSourceName() override;
|
2013-10-23 21:30:47 +02:00
|
|
|
|
|
|
|
protected:
|
2016-07-14 03:35:07 +02:00
|
|
|
explicit CefPrintViewManagerBase(content::WebContents* web_contents);
|
2013-10-23 21:30:47 +02:00
|
|
|
|
|
|
|
// Helper method for Print*Now().
|
2016-11-23 21:54:29 +01:00
|
|
|
bool PrintNowInternal(content::RenderFrameHost* rfh,
|
|
|
|
std::unique_ptr<IPC::Message> message);
|
2013-10-23 21:30:47 +02:00
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
void SetPrintingRFH(content::RenderFrameHost* rfh);
|
2013-10-23 21:30:47 +02:00
|
|
|
|
|
|
|
// content::WebContentsObserver implementation.
|
2016-11-23 21:54:29 +01:00
|
|
|
void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
|
|
|
|
bool OnMessageReceived(const IPC::Message& message,
|
|
|
|
content::RenderFrameHost* render_frame_host) override;
|
|
|
|
|
|
|
|
// Cancels the print job.
|
|
|
|
void NavigationStopped() override;
|
2013-10-23 21:30:47 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// content::NotificationObserver implementation.
|
2014-11-12 20:25:15 +01:00
|
|
|
void Observe(int type,
|
|
|
|
const content::NotificationSource& source,
|
|
|
|
const content::NotificationDetails& details) override;
|
2013-10-23 21:30:47 +02:00
|
|
|
|
|
|
|
// content::WebContentsObserver implementation.
|
2015-03-19 23:06:16 +01:00
|
|
|
void DidStartLoading() override;
|
2013-10-23 21:30:47 +02:00
|
|
|
|
|
|
|
// IPC Message handlers.
|
2015-08-14 16:41:08 +02:00
|
|
|
void OnDidGetPrintedPagesCount(int cookie, int number_pages) override;
|
2013-10-23 21:30:47 +02:00
|
|
|
void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params);
|
2015-08-14 16:41:08 +02:00
|
|
|
void OnPrintingFailed(int cookie) override;
|
2014-09-27 01:48:19 +02:00
|
|
|
void OnShowInvalidPrinterSettingsError();
|
2013-10-23 21:30:47 +02:00
|
|
|
|
|
|
|
// Processes a NOTIFY_PRINT_JOB_EVENT notification.
|
|
|
|
void OnNotifyPrintJobEvent(const JobEventDetails& event_details);
|
|
|
|
|
|
|
|
// Requests the RenderView to render all the missing pages for the print job.
|
|
|
|
// No-op if no print job is pending. Returns true if at least one page has
|
|
|
|
// been requested to the renderer.
|
|
|
|
bool RenderAllMissingPagesNow();
|
|
|
|
|
|
|
|
// Quits the current message loop if these conditions hold true: a document is
|
|
|
|
// loaded and is complete and waiting_for_pages_to_be_rendered_ is true. This
|
|
|
|
// function is called in DidPrintPage() or on ALL_PAGES_REQUESTED
|
|
|
|
// notification. The inner message loop is created was created by
|
|
|
|
// RenderAllMissingPagesNow().
|
|
|
|
void ShouldQuitFromInnerMessageLoop();
|
|
|
|
|
|
|
|
// Creates a new empty print job. It has no settings loaded. If there is
|
|
|
|
// currently a print job, safely disconnect from it. Returns false if it is
|
|
|
|
// impossible to safely disconnect from the current print job or it is
|
|
|
|
// impossible to create a new print job.
|
|
|
|
bool CreateNewPrintJob(PrintJobWorkerOwner* job);
|
|
|
|
|
|
|
|
// Makes sure the current print_job_ has all its data before continuing, and
|
|
|
|
// disconnect from it.
|
|
|
|
void DisconnectFromCurrentPrintJob();
|
|
|
|
|
|
|
|
// Terminates the print job. No-op if no print job has been created. If
|
|
|
|
// |cancel| is true, cancel it instead of waiting for the job to finish. Will
|
|
|
|
// call ReleasePrintJob().
|
|
|
|
void TerminatePrintJob(bool cancel);
|
|
|
|
|
|
|
|
// Releases print_job_. Correctly deregisters from notifications. No-op if
|
|
|
|
// no print job has been created.
|
|
|
|
void ReleasePrintJob();
|
|
|
|
|
|
|
|
// Runs an inner message loop. It will set inside_inner_message_loop_ to true
|
|
|
|
// while the blocking inner message loop is running. This is useful in cases
|
|
|
|
// where the RenderView is about to be destroyed while a printing job isn't
|
|
|
|
// finished.
|
|
|
|
bool RunInnerMessageLoop();
|
|
|
|
|
|
|
|
// In the case of Scripted Printing, where the renderer is controlling the
|
|
|
|
// control flow, print_job_ is initialized whenever possible. No-op is
|
|
|
|
// print_job_ is initialized.
|
|
|
|
bool OpportunisticallyCreatePrintJob(int cookie);
|
|
|
|
|
|
|
|
// Release the PrinterQuery associated with our |cookie_|.
|
|
|
|
void ReleasePrinterQuery();
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
// Helper method for UpdatePrintingEnabled().
|
|
|
|
void SendPrintingEnabled(bool enabled, content::RenderFrameHost* rfh);
|
|
|
|
|
2013-10-23 21:30:47 +02:00
|
|
|
content::NotificationRegistrar registrar_;
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
// The current RFH that is printing with a system printing dialog.
|
|
|
|
content::RenderFrameHost* printing_rfh_;
|
|
|
|
|
2013-10-23 21:30:47 +02:00
|
|
|
// Manages the low-level talk to the printer.
|
|
|
|
scoped_refptr<PrintJob> print_job_;
|
|
|
|
|
|
|
|
// Indication of success of the print job.
|
|
|
|
bool printing_succeeded_;
|
|
|
|
|
|
|
|
// Running an inner message loop inside RenderAllMissingPagesNow(). This means
|
|
|
|
// we are _blocking_ until all the necessary pages have been rendered or the
|
|
|
|
// print settings are being loaded.
|
|
|
|
bool inside_inner_message_loop_;
|
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
#if !defined(OS_MACOSX)
|
2013-10-23 21:30:47 +02:00
|
|
|
// Set to true when OnDidPrintPage() should be expecting the first page.
|
|
|
|
bool expecting_first_page_;
|
2014-09-27 01:48:19 +02:00
|
|
|
#endif // OS_MACOSX
|
2014-07-03 20:34:58 +02:00
|
|
|
|
2013-10-23 21:30:47 +02:00
|
|
|
// Whether printing is enabled.
|
|
|
|
BooleanPrefMember printing_enabled_;
|
|
|
|
|
|
|
|
scoped_refptr<printing::PrintQueriesQueue> queue_;
|
|
|
|
|
2016-07-14 03:35:07 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefPrintViewManagerBase);
|
2013-10-23 21:30:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace printing
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_PRINTING_PRINT_VIEW_MANAGER_BASE_H_
|