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

Side by Side Diff: chrome/browser/ui/webui/print_preview_handler.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/ui/webui/print_preview_handler.h" 5 #include "chrome/browser/ui/webui/print_preview_handler.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 361
362 void PrintPreviewHandler::HandlePrint(const ListValue* args) { 362 void PrintPreviewHandler::HandlePrint(const ListValue* args) {
363 ReportStats(); 363 ReportStats();
364 364
365 // Record the number of times the user requests to regenerate preview data 365 // Record the number of times the user requests to regenerate preview data
366 // before printing. 366 // before printing.
367 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", 367 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint",
368 regenerate_preview_request_count_); 368 regenerate_preview_request_count_);
369 369
370 TabContentsWrapper* initiator_tab = GetInitiatorTab(); 370 TabContentsWrapper* initiator_tab = GetInitiatorTab();
371 if (initiator_tab) { 371 CHECK(initiator_tab);
372 RenderViewHost* rvh = initiator_tab->render_view_host(); 372
373 rvh->Send(new PrintMsg_ResetScriptedPrintCount(rvh->routing_id())); 373 RenderViewHost* init_rvh = initiator_tab->render_view_host();
374 } 374 init_rvh->Send(new PrintMsg_ResetScriptedPrintCount(init_rvh->routing_id()));
375 375
376 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); 376 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args));
377 if (!settings.get()) 377 if (!settings.get())
378 return; 378 return;
379 379
380 // Storing last used color model. 380 // Storing last used color model.
381 int color_model; 381 int color_model;
382 if (!settings->GetInteger(printing::kSettingColor, &color_model)) 382 if (!settings->GetInteger(printing::kSettingColor, &color_model))
383 color_model = printing::GRAY; 383 color_model = printing::GRAY;
384 last_used_color_model_ = static_cast<printing::ColorModels>(color_model); 384 last_used_color_model_ = static_cast<printing::ColorModels>(color_model);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 432
433 // Do this so the initiator tab can open a new print preview tab. 433 // Do this so the initiator tab can open a new print preview tab.
434 ClearInitiatorTabDetails(); 434 ClearInitiatorTabDetails();
435 435
436 // The PDF being printed contains only the pages that the user selected, 436 // The PDF being printed contains only the pages that the user selected,
437 // so ignore the page range and print all pages. 437 // so ignore the page range and print all pages.
438 settings->Remove(printing::kSettingPageRange, NULL); 438 settings->Remove(printing::kSettingPageRange, NULL);
439 RenderViewHost* rvh = web_ui_->tab_contents()->render_view_host(); 439 RenderViewHost* rvh = web_ui_->tab_contents()->render_view_host();
440 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings)); 440 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings));
441 } 441 }
442 initiator_tab->print_view_manager()->PrintPreviewDone();
442 } 443 }
443 444
444 void PrintPreviewHandler::HandlePrintToPdf( 445 void PrintPreviewHandler::HandlePrintToPdf(
445 const base::DictionaryValue& settings) { 446 const base::DictionaryValue& settings) {
446 if (print_to_pdf_path_.get()) { 447 if (print_to_pdf_path_.get()) {
447 // User has already selected a path, no need to show the dialog again. 448 // User has already selected a path, no need to show the dialog again.
448 PostPrintToPdfTask(); 449 PostPrintToPdfTask();
449 } else if (!select_file_dialog_.get() || !select_file_dialog_->IsRunning( 450 } else if (!select_file_dialog_.get() || !select_file_dialog_->IsRunning(
450 platform_util::GetTopLevel(preview_tab()->GetNativeView()))) { 451 platform_util::GetTopLevel(preview_tab()->GetNativeView()))) {
451 ReportUserActionHistogram(PRINT_TO_PDF); 452 ReportUserActionHistogram(PRINT_TO_PDF);
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 return; 855 return;
855 856
856 // We no longer require the initiator tab details. Remove those details 857 // We no longer require the initiator tab details. Remove those details
857 // associated with the preview tab to allow the initiator tab to create 858 // associated with the preview tab to allow the initiator tab to create
858 // another preview tab. 859 // another preview tab.
859 printing::PrintPreviewTabController* tab_controller = 860 printing::PrintPreviewTabController* tab_controller =
860 printing::PrintPreviewTabController::GetInstance(); 861 printing::PrintPreviewTabController::GetInstance();
861 if (tab_controller) 862 if (tab_controller)
862 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); 863 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper());
863 } 864 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/printing_message_filter.cc ('k') | chrome/browser/ui/webui/print_preview_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698