OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/print_web_view_helper.h" | 5 #include "chrome/renderer/print_web_view_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/print_messages.h" | 14 #include "chrome/common/print_messages.h" |
15 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
16 #include "content/renderer/render_view.h" | 16 #include "content/renderer/render_view.h" |
17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 #include "printing/print_job_constants.h" |
18 #include "printing/units.h" | 19 #include "printing/units.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 NOTREACHED() << "Failed to initialize print page settings"; | 191 NOTREACHED() << "Failed to initialize print page settings"; |
191 return; | 192 return; |
192 } | 193 } |
193 | 194 |
194 if (!UpdatePrintSettings(job_settings)) { | 195 if (!UpdatePrintSettings(job_settings)) { |
195 NOTREACHED() << "Failed to update print page settings"; | 196 NOTREACHED() << "Failed to update print page settings"; |
196 DidFinishPrinting(true); // Release all printing resources. | 197 DidFinishPrinting(true); // Release all printing resources. |
197 return; | 198 return; |
198 } | 199 } |
199 | 200 |
| 201 job_settings.GetString(printing::kSettingPrintJobTitle, &job_title_); |
| 202 |
200 // Render Pages for printing. | 203 // Render Pages for printing. |
201 RenderPagesForPrint(pdf_frame, &pdf_element); | 204 RenderPagesForPrint(pdf_frame, &pdf_element); |
202 #endif | 205 #endif |
203 } | 206 } |
204 | 207 |
205 bool PrintWebViewHelper::GetPrintFrame(WebKit::WebFrame** frame) { | 208 bool PrintWebViewHelper::GetPrintFrame(WebKit::WebFrame** frame) { |
206 DCHECK(frame); | 209 DCHECK(frame); |
207 DCHECK(render_view()->webview()); | 210 DCHECK(render_view()->webview()); |
208 if (!render_view()->webview()) | 211 if (!render_view()->webview()) |
209 return false; | 212 return false; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 render_view()->runModalAlertDialog( | 346 render_view()->runModalAlertDialog( |
344 web_view->mainFrame(), | 347 web_view->mainFrame(), |
345 l10n_util::GetStringUTF16(IDS_PRINT_SPOOL_FAILED_ERROR_TEXT)); | 348 l10n_util::GetStringUTF16(IDS_PRINT_SPOOL_FAILED_ERROR_TEXT)); |
346 } | 349 } |
347 | 350 |
348 if (print_web_view_) { | 351 if (print_web_view_) { |
349 print_web_view_->close(); | 352 print_web_view_->close(); |
350 print_web_view_ = NULL; | 353 print_web_view_ = NULL; |
351 } | 354 } |
352 print_pages_params_.reset(); | 355 print_pages_params_.reset(); |
| 356 job_title_.clear(); |
353 } | 357 } |
354 | 358 |
355 bool PrintWebViewHelper::CopyAndPrint(WebKit::WebFrame* web_frame) { | 359 bool PrintWebViewHelper::CopyAndPrint(WebKit::WebFrame* web_frame) { |
356 // Create a new WebView with the same settings as the current display one. | 360 // Create a new WebView with the same settings as the current display one. |
357 // Except that we disable javascript (don't want any active content running | 361 // Except that we disable javascript (don't want any active content running |
358 // on the page). | 362 // on the page). |
359 WebPreferences prefs = render_view()->webkit_preferences(); | 363 WebPreferences prefs = render_view()->webkit_preferences(); |
360 prefs.javascript_enabled = false; | 364 prefs.javascript_enabled = false; |
361 prefs.java_enabled = false; | 365 prefs.java_enabled = false; |
362 | 366 |
(...skipping 21 matching lines...) Expand all Loading... |
384 WebNode* node) { | 388 WebNode* node) { |
385 PrintMsg_Print_Params printParams = params.params; | 389 PrintMsg_Print_Params printParams = params.params; |
386 UpdatePrintableSizeInPrintParameters(frame, node, &printParams); | 390 UpdatePrintableSizeInPrintParameters(frame, node, &printParams); |
387 | 391 |
388 PrepareFrameAndViewForPrint prep_frame_view(printParams, | 392 PrepareFrameAndViewForPrint prep_frame_view(printParams, |
389 frame, | 393 frame, |
390 node, | 394 node, |
391 frame->view()); | 395 frame->view()); |
392 int page_count = prep_frame_view.GetExpectedPageCount(); | 396 int page_count = prep_frame_view.GetExpectedPageCount(); |
393 | 397 |
394 render_view()->Send(new PrintHostMsg_DidGetPrintedPagesCount( | 398 render_view()->Send(new PrintHostMsg_DidGetBasicPrintJobInfo( |
395 render_view()->routing_id(), printParams.document_cookie, page_count)); | 399 render_view()->routing_id(), printParams.document_cookie, page_count, |
| 400 job_title_)); |
396 if (!page_count) | 401 if (!page_count) |
397 return; | 402 return; |
398 | 403 |
399 const gfx::Size& canvas_size = prep_frame_view.GetPrintCanvasSize(); | 404 const gfx::Size& canvas_size = prep_frame_view.GetPrintCanvasSize(); |
400 PrintMsg_PrintPage_Params page_params; | 405 PrintMsg_PrintPage_Params page_params; |
401 page_params.params = printParams; | 406 page_params.params = printParams; |
402 if (params.pages.empty()) { | 407 if (params.pages.empty()) { |
403 for (int i = 0; i < page_count; ++i) { | 408 for (int i = 0; i < page_count; ++i) { |
404 page_params.page_number = i; | 409 page_params.page_number = i; |
405 PrintPage(page_params, canvas_size, frame); | 410 PrintPage(page_params, canvas_size, frame); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 | 688 |
684 void PrintWebViewHelper::ResetScriptedPrintCount() { | 689 void PrintWebViewHelper::ResetScriptedPrintCount() { |
685 // Reset cancel counter on successful print. | 690 // Reset cancel counter on successful print. |
686 user_cancelled_scripted_print_count_ = 0; | 691 user_cancelled_scripted_print_count_ = 0; |
687 } | 692 } |
688 | 693 |
689 void PrintWebViewHelper::IncrementScriptedPrintCount() { | 694 void PrintWebViewHelper::IncrementScriptedPrintCount() { |
690 ++user_cancelled_scripted_print_count_; | 695 ++user_cancelled_scripted_print_count_; |
691 last_cancelled_script_print_ = base::Time::Now(); | 696 last_cancelled_script_print_ = base::Time::Now(); |
692 } | 697 } |
OLD | NEW |