Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1980)

Unified Diff: chrome/browser/printing/print_view_manager_base.cc

Issue 22577010: Printing: Add a basic printing mode without print preview and cloud print. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/printing/print_view_manager_base.cc
diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager_base.cc
similarity index 67%
copy from chrome/browser/printing/print_view_manager.cc
copy to chrome/browser/printing/print_view_manager_base.cc
index 7ed48ac70b5461d8f474153c7c331aa479036a47..89c7bd7678330676537e138708e563498f1bb1b3 100644
--- a/chrome/browser/printing/print_view_manager.cc
+++ b/chrome/browser/printing/print_view_manager_base.cc
@@ -1,30 +1,22 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 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.
-#include "chrome/browser/printing/print_view_manager.h"
+#include "chrome/browser/printing/print_view_manager_base.h"
#include <map>
#include "base/bind.h"
-#include "base/command_line.h"
-#include "base/lazy_instance.h"
#include "base/memory/scoped_ptr.h"
-#include "base/metrics/histogram.h"
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
#include "base/timer/timer.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/printing/print_error_dialog.h"
#include "chrome/browser/printing/print_job.h"
#include "chrome/browser/printing/print_job_manager.h"
-#include "chrome/browser/printing/print_preview_dialog_controller.h"
-#include "chrome/browser/printing/print_view_manager_observer.h"
#include "chrome/browser/printing/printer_query.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
-#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/print_messages.h"
#include "content/public/browser/browser_thread.h"
@@ -35,27 +27,24 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "grit/generated_resources.h"
-#include "printing/metafile.h"
#include "printing/metafile_impl.h"
-#include "printing/print_destination_interface.h"
#include "printing/printed_document.h"
#include "ui/base/l10n/l10n_util.h"
+#if defined(OS_WIN)
+#include "base/command_line.h"
+#include "chrome/common/chrome_switches.h"
+#endif
+
+#if defined(ENABLE_FULL_PRINTING)
+#include "chrome/browser/printing/print_error_dialog.h"
+#endif
+
using base::TimeDelta;
using content::BrowserThread;
-using content::WebContents;
-
-DEFINE_WEB_CONTENTS_USER_DATA_KEY(printing::PrintViewManager);
namespace {
-// Keeps track of pending scripted print preview closures.
-// No locking, only access on the UI thread.
-typedef std::map<content::RenderProcessHost*, base::Closure>
- ScriptedPrintPreviewClosureMap;
-static base::LazyInstance<ScriptedPrintPreviewClosureMap>
- g_scripted_print_preview_closure_map = LAZY_INSTANCE_INITIALIZER;
-
// Limits memory usage by raster to 64 MiB.
const int kMaxRasterSizeInPixels = 16*1024*1024;
@@ -63,15 +52,12 @@ const int kMaxRasterSizeInPixels = 16*1024*1024;
namespace printing {
-PrintViewManager::PrintViewManager(content::WebContents* web_contents)
+PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
number_pages_(0),
printing_succeeded_(false),
inside_inner_message_loop_(false),
- observer_(NULL),
cookie_(0),
- print_preview_state_(NOT_PREVIEWING),
- scripted_print_preview_rph_(NULL),
tab_content_blocked_(false) {
#if defined(OS_POSIX) && !defined(OS_MACOSX)
expecting_first_page_ = true;
@@ -83,109 +69,31 @@ PrintViewManager::PrintViewManager(content::WebContents* web_contents)
printing_enabled_.Init(
prefs::kPrintingEnabled,
profile->GetPrefs(),
- base::Bind(&PrintViewManager::UpdateScriptedPrintingBlocked,
+ base::Bind(&PrintViewManagerBase::UpdateScriptedPrintingBlocked,
base::Unretained(this)));
}
-PrintViewManager::~PrintViewManager() {
- DCHECK_EQ(NOT_PREVIEWING, print_preview_state_);
+PrintViewManagerBase::~PrintViewManagerBase() {
ReleasePrinterQuery();
DisconnectFromCurrentPrintJob();
}
-bool PrintViewManager::PrintNow() {
+bool PrintViewManagerBase::PrintNow() {
return PrintNowInternal(new PrintMsg_PrintPages(routing_id()));
}
-bool PrintViewManager::PrintForSystemDialogNow() {
- return PrintNowInternal(new PrintMsg_PrintForSystemDialog(routing_id()));
-}
-
-bool PrintViewManager::AdvancedPrintNow() {
- PrintPreviewDialogController* dialog_controller =
- PrintPreviewDialogController::GetInstance();
- if (!dialog_controller)
- return false;
- WebContents* print_preview_dialog =
- dialog_controller->GetPrintPreviewForContents(web_contents());
- if (print_preview_dialog) {
- if (!print_preview_dialog->GetWebUI())
- return false;
- PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
- print_preview_dialog->GetWebUI()->GetController());
- print_preview_ui->OnShowSystemDialog();
- return true;
- } else {
- return PrintNow();
- }
-}
-
-bool PrintViewManager::PrintToDestination() {
- // TODO(mad): Remove this once we can send user metrics from the metro driver.
- // crbug.com/142330
- UMA_HISTOGRAM_ENUMERATION("Metro.Print", 0, 2);
- // TODO(mad): Use a passed in destination interface instead.
- g_browser_process->print_job_manager()->SetPrintDestination(
- printing::CreatePrintDestination());
- return PrintNowInternal(new PrintMsg_PrintPages(routing_id()));
-}
-
-bool PrintViewManager::PrintPreviewNow(bool selection_only) {
- // Users can send print commands all they want and it is beyond
- // PrintViewManager's control. Just ignore the extra commands.
- // See http://crbug.com/136842 for example.
- if (print_preview_state_ != NOT_PREVIEWING)
- return false;
-
- if (!PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id(),
- selection_only))) {
- return false;
- }
-
- print_preview_state_ = USER_INITIATED_PREVIEW;
- return true;
-}
-
-void PrintViewManager::PrintPreviewForWebNode() {
- DCHECK_EQ(NOT_PREVIEWING, print_preview_state_);
- print_preview_state_ = USER_INITIATED_PREVIEW;
-}
-
-void PrintViewManager::PrintPreviewDone() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK_NE(NOT_PREVIEWING, print_preview_state_);
-
- if (print_preview_state_ == SCRIPTED_PREVIEW) {
- ScriptedPrintPreviewClosureMap& map =
- g_scripted_print_preview_closure_map.Get();
- ScriptedPrintPreviewClosureMap::iterator it =
- map.find(scripted_print_preview_rph_);
- CHECK(it != map.end());
- it->second.Run();
- map.erase(scripted_print_preview_rph_);
- scripted_print_preview_rph_ = NULL;
- }
- print_preview_state_ = NOT_PREVIEWING;
-}
-
-void PrintViewManager::UpdateScriptedPrintingBlocked() {
+void PrintViewManagerBase::UpdateScriptedPrintingBlocked() {
Send(new PrintMsg_SetScriptedPrintingBlocked(
routing_id(),
!printing_enabled_.GetValue() || tab_content_blocked_));
}
-void PrintViewManager::set_observer(PrintViewManagerObserver* observer) {
- DCHECK(!observer || !observer_);
- observer_ = observer;
-}
-
-void PrintViewManager::StopNavigation() {
+void PrintViewManagerBase::StopNavigation() {
// Cancel the current job, wait for the worker to finish.
TerminatePrintJob(true);
}
-void PrintViewManager::RenderProcessGone(base::TerminationStatus status) {
- print_preview_state_ = NOT_PREVIEWING;
+void PrintViewManagerBase::RenderProcessGone(base::TerminationStatus status) {
ReleasePrinterQuery();
if (!print_job_.get())
@@ -200,30 +108,26 @@ void PrintViewManager::RenderProcessGone(base::TerminationStatus status) {
}
}
-string16 PrintViewManager::RenderSourceName() {
+string16 PrintViewManagerBase::RenderSourceName() {
string16 name(web_contents()->GetTitle());
if (name.empty())
name = l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE);
return name;
}
-void PrintViewManager::OnDidGetPrintedPagesCount(int cookie, int number_pages) {
+void PrintViewManagerBase::OnDidGetPrintedPagesCount(int cookie,
+ int number_pages) {
DCHECK_GT(cookie, 0);
DCHECK_GT(number_pages, 0);
number_pages_ = number_pages;
OpportunisticallyCreatePrintJob(cookie);
}
-void PrintViewManager::OnDidGetDocumentCookie(int cookie) {
+void PrintViewManagerBase::OnDidGetDocumentCookie(int cookie) {
cookie_ = cookie;
}
-void PrintViewManager::OnDidShowPrintDialog() {
- if (observer_)
- observer_->OnPrintDialogShown();
-}
-
-void PrintViewManager::OnDidPrintPage(
+void PrintViewManagerBase::OnDidPrintPage(
const PrintHostMsg_DidPrintPage_Params& params) {
if (!OpportunisticallyCreatePrintJob(params.document_cookie))
return;
@@ -290,14 +194,16 @@ void PrintViewManager::OnDidPrintPage(
ShouldQuitFromInnerMessageLoop();
}
-void PrintViewManager::OnPrintingFailed(int cookie) {
+void PrintViewManagerBase::OnPrintingFailed(int cookie) {
if (cookie != cookie_) {
NOTREACHED();
return;
}
+#if defined(ENABLE_FULL_PRINTING)
chrome::ShowPrintErrorDialog(
web_contents()->GetView()->GetTopLevelNativeWindow());
+#endif
ReleasePrinterQuery();
@@ -307,79 +213,29 @@ void PrintViewManager::OnPrintingFailed(int cookie) {
content::NotificationService::NoDetails());
}
-void PrintViewManager::OnScriptedPrintPreview(bool source_is_modifiable,
- IPC::Message* reply_msg) {
- BrowserThread::CurrentlyOn(BrowserThread::UI);
- ScriptedPrintPreviewClosureMap& map =
- g_scripted_print_preview_closure_map.Get();
- content::RenderProcessHost* rph = web_contents()->GetRenderProcessHost();
-
- // This should always be 0 once we get modal window.print().
- if (map.count(rph) != 0) {
- // Renderer already handling window.print() in another View.
- Send(reply_msg);
- return;
- }
- if (print_preview_state_ != NOT_PREVIEWING) {
- // If a user initiated print dialog is already open, ignore the scripted
- // print message.
- DCHECK_EQ(USER_INITIATED_PREVIEW, print_preview_state_);
- Send(reply_msg);
- return;
- }
-
- PrintPreviewDialogController* dialog_controller =
- PrintPreviewDialogController::GetInstance();
- if (!dialog_controller) {
- Send(reply_msg);
- return;
- }
-
- print_preview_state_ = SCRIPTED_PREVIEW;
- base::Closure callback =
- base::Bind(&PrintViewManager::OnScriptedPrintPreviewReply,
- base::Unretained(this),
- reply_msg);
- map[rph] = callback;
- scripted_print_preview_rph_ = rph;
-
- dialog_controller->PrintPreview(web_contents());
- PrintHostMsg_RequestPrintPreview_Params params;
- params.is_modifiable = source_is_modifiable;
- PrintPreviewUI::SetInitialParams(
- dialog_controller->GetPrintPreviewForContents(web_contents()), params);
-}
-
-void PrintViewManager::OnScriptedPrintPreviewReply(IPC::Message* reply_msg) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- Send(reply_msg);
-}
-
-void PrintViewManager::DidStartLoading(
+void PrintViewManagerBase::DidStartLoading(
content::RenderViewHost* render_view_host) {
UpdateScriptedPrintingBlocked();
}
-bool PrintViewManager::OnMessageReceived(const IPC::Message& message) {
+bool PrintViewManagerBase::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message)
+ IPC_BEGIN_MESSAGE_MAP(PrintViewManagerBase, message)
IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount,
OnDidGetPrintedPagesCount)
IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetDocumentCookie,
OnDidGetDocumentCookie)
- IPC_MESSAGE_HANDLER(PrintHostMsg_DidShowPrintDialog, OnDidShowPrintDialog)
IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage)
IPC_MESSAGE_HANDLER(PrintHostMsg_PrintingFailed, OnPrintingFailed)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_ScriptedPrintPreview,
- OnScriptedPrintPreview)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
-void PrintViewManager::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
+void PrintViewManagerBase::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_PRINT_JOB_EVENT: {
OnNotifyPrintJobEvent(*content::Details<JobEventDetails>(details).ptr());
@@ -397,7 +253,7 @@ void PrintViewManager::Observe(int type,
}
}
-void PrintViewManager::OnNotifyPrintJobEvent(
+void PrintViewManagerBase::OnNotifyPrintJobEvent(
const JobEventDetails& event_details) {
switch (event_details.type()) {
case JobEventDetails::FAILED: {
@@ -446,7 +302,7 @@ void PrintViewManager::OnNotifyPrintJobEvent(
}
}
-bool PrintViewManager::RenderAllMissingPagesNow() {
+bool PrintViewManagerBase::RenderAllMissingPagesNow() {
if (!print_job_.get() || !print_job_->is_job_pending())
return false;
@@ -482,7 +338,7 @@ bool PrintViewManager::RenderAllMissingPagesNow() {
return true;
}
-void PrintViewManager::ShouldQuitFromInnerMessageLoop() {
+void PrintViewManagerBase::ShouldQuitFromInnerMessageLoop() {
// Look at the reason.
DCHECK(print_job_->document());
if (print_job_->document() &&
@@ -495,7 +351,7 @@ void PrintViewManager::ShouldQuitFromInnerMessageLoop() {
}
}
-bool PrintViewManager::CreateNewPrintJob(PrintJobWorkerOwner* job) {
+bool PrintViewManagerBase::CreateNewPrintJob(PrintJobWorkerOwner* job) {
DCHECK(!inside_inner_message_loop_);
// Disconnect the current print_job_.
@@ -522,7 +378,7 @@ bool PrintViewManager::CreateNewPrintJob(PrintJobWorkerOwner* job) {
return true;
}
-void PrintViewManager::DisconnectFromCurrentPrintJob() {
+void PrintViewManagerBase::DisconnectFromCurrentPrintJob() {
// Make sure all the necessary rendered page are done. Don't bother with the
// return value.
bool result = RenderAllMissingPagesNow();
@@ -543,13 +399,13 @@ void PrintViewManager::DisconnectFromCurrentPrintJob() {
#endif
}
-void PrintViewManager::PrintingDone(bool success) {
+void PrintViewManagerBase::PrintingDone(bool success) {
if (!print_job_.get())
return;
Send(new PrintMsg_PrintingDone(routing_id(), success));
}
-void PrintViewManager::TerminatePrintJob(bool cancel) {
+void PrintViewManagerBase::TerminatePrintJob(bool cancel) {
if (!print_job_.get())
return;
@@ -569,7 +425,7 @@ void PrintViewManager::TerminatePrintJob(bool cancel) {
ReleasePrintJob();
}
-void PrintViewManager::ReleasePrintJob() {
+void PrintViewManagerBase::ReleasePrintJob() {
if (!print_job_.get())
return;
@@ -582,7 +438,7 @@ void PrintViewManager::ReleasePrintJob() {
print_job_ = NULL;
}
-bool PrintViewManager::RunInnerMessageLoop() {
+bool PrintViewManagerBase::RunInnerMessageLoop() {
// This value may actually be too low:
//
// - If we're looping because of printer settings initialization, the premise
@@ -619,7 +475,7 @@ bool PrintViewManager::RunInnerMessageLoop() {
return success;
}
-bool PrintViewManager::OpportunisticallyCreatePrintJob(int cookie) {
+bool PrintViewManagerBase::OpportunisticallyCreatePrintJob(int cookie) {
if (print_job_.get())
return true;
@@ -649,7 +505,7 @@ bool PrintViewManager::OpportunisticallyCreatePrintJob(int cookie) {
return true;
}
-bool PrintViewManager::PrintNowInternal(IPC::Message* message) {
+bool PrintViewManagerBase::PrintNowInternal(IPC::Message* message) {
// Don't print / print preview interstitials.
if (web_contents()->ShowingInterstitialPage()) {
delete message;
@@ -658,7 +514,7 @@ bool PrintViewManager::PrintNowInternal(IPC::Message* message) {
return Send(message);
}
-void PrintViewManager::ReleasePrinterQuery() {
+void PrintViewManagerBase::ReleasePrinterQuery() {
if (!cookie_)
return;
« no previous file with comments | « chrome/browser/printing/print_view_manager_base.h ('k') | chrome/browser/printing/print_view_manager_basic.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698