NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / webui / local_discovery / local_discovery_ui.cc
blob3383e18300a020ee357959c12948e87e6157d555
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h"
9 #include "chrome/browser/ui/webui/metrics_handler.h"
10 #include "chrome/common/pref_names.h"
11 #include "chrome/common/url_constants.h"
12 #include "content/public/browser/web_ui.h"
13 #include "content/public/browser/web_ui_data_source.h"
14 #include "grit/browser_resources.h"
15 #include "grit/generated_resources.h"
17 namespace {
19 content::WebUIDataSource* CreateLocalDiscoveryHTMLSource() {
20 content::WebUIDataSource* source =
21 content::WebUIDataSource::Create(chrome::kChromeUIDevicesHost);
23 source->SetDefaultResource(IDR_LOCAL_DISCOVERY_HTML);
24 source->AddResourcePath("local_discovery.css", IDR_LOCAL_DISCOVERY_CSS);
25 source->AddResourcePath("local_discovery.js", IDR_LOCAL_DISCOVERY_JS);
26 source->AddResourcePath("printer.png", IDR_LOCAL_DISCOVERY_PRINTER_PNG);
28 source->SetUseJsonJSFormatV2();
29 source->AddLocalizedString("serviceRegister",
30 IDS_LOCAL_DISCOVERY_SERVICE_REGISTER);
32 source->AddLocalizedString("registerConfirmMessage",
33 IDS_LOCAL_DISCOVERY_REGISTER_CONFIRMATION);
34 source->AddLocalizedString("registerUser",
35 IDS_LOCAL_DISCOVERY_REGISTER_USER);
36 source->AddLocalizedString("confirmRegistration",
37 IDS_LOCAL_DISCOVERY_CONFIRM_REGISTRATION);
38 source->AddLocalizedString("addingPrinter",
39 IDS_LOCAL_DISCOVERY_ADDING_PRINTER);
40 source->AddLocalizedString("addingError",
41 IDS_LOCAL_DISCOVERY_ERROR_OCURRED);
42 source->AddLocalizedString("addingErrorMessage",
43 IDS_LOCAL_DISCOVERY_ERROR_OCURRED_MESSAGE);
44 source->AddLocalizedString("addingCanceledMessage",
45 IDS_LOCAL_DISCOVERY_REGISTER_CANCELED_ON_PRINTER);
46 source->AddLocalizedString("addingTimeoutMessage",
47 IDS_LOCAL_DISCOVERY_REGISTER_TIMEOUT_ON_PRINTER);
48 source->AddLocalizedString("addingMessage1",
49 IDS_LOCAL_DISCOVERY_ADDING_PRINTER_MESSAGE1);
50 source->AddLocalizedString("addingMessage2",
51 IDS_LOCAL_DISCOVERY_ADDING_PRINTER_MESSAGE2);
52 source->AddLocalizedString("devicesTitle",
53 IDS_LOCAL_DISCOVERY_DEVICES_PAGE_TITLE);
54 source->AddLocalizedString("noDescription",
55 IDS_LOCAL_DISCOVERY_NO_DESCRIPTION);
56 source->AddLocalizedString("printersOnNetworkZero",
57 IDS_LOCAL_DISCOVERY_PRINTERS_ON_NETWORK_ZERO);
58 source->AddLocalizedString("printersOnNetworkOne",
59 IDS_LOCAL_DISCOVERY_PRINTERS_ON_NETWORK_ONE);
60 source->AddLocalizedString("printersOnNetworkMultiple",
61 IDS_LOCAL_DISCOVERY_PRINTERS_ON_NETWORK_MULTIPLE);
62 source->AddLocalizedString("cancel", IDS_CANCEL);
63 source->AddLocalizedString("ok", IDS_OK);
64 source->AddLocalizedString("loading", IDS_LOCAL_DISCOVERY_LOADING);
65 source->AddLocalizedString("addPrinters", IDS_LOCAL_DISCOVERY_ADD_PRINTERS);
66 source->AddLocalizedString(
67 "noPrintersOnNetworkExplanation",
68 IDS_LOCAL_DISCOVERY_NO_PRINTERS_ON_NETWORK_EXPLANATION);
69 source->AddLocalizedString("cloudDevicesUnavailable",
70 IDS_LOCAL_DISCOVERY_CLOUD_DEVICES_UNAVAILABLE);
71 source->AddLocalizedString("retryLoadCloudDevices",
72 IDS_LOCAL_DISCOVERY_RETRY_LOAD_CLOUD_DEVICES);
73 source->AddLocalizedString("cloudDevicesNeedLogin",
74 IDS_LOCAL_DISCOVERY_CLOUD_DEVICES_NEED_LOGIN);
75 source->AddLocalizedString("cloudDevicesLogin",
76 IDS_LOCAL_DISCOVERY_CLOUD_DEVICES_LOGIN);
77 source->AddLocalizedString("registerNeedLogin",
78 IDS_LOCAL_DISCOVERY_REGISTER_NEED_LOGIN);
79 source->AddLocalizedString("availableDevicesTitle",
80 IDS_LOCAL_DISCOVERY_AVAILABLE_DEVICES);
81 source->AddLocalizedString("myDevicesTitle",
82 IDS_LOCAL_DISCOVERY_MY_DEVICES);
85 // Cloud print connector-related strings.
86 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
87 source->AddLocalizedString("cloudPrintConnectorEnablingButton",
88 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLING_BUTTON);
89 source->AddLocalizedString("cloudPrintConnectorDisabledButton",
90 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_BUTTON);
91 source->AddLocalizedString("cloudPrintConnectorEnabledButton",
92 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_BUTTON);
93 source->AddLocalizedString("cloudPrintName",
94 IDS_GOOGLE_CLOUD_PRINT);
95 source->AddLocalizedString("titleConnector",
96 IDS_LOCAL_DISCOVERY_CONNECTOR_SECTION);
97 #endif
99 source->SetJsonPath("strings.js");
101 source->DisableDenyXFrameOptions();
103 return source;
106 } // namespace
108 LocalDiscoveryUI::LocalDiscoveryUI(content::WebUI* web_ui)
109 : WebUIController(web_ui) {
110 // Set up the chrome://devices/ source.
111 Profile* profile = Profile::FromWebUI(web_ui);
112 content::WebUIDataSource::Add(profile, CreateLocalDiscoveryHTMLSource());
114 // TODO(gene): Use LocalDiscoveryUIHandler to send updated to the devices
115 // page. For example
116 web_ui->AddMessageHandler(new local_discovery::LocalDiscoveryUIHandler());
117 web_ui->AddMessageHandler(new MetricsHandler());
120 void LocalDiscoveryUI::RegisterProfilePrefs(
121 user_prefs::PrefRegistrySyncable* registry) {
122 registry->RegisterBooleanPref(
123 prefs::kLocalDiscoveryNotificationsEnabled,
124 #if defined(OS_WIN)
125 false,
126 #else
127 true,
128 #endif
129 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);