Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: android_webview/renderer/print_web_view_helper.cc

Issue 357203003: Move webpreferences.* from webkit/ to content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: RenderView::FromWebView Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
670 web_view->setMainFrame(blink::WebLocalFrame::create(this)); 669 web_view->setMainFrame(blink::WebLocalFrame::create(this));
671 frame_.Reset(web_view->mainFrame()->toWebLocalFrame()); 670 frame_.Reset(web_view->mainFrame()->toWebLocalFrame());
672 node_to_print_.reset(); 671 node_to_print_.reset();
673 672
673 content::RenderView::FromWebView(frame_.GetFrame()->view())
674 ->ApplyWebPreferences(prefs);
boliu 2014/07/03 16:49:32 Ohh, now I understand. Printing is creating its ow
tfarina 2014/07/03 17:25:34 OK. That is a design decision. John, what is you
675
674 // When loading is done this will call didStopLoading() and that will do the 676 // When loading is done this will call didStopLoading() and that will do the
675 // actual printing. 677 // actual printing.
676 frame()->loadRequest(blink::WebURLRequest(GURL(url_str))); 678 frame()->loadRequest(blink::WebURLRequest(GURL(url_str)));
677 } 679 }
678 680
679 bool PrepareFrameAndViewForPrint::allowsBrokenNullLayerTreeView() const { 681 bool PrepareFrameAndViewForPrint::allowsBrokenNullLayerTreeView() const {
680 return true; 682 return true;
681 } 683 }
682 684
683 void PrepareFrameAndViewForPrint::didStopLoading() { 685 void PrepareFrameAndViewForPrint::didStopLoading() {
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 print_pages_params_->params.print_scaling_option = scaling_option; 1585 print_pages_params_->params.print_scaling_option = scaling_option;
1584 return (print_settings.params.dpi && print_settings.params.document_cookie); 1586 return (print_settings.params.dpi && print_settings.params.document_cookie);
1585 } 1587 }
1586 1588
1587 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame, 1589 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame,
1588 const blink::WebNode& node) { 1590 const blink::WebNode& node) {
1589 if (!frame || prep_frame_view_) 1591 if (!frame || prep_frame_view_)
1590 return false; 1592 return false;
1591 const PrintMsg_PrintPages_Params& params = *print_pages_params_; 1593 const PrintMsg_PrintPages_Params& params = *print_pages_params_;
1592 const PrintMsg_Print_Params& print_params = params.params; 1594 const PrintMsg_Print_Params& print_params = params.params;
1593 prep_frame_view_.reset( 1595 prep_frame_view_.reset(new PrepareFrameAndViewForPrint(
1594 new PrepareFrameAndViewForPrint(print_params, frame, node, 1596 print_params, frame, node, ignore_css_margins_));
1595 ignore_css_margins_));
1596 DCHECK(!print_pages_params_->params.selection_only || 1597 DCHECK(!print_pages_params_->params.selection_only ||
1597 print_pages_params_->pages.empty()); 1598 print_pages_params_->pages.empty());
1598 prep_frame_view_->CopySelectionIfNeeded( 1599 prep_frame_view_->CopySelectionIfNeeded(
1599 render_view()->GetWebkitPreferences(), 1600 render_view()->GetWebkitPreferences(),
1600 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, 1601 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages,
1601 base::Unretained(this))); 1602 base::Unretained(this)));
1602 return true; 1603 return true;
1603 } 1604 }
1604 1605
1605 #if defined(OS_POSIX) 1606 #if defined(OS_POSIX)
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
2017 } 2018 }
2018 2019
2019 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { 2020 void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
2020 prep_frame_view_.reset(); 2021 prep_frame_view_.reset();
2021 metafile_.reset(); 2022 metafile_.reset();
2022 pages_to_render_.clear(); 2023 pages_to_render_.clear();
2023 error_ = PREVIEW_ERROR_NONE; 2024 error_ = PREVIEW_ERROR_NONE;
2024 } 2025 }
2025 2026
2026 } // namespace printing 2027 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698