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_ui.h" | 5 #include "chrome/browser/ui/webui/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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/printing/background_printing_manager.h" | 15 #include "chrome/browser/printing/background_printing_manager.h" |
16 #include "chrome/browser/printing/print_preview_data_service.h" | 16 #include "chrome/browser/printing/print_preview_data_service.h" |
17 #include "chrome/browser/printing/print_preview_tab_controller.h" | |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
19 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 20 #include "chrome/browser/ui/webui/html_dialog_ui.h" |
20 #include "chrome/browser/ui/webui/print_preview_data_source.h" | 21 #include "chrome/browser/ui/webui/print_preview_data_source.h" |
21 #include "chrome/browser/ui/webui/print_preview_handler.h" | 22 #include "chrome/browser/ui/webui/print_preview_handler.h" |
22 #include "chrome/common/print_messages.h" | 23 #include "chrome/common/print_messages.h" |
23 #include "content/browser/tab_contents/tab_contents.h" | 24 #include "content/browser/tab_contents/tab_contents.h" |
24 #include "printing/page_size_margins.h" | 25 #include "printing/page_size_margins.h" |
25 #include "printing/print_job_constants.h" | 26 #include "printing/print_job_constants.h" |
26 | 27 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 | 67 |
67 // Written to on the UI thread, read from any thread. | 68 // Written to on the UI thread, read from any thread. |
68 base::LazyInstance<PrintPreviewRequestIdMapWithLock> | 69 base::LazyInstance<PrintPreviewRequestIdMapWithLock> |
69 g_print_preview_request_id_map = LAZY_INSTANCE_INITIALIZER; | 70 g_print_preview_request_id_map = LAZY_INSTANCE_INITIALIZER; |
70 | 71 |
71 } // namespace | 72 } // namespace |
72 | 73 |
73 PrintPreviewUI::PrintPreviewUI(TabContents* contents) | 74 PrintPreviewUI::PrintPreviewUI(TabContents* contents) |
74 : ConstrainedHtmlUI(contents), | 75 : ConstrainedHtmlUI(contents), |
75 initial_preview_start_time_(base::TimeTicks::Now()), | 76 initial_preview_start_time_(base::TimeTicks::Now()), |
77 handler_(NULL), | |
76 source_is_modifiable_(true), | 78 source_is_modifiable_(true), |
77 tab_closed_(false) { | 79 tab_closed_(false), |
80 is_dummy_(false) { | |
81 printing::PrintPreviewTabController* controller = | |
82 printing::PrintPreviewTabController::GetInstance(); | |
83 if (!controller || !controller->is_creating_print_preview_tab()) | |
84 is_dummy_ = true; | |
dpapad
2011/12/13 17:00:43
Nit (optional):
is_dummy_ = (!controller || !contr
Lei Zhang
2011/12/13 20:34:30
Done.
| |
85 | |
86 // Set up the chrome://print/ data source. | |
87 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | |
88 profile->GetChromeURLDataManager()->AddDataSource( | |
89 new PrintPreviewDataSource(is_dummy_)); | |
90 if (is_dummy_) | |
91 return; | |
92 | |
78 // WebUI owns |handler_|. | 93 // WebUI owns |handler_|. |
79 handler_ = new PrintPreviewHandler(); | 94 handler_ = new PrintPreviewHandler(); |
80 AddMessageHandler(handler_->Attach(this)); | 95 AddMessageHandler(handler_->Attach(this)); |
81 | 96 |
82 // Set up the chrome://print/ data source. | |
83 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | |
84 profile->GetChromeURLDataManager()->AddDataSource( | |
85 new PrintPreviewDataSource()); | |
86 | |
87 preview_ui_addr_str_ = GetPrintPreviewUIAddress(); | 97 preview_ui_addr_str_ = GetPrintPreviewUIAddress(); |
88 | |
89 g_print_preview_request_id_map.Get().Set(preview_ui_addr_str_, -1); | 98 g_print_preview_request_id_map.Get().Set(preview_ui_addr_str_, -1); |
90 } | 99 } |
91 | 100 |
92 PrintPreviewUI::~PrintPreviewUI() { | 101 PrintPreviewUI::~PrintPreviewUI() { |
102 if (is_dummy_) | |
103 return; | |
104 | |
93 print_preview_data_service()->RemoveEntry(preview_ui_addr_str_); | 105 print_preview_data_service()->RemoveEntry(preview_ui_addr_str_); |
94 | |
95 g_print_preview_request_id_map.Get().Erase(preview_ui_addr_str_); | 106 g_print_preview_request_id_map.Get().Erase(preview_ui_addr_str_); |
96 } | 107 } |
97 | 108 |
98 void PrintPreviewUI::GetPrintPreviewDataForIndex( | 109 void PrintPreviewUI::GetPrintPreviewDataForIndex( |
99 int index, | 110 int index, |
100 scoped_refptr<RefCountedBytes>* data) { | 111 scoped_refptr<RefCountedBytes>* data) { |
101 print_preview_data_service()->GetDataEntry(preview_ui_addr_str_, index, data); | 112 print_preview_data_service()->GetDataEntry(preview_ui_addr_str_, index, data); |
102 } | 113 } |
103 | 114 |
104 void PrintPreviewUI::SetPrintPreviewDataForIndex(int index, | 115 void PrintPreviewUI::SetPrintPreviewDataForIndex(int index, |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); | 304 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); |
294 if (!delegate) | 305 if (!delegate) |
295 return; | 306 return; |
296 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(""); | 307 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(""); |
297 delegate->OnDialogCloseFromWebUI(); | 308 delegate->OnDialogCloseFromWebUI(); |
298 } | 309 } |
299 | 310 |
300 void PrintPreviewUI::OnReloadPrintersList() { | 311 void PrintPreviewUI::OnReloadPrintersList() { |
301 CallJavascriptFunction("reloadPrintersList"); | 312 CallJavascriptFunction("reloadPrintersList"); |
302 } | 313 } |
OLD | NEW |