OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // TODO(sgurun) copied from chrome/renderer. Remove after crbug.com/322276 | 5 // TODO(sgurun) copied from chrome/renderer. Remove after crbug.com/322276 |
6 | 6 |
7 #include "android_webview/renderer/print_web_view_helper.h" | 7 #include "android_webview/renderer/print_web_view_helper.h" |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "android_webview/common/print_messages.h" | 11 #include "android_webview/common/print_messages.h" |
12 #include "base/auto_reset.h" | 12 #include "base/auto_reset.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/process/process_handle.h" | 18 #include "base/process/process_handle.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "content/public/common/web_preferences.h" |
22 #include "content/public/renderer/render_thread.h" | 23 #include "content/public/renderer/render_thread.h" |
23 #include "content/public/renderer/render_view.h" | 24 #include "content/public/renderer/render_view.h" |
24 #include "content/public/renderer/web_preferences.h" | |
25 #include "net/base/escape.h" | 25 #include "net/base/escape.h" |
26 #include "printing/metafile.h" | 26 #include "printing/metafile.h" |
27 #include "printing/metafile_impl.h" | 27 #include "printing/metafile_impl.h" |
28 #include "printing/units.h" | 28 #include "printing/units.h" |
29 #include "skia/ext/vector_platform_device_skia.h" | 29 #include "skia/ext/vector_platform_device_skia.h" |
30 #include "third_party/WebKit/public/platform/WebSize.h" | 30 #include "third_party/WebKit/public/platform/WebSize.h" |
31 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 31 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
32 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 32 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
33 #include "third_party/WebKit/public/web/WebDocument.h" | 33 #include "third_party/WebKit/public/web/WebDocument.h" |
34 #include "third_party/WebKit/public/web/WebElement.h" | 34 #include "third_party/WebKit/public/web/WebElement.h" |
35 #include "third_party/WebKit/public/web/WebFrameClient.h" | 35 #include "third_party/WebKit/public/web/WebFrameClient.h" |
36 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 36 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
37 #include "third_party/WebKit/public/web/WebPlugin.h" | 37 #include "third_party/WebKit/public/web/WebPlugin.h" |
38 #include "third_party/WebKit/public/web/WebPluginDocument.h" | 38 #include "third_party/WebKit/public/web/WebPluginDocument.h" |
39 #include "third_party/WebKit/public/web/WebPrintParams.h" | 39 #include "third_party/WebKit/public/web/WebPrintParams.h" |
40 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" | 40 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" |
41 #include "third_party/WebKit/public/web/WebScriptSource.h" | 41 #include "third_party/WebKit/public/web/WebScriptSource.h" |
42 #include "third_party/WebKit/public/web/WebSettings.h" | 42 #include "third_party/WebKit/public/web/WebSettings.h" |
43 #include "third_party/WebKit/public/web/WebView.h" | 43 #include "third_party/WebKit/public/web/WebView.h" |
44 #include "third_party/WebKit/public/web/WebViewClient.h" | 44 #include "third_party/WebKit/public/web/WebViewClient.h" |
45 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
46 #include "ui/base/resource/resource_bundle.h" | 46 #include "ui/base/resource/resource_bundle.h" |
47 #include "webkit/common/webpreferences.h" | |
48 | 47 |
49 // This code is copied from chrome/renderer/printing. Code is slightly | 48 // This code is copied from chrome/renderer/printing. Code is slightly |
50 // modified to run it with webview, and the modifications are marked | 49 // modified to run it with webview, and the modifications are marked |
51 // using OS_ANDROID. | 50 // using OS_ANDROID. |
52 // TODO(sgurun): remove the code as part of componentization of printing. | 51 // TODO(sgurun): remove the code as part of componentization of printing. |
53 | 52 |
| 53 using content::WebPreferences; |
| 54 |
54 namespace printing { | 55 namespace printing { |
55 | 56 |
56 namespace { | 57 namespace { |
57 | 58 |
58 enum PrintPreviewHelperEvents { | 59 enum PrintPreviewHelperEvents { |
59 PREVIEW_EVENT_REQUESTED, | 60 PREVIEW_EVENT_REQUESTED, |
60 PREVIEW_EVENT_CACHE_HIT, // Unused | 61 PREVIEW_EVENT_CACHE_HIT, // Unused |
61 PREVIEW_EVENT_CREATE_DOCUMENT, | 62 PREVIEW_EVENT_CREATE_DOCUMENT, |
62 PREVIEW_EVENT_NEW_SETTINGS, // Unused | 63 PREVIEW_EVENT_NEW_SETTINGS, // Unused |
63 PREVIEW_EVENT_MAX, | 64 PREVIEW_EVENT_MAX, |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 RestoreSize(); | 659 RestoreSize(); |
659 // Create a new WebView with the same settings as the current display one. | 660 // Create a new WebView with the same settings as the current display one. |
660 // Except that we disable javascript (don't want any active content running | 661 // Except that we disable javascript (don't want any active content running |
661 // on the page). | 662 // on the page). |
662 WebPreferences prefs = preferences; | 663 WebPreferences prefs = preferences; |
663 prefs.javascript_enabled = false; | 664 prefs.javascript_enabled = false; |
664 prefs.java_enabled = false; | 665 prefs.java_enabled = false; |
665 | 666 |
666 blink::WebView* web_view = blink::WebView::create(this); | 667 blink::WebView* web_view = blink::WebView::create(this); |
667 owns_web_view_ = true; | 668 owns_web_view_ = true; |
668 content::ApplyWebPreferences(prefs, web_view); | 669 content::RenderView::ApplyWebPreferences(prefs, web_view); |
669 | |
670 web_view->setMainFrame(blink::WebLocalFrame::create(this)); | 670 web_view->setMainFrame(blink::WebLocalFrame::create(this)); |
671 frame_.Reset(web_view->mainFrame()->toWebLocalFrame()); | 671 frame_.Reset(web_view->mainFrame()->toWebLocalFrame()); |
672 node_to_print_.reset(); | 672 node_to_print_.reset(); |
673 | 673 |
674 // When loading is done this will call didStopLoading() and that will do the | 674 // When loading is done this will call didStopLoading() and that will do the |
675 // actual printing. | 675 // actual printing. |
676 frame()->loadRequest(blink::WebURLRequest(GURL(url_str))); | 676 frame()->loadRequest(blink::WebURLRequest(GURL(url_str))); |
677 } | 677 } |
678 | 678 |
679 bool PrepareFrameAndViewForPrint::allowsBrokenNullLayerTreeView() const { | 679 bool PrepareFrameAndViewForPrint::allowsBrokenNullLayerTreeView() const { |
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1583 print_pages_params_->params.print_scaling_option = scaling_option; | 1583 print_pages_params_->params.print_scaling_option = scaling_option; |
1584 return (print_settings.params.dpi && print_settings.params.document_cookie); | 1584 return (print_settings.params.dpi && print_settings.params.document_cookie); |
1585 } | 1585 } |
1586 | 1586 |
1587 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame, | 1587 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame, |
1588 const blink::WebNode& node) { | 1588 const blink::WebNode& node) { |
1589 if (!frame || prep_frame_view_) | 1589 if (!frame || prep_frame_view_) |
1590 return false; | 1590 return false; |
1591 const PrintMsg_PrintPages_Params& params = *print_pages_params_; | 1591 const PrintMsg_PrintPages_Params& params = *print_pages_params_; |
1592 const PrintMsg_Print_Params& print_params = params.params; | 1592 const PrintMsg_Print_Params& print_params = params.params; |
1593 prep_frame_view_.reset( | 1593 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( |
1594 new PrepareFrameAndViewForPrint(print_params, frame, node, | 1594 print_params, frame, node, ignore_css_margins_)); |
1595 ignore_css_margins_)); | |
1596 DCHECK(!print_pages_params_->params.selection_only || | 1595 DCHECK(!print_pages_params_->params.selection_only || |
1597 print_pages_params_->pages.empty()); | 1596 print_pages_params_->pages.empty()); |
1598 prep_frame_view_->CopySelectionIfNeeded( | 1597 prep_frame_view_->CopySelectionIfNeeded( |
1599 render_view()->GetWebkitPreferences(), | 1598 render_view()->GetWebkitPreferences(), |
1600 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, | 1599 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, |
1601 base::Unretained(this))); | 1600 base::Unretained(this))); |
1602 return true; | 1601 return true; |
1603 } | 1602 } |
1604 | 1603 |
1605 #if defined(OS_POSIX) | 1604 #if defined(OS_POSIX) |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2017 } | 2016 } |
2018 | 2017 |
2019 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 2018 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
2020 prep_frame_view_.reset(); | 2019 prep_frame_view_.reset(); |
2021 metafile_.reset(); | 2020 metafile_.reset(); |
2022 pages_to_render_.clear(); | 2021 pages_to_render_.clear(); |
2023 error_ = PREVIEW_ERROR_NONE; | 2022 error_ = PREVIEW_ERROR_NONE; |
2024 } | 2023 } |
2025 | 2024 |
2026 } // namespace printing | 2025 } // namespace printing |
OLD | NEW |