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

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: do not listen for F1 key in JS 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()) {
72 // WebUI owns |handler_|. 76 // WebUI owns |handler_|.
73 handler_ = new PrintPreviewHandler(); 77 handler_ = new PrintPreviewHandler();
74 AddMessageHandler(handler_->Attach(this)); 78 AddMessageHandler(handler_->Attach(this));
75 79
76 // Set up the chrome://print/ data source. 80 // Set up the chrome://print/ data source.
77 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); 81 Profile* profile = Profile::FromBrowserContext(contents->browser_context());
78 profile->GetChromeURLDataManager()->AddDataSource( 82 profile->GetChromeURLDataManager()->AddDataSource(
79 new PrintPreviewDataSource()); 83 new PrintPreviewDataSource());
80 84
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 134 }
131 135
132 std::string PrintPreviewUI::GetPrintPreviewUIAddress() const { 136 std::string PrintPreviewUI::GetPrintPreviewUIAddress() const {
133 // Store the PrintPreviewUIAddress as a string. 137 // Store the PrintPreviewUIAddress as a string.
134 // "0x" + deadc0de + '\0' = 2 + 2 * sizeof(this) + 1; 138 // "0x" + deadc0de + '\0' = 2 + 2 * sizeof(this) + 1;
135 char preview_ui_addr[2 + (2 * sizeof(this)) + 1]; 139 char preview_ui_addr[2 + (2 * sizeof(this)) + 1];
136 base::snprintf(preview_ui_addr, sizeof(preview_ui_addr), "%p", this); 140 base::snprintf(preview_ui_addr, sizeof(preview_ui_addr), "%p", this);
137 return preview_ui_addr; 141 return preview_ui_addr;
138 } 142 }
139 143
140 void PrintPreviewUI::OnInitiatorTabCrashed() { 144 void PrintPreviewUI::OnPrintPreviewTabCrashed() {
141 StringValue initiator_tab_url(initiator_url_); 145 TabContentsWrapper* preview_tab =
142 CallJavascriptFunction("onInitiatorTabCrashed", initiator_tab_url); 146 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents());
147 printing::BackgroundPrintingManager* background_printing_manager =
148 g_browser_process->background_printing_manager();
149 if (background_printing_manager->HasPrintPreviewTab(preview_tab))
150 return;
151 ClosePrintPreviewTab();
143 } 152 }
144 153
145 void PrintPreviewUI::OnInitiatorTabClosed() { 154 void PrintPreviewUI::OnInitiatorTabClosed() {
146 StringValue initiator_tab_url(initiator_url_); 155 TabContentsWrapper* preview_tab =
147 CallJavascriptFunction("onInitiatorTabClosed", initiator_tab_url); 156 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents());
157 printing::BackgroundPrintingManager* background_printing_manager =
158 g_browser_process->background_printing_manager();
159 if (background_printing_manager->HasPrintPreviewTab(preview_tab))
160 CallJavascriptFunction("cancelPendingPrintRequest");
161 else
162 ClosePrintPreviewTab();
148 } 163 }
149 164
150 void PrintPreviewUI::OnPrintPreviewRequest(int request_id) { 165 void PrintPreviewUI::OnPrintPreviewRequest(int request_id) {
151 g_print_preview_request_id_map.Get().Set(preview_ui_addr_str_, request_id); 166 g_print_preview_request_id_map.Get().Set(preview_ui_addr_str_, request_id);
152 } 167 }
153 168
154 void PrintPreviewUI::OnShowSystemDialog() { 169 void PrintPreviewUI::OnShowSystemDialog() {
155 CallJavascriptFunction("onSystemDialogLinkClicked"); 170 CallJavascriptFunction("onSystemDialogLinkClicked");
156 } 171 }
157 172
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 CallJavascriptFunction("printPreviewFailed"); 251 CallJavascriptFunction("printPreviewFailed");
237 } 252 }
238 253
239 void PrintPreviewUI::OnInvalidPrinterSettings() { 254 void PrintPreviewUI::OnInvalidPrinterSettings() {
240 CallJavascriptFunction("invalidPrinterSettings"); 255 CallJavascriptFunction("invalidPrinterSettings");
241 } 256 }
242 257
243 PrintPreviewDataService* PrintPreviewUI::print_preview_data_service() { 258 PrintPreviewDataService* PrintPreviewUI::print_preview_data_service() {
244 return PrintPreviewDataService::GetInstance(); 259 return PrintPreviewDataService::GetInstance();
245 } 260 }
261
262 void PrintPreviewUI::HidePreviewTab() {
263 TabContentsWrapper* preview_tab =
264 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents());
265 printing::BackgroundPrintingManager* background_printing_manager =
266 g_browser_process->background_printing_manager();
267 if (background_printing_manager->HasPrintPreviewTab(preview_tab))
268 return;
269
270 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate();
271 if (!delegate)
272 return;
273 delegate->ReleaseTabContentsOnDialogClose();
274 background_printing_manager->OwnPrintPreviewTab(preview_tab);
275 ClosePrintPreviewTab();
276 }
277
278 void PrintPreviewUI::ClosePrintPreviewTab() {
279 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate();
280 if (!delegate)
281 return;
282 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed("");
283 delegate->OnDialogCloseFromWebUI();
284 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698