Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / task_manager / printing_information.cc
blobac0d904ff2f7c323ab510d14395f1d8b80c26255
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_utils.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 "components/favicon/content/content_favicon_driver.h"
20 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/render_view_host.h"
23 #include "content/public/browser/web_contents.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/gfx/image/image_skia.h"
27 using content::WebContents;
29 namespace task_manager {
31 class PrintingResource : public RendererResource {
32 public:
33 explicit PrintingResource(content::WebContents* web_contents);
34 ~PrintingResource() override;
36 // Resource methods:
37 Type GetType() const override;
38 base::string16 GetTitle() const override;
39 gfx::ImageSkia GetIcon() const override;
40 content::WebContents* GetWebContents() const override;
42 private:
43 content::WebContents* web_contents_;
45 DISALLOW_COPY_AND_ASSIGN(PrintingResource);
48 PrintingResource::PrintingResource(WebContents* web_contents)
49 : RendererResource(web_contents->GetRenderProcessHost()->GetHandle(),
50 web_contents->GetRenderViewHost()),
51 web_contents_(web_contents) {}
53 PrintingResource::~PrintingResource() {}
55 Resource::Type PrintingResource::GetType() const { return RENDERER; }
57 base::string16 PrintingResource::GetTitle() const {
58 return l10n_util::GetStringFUTF16(
59 IDS_TASK_MANAGER_PRINT_PREFIX,
60 util::GetTitleFromWebContents(web_contents_));
63 gfx::ImageSkia PrintingResource::GetIcon() const {
64 favicon::CreateContentFaviconDriverForWebContents(web_contents_);
65 return favicon::ContentFaviconDriver::FromWebContents(web_contents_)
66 ->GetFavicon()
67 .AsImageSkia();
70 WebContents* PrintingResource::GetWebContents() const { return web_contents_; }
72 ////////////////////////////////////////////////////////////////////////////////
73 // PrintingInformation class
74 ////////////////////////////////////////////////////////////////////////////////
76 PrintingInformation::PrintingInformation() {}
78 PrintingInformation::~PrintingInformation() {}
80 bool PrintingInformation::CheckOwnership(WebContents* web_contents) {
81 printing::BackgroundPrintingManager* backgrounded_print_jobs =
82 g_browser_process->background_printing_manager();
83 // Is it a background print job?
84 if (backgrounded_print_jobs->HasPrintPreviewDialog(web_contents)) {
85 return true;
87 // Is it a foreground print preview window?
88 if (printing::PrintPreviewDialogController::IsPrintPreviewDialog(
89 web_contents)) {
90 return true;
92 return false;
95 void PrintingInformation::GetAll(const NewWebContentsCallback& callback) {
96 // Add all the pages being background printed.
97 printing::BackgroundPrintingManager* printing_manager =
98 g_browser_process->background_printing_manager();
99 std::set<content::WebContents*> printing_contents =
100 printing_manager->CurrentContentSet();
101 for (std::set<content::WebContents*>::iterator i = printing_contents.begin();
102 i != printing_contents.end();
103 ++i) {
104 callback.Run(*i);
106 // Add all the foreground print preview dialogs.
107 printing::PrintPreviewDialogController::GetInstance()->ForEachPreviewDialog(
108 callback);
111 scoped_ptr<RendererResource> PrintingInformation::MakeResource(
112 WebContents* web_contents) {
113 return scoped_ptr<RendererResource>(new PrintingResource(web_contents));
116 } // namespace task_manager