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

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

Issue 8515017: Print Preview: Properly handle window.print(). (Closed)
Patch Set: fail instead of crash when 2 views both do window.print() Created 9 years, 1 month 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
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 <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 245
246 for (size_t i = 0; i < closed_preview_tabs.size(); ++i) { 246 for (size_t i = 0; i < closed_preview_tabs.size(); ++i) {
247 RemovePreviewTab(closed_preview_tabs[i]); 247 RemovePreviewTab(closed_preview_tabs[i]);
248 PrintPreviewUI* print_preview_ui = 248 PrintPreviewUI* print_preview_ui =
249 static_cast<PrintPreviewUI*>(closed_preview_tabs[i]->web_ui()); 249 static_cast<PrintPreviewUI*>(closed_preview_tabs[i]->web_ui());
250 if (print_preview_ui) 250 if (print_preview_ui)
251 print_preview_ui->OnPrintPreviewTabClosed(); 251 print_preview_ui->OnPrintPreviewTabClosed();
252 } 252 }
253 253
254 for (size_t i = 0; i < closed_initiator_tabs.size(); ++i) 254 for (size_t i = 0; i < closed_initiator_tabs.size(); ++i)
255 RemoveInitiatorTab(closed_initiator_tabs[i]); 255 RemoveInitiatorTab(closed_initiator_tabs[i], false);
256 } 256 }
257 257
258 void PrintPreviewTabController::OnTabContentsDestroyed( 258 void PrintPreviewTabController::OnTabContentsDestroyed(
259 TabContentsWrapper* tab) { 259 TabContentsWrapper* tab) {
260 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(tab); 260 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(tab);
261 if (!preview_tab) { 261 if (!preview_tab) {
262 NOTREACHED(); 262 NOTREACHED();
263 return; 263 return;
264 } 264 }
265 265
266 if (tab == preview_tab) 266 if (tab == preview_tab)
267 RemovePreviewTab(tab); 267 RemovePreviewTab(tab);
268 else 268 else
269 RemoveInitiatorTab(tab); 269 RemoveInitiatorTab(tab, false);
270 } 270 }
271 271
272 void PrintPreviewTabController::OnNavEntryCommitted( 272 void PrintPreviewTabController::OnNavEntryCommitted(
273 TabContentsWrapper* tab, content::LoadCommittedDetails* details) { 273 TabContentsWrapper* tab, content::LoadCommittedDetails* details) {
274 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(tab); 274 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(tab);
275 if (!preview_tab) { 275 if (!preview_tab) {
276 NOTREACHED(); 276 NOTREACHED();
277 return; 277 return;
278 } 278 }
279 bool source_tab_is_preview_tab = (tab == preview_tab); 279 bool source_tab_is_preview_tab = (tab == preview_tab);
(...skipping 23 matching lines...) Expand all
303 nav_type == content::NAVIGATION_TYPE_EXISTING_PAGE && 303 nav_type == content::NAVIGATION_TYPE_EXISTING_PAGE &&
304 IsPrintPreviewURL(details->previous_url)) { 304 IsPrintPreviewURL(details->previous_url)) {
305 return; 305 return;
306 } 306 }
307 } 307 }
308 NOTREACHED(); 308 NOTREACHED();
309 return; 309 return;
310 } 310 }
311 311
312 // Initiator tab navigated. 312 // Initiator tab navigated.
313 RemoveInitiatorTab(tab); 313 RemoveInitiatorTab(tab, true);
314 } 314 }
315 315
316 // static 316 // static
317 bool PrintPreviewTabController::IsPrintPreviewTab(TabContentsWrapper* tab) { 317 bool PrintPreviewTabController::IsPrintPreviewTab(TabContentsWrapper* tab) {
318 return IsPrintPreviewURL(tab->tab_contents()->GetURL()); 318 return IsPrintPreviewURL(tab->tab_contents()->GetURL());
319 } 319 }
320 320
321 // static 321 // static
322 bool PrintPreviewTabController::IsPrintPreviewURL(const GURL& url) { 322 bool PrintPreviewTabController::IsPrintPreviewURL(const GURL& url) {
323 return (url.SchemeIs(chrome::kChromeUIScheme) && 323 return (url.SchemeIs(chrome::kChromeUIScheme) &&
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 if (registrar_.IsRegistered(this, 429 if (registrar_.IsRegistered(this,
430 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 430 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
431 content::Source<content::RenderProcessHost>( 431 content::Source<content::RenderProcessHost>(
432 rph))) { 432 rph))) {
433 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 433 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
434 content::Source<content::RenderProcessHost>(rph)); 434 content::Source<content::RenderProcessHost>(rph));
435 } 435 }
436 } 436 }
437 437
438 void PrintPreviewTabController::RemoveInitiatorTab( 438 void PrintPreviewTabController::RemoveInitiatorTab(
439 TabContentsWrapper* initiator_tab) { 439 TabContentsWrapper* initiator_tab, bool is_navigation) {
440 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(initiator_tab); 440 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(initiator_tab);
441 DCHECK(preview_tab); 441 DCHECK(preview_tab);
442 // Update the map entry first, so when the print preview tab gets destroyed 442 // Update the map entry first, so when the print preview tab gets destroyed
443 // and reaches RemovePreviewTab(), it does not attempt to also remove the 443 // and reaches RemovePreviewTab(), it does not attempt to also remove the
444 // initiator tab's observers. 444 // initiator tab's observers.
445 preview_tab_map_[preview_tab] = NULL; 445 preview_tab_map_[preview_tab] = NULL;
446 RemoveObservers(initiator_tab); 446 RemoveObservers(initiator_tab);
447 447
448 // For the navigation case, PrintPreviewDone() has already been called in
449 // PrintPreviewMessageHandler::NavigateToPendingEntry().
450 if (!is_navigation)
451 initiator_tab->print_view_manager()->PrintPreviewDone();
452
448 // Initiator tab is closed. Close the print preview tab too. 453 // Initiator tab is closed. Close the print preview tab too.
449 PrintPreviewUI* print_preview_ui = 454 PrintPreviewUI* print_preview_ui =
450 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); 455 static_cast<PrintPreviewUI*>(preview_tab->web_ui());
451 if (print_preview_ui) 456 if (print_preview_ui)
452 print_preview_ui->OnInitiatorTabClosed(); 457 print_preview_ui->OnInitiatorTabClosed();
453 } 458 }
454 459
455 void PrintPreviewTabController::RemovePreviewTab( 460 void PrintPreviewTabController::RemovePreviewTab(
456 TabContentsWrapper* preview_tab) { 461 TabContentsWrapper* preview_tab) {
457 // Remove the initiator tab's observers before erasing the mapping. 462 // Remove the initiator tab's observers before erasing the mapping.
458 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab); 463 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab);
459 if (initiator_tab) 464 if (initiator_tab) {
460 RemoveObservers(initiator_tab); 465 RemoveObservers(initiator_tab);
466 initiator_tab->print_view_manager()->PrintPreviewDone();
467 }
461 468
462 // Print preview TabContents is destroyed. Notify |PrintPreviewUI| to abort 469 // Print preview TabContents is destroyed. Notify |PrintPreviewUI| to abort
463 // the initiator tab preview request. 470 // the initiator tab preview request.
464 PrintPreviewUI* print_preview_ui = 471 PrintPreviewUI* print_preview_ui =
465 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); 472 static_cast<PrintPreviewUI*>(preview_tab->web_ui());
466 if (print_preview_ui) 473 if (print_preview_ui)
467 print_preview_ui->OnTabDestroyed(); 474 print_preview_ui->OnTabDestroyed();
468 475
469 preview_tab_map_.erase(preview_tab); 476 preview_tab_map_.erase(preview_tab);
470 RemoveObservers(preview_tab); 477 RemoveObservers(preview_tab);
471 } 478 }
472 479
473 } // namespace printing 480 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698