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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 const PageSizeMargins& page_layout, | 515 const PageSizeMargins& page_layout, |
516 const PrintMsg_Print_Params& params) { | 516 const PrintMsg_Print_Params& params) { |
517 SkAutoCanvasRestore auto_restore(canvas, true); | 517 SkAutoCanvasRestore auto_restore(canvas, true); |
518 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); | 518 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); |
519 | 519 |
520 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + | 520 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + |
521 page_layout.content_width, | 521 page_layout.content_width, |
522 page_layout.margin_top + page_layout.margin_bottom + | 522 page_layout.margin_top + page_layout.margin_bottom + |
523 page_layout.content_height); | 523 page_layout.content_height); |
524 | 524 |
525 blink::WebView* web_view = blink::WebView::create(NULL); | 525 blink::WebView* web_view = blink::WebView::create(nullptr, true); |
526 web_view->settings()->setJavaScriptEnabled(true); | 526 web_view->settings()->setJavaScriptEnabled(true); |
527 | 527 |
528 blink::WebLocalFrame* frame = | 528 blink::WebLocalFrame* frame = |
529 blink::WebLocalFrame::create(blink::WebTreeScopeType::Document, NULL); | 529 blink::WebLocalFrame::create(blink::WebTreeScopeType::Document, NULL); |
530 web_view->setMainFrame(frame); | 530 web_view->setMainFrame(frame); |
531 | 531 |
532 base::StringValue html(ResourceBundle::GetSharedInstance().GetLocalizedString( | 532 base::StringValue html(ResourceBundle::GetSharedInstance().GetLocalizedString( |
533 IDR_PRINT_PREVIEW_PAGE)); | 533 IDR_PRINT_PREVIEW_PAGE)); |
534 // Load page with script to avoid async operations. | 534 // Load page with script to avoid async operations. |
535 ExecuteScript(frame, kPageLoadScriptFormat, html); | 535 ExecuteScript(frame, kPageLoadScriptFormat, html); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 std::string url_str = "data:text/html;charset=utf-8,"; | 732 std::string url_str = "data:text/html;charset=utf-8,"; |
733 url_str.append( | 733 url_str.append( |
734 net::EscapeQueryParamValue(frame()->selectionAsMarkup().utf8(), false)); | 734 net::EscapeQueryParamValue(frame()->selectionAsMarkup().utf8(), false)); |
735 RestoreSize(); | 735 RestoreSize(); |
736 // Create a new WebView with the same settings as the current display one. | 736 // Create a new WebView with the same settings as the current display one. |
737 // Except that we disable javascript (don't want any active content running | 737 // Except that we disable javascript (don't want any active content running |
738 // on the page). | 738 // on the page). |
739 WebPreferences prefs = preferences; | 739 WebPreferences prefs = preferences; |
740 prefs.javascript_enabled = false; | 740 prefs.javascript_enabled = false; |
741 | 741 |
742 blink::WebView* web_view = blink::WebView::create(this); | 742 blink::WebView* web_view = blink::WebView::create(this, true); |
743 owns_web_view_ = true; | 743 owns_web_view_ = true; |
744 content::RenderView::ApplyWebPreferences(prefs, web_view); | 744 content::RenderView::ApplyWebPreferences(prefs, web_view); |
745 web_view->setMainFrame( | 745 web_view->setMainFrame( |
746 blink::WebLocalFrame::create(blink::WebTreeScopeType::Document, this)); | 746 blink::WebLocalFrame::create(blink::WebTreeScopeType::Document, this)); |
747 frame_.Reset(web_view->mainFrame()->toWebLocalFrame()); | 747 frame_.Reset(web_view->mainFrame()->toWebLocalFrame()); |
748 node_to_print_.reset(); | 748 node_to_print_.reset(); |
749 | 749 |
750 // When loading is done this will call didStopLoading() and that will do the | 750 // When loading is done this will call didStopLoading() and that will do the |
751 // actual printing. | 751 // actual printing. |
752 frame()->loadRequest(blink::WebURLRequest(GURL(url_str))); | 752 frame()->loadRequest(blink::WebURLRequest(GURL(url_str))); |
(...skipping 1492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2245 blink::WebConsoleMessage::LevelWarning, message)); | 2245 blink::WebConsoleMessage::LevelWarning, message)); |
2246 return false; | 2246 return false; |
2247 } | 2247 } |
2248 | 2248 |
2249 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2249 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2250 // Reset counter on successful print. | 2250 // Reset counter on successful print. |
2251 count_ = 0; | 2251 count_ = 0; |
2252 } | 2252 } |
2253 | 2253 |
2254 } // namespace printing | 2254 } // namespace printing |
OLD | NEW |