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