Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: chrome/browser/ui/webui/print_preview_ui.cc

Issue 8136027: Print Preview: Make print preview tab modal. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: address comments Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
15 #include "chrome/browser/printing/background_printing_manager.h"
14 #include "chrome/browser/printing/print_preview_data_service.h" 16 #include "chrome/browser/printing/print_preview_data_service.h"
15 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
19 #include "chrome/browser/ui/webui/html_dialog_ui.h"
16 #include "chrome/browser/ui/webui/print_preview_data_source.h" 20 #include "chrome/browser/ui/webui/print_preview_data_source.h"
17 #include "chrome/browser/ui/webui/print_preview_handler.h" 21 #include "chrome/browser/ui/webui/print_preview_handler.h"
18 #include "chrome/common/print_messages.h" 22 #include "chrome/common/print_messages.h"
19 #include "content/browser/tab_contents/tab_contents.h" 23 #include "content/browser/tab_contents/tab_contents.h"
20 #include "printing/page_size_margins.h" 24 #include "printing/page_size_margins.h"
21 #include "printing/print_job_constants.h" 25 #include "printing/print_job_constants.h"
22 26
23 using printing::PageSizeMargins; 27 using printing::PageSizeMargins;
24 28
25 namespace { 29 namespace {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 base::Lock lock_; 64 base::Lock lock_;
61 }; 65 };
62 66
63 // Written to on the UI thread, read from any thread. 67 // Written to on the UI thread, read from any thread.
64 base::LazyInstance<PrintPreviewRequestIdMapWithLock> 68 base::LazyInstance<PrintPreviewRequestIdMapWithLock>
65 g_print_preview_request_id_map(base::LINKER_INITIALIZED); 69 g_print_preview_request_id_map(base::LINKER_INITIALIZED);
66 70
67 } // namespace 71 } // namespace
68 72
69 PrintPreviewUI::PrintPreviewUI(TabContents* contents) 73 PrintPreviewUI::PrintPreviewUI(TabContents* contents)
70 : ChromeWebUI(contents), 74 : ConstrainedHtmlUI(contents),
71 initial_preview_start_time_(base::TimeTicks::Now()) { 75 initial_preview_start_time_(base::TimeTicks::Now()),
76 tab_closed_(false) {
72 // WebUI owns |handler_|. 77 // WebUI owns |handler_|.
73 handler_ = new PrintPreviewHandler(); 78 handler_ = new PrintPreviewHandler();
74 AddMessageHandler(handler_->Attach(this)); 79 AddMessageHandler(handler_->Attach(this));
75 80
76 // Set up the chrome://print/ data source. 81 // Set up the chrome://print/ data source.
77 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); 82 Profile* profile = Profile::FromBrowserContext(contents->browser_context());
78 profile->GetChromeURLDataManager()->AddDataSource( 83 profile->GetChromeURLDataManager()->AddDataSource(
79 new PrintPreviewDataSource()); 84 new PrintPreviewDataSource());
80 85
81 preview_ui_addr_str_ = GetPrintPreviewUIAddress(); 86 preview_ui_addr_str_ = GetPrintPreviewUIAddress();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 135 }
131 136
132 std::string PrintPreviewUI::GetPrintPreviewUIAddress() const { 137 std::string PrintPreviewUI::GetPrintPreviewUIAddress() const {
133 // Store the PrintPreviewUIAddress as a string. 138 // Store the PrintPreviewUIAddress as a string.
134 // "0x" + deadc0de + '\0' = 2 + 2 * sizeof(this) + 1; 139 // "0x" + deadc0de + '\0' = 2 + 2 * sizeof(this) + 1;
135 char preview_ui_addr[2 + (2 * sizeof(this)) + 1]; 140 char preview_ui_addr[2 + (2 * sizeof(this)) + 1];
136 base::snprintf(preview_ui_addr, sizeof(preview_ui_addr), "%p", this); 141 base::snprintf(preview_ui_addr, sizeof(preview_ui_addr), "%p", this);
137 return preview_ui_addr; 142 return preview_ui_addr;
138 } 143 }
139 144
140 void PrintPreviewUI::OnInitiatorTabCrashed() { 145 void PrintPreviewUI::OnPrintPreviewTabCrashed() {
141 StringValue initiator_tab_url(initiator_url_); 146 TabContentsWrapper* preview_tab =
142 CallJavascriptFunction("onInitiatorTabCrashed", initiator_tab_url); 147 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents());
148 printing::BackgroundPrintingManager* background_printing_manager =
149 g_browser_process->background_printing_manager();
150 if (background_printing_manager->HasPrintPreviewTab(preview_tab))
151 return;
152 OnClosePrintPreviewTab();
143 } 153 }
144 154
145 void PrintPreviewUI::OnInitiatorTabClosed() { 155 void PrintPreviewUI::OnInitiatorTabClosed() {
146 StringValue initiator_tab_url(initiator_url_); 156 TabContentsWrapper* preview_tab =
147 CallJavascriptFunction("onInitiatorTabClosed", initiator_tab_url); 157 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents());
158 printing::BackgroundPrintingManager* background_printing_manager =
159 g_browser_process->background_printing_manager();
160 if (background_printing_manager->HasPrintPreviewTab(preview_tab))
161 CallJavascriptFunction("cancelPendingPrintRequest");
162 else
163 OnClosePrintPreviewTab();
148 } 164 }
149 165
150 void PrintPreviewUI::OnPrintPreviewRequest(int request_id) { 166 void PrintPreviewUI::OnPrintPreviewRequest(int request_id) {
151 g_print_preview_request_id_map.Get().Set(preview_ui_addr_str_, request_id); 167 g_print_preview_request_id_map.Get().Set(preview_ui_addr_str_, request_id);
152 } 168 }
153 169
154 void PrintPreviewUI::OnShowSystemDialog() { 170 void PrintPreviewUI::OnShowSystemDialog() {
155 CallJavascriptFunction("onSystemDialogLinkClicked"); 171 CallJavascriptFunction("onSystemDialogLinkClicked");
156 } 172 }
157 173
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 CallJavascriptFunction("printPreviewFailed"); 252 CallJavascriptFunction("printPreviewFailed");
237 } 253 }
238 254
239 void PrintPreviewUI::OnInvalidPrinterSettings() { 255 void PrintPreviewUI::OnInvalidPrinterSettings() {
240 CallJavascriptFunction("invalidPrinterSettings"); 256 CallJavascriptFunction("invalidPrinterSettings");
241 } 257 }
242 258
243 PrintPreviewDataService* PrintPreviewUI::print_preview_data_service() { 259 PrintPreviewDataService* PrintPreviewUI::print_preview_data_service() {
244 return PrintPreviewDataService::GetInstance(); 260 return PrintPreviewDataService::GetInstance();
245 } 261 }
262
263 void PrintPreviewUI::OnHidePreviewTab() {
264 TabContentsWrapper* preview_tab =
265 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents());
266 printing::BackgroundPrintingManager* background_printing_manager =
267 g_browser_process->background_printing_manager();
268 if (background_printing_manager->HasPrintPreviewTab(preview_tab))
269 return;
270
271 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate();
272 if (!delegate)
273 return;
274 delegate->ReleaseTabContentsOnDialogClose();
275 background_printing_manager->OwnPrintPreviewTab(preview_tab);
276 OnClosePrintPreviewTab();
277 }
278
279 void PrintPreviewUI::OnClosePrintPreviewTab() {
280 if (tab_closed_)
281 return;
282 tab_closed_ = true;
283 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate();
284 if (!delegate)
285 return;
286 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed("");
287 delegate->OnDialogCloseFromWebUI();
288 }
289
290 void PrintPreviewUI::OnReloadPrintersList() {
291 CallJavascriptFunction("reloadPrintersList");
292 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698