summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-06 04:06:40 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-06 04:06:40 +0000
commitb3ee0b52394b74dffc5bb746b0906d42a7b12076 (patch)
tree16e1fa68c358847463eaaf9d8cd723975061e9ce /chrome/renderer
parent5ca55b5b77bac3d6b853cc240965d21e8084ec7c (diff)
downloadchromium_src-b3ee0b52394b74dffc5bb746b0906d42a7b12076.zip
chromium_src-b3ee0b52394b74dffc5bb746b0906d42a7b12076.tar.gz
chromium_src-b3ee0b52394b74dffc5bb746b0906d42a7b12076.tar.bz2
Printing: Notify the browser process of renderer print failures. (try 2)
Original code review: http://codereview.chromium.org/6883278 BUG=none TEST=included TBR=kmadhusu Review URL: http://codereview.chromium.org/6932061 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84398 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/mock_printer.cc1
-rw-r--r--chrome/renderer/mock_render_thread.cc4
-rw-r--r--chrome/renderer/print_web_view_helper.cc10
-rw-r--r--chrome/renderer/print_web_view_helper.h12
-rw-r--r--chrome/renderer/print_web_view_helper_browsertest.cc55
5 files changed, 69 insertions, 13 deletions
diff --git a/chrome/renderer/mock_printer.cc b/chrome/renderer/mock_printer.cc
index 3117a87..a4d5e2d 100644
--- a/chrome/renderer/mock_printer.cc
+++ b/chrome/renderer/mock_printer.cc
@@ -99,6 +99,7 @@ void MockPrinter::UpdateSettings(int cookie,
memset(params, 0, sizeof(PrintMsg_PrintPages_Params));
SetPrintParams(&(params->params));
+ printer_status_ = PRINTER_PRINTING;
}
void MockPrinter::SetPrintedPagesCount(int cookie, int number_pages) {
diff --git a/chrome/renderer/mock_render_thread.cc b/chrome/renderer/mock_render_thread.cc
index 578409a..de3daef 100644
--- a/chrome/renderer/mock_render_thread.cc
+++ b/chrome/renderer/mock_render_thread.cc
@@ -106,11 +106,9 @@ bool MockRenderThread::OnMessageReceived(const IPC::Message& msg) {
OnScriptedPrint)
IPC_MESSAGE_HANDLER(PrintHostMsg_UpdatePrintSettings,
OnUpdatePrintSettings)
-#if defined(OS_WIN) || defined(OS_MACOSX)
IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount,
OnDidGetPrintedPagesCount)
IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage)
-#endif
#if defined(OS_WIN)
IPC_MESSAGE_HANDLER(PrintHostMsg_DuplicateSection, OnDuplicateSection)
#endif
@@ -150,7 +148,7 @@ void MockRenderThread::OnDuplicateSection(
// separate a browser process from a renderer process.
*browser_handle = renderer_handle;
}
-#endif
+#endif // defined(OS_WIN)
void MockRenderThread::OnAllocateSharedMemoryBuffer(
uint32 buffer_size, base::SharedMemoryHandle* handle) {
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
index 10548ab..15ae839 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -119,7 +119,8 @@ PrintWebViewHelper::PrintWebViewHelper(RenderView* render_view)
print_web_view_(NULL),
script_initiated_preview_frame_(NULL),
context_menu_preview_node_(NULL),
- user_cancelled_scripted_print_count_(0) {
+ user_cancelled_scripted_print_count_(0),
+ notify_browser_of_print_failure_(true) {
is_preview_ = CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnablePrintPreview);
}
@@ -240,6 +241,7 @@ void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) {
}
void PrintWebViewHelper::OnPrintingDone(bool success) {
+ notify_browser_of_print_failure_ = false;
DidFinishPrinting(success ? OK : FAIL_PRINT);
}
@@ -323,6 +325,7 @@ void PrintWebViewHelper::PrintPreview(WebKit::WebFrame* frame,
}
void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) {
+ int cookie = print_pages_params_->params.document_cookie;
if (result == FAIL_PRINT) {
WebView* web_view = print_web_view_;
if (!web_view)
@@ -331,8 +334,10 @@ void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) {
render_view()->runModalAlertDialog(
web_view->mainFrame(),
l10n_util::GetStringUTF16(IDS_PRINT_SPOOL_FAILED_ERROR_TEXT));
+
+ if (notify_browser_of_print_failure_)
+ Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie));
} else if (result == FAIL_PREVIEW) {
- int cookie = print_pages_params_->params.document_cookie;
Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie));
}
@@ -341,6 +346,7 @@ void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) {
print_web_view_ = NULL;
}
print_pages_params_.reset();
+ notify_browser_of_print_failure_ = true;
}
bool PrintWebViewHelper::CopyAndPrint(WebKit::WebFrame* web_frame) {
diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/print_web_view_helper.h
index ee64527..4b1dd33 100644
--- a/chrome/renderer/print_web_view_helper.h
+++ b/chrome/renderer/print_web_view_helper.h
@@ -87,6 +87,10 @@ class PrintWebViewHelper : public RenderViewObserver ,
FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, OnPrintPages);
FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, OnPrintPreview);
FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, OnPrintPreviewFail);
+ FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest,
+ OnPrintForPrintPreview);
+ FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest,
+ OnPrintForPrintPreviewFail);
#if defined(OS_WIN) || defined(OS_MACOSX)
FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintLayoutTest);
@@ -246,9 +250,15 @@ class PrintWebViewHelper : public RenderViewObserver ,
scoped_ptr<WebKit::WebNode> context_menu_preview_node_;
scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_;
+ bool is_preview_;
+
+ // Used for scripted initiated printing blocking.
base::Time last_cancelled_script_print_;
int user_cancelled_scripted_print_count_;
- bool is_preview_;
+
+ // Let the browser process know of a printing failure. Only set to false when
+ // the failure came from the browser in the first place.
+ bool notify_browser_of_print_failure_;
DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
};
diff --git a/chrome/renderer/print_web_view_helper_browsertest.cc b/chrome/renderer/print_web_view_helper_browsertest.cc
index 21cb426..2c0eafb 100644
--- a/chrome/renderer/print_web_view_helper_browsertest.cc
+++ b/chrome/renderer/print_web_view_helper_browsertest.cc
@@ -29,6 +29,20 @@ const char kHelloWorldHTML[] = "<body><p>Hello World!</p></body>";
const char kPrintWithJSHTML[] =
"<body>Hello<script>window.print()</script>World</body>";
+// A web page to simulate the print preview page.
+const char kPrintPreviewHTML[] =
+ "<body><p id=\"pdf-viewer\">Hello World!</p></body>";
+
+void CreatePrintSettingsDictionary(DictionaryValue* dict) {
+ dict->SetBoolean(printing::kSettingLandscape, false);
+ dict->SetBoolean(printing::kSettingCollate, false);
+ dict->SetBoolean(printing::kSettingColor, false);
+ dict->SetBoolean(printing::kSettingPrintToPDF, true);
+ dict->SetInteger(printing::kSettingDuplexMode, printing::SIMPLEX);
+ dict->SetInteger(printing::kSettingCopies, 1);
+ dict->SetString(printing::kSettingDeviceName, "dummy");
+}
+
} // namespace
class PrintWebViewHelperTest : public RenderViewTest {
@@ -297,6 +311,12 @@ class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTest {
}
}
+ void VerifyPrintFailed(bool did_fail) {
+ bool print_failed = (render_thread_.sink().GetUniqueMessageMatching(
+ PrintHostMsg_PrintingFailed::ID) != NULL);
+ EXPECT_EQ(did_fail, print_failed);
+ }
+
DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperPreviewTest);
};
@@ -307,13 +327,7 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) {
// Fill in some dummy values.
DictionaryValue dict;
- dict.SetBoolean(printing::kSettingLandscape, false);
- dict.SetBoolean(printing::kSettingCollate, false);
- dict.SetBoolean(printing::kSettingColor, false);
- dict.SetBoolean(printing::kSettingPrintToPDF, true);
- dict.SetInteger(printing::kSettingDuplexMode, printing::SIMPLEX);
- dict.SetInteger(printing::kSettingCopies, 1);
- dict.SetString(printing::kSettingDeviceName, "dummy");
+ CreatePrintSettingsDictionary(&dict);
PrintWebViewHelper::Get(view_)->OnPrintPreview(dict);
VerifyPrintPreviewFailed(false);
@@ -334,4 +348,31 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) {
VerifyPrintPreviewGenerated(false);
VerifyPagesPrinted(false);
}
+
+// Tests that printing from print preview works and sending and receiving
+// messages through that channel all works.
+TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) {
+ LoadHTML(kPrintPreviewHTML);
+
+ // Fill in some dummy values.
+ DictionaryValue dict;
+ CreatePrintSettingsDictionary(&dict);
+ PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(dict);
+
+ VerifyPrintFailed(false);
+ VerifyPagesPrinted(true);
+}
+
+// Tests that printing from print preview fails and receiving error messages
+// through that channel all works.
+TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) {
+ LoadHTML(kPrintPreviewHTML);
+
+ // An empty dictionary should fail.
+ DictionaryValue empty_dict;
+ PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(empty_dict);
+
+ VerifyPrintFailed(true);
+ VerifyPagesPrinted(false);
+}
#endif // !defined(OS_CHROMEOS)