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

Side by Side Diff: chrome/browser/printing/print_preview_tab_controller.cc

Issue 7574002: Be able to print items that do window.print(); window.close() (airline tix e.g.) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 9 years, 4 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/printing/print_preview_tab_controller.h" 5 #include "chrome/browser/printing/print_preview_tab_controller.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/printing/background_printing_manager.h"
Lei Zhang 2011/08/26 10:01:54 nit: alphabetical order
Sheridan Rawlins 2011/08/26 23:45:39 Done.
13 #include "chrome/browser/sessions/restore_tab_helper.h" 14 #include "chrome/browser/sessions/restore_tab_helper.h"
14 #include "chrome/browser/tabs/tab_strip_model.h" 15 #include "chrome/browser/tabs/tab_strip_model.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_list.h" 17 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/browser_navigator.h" 18 #include "chrome/browser/ui/browser_navigator.h"
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
19 #include "chrome/browser/ui/webui/print_preview_ui.h" 20 #include "chrome/browser/ui/webui/print_preview_ui.h"
20 #include "chrome/common/chrome_content_client.h" 21 #include "chrome/common/chrome_content_client.h"
21 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 152 }
152 } 153 }
153 } 154 }
154 155
155 void PrintPreviewTabController::OnRendererProcessClosed( 156 void PrintPreviewTabController::OnRendererProcessClosed(
156 RenderProcessHost* rph) { 157 RenderProcessHost* rph) {
157 for (PrintPreviewTabMap::iterator iter = preview_tab_map_.begin(); 158 for (PrintPreviewTabMap::iterator iter = preview_tab_map_.begin();
158 iter != preview_tab_map_.end(); ++iter) { 159 iter != preview_tab_map_.end(); ++iter) {
159 if (iter->second != NULL && 160 if (iter->second != NULL &&
160 iter->second->render_view_host()->process() == rph) { 161 iter->second->render_view_host()->process() == rph) {
161 TabContents* preview_tab = GetPrintPreviewForTab(iter->second); 162 TabContents* initiator_tab = iter->second;
Lei Zhang 2011/08/26 10:01:54 move this up to between line 159/160 and then you
Sheridan Rawlins 2011/08/26 23:45:39 Done.
163 // Release the initiator tab contents, possibly deleting if owned.
164 if (initiator_tab) {
Lei Zhang 2011/08/26 10:01:54 this will always be true, we already tested this c
Sheridan Rawlins 2011/08/26 23:45:39 Yeah, the previous comment made this obvious :) D
165 RemoveObservers(initiator_tab);
166 TabContentsWrapper* initiator_wrapper =
167 TabContentsWrapper::GetCurrentWrapperForContents(initiator_tab);
168 g_browser_process->background_printing_manager()->
169 ReleaseInitiatorTabContents(initiator_wrapper);
170 }
171 TabContents* preview_tab = GetPrintPreviewForTab(initiator_tab);
162 PrintPreviewUI* print_preview_ui = 172 PrintPreviewUI* print_preview_ui =
163 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); 173 static_cast<PrintPreviewUI*>(preview_tab->web_ui());
164 print_preview_ui->OnInitiatorTabCrashed(); 174 print_preview_ui->OnInitiatorTabCrashed();
165 } 175 }
166 } 176 }
167 } 177 }
168 178
169 void PrintPreviewTabController::OnTabContentsDestroyed(TabContents* tab) { 179 void PrintPreviewTabController::OnTabContentsDestroyed(TabContents* tab) {
170 TabContents* preview_tab = GetPrintPreviewForTab(tab); 180 TabContents* preview_tab = GetPrintPreviewForTab(tab);
171 if (!preview_tab) 181 if (!preview_tab)
172 return; 182 return;
173 183
174 if (tab == preview_tab) { 184 if (tab == preview_tab) {
175 // Remove the initiator tab's observers before erasing the mapping.
176 TabContents* initiator_tab = GetInitiatorTab(tab);
177 if (initiator_tab)
178 RemoveObservers(initiator_tab);
179
180 // Print preview tab contents are destroyed. Notify |PrintPreviewUI| to 185 // Print preview tab contents are destroyed. Notify |PrintPreviewUI| to
181 // abort the initiator tab preview request. 186 // abort the initiator tab preview request.
182 if (IsPrintPreviewTab(tab) && tab->web_ui()) { 187 if (IsPrintPreviewTab(tab) && tab->web_ui()) {
183 PrintPreviewUI* print_preview_ui = 188 PrintPreviewUI* print_preview_ui =
184 static_cast<PrintPreviewUI*>(tab->web_ui()); 189 static_cast<PrintPreviewUI*>(tab->web_ui());
185 print_preview_ui->OnTabDestroyed(); 190 print_preview_ui->OnTabDestroyed();
186 } 191 }
187 192
193 // Remove the initiator tab's observers before erasing the mapping. Also
194 // release the initiator tab contents, possibly deleting if owned.
195 TabContents* initiator_tab = GetInitiatorTab(tab);
196 if (initiator_tab) {
197 RemoveObservers(initiator_tab);
198 TabContentsWrapper* initiator_wrapper =
199 TabContentsWrapper::GetCurrentWrapperForContents(initiator_tab);
200 g_browser_process->background_printing_manager()->
201 ReleaseInitiatorTabContents(initiator_wrapper);
202 }
188 // Erase the map entry. 203 // Erase the map entry.
189 preview_tab_map_.erase(tab); 204 preview_tab_map_.erase(tab);
190 } else { 205 } else {
191 // Initiator tab is closed. Disable the controls in preview tab. 206 // Initiator tab is closed. Disable the controls in preview tab.
192 if (preview_tab->web_ui()) { 207 if (preview_tab->web_ui()) {
193 PrintPreviewUI* print_preview_ui = 208 PrintPreviewUI* print_preview_ui =
194 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); 209 static_cast<PrintPreviewUI*>(preview_tab->web_ui());
195 print_preview_ui->OnInitiatorTabClosed(); 210 print_preview_ui->OnInitiatorTabClosed();
196 } 211 }
197 212
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 transition_type == PageTransition::FORWARD_BACK && 256 transition_type == PageTransition::FORWARD_BACK &&
242 nav_type == NavigationType::EXISTING_PAGE) { 257 nav_type == NavigationType::EXISTING_PAGE) {
243 return; 258 return;
244 } 259 }
245 } 260 }
246 261
247 RemoveObservers(tab); 262 RemoveObservers(tab);
248 if (source_tab_is_preview_tab) { 263 if (source_tab_is_preview_tab) {
249 // Remove the initiator tab's observers before erasing the mapping. 264 // Remove the initiator tab's observers before erasing the mapping.
250 TabContents* initiator_tab = GetInitiatorTab(tab); 265 TabContents* initiator_tab = GetInitiatorTab(tab);
251 if (initiator_tab) 266 if (initiator_tab) {
252 RemoveObservers(initiator_tab); 267 RemoveObservers(initiator_tab);
268 TabContentsWrapper* initiator_wrapper =
269 TabContentsWrapper::GetCurrentWrapperForContents(initiator_tab);
270 g_browser_process->background_printing_manager()->
271 ReleaseInitiatorTabContents(initiator_wrapper);
272 }
253 preview_tab_map_.erase(tab); 273 preview_tab_map_.erase(tab);
254 } else { 274 } else {
255 preview_tab_map_[preview_tab] = NULL; 275 preview_tab_map_[preview_tab] = NULL;
256 276
257 // Initiator tab is closed. Disable the controls in preview tab. 277 // Initiator tab is closed. Disable the controls in preview tab.
258 if (preview_tab->web_ui()) { 278 if (preview_tab->web_ui()) {
259 PrintPreviewUI* print_preview_ui = 279 PrintPreviewUI* print_preview_ui =
260 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); 280 static_cast<PrintPreviewUI*>(preview_tab->web_ui());
261 print_preview_ui->OnInitiatorTabClosed(); 281 print_preview_ui->OnInitiatorTabClosed();
262 } 282 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 RenderProcessHost* rph = tab->render_view_host()->process(); 382 RenderProcessHost* rph = tab->render_view_host()->process();
363 if (registrar_.IsRegistered(this, 383 if (registrar_.IsRegistered(this,
364 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 384 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
365 Source<RenderProcessHost>(rph))) { 385 Source<RenderProcessHost>(rph))) {
366 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 386 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
367 Source<RenderProcessHost>(rph)); 387 Source<RenderProcessHost>(rph));
368 } 388 }
369 } 389 }
370 390
371 } // namespace printing 391 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698