| 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" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 // Written to on the UI thread, read from any thread. | 67 // Written to on the UI thread, read from any thread. |
| 68 base::LazyInstance<PrintPreviewRequestIdMapWithLock> | 68 base::LazyInstance<PrintPreviewRequestIdMapWithLock> |
| 69 g_print_preview_request_id_map = LAZY_INSTANCE_INITIALIZER; | 69 g_print_preview_request_id_map = LAZY_INSTANCE_INITIALIZER; |
| 70 | 70 |
| 71 } // namespace | 71 } // namespace |
| 72 | 72 |
| 73 PrintPreviewUI::PrintPreviewUI(TabContents* contents) | 73 PrintPreviewUI::PrintPreviewUI(TabContents* contents) |
| 74 : ConstrainedHtmlUI(contents), | 74 : ConstrainedHtmlUI(contents), |
| 75 initial_preview_start_time_(base::TimeTicks::Now()), | 75 initial_preview_start_time_(base::TimeTicks::Now()), |
| 76 source_is_modifiable_(true), |
| 76 tab_closed_(false) { | 77 tab_closed_(false) { |
| 77 // WebUI owns |handler_|. | 78 // WebUI owns |handler_|. |
| 78 handler_ = new PrintPreviewHandler(); | 79 handler_ = new PrintPreviewHandler(); |
| 79 AddMessageHandler(handler_->Attach(this)); | 80 AddMessageHandler(handler_->Attach(this)); |
| 80 | 81 |
| 81 // Set up the chrome://print/ data source. | 82 // Set up the chrome://print/ data source. |
| 82 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 83 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
| 83 profile->GetChromeURLDataManager()->AddDataSource( | 84 profile->GetChromeURLDataManager()->AddDataSource( |
| 84 new PrintPreviewDataSource()); | 85 new PrintPreviewDataSource()); |
| 85 | 86 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 114 preview_ui_addr_str_); | 115 preview_ui_addr_str_); |
| 115 } | 116 } |
| 116 | 117 |
| 117 void PrintPreviewUI::SetInitiatorTabURLAndTitle( | 118 void PrintPreviewUI::SetInitiatorTabURLAndTitle( |
| 118 const std::string& initiator_url, | 119 const std::string& initiator_url, |
| 119 const string16& job_title) { | 120 const string16& job_title) { |
| 120 initiator_url_ = initiator_url; | 121 initiator_url_ = initiator_url; |
| 121 initiator_tab_title_ = job_title; | 122 initiator_tab_title_ = job_title; |
| 122 } | 123 } |
| 123 | 124 |
| 124 void PrintPreviewUI::SetSourceIsModifiable(bool source_is_modifiable) { | 125 // static |
| 125 source_is_modifiable_ = source_is_modifiable; | 126 void PrintPreviewUI::SetSourceIsModifiable( |
| 127 TabContentsWrapper* print_preview_tab, |
| 128 bool source_is_modifiable) { |
| 129 if (!print_preview_tab || !print_preview_tab->web_ui()) |
| 130 return; |
| 131 PrintPreviewUI* print_preview_ui = |
| 132 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); |
| 133 print_preview_ui->source_is_modifiable_ = source_is_modifiable; |
| 126 } | 134 } |
| 127 | 135 |
| 128 // static | 136 // static |
| 129 void PrintPreviewUI::GetCurrentPrintPreviewStatus( | 137 void PrintPreviewUI::GetCurrentPrintPreviewStatus( |
| 130 const std::string& preview_ui_addr, | 138 const std::string& preview_ui_addr, |
| 131 int request_id, | 139 int request_id, |
| 132 bool* cancel) { | 140 bool* cancel) { |
| 133 int current_id = -1; | 141 int current_id = -1; |
| 134 if (!g_print_preview_request_id_map.Get().Get(preview_ui_addr, ¤t_id)) { | 142 if (!g_print_preview_request_id_map.Get().Get(preview_ui_addr, ¤t_id)) { |
| 135 *cancel = true; | 143 *cancel = true; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); | 293 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); |
| 286 if (!delegate) | 294 if (!delegate) |
| 287 return; | 295 return; |
| 288 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(""); | 296 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(""); |
| 289 delegate->OnDialogCloseFromWebUI(); | 297 delegate->OnDialogCloseFromWebUI(); |
| 290 } | 298 } |
| 291 | 299 |
| 292 void PrintPreviewUI::OnReloadPrintersList() { | 300 void PrintPreviewUI::OnReloadPrintersList() { |
| 293 CallJavascriptFunction("reloadPrintersList"); | 301 CallJavascriptFunction("reloadPrintersList"); |
| 294 } | 302 } |
| OLD | NEW |