| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/printing/renderer/print_web_view_helper.h" | 5 #include "components/printing/renderer/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 int new_content_height = page_size_in_pixels.height - | 137 int new_content_height = page_size_in_pixels.height - |
| 138 margin_top_in_pixels - margin_bottom_in_pixels; | 138 margin_top_in_pixels - margin_bottom_in_pixels; |
| 139 | 139 |
| 140 // Invalid page size and/or margins. We just use the default setting. | 140 // Invalid page size and/or margins. We just use the default setting. |
| 141 if (new_content_width < 1 || new_content_height < 1) { | 141 if (new_content_width < 1 || new_content_height < 1) { |
| 142 CHECK(frame != NULL); | 142 CHECK(frame != NULL); |
| 143 page_css_params = GetCssPrintParams(NULL, page_index, page_params); | 143 page_css_params = GetCssPrintParams(NULL, page_index, page_params); |
| 144 return page_css_params; | 144 return page_css_params; |
| 145 } | 145 } |
| 146 | 146 |
| 147 page_css_params.content_size = gfx::Size( | 147 page_css_params.content_size = |
| 148 ConvertUnit(new_content_width, kPixelsPerInch, dpi), | 148 gfx::Size(ConvertUnit(new_content_width, kPixelsPerInch, dpi), |
| 149 ConvertUnit(new_content_height, kPixelsPerInch, dpi)); | 149 ConvertUnit(new_content_height, kPixelsPerInch, dpi)); |
| 150 | 150 |
| 151 if (original_page_size_in_pixels != page_size_in_pixels) { | 151 if (original_page_size_in_pixels != page_size_in_pixels) { |
| 152 page_css_params.page_size = gfx::Size( | 152 page_css_params.page_size = |
| 153 ConvertUnit(page_size_in_pixels.width, kPixelsPerInch, dpi), | 153 gfx::Size(ConvertUnit(page_size_in_pixels.width, kPixelsPerInch, dpi), |
| 154 ConvertUnit(page_size_in_pixels.height, kPixelsPerInch, dpi)); | 154 ConvertUnit(page_size_in_pixels.height, kPixelsPerInch, dpi)); |
| 155 } else { | 155 } else { |
| 156 // Printing frame doesn't have any page size css. Pixels to dpi conversion | 156 // Printing frame doesn't have any page size css. Pixels to dpi conversion |
| 157 // causes rounding off errors. Therefore use the default page size values | 157 // causes rounding off errors. Therefore use the default page size values |
| 158 // directly. | 158 // directly. |
| 159 page_css_params.page_size = page_params.page_size; | 159 page_css_params.page_size = page_params.page_size; |
| 160 } | 160 } |
| 161 | 161 |
| 162 page_css_params.margin_top = | 162 page_css_params.margin_top = |
| 163 ConvertUnit(margin_top_in_pixels, kPixelsPerInch, dpi); | 163 ConvertUnit(margin_top_in_pixels, kPixelsPerInch, dpi); |
| 164 page_css_params.margin_left = | 164 page_css_params.margin_left = |
| (...skipping 25 matching lines...) Expand all Loading... |
| 190 scale_factor = ratio_width < ratio_height ? ratio_width : ratio_height; | 190 scale_factor = ratio_width < ratio_height ? ratio_width : ratio_height; |
| 191 content_width *= scale_factor; | 191 content_width *= scale_factor; |
| 192 content_height *= scale_factor; | 192 content_height *= scale_factor; |
| 193 } | 193 } |
| 194 params_to_fit->margin_top = static_cast<int>( | 194 params_to_fit->margin_top = static_cast<int>( |
| 195 (default_page_size_height - css_page_size_height * scale_factor) / 2 + | 195 (default_page_size_height - css_page_size_height * scale_factor) / 2 + |
| 196 (params_to_fit->margin_top * scale_factor)); | 196 (params_to_fit->margin_top * scale_factor)); |
| 197 params_to_fit->margin_left = static_cast<int>( | 197 params_to_fit->margin_left = static_cast<int>( |
| 198 (default_page_size_width - css_page_size_width * scale_factor) / 2 + | 198 (default_page_size_width - css_page_size_width * scale_factor) / 2 + |
| 199 (params_to_fit->margin_left * scale_factor)); | 199 (params_to_fit->margin_left * scale_factor)); |
| 200 params_to_fit->content_size = gfx::Size( | 200 params_to_fit->content_size = gfx::Size(static_cast<int>(content_width), |
| 201 static_cast<int>(content_width), static_cast<int>(content_height)); | 201 static_cast<int>(content_height)); |
| 202 params_to_fit->page_size = page_params.page_size; | 202 params_to_fit->page_size = page_params.page_size; |
| 203 return scale_factor; | 203 return scale_factor; |
| 204 } | 204 } |
| 205 | 205 |
| 206 void CalculatePageLayoutFromPrintParams( | 206 void CalculatePageLayoutFromPrintParams( |
| 207 const PrintMsg_Print_Params& params, | 207 const PrintMsg_Print_Params& params, |
| 208 PageSizeMargins* page_layout_in_points) { | 208 PageSizeMargins* page_layout_in_points) { |
| 209 int dpi = GetDPI(¶ms); | 209 int dpi = GetDPI(¶ms); |
| 210 int content_width = params.content_size.width(); | 210 int content_width = params.content_size.width(); |
| 211 int content_height = params.content_size.height(); | 211 int content_height = params.content_size.height(); |
| 212 | 212 |
| 213 int margin_bottom = params.page_size.height() - | 213 int margin_bottom = |
| 214 content_height - params.margin_top; | 214 params.page_size.height() - content_height - params.margin_top; |
| 215 int margin_right = params.page_size.width() - | 215 int margin_right = |
| 216 content_width - params.margin_left; | 216 params.page_size.width() - content_width - params.margin_left; |
| 217 | 217 |
| 218 page_layout_in_points->content_width = | 218 page_layout_in_points->content_width = |
| 219 ConvertUnit(content_width, dpi, kPointsPerInch); | 219 ConvertUnit(content_width, dpi, kPointsPerInch); |
| 220 page_layout_in_points->content_height = | 220 page_layout_in_points->content_height = |
| 221 ConvertUnit(content_height, dpi, kPointsPerInch); | 221 ConvertUnit(content_height, dpi, kPointsPerInch); |
| 222 page_layout_in_points->margin_top = | 222 page_layout_in_points->margin_top = |
| 223 ConvertUnit(params.margin_top, dpi, kPointsPerInch); | 223 ConvertUnit(params.margin_top, dpi, kPointsPerInch); |
| 224 page_layout_in_points->margin_right = | 224 page_layout_in_points->margin_right = |
| 225 ConvertUnit(margin_right, dpi, kPointsPerInch); | 225 ConvertUnit(margin_right, dpi, kPointsPerInch); |
| 226 page_layout_in_points->margin_bottom = | 226 page_layout_in_points->margin_bottom = |
| (...skipping 19 matching lines...) Expand all Loading... |
| 246 page_params->printable_area.width())); | 246 page_params->printable_area.width())); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void ComputeWebKitPrintParamsInDesiredDpi( | 249 void ComputeWebKitPrintParamsInDesiredDpi( |
| 250 const PrintMsg_Print_Params& print_params, | 250 const PrintMsg_Print_Params& print_params, |
| 251 blink::WebPrintParams* webkit_print_params) { | 251 blink::WebPrintParams* webkit_print_params) { |
| 252 int dpi = GetDPI(&print_params); | 252 int dpi = GetDPI(&print_params); |
| 253 webkit_print_params->printerDPI = dpi; | 253 webkit_print_params->printerDPI = dpi; |
| 254 webkit_print_params->printScalingOption = print_params.print_scaling_option; | 254 webkit_print_params->printScalingOption = print_params.print_scaling_option; |
| 255 | 255 |
| 256 webkit_print_params->printContentArea.width = | 256 webkit_print_params->printContentArea.width = ConvertUnit( |
| 257 ConvertUnit(print_params.content_size.width(), dpi, | 257 print_params.content_size.width(), dpi, print_params.desired_dpi); |
| 258 print_params.desired_dpi); | 258 webkit_print_params->printContentArea.height = ConvertUnit( |
| 259 webkit_print_params->printContentArea.height = | 259 print_params.content_size.height(), dpi, print_params.desired_dpi); |
| 260 ConvertUnit(print_params.content_size.height(), dpi, | |
| 261 print_params.desired_dpi); | |
| 262 | 260 |
| 263 webkit_print_params->printableArea.x = | 261 webkit_print_params->printableArea.x = ConvertUnit( |
| 264 ConvertUnit(print_params.printable_area.x(), dpi, | 262 print_params.printable_area.x(), dpi, print_params.desired_dpi); |
| 265 print_params.desired_dpi); | 263 webkit_print_params->printableArea.y = ConvertUnit( |
| 266 webkit_print_params->printableArea.y = | 264 print_params.printable_area.y(), dpi, print_params.desired_dpi); |
| 267 ConvertUnit(print_params.printable_area.y(), dpi, | 265 webkit_print_params->printableArea.width = ConvertUnit( |
| 268 print_params.desired_dpi); | 266 print_params.printable_area.width(), dpi, print_params.desired_dpi); |
| 269 webkit_print_params->printableArea.width = | 267 webkit_print_params->printableArea.height = ConvertUnit( |
| 270 ConvertUnit(print_params.printable_area.width(), dpi, | 268 print_params.printable_area.height(), dpi, print_params.desired_dpi); |
| 271 print_params.desired_dpi); | |
| 272 webkit_print_params->printableArea.height = | |
| 273 ConvertUnit(print_params.printable_area.height(), | |
| 274 dpi, print_params.desired_dpi); | |
| 275 | 269 |
| 276 webkit_print_params->paperSize.width = | 270 webkit_print_params->paperSize.width = ConvertUnit( |
| 277 ConvertUnit(print_params.page_size.width(), dpi, | 271 print_params.page_size.width(), dpi, print_params.desired_dpi); |
| 278 print_params.desired_dpi); | 272 webkit_print_params->paperSize.height = ConvertUnit( |
| 279 webkit_print_params->paperSize.height = | 273 print_params.page_size.height(), dpi, print_params.desired_dpi); |
| 280 ConvertUnit(print_params.page_size.height(), dpi, | |
| 281 print_params.desired_dpi); | |
| 282 } | 274 } |
| 283 | 275 |
| 284 blink::WebPlugin* GetPlugin(const blink::WebFrame* frame) { | 276 blink::WebPlugin* GetPlugin(const blink::WebFrame* frame) { |
| 285 return frame->document().isPluginDocument() ? | 277 return frame->document().isPluginDocument() |
| 286 frame->document().to<blink::WebPluginDocument>().plugin() : NULL; | 278 ? frame->document().to<blink::WebPluginDocument>().plugin() |
| 279 : NULL; |
| 287 } | 280 } |
| 288 | 281 |
| 289 bool PrintingNodeOrPdfFrame(const blink::WebFrame* frame, | 282 bool PrintingNodeOrPdfFrame(const blink::WebFrame* frame, |
| 290 const blink::WebNode& node) { | 283 const blink::WebNode& node) { |
| 291 if (!node.isNull()) | 284 if (!node.isNull()) |
| 292 return true; | 285 return true; |
| 293 blink::WebPlugin* plugin = GetPlugin(frame); | 286 blink::WebPlugin* plugin = GetPlugin(frame); |
| 294 return plugin && plugin->supportsPaginatedPrint(); | 287 return plugin && plugin->supportsPaginatedPrint(); |
| 295 } | 288 } |
| 296 | 289 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 return blink::WebPrintScalingOptionFitToPrintableArea; | 352 return blink::WebPrintScalingOptionFitToPrintableArea; |
| 360 } | 353 } |
| 361 | 354 |
| 362 PrintMsg_Print_Params CalculatePrintParamsForCss( | 355 PrintMsg_Print_Params CalculatePrintParamsForCss( |
| 363 blink::WebFrame* frame, | 356 blink::WebFrame* frame, |
| 364 int page_index, | 357 int page_index, |
| 365 const PrintMsg_Print_Params& page_params, | 358 const PrintMsg_Print_Params& page_params, |
| 366 bool ignore_css_margins, | 359 bool ignore_css_margins, |
| 367 bool fit_to_page, | 360 bool fit_to_page, |
| 368 double* scale_factor) { | 361 double* scale_factor) { |
| 369 PrintMsg_Print_Params css_params = GetCssPrintParams(frame, page_index, | 362 PrintMsg_Print_Params css_params = |
| 370 page_params); | 363 GetCssPrintParams(frame, page_index, page_params); |
| 371 | 364 |
| 372 PrintMsg_Print_Params params = page_params; | 365 PrintMsg_Print_Params params = page_params; |
| 373 EnsureOrientationMatches(css_params, ¶ms); | 366 EnsureOrientationMatches(css_params, ¶ms); |
| 374 | 367 |
| 375 if (ignore_css_margins && fit_to_page) | 368 if (ignore_css_margins && fit_to_page) |
| 376 return params; | 369 return params; |
| 377 | 370 |
| 378 PrintMsg_Print_Params result_params = css_params; | 371 PrintMsg_Print_Params result_params = css_params; |
| 379 if (ignore_css_margins) { | 372 if (ignore_css_margins) { |
| 380 result_params.margin_top = params.margin_top; | 373 result_params.margin_top = params.margin_top; |
| 381 result_params.margin_left = params.margin_left; | 374 result_params.margin_left = params.margin_left; |
| 382 | 375 |
| 383 DCHECK(!fit_to_page); | 376 DCHECK(!fit_to_page); |
| 384 // Since we are ignoring the margins, the css page size is no longer | 377 // Since we are ignoring the margins, the css page size is no longer |
| 385 // valid. | 378 // valid. |
| 386 int default_margin_right = params.page_size.width() - | 379 int default_margin_right = params.page_size.width() - |
| 387 params.content_size.width() - params.margin_left; | 380 params.content_size.width() - params.margin_left; |
| 388 int default_margin_bottom = params.page_size.height() - | 381 int default_margin_bottom = params.page_size.height() - |
| 389 params.content_size.height() - params.margin_top; | 382 params.content_size.height() - |
| 390 result_params.content_size = gfx::Size( | 383 params.margin_top; |
| 391 result_params.page_size.width() - result_params.margin_left - | 384 result_params.content_size = |
| 392 default_margin_right, | 385 gfx::Size(result_params.page_size.width() - result_params.margin_left - |
| 393 result_params.page_size.height() - result_params.margin_top - | 386 default_margin_right, |
| 394 default_margin_bottom); | 387 result_params.page_size.height() - result_params.margin_top - |
| 388 default_margin_bottom); |
| 395 } | 389 } |
| 396 | 390 |
| 397 if (fit_to_page) { | 391 if (fit_to_page) { |
| 398 double factor = FitPrintParamsToPage(params, &result_params); | 392 double factor = FitPrintParamsToPage(params, &result_params); |
| 399 if (scale_factor) | 393 if (scale_factor) |
| 400 *scale_factor = factor; | 394 *scale_factor = factor; |
| 401 } | 395 } |
| 402 return result_params; | 396 return result_params; |
| 403 } | 397 } |
| 404 | 398 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 422 } else { | 416 } else { |
| 423 view_ = NULL; | 417 view_ = NULL; |
| 424 frame_ = NULL; | 418 frame_ = NULL; |
| 425 } | 419 } |
| 426 } | 420 } |
| 427 | 421 |
| 428 blink::WebLocalFrame* FrameReference::GetFrame() { | 422 blink::WebLocalFrame* FrameReference::GetFrame() { |
| 429 if (view_ == NULL || frame_ == NULL) | 423 if (view_ == NULL || frame_ == NULL) |
| 430 return NULL; | 424 return NULL; |
| 431 for (blink::WebFrame* frame = view_->mainFrame(); frame != NULL; | 425 for (blink::WebFrame* frame = view_->mainFrame(); frame != NULL; |
| 432 frame = frame->traverseNext(false)) { | 426 frame = frame->traverseNext(false)) { |
| 433 if (frame == frame_) | 427 if (frame == frame_) |
| 434 return frame_; | 428 return frame_; |
| 435 } | 429 } |
| 436 return NULL; | 430 return NULL; |
| 437 } | 431 } |
| 438 | 432 |
| 439 blink::WebView* FrameReference::view() { | 433 blink::WebView* FrameReference::view() { |
| 440 return view_; | 434 return view_; |
| 441 } | 435 } |
| 442 | 436 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 virtual ~PrepareFrameAndViewForPrint(); | 518 virtual ~PrepareFrameAndViewForPrint(); |
| 525 | 519 |
| 526 // Optional. Replaces |frame_| with selection if needed. Will call |on_ready| | 520 // Optional. Replaces |frame_| with selection if needed. Will call |on_ready| |
| 527 // when completed. | 521 // when completed. |
| 528 void CopySelectionIfNeeded(const WebPreferences& preferences, | 522 void CopySelectionIfNeeded(const WebPreferences& preferences, |
| 529 const base::Closure& on_ready); | 523 const base::Closure& on_ready); |
| 530 | 524 |
| 531 // Prepares frame for printing. | 525 // Prepares frame for printing. |
| 532 void StartPrinting(); | 526 void StartPrinting(); |
| 533 | 527 |
| 534 blink::WebLocalFrame* frame() { | 528 blink::WebLocalFrame* frame() { return frame_.GetFrame(); } |
| 535 return frame_.GetFrame(); | |
| 536 } | |
| 537 | 529 |
| 538 const blink::WebNode& node() const { | 530 const blink::WebNode& node() const { return node_to_print_; } |
| 539 return node_to_print_; | |
| 540 } | |
| 541 | 531 |
| 542 int GetExpectedPageCount() const { | 532 int GetExpectedPageCount() const { return expected_pages_count_; } |
| 543 return expected_pages_count_; | |
| 544 } | |
| 545 | 533 |
| 546 void FinishPrinting(); | 534 void FinishPrinting(); |
| 547 | 535 |
| 548 bool IsLoadingSelection() { | 536 bool IsLoadingSelection() { |
| 549 // It's not selection if not |owns_web_view_|. | 537 // It's not selection if not |owns_web_view_|. |
| 550 return owns_web_view_ && frame() && frame()->isLoading(); | 538 return owns_web_view_ && frame() && frame()->isLoading(); |
| 551 } | 539 } |
| 552 | 540 |
| 553 // TODO(ojan): Remove this override and have this class use a non-null | 541 // TODO(ojan): Remove this override and have this class use a non-null |
| 554 // layerTreeView. | 542 // layerTreeView. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 expected_pages_count_(0), | 588 expected_pages_count_(0), |
| 601 should_print_backgrounds_(params.should_print_backgrounds), | 589 should_print_backgrounds_(params.should_print_backgrounds), |
| 602 should_print_selection_only_(params.selection_only), | 590 should_print_selection_only_(params.selection_only), |
| 603 is_printing_started_(false), | 591 is_printing_started_(false), |
| 604 weak_ptr_factory_(this) { | 592 weak_ptr_factory_(this) { |
| 605 PrintMsg_Print_Params print_params = params; | 593 PrintMsg_Print_Params print_params = params; |
| 606 if (!should_print_selection_only_ || | 594 if (!should_print_selection_only_ || |
| 607 !PrintingNodeOrPdfFrame(frame, node_to_print_)) { | 595 !PrintingNodeOrPdfFrame(frame, node_to_print_)) { |
| 608 bool fit_to_page = ignore_css_margins && | 596 bool fit_to_page = ignore_css_margins && |
| 609 print_params.print_scaling_option == | 597 print_params.print_scaling_option == |
| 610 blink::WebPrintScalingOptionFitToPrintableArea; | 598 blink::WebPrintScalingOptionFitToPrintableArea; |
| 611 ComputeWebKitPrintParamsInDesiredDpi(params, &web_print_params_); | 599 ComputeWebKitPrintParamsInDesiredDpi(params, &web_print_params_); |
| 612 frame->printBegin(web_print_params_, node_to_print_); | 600 frame->printBegin(web_print_params_, node_to_print_); |
| 613 print_params = CalculatePrintParamsForCss(frame, 0, print_params, | 601 print_params = CalculatePrintParamsForCss( |
| 614 ignore_css_margins, fit_to_page, | 602 frame, 0, print_params, ignore_css_margins, fit_to_page, NULL); |
| 615 NULL); | |
| 616 frame->printEnd(); | 603 frame->printEnd(); |
| 617 } | 604 } |
| 618 ComputeWebKitPrintParamsInDesiredDpi(print_params, &web_print_params_); | 605 ComputeWebKitPrintParamsInDesiredDpi(print_params, &web_print_params_); |
| 619 } | 606 } |
| 620 | 607 |
| 621 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { | 608 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { |
| 622 FinishPrinting(); | 609 FinishPrinting(); |
| 623 } | 610 } |
| 624 | 611 |
| 625 void PrepareFrameAndViewForPrint::ResizeForPrinting() { | 612 void PrepareFrameAndViewForPrint::ResizeForPrinting() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 637 return; | 624 return; |
| 638 blink::WebView* web_view = frame_.view(); | 625 blink::WebView* web_view = frame_.view(); |
| 639 // Backup size and offset. | 626 // Backup size and offset. |
| 640 if (blink::WebFrame* web_frame = web_view->mainFrame()) | 627 if (blink::WebFrame* web_frame = web_view->mainFrame()) |
| 641 prev_scroll_offset_ = web_frame->scrollOffset(); | 628 prev_scroll_offset_ = web_frame->scrollOffset(); |
| 642 prev_view_size_ = web_view->size(); | 629 prev_view_size_ = web_view->size(); |
| 643 | 630 |
| 644 web_view->resize(print_layout_size); | 631 web_view->resize(print_layout_size); |
| 645 } | 632 } |
| 646 | 633 |
| 647 | |
| 648 void PrepareFrameAndViewForPrint::StartPrinting() { | 634 void PrepareFrameAndViewForPrint::StartPrinting() { |
| 649 ResizeForPrinting(); | 635 ResizeForPrinting(); |
| 650 blink::WebView* web_view = frame_.view(); | 636 blink::WebView* web_view = frame_.view(); |
| 651 web_view->settings()->setShouldPrintBackgrounds(should_print_backgrounds_); | 637 web_view->settings()->setShouldPrintBackgrounds(should_print_backgrounds_); |
| 652 expected_pages_count_ = | 638 expected_pages_count_ = |
| 653 frame()->printBegin(web_print_params_, node_to_print_); | 639 frame()->printBegin(web_print_params_, node_to_print_); |
| 654 is_printing_started_ = true; | 640 is_printing_started_ = true; |
| 655 } | 641 } |
| 656 | 642 |
| 657 void PrepareFrameAndViewForPrint::CopySelectionIfNeeded( | 643 void PrepareFrameAndViewForPrint::CopySelectionIfNeeded( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 | 680 |
| 695 bool PrepareFrameAndViewForPrint::allowsBrokenNullLayerTreeView() const { | 681 bool PrepareFrameAndViewForPrint::allowsBrokenNullLayerTreeView() const { |
| 696 return true; | 682 return true; |
| 697 } | 683 } |
| 698 | 684 |
| 699 void PrepareFrameAndViewForPrint::didStopLoading() { | 685 void PrepareFrameAndViewForPrint::didStopLoading() { |
| 700 DCHECK(!on_ready_.is_null()); | 686 DCHECK(!on_ready_.is_null()); |
| 701 // Don't call callback here, because it can delete |this| and WebView that is | 687 // Don't call callback here, because it can delete |this| and WebView that is |
| 702 // called didStopLoading. | 688 // called didStopLoading. |
| 703 base::MessageLoop::current()->PostTask( | 689 base::MessageLoop::current()->PostTask( |
| 704 FROM_HERE, | 690 FROM_HERE, base::Bind(&PrepareFrameAndViewForPrint::CallOnReady, |
| 705 base::Bind(&PrepareFrameAndViewForPrint::CallOnReady, | 691 weak_ptr_factory_.GetWeakPtr())); |
| 706 weak_ptr_factory_.GetWeakPtr())); | |
| 707 } | 692 } |
| 708 | 693 |
| 709 blink::WebFrame* PrepareFrameAndViewForPrint::createChildFrame( | 694 blink::WebFrame* PrepareFrameAndViewForPrint::createChildFrame( |
| 710 blink::WebLocalFrame* parent, | 695 blink::WebLocalFrame* parent, |
| 711 const blink::WebString& name, | 696 const blink::WebString& name, |
| 712 blink::WebSandboxFlags sandboxFlags) { | 697 blink::WebSandboxFlags sandboxFlags) { |
| 713 blink::WebFrame* frame = blink::WebLocalFrame::create(this); | 698 blink::WebFrame* frame = blink::WebLocalFrame::create(this); |
| 714 parent->appendChild(frame); | 699 parent->appendChild(frame); |
| 715 return frame; | 700 return frame; |
| 716 } | 701 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 } | 742 } |
| 758 | 743 |
| 759 bool PrintWebViewHelper::Delegate::IsAskPrintSettingsEnabled() { | 744 bool PrintWebViewHelper::Delegate::IsAskPrintSettingsEnabled() { |
| 760 return true; | 745 return true; |
| 761 } | 746 } |
| 762 | 747 |
| 763 bool PrintWebViewHelper::Delegate::IsScriptedPrintEnabled() { | 748 bool PrintWebViewHelper::Delegate::IsScriptedPrintEnabled() { |
| 764 return true; | 749 return true; |
| 765 } | 750 } |
| 766 | 751 |
| 767 PrintWebViewHelper::PrintWebViewHelper( | 752 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view, |
| 768 content::RenderView* render_view, | 753 scoped_ptr<Delegate> delegate) |
| 769 scoped_ptr<Delegate> delegate) | |
| 770 : content::RenderViewObserver(render_view), | 754 : content::RenderViewObserver(render_view), |
| 771 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), | 755 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), |
| 772 reset_prep_frame_view_(false), | 756 reset_prep_frame_view_(false), |
| 773 is_print_ready_metafile_sent_(false), | 757 is_print_ready_metafile_sent_(false), |
| 774 ignore_css_margins_(false), | 758 ignore_css_margins_(false), |
| 775 is_scripted_printing_blocked_(false), | 759 is_scripted_printing_blocked_(false), |
| 776 notify_browser_of_print_failure_(true), | 760 notify_browser_of_print_failure_(true), |
| 777 print_for_preview_(false), | 761 print_for_preview_(false), |
| 778 delegate_(delegate.Pass()), | 762 delegate_(delegate.Pass()), |
| 779 print_node_in_progress_(false), | 763 print_node_in_progress_(false), |
| 780 is_loading_(false), | 764 is_loading_(false), |
| 781 is_scripted_preview_delayed_(false), | 765 is_scripted_preview_delayed_(false), |
| 782 weak_ptr_factory_(this) { | 766 weak_ptr_factory_(this) { |
| 783 if (!delegate_->IsPrintPreviewEnabled()) | 767 if (!delegate_->IsPrintPreviewEnabled()) |
| 784 DisablePreview(); | 768 DisablePreview(); |
| 785 } | 769 } |
| 786 | 770 |
| 787 PrintWebViewHelper::~PrintWebViewHelper() {} | 771 PrintWebViewHelper::~PrintWebViewHelper() { |
| 772 } |
| 788 | 773 |
| 789 // static | 774 // static |
| 790 void PrintWebViewHelper::DisablePreview() { | 775 void PrintWebViewHelper::DisablePreview() { |
| 791 g_is_preview_enabled_ = false; | 776 g_is_preview_enabled_ = false; |
| 792 } | 777 } |
| 793 | 778 |
| 794 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( | 779 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed(blink::WebFrame* frame, |
| 795 blink::WebFrame* frame, bool user_initiated) { | 780 bool user_initiated) { |
| 796 if (!delegate_->IsScriptedPrintEnabled()) | 781 if (!delegate_->IsScriptedPrintEnabled()) |
| 797 return false; | 782 return false; |
| 798 | 783 |
| 799 // If preview is enabled, then the print dialog is tab modal, and the user | 784 // If preview is enabled, then the print dialog is tab modal, and the user |
| 800 // can always close the tab on a mis-behaving page (the system print dialog | 785 // can always close the tab on a mis-behaving page (the system print dialog |
| 801 // is app modal). If the print was initiated through user action, don't | 786 // is app modal). If the print was initiated through user action, don't |
| 802 // throttle. Or, if the command line flag to skip throttling has been set. | 787 // throttle. Or, if the command line flag to skip throttling has been set. |
| 803 return !is_scripted_printing_blocked_ && | 788 return !is_scripted_printing_blocked_ && |
| 804 (user_initiated || g_is_preview_enabled_ || | 789 (user_initiated || g_is_preview_enabled_ || |
| 805 scripting_throttler_.IsAllowed(frame)); | 790 scripting_throttler_.IsAllowed(frame)); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 NOTREACHED(); | 863 NOTREACHED(); |
| 879 return; | 864 return; |
| 880 } | 865 } |
| 881 | 866 |
| 882 // The out-of-process plugin element is nested within a frame. In tests, there | 867 // The out-of-process plugin element is nested within a frame. In tests, there |
| 883 // may not be an iframe containing the out-of-process plugin, so continue with | 868 // may not be an iframe containing the out-of-process plugin, so continue with |
| 884 // the element with ID "pdf-viewer" if it isn't an iframe. | 869 // the element with ID "pdf-viewer" if it isn't an iframe. |
| 885 blink::WebLocalFrame* plugin_frame = pdf_element.document().frame(); | 870 blink::WebLocalFrame* plugin_frame = pdf_element.document().frame(); |
| 886 blink::WebElement plugin_element = pdf_element; | 871 blink::WebElement plugin_element = pdf_element; |
| 887 if (delegate_->IsOutOfProcessPdfEnabled() && | 872 if (delegate_->IsOutOfProcessPdfEnabled() && |
| 888 pdf_element.hasHTMLTagName("iframe")) { | 873 pdf_element.hasHTMLTagName("iframe")) { |
| 889 plugin_frame = blink::WebLocalFrame::fromFrameOwnerElement(pdf_element); | 874 plugin_frame = blink::WebLocalFrame::fromFrameOwnerElement(pdf_element); |
| 890 plugin_element = delegate_->GetPdfElement(plugin_frame); | 875 plugin_element = delegate_->GetPdfElement(plugin_frame); |
| 891 if (plugin_element.isNull()) { | 876 if (plugin_element.isNull()) { |
| 892 NOTREACHED(); | 877 NOTREACHED(); |
| 893 return; | 878 return; |
| 894 } | 879 } |
| 895 } | 880 } |
| 896 | 881 |
| 897 // Set |print_for_preview_| flag and autoreset it to back to original | 882 // Set |print_for_preview_| flag and autoreset it to back to original |
| 898 // on return. | 883 // on return. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 } | 944 } |
| 960 Print(frame, print_preview_context_.source_node(), false); | 945 Print(frame, print_preview_context_.source_node(), false); |
| 961 } | 946 } |
| 962 #endif // ENABLE_BASIC_PRINTING | 947 #endif // ENABLE_BASIC_PRINTING |
| 963 | 948 |
| 964 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( | 949 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( |
| 965 const PageSizeMargins& page_layout_in_points, | 950 const PageSizeMargins& page_layout_in_points, |
| 966 gfx::Size* page_size, | 951 gfx::Size* page_size, |
| 967 gfx::Rect* content_area) { | 952 gfx::Rect* content_area) { |
| 968 *page_size = gfx::Size( | 953 *page_size = gfx::Size( |
| 969 page_layout_in_points.content_width + | 954 page_layout_in_points.content_width + page_layout_in_points.margin_right + |
| 970 page_layout_in_points.margin_right + | |
| 971 page_layout_in_points.margin_left, | 955 page_layout_in_points.margin_left, |
| 972 page_layout_in_points.content_height + | 956 page_layout_in_points.content_height + page_layout_in_points.margin_top + |
| 973 page_layout_in_points.margin_top + | |
| 974 page_layout_in_points.margin_bottom); | 957 page_layout_in_points.margin_bottom); |
| 975 *content_area = gfx::Rect(page_layout_in_points.margin_left, | 958 *content_area = gfx::Rect(page_layout_in_points.margin_left, |
| 976 page_layout_in_points.margin_top, | 959 page_layout_in_points.margin_top, |
| 977 page_layout_in_points.content_width, | 960 page_layout_in_points.content_width, |
| 978 page_layout_in_points.content_height); | 961 page_layout_in_points.content_height); |
| 979 } | 962 } |
| 980 | 963 |
| 981 void PrintWebViewHelper::UpdateFrameMarginsCssInfo( | 964 void PrintWebViewHelper::UpdateFrameMarginsCssInfo( |
| 982 const base::DictionaryValue& settings) { | 965 const base::DictionaryValue& settings) { |
| 983 int margins_type = 0; | 966 int margins_type = 0; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1002 | 985 |
| 1003 if (!print_preview_context_.source_frame()) { | 986 if (!print_preview_context_.source_frame()) { |
| 1004 DidFinishPrinting(FAIL_PREVIEW); | 987 DidFinishPrinting(FAIL_PREVIEW); |
| 1005 return; | 988 return; |
| 1006 } | 989 } |
| 1007 | 990 |
| 1008 if (!UpdatePrintSettings(print_preview_context_.source_frame(), | 991 if (!UpdatePrintSettings(print_preview_context_.source_frame(), |
| 1009 print_preview_context_.source_node(), settings)) { | 992 print_preview_context_.source_node(), settings)) { |
| 1010 if (print_preview_context_.last_error() != PREVIEW_ERROR_BAD_SETTING) { | 993 if (print_preview_context_.last_error() != PREVIEW_ERROR_BAD_SETTING) { |
| 1011 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings( | 994 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings( |
| 1012 routing_id(), | 995 routing_id(), print_pages_params_ |
| 1013 print_pages_params_ ? | 996 ? print_pages_params_->params.document_cookie |
| 1014 print_pages_params_->params.document_cookie : 0)); | 997 : 0)); |
| 1015 notify_browser_of_print_failure_ = false; // Already sent. | 998 notify_browser_of_print_failure_ = false; // Already sent. |
| 1016 } | 999 } |
| 1017 DidFinishPrinting(FAIL_PREVIEW); | 1000 DidFinishPrinting(FAIL_PREVIEW); |
| 1018 return; | 1001 return; |
| 1019 } | 1002 } |
| 1020 | 1003 |
| 1021 // Set the options from document if we are previewing a pdf and send a | 1004 // Set the options from document if we are previewing a pdf and send a |
| 1022 // message to browser. | 1005 // message to browser. |
| 1023 if (print_pages_params_->params.is_first_request && | 1006 if (print_pages_params_->params.is_first_request && |
| 1024 !print_preview_context_.IsModifiable()) { | 1007 !print_preview_context_.IsModifiable()) { |
| 1025 PrintHostMsg_SetOptionsFromDocument_Params params; | 1008 PrintHostMsg_SetOptionsFromDocument_Params params; |
| 1026 SetOptionsFromDocument(params); | 1009 SetOptionsFromDocument(params); |
| 1027 Send(new PrintHostMsg_SetOptionsFromDocument(routing_id(), params)); | 1010 Send(new PrintHostMsg_SetOptionsFromDocument(routing_id(), params)); |
| 1028 } | 1011 } |
| 1029 | 1012 |
| 1030 is_print_ready_metafile_sent_ = false; | 1013 is_print_ready_metafile_sent_ = false; |
| 1031 | 1014 |
| 1032 // PDF printer device supports alpha blending. | 1015 // PDF printer device supports alpha blending. |
| 1033 print_pages_params_->params.supports_alpha_blend = true; | 1016 print_pages_params_->params.supports_alpha_blend = true; |
| 1034 | 1017 |
| 1035 bool generate_draft_pages = false; | 1018 bool generate_draft_pages = false; |
| 1036 if (!settings.GetBoolean(kSettingGenerateDraftData, | 1019 if (!settings.GetBoolean(kSettingGenerateDraftData, &generate_draft_pages)) { |
| 1037 &generate_draft_pages)) { | |
| 1038 NOTREACHED(); | 1020 NOTREACHED(); |
| 1039 } | 1021 } |
| 1040 print_preview_context_.set_generate_draft_pages(generate_draft_pages); | 1022 print_preview_context_.set_generate_draft_pages(generate_draft_pages); |
| 1041 | 1023 |
| 1042 PrepareFrameForPreviewDocument(); | 1024 PrepareFrameForPreviewDocument(); |
| 1043 } | 1025 } |
| 1044 | 1026 |
| 1045 void PrintWebViewHelper::PrepareFrameForPreviewDocument() { | 1027 void PrintWebViewHelper::PrepareFrameForPreviewDocument() { |
| 1046 reset_prep_frame_view_ = false; | 1028 reset_prep_frame_view_ = false; |
| 1047 | 1029 |
| 1048 if (!print_pages_params_ || CheckForCancel()) { | 1030 if (!print_pages_params_ || CheckForCancel()) { |
| 1049 DidFinishPrinting(FAIL_PREVIEW); | 1031 DidFinishPrinting(FAIL_PREVIEW); |
| 1050 return; | 1032 return; |
| 1051 } | 1033 } |
| 1052 | 1034 |
| 1053 // Don't reset loading frame or WebKit will fail assert. Just retry when | 1035 // Don't reset loading frame or WebKit will fail assert. Just retry when |
| 1054 // current selection is loaded. | 1036 // current selection is loaded. |
| 1055 if (prep_frame_view_ && prep_frame_view_->IsLoadingSelection()) { | 1037 if (prep_frame_view_ && prep_frame_view_->IsLoadingSelection()) { |
| 1056 reset_prep_frame_view_ = true; | 1038 reset_prep_frame_view_ = true; |
| 1057 return; | 1039 return; |
| 1058 } | 1040 } |
| 1059 | 1041 |
| 1060 const PrintMsg_Print_Params& print_params = print_pages_params_->params; | 1042 const PrintMsg_Print_Params& print_params = print_pages_params_->params; |
| 1061 prep_frame_view_.reset( | 1043 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( |
| 1062 new PrepareFrameAndViewForPrint(print_params, | 1044 print_params, print_preview_context_.source_frame(), |
| 1063 print_preview_context_.source_frame(), | 1045 print_preview_context_.source_node(), ignore_css_margins_)); |
| 1064 print_preview_context_.source_node(), | |
| 1065 ignore_css_margins_)); | |
| 1066 prep_frame_view_->CopySelectionIfNeeded( | 1046 prep_frame_view_->CopySelectionIfNeeded( |
| 1067 render_view()->GetWebkitPreferences(), | 1047 render_view()->GetWebkitPreferences(), |
| 1068 base::Bind(&PrintWebViewHelper::OnFramePreparedForPreviewDocument, | 1048 base::Bind(&PrintWebViewHelper::OnFramePreparedForPreviewDocument, |
| 1069 base::Unretained(this))); | 1049 base::Unretained(this))); |
| 1070 } | 1050 } |
| 1071 | 1051 |
| 1072 void PrintWebViewHelper::OnFramePreparedForPreviewDocument() { | 1052 void PrintWebViewHelper::OnFramePreparedForPreviewDocument() { |
| 1073 if (reset_prep_frame_view_) { | 1053 if (reset_prep_frame_view_) { |
| 1074 PrepareFrameForPreviewDocument(); | 1054 PrepareFrameForPreviewDocument(); |
| 1075 return; | 1055 return; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1090 if (!print_preview_context_.CreatePreviewDocument(prep_frame_view_.release(), | 1070 if (!print_preview_context_.CreatePreviewDocument(prep_frame_view_.release(), |
| 1091 pages)) { | 1071 pages)) { |
| 1092 return false; | 1072 return false; |
| 1093 } | 1073 } |
| 1094 | 1074 |
| 1095 PageSizeMargins default_page_layout; | 1075 PageSizeMargins default_page_layout; |
| 1096 ComputePageLayoutInPointsForCss(print_preview_context_.prepared_frame(), 0, | 1076 ComputePageLayoutInPointsForCss(print_preview_context_.prepared_frame(), 0, |
| 1097 print_params, ignore_css_margins_, NULL, | 1077 print_params, ignore_css_margins_, NULL, |
| 1098 &default_page_layout); | 1078 &default_page_layout); |
| 1099 | 1079 |
| 1100 bool has_page_size_style = PrintingFrameHasPageSizeStyle( | 1080 bool has_page_size_style = |
| 1101 print_preview_context_.prepared_frame(), | 1081 PrintingFrameHasPageSizeStyle(print_preview_context_.prepared_frame(), |
| 1102 print_preview_context_.total_page_count()); | 1082 print_preview_context_.total_page_count()); |
| 1103 int dpi = GetDPI(&print_params); | 1083 int dpi = GetDPI(&print_params); |
| 1104 | 1084 |
| 1105 gfx::Rect printable_area_in_points( | 1085 gfx::Rect printable_area_in_points( |
| 1106 ConvertUnit(print_params.printable_area.x(), dpi, kPointsPerInch), | 1086 ConvertUnit(print_params.printable_area.x(), dpi, kPointsPerInch), |
| 1107 ConvertUnit(print_params.printable_area.y(), dpi, kPointsPerInch), | 1087 ConvertUnit(print_params.printable_area.y(), dpi, kPointsPerInch), |
| 1108 ConvertUnit(print_params.printable_area.width(), dpi, kPointsPerInch), | 1088 ConvertUnit(print_params.printable_area.width(), dpi, kPointsPerInch), |
| 1109 ConvertUnit(print_params.printable_area.height(), dpi, kPointsPerInch)); | 1089 ConvertUnit(print_params.printable_area.height(), dpi, kPointsPerInch)); |
| 1110 | 1090 |
| 1111 // Margins: Send default page layout to browser process. | 1091 // Margins: Send default page layout to browser process. |
| 1112 Send(new PrintHostMsg_DidGetDefaultPageLayout(routing_id(), | 1092 Send(new PrintHostMsg_DidGetDefaultPageLayout(routing_id(), |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1201 GetPrintFrame(&frame); | 1181 GetPrintFrame(&frame); |
| 1202 DCHECK(frame); | 1182 DCHECK(frame); |
| 1203 // If we are printing a PDF extension frame, find the plugin node and print | 1183 // If we are printing a PDF extension frame, find the plugin node and print |
| 1204 // that instead. | 1184 // that instead. |
| 1205 auto plugin = delegate_->GetPdfElement(frame); | 1185 auto plugin = delegate_->GetPdfElement(frame); |
| 1206 if (!plugin.isNull()) { | 1186 if (!plugin.isNull()) { |
| 1207 PrintNode(plugin); | 1187 PrintNode(plugin); |
| 1208 return; | 1188 return; |
| 1209 } | 1189 } |
| 1210 print_preview_context_.InitWithFrame(frame); | 1190 print_preview_context_.InitWithFrame(frame); |
| 1211 RequestPrintPreview(selection_only ? | 1191 RequestPrintPreview(selection_only |
| 1212 PRINT_PREVIEW_USER_INITIATED_SELECTION : | 1192 ? PRINT_PREVIEW_USER_INITIATED_SELECTION |
| 1213 PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME); | 1193 : PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME); |
| 1214 } | 1194 } |
| 1215 | 1195 |
| 1216 bool PrintWebViewHelper::IsPrintingEnabled() { | 1196 bool PrintWebViewHelper::IsPrintingEnabled() { |
| 1217 bool result = false; | 1197 bool result = false; |
| 1218 Send(new PrintHostMsg_IsPrintingEnabled(routing_id(), &result)); | 1198 Send(new PrintHostMsg_IsPrintingEnabled(routing_id(), &result)); |
| 1219 return result; | 1199 return result; |
| 1220 } | 1200 } |
| 1221 | 1201 |
| 1222 void PrintWebViewHelper::PrintNode(const blink::WebNode& node) { | 1202 void PrintWebViewHelper::PrintNode(const blink::WebNode& node) { |
| 1223 if (node.isNull() || !node.document().frame()) { | 1203 if (node.isNull() || !node.document().frame()) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 } | 1244 } |
| 1265 | 1245 |
| 1266 // Some full screen plugins can say they don't want to print. | 1246 // Some full screen plugins can say they don't want to print. |
| 1267 if (!expected_page_count) { | 1247 if (!expected_page_count) { |
| 1268 DidFinishPrinting(FAIL_PRINT); | 1248 DidFinishPrinting(FAIL_PRINT); |
| 1269 return; | 1249 return; |
| 1270 } | 1250 } |
| 1271 | 1251 |
| 1272 // Ask the browser to show UI to retrieve the final print settings. | 1252 // Ask the browser to show UI to retrieve the final print settings. |
| 1273 if (delegate_->IsAskPrintSettingsEnabled() && | 1253 if (delegate_->IsAskPrintSettingsEnabled() && |
| 1274 !GetPrintSettingsFromUser(frame_ref.GetFrame(), node, | 1254 !GetPrintSettingsFromUser(frame_ref.GetFrame(), node, expected_page_count, |
| 1275 expected_page_count, | |
| 1276 is_scripted)) { | 1255 is_scripted)) { |
| 1277 DidFinishPrinting(OK); // Release resources and fail silently. | 1256 DidFinishPrinting(OK); // Release resources and fail silently. |
| 1278 return; | 1257 return; |
| 1279 } | 1258 } |
| 1280 | 1259 |
| 1281 // Render Pages for printing. | 1260 // Render Pages for printing. |
| 1282 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1261 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
| 1283 LOG(ERROR) << "RenderPagesForPrint failed"; | 1262 LOG(ERROR) << "RenderPagesForPrint failed"; |
| 1284 DidFinishPrinting(FAIL_PRINT); | 1263 DidFinishPrinting(FAIL_PRINT); |
| 1285 } | 1264 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1296 break; | 1275 break; |
| 1297 | 1276 |
| 1298 case FAIL_PRINT: | 1277 case FAIL_PRINT: |
| 1299 if (notify_browser_of_print_failure_ && print_pages_params_) { | 1278 if (notify_browser_of_print_failure_ && print_pages_params_) { |
| 1300 int cookie = print_pages_params_->params.document_cookie; | 1279 int cookie = print_pages_params_->params.document_cookie; |
| 1301 Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie)); | 1280 Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie)); |
| 1302 } | 1281 } |
| 1303 break; | 1282 break; |
| 1304 | 1283 |
| 1305 case FAIL_PREVIEW: | 1284 case FAIL_PREVIEW: |
| 1306 int cookie = print_pages_params_ ? | 1285 int cookie = |
| 1307 print_pages_params_->params.document_cookie : 0; | 1286 print_pages_params_ ? print_pages_params_->params.document_cookie : 0; |
| 1308 if (notify_browser_of_print_failure_) { | 1287 if (notify_browser_of_print_failure_) { |
| 1309 LOG(ERROR) << "CreatePreviewDocument failed"; | 1288 LOG(ERROR) << "CreatePreviewDocument failed"; |
| 1310 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); | 1289 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); |
| 1311 } else { | 1290 } else { |
| 1312 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); | 1291 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); |
| 1313 } | 1292 } |
| 1314 print_preview_context_.Failed(notify_browser_of_print_failure_); | 1293 print_preview_context_.Failed(notify_browser_of_print_failure_); |
| 1315 break; | 1294 break; |
| 1316 } | 1295 } |
| 1317 prep_frame_view_.reset(); | 1296 prep_frame_view_.reset(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 // Printing for system dialog. | 1329 // Printing for system dialog. |
| 1351 int printed_count = params.pages.empty() ? page_count : params.pages.size(); | 1330 int printed_count = params.pages.empty() ? page_count : params.pages.size(); |
| 1352 #if !defined(OS_CHROMEOS) | 1331 #if !defined(OS_CHROMEOS) |
| 1353 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.SystemDialog", printed_count); | 1332 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.SystemDialog", printed_count); |
| 1354 #else | 1333 #else |
| 1355 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToCloudPrintWebDialog", | 1334 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToCloudPrintWebDialog", |
| 1356 printed_count); | 1335 printed_count); |
| 1357 #endif // !defined(OS_CHROMEOS) | 1336 #endif // !defined(OS_CHROMEOS) |
| 1358 } | 1337 } |
| 1359 | 1338 |
| 1360 | |
| 1361 if (!PrintPagesNative(prep_frame_view_->frame(), page_count)) { | 1339 if (!PrintPagesNative(prep_frame_view_->frame(), page_count)) { |
| 1362 LOG(ERROR) << "Printing failed."; | 1340 LOG(ERROR) << "Printing failed."; |
| 1363 return DidFinishPrinting(FAIL_PRINT); | 1341 return DidFinishPrinting(FAIL_PRINT); |
| 1364 } | 1342 } |
| 1365 } | 1343 } |
| 1366 | 1344 |
| 1367 void PrintWebViewHelper::FinishFramePrinting() { | 1345 void PrintWebViewHelper::FinishFramePrinting() { |
| 1368 prep_frame_view_.reset(); | 1346 prep_frame_view_.reset(); |
| 1369 } | 1347 } |
| 1370 | 1348 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1418 // can safely assume there are no printer drivers configured. So we safely | 1396 // can safely assume there are no printer drivers configured. So we safely |
| 1419 // terminate. | 1397 // terminate. |
| 1420 bool result = true; | 1398 bool result = true; |
| 1421 if (!PrintMsg_Print_Params_IsValid(settings.params)) | 1399 if (!PrintMsg_Print_Params_IsValid(settings.params)) |
| 1422 result = false; | 1400 result = false; |
| 1423 | 1401 |
| 1424 // Reset to default values. | 1402 // Reset to default values. |
| 1425 ignore_css_margins_ = false; | 1403 ignore_css_margins_ = false; |
| 1426 settings.pages.clear(); | 1404 settings.pages.clear(); |
| 1427 | 1405 |
| 1428 settings.params.print_scaling_option = | 1406 settings.params.print_scaling_option = blink::WebPrintScalingOptionSourceSize; |
| 1429 blink::WebPrintScalingOptionSourceSize; | |
| 1430 if (fit_to_paper_size) { | 1407 if (fit_to_paper_size) { |
| 1431 settings.params.print_scaling_option = | 1408 settings.params.print_scaling_option = |
| 1432 blink::WebPrintScalingOptionFitToPrintableArea; | 1409 blink::WebPrintScalingOptionFitToPrintableArea; |
| 1433 } | 1410 } |
| 1434 | 1411 |
| 1435 SetPrintPagesParams(settings); | 1412 SetPrintPagesParams(settings); |
| 1436 return result; | 1413 return result; |
| 1437 } | 1414 } |
| 1438 | 1415 |
| 1439 bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebLocalFrame* frame, | 1416 bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebLocalFrame* frame, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1493 | 1470 |
| 1494 if (print_for_preview_ || !source_is_html) { | 1471 if (print_for_preview_ || !source_is_html) { |
| 1495 modified_job_settings.MergeDictionary(job_settings); | 1472 modified_job_settings.MergeDictionary(job_settings); |
| 1496 modified_job_settings.SetBoolean(kSettingHeaderFooterEnabled, false); | 1473 modified_job_settings.SetBoolean(kSettingHeaderFooterEnabled, false); |
| 1497 modified_job_settings.SetInteger(kSettingMarginsType, NO_MARGINS); | 1474 modified_job_settings.SetInteger(kSettingMarginsType, NO_MARGINS); |
| 1498 job_settings = &modified_job_settings; | 1475 job_settings = &modified_job_settings; |
| 1499 } | 1476 } |
| 1500 | 1477 |
| 1501 // Send the cookie so that UpdatePrintSettings can reuse PrinterQuery when | 1478 // Send the cookie so that UpdatePrintSettings can reuse PrinterQuery when |
| 1502 // possible. | 1479 // possible. |
| 1503 int cookie = print_pages_params_ ? | 1480 int cookie = |
| 1504 print_pages_params_->params.document_cookie : 0; | 1481 print_pages_params_ ? print_pages_params_->params.document_cookie : 0; |
| 1505 PrintMsg_PrintPages_Params settings; | 1482 PrintMsg_PrintPages_Params settings; |
| 1506 bool canceled = false; | 1483 bool canceled = false; |
| 1507 Send(new PrintHostMsg_UpdatePrintSettings( | 1484 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings, |
| 1508 routing_id(), cookie, *job_settings, &settings, &canceled)); | 1485 &settings, &canceled)); |
| 1509 if (canceled) { | 1486 if (canceled) { |
| 1510 notify_browser_of_print_failure_ = false; | 1487 notify_browser_of_print_failure_ = false; |
| 1511 return false; | 1488 return false; |
| 1512 } | 1489 } |
| 1513 | 1490 |
| 1514 if (!job_settings->GetInteger(kPreviewUIID, &settings.params.preview_ui_id)) { | 1491 if (!job_settings->GetInteger(kPreviewUIID, &settings.params.preview_ui_id)) { |
| 1515 NOTREACHED(); | 1492 NOTREACHED(); |
| 1516 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); | 1493 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); |
| 1517 return false; | 1494 return false; |
| 1518 } | 1495 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1597 base::Unretained(this))); | 1574 base::Unretained(this))); |
| 1598 return true; | 1575 return true; |
| 1599 } | 1576 } |
| 1600 | 1577 |
| 1601 #if defined(OS_POSIX) | 1578 #if defined(OS_POSIX) |
| 1602 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( | 1579 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( |
| 1603 PdfMetafileSkia* metafile, | 1580 PdfMetafileSkia* metafile, |
| 1604 base::SharedMemoryHandle* shared_mem_handle) { | 1581 base::SharedMemoryHandle* shared_mem_handle) { |
| 1605 uint32 buf_size = metafile->GetDataSize(); | 1582 uint32 buf_size = metafile->GetDataSize(); |
| 1606 scoped_ptr<base::SharedMemory> shared_buf( | 1583 scoped_ptr<base::SharedMemory> shared_buf( |
| 1607 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer( | 1584 content::RenderThread::Get() |
| 1608 buf_size).release()); | 1585 ->HostAllocateSharedMemoryBuffer(buf_size) |
| 1586 .release()); |
| 1609 | 1587 |
| 1610 if (shared_buf) { | 1588 if (shared_buf) { |
| 1611 if (shared_buf->Map(buf_size)) { | 1589 if (shared_buf->Map(buf_size)) { |
| 1612 metafile->GetData(shared_buf->memory(), buf_size); | 1590 metafile->GetData(shared_buf->memory(), buf_size); |
| 1613 return shared_buf->GiveToProcess(base::GetCurrentProcessHandle(), | 1591 return shared_buf->GiveToProcess(base::GetCurrentProcessHandle(), |
| 1614 shared_mem_handle); | 1592 shared_mem_handle); |
| 1615 } | 1593 } |
| 1616 } | 1594 } |
| 1617 return false; | 1595 return false; |
| 1618 } | 1596 } |
| 1619 #endif // defined(OS_POSIX) | 1597 #endif // defined(OS_POSIX) |
| 1620 | 1598 |
| 1621 void PrintWebViewHelper::ShowScriptedPrintPreview() { | 1599 void PrintWebViewHelper::ShowScriptedPrintPreview() { |
| 1622 if (is_scripted_preview_delayed_) { | 1600 if (is_scripted_preview_delayed_) { |
| 1623 is_scripted_preview_delayed_ = false; | 1601 is_scripted_preview_delayed_ = false; |
| 1624 Send(new PrintHostMsg_ShowScriptedPrintPreview(routing_id(), | 1602 Send(new PrintHostMsg_ShowScriptedPrintPreview( |
| 1625 print_preview_context_.IsModifiable())); | 1603 routing_id(), print_preview_context_.IsModifiable())); |
| 1626 } | 1604 } |
| 1627 } | 1605 } |
| 1628 | 1606 |
| 1629 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { | 1607 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { |
| 1630 const bool is_modifiable = print_preview_context_.IsModifiable(); | 1608 const bool is_modifiable = print_preview_context_.IsModifiable(); |
| 1631 const bool has_selection = print_preview_context_.HasSelection(); | 1609 const bool has_selection = print_preview_context_.HasSelection(); |
| 1632 PrintHostMsg_RequestPrintPreview_Params params; | 1610 PrintHostMsg_RequestPrintPreview_Params params; |
| 1633 params.is_modifiable = is_modifiable; | 1611 params.is_modifiable = is_modifiable; |
| 1634 params.has_selection = has_selection; | 1612 params.has_selection = has_selection; |
| 1635 switch (type) { | 1613 switch (type) { |
| 1636 case PRINT_PREVIEW_SCRIPTED: { | 1614 case PRINT_PREVIEW_SCRIPTED: { |
| 1637 // Shows scripted print preview in two stages. | 1615 // Shows scripted print preview in two stages. |
| 1638 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by | 1616 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by |
| 1639 // pumping messages here. | 1617 // pumping messages here. |
| 1640 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the | 1618 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the |
| 1641 // document has been loaded. | 1619 // document has been loaded. |
| 1642 is_scripted_preview_delayed_ = true; | 1620 is_scripted_preview_delayed_ = true; |
| 1643 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { | 1621 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { |
| 1644 // Wait for DidStopLoading. Plugins may not know the correct | 1622 // Wait for DidStopLoading. Plugins may not know the correct |
| 1645 // |is_modifiable| value until they are fully loaded, which occurs when | 1623 // |is_modifiable| value until they are fully loaded, which occurs when |
| 1646 // DidStopLoading() is called. Defer showing the preview until then. | 1624 // DidStopLoading() is called. Defer showing the preview until then. |
| 1647 on_stop_loading_closure_ = | 1625 on_stop_loading_closure_ = |
| 1648 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, | 1626 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, |
| 1649 base::Unretained(this)); | 1627 base::Unretained(this)); |
| 1650 } else { | 1628 } else { |
| 1651 base::MessageLoop::current()->PostTask( | 1629 base::MessageLoop::current()->PostTask( |
| 1652 FROM_HERE, | 1630 FROM_HERE, base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, |
| 1653 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, | 1631 weak_ptr_factory_.GetWeakPtr())); |
| 1654 weak_ptr_factory_.GetWeakPtr())); | |
| 1655 } | 1632 } |
| 1656 IPC::SyncMessage* msg = | 1633 IPC::SyncMessage* msg = |
| 1657 new PrintHostMsg_SetupScriptedPrintPreview(routing_id()); | 1634 new PrintHostMsg_SetupScriptedPrintPreview(routing_id()); |
| 1658 msg->EnableMessagePumping(); | 1635 msg->EnableMessagePumping(); |
| 1659 Send(msg); | 1636 Send(msg); |
| 1660 is_scripted_preview_delayed_ = false; | 1637 is_scripted_preview_delayed_ = false; |
| 1661 return; | 1638 return; |
| 1662 } | 1639 } |
| 1663 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { | 1640 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { |
| 1664 // Wait for DidStopLoading. Continuing with this function while | 1641 // Wait for DidStopLoading. Continuing with this function while |
| 1665 // |is_loading_| is true will cause print preview to hang when try to | 1642 // |is_loading_| is true will cause print preview to hang when try to |
| 1666 // print a PDF document. | 1643 // print a PDF document. |
| 1667 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { | 1644 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { |
| 1668 on_stop_loading_closure_ = | 1645 on_stop_loading_closure_ = |
| 1669 base::Bind(&PrintWebViewHelper::RequestPrintPreview, | 1646 base::Bind(&PrintWebViewHelper::RequestPrintPreview, |
| 1670 base::Unretained(this), | 1647 base::Unretained(this), type); |
| 1671 type); | |
| 1672 return; | 1648 return; |
| 1673 } | 1649 } |
| 1674 | 1650 |
| 1675 break; | 1651 break; |
| 1676 } | 1652 } |
| 1677 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { | 1653 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { |
| 1678 DCHECK(has_selection); | 1654 DCHECK(has_selection); |
| 1679 DCHECK(!GetPlugin(print_preview_context_.source_frame())); | 1655 DCHECK(!GetPlugin(print_preview_context_.source_frame())); |
| 1680 params.selection_only = has_selection; | 1656 params.selection_only = has_selection; |
| 1681 break; | 1657 break; |
| 1682 } | 1658 } |
| 1683 case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: { | 1659 case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: { |
| 1684 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { | 1660 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { |
| 1685 on_stop_loading_closure_ = | 1661 on_stop_loading_closure_ = |
| 1686 base::Bind(&PrintWebViewHelper::RequestPrintPreview, | 1662 base::Bind(&PrintWebViewHelper::RequestPrintPreview, |
| 1687 base::Unretained(this), | 1663 base::Unretained(this), type); |
| 1688 type); | |
| 1689 return; | 1664 return; |
| 1690 } | 1665 } |
| 1691 | 1666 |
| 1692 params.webnode_only = true; | 1667 params.webnode_only = true; |
| 1693 break; | 1668 break; |
| 1694 } | 1669 } |
| 1695 default: { | 1670 default: { |
| 1696 NOTREACHED(); | 1671 NOTREACHED(); |
| 1697 return; | 1672 return; |
| 1698 } | 1673 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1730 print_preview_context_.set_error( | 1705 print_preview_context_.set_error( |
| 1731 PREVIEW_ERROR_PAGE_RENDERED_WITHOUT_METAFILE); | 1706 PREVIEW_ERROR_PAGE_RENDERED_WITHOUT_METAFILE); |
| 1732 return false; | 1707 return false; |
| 1733 } | 1708 } |
| 1734 | 1709 |
| 1735 PrintHostMsg_DidPreviewPage_Params preview_page_params; | 1710 PrintHostMsg_DidPreviewPage_Params preview_page_params; |
| 1736 // Get the size of the resulting metafile. | 1711 // Get the size of the resulting metafile. |
| 1737 uint32 buf_size = metafile->GetDataSize(); | 1712 uint32 buf_size = metafile->GetDataSize(); |
| 1738 DCHECK_GT(buf_size, 0u); | 1713 DCHECK_GT(buf_size, 0u); |
| 1739 if (!CopyMetafileDataToSharedMem( | 1714 if (!CopyMetafileDataToSharedMem( |
| 1740 metafile, &(preview_page_params.metafile_data_handle))) { | 1715 metafile, &(preview_page_params.metafile_data_handle))) { |
| 1741 LOG(ERROR) << "CopyMetafileDataToSharedMem failed"; | 1716 LOG(ERROR) << "CopyMetafileDataToSharedMem failed"; |
| 1742 print_preview_context_.set_error(PREVIEW_ERROR_METAFILE_COPY_FAILED); | 1717 print_preview_context_.set_error(PREVIEW_ERROR_METAFILE_COPY_FAILED); |
| 1743 return false; | 1718 return false; |
| 1744 } | 1719 } |
| 1745 preview_page_params.data_size = buf_size; | 1720 preview_page_params.data_size = buf_size; |
| 1746 preview_page_params.page_number = page_number; | 1721 preview_page_params.page_number = page_number; |
| 1747 preview_page_params.preview_request_id = | 1722 preview_page_params.preview_request_id = |
| 1748 print_pages_params_->params.preview_request_id; | 1723 print_pages_params_->params.preview_request_id; |
| 1749 | 1724 |
| 1750 Send(new PrintHostMsg_DidPreviewPage(routing_id(), preview_page_params)); | 1725 Send(new PrintHostMsg_DidPreviewPage(routing_id(), preview_page_params)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1808 if (!metafile_->Init()) { | 1783 if (!metafile_->Init()) { |
| 1809 set_error(PREVIEW_ERROR_METAFILE_INIT_FAILED); | 1784 set_error(PREVIEW_ERROR_METAFILE_INIT_FAILED); |
| 1810 LOG(ERROR) << "PdfMetafileSkia Init failed"; | 1785 LOG(ERROR) << "PdfMetafileSkia Init failed"; |
| 1811 return false; | 1786 return false; |
| 1812 } | 1787 } |
| 1813 | 1788 |
| 1814 current_page_index_ = 0; | 1789 current_page_index_ = 0; |
| 1815 pages_to_render_ = pages; | 1790 pages_to_render_ = pages; |
| 1816 // Sort and make unique. | 1791 // Sort and make unique. |
| 1817 std::sort(pages_to_render_.begin(), pages_to_render_.end()); | 1792 std::sort(pages_to_render_.begin(), pages_to_render_.end()); |
| 1818 pages_to_render_.resize(std::unique(pages_to_render_.begin(), | 1793 pages_to_render_.resize( |
| 1819 pages_to_render_.end()) - | 1794 std::unique(pages_to_render_.begin(), pages_to_render_.end()) - |
| 1820 pages_to_render_.begin()); | 1795 pages_to_render_.begin()); |
| 1821 // Remove invalid pages. | 1796 // Remove invalid pages. |
| 1822 pages_to_render_.resize(std::lower_bound(pages_to_render_.begin(), | 1797 pages_to_render_.resize(std::lower_bound(pages_to_render_.begin(), |
| 1823 pages_to_render_.end(), | 1798 pages_to_render_.end(), |
| 1824 total_page_count_) - | 1799 total_page_count_) - |
| 1825 pages_to_render_.begin()); | 1800 pages_to_render_.begin()); |
| 1826 print_ready_metafile_page_count_ = pages_to_render_.size(); | 1801 print_ready_metafile_page_count_ = pages_to_render_.size(); |
| 1827 if (pages_to_render_.empty()) { | 1802 if (pages_to_render_.empty()) { |
| 1828 print_ready_metafile_page_count_ = total_page_count_; | 1803 print_ready_metafile_page_count_ = total_page_count_; |
| 1829 // Render all pages. | 1804 // Render all pages. |
| 1830 for (int i = 0; i < total_page_count_; ++i) | 1805 for (int i = 0; i < total_page_count_; ++i) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1866 base::TimeTicks begin_time = base::TimeTicks::Now(); | 1841 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 1867 metafile_->FinishDocument(); | 1842 metafile_->FinishDocument(); |
| 1868 | 1843 |
| 1869 if (print_ready_metafile_page_count_ <= 0) { | 1844 if (print_ready_metafile_page_count_ <= 0) { |
| 1870 NOTREACHED(); | 1845 NOTREACHED(); |
| 1871 return; | 1846 return; |
| 1872 } | 1847 } |
| 1873 | 1848 |
| 1874 UMA_HISTOGRAM_MEDIUM_TIMES("PrintPreview.RenderToPDFTime", | 1849 UMA_HISTOGRAM_MEDIUM_TIMES("PrintPreview.RenderToPDFTime", |
| 1875 document_render_time_); | 1850 document_render_time_); |
| 1876 base::TimeDelta total_time = (base::TimeTicks::Now() - begin_time) + | 1851 base::TimeDelta total_time = |
| 1877 document_render_time_; | 1852 (base::TimeTicks::Now() - begin_time) + document_render_time_; |
| 1878 UMA_HISTOGRAM_MEDIUM_TIMES("PrintPreview.RenderAndGeneratePDFTime", | 1853 UMA_HISTOGRAM_MEDIUM_TIMES("PrintPreview.RenderAndGeneratePDFTime", |
| 1879 total_time); | 1854 total_time); |
| 1880 UMA_HISTOGRAM_MEDIUM_TIMES("PrintPreview.RenderAndGeneratePDFTimeAvgPerPage", | 1855 UMA_HISTOGRAM_MEDIUM_TIMES("PrintPreview.RenderAndGeneratePDFTimeAvgPerPage", |
| 1881 total_time / pages_to_render_.size()); | 1856 total_time / pages_to_render_.size()); |
| 1882 } | 1857 } |
| 1883 | 1858 |
| 1884 void PrintWebViewHelper::PrintPreviewContext::Finished() { | 1859 void PrintWebViewHelper::PrintPreviewContext::Finished() { |
| 1885 DCHECK_EQ(DONE, state_); | 1860 DCHECK_EQ(DONE, state_); |
| 1886 state_ = INITIALIZED; | 1861 state_ = INITIALIZED; |
| 1887 ClearContext(); | 1862 ClearContext(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1917 bool PrintWebViewHelper::PrintPreviewContext::HasSelection() { | 1892 bool PrintWebViewHelper::PrintPreviewContext::HasSelection() { |
| 1918 return IsModifiable() && source_frame()->hasSelection(); | 1893 return IsModifiable() && source_frame()->hasSelection(); |
| 1919 } | 1894 } |
| 1920 | 1895 |
| 1921 bool PrintWebViewHelper::PrintPreviewContext::IsLastPageOfPrintReadyMetafile() | 1896 bool PrintWebViewHelper::PrintPreviewContext::IsLastPageOfPrintReadyMetafile() |
| 1922 const { | 1897 const { |
| 1923 DCHECK(IsRendering()); | 1898 DCHECK(IsRendering()); |
| 1924 return current_page_index_ == print_ready_metafile_page_count_; | 1899 return current_page_index_ == print_ready_metafile_page_count_; |
| 1925 } | 1900 } |
| 1926 | 1901 |
| 1927 bool PrintWebViewHelper::PrintPreviewContext::IsFinalPageRendered() const { | 1902 bool PrintWebViewHelper::PrintPreviewContext::IsFinalPageRendered() const { |
| 1928 DCHECK(IsRendering()); | 1903 DCHECK(IsRendering()); |
| 1929 return static_cast<size_t>(current_page_index_) == pages_to_render_.size(); | 1904 return static_cast<size_t>(current_page_index_) == pages_to_render_.size(); |
| 1930 } | 1905 } |
| 1931 | 1906 |
| 1932 void PrintWebViewHelper::PrintPreviewContext::set_generate_draft_pages( | 1907 void PrintWebViewHelper::PrintPreviewContext::set_generate_draft_pages( |
| 1933 bool generate_draft_pages) { | 1908 bool generate_draft_pages) { |
| 1934 DCHECK_EQ(INITIALIZED, state_); | 1909 DCHECK_EQ(INITIALIZED, state_); |
| 1935 generate_draft_pages_ = generate_draft_pages; | 1910 generate_draft_pages_ = generate_draft_pages; |
| 1936 } | 1911 } |
| 1937 | 1912 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2034 blink::WebConsoleMessage::LevelWarning, message)); | 2009 blink::WebConsoleMessage::LevelWarning, message)); |
| 2035 return false; | 2010 return false; |
| 2036 } | 2011 } |
| 2037 | 2012 |
| 2038 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2013 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2039 // Reset counter on successful print. | 2014 // Reset counter on successful print. |
| 2040 count_ = 0; | 2015 count_ = 0; |
| 2041 } | 2016 } |
| 2042 | 2017 |
| 2043 } // namespace printing | 2018 } // namespace printing |
| OLD | NEW |