| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/print_preview_ui.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/printing/background_printing_manager.h" | 16 #include "chrome/browser/printing/background_printing_manager.h" |
| 17 #include "chrome/browser/printing/print_preview_data_service.h" | 17 #include "chrome/browser/printing/print_preview_data_service.h" |
| 18 #include "chrome/browser/printing/print_preview_tab_controller.h" | 18 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 21 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 21 #include "chrome/browser/ui/webui/web_dialog_ui.h" |
| 22 #include "chrome/browser/ui/webui/print_preview/print_preview_data_source.h" | 22 #include "chrome/browser/ui/webui/print_preview/print_preview_data_source.h" |
| 23 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" | 23 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" |
| 24 #include "chrome/common/print_messages.h" | 24 #include "chrome/common/print_messages.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "printing/page_size_margins.h" | 26 #include "printing/page_size_margins.h" |
| 27 #include "printing/print_job_constants.h" | 27 #include "printing/print_job_constants.h" |
| 28 #include "ui/gfx/rect.h" | 28 #include "ui/gfx/rect.h" |
| 29 | 29 |
| 30 using content::WebContents; | 30 using content::WebContents; |
| 31 using printing::PageSizeMargins; | 31 using printing::PageSizeMargins; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 base::Lock lock_; | 68 base::Lock lock_; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 // Written to on the UI thread, read from any thread. | 71 // Written to on the UI thread, read from any thread. |
| 72 base::LazyInstance<PrintPreviewRequestIdMapWithLock> | 72 base::LazyInstance<PrintPreviewRequestIdMapWithLock> |
| 73 g_print_preview_request_id_map = LAZY_INSTANCE_INITIALIZER; | 73 g_print_preview_request_id_map = LAZY_INSTANCE_INITIALIZER; |
| 74 | 74 |
| 75 } // namespace | 75 } // namespace |
| 76 | 76 |
| 77 PrintPreviewUI::PrintPreviewUI(content::WebUI* web_ui) | 77 PrintPreviewUI::PrintPreviewUI(content::WebUI* web_ui) |
| 78 : ConstrainedHtmlUI(web_ui), | 78 : ConstrainedWebDialogUI(web_ui), |
| 79 initial_preview_start_time_(base::TimeTicks::Now()), | 79 initial_preview_start_time_(base::TimeTicks::Now()), |
| 80 handler_(NULL), | 80 handler_(NULL), |
| 81 source_is_modifiable_(true), | 81 source_is_modifiable_(true), |
| 82 tab_closed_(false) { | 82 tab_closed_(false) { |
| 83 printing::PrintPreviewTabController* controller = | 83 printing::PrintPreviewTabController* controller = |
| 84 printing::PrintPreviewTabController::GetInstance(); | 84 printing::PrintPreviewTabController::GetInstance(); |
| 85 is_dummy_ = (!controller || !controller->is_creating_print_preview_tab()); | 85 is_dummy_ = (!controller || !controller->is_creating_print_preview_tab()); |
| 86 | 86 |
| 87 // Set up the chrome://print/ data source. | 87 // Set up the chrome://print/ data source. |
| 88 Profile* profile = Profile::FromWebUI(web_ui); | 88 Profile* profile = Profile::FromWebUI(web_ui); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 300 |
| 301 void PrintPreviewUI::OnHidePreviewTab() { | 301 void PrintPreviewUI::OnHidePreviewTab() { |
| 302 TabContentsWrapper* preview_tab = | 302 TabContentsWrapper* preview_tab = |
| 303 TabContentsWrapper::GetCurrentWrapperForContents( | 303 TabContentsWrapper::GetCurrentWrapperForContents( |
| 304 web_ui()->GetWebContents()); | 304 web_ui()->GetWebContents()); |
| 305 printing::BackgroundPrintingManager* background_printing_manager = | 305 printing::BackgroundPrintingManager* background_printing_manager = |
| 306 g_browser_process->background_printing_manager(); | 306 g_browser_process->background_printing_manager(); |
| 307 if (background_printing_manager->HasPrintPreviewTab(preview_tab)) | 307 if (background_printing_manager->HasPrintPreviewTab(preview_tab)) |
| 308 return; | 308 return; |
| 309 | 309 |
| 310 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); | 310 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate(); |
| 311 if (!delegate) | 311 if (!delegate) |
| 312 return; | 312 return; |
| 313 delegate->ReleaseTabContentsOnDialogClose(); | 313 delegate->ReleaseTabContentsOnDialogClose(); |
| 314 background_printing_manager->OwnPrintPreviewTab(preview_tab); | 314 background_printing_manager->OwnPrintPreviewTab(preview_tab); |
| 315 OnClosePrintPreviewTab(); | 315 OnClosePrintPreviewTab(); |
| 316 } | 316 } |
| 317 | 317 |
| 318 void PrintPreviewUI::OnClosePrintPreviewTab() { | 318 void PrintPreviewUI::OnClosePrintPreviewTab() { |
| 319 if (tab_closed_) | 319 if (tab_closed_) |
| 320 return; | 320 return; |
| 321 tab_closed_ = true; | 321 tab_closed_ = true; |
| 322 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); | 322 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate(); |
| 323 if (!delegate) | 323 if (!delegate) |
| 324 return; | 324 return; |
| 325 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(""); | 325 delegate->GetWebDialogDelegate()->OnDialogClosed(""); |
| 326 delegate->OnDialogCloseFromWebUI(); | 326 delegate->OnDialogCloseFromWebUI(); |
| 327 } | 327 } |
| 328 | 328 |
| 329 void PrintPreviewUI::OnReloadPrintersList() { | 329 void PrintPreviewUI::OnReloadPrintersList() { |
| 330 web_ui()->CallJavascriptFunction("reloadPrintersList"); | 330 web_ui()->CallJavascriptFunction("reloadPrintersList"); |
| 331 } | 331 } |
| OLD | NEW |