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

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

Issue 9003014: Replace WebUI::tab_contents() with web_contents() and switch all users to use web_contents.h inst... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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
« no previous file with comments | « chrome/browser/ui/webui/print_preview_ui.h ('k') | chrome/browser/ui/webui/profiler_ui.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" 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/printing/print_preview_tab_controller.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
20 #include "chrome/browser/ui/webui/html_dialog_ui.h" 20 #include "chrome/browser/ui/webui/html_dialog_ui.h"
21 #include "chrome/browser/ui/webui/print_preview_data_source.h" 21 #include "chrome/browser/ui/webui/print_preview_data_source.h"
22 #include "chrome/browser/ui/webui/print_preview_handler.h" 22 #include "chrome/browser/ui/webui/print_preview_handler.h"
23 #include "chrome/common/print_messages.h" 23 #include "chrome/common/print_messages.h"
24 #include "content/browser/tab_contents/tab_contents.h" 24 #include "content/public/browser/web_contents.h"
25 #include "printing/page_size_margins.h" 25 #include "printing/page_size_margins.h"
26 #include "printing/print_job_constants.h" 26 #include "printing/print_job_constants.h"
27 27
28 using content::WebContents;
28 using printing::PageSizeMargins; 29 using printing::PageSizeMargins;
29 30
30 namespace { 31 namespace {
31 32
32 // Thread-safe wrapper around a std::map to keep track of mappings from 33 // Thread-safe wrapper around a std::map to keep track of mappings from
33 // PrintPreviewUI addresses to most recent print preview request ids. 34 // PrintPreviewUI addresses to most recent print preview request ids.
34 class PrintPreviewRequestIdMapWithLock { 35 class PrintPreviewRequestIdMapWithLock {
35 public: 36 public:
36 PrintPreviewRequestIdMapWithLock() {} 37 PrintPreviewRequestIdMapWithLock() {}
37 ~PrintPreviewRequestIdMapWithLock() {} 38 ~PrintPreviewRequestIdMapWithLock() {}
(...skipping 26 matching lines...) Expand all
64 PrintPreviewRequestIdMap map_; 65 PrintPreviewRequestIdMap map_;
65 base::Lock lock_; 66 base::Lock lock_;
66 }; 67 };
67 68
68 // Written to on the UI thread, read from any thread. 69 // Written to on the UI thread, read from any thread.
69 base::LazyInstance<PrintPreviewRequestIdMapWithLock> 70 base::LazyInstance<PrintPreviewRequestIdMapWithLock>
70 g_print_preview_request_id_map = LAZY_INSTANCE_INITIALIZER; 71 g_print_preview_request_id_map = LAZY_INSTANCE_INITIALIZER;
71 72
72 } // namespace 73 } // namespace
73 74
74 PrintPreviewUI::PrintPreviewUI(TabContents* contents) 75 PrintPreviewUI::PrintPreviewUI(WebContents* contents)
75 : ConstrainedHtmlUI(contents), 76 : ConstrainedHtmlUI(contents),
76 initial_preview_start_time_(base::TimeTicks::Now()), 77 initial_preview_start_time_(base::TimeTicks::Now()),
77 handler_(NULL), 78 handler_(NULL),
78 source_is_modifiable_(true), 79 source_is_modifiable_(true),
79 tab_closed_(false) { 80 tab_closed_(false) {
80 printing::PrintPreviewTabController* controller = 81 printing::PrintPreviewTabController* controller =
81 printing::PrintPreviewTabController::GetInstance(); 82 printing::PrintPreviewTabController::GetInstance();
82 is_dummy_ = (!controller || !controller->is_creating_print_preview_tab()); 83 is_dummy_ = (!controller || !controller->is_creating_print_preview_tab());
83 84
84 // Set up the chrome://print/ data source. 85 // Set up the chrome://print/ data source.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 const std::string& initiator_url, 129 const std::string& initiator_url,
129 const string16& job_title) { 130 const string16& job_title) {
130 initiator_url_ = initiator_url; 131 initiator_url_ = initiator_url;
131 initiator_tab_title_ = job_title; 132 initiator_tab_title_ = job_title;
132 } 133 }
133 134
134 // static 135 // static
135 void PrintPreviewUI::SetSourceIsModifiable( 136 void PrintPreviewUI::SetSourceIsModifiable(
136 TabContentsWrapper* print_preview_tab, 137 TabContentsWrapper* print_preview_tab,
137 bool source_is_modifiable) { 138 bool source_is_modifiable) {
138 if (!print_preview_tab || !print_preview_tab->tab_contents()->GetWebUI()) 139 if (!print_preview_tab || !print_preview_tab->web_contents()->GetWebUI())
139 return; 140 return;
140 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 141 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
141 print_preview_tab->tab_contents()->GetWebUI()); 142 print_preview_tab->web_contents()->GetWebUI());
142 print_preview_ui->source_is_modifiable_ = source_is_modifiable; 143 print_preview_ui->source_is_modifiable_ = source_is_modifiable;
143 } 144 }
144 145
145 // static 146 // static
146 void PrintPreviewUI::GetCurrentPrintPreviewStatus( 147 void PrintPreviewUI::GetCurrentPrintPreviewStatus(
147 const std::string& preview_ui_addr, 148 const std::string& preview_ui_addr,
148 int request_id, 149 int request_id,
149 bool* cancel) { 150 bool* cancel) {
150 int current_id = -1; 151 int current_id = -1;
151 if (!g_print_preview_request_id_map.Get().Get(preview_ui_addr, &current_id)) { 152 if (!g_print_preview_request_id_map.Get().Get(preview_ui_addr, &current_id)) {
152 *cancel = true; 153 *cancel = true;
153 return; 154 return;
154 } 155 }
155 *cancel = (request_id != current_id); 156 *cancel = (request_id != current_id);
156 } 157 }
157 158
158 std::string PrintPreviewUI::GetPrintPreviewUIAddress() const { 159 std::string PrintPreviewUI::GetPrintPreviewUIAddress() const {
159 // Store the PrintPreviewUIAddress as a string. 160 // Store the PrintPreviewUIAddress as a string.
160 // "0x" + deadc0de + '\0' = 2 + 2 * sizeof(this) + 1; 161 // "0x" + deadc0de + '\0' = 2 + 2 * sizeof(this) + 1;
161 char preview_ui_addr[2 + (2 * sizeof(this)) + 1]; 162 char preview_ui_addr[2 + (2 * sizeof(this)) + 1];
162 base::snprintf(preview_ui_addr, sizeof(preview_ui_addr), "%p", this); 163 base::snprintf(preview_ui_addr, sizeof(preview_ui_addr), "%p", this);
163 return preview_ui_addr; 164 return preview_ui_addr;
164 } 165 }
165 166
166 void PrintPreviewUI::OnPrintPreviewTabClosed() { 167 void PrintPreviewUI::OnPrintPreviewTabClosed() {
167 TabContentsWrapper* preview_tab = 168 TabContentsWrapper* preview_tab =
168 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents()); 169 TabContentsWrapper::GetCurrentWrapperForContents(web_contents());
169 printing::BackgroundPrintingManager* background_printing_manager = 170 printing::BackgroundPrintingManager* background_printing_manager =
170 g_browser_process->background_printing_manager(); 171 g_browser_process->background_printing_manager();
171 if (background_printing_manager->HasPrintPreviewTab(preview_tab)) 172 if (background_printing_manager->HasPrintPreviewTab(preview_tab))
172 return; 173 return;
173 OnClosePrintPreviewTab(); 174 OnClosePrintPreviewTab();
174 } 175 }
175 176
176 void PrintPreviewUI::OnInitiatorTabClosed() { 177 void PrintPreviewUI::OnInitiatorTabClosed() {
177 TabContentsWrapper* preview_tab = 178 TabContentsWrapper* preview_tab =
178 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents()); 179 TabContentsWrapper::GetCurrentWrapperForContents(web_contents());
179 printing::BackgroundPrintingManager* background_printing_manager = 180 printing::BackgroundPrintingManager* background_printing_manager =
180 g_browser_process->background_printing_manager(); 181 g_browser_process->background_printing_manager();
181 if (background_printing_manager->HasPrintPreviewTab(preview_tab)) 182 if (background_printing_manager->HasPrintPreviewTab(preview_tab))
182 CallJavascriptFunction("cancelPendingPrintRequest"); 183 CallJavascriptFunction("cancelPendingPrintRequest");
183 else 184 else
184 OnClosePrintPreviewTab(); 185 OnClosePrintPreviewTab();
185 } 186 }
186 187
187 void PrintPreviewUI::OnPrintPreviewRequest(int request_id) { 188 void PrintPreviewUI::OnPrintPreviewRequest(int request_id) {
188 g_print_preview_request_id_map.Get().Set(preview_ui_addr_str_, request_id); 189 g_print_preview_request_id_map.Get().Set(preview_ui_addr_str_, request_id);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 void PrintPreviewUI::OnInvalidPrinterSettings() { 275 void PrintPreviewUI::OnInvalidPrinterSettings() {
275 CallJavascriptFunction("invalidPrinterSettings"); 276 CallJavascriptFunction("invalidPrinterSettings");
276 } 277 }
277 278
278 PrintPreviewDataService* PrintPreviewUI::print_preview_data_service() { 279 PrintPreviewDataService* PrintPreviewUI::print_preview_data_service() {
279 return PrintPreviewDataService::GetInstance(); 280 return PrintPreviewDataService::GetInstance();
280 } 281 }
281 282
282 void PrintPreviewUI::OnHidePreviewTab() { 283 void PrintPreviewUI::OnHidePreviewTab() {
283 TabContentsWrapper* preview_tab = 284 TabContentsWrapper* preview_tab =
284 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents()); 285 TabContentsWrapper::GetCurrentWrapperForContents(web_contents());
285 printing::BackgroundPrintingManager* background_printing_manager = 286 printing::BackgroundPrintingManager* background_printing_manager =
286 g_browser_process->background_printing_manager(); 287 g_browser_process->background_printing_manager();
287 if (background_printing_manager->HasPrintPreviewTab(preview_tab)) 288 if (background_printing_manager->HasPrintPreviewTab(preview_tab))
288 return; 289 return;
289 290
290 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); 291 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate();
291 if (!delegate) 292 if (!delegate)
292 return; 293 return;
293 delegate->ReleaseTabContentsOnDialogClose(); 294 delegate->ReleaseTabContentsOnDialogClose();
294 background_printing_manager->OwnPrintPreviewTab(preview_tab); 295 background_printing_manager->OwnPrintPreviewTab(preview_tab);
295 OnClosePrintPreviewTab(); 296 OnClosePrintPreviewTab();
296 } 297 }
297 298
298 void PrintPreviewUI::OnClosePrintPreviewTab() { 299 void PrintPreviewUI::OnClosePrintPreviewTab() {
299 if (tab_closed_) 300 if (tab_closed_)
300 return; 301 return;
301 tab_closed_ = true; 302 tab_closed_ = true;
302 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); 303 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate();
303 if (!delegate) 304 if (!delegate)
304 return; 305 return;
305 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(""); 306 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed("");
306 delegate->OnDialogCloseFromWebUI(); 307 delegate->OnDialogCloseFromWebUI();
307 } 308 }
308 309
309 void PrintPreviewUI::OnReloadPrintersList() { 310 void PrintPreviewUI::OnReloadPrintersList() {
310 CallJavascriptFunction("reloadPrintersList"); 311 CallJavascriptFunction("reloadPrintersList");
311 } 312 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/print_preview_ui.h ('k') | chrome/browser/ui/webui/profiler_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698