Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / printing / print_view_manager_common.cc
blob76ac0c1fe38baec42b300dd9c0c9455ac22821e8
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 "extensions/browser/guest_view/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 extensions::GuestViewManager::FromBrowserContext(
40 contents->GetBrowserContext())
41 ->ForEachGuest(contents, base::Bind(&StoreFullPagePlugin, &contents));
42 #endif // defined(ENABLE_EXTENSIONS)
43 return contents;
46 } // namespace
48 void StartPrint(content::WebContents* contents,
49 bool print_preview_disabled,
50 bool selection_only) {
51 #if defined(ENABLE_PRINT_PREVIEW)
52 using PrintViewManagerImpl = PrintViewManager;
53 #else
54 using PrintViewManagerImpl = PrintViewManagerBasic;
55 #endif // defined(ENABLE_PRINT_PREVIEW)
57 auto print_view_manager =
58 PrintViewManagerImpl::FromWebContents(GetWebContentsToUse(contents));
59 if (!print_view_manager)
60 return;
61 #if defined(ENABLE_PRINT_PREVIEW)
62 if (!print_preview_disabled) {
63 print_view_manager->PrintPreviewNow(selection_only);
64 return;
66 #endif // ENABLE_PRINT_PREVIEW
68 #if defined(ENABLE_BASIC_PRINTING)
69 print_view_manager->PrintNow();
70 #endif // ENABLE_BASIC_PRINTING
73 #if defined(ENABLE_BASIC_PRINTING)
74 void StartBasicPrint(content::WebContents* contents) {
75 #if defined(ENABLE_PRINT_PREVIEW)
76 PrintViewManager* print_view_manager =
77 PrintViewManager::FromWebContents(GetWebContentsToUse(contents));
78 if (!print_view_manager)
79 return;
80 print_view_manager->BasicPrint();
81 #endif // ENABLE_PRINT_PREVIEW
83 #endif // ENABLE_BASIC_PRINTING
85 } // namespace printing