| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/renderer/printing/chrome_print_web_view_helper_delegate.h" | 5 #include "chrome/renderer/printing/chrome_print_web_view_helper_delegate.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
| 13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
| 14 #include "chrome/renderer/prerender/prerender_helper.h" | 14 #include "chrome/renderer/prerender/prerender_helper.h" |
| 15 #include "content/public/renderer/render_frame.h" | 15 #include "content/public/renderer/render_frame.h" |
| 16 #include "content/public/renderer/render_view.h" | 16 #include "content/public/renderer/render_view.h" |
| 17 #include "extensions/features/features.h" |
| 17 #include "ipc/ipc_message.h" | 18 #include "ipc/ipc_message.h" |
| 18 #include "third_party/WebKit/public/web/WebDocument.h" | 19 #include "third_party/WebKit/public/web/WebDocument.h" |
| 19 #include "third_party/WebKit/public/web/WebElement.h" | 20 #include "third_party/WebKit/public/web/WebElement.h" |
| 20 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 21 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 21 | 22 |
| 22 #if defined(ENABLE_EXTENSIONS) | 23 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 23 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
| 24 #include "extensions/common/constants.h" | 25 #include "extensions/common/constants.h" |
| 25 #include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_con
tainer.h" | 26 #include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_con
tainer.h" |
| 26 #endif // defined(ENABLE_EXTENSIONS) | 27 #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 27 | 28 |
| 28 ChromePrintWebViewHelperDelegate::~ChromePrintWebViewHelperDelegate(){ | 29 ChromePrintWebViewHelperDelegate::~ChromePrintWebViewHelperDelegate(){ |
| 29 } | 30 } |
| 30 | 31 |
| 31 bool ChromePrintWebViewHelperDelegate::CancelPrerender( | 32 bool ChromePrintWebViewHelperDelegate::CancelPrerender( |
| 32 content::RenderView* render_view, int routing_id) { | 33 content::RenderView* render_view, int routing_id) { |
| 33 if (!render_view || !prerender::PrerenderHelper::IsPrerendering( | 34 if (!render_view || !prerender::PrerenderHelper::IsPrerendering( |
| 34 render_view->GetMainRenderFrame())) | 35 render_view->GetMainRenderFrame())) |
| 35 return false; | 36 return false; |
| 36 | 37 |
| 37 return render_view->Send( | 38 return render_view->Send( |
| 38 new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id)); | 39 new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id)); |
| 39 } | 40 } |
| 40 | 41 |
| 41 // Return the PDF object element if |frame| is the out of process PDF extension. | 42 // Return the PDF object element if |frame| is the out of process PDF extension. |
| 42 blink::WebElement ChromePrintWebViewHelperDelegate::GetPdfElement( | 43 blink::WebElement ChromePrintWebViewHelperDelegate::GetPdfElement( |
| 43 blink::WebLocalFrame* frame) { | 44 blink::WebLocalFrame* frame) { |
| 44 #if defined(ENABLE_EXTENSIONS) | 45 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 45 GURL url = frame->document().url(); | 46 GURL url = frame->document().url(); |
| 46 bool inside_print_preview = url.GetOrigin() == chrome::kChromeUIPrintURL; | 47 bool inside_print_preview = url.GetOrigin() == chrome::kChromeUIPrintURL; |
| 47 bool inside_pdf_extension = url.SchemeIs(extensions::kExtensionScheme) && | 48 bool inside_pdf_extension = url.SchemeIs(extensions::kExtensionScheme) && |
| 48 url.host() == extension_misc::kPdfExtensionId; | 49 url.host() == extension_misc::kPdfExtensionId; |
| 49 if (inside_print_preview || inside_pdf_extension) { | 50 if (inside_print_preview || inside_pdf_extension) { |
| 50 // <object> with id="plugin" is created in | 51 // <object> with id="plugin" is created in |
| 51 // chrome/browser/resources/pdf/pdf.js. | 52 // chrome/browser/resources/pdf/pdf.js. |
| 52 auto plugin_element = frame->document().getElementById("plugin"); | 53 auto plugin_element = frame->document().getElementById("plugin"); |
| 53 if (!plugin_element.isNull()) { | 54 if (!plugin_element.isNull()) { |
| 54 return plugin_element; | 55 return plugin_element; |
| 55 } | 56 } |
| 56 NOTREACHED(); | 57 NOTREACHED(); |
| 57 } | 58 } |
| 58 #endif // defined(ENABLE_EXTENSIONS) | 59 #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 59 return blink::WebElement(); | 60 return blink::WebElement(); |
| 60 } | 61 } |
| 61 | 62 |
| 62 bool ChromePrintWebViewHelperDelegate::IsPrintPreviewEnabled() { | 63 bool ChromePrintWebViewHelperDelegate::IsPrintPreviewEnabled() { |
| 63 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 64 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 64 return !command_line->HasSwitch(switches::kDisablePrintPreview); | 65 return !command_line->HasSwitch(switches::kDisablePrintPreview); |
| 65 } | 66 } |
| 66 | 67 |
| 67 bool ChromePrintWebViewHelperDelegate::OverridePrint( | 68 bool ChromePrintWebViewHelperDelegate::OverridePrint( |
| 68 blink::WebLocalFrame* frame) { | 69 blink::WebLocalFrame* frame) { |
| 69 #if defined(ENABLE_EXTENSIONS) | 70 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 70 if (!frame->document().isPluginDocument()) | 71 if (!frame->document().isPluginDocument()) |
| 71 return false; | 72 return false; |
| 72 | 73 |
| 73 std::vector<extensions::MimeHandlerViewContainer*> mime_handlers = | 74 std::vector<extensions::MimeHandlerViewContainer*> mime_handlers = |
| 74 extensions::MimeHandlerViewContainer::FromRenderFrame( | 75 extensions::MimeHandlerViewContainer::FromRenderFrame( |
| 75 content::RenderFrame::FromWebFrame(frame)); | 76 content::RenderFrame::FromWebFrame(frame)); |
| 76 if (!mime_handlers.empty()) { | 77 if (!mime_handlers.empty()) { |
| 77 // This message is handled in chrome/browser/resources/pdf/pdf.js and | 78 // This message is handled in chrome/browser/resources/pdf/pdf.js and |
| 78 // instructs the PDF plugin to print. This is to make window.print() on a | 79 // instructs the PDF plugin to print. This is to make window.print() on a |
| 79 // PDF plugin document correctly print the PDF. See | 80 // PDF plugin document correctly print the PDF. See |
| 80 // https://crbug.com/448720. | 81 // https://crbug.com/448720. |
| 81 base::DictionaryValue message; | 82 base::DictionaryValue message; |
| 82 message.SetString("type", "print"); | 83 message.SetString("type", "print"); |
| 83 mime_handlers.front()->PostMessageFromValue(message); | 84 mime_handlers.front()->PostMessageFromValue(message); |
| 84 return true; | 85 return true; |
| 85 } | 86 } |
| 86 #endif // defined(ENABLE_EXTENSIONS) | 87 #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 87 return false; | 88 return false; |
| 88 } | 89 } |
| OLD | NEW |