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/task_manager/printing_information.h"
7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/favicon/favicon_tab_helper.h"
11 #include "chrome/browser/printing/background_printing_manager.h"
12 #include "chrome/browser/printing/print_preview_dialog_controller.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/task_manager/renderer_resource.h"
16 #include "chrome/browser/task_manager/task_manager.h"
17 #include "chrome/browser/task_manager/task_manager_util.h"
18 #include "chrome/grit/generated_resources.h"
19 #include "content/public/browser/render_frame_host.h"
20 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/render_view_host.h"
22 #include "content/public/browser/web_contents.h"
23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/gfx/image/image_skia.h"
26 using content::WebContents
;
28 namespace task_manager
{
30 class PrintingResource
: public RendererResource
{
32 explicit PrintingResource(content::WebContents
* web_contents
);
33 ~PrintingResource() override
;
36 Type
GetType() const override
;
37 base::string16
GetTitle() const override
;
38 gfx::ImageSkia
GetIcon() const override
;
39 content::WebContents
* GetWebContents() const override
;
42 content::WebContents
* web_contents_
;
44 DISALLOW_COPY_AND_ASSIGN(PrintingResource
);
47 PrintingResource::PrintingResource(WebContents
* web_contents
)
48 : RendererResource(web_contents
->GetRenderProcessHost()->GetHandle(),
49 web_contents
->GetRenderViewHost()),
50 web_contents_(web_contents
) {}
52 PrintingResource::~PrintingResource() {}
54 Resource::Type
PrintingResource::GetType() const { return RENDERER
; }
56 base::string16
PrintingResource::GetTitle() const {
57 return l10n_util::GetStringFUTF16(
58 IDS_TASK_MANAGER_PRINT_PREFIX
,
59 util::GetTitleFromWebContents(web_contents_
));
62 gfx::ImageSkia
PrintingResource::GetIcon() const {
63 FaviconTabHelper::CreateForWebContents(web_contents_
);
64 return FaviconTabHelper::FromWebContents(web_contents_
)->
65 GetFavicon().AsImageSkia();
68 WebContents
* PrintingResource::GetWebContents() const { return web_contents_
; }
70 ////////////////////////////////////////////////////////////////////////////////
71 // PrintingInformation class
72 ////////////////////////////////////////////////////////////////////////////////
74 PrintingInformation::PrintingInformation() {}
76 PrintingInformation::~PrintingInformation() {}
78 bool PrintingInformation::CheckOwnership(WebContents
* web_contents
) {
79 printing::BackgroundPrintingManager
* backgrounded_print_jobs
=
80 g_browser_process
->background_printing_manager();
81 // Is it a background print job?
82 if (backgrounded_print_jobs
->HasPrintPreviewDialog(web_contents
)) {
85 // Is it a foreground print preview window?
86 if (printing::PrintPreviewDialogController::IsPrintPreviewDialog(
93 void PrintingInformation::GetAll(const NewWebContentsCallback
& callback
) {
94 // Add all the pages being background printed.
95 printing::BackgroundPrintingManager
* printing_manager
=
96 g_browser_process
->background_printing_manager();
97 std::set
<content::WebContents
*> printing_contents
=
98 printing_manager
->CurrentContentSet();
99 for (std::set
<content::WebContents
*>::iterator i
= printing_contents
.begin();
100 i
!= printing_contents
.end();
104 // Add all the foreground print preview dialogs.
105 printing::PrintPreviewDialogController::GetInstance()->ForEachPreviewDialog(
109 scoped_ptr
<RendererResource
> PrintingInformation::MakeResource(
110 WebContents
* web_contents
) {
111 return scoped_ptr
<RendererResource
>(new PrintingResource(web_contents
));
114 } // namespace task_manager