| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/webui/print_preview_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/platform_util.h" | 12 #include "chrome/browser/platform_util.h" |
| 13 #include "chrome/browser/printing/print_preview_tab_controller.h" | 13 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 14 #include "chrome/browser/ui/webui/print_preview_ui_html_source.h" | 14 #include "chrome/browser/ui/webui/print_preview_ui_html_source.h" |
| 15 #include "chrome/browser/ui/webui/print_preview_ui.h" | 15 #include "chrome/browser/ui/webui/print_preview_ui.h" |
| 16 #include "chrome/common/print_messages.h" | 16 #include "chrome/common/print_messages.h" |
| 17 #include "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
| 18 #include "content/browser/renderer_host/render_view_host.h" | 18 #include "content/browser/renderer_host/render_view_host.h" |
| 19 #include "content/browser/tab_contents/tab_contents.h" | 19 #include "content/browser/tab_contents/tab_contents.h" |
| 20 #include "printing/backend/print_backend.h" | 20 #include "printing/backend/print_backend.h" |
| 21 #include "printing/native_metafile_factory.h" | 21 #include "printing/metafile.h" |
| 22 #include "printing/native_metafile.h" | 22 #include "printing/metafile_impl.h" |
| 23 #include "printing/print_job_constants.h" | 23 #include "printing/print_job_constants.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const bool kColorDefaultValue = false; | 27 const bool kColorDefaultValue = false; |
| 28 const bool kLandscapeDefaultValue = false; | 28 const bool kLandscapeDefaultValue = false; |
| 29 | 29 |
| 30 TabContents* GetInitiatorTab(TabContents* preview_tab) { | 30 TabContents* GetInitiatorTab(TabContents* preview_tab) { |
| 31 printing::PrintPreviewTabController* tab_controller = | 31 printing::PrintPreviewTabController* tab_controller = |
| 32 printing::PrintPreviewTabController::GetInstance(); | 32 printing::PrintPreviewTabController::GetInstance(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 scoped_refptr<printing::PrintBackend> print_backend_; | 115 scoped_refptr<printing::PrintBackend> print_backend_; |
| 116 | 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(EnumeratePrintersTaskProxy); | 117 DISALLOW_COPY_AND_ASSIGN(EnumeratePrintersTaskProxy); |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 // A Task implementation that stores a PDF file on disk. | 120 // A Task implementation that stores a PDF file on disk. |
| 121 class PrintToPdfTask : public Task { | 121 class PrintToPdfTask : public Task { |
| 122 public: | 122 public: |
| 123 // Takes ownership of |metafile|. | 123 // Takes ownership of |metafile|. |
| 124 PrintToPdfTask(printing::NativeMetafile* metafile, const FilePath& path) | 124 PrintToPdfTask(printing::Metafile* metafile, const FilePath& path) |
| 125 : metafile_(metafile), path_(path) { | 125 : metafile_(metafile), path_(path) { |
| 126 } | 126 } |
| 127 | 127 |
| 128 ~PrintToPdfTask() {} | 128 ~PrintToPdfTask() {} |
| 129 | 129 |
| 130 // Task implementation | 130 // Task implementation |
| 131 virtual void Run() { | 131 virtual void Run() { |
| 132 metafile_->SaveTo(path_); | 132 metafile_->SaveTo(path_); |
| 133 } | 133 } |
| 134 | 134 |
| 135 private: | 135 private: |
| 136 // The metafile holding the PDF data. | 136 // The metafile holding the PDF data. |
| 137 scoped_ptr<printing::NativeMetafile> metafile_; | 137 scoped_ptr<printing::Metafile> metafile_; |
| 138 | 138 |
| 139 // The absolute path where the file will be saved. | 139 // The absolute path where the file will be saved. |
| 140 FilePath path_; | 140 FilePath path_; |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 PrintPreviewHandler::PrintPreviewHandler() | 143 PrintPreviewHandler::PrintPreviewHandler() |
| 144 : print_backend_(printing::PrintBackend::CreateInstance(NULL)), | 144 : print_backend_(printing::PrintBackend::CreateInstance(NULL)), |
| 145 need_to_generate_preview_(true), | 145 need_to_generate_preview_(true), |
| 146 color_(kColorDefaultValue), | 146 color_(kColorDefaultValue), |
| 147 landscape_(kLandscapeDefaultValue) { | 147 landscape_(kLandscapeDefaultValue) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 &file_type_info, | 255 &file_type_info, |
| 256 0, | 256 0, |
| 257 FILE_PATH_LITERAL(""), | 257 FILE_PATH_LITERAL(""), |
| 258 platform_util::GetTopLevel( | 258 platform_util::GetTopLevel( |
| 259 web_ui_->tab_contents()->GetNativeView()), | 259 web_ui_->tab_contents()->GetNativeView()), |
| 260 NULL); | 260 NULL); |
| 261 } | 261 } |
| 262 | 262 |
| 263 void PrintPreviewHandler::FileSelected(const FilePath& path, | 263 void PrintPreviewHandler::FileSelected(const FilePath& path, |
| 264 int index, void* params) { | 264 int index, void* params) { |
| 265 #if defined(OS_POSIX) | |
| 266 PrintPreviewUIHTMLSource::PrintPreviewData data; | 265 PrintPreviewUIHTMLSource::PrintPreviewData data; |
| 267 PrintPreviewUI* pp_ui = reinterpret_cast<PrintPreviewUI*>(web_ui_); | 266 PrintPreviewUI* pp_ui = reinterpret_cast<PrintPreviewUI*>(web_ui_); |
| 268 pp_ui->html_source()->GetPrintPreviewData(&data); | 267 pp_ui->html_source()->GetPrintPreviewData(&data); |
| 269 DCHECK(data.first != NULL); | 268 DCHECK(data.first != NULL); |
| 270 DCHECK(data.second > 0); | 269 DCHECK(data.second > 0); |
| 271 | 270 |
| 272 printing::NativeMetafile* metafile = | 271 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; |
| 273 printing::NativeMetafileFactory::CreateFromData(data.first->memory(), | 272 metafile->InitFromData(data.first->memory(), data.second); |
| 274 data.second); | |
| 275 metafile->FinishDocument(); | |
| 276 | 273 |
| 277 PrintToPdfTask* task = new PrintToPdfTask(metafile, path); | 274 PrintToPdfTask* task = new PrintToPdfTask(metafile, path); |
| 278 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); | 275 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task); |
| 279 #else | |
| 280 NOTIMPLEMENTED(); | |
| 281 #endif | |
| 282 } | 276 } |
| OLD | NEW |