| 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" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 NOTREACHED() << "Failed to initialize print page settings"; | 190 NOTREACHED() << "Failed to initialize print page settings"; |
| 191 return; | 191 return; |
| 192 } | 192 } |
| 193 | 193 |
| 194 if (!UpdatePrintSettings(job_settings)) { | 194 if (!UpdatePrintSettings(job_settings)) { |
| 195 NOTREACHED() << "Failed to update print page settings"; | 195 NOTREACHED() << "Failed to update print page settings"; |
| 196 DidFinishPrinting(true); // Release all printing resources. | 196 DidFinishPrinting(true); // Release all printing resources. |
| 197 return; | 197 return; |
| 198 } | 198 } |
| 199 | 199 |
| 200 job_settings.GetString("printJobTitle", &job_title_); |
| 201 |
| 200 // Render Pages for printing. | 202 // Render Pages for printing. |
| 201 RenderPagesForPrint(pdf_frame, &pdf_element); | 203 RenderPagesForPrint(pdf_frame, &pdf_element); |
| 202 #endif | 204 #endif |
| 203 } | 205 } |
| 204 | 206 |
| 205 bool PrintWebViewHelper::GetPrintFrame(WebKit::WebFrame** frame) { | 207 bool PrintWebViewHelper::GetPrintFrame(WebKit::WebFrame** frame) { |
| 206 DCHECK(frame); | 208 DCHECK(frame); |
| 207 DCHECK(render_view()->webview()); | 209 DCHECK(render_view()->webview()); |
| 208 if (!render_view()->webview()) | 210 if (!render_view()->webview()) |
| 209 return false; | 211 return false; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 render_view()->runModalAlertDialog( | 345 render_view()->runModalAlertDialog( |
| 344 web_view->mainFrame(), | 346 web_view->mainFrame(), |
| 345 l10n_util::GetStringUTF16(IDS_PRINT_SPOOL_FAILED_ERROR_TEXT)); | 347 l10n_util::GetStringUTF16(IDS_PRINT_SPOOL_FAILED_ERROR_TEXT)); |
| 346 } | 348 } |
| 347 | 349 |
| 348 if (print_web_view_) { | 350 if (print_web_view_) { |
| 349 print_web_view_->close(); | 351 print_web_view_->close(); |
| 350 print_web_view_ = NULL; | 352 print_web_view_ = NULL; |
| 351 } | 353 } |
| 352 print_pages_params_.reset(); | 354 print_pages_params_.reset(); |
| 355 job_title_.clear(); |
| 353 } | 356 } |
| 354 | 357 |
| 355 bool PrintWebViewHelper::CopyAndPrint(WebKit::WebFrame* web_frame) { | 358 bool PrintWebViewHelper::CopyAndPrint(WebKit::WebFrame* web_frame) { |
| 356 // Create a new WebView with the same settings as the current display one. | 359 // 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 | 360 // Except that we disable javascript (don't want any active content running |
| 358 // on the page). | 361 // on the page). |
| 359 WebPreferences prefs = render_view()->webkit_preferences(); | 362 WebPreferences prefs = render_view()->webkit_preferences(); |
| 360 prefs.javascript_enabled = false; | 363 prefs.javascript_enabled = false; |
| 361 prefs.java_enabled = false; | 364 prefs.java_enabled = false; |
| 362 | 365 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 384 WebNode* node) { | 387 WebNode* node) { |
| 385 PrintMsg_Print_Params printParams = params.params; | 388 PrintMsg_Print_Params printParams = params.params; |
| 386 UpdatePrintableSizeInPrintParameters(frame, node, &printParams); | 389 UpdatePrintableSizeInPrintParameters(frame, node, &printParams); |
| 387 | 390 |
| 388 PrepareFrameAndViewForPrint prep_frame_view(printParams, | 391 PrepareFrameAndViewForPrint prep_frame_view(printParams, |
| 389 frame, | 392 frame, |
| 390 node, | 393 node, |
| 391 frame->view()); | 394 frame->view()); |
| 392 int page_count = prep_frame_view.GetExpectedPageCount(); | 395 int page_count = prep_frame_view.GetExpectedPageCount(); |
| 393 | 396 |
| 394 render_view()->Send(new PrintHostMsg_DidGetPrintedPagesCount( | 397 render_view()->Send(new PrintHostMsg_DidGetBasicPrintJobInfo( |
| 395 render_view()->routing_id(), printParams.document_cookie, page_count)); | 398 render_view()->routing_id(), printParams.document_cookie, page_count, |
| 399 job_title_)); |
| 396 if (!page_count) | 400 if (!page_count) |
| 397 return; | 401 return; |
| 398 | 402 |
| 399 const gfx::Size& canvas_size = prep_frame_view.GetPrintCanvasSize(); | 403 const gfx::Size& canvas_size = prep_frame_view.GetPrintCanvasSize(); |
| 400 PrintMsg_PrintPage_Params page_params; | 404 PrintMsg_PrintPage_Params page_params; |
| 401 page_params.params = printParams; | 405 page_params.params = printParams; |
| 402 if (params.pages.empty()) { | 406 if (params.pages.empty()) { |
| 403 for (int i = 0; i < page_count; ++i) { | 407 for (int i = 0; i < page_count; ++i) { |
| 404 page_params.page_number = i; | 408 page_params.page_number = i; |
| 405 PrintPage(page_params, canvas_size, frame); | 409 PrintPage(page_params, canvas_size, frame); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 | 687 |
| 684 void PrintWebViewHelper::ResetScriptedPrintCount() { | 688 void PrintWebViewHelper::ResetScriptedPrintCount() { |
| 685 // Reset cancel counter on successful print. | 689 // Reset cancel counter on successful print. |
| 686 user_cancelled_scripted_print_count_ = 0; | 690 user_cancelled_scripted_print_count_ = 0; |
| 687 } | 691 } |
| 688 | 692 |
| 689 void PrintWebViewHelper::IncrementScriptedPrintCount() { | 693 void PrintWebViewHelper::IncrementScriptedPrintCount() { |
| 690 ++user_cancelled_scripted_print_count_; | 694 ++user_cancelled_scripted_print_count_; |
| 691 last_cancelled_script_print_ = base::Time::Now(); | 695 last_cancelled_script_print_ = base::Time::Now(); |
| 692 } | 696 } |
| OLD | NEW |