| 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 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 is_print_ready_metafile_sent_(false), | 905 is_print_ready_metafile_sent_(false), |
| 906 ignore_css_margins_(false), | 906 ignore_css_margins_(false), |
| 907 is_printing_enabled_(true), | 907 is_printing_enabled_(true), |
| 908 notify_browser_of_print_failure_(true), | 908 notify_browser_of_print_failure_(true), |
| 909 print_for_preview_(false), | 909 print_for_preview_(false), |
| 910 delegate_(std::move(delegate)), | 910 delegate_(std::move(delegate)), |
| 911 print_node_in_progress_(false), | 911 print_node_in_progress_(false), |
| 912 is_loading_(false), | 912 is_loading_(false), |
| 913 is_scripted_preview_delayed_(false), | 913 is_scripted_preview_delayed_(false), |
| 914 ipc_nesting_level_(0), | 914 ipc_nesting_level_(0), |
| 915 render_frame_gone_(false), |
| 915 weak_ptr_factory_(this) { | 916 weak_ptr_factory_(this) { |
| 916 if (!delegate_->IsPrintPreviewEnabled()) | 917 if (!delegate_->IsPrintPreviewEnabled()) |
| 917 DisablePreview(); | 918 DisablePreview(); |
| 918 } | 919 } |
| 919 | 920 |
| 920 PrintWebViewHelper::~PrintWebViewHelper() { | 921 PrintWebViewHelper::~PrintWebViewHelper() { |
| 921 } | 922 } |
| 922 | 923 |
| 923 // static | 924 // static |
| 924 void PrintWebViewHelper::DisablePreview() { | 925 void PrintWebViewHelper::DisablePreview() { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { | 987 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
| 987 // The class is not designed to handle recursive messages. This is not | 988 // The class is not designed to handle recursive messages. This is not |
| 988 // expected during regular flow. However, during rendering of content for | 989 // expected during regular flow. However, during rendering of content for |
| 989 // printing, lower level code may run nested message loop. E.g. PDF may has | 990 // printing, lower level code may run nested message loop. E.g. PDF may has |
| 990 // script to show message box http://crbug.com/502562. In that moment browser | 991 // script to show message box http://crbug.com/502562. In that moment browser |
| 991 // may receive updated printer capabilities and decide to restart print | 992 // may receive updated printer capabilities and decide to restart print |
| 992 // preview generation. When this happened message handling function may | 993 // preview generation. When this happened message handling function may |
| 993 // choose to ignore message or safely crash process. | 994 // choose to ignore message or safely crash process. |
| 994 ++ipc_nesting_level_; | 995 ++ipc_nesting_level_; |
| 995 | 996 |
| 996 auto self = weak_ptr_factory_.GetWeakPtr(); | |
| 997 | |
| 998 bool handled = true; | 997 bool handled = true; |
| 999 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) | 998 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) |
| 1000 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 999 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 1001 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) | 1000 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) |
| 1002 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) | 1001 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) |
| 1003 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) | 1002 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 1004 #if BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1003 #if BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 1005 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) | 1004 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) |
| 1006 #endif | 1005 #endif |
| 1007 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1006 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 1008 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) | 1007 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) |
| 1009 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) | 1008 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) |
| 1010 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) | 1009 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) |
| 1011 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1010 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 1012 IPC_MESSAGE_HANDLER(PrintMsg_SetPrintingEnabled, OnSetPrintingEnabled) | 1011 IPC_MESSAGE_HANDLER(PrintMsg_SetPrintingEnabled, OnSetPrintingEnabled) |
| 1013 IPC_MESSAGE_UNHANDLED(handled = false) | 1012 IPC_MESSAGE_UNHANDLED(handled = false) |
| 1014 IPC_END_MESSAGE_MAP() | 1013 IPC_END_MESSAGE_MAP() |
| 1015 | 1014 |
| 1016 // Check if |this| is still valid. e.g. when OnPrintPages() returns. | 1015 --ipc_nesting_level_; |
| 1017 if (self) | 1016 if (ipc_nesting_level_ == 0 && render_frame_gone_) |
| 1018 --ipc_nesting_level_; | 1017 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 1019 return handled; | 1018 return handled; |
| 1020 } | 1019 } |
| 1021 | 1020 |
| 1022 void PrintWebViewHelper::OnDestruct() { | 1021 void PrintWebViewHelper::OnDestruct() { |
| 1022 if (ipc_nesting_level_ > 0) { |
| 1023 render_frame_gone_ = true; |
| 1024 return; |
| 1025 } |
| 1023 delete this; | 1026 delete this; |
| 1024 } | 1027 } |
| 1025 | 1028 |
| 1026 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 1029 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 1027 void PrintWebViewHelper::OnPrintPages() { | 1030 void PrintWebViewHelper::OnPrintPages() { |
| 1028 if (ipc_nesting_level_> 1) | 1031 if (ipc_nesting_level_> 1) |
| 1029 return; | 1032 return; |
| 1030 | 1033 |
| 1031 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); | 1034 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); |
| 1032 | 1035 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 return; | 1206 return; |
| 1204 } | 1207 } |
| 1205 | 1208 |
| 1206 const PrintMsg_Print_Params& print_params = print_pages_params_->params; | 1209 const PrintMsg_Print_Params& print_params = print_pages_params_->params; |
| 1207 prep_frame_view_ = base::MakeUnique<PrepareFrameAndViewForPrint>( | 1210 prep_frame_view_ = base::MakeUnique<PrepareFrameAndViewForPrint>( |
| 1208 print_params, print_preview_context_.source_frame(), | 1211 print_params, print_preview_context_.source_frame(), |
| 1209 print_preview_context_.source_node(), ignore_css_margins_); | 1212 print_preview_context_.source_node(), ignore_css_margins_); |
| 1210 prep_frame_view_->CopySelectionIfNeeded( | 1213 prep_frame_view_->CopySelectionIfNeeded( |
| 1211 render_frame()->GetWebkitPreferences(), | 1214 render_frame()->GetWebkitPreferences(), |
| 1212 base::Bind(&PrintWebViewHelper::OnFramePreparedForPreviewDocument, | 1215 base::Bind(&PrintWebViewHelper::OnFramePreparedForPreviewDocument, |
| 1213 base::Unretained(this))); | 1216 weak_ptr_factory_.GetWeakPtr())); |
| 1214 } | 1217 } |
| 1215 | 1218 |
| 1216 void PrintWebViewHelper::OnFramePreparedForPreviewDocument() { | 1219 void PrintWebViewHelper::OnFramePreparedForPreviewDocument() { |
| 1217 if (reset_prep_frame_view_) { | 1220 if (reset_prep_frame_view_) { |
| 1218 PrepareFrameForPreviewDocument(); | 1221 PrepareFrameForPreviewDocument(); |
| 1219 return; | 1222 return; |
| 1220 } | 1223 } |
| 1221 DidFinishPrinting(CreatePreviewDocument() ? OK : FAIL_PREVIEW); | 1224 DidFinishPrinting(CreatePreviewDocument() ? OK : FAIL_PREVIEW); |
| 1222 } | 1225 } |
| 1223 | 1226 |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1831 | 1834 |
| 1832 const PrintMsg_PrintPages_Params& params = *print_pages_params_; | 1835 const PrintMsg_PrintPages_Params& params = *print_pages_params_; |
| 1833 const PrintMsg_Print_Params& print_params = params.params; | 1836 const PrintMsg_Print_Params& print_params = params.params; |
| 1834 prep_frame_view_ = base::MakeUnique<PrepareFrameAndViewForPrint>( | 1837 prep_frame_view_ = base::MakeUnique<PrepareFrameAndViewForPrint>( |
| 1835 print_params, frame, node, ignore_css_margins_); | 1838 print_params, frame, node, ignore_css_margins_); |
| 1836 DCHECK(!print_pages_params_->params.selection_only || | 1839 DCHECK(!print_pages_params_->params.selection_only || |
| 1837 print_pages_params_->pages.empty()); | 1840 print_pages_params_->pages.empty()); |
| 1838 prep_frame_view_->CopySelectionIfNeeded( | 1841 prep_frame_view_->CopySelectionIfNeeded( |
| 1839 render_frame()->GetWebkitPreferences(), | 1842 render_frame()->GetWebkitPreferences(), |
| 1840 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, | 1843 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, |
| 1841 base::Unretained(this))); | 1844 weak_ptr_factory_.GetWeakPtr())); |
| 1842 return true; | 1845 return true; |
| 1843 } | 1846 } |
| 1844 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) | 1847 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 1845 | 1848 |
| 1846 #if !defined(OS_MACOSX) | 1849 #if !defined(OS_MACOSX) |
| 1847 void PrintWebViewHelper::PrintPageInternal(const PrintMsg_Print_Params& params, | 1850 void PrintWebViewHelper::PrintPageInternal(const PrintMsg_Print_Params& params, |
| 1848 int page_number, | 1851 int page_number, |
| 1849 blink::WebLocalFrame* frame, | 1852 blink::WebLocalFrame* frame, |
| 1850 PdfMetafileSkia* metafile, | 1853 PdfMetafileSkia* metafile, |
| 1851 gfx::Size* page_size_in_dpi, | 1854 gfx::Size* page_size_in_dpi, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1975 // pumping messages here. | 1978 // pumping messages here. |
| 1976 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the | 1979 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the |
| 1977 // document has been loaded. | 1980 // document has been loaded. |
| 1978 is_scripted_preview_delayed_ = true; | 1981 is_scripted_preview_delayed_ = true; |
| 1979 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { | 1982 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { |
| 1980 // Wait for DidStopLoading. Plugins may not know the correct | 1983 // Wait for DidStopLoading. Plugins may not know the correct |
| 1981 // |is_modifiable| value until they are fully loaded, which occurs when | 1984 // |is_modifiable| value until they are fully loaded, which occurs when |
| 1982 // DidStopLoading() is called. Defer showing the preview until then. | 1985 // DidStopLoading() is called. Defer showing the preview until then. |
| 1983 on_stop_loading_closure_ = | 1986 on_stop_loading_closure_ = |
| 1984 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, | 1987 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, |
| 1985 base::Unretained(this)); | 1988 weak_ptr_factory_.GetWeakPtr()); |
| 1986 } else { | 1989 } else { |
| 1987 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1990 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1988 FROM_HERE, base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, | 1991 FROM_HERE, base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, |
| 1989 weak_ptr_factory_.GetWeakPtr())); | 1992 weak_ptr_factory_.GetWeakPtr())); |
| 1990 } | 1993 } |
| 1991 auto msg = base::MakeUnique<PrintHostMsg_SetupScriptedPrintPreview>( | 1994 auto msg = base::MakeUnique<PrintHostMsg_SetupScriptedPrintPreview>( |
| 1992 routing_id()); | 1995 routing_id()); |
| 1993 msg->EnableMessagePumping(); | 1996 msg->EnableMessagePumping(); |
| 1994 auto self = weak_ptr_factory_.GetWeakPtr(); | 1997 auto self = weak_ptr_factory_.GetWeakPtr(); |
| 1995 Send(msg.release()); | 1998 Send(msg.release()); |
| 1996 // Check if |this| is still valid. | 1999 // Check if |this| is still valid. |
| 1997 if (self) | 2000 if (self) |
| 1998 is_scripted_preview_delayed_ = false; | 2001 is_scripted_preview_delayed_ = false; |
| 1999 return; | 2002 return; |
| 2000 } | 2003 } |
| 2001 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { | 2004 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { |
| 2002 // Wait for DidStopLoading. Continuing with this function while | 2005 // Wait for DidStopLoading. Continuing with this function while |
| 2003 // |is_loading_| is true will cause print preview to hang when try to | 2006 // |is_loading_| is true will cause print preview to hang when try to |
| 2004 // print a PDF document. | 2007 // print a PDF document. |
| 2005 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { | 2008 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { |
| 2006 on_stop_loading_closure_ = | 2009 on_stop_loading_closure_ = |
| 2007 base::Bind(&PrintWebViewHelper::RequestPrintPreview, | 2010 base::Bind(&PrintWebViewHelper::RequestPrintPreview, |
| 2008 base::Unretained(this), type); | 2011 weak_ptr_factory_.GetWeakPtr(), type); |
| 2009 return; | 2012 return; |
| 2010 } | 2013 } |
| 2011 | 2014 |
| 2012 break; | 2015 break; |
| 2013 } | 2016 } |
| 2014 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { | 2017 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { |
| 2015 DCHECK(has_selection); | 2018 DCHECK(has_selection); |
| 2016 DCHECK(!GetPlugin(print_preview_context_.source_frame())); | 2019 DCHECK(!GetPlugin(print_preview_context_.source_frame())); |
| 2017 params.selection_only = has_selection; | 2020 params.selection_only = has_selection; |
| 2018 break; | 2021 break; |
| 2019 } | 2022 } |
| 2020 case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: { | 2023 case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: { |
| 2021 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { | 2024 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { |
| 2022 on_stop_loading_closure_ = | 2025 on_stop_loading_closure_ = |
| 2023 base::Bind(&PrintWebViewHelper::RequestPrintPreview, | 2026 base::Bind(&PrintWebViewHelper::RequestPrintPreview, |
| 2024 base::Unretained(this), type); | 2027 weak_ptr_factory_.GetWeakPtr(), type); |
| 2025 return; | 2028 return; |
| 2026 } | 2029 } |
| 2027 | 2030 |
| 2028 params.webnode_only = true; | 2031 params.webnode_only = true; |
| 2029 break; | 2032 break; |
| 2030 } | 2033 } |
| 2031 default: { | 2034 default: { |
| 2032 NOTREACHED(); | 2035 NOTREACHED(); |
| 2033 return; | 2036 return; |
| 2034 } | 2037 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2083 | 2086 |
| 2084 Send(new PrintHostMsg_DidPreviewPage(routing_id(), preview_page_params)); | 2087 Send(new PrintHostMsg_DidPreviewPage(routing_id(), preview_page_params)); |
| 2085 return true; | 2088 return true; |
| 2086 } | 2089 } |
| 2087 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 2090 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 2088 | 2091 |
| 2089 PrintWebViewHelper::PrintPreviewContext::PrintPreviewContext() | 2092 PrintWebViewHelper::PrintPreviewContext::PrintPreviewContext() |
| 2090 : total_page_count_(0), | 2093 : total_page_count_(0), |
| 2091 current_page_index_(0), | 2094 current_page_index_(0), |
| 2092 generate_draft_pages_(true), | 2095 generate_draft_pages_(true), |
| 2096 is_modifiable_(true), |
| 2093 print_ready_metafile_page_count_(0), | 2097 print_ready_metafile_page_count_(0), |
| 2094 error_(PREVIEW_ERROR_NONE), | 2098 error_(PREVIEW_ERROR_NONE), |
| 2095 state_(UNINITIALIZED) { | 2099 state_(UNINITIALIZED) {} |
| 2096 } | |
| 2097 | 2100 |
| 2098 PrintWebViewHelper::PrintPreviewContext::~PrintPreviewContext() { | 2101 PrintWebViewHelper::PrintPreviewContext::~PrintPreviewContext() { |
| 2099 } | 2102 } |
| 2100 | 2103 |
| 2101 void PrintWebViewHelper::PrintPreviewContext::InitWithFrame( | 2104 void PrintWebViewHelper::PrintPreviewContext::InitWithFrame( |
| 2102 blink::WebLocalFrame* web_frame) { | 2105 blink::WebLocalFrame* web_frame) { |
| 2103 DCHECK(web_frame); | 2106 DCHECK(web_frame); |
| 2104 DCHECK(!IsRendering()); | 2107 DCHECK(!IsRendering()); |
| 2105 state_ = INITIALIZED; | 2108 state_ = INITIALIZED; |
| 2106 source_frame_.Reset(web_frame); | 2109 source_frame_.Reset(web_frame); |
| 2107 source_node_.Reset(); | 2110 source_node_.Reset(); |
| 2111 CalculateIsModifiable(); |
| 2108 } | 2112 } |
| 2109 | 2113 |
| 2110 void PrintWebViewHelper::PrintPreviewContext::InitWithNode( | 2114 void PrintWebViewHelper::PrintPreviewContext::InitWithNode( |
| 2111 const blink::WebNode& web_node) { | 2115 const blink::WebNode& web_node) { |
| 2112 DCHECK(!web_node.IsNull()); | 2116 DCHECK(!web_node.IsNull()); |
| 2113 DCHECK(web_node.GetDocument().GetFrame()); | 2117 DCHECK(web_node.GetDocument().GetFrame()); |
| 2114 DCHECK(!IsRendering()); | 2118 DCHECK(!IsRendering()); |
| 2115 state_ = INITIALIZED; | 2119 state_ = INITIALIZED; |
| 2116 source_frame_.Reset(web_node.GetDocument().GetFrame()); | 2120 source_frame_.Reset(web_node.GetDocument().GetFrame()); |
| 2117 source_node_ = web_node; | 2121 source_node_ = web_node; |
| 2122 CalculateIsModifiable(); |
| 2118 } | 2123 } |
| 2119 | 2124 |
| 2120 void PrintWebViewHelper::PrintPreviewContext::OnPrintPreview() { | 2125 void PrintWebViewHelper::PrintPreviewContext::OnPrintPreview() { |
| 2121 DCHECK_EQ(INITIALIZED, state_); | 2126 DCHECK_EQ(INITIALIZED, state_); |
| 2122 ClearContext(); | 2127 ClearContext(); |
| 2123 } | 2128 } |
| 2124 | 2129 |
| 2125 bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument( | 2130 bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument( |
| 2126 PrepareFrameAndViewForPrint* prepared_frame, | 2131 PrepareFrameAndViewForPrint* prepared_frame, |
| 2127 const std::vector<int>& pages) { | 2132 const std::vector<int>& pages) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2233 DCHECK_EQ(RENDERING, state_); | 2238 DCHECK_EQ(RENDERING, state_); |
| 2234 if (IsFinalPageRendered()) | 2239 if (IsFinalPageRendered()) |
| 2235 return -1; | 2240 return -1; |
| 2236 return pages_to_render_[current_page_index_++]; | 2241 return pages_to_render_[current_page_index_++]; |
| 2237 } | 2242 } |
| 2238 | 2243 |
| 2239 bool PrintWebViewHelper::PrintPreviewContext::IsRendering() const { | 2244 bool PrintWebViewHelper::PrintPreviewContext::IsRendering() const { |
| 2240 return state_ == RENDERING || state_ == DONE; | 2245 return state_ == RENDERING || state_ == DONE; |
| 2241 } | 2246 } |
| 2242 | 2247 |
| 2243 bool PrintWebViewHelper::PrintPreviewContext::IsModifiable() { | 2248 bool PrintWebViewHelper::PrintPreviewContext::IsModifiable() const { |
| 2244 // The only kind of node we can print right now is a PDF node. | 2249 DCHECK(state_ != UNINITIALIZED); |
| 2245 return !PrintingNodeOrPdfFrame(source_frame(), source_node_); | 2250 return is_modifiable_; |
| 2246 } | 2251 } |
| 2247 | 2252 |
| 2248 bool PrintWebViewHelper::PrintPreviewContext::HasSelection() { | 2253 bool PrintWebViewHelper::PrintPreviewContext::HasSelection() { |
| 2249 return IsModifiable() && source_frame()->HasSelection(); | 2254 return IsModifiable() && source_frame()->HasSelection(); |
| 2250 } | 2255 } |
| 2251 | 2256 |
| 2252 bool PrintWebViewHelper::PrintPreviewContext::IsLastPageOfPrintReadyMetafile() | 2257 bool PrintWebViewHelper::PrintPreviewContext::IsLastPageOfPrintReadyMetafile() |
| 2253 const { | 2258 const { |
| 2254 DCHECK(IsRendering()); | 2259 DCHECK(IsRendering()); |
| 2255 return current_page_index_ == print_ready_metafile_page_count_; | 2260 return current_page_index_ == print_ready_metafile_page_count_; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2312 return error_; | 2317 return error_; |
| 2313 } | 2318 } |
| 2314 | 2319 |
| 2315 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 2320 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 2316 prep_frame_view_.reset(); | 2321 prep_frame_view_.reset(); |
| 2317 metafile_.reset(); | 2322 metafile_.reset(); |
| 2318 pages_to_render_.clear(); | 2323 pages_to_render_.clear(); |
| 2319 error_ = PREVIEW_ERROR_NONE; | 2324 error_ = PREVIEW_ERROR_NONE; |
| 2320 } | 2325 } |
| 2321 | 2326 |
| 2327 void PrintWebViewHelper::PrintPreviewContext::CalculateIsModifiable() { |
| 2328 // The only kind of node we can print right now is a PDF node. |
| 2329 is_modifiable_ = !PrintingNodeOrPdfFrame(source_frame(), source_node_); |
| 2330 } |
| 2331 |
| 2322 void PrintWebViewHelper::SetPrintPagesParams( | 2332 void PrintWebViewHelper::SetPrintPagesParams( |
| 2323 const PrintMsg_PrintPages_Params& settings) { | 2333 const PrintMsg_PrintPages_Params& settings) { |
| 2324 print_pages_params_ = base::MakeUnique<PrintMsg_PrintPages_Params>(settings); | 2334 print_pages_params_ = base::MakeUnique<PrintMsg_PrintPages_Params>(settings); |
| 2325 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), | 2335 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), |
| 2326 settings.params.document_cookie)); | 2336 settings.params.document_cookie)); |
| 2327 } | 2337 } |
| 2328 | 2338 |
| 2329 PrintWebViewHelper::ScriptingThrottler::ScriptingThrottler() : count_(0) { | 2339 PrintWebViewHelper::ScriptingThrottler::ScriptingThrottler() : count_(0) { |
| 2330 } | 2340 } |
| 2331 | 2341 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2366 blink::WebConsoleMessage::kLevelWarning, message)); | 2376 blink::WebConsoleMessage::kLevelWarning, message)); |
| 2367 return false; | 2377 return false; |
| 2368 } | 2378 } |
| 2369 | 2379 |
| 2370 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2380 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2371 // Reset counter on successful print. | 2381 // Reset counter on successful print. |
| 2372 count_ = 0; | 2382 count_ = 0; |
| 2373 } | 2383 } |
| 2374 | 2384 |
| 2375 } // namespace printing | 2385 } // namespace printing |
| OLD | NEW |