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