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

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

Issue 2508923003: Make printing work better with OOPIF. (try 2) (Closed)
Patch Set: Fix android_webview 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"
7 #include "extensions/features/features.h" 8 #include "extensions/features/features.h"
8 #include "printing/features/features.h" 9 #include "printing/features/features.h"
9 10
10 #if BUILDFLAG(ENABLE_EXTENSIONS) 11 #if BUILDFLAG(ENABLE_EXTENSIONS)
11 #include "components/guest_view/browser/guest_view_manager.h" 12 #include "components/guest_view/browser/guest_view_manager.h"
12 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues t.h" 13 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues t.h"
13 #endif // BUILDFLAG(ENABLE_EXTENSIONS) 14 #endif // BUILDFLAG(ENABLE_EXTENSIONS)
14 15
15 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 16 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
16 #include "chrome/browser/printing/print_view_manager.h" 17 #include "chrome/browser/printing/print_view_manager.h"
17 #else 18 #else
18 #include "chrome/browser/printing/print_view_manager_basic.h" 19 #include "chrome/browser/printing/print_view_manager_basic.h"
19 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 20 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
20 21
21 namespace printing { 22 namespace printing {
23
22 namespace { 24 namespace {
23 #if BUILDFLAG(ENABLE_EXTENSIONS) 25 #if BUILDFLAG(ENABLE_EXTENSIONS)
24 // Stores |guest_contents| in |result| and returns true if |guest_contents| is a 26 // Stores |guest_contents| in |result| and returns true if |guest_contents| is a
25 // full page MimeHandlerViewGuest plugin. Otherwise, returns false. 27 // full page MimeHandlerViewGuest plugin. Otherwise, returns false.
26 bool StoreFullPagePlugin(content::WebContents** result, 28 bool StoreFullPagePlugin(content::WebContents** result,
27 content::WebContents* guest_contents) { 29 content::WebContents* guest_contents) {
28 auto* guest_view = 30 auto* guest_view =
29 extensions::MimeHandlerViewGuest::FromWebContents(guest_contents); 31 extensions::MimeHandlerViewGuest::FromWebContents(guest_contents);
30 if (guest_view && guest_view->is_full_page_plugin()) { 32 if (guest_view && guest_view->is_full_page_plugin()) {
31 *result = guest_contents; 33 *result = guest_contents;
(...skipping 12 matching lines...) Expand all
44 contents->GetBrowserContext()); 46 contents->GetBrowserContext());
45 if (guest_view_manager) { 47 if (guest_view_manager) {
46 guest_view_manager->ForEachGuest( 48 guest_view_manager->ForEachGuest(
47 contents, 49 contents,
48 base::Bind(&StoreFullPagePlugin, &contents)); 50 base::Bind(&StoreFullPagePlugin, &contents));
49 } 51 }
50 #endif // BUILDFLAG(ENABLE_EXTENSIONS) 52 #endif // BUILDFLAG(ENABLE_EXTENSIONS)
51 return contents; 53 return contents;
52 } 54 }
53 55
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
54 } // namespace 65 } // namespace
55 66
56 void StartPrint(content::WebContents* contents, 67 void StartPrint(content::WebContents* contents,
57 bool print_preview_disabled, 68 bool print_preview_disabled,
58 bool selection_only) { 69 bool has_selection) {
59 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 70 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
60 using PrintViewManagerImpl = PrintViewManager; 71 using PrintViewManagerImpl = PrintViewManager;
61 #else 72 #else
62 using PrintViewManagerImpl = PrintViewManagerBasic; 73 using PrintViewManagerImpl = PrintViewManagerBasic;
63 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 74 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
64 75
76 content::WebContents* contents_to_use = GetWebContentsToUse(contents);
65 auto* print_view_manager = 77 auto* print_view_manager =
66 PrintViewManagerImpl::FromWebContents(GetWebContentsToUse(contents)); 78 PrintViewManagerImpl::FromWebContents(contents_to_use);
67 if (!print_view_manager) 79 if (!print_view_manager)
68 return; 80 return;
81
82 content::RenderFrameHost* rfh_to_use =
83 GetRenderFrameHostToUse(contents, contents_to_use);
84 if (!rfh_to_use)
85 return;
86
69 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 87 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
70 if (!print_preview_disabled) { 88 if (!print_preview_disabled) {
71 print_view_manager->PrintPreviewNow(selection_only); 89 print_view_manager->PrintPreviewNow(rfh_to_use, has_selection);
72 return; 90 return;
73 } 91 }
74 #endif // ENABLE_PRINT_PREVIEW 92 #endif // ENABLE_PRINT_PREVIEW
75 93
76 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 94 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
77 print_view_manager->PrintNow(); 95 print_view_manager->PrintNow(rfh_to_use);
78 #endif // ENABLE_BASIC_PRINTING 96 #endif // ENABLE_BASIC_PRINTING
79 } 97 }
80 98
81 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 99 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
82 void StartBasicPrint(content::WebContents* contents) { 100 void StartBasicPrint(content::WebContents* contents) {
83 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 101 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
102 content::WebContents* contents_to_use = GetWebContentsToUse(contents);
84 PrintViewManager* print_view_manager = 103 PrintViewManager* print_view_manager =
85 PrintViewManager::FromWebContents(GetWebContentsToUse(contents)); 104 PrintViewManager::FromWebContents(contents_to_use);
86 if (!print_view_manager) 105 if (!print_view_manager)
87 return; 106 return;
88 print_view_manager->BasicPrint(); 107
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);
89 #endif // ENABLE_PRINT_PREVIEW 114 #endif // ENABLE_PRINT_PREVIEW
90 } 115 }
91 #endif // ENABLE_BASIC_PRINTING 116 #endif // ENABLE_BASIC_PRINTING
92 117
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
93 } // namespace printing 125 } // 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