| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/task_manager/printing_information.h" | |
| 6 | |
| 7 #include "base/macros.h" | |
| 8 #include "base/strings/string16.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 10 #include "chrome/browser/browser_process.h" | |
| 11 #include "chrome/browser/favicon/favicon_utils.h" | |
| 12 #include "chrome/browser/printing/background_printing_manager.h" | |
| 13 #include "chrome/browser/printing/print_preview_dialog_controller.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | |
| 15 #include "chrome/browser/profiles/profile_manager.h" | |
| 16 #include "chrome/browser/task_manager/renderer_resource.h" | |
| 17 #include "chrome/browser/task_manager/task_manager.h" | |
| 18 #include "chrome/browser/task_manager/task_manager_util.h" | |
| 19 #include "chrome/grit/generated_resources.h" | |
| 20 #include "components/favicon/content/content_favicon_driver.h" | |
| 21 #include "content/public/browser/render_frame_host.h" | |
| 22 #include "content/public/browser/render_process_host.h" | |
| 23 #include "content/public/browser/render_view_host.h" | |
| 24 #include "content/public/browser/web_contents.h" | |
| 25 #include "ui/base/l10n/l10n_util.h" | |
| 26 #include "ui/gfx/image/image_skia.h" | |
| 27 | |
| 28 using content::WebContents; | |
| 29 | |
| 30 namespace task_manager { | |
| 31 | |
| 32 class PrintingResource : public RendererResource { | |
| 33 public: | |
| 34 explicit PrintingResource(content::WebContents* web_contents); | |
| 35 ~PrintingResource() override; | |
| 36 | |
| 37 // Resource methods: | |
| 38 Type GetType() const override; | |
| 39 base::string16 GetTitle() const override; | |
| 40 gfx::ImageSkia GetIcon() const override; | |
| 41 content::WebContents* GetWebContents() const override; | |
| 42 | |
| 43 private: | |
| 44 content::WebContents* web_contents_; | |
| 45 | |
| 46 DISALLOW_COPY_AND_ASSIGN(PrintingResource); | |
| 47 }; | |
| 48 | |
| 49 PrintingResource::PrintingResource(WebContents* web_contents) | |
| 50 : RendererResource(web_contents->GetRenderProcessHost()->GetHandle(), | |
| 51 web_contents->GetRenderViewHost()), | |
| 52 web_contents_(web_contents) {} | |
| 53 | |
| 54 PrintingResource::~PrintingResource() {} | |
| 55 | |
| 56 Resource::Type PrintingResource::GetType() const { return RENDERER; } | |
| 57 | |
| 58 base::string16 PrintingResource::GetTitle() const { | |
| 59 return l10n_util::GetStringFUTF16( | |
| 60 IDS_TASK_MANAGER_PRINT_PREFIX, | |
| 61 util::GetTitleFromWebContents(web_contents_)); | |
| 62 } | |
| 63 | |
| 64 gfx::ImageSkia PrintingResource::GetIcon() const { | |
| 65 favicon::CreateContentFaviconDriverForWebContents(web_contents_); | |
| 66 return favicon::ContentFaviconDriver::FromWebContents(web_contents_) | |
| 67 ->GetFavicon() | |
| 68 .AsImageSkia(); | |
| 69 } | |
| 70 | |
| 71 WebContents* PrintingResource::GetWebContents() const { return web_contents_; } | |
| 72 | |
| 73 //////////////////////////////////////////////////////////////////////////////// | |
| 74 // PrintingInformation class | |
| 75 //////////////////////////////////////////////////////////////////////////////// | |
| 76 | |
| 77 PrintingInformation::PrintingInformation() {} | |
| 78 | |
| 79 PrintingInformation::~PrintingInformation() {} | |
| 80 | |
| 81 bool PrintingInformation::CheckOwnership(WebContents* web_contents) { | |
| 82 printing::BackgroundPrintingManager* backgrounded_print_jobs = | |
| 83 g_browser_process->background_printing_manager(); | |
| 84 // Is it a background print job? | |
| 85 if (backgrounded_print_jobs->HasPrintPreviewDialog(web_contents)) { | |
| 86 return true; | |
| 87 } | |
| 88 // Is it a foreground print preview window? | |
| 89 if (printing::PrintPreviewDialogController::IsPrintPreviewDialog( | |
| 90 web_contents)) { | |
| 91 return true; | |
| 92 } | |
| 93 return false; | |
| 94 } | |
| 95 | |
| 96 void PrintingInformation::GetAll(const NewWebContentsCallback& callback) { | |
| 97 // Add all the pages being background printed. | |
| 98 printing::BackgroundPrintingManager* printing_manager = | |
| 99 g_browser_process->background_printing_manager(); | |
| 100 std::set<content::WebContents*> printing_contents = | |
| 101 printing_manager->CurrentContentSet(); | |
| 102 for (std::set<content::WebContents*>::iterator i = printing_contents.begin(); | |
| 103 i != printing_contents.end(); | |
| 104 ++i) { | |
| 105 callback.Run(*i); | |
| 106 } | |
| 107 // Add all the foreground print preview dialogs. | |
| 108 printing::PrintPreviewDialogController::GetInstance()->ForEachPreviewDialog( | |
| 109 callback); | |
| 110 } | |
| 111 | |
| 112 std::unique_ptr<RendererResource> PrintingInformation::MakeResource( | |
| 113 WebContents* web_contents) { | |
| 114 return std::unique_ptr<RendererResource>(new PrintingResource(web_contents)); | |
| 115 } | |
| 116 | |
| 117 } // namespace task_manager | |
| OLD | NEW |