| OLD | NEW |
| 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 <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 web_ui()->RegisterMessageCallback("stopGetPrivetPrinters", | 630 web_ui()->RegisterMessageCallback("stopGetPrivetPrinters", |
| 631 base::Bind(&PrintPreviewHandler::HandleStopGetPrivetPrinters, | 631 base::Bind(&PrintPreviewHandler::HandleStopGetPrivetPrinters, |
| 632 base::Unretained(this))); | 632 base::Unretained(this))); |
| 633 web_ui()->RegisterMessageCallback("getPrivetPrinterCapabilities", | 633 web_ui()->RegisterMessageCallback("getPrivetPrinterCapabilities", |
| 634 base::Bind(&PrintPreviewHandler::HandleGetPrivetPrinterCapabilities, | 634 base::Bind(&PrintPreviewHandler::HandleGetPrivetPrinterCapabilities, |
| 635 base::Unretained(this))); | 635 base::Unretained(this))); |
| 636 } | 636 } |
| 637 | 637 |
| 638 bool PrintPreviewHandler::PrivetPrintingEnabled() { | 638 bool PrintPreviewHandler::PrivetPrintingEnabled() { |
| 639 #if defined(ENABLE_SERVICE_DISCOVERY) | 639 #if defined(ENABLE_SERVICE_DISCOVERY) |
| 640 return !CommandLine::ForCurrentProcess()->HasSwitch( | 640 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 641 switches::kDisableDeviceDiscovery); | 641 switches::kDisableDeviceDiscovery); |
| 642 #else | 642 #else |
| 643 return false; | 643 return false; |
| 644 #endif | 644 #endif |
| 645 } | 645 } |
| 646 | 646 |
| 647 WebContents* PrintPreviewHandler::preview_web_contents() const { | 647 WebContents* PrintPreviewHandler::preview_web_contents() const { |
| 648 return web_ui()->GetWebContents(); | 648 return web_ui()->GetWebContents(); |
| 649 } | 649 } |
| 650 | 650 |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1184 initial_settings.SetBoolean(printing::kSettingPreviewModifiable, | 1184 initial_settings.SetBoolean(printing::kSettingPreviewModifiable, |
| 1185 print_preview_ui->source_is_modifiable()); | 1185 print_preview_ui->source_is_modifiable()); |
| 1186 initial_settings.SetString(printing::kSettingPrinterName, default_printer); | 1186 initial_settings.SetString(printing::kSettingPrinterName, default_printer); |
| 1187 initial_settings.SetBoolean(kDocumentHasSelection, | 1187 initial_settings.SetBoolean(kDocumentHasSelection, |
| 1188 print_preview_ui->source_has_selection()); | 1188 print_preview_ui->source_has_selection()); |
| 1189 initial_settings.SetBoolean(printing::kSettingShouldPrintSelectionOnly, | 1189 initial_settings.SetBoolean(printing::kSettingShouldPrintSelectionOnly, |
| 1190 print_preview_ui->print_selection_only()); | 1190 print_preview_ui->print_selection_only()); |
| 1191 printing::StickySettings* sticky_settings = GetStickySettings(); | 1191 printing::StickySettings* sticky_settings = GetStickySettings(); |
| 1192 sticky_settings->RestoreFromPrefs(Profile::FromBrowserContext( | 1192 sticky_settings->RestoreFromPrefs(Profile::FromBrowserContext( |
| 1193 preview_web_contents()->GetBrowserContext())->GetPrefs()); | 1193 preview_web_contents()->GetBrowserContext())->GetPrefs()); |
| 1194 if (sticky_settings->printer_app_state()) | 1194 if (sticky_settings->printer_app_state()) { |
| 1195 initial_settings.SetString(kAppState, | 1195 initial_settings.SetString(kAppState, |
| 1196 *sticky_settings->printer_app_state()); | 1196 *sticky_settings->printer_app_state()); |
| 1197 } |
| 1197 | 1198 |
| 1198 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 1199 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
| 1199 initial_settings.SetBoolean(kPrintAutomaticallyInKioskMode, | 1200 initial_settings.SetBoolean(kPrintAutomaticallyInKioskMode, |
| 1200 cmdline->HasSwitch(switches::kKioskModePrinting)); | 1201 cmdline->HasSwitch(switches::kKioskModePrinting)); |
| 1201 #if defined(OS_WIN) | 1202 #if defined(OS_WIN) |
| 1202 // In Win8 metro, the system print dialog can only open on the desktop. Doing | 1203 // In Win8 metro, the system print dialog can only open on the desktop. Doing |
| 1203 // so will cause the browser to appear hung, so we don't show the link in | 1204 // so will cause the browser to appear hung, so we don't show the link in |
| 1204 // metro. | 1205 // metro. |
| 1205 bool is_ash = (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH); | 1206 bool is_ash = (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH); |
| 1206 initial_settings.SetBoolean(kHidePrintWithSystemDialogLink, is_ash); | 1207 initial_settings.SetBoolean(kHidePrintWithSystemDialogLink, is_ash); |
| 1207 #endif | 1208 #endif |
| 1208 | 1209 |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 cups_printer_color_models_->bw_model); | 1454 cups_printer_color_models_->bw_model); |
| 1454 } | 1455 } |
| 1455 return; | 1456 return; |
| 1456 } | 1457 } |
| 1457 | 1458 |
| 1458 printing::ColorModel color_model = cups_printer_color_models_->color_model; | 1459 printing::ColorModel color_model = cups_printer_color_models_->color_model; |
| 1459 if (color_model != printing::UNKNOWN_COLOR_MODEL) | 1460 if (color_model != printing::UNKNOWN_COLOR_MODEL) |
| 1460 settings->SetInteger(printing::kSettingColor, color_model); | 1461 settings->SetInteger(printing::kSettingColor, color_model); |
| 1461 } | 1462 } |
| 1462 | 1463 |
| 1463 #endif | 1464 #endif // defined(USE_CUPS) |
| 1464 | 1465 |
| 1465 #if defined(ENABLE_SERVICE_DISCOVERY) | 1466 #if defined(ENABLE_SERVICE_DISCOVERY) |
| 1466 void PrintPreviewHandler::LocalPrinterChanged( | 1467 void PrintPreviewHandler::LocalPrinterChanged( |
| 1467 bool added, | 1468 bool added, |
| 1468 const std::string& name, | 1469 const std::string& name, |
| 1469 bool has_local_printing, | 1470 bool has_local_printing, |
| 1470 const local_discovery::DeviceDescription& description) { | 1471 const local_discovery::DeviceDescription& description) { |
| 1471 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1472 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 1472 if (has_local_printing || | 1473 if (has_local_printing || |
| 1473 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)) { | 1474 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)) { |
| 1474 base::DictionaryValue info; | 1475 base::DictionaryValue info; |
| 1475 FillPrinterDescription(name, description, has_local_printing, &info); | 1476 FillPrinterDescription(name, description, has_local_printing, &info); |
| 1476 web_ui()->CallJavascriptFunction("onPrivetPrinterChanged", info); | 1477 web_ui()->CallJavascriptFunction("onPrivetPrinterChanged", info); |
| 1477 } | 1478 } |
| 1478 } | 1479 } |
| 1479 | 1480 |
| 1480 void PrintPreviewHandler::LocalPrinterRemoved(const std::string& name) { | 1481 void PrintPreviewHandler::LocalPrinterRemoved(const std::string& name) { |
| 1481 } | 1482 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1642 int http_code) { | 1643 int http_code) { |
| 1643 base::FundamentalValue http_code_value(http_code); | 1644 base::FundamentalValue http_code_value(http_code); |
| 1644 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); | 1645 web_ui()->CallJavascriptFunction("onPrivetPrintFailed", http_code_value); |
| 1645 } | 1646 } |
| 1646 | 1647 |
| 1647 void PrintPreviewHandler::FillPrinterDescription( | 1648 void PrintPreviewHandler::FillPrinterDescription( |
| 1648 const std::string& name, | 1649 const std::string& name, |
| 1649 const local_discovery::DeviceDescription& description, | 1650 const local_discovery::DeviceDescription& description, |
| 1650 bool has_local_printing, | 1651 bool has_local_printing, |
| 1651 base::DictionaryValue* printer_value) { | 1652 base::DictionaryValue* printer_value) { |
| 1652 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1653 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 1653 | 1654 |
| 1654 printer_value->SetString("serviceName", name); | 1655 printer_value->SetString("serviceName", name); |
| 1655 printer_value->SetString("name", description.name); | 1656 printer_value->SetString("name", description.name); |
| 1656 printer_value->SetBoolean("hasLocalPrinting", has_local_printing); | 1657 printer_value->SetBoolean("hasLocalPrinting", has_local_printing); |
| 1657 printer_value->SetBoolean( | 1658 printer_value->SetBoolean( |
| 1658 "isUnregistered", | 1659 "isUnregistered", |
| 1659 description.id.empty() && | 1660 description.id.empty() && |
| 1660 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)); | 1661 command_line->HasSwitch(switches::kEnablePrintPreviewRegisterPromos)); |
| 1661 printer_value->SetString("cloudID", description.id); | 1662 printer_value->SetString("cloudID", description.id); |
| 1662 } | 1663 } |
| 1663 | 1664 |
| 1664 #endif | 1665 #endif // defined(ENABLE_SERVICE_DISCOVERY) |
| OLD | NEW |