Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Side by Side Diff: chrome/browser/printing/print_view_manager_common.cc

Issue 2510753002: Revert of Make printing work better with OOPIF. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/browser/printing/print_view_manager_common.h" 5 #include "chrome/browser/printing/print_view_manager_common.h"
6 6
7 #include "content/public/browser/render_frame_host.h"
8 #include "extensions/features/features.h" 7 #include "extensions/features/features.h"
9 #include "printing/features/features.h" 8 #include "printing/features/features.h"
10 9
11 #if BUILDFLAG(ENABLE_EXTENSIONS) 10 #if BUILDFLAG(ENABLE_EXTENSIONS)
12 #include "components/guest_view/browser/guest_view_manager.h" 11 #include "components/guest_view/browser/guest_view_manager.h"
13 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues t.h" 12 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues t.h"
14 #endif // BUILDFLAG(ENABLE_EXTENSIONS) 13 #endif // BUILDFLAG(ENABLE_EXTENSIONS)
15 14
16 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 15 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
17 #include "chrome/browser/printing/print_view_manager.h" 16 #include "chrome/browser/printing/print_view_manager.h"
18 #else 17 #else
19 #include "chrome/browser/printing/print_view_manager_basic.h" 18 #include "chrome/browser/printing/print_view_manager_basic.h"
20 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 19 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
21 20
22 namespace printing { 21 namespace printing {
23
24 namespace { 22 namespace {
25 #if BUILDFLAG(ENABLE_EXTENSIONS) 23 #if BUILDFLAG(ENABLE_EXTENSIONS)
26 // Stores |guest_contents| in |result| and returns true if |guest_contents| is a 24 // Stores |guest_contents| in |result| and returns true if |guest_contents| is a
27 // full page MimeHandlerViewGuest plugin. Otherwise, returns false. 25 // full page MimeHandlerViewGuest plugin. Otherwise, returns false.
28 bool StoreFullPagePlugin(content::WebContents** result, 26 bool StoreFullPagePlugin(content::WebContents** result,
29 content::WebContents* guest_contents) { 27 content::WebContents* guest_contents) {
30 auto* guest_view = 28 auto* guest_view =
31 extensions::MimeHandlerViewGuest::FromWebContents(guest_contents); 29 extensions::MimeHandlerViewGuest::FromWebContents(guest_contents);
32 if (guest_view && guest_view->is_full_page_plugin()) { 30 if (guest_view && guest_view->is_full_page_plugin()) {
33 *result = guest_contents; 31 *result = guest_contents;
(...skipping 12 matching lines...) Expand all
46 contents->GetBrowserContext()); 44 contents->GetBrowserContext());
47 if (guest_view_manager) { 45 if (guest_view_manager) {
48 guest_view_manager->ForEachGuest( 46 guest_view_manager->ForEachGuest(
49 contents, 47 contents,
50 base::Bind(&StoreFullPagePlugin, &contents)); 48 base::Bind(&StoreFullPagePlugin, &contents));
51 } 49 }
52 #endif // BUILDFLAG(ENABLE_EXTENSIONS) 50 #endif // BUILDFLAG(ENABLE_EXTENSIONS)
53 return contents; 51 return contents;
54 } 52 }
55 53
56 // Pick the right RenderFrameHost based on the WebContentses.
57 content::RenderFrameHost* GetRenderFrameHostToUse(
58 content::WebContents* original_contents,
59 content::WebContents* contents_to_use) {
60 if (original_contents != contents_to_use)
61 return contents_to_use->GetMainFrame();
62 return GetFrameToPrint(contents_to_use);
63 }
64
65 } // namespace 54 } // namespace
66 55
67 void StartPrint(content::WebContents* contents, 56 void StartPrint(content::WebContents* contents,
68 bool print_preview_disabled, 57 bool print_preview_disabled,
69 bool has_selection) { 58 bool selection_only) {
70 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 59 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
71 using PrintViewManagerImpl = PrintViewManager; 60 using PrintViewManagerImpl = PrintViewManager;
72 #else 61 #else
73 using PrintViewManagerImpl = PrintViewManagerBasic; 62 using PrintViewManagerImpl = PrintViewManagerBasic;
74 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 63 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
75 64
76 content::WebContents* contents_to_use = GetWebContentsToUse(contents);
77 auto* print_view_manager = 65 auto* print_view_manager =
78 PrintViewManagerImpl::FromWebContents(contents_to_use); 66 PrintViewManagerImpl::FromWebContents(GetWebContentsToUse(contents));
79 if (!print_view_manager) 67 if (!print_view_manager)
80 return; 68 return;
81
82 content::RenderFrameHost* rfh_to_use =
83 GetRenderFrameHostToUse(contents, contents_to_use);
84 if (!rfh_to_use)
85 return;
86
87 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 69 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
88 if (!print_preview_disabled) { 70 if (!print_preview_disabled) {
89 print_view_manager->PrintPreviewNow(rfh_to_use, has_selection); 71 print_view_manager->PrintPreviewNow(selection_only);
90 return; 72 return;
91 } 73 }
92 #endif // ENABLE_PRINT_PREVIEW 74 #endif // ENABLE_PRINT_PREVIEW
93 75
94 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 76 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
95 print_view_manager->PrintNow(rfh_to_use); 77 print_view_manager->PrintNow();
96 #endif // ENABLE_BASIC_PRINTING 78 #endif // ENABLE_BASIC_PRINTING
97 } 79 }
98 80
99 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 81 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
100 void StartBasicPrint(content::WebContents* contents) { 82 void StartBasicPrint(content::WebContents* contents) {
101 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 83 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
102 content::WebContents* contents_to_use = GetWebContentsToUse(contents);
103 PrintViewManager* print_view_manager = 84 PrintViewManager* print_view_manager =
104 PrintViewManager::FromWebContents(contents_to_use); 85 PrintViewManager::FromWebContents(GetWebContentsToUse(contents));
105 if (!print_view_manager) 86 if (!print_view_manager)
106 return; 87 return;
107 88 print_view_manager->BasicPrint();
108 content::RenderFrameHost* rfh_to_use =
109 GetRenderFrameHostToUse(contents, contents_to_use);
110 if (!rfh_to_use)
111 return;
112
113 print_view_manager->BasicPrint(rfh_to_use);
114 #endif // ENABLE_PRINT_PREVIEW 89 #endif // ENABLE_PRINT_PREVIEW
115 } 90 }
116 #endif // ENABLE_BASIC_PRINTING 91 #endif // ENABLE_BASIC_PRINTING
117 92
118 content::RenderFrameHost* GetFrameToPrint(content::WebContents* contents) {
119 auto* focused_frame = contents->GetFocusedFrame();
120 return (focused_frame && focused_frame->HasSelection())
121 ? focused_frame
122 : contents->GetMainFrame();
123 }
124
125 } // namespace printing 93 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_view_manager_common.h ('k') | chrome/browser/printing/printing_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698