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

Side by Side Diff: chrome/browser/ui/webui/print_preview/print_preview_handler.cc

Issue 10535045: TabContentsWrapper -> TabContents, for printing code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/print_preview_handler.h" 5 #include "chrome/browser/ui/webui/print_preview/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 17 matching lines...) Expand all
28 #include "chrome/browser/prefs/pref_service.h" 28 #include "chrome/browser/prefs/pref_service.h"
29 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" 29 #include "chrome/browser/printing/cloud_print/cloud_print_url.h"
30 #include "chrome/browser/printing/print_dialog_cloud.h" 30 #include "chrome/browser/printing/print_dialog_cloud.h"
31 #include "chrome/browser/printing/print_error_dialog.h" 31 #include "chrome/browser/printing/print_error_dialog.h"
32 #include "chrome/browser/printing/print_job_manager.h" 32 #include "chrome/browser/printing/print_job_manager.h"
33 #include "chrome/browser/printing/print_preview_tab_controller.h" 33 #include "chrome/browser/printing/print_preview_tab_controller.h"
34 #include "chrome/browser/printing/print_system_task_proxy.h" 34 #include "chrome/browser/printing/print_system_task_proxy.h"
35 #include "chrome/browser/printing/print_view_manager.h" 35 #include "chrome/browser/printing/print_view_manager.h"
36 #include "chrome/browser/printing/printer_manager_dialog.h" 36 #include "chrome/browser/printing/printer_manager_dialog.h"
37 #include "chrome/browser/profiles/profile.h" 37 #include "chrome/browser/profiles/profile.h"
38 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 38 #include "chrome/browser/ui/tab_contents/tab_contents.h"
39 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" 39 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
40 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h" 40 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h"
41 #include "chrome/common/chrome_paths.h" 41 #include "chrome/common/chrome_paths.h"
42 #include "chrome/common/pref_names.h" 42 #include "chrome/common/pref_names.h"
43 #include "chrome/common/print_messages.h" 43 #include "chrome/common/print_messages.h"
44 #include "content/public/browser/browser_thread.h" 44 #include "content/public/browser/browser_thread.h"
45 #include "content/public/browser/navigation_controller.h" 45 #include "content/public/browser/navigation_controller.h"
46 #include "content/public/browser/navigation_entry.h" 46 #include "content/public/browser/navigation_entry.h"
47 #include "content/public/browser/render_view_host.h" 47 #include "content/public/browser/render_view_host.h"
48 #include "content/public/browser/web_contents.h" 48 #include "content/public/browser/web_contents.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 base::Bind(&PrintPreviewHandler::HandleSaveLastPrinter, 274 base::Bind(&PrintPreviewHandler::HandleSaveLastPrinter,
275 base::Unretained(this))); 275 base::Unretained(this)));
276 web_ui()->RegisterMessageCallback("getInitialSettings", 276 web_ui()->RegisterMessageCallback("getInitialSettings",
277 base::Bind(&PrintPreviewHandler::HandleGetInitialSettings, 277 base::Bind(&PrintPreviewHandler::HandleGetInitialSettings,
278 base::Unretained(this))); 278 base::Unretained(this)));
279 web_ui()->RegisterMessageCallback("reportDestinationEvent", 279 web_ui()->RegisterMessageCallback("reportDestinationEvent",
280 base::Bind(&PrintPreviewHandler::HandleReportDestinationEvent, 280 base::Bind(&PrintPreviewHandler::HandleReportDestinationEvent,
281 base::Unretained(this))); 281 base::Unretained(this)));
282 } 282 }
283 283
284 TabContentsWrapper* PrintPreviewHandler::preview_tab_wrapper() const { 284 TabContents* PrintPreviewHandler::preview_tab_contents() const {
285 return TabContentsWrapper::GetCurrentWrapperForContents(preview_tab()); 285 return TabContents::GetCurrentWrapperForContents(preview_web_contents());
286 } 286 }
287 287
288 WebContents* PrintPreviewHandler::preview_tab() const { 288 WebContents* PrintPreviewHandler::preview_web_contents() const {
289 return web_ui()->GetWebContents(); 289 return web_ui()->GetWebContents();
290 } 290 }
291 291
292 void PrintPreviewHandler::HandleGetPrinters(const ListValue* /*args*/) { 292 void PrintPreviewHandler::HandleGetPrinters(const ListValue* /*args*/) {
293 scoped_refptr<PrintSystemTaskProxy> task = 293 scoped_refptr<PrintSystemTaskProxy> task =
294 new PrintSystemTaskProxy(AsWeakPtr(), 294 new PrintSystemTaskProxy(AsWeakPtr(),
295 print_backend_.get(), 295 print_backend_.get(),
296 has_logged_printers_count_); 296 has_logged_printers_count_);
297 has_logged_printers_count_ = true; 297 has_logged_printers_count_ = true;
298 298
(...skipping 16 matching lines...) Expand all
315 print_preview_ui->OnPrintPreviewRequest(request_id); 315 print_preview_ui->OnPrintPreviewRequest(request_id);
316 // Add an additional key in order to identify |print_preview_ui| later on 316 // Add an additional key in order to identify |print_preview_ui| later on
317 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO 317 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO
318 // thread. 318 // thread.
319 settings->SetString(printing::kPreviewUIAddr, 319 settings->SetString(printing::kPreviewUIAddr,
320 print_preview_ui->GetPrintPreviewUIAddress()); 320 print_preview_ui->GetPrintPreviewUIAddress());
321 321
322 // Increment request count. 322 // Increment request count.
323 ++regenerate_preview_request_count_; 323 ++regenerate_preview_request_count_;
324 324
325 TabContentsWrapper* initiator_tab = GetInitiatorTab(); 325 TabContents* initiator_tab = GetInitiatorTab();
326 if (!initiator_tab) { 326 if (!initiator_tab) {
327 ReportUserActionHistogram(INITIATOR_TAB_CLOSED); 327 ReportUserActionHistogram(INITIATOR_TAB_CLOSED);
328 print_preview_ui->OnClosePrintPreviewTab(); 328 print_preview_ui->OnClosePrintPreviewTab();
329 return; 329 return;
330 } 330 }
331 331
332 // Retrieve the page title and url and send it to the renderer process if 332 // Retrieve the page title and url and send it to the renderer process if
333 // headers and footers are to be displayed. 333 // headers and footers are to be displayed.
334 bool display_header_footer = false; 334 bool display_header_footer = false;
335 if (!settings->GetBoolean(printing::kSettingHeaderFooterEnabled, 335 if (!settings->GetBoolean(printing::kSettingHeaderFooterEnabled,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 } 374 }
375 375
376 void PrintPreviewHandler::HandlePrint(const ListValue* args) { 376 void PrintPreviewHandler::HandlePrint(const ListValue* args) {
377 ReportStats(); 377 ReportStats();
378 378
379 // Record the number of times the user requests to regenerate preview data 379 // Record the number of times the user requests to regenerate preview data
380 // before printing. 380 // before printing.
381 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", 381 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint",
382 regenerate_preview_request_count_); 382 regenerate_preview_request_count_);
383 383
384 TabContentsWrapper* initiator_tab = GetInitiatorTab(); 384 TabContents* initiator_tab = GetInitiatorTab();
385 if (initiator_tab) { 385 if (initiator_tab) {
386 RenderViewHost* rvh = initiator_tab->web_contents()->GetRenderViewHost(); 386 RenderViewHost* rvh = initiator_tab->web_contents()->GetRenderViewHost();
387 rvh->Send(new PrintMsg_ResetScriptedPrintCount(rvh->GetRoutingID())); 387 rvh->Send(new PrintMsg_ResetScriptedPrintCount(rvh->GetRoutingID()));
388 } 388 }
389 389
390 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); 390 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args));
391 if (!settings.get()) 391 if (!settings.get())
392 return; 392 return;
393 393
394 // Storing last used settings. 394 // Storing last used settings.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 432 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
433 web_ui()->GetController()); 433 web_ui()->GetController());
434 print_preview_ui->OnHidePreviewTab(); 434 print_preview_ui->OnHidePreviewTab();
435 435
436 // Do this so the initiator tab can open a new print preview tab. 436 // Do this so the initiator tab can open a new print preview tab.
437 ClearInitiatorTabDetails(); 437 ClearInitiatorTabDetails();
438 438
439 // The PDF being printed contains only the pages that the user selected, 439 // The PDF being printed contains only the pages that the user selected,
440 // so ignore the page range and print all pages. 440 // so ignore the page range and print all pages.
441 settings->Remove(printing::kSettingPageRange, NULL); 441 settings->Remove(printing::kSettingPageRange, NULL);
442 RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost(); 442 RenderViewHost* rvh = preview_web_contents()->GetRenderViewHost();
443 rvh->Send( 443 rvh->Send(
444 new PrintMsg_PrintForPrintPreview(rvh->GetRoutingID(), *settings)); 444 new PrintMsg_PrintForPrintPreview(rvh->GetRoutingID(), *settings));
445 445
446 // For all other cases above, the tab will stay open until the printing has 446 // For all other cases above, the tab will stay open until the printing has
447 // finished. Then the tab closes and PrintPreviewDone() gets called. Here, 447 // finished. Then the tab closes and PrintPreviewDone() gets called. Here,
448 // since we are hiding the tab, and not closing it, we need to make this 448 // since we are hiding the tab, and not closing it, we need to make this
449 // call. 449 // call.
450 if (initiator_tab) 450 if (initiator_tab)
451 initiator_tab->print_view_manager()->PrintPreviewDone(); 451 initiator_tab->print_view_manager()->PrintPreviewDone();
452 } 452 }
453 } 453 }
454 454
455 void PrintPreviewHandler::HandlePrintToPdf( 455 void PrintPreviewHandler::HandlePrintToPdf(
456 const base::DictionaryValue& settings) { 456 const base::DictionaryValue& settings) {
457 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 457 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
458 web_ui()->GetController()); 458 web_ui()->GetController());
459 if (print_to_pdf_path_.get()) { 459 if (print_to_pdf_path_.get()) {
460 // User has already selected a path, no need to show the dialog again. 460 // User has already selected a path, no need to show the dialog again.
461 scoped_refptr<base::RefCountedBytes> data; 461 scoped_refptr<base::RefCountedBytes> data;
462 print_preview_ui->GetPrintPreviewDataForIndex( 462 print_preview_ui->GetPrintPreviewDataForIndex(
463 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); 463 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data);
464 PostPrintToPdfTask(data); 464 PostPrintToPdfTask(data);
465 } else if (!select_file_dialog_.get() || !select_file_dialog_->IsRunning( 465 } else if (!select_file_dialog_.get() || !select_file_dialog_->IsRunning(
466 platform_util::GetTopLevel(preview_tab()->GetNativeView()))) { 466 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()))) {
467 ReportUserActionHistogram(PRINT_TO_PDF); 467 ReportUserActionHistogram(PRINT_TO_PDF);
468 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", 468 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF",
469 GetPageCountFromSettingsDictionary(settings)); 469 GetPageCountFromSettingsDictionary(settings));
470 470
471 // Pre-populating select file dialog with print job title. 471 // Pre-populating select file dialog with print job title.
472 string16 print_job_title_utf16 = print_preview_ui->initiator_tab_title(); 472 string16 print_job_title_utf16 = print_preview_ui->initiator_tab_title();
473 473
474 #if defined(OS_WIN) 474 #if defined(OS_WIN)
475 FilePath::StringType print_job_title(print_job_title_utf16); 475 FilePath::StringType print_job_title(print_job_title_utf16);
476 #elif defined(OS_POSIX) 476 #elif defined(OS_POSIX)
(...skipping 10 matching lines...) Expand all
487 } 487 }
488 488
489 void PrintPreviewHandler::HandleHidePreview(const ListValue* /*args*/) { 489 void PrintPreviewHandler::HandleHidePreview(const ListValue* /*args*/) {
490 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 490 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
491 web_ui()->GetController()); 491 web_ui()->GetController());
492 print_preview_ui->OnHidePreviewTab(); 492 print_preview_ui->OnHidePreviewTab();
493 } 493 }
494 494
495 void PrintPreviewHandler::HandleCancelPendingPrintRequest( 495 void PrintPreviewHandler::HandleCancelPendingPrintRequest(
496 const ListValue* /*args*/) { 496 const ListValue* /*args*/) {
497 TabContentsWrapper* initiator_tab = GetInitiatorTab(); 497 TabContents* initiator_tab = GetInitiatorTab();
498 if (initiator_tab) 498 if (initiator_tab)
499 ClearInitiatorTabDetails(); 499 ClearInitiatorTabDetails();
500 gfx::NativeWindow parent = initiator_tab ? 500 gfx::NativeWindow parent = initiator_tab ?
501 initiator_tab->web_contents()->GetView()->GetTopLevelNativeWindow() : 501 initiator_tab->web_contents()->GetView()->GetTopLevelNativeWindow() :
502 NULL; 502 NULL;
503 browser::ShowPrintErrorDialog(parent); 503 browser::ShowPrintErrorDialog(parent);
504 delete preview_tab_wrapper(); 504 delete preview_tab_contents();
505 } 505 }
506 506
507 void PrintPreviewHandler::HandleSaveLastPrinter(const ListValue* args) { 507 void PrintPreviewHandler::HandleSaveLastPrinter(const ListValue* args) {
508 std::string data_to_save; 508 std::string data_to_save;
509 if (args->GetString(0, &data_to_save) && !data_to_save.empty()) 509 if (args->GetString(0, &data_to_save) && !data_to_save.empty())
510 GetStickySettings()->StorePrinterName(data_to_save); 510 GetStickySettings()->StorePrinterName(data_to_save);
511 511
512 if (args->GetString(1, &data_to_save) && !data_to_save.empty()) 512 if (args->GetString(1, &data_to_save) && !data_to_save.empty())
513 GetStickySettings()->StoreCloudPrintData(data_to_save); 513 GetStickySettings()->StoreCloudPrintData(data_to_save);
514 } 514 }
(...skipping 21 matching lines...) Expand all
536 if (handler.get()) { 536 if (handler.get()) {
537 PrintPreviewUI* print_preview_ui = 537 PrintPreviewUI* print_preview_ui =
538 static_cast<PrintPreviewUI*>(handler->web_ui()->GetController()); 538 static_cast<PrintPreviewUI*>(handler->web_ui()->GetController());
539 if (print_preview_ui) 539 if (print_preview_ui)
540 print_preview_ui->OnReloadPrintersList(); 540 print_preview_ui->OnReloadPrintersList();
541 } 541 }
542 } 542 }
543 543
544 void PrintPreviewHandler::HandleSignin(const ListValue* /*args*/) { 544 void PrintPreviewHandler::HandleSignin(const ListValue* /*args*/) {
545 gfx::NativeWindow modal_parent = 545 gfx::NativeWindow modal_parent =
546 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(); 546 preview_web_contents()->GetView()->GetTopLevelNativeWindow();
547 print_dialog_cloud::CreateCloudPrintSigninDialog( 547 print_dialog_cloud::CreateCloudPrintSigninDialog(
548 web_ui()->GetWebContents()->GetBrowserContext(), 548 preview_web_contents()->GetBrowserContext(),
549 modal_parent, 549 modal_parent,
550 base::Bind(&PrintPreviewHandler::OnSigninComplete, AsWeakPtr())); 550 base::Bind(&PrintPreviewHandler::OnSigninComplete, AsWeakPtr()));
551 } 551 }
552 552
553 void PrintPreviewHandler::HandlePrintWithCloudPrint() { 553 void PrintPreviewHandler::HandlePrintWithCloudPrint() {
554 // Record the number of times the user asks to print via cloud print 554 // Record the number of times the user asks to print via cloud print
555 // instead of the print preview dialog. 555 // instead of the print preview dialog.
556 ReportStats(); 556 ReportStats();
557 557
558 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 558 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
559 web_ui()->GetController()); 559 web_ui()->GetController());
560 scoped_refptr<base::RefCountedBytes> data; 560 scoped_refptr<base::RefCountedBytes> data;
561 print_preview_ui->GetPrintPreviewDataForIndex( 561 print_preview_ui->GetPrintPreviewDataForIndex(
562 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); 562 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data);
563 if (!data.get()) { 563 if (!data.get()) {
564 NOTREACHED(); 564 NOTREACHED();
565 return; 565 return;
566 } 566 }
567 DCHECK_GT(data->size(), 0U); 567 DCHECK_GT(data->size(), 0U);
568 568
569 gfx::NativeWindow modal_parent = 569 gfx::NativeWindow modal_parent =
570 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(); 570 preview_web_contents()->GetView()->GetTopLevelNativeWindow();
571 print_dialog_cloud::CreatePrintDialogForBytes( 571 print_dialog_cloud::CreatePrintDialogForBytes(
572 web_ui()->GetWebContents()->GetBrowserContext(), 572 preview_web_contents()->GetBrowserContext(),
573 modal_parent, 573 modal_parent,
574 data, 574 data,
575 string16(print_preview_ui->initiator_tab_title()), 575 string16(print_preview_ui->initiator_tab_title()),
576 string16(), 576 string16(),
577 std::string("application/pdf")); 577 std::string("application/pdf"));
578 578
579 // Once the cloud print dialog comes up we're no longer in a background 579 // Once the cloud print dialog comes up we're no longer in a background
580 // printing situation. Close the print preview. 580 // printing situation. Close the print preview.
581 // TODO(abodenha@chromium.org) The flow should be changed as described in 581 // TODO(abodenha@chromium.org) The flow should be changed as described in
582 // http://code.google.com/p/chromium/issues/detail?id=44093 582 // http://code.google.com/p/chromium/issues/detail?id=44093
583 ActivateInitiatorTabAndClosePreviewTab(); 583 ActivateInitiatorTabAndClosePreviewTab();
584 } 584 }
585 585
586 void PrintPreviewHandler::HandleManageCloudPrint(const ListValue* /*args*/) { 586 void PrintPreviewHandler::HandleManageCloudPrint(const ListValue* /*args*/) {
587 ++manage_cloud_printers_dialog_request_count_; 587 ++manage_cloud_printers_dialog_request_count_;
588 Profile* profile = Profile::FromBrowserContext( 588 Profile* profile = Profile::FromBrowserContext(
589 web_ui()->GetWebContents()->GetBrowserContext()); 589 preview_web_contents()->GetBrowserContext());
590 web_ui()->GetWebContents()->OpenURL( 590 preview_web_contents()->OpenURL(
591 OpenURLParams( 591 OpenURLParams(
592 CloudPrintURL(profile).GetCloudPrintServiceManageURL(), 592 CloudPrintURL(profile).GetCloudPrintServiceManageURL(),
593 Referrer(), 593 Referrer(),
594 NEW_FOREGROUND_TAB, 594 NEW_FOREGROUND_TAB,
595 content::PAGE_TRANSITION_LINK, 595 content::PAGE_TRANSITION_LINK,
596 false)); 596 false));
597 } 597 }
598 598
599 void PrintPreviewHandler::HandleShowSystemDialog(const ListValue* /*args*/) { 599 void PrintPreviewHandler::HandleShowSystemDialog(const ListValue* /*args*/) {
600 ReportStats(); 600 ReportStats();
601 ReportUserActionHistogram(FALLBACK_TO_ADVANCED_SETTINGS_DIALOG); 601 ReportUserActionHistogram(FALLBACK_TO_ADVANCED_SETTINGS_DIALOG);
602 602
603 TabContentsWrapper* initiator_tab = GetInitiatorTab(); 603 TabContents* initiator_tab = GetInitiatorTab();
604 if (!initiator_tab) 604 if (!initiator_tab)
605 return; 605 return;
606 606
607 printing::PrintViewManager* manager = initiator_tab->print_view_manager(); 607 printing::PrintViewManager* manager = initiator_tab->print_view_manager();
608 manager->set_observer(this); 608 manager->set_observer(this);
609 manager->PrintForSystemDialogNow(); 609 manager->PrintForSystemDialogNow();
610 610
611 // Cancel the pending preview request if exists. 611 // Cancel the pending preview request if exists.
612 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 612 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
613 web_ui()->GetController()); 613 web_ui()->GetController());
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 initial_settings.SetBoolean(kPrintAutomaticallyInKioskMode, kiosk_mode); 704 initial_settings.SetBoolean(kPrintAutomaticallyInKioskMode, kiosk_mode);
705 705
706 if (print_preview_ui->source_is_modifiable()) { 706 if (print_preview_ui->source_is_modifiable()) {
707 GetStickySettings()->GetLastUsedMarginSettings(&initial_settings); 707 GetStickySettings()->GetLastUsedMarginSettings(&initial_settings);
708 GetNumberFormatAndMeasurementSystem(&initial_settings); 708 GetNumberFormatAndMeasurementSystem(&initial_settings);
709 } 709 }
710 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); 710 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings);
711 } 711 }
712 712
713 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { 713 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() {
714 TabContentsWrapper* initiator_tab = GetInitiatorTab(); 714 TabContents* initiator_tab = GetInitiatorTab();
715 if (initiator_tab) { 715 if (initiator_tab) {
716 WebContents* web_contents = initiator_tab->web_contents(); 716 WebContents* web_contents = initiator_tab->web_contents();
717 web_contents->GetDelegate()->ActivateContents(web_contents); 717 web_contents->GetDelegate()->ActivateContents(web_contents);
718 } 718 }
719 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 719 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
720 web_ui()->GetController()); 720 web_ui()->GetController());
721 print_preview_ui->OnClosePrintPreviewTab(); 721 print_preview_ui->OnClosePrintPreviewTab();
722 } 722 }
723 723
724 void PrintPreviewHandler::SendPrinterCapabilities( 724 void PrintPreviewHandler::SendPrinterCapabilities(
725 const DictionaryValue& settings_info) { 725 const DictionaryValue& settings_info) {
726 VLOG(1) << "Get printer capabilities finished"; 726 VLOG(1) << "Get printer capabilities finished";
727 web_ui()->CallJavascriptFunction("updateWithPrinterCapabilities", 727 web_ui()->CallJavascriptFunction("updateWithPrinterCapabilities",
728 settings_info); 728 settings_info);
729 } 729 }
730 730
731 void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) { 731 void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) {
732 SendCloudPrintEnabled(); 732 SendCloudPrintEnabled();
733 web_ui()->CallJavascriptFunction("setPrinters", printers); 733 web_ui()->CallJavascriptFunction("setPrinters", printers);
734 } 734 }
735 735
736 void PrintPreviewHandler::SendCloudPrintEnabled() { 736 void PrintPreviewHandler::SendCloudPrintEnabled() {
737 Profile* profile = Profile::FromBrowserContext( 737 Profile* profile = Profile::FromBrowserContext(
738 web_ui()->GetWebContents()->GetBrowserContext()); 738 preview_web_contents()->GetBrowserContext());
739 PrefService* prefs = profile->GetPrefs(); 739 PrefService* prefs = profile->GetPrefs();
740 if (prefs->GetBoolean(prefs::kCloudPrintSubmitEnabled)) { 740 if (prefs->GetBoolean(prefs::kCloudPrintSubmitEnabled)) {
741 GURL gcp_url(CloudPrintURL(profile).GetCloudPrintServiceURL()); 741 GURL gcp_url(CloudPrintURL(profile).GetCloudPrintServiceURL());
742 base::StringValue gcp_url_value(gcp_url.spec()); 742 base::StringValue gcp_url_value(gcp_url.spec());
743 web_ui()->CallJavascriptFunction("setUseCloudPrint", gcp_url_value); 743 web_ui()->CallJavascriptFunction("setUseCloudPrint", gcp_url_value);
744 } 744 }
745 } 745 }
746 746
747 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, 747 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings,
748 std::string print_ticket) { 748 std::string print_ticket) {
749 ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT); 749 ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT);
750 scoped_refptr<base::RefCountedBytes> data; 750 scoped_refptr<base::RefCountedBytes> data;
751 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 751 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
752 web_ui()->GetController()); 752 web_ui()->GetController());
753 print_preview_ui->GetPrintPreviewDataForIndex( 753 print_preview_ui->GetPrintPreviewDataForIndex(
754 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); 754 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data);
755 if (data.get() && data->size() > 0U && data->front()) { 755 if (data.get() && data->size() > 0U && data->front()) {
756 string16 print_job_title_utf16 = 756 string16 print_job_title_utf16 =
757 preview_tab_wrapper()->print_view_manager()->RenderSourceName(); 757 preview_tab_contents()->print_view_manager()->RenderSourceName();
758 std::string print_job_title = UTF16ToUTF8(print_job_title_utf16); 758 std::string print_job_title = UTF16ToUTF8(print_job_title_utf16);
759 std::string printer_id; 759 std::string printer_id;
760 settings.GetString(printing::kSettingCloudPrintId, &printer_id); 760 settings.GetString(printing::kSettingCloudPrintId, &printer_id);
761 // BASE64 encode the job data. 761 // BASE64 encode the job data.
762 std::string raw_data(reinterpret_cast<const char*>(data->front()), 762 std::string raw_data(reinterpret_cast<const char*>(data->front()),
763 data->size()); 763 data->size());
764 std::string base64_data; 764 std::string base64_data;
765 if (!base::Base64Encode(raw_data, &base64_data)) { 765 if (!base::Base64Encode(raw_data, &base64_data)) {
766 NOTREACHED() << "Base64 encoding PDF data."; 766 NOTREACHED() << "Base64 encoding PDF data.";
767 } 767 }
(...skipping 29 matching lines...) Expand all
797 boundary); 797 boundary);
798 798
799 StringValue data_value(final_data); 799 StringValue data_value(final_data);
800 800
801 web_ui()->CallJavascriptFunction("printToCloud", data_value); 801 web_ui()->CallJavascriptFunction("printToCloud", data_value);
802 } else { 802 } else {
803 NOTREACHED(); 803 NOTREACHED();
804 } 804 }
805 } 805 }
806 806
807 TabContentsWrapper* PrintPreviewHandler::GetInitiatorTab() const { 807 TabContents* PrintPreviewHandler::GetInitiatorTab() const {
808 printing::PrintPreviewTabController* tab_controller = 808 printing::PrintPreviewTabController* tab_controller =
809 printing::PrintPreviewTabController::GetInstance(); 809 printing::PrintPreviewTabController::GetInstance();
810 if (!tab_controller) 810 if (!tab_controller)
811 return NULL; 811 return NULL;
812 return tab_controller->GetInitiatorTab(preview_tab_wrapper()); 812 return tab_controller->GetInitiatorTab(preview_tab_contents());
813 } 813 }
814 814
815 void PrintPreviewHandler::OnPrintDialogShown() { 815 void PrintPreviewHandler::OnPrintDialogShown() {
816 ActivateInitiatorTabAndClosePreviewTab(); 816 ActivateInitiatorTabAndClosePreviewTab();
817 } 817 }
818 818
819 void PrintPreviewHandler::SelectFile(const FilePath& default_filename) { 819 void PrintPreviewHandler::SelectFile(const FilePath& default_filename) {
820 SelectFileDialog::FileTypeInfo file_type_info; 820 SelectFileDialog::FileTypeInfo file_type_info;
821 file_type_info.extensions.resize(1); 821 file_type_info.extensions.resize(1);
822 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pdf")); 822 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pdf"));
(...skipping 12 matching lines...) Expand all
835 if (!select_file_dialog_.get()) 835 if (!select_file_dialog_.get())
836 select_file_dialog_ = SelectFileDialog::Create(this); 836 select_file_dialog_ = SelectFileDialog::Create(this);
837 837
838 select_file_dialog_->SelectFile( 838 select_file_dialog_->SelectFile(
839 SelectFileDialog::SELECT_SAVEAS_FILE, 839 SelectFileDialog::SELECT_SAVEAS_FILE,
840 string16(), 840 string16(),
841 GetStickySettings()->save_path()->Append(default_filename), 841 GetStickySettings()->save_path()->Append(default_filename),
842 &file_type_info, 842 &file_type_info,
843 0, 843 0,
844 FILE_PATH_LITERAL(""), 844 FILE_PATH_LITERAL(""),
845 preview_tab(), 845 preview_web_contents(),
846 platform_util::GetTopLevel(preview_tab()->GetNativeView()), 846 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()),
847 NULL); 847 NULL);
848 } 848 }
849 849
850 void PrintPreviewHandler::OnTabDestroyed() { 850 void PrintPreviewHandler::OnTabDestroyed() {
851 TabContentsWrapper* initiator_tab = GetInitiatorTab(); 851 TabContents* initiator_tab = GetInitiatorTab();
852 if (!initiator_tab) 852 if (!initiator_tab)
853 return; 853 return;
854 854
855 initiator_tab->print_view_manager()->set_observer(NULL); 855 initiator_tab->print_view_manager()->set_observer(NULL);
856 } 856 }
857 857
858 void PrintPreviewHandler::OnPrintPreviewFailed() { 858 void PrintPreviewHandler::OnPrintPreviewFailed() {
859 if (reported_failed_preview_) 859 if (reported_failed_preview_)
860 return; 860 return;
861 reported_failed_preview_ = true; 861 reported_failed_preview_ = true;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 ActivateInitiatorTabAndClosePreviewTab(); 896 ActivateInitiatorTabAndClosePreviewTab();
897 } 897 }
898 898
899 void PrintPreviewHandler::FileSelectionCanceled(void* params) { 899 void PrintPreviewHandler::FileSelectionCanceled(void* params) {
900 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 900 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
901 web_ui()->GetController()); 901 web_ui()->GetController());
902 print_preview_ui->OnFileSelectionCancelled(); 902 print_preview_ui->OnFileSelectionCancelled();
903 } 903 }
904 904
905 void PrintPreviewHandler::ClearInitiatorTabDetails() { 905 void PrintPreviewHandler::ClearInitiatorTabDetails() {
906 TabContentsWrapper* initiator_tab = GetInitiatorTab(); 906 TabContents* initiator_tab = GetInitiatorTab();
907 if (!initiator_tab) 907 if (!initiator_tab)
908 return; 908 return;
909 909
910 // We no longer require the initiator tab details. Remove those details 910 // We no longer require the initiator tab details. Remove those details
911 // associated with the preview tab to allow the initiator tab to create 911 // associated with the preview tab to allow the initiator tab to create
912 // another preview tab. 912 // another preview tab.
913 printing::PrintPreviewTabController* tab_controller = 913 printing::PrintPreviewTabController* tab_controller =
914 printing::PrintPreviewTabController::GetInstance(); 914 printing::PrintPreviewTabController::GetInstance();
915 if (tab_controller) 915 if (tab_controller)
916 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); 916 tab_controller->EraseInitiatorTabInfo(preview_tab_contents());
917 } 917 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698