| 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" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 std::string PrintPreviewUI::GetPrintPreviewUIAddress() const { | 155 std::string PrintPreviewUI::GetPrintPreviewUIAddress() const { |
| 156 // Store the PrintPreviewUIAddress as a string. | 156 // Store the PrintPreviewUIAddress as a string. |
| 157 // "0x" + deadc0de + '\0' = 2 + 2 * sizeof(this) + 1; | 157 // "0x" + deadc0de + '\0' = 2 + 2 * sizeof(this) + 1; |
| 158 char preview_ui_addr[2 + (2 * sizeof(this)) + 1]; | 158 char preview_ui_addr[2 + (2 * sizeof(this)) + 1]; |
| 159 base::snprintf(preview_ui_addr, sizeof(preview_ui_addr), "%p", this); | 159 base::snprintf(preview_ui_addr, sizeof(preview_ui_addr), "%p", this); |
| 160 return preview_ui_addr; | 160 return preview_ui_addr; |
| 161 } | 161 } |
| 162 | 162 |
| 163 void PrintPreviewUI::OnPrintPreviewTabClosed() { | 163 void PrintPreviewUI::OnPrintPreviewTabClosed() { |
| 164 TabContents* preview_tab = | 164 TabContents* preview_tab = |
| 165 TabContents::GetCurrentWrapperForContents(web_ui()->GetWebContents()); | 165 TabContents::FromWebContents(web_ui()->GetWebContents()); |
| 166 printing::BackgroundPrintingManager* background_printing_manager = | 166 printing::BackgroundPrintingManager* background_printing_manager = |
| 167 g_browser_process->background_printing_manager(); | 167 g_browser_process->background_printing_manager(); |
| 168 if (background_printing_manager->HasPrintPreviewTab(preview_tab)) | 168 if (background_printing_manager->HasPrintPreviewTab(preview_tab)) |
| 169 return; | 169 return; |
| 170 OnClosePrintPreviewTab(); | 170 OnClosePrintPreviewTab(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void PrintPreviewUI::OnInitiatorTabClosed() { | 173 void PrintPreviewUI::OnInitiatorTabClosed() { |
| 174 TabContents* preview_tab = | 174 TabContents* preview_tab = |
| 175 TabContents::GetCurrentWrapperForContents(web_ui()->GetWebContents()); | 175 TabContents::FromWebContents(web_ui()->GetWebContents()); |
| 176 printing::BackgroundPrintingManager* background_printing_manager = | 176 printing::BackgroundPrintingManager* background_printing_manager = |
| 177 g_browser_process->background_printing_manager(); | 177 g_browser_process->background_printing_manager(); |
| 178 if (background_printing_manager->HasPrintPreviewTab(preview_tab)) | 178 if (background_printing_manager->HasPrintPreviewTab(preview_tab)) |
| 179 web_ui()->CallJavascriptFunction("cancelPendingPrintRequest"); | 179 web_ui()->CallJavascriptFunction("cancelPendingPrintRequest"); |
| 180 else | 180 else |
| 181 OnClosePrintPreviewTab(); | 181 OnClosePrintPreviewTab(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void PrintPreviewUI::OnPrintPreviewRequest(int request_id) { | 184 void PrintPreviewUI::OnPrintPreviewRequest(int request_id) { |
| 185 g_print_preview_request_id_map.Get().Set(preview_ui_addr_str_, request_id); | 185 g_print_preview_request_id_map.Get().Set(preview_ui_addr_str_, request_id); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 void PrintPreviewUI::OnInvalidPrinterSettings() { | 284 void PrintPreviewUI::OnInvalidPrinterSettings() { |
| 285 web_ui()->CallJavascriptFunction("invalidPrinterSettings"); | 285 web_ui()->CallJavascriptFunction("invalidPrinterSettings"); |
| 286 } | 286 } |
| 287 | 287 |
| 288 PrintPreviewDataService* PrintPreviewUI::print_preview_data_service() { | 288 PrintPreviewDataService* PrintPreviewUI::print_preview_data_service() { |
| 289 return PrintPreviewDataService::GetInstance(); | 289 return PrintPreviewDataService::GetInstance(); |
| 290 } | 290 } |
| 291 | 291 |
| 292 void PrintPreviewUI::OnHidePreviewTab() { | 292 void PrintPreviewUI::OnHidePreviewTab() { |
| 293 TabContents* preview_tab = | 293 TabContents* preview_tab = |
| 294 TabContents::GetCurrentWrapperForContents(web_ui()->GetWebContents()); | 294 TabContents::FromWebContents(web_ui()->GetWebContents()); |
| 295 printing::BackgroundPrintingManager* background_printing_manager = | 295 printing::BackgroundPrintingManager* background_printing_manager = |
| 296 g_browser_process->background_printing_manager(); | 296 g_browser_process->background_printing_manager(); |
| 297 if (background_printing_manager->HasPrintPreviewTab(preview_tab)) | 297 if (background_printing_manager->HasPrintPreviewTab(preview_tab)) |
| 298 return; | 298 return; |
| 299 | 299 |
| 300 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate(); | 300 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate(); |
| 301 if (!delegate) | 301 if (!delegate) |
| 302 return; | 302 return; |
| 303 delegate->ReleaseTabContentsOnDialogClose(); | 303 delegate->ReleaseTabContentsOnDialogClose(); |
| 304 background_printing_manager->OwnPrintPreviewTab(preview_tab); | 304 background_printing_manager->OwnPrintPreviewTab(preview_tab); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 316 delegate->OnDialogCloseFromWebUI(); | 316 delegate->OnDialogCloseFromWebUI(); |
| 317 } | 317 } |
| 318 | 318 |
| 319 void PrintPreviewUI::OnReloadPrintersList() { | 319 void PrintPreviewUI::OnReloadPrintersList() { |
| 320 web_ui()->CallJavascriptFunction("reloadPrintersList"); | 320 web_ui()->CallJavascriptFunction("reloadPrintersList"); |
| 321 } | 321 } |
| 322 | 322 |
| 323 void PrintPreviewUI::OnPrintPreviewScalingDisabled() { | 323 void PrintPreviewUI::OnPrintPreviewScalingDisabled() { |
| 324 web_ui()->CallJavascriptFunction("printScalingDisabledForSourcePDF"); | 324 web_ui()->CallJavascriptFunction("printScalingDisabledForSourcePDF"); |
| 325 } | 325 } |
| OLD | NEW |