Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / printing / print_view_manager_common.cc
blob1d1a2c36cfc359e89943348c27b73e13688f8185
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/printing/print_view_manager_common.h"
7 #if defined(ENABLE_EXTENSIONS)
8 #include "components/guest_view/browser/guest_view_manager.h"
9 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
10 #endif // defined(ENABLE_EXTENSIONS)
12 #if defined(ENABLE_PRINT_PREVIEW)
13 #include "chrome/browser/printing/print_view_manager.h"
14 #else
15 #include "chrome/browser/printing/print_view_manager_basic.h"
16 #endif // defined(ENABLE_PRINT_PREVIEW)
18 namespace printing {
19 namespace {
20 #if defined(ENABLE_EXTENSIONS)
21 // Stores |guest_contents| in |result| and returns true if |guest_contents| is a
22 // full page MimeHandlerViewGuest plugin. Otherwise, returns false.
23 bool StoreFullPagePlugin(content::WebContents** result,
24 content::WebContents* guest_contents) {
25 auto guest_view =
26 extensions::MimeHandlerViewGuest::FromWebContents(guest_contents);
27 if (guest_view && guest_view->is_full_page_plugin()) {
28 *result = guest_contents;
29 return true;
31 return false;
33 #endif // defined(ENABLE_EXTENSIONS)
35 // If we have a single full-page embedded mime handler view guest, print the
36 // guest's WebContents instead.
37 content::WebContents* GetWebContentsToUse(content::WebContents* contents) {
38 #if defined(ENABLE_EXTENSIONS)
39 guest_view::GuestViewManager* guest_view_manager =
40 guest_view::GuestViewManager::FromBrowserContext(
41 contents->GetBrowserContext());
42 if (guest_view_manager) {
43 guest_view_manager->ForEachGuest(
44 contents,
45 base::Bind(&StoreFullPagePlugin, &contents));
47 #endif // defined(ENABLE_EXTENSIONS)
48 return contents;
51 } // namespace
53 void StartPrint(content::WebContents* contents,
54 bool print_preview_disabled,
55 bool selection_only) {
56 #if defined(ENABLE_PRINT_PREVIEW)
57 using PrintViewManagerImpl = PrintViewManager;
58 #else
59 using PrintViewManagerImpl = PrintViewManagerBasic;
60 #endif // defined(ENABLE_PRINT_PREVIEW)
62 auto print_view_manager =
63 PrintViewManagerImpl::FromWebContents(GetWebContentsToUse(contents));
64 if (!print_view_manager)
65 return;
66 #if defined(ENABLE_PRINT_PREVIEW)
67 if (!print_preview_disabled) {
68 print_view_manager->PrintPreviewNow(selection_only);
69 return;
71 #endif // ENABLE_PRINT_PREVIEW
73 #if defined(ENABLE_BASIC_PRINTING)
74 print_view_manager->PrintNow();
75 #endif // ENABLE_BASIC_PRINTING
78 #if defined(ENABLE_BASIC_PRINTING)
79 void StartBasicPrint(content::WebContents* contents) {
80 #if defined(ENABLE_PRINT_PREVIEW)
81 PrintViewManager* print_view_manager =
82 PrintViewManager::FromWebContents(GetWebContentsToUse(contents));
83 if (!print_view_manager)
84 return;
85 print_view_manager->BasicPrint();
86 #endif // ENABLE_PRINT_PREVIEW
88 #endif // ENABLE_BASIC_PRINTING
90 } // namespace printing