Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / local_discovery / local_discovery_ui.cc
blobeda0cdc0bd84cb10464e80e5485dabcf4aa7d2eb
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/browser.h"
9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h"
11 #include "chrome/browser/ui/webui/metrics_handler.h"
12 #include "chrome/common/pref_names.h"
13 #include "chrome/common/url_constants.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_ui.h"
17 #include "content/public/browser/web_ui_data_source.h"
18 #include "grit/browser_resources.h"
20 namespace {
22 content::WebUIDataSource* CreateLocalDiscoveryHTMLSource() {
23 content::WebUIDataSource* source =
24 content::WebUIDataSource::Create(chrome::kChromeUIDevicesHost);
26 source->SetDefaultResource(IDR_LOCAL_DISCOVERY_HTML);
27 source->AddResourcePath("local_discovery.css", IDR_LOCAL_DISCOVERY_CSS);
28 source->AddResourcePath("local_discovery.js", IDR_LOCAL_DISCOVERY_JS);
29 source->AddResourcePath("device.png", IDR_LOCAL_DISCOVERY_DEVICE_PNG);
30 source->AddResourcePath("printer.png", IDR_LOCAL_DISCOVERY_PRINTER_PNG);
32 source->AddLocalizedString("serviceRegister",
33 IDS_LOCAL_DISCOVERY_SERVICE_REGISTER);
34 source->AddLocalizedString("manageDevice", IDS_LOCAL_DISCOVERY_MANAGE_DEVICE);
36 source->AddLocalizedString("registerPrinterConfirmMessage",
37 IDS_LOCAL_DISCOVERY_REGISTER_PRINTER_CONFIRMATION);
38 source->AddLocalizedString("registerDeviceConfirmMessage",
39 IDS_LOCAL_DISCOVERY_REGISTER_DEVICE_CONFIRMATION);
40 source->AddLocalizedString("registerUser",
41 IDS_LOCAL_DISCOVERY_REGISTER_USER);
42 source->AddLocalizedString("confirmRegistration",
43 IDS_LOCAL_DISCOVERY_CONFIRM_REGISTRATION);
44 source->AddLocalizedString("addingPrinter",
45 IDS_LOCAL_DISCOVERY_ADDING_PRINTER);
46 source->AddLocalizedString("addingDevice", IDS_LOCAL_DISCOVERY_ADDING_DEVICE);
47 source->AddLocalizedString("addingError",
48 IDS_LOCAL_DISCOVERY_ERROR_OCURRED);
49 source->AddLocalizedString("addingErrorMessage",
50 IDS_LOCAL_DISCOVERY_ERROR_OCURRED_MESSAGE);
51 source->AddLocalizedString("addingCanceledMessage",
52 IDS_LOCAL_DISCOVERY_REGISTER_CANCELED_ON_PRINTER);
53 source->AddLocalizedString("addingTimeoutMessage",
54 IDS_LOCAL_DISCOVERY_REGISTER_TIMEOUT_ON_PRINTER);
55 source->AddLocalizedString("addingPrinterMessage1",
56 IDS_LOCAL_DISCOVERY_ADDING_PRINTER_MESSAGE1);
57 source->AddLocalizedString("addingPrinterMessage2",
58 IDS_LOCAL_DISCOVERY_ADDING_PRINTER_MESSAGE2);
59 source->AddLocalizedString("addingDeviceMessage1",
60 IDS_LOCAL_DISCOVERY_ADDING_DEVICE_MESSAGE1);
61 source->AddLocalizedString("addingDeviceConfirmCodeMessage",
62 IDS_LOCAL_DISCOVERY_CONFIRM_CODE_MESSAGE);
63 source->AddLocalizedString("confirmCode", IDS_LOCAL_DISCOVERY_CONFIRM_CODE);
64 source->AddLocalizedString("devicesTitle",
65 IDS_LOCAL_DISCOVERY_DEVICES_PAGE_TITLE);
66 source->AddLocalizedString("noDescriptionDevice",
67 IDS_LOCAL_DISCOVERY_NO_DESCRIPTION_DEVICE);
68 source->AddLocalizedString("noDescriptionPrinter",
69 IDS_LOCAL_DISCOVERY_NO_DESCRIPTION_PRINTER);
70 source->AddLocalizedString("printersOnNetworkZero",
71 IDS_LOCAL_DISCOVERY_PRINTERS_ON_NETWORK_ZERO);
72 source->AddLocalizedString("printersOnNetworkOne",
73 IDS_LOCAL_DISCOVERY_PRINTERS_ON_NETWORK_ONE);
74 source->AddLocalizedString("printersOnNetworkMultiple",
75 IDS_LOCAL_DISCOVERY_PRINTERS_ON_NETWORK_MULTIPLE);
76 source->AddLocalizedString("cancel", IDS_CANCEL);
77 source->AddLocalizedString("ok", IDS_OK);
78 source->AddLocalizedString("loading", IDS_LOCAL_DISCOVERY_LOADING);
79 source->AddLocalizedString("addPrinters", IDS_LOCAL_DISCOVERY_ADD_PRINTERS);
80 source->AddLocalizedString(
81 "noPrintersOnNetworkExplanation",
82 IDS_LOCAL_DISCOVERY_NO_PRINTERS_ON_NETWORK_EXPLANATION);
83 source->AddLocalizedString("cloudDevicesUnavailable",
84 IDS_LOCAL_DISCOVERY_CLOUD_DEVICES_UNAVAILABLE);
85 source->AddLocalizedString("retryLoadCloudDevices",
86 IDS_LOCAL_DISCOVERY_RETRY_LOAD_CLOUD_DEVICES);
87 source->AddLocalizedString("cloudDevicesNeedLogin",
88 IDS_LOCAL_DISCOVERY_CLOUD_DEVICES_NEED_LOGIN);
89 source->AddLocalizedString("cloudDevicesLogin",
90 IDS_LOCAL_DISCOVERY_CLOUD_DEVICES_LOGIN);
91 source->AddLocalizedString("registerNeedLogin",
92 IDS_LOCAL_DISCOVERY_REGISTER_NEED_LOGIN);
93 source->AddLocalizedString("availableDevicesTitle",
94 IDS_LOCAL_DISCOVERY_AVAILABLE_DEVICES);
95 source->AddLocalizedString("myDevicesTitle",
96 IDS_LOCAL_DISCOVERY_MY_DEVICES);
97 source->AddLocalizedString("backButton", IDS_SETTINGS_TITLE);
99 // Cloud print connector-related strings.
100 #if defined(ENABLE_PRINT_PREVIEW) && !defined(OS_CHROMEOS)
101 source->AddLocalizedString("cloudPrintConnectorEnablingButton",
102 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLING_BUTTON);
103 source->AddLocalizedString("cloudPrintConnectorDisabledButton",
104 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_DISABLED_BUTTON);
105 source->AddLocalizedString("cloudPrintConnectorEnabledButton",
106 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_BUTTON);
107 source->AddLocalizedString("cloudPrintName",
108 IDS_GOOGLE_CLOUD_PRINT);
109 source->AddLocalizedString("titleConnector",
110 IDS_LOCAL_DISCOVERY_CONNECTOR_SECTION);
111 #endif
113 source->SetJsonPath("strings.js");
115 source->DisableDenyXFrameOptions();
117 return source;
120 } // namespace
122 LocalDiscoveryUI::LocalDiscoveryUI(content::WebUI* web_ui)
123 : WebUIController(web_ui) {
124 // Set up the chrome://devices/ source.
125 content::WebUIDataSource* source = CreateLocalDiscoveryHTMLSource();
126 Browser* browser =
127 chrome::FindBrowserWithWebContents(web_ui->GetWebContents());
128 // Show a back button pointing to Settings if the browser has no location bar.
129 if (browser && browser->is_trusted_source())
130 source->AddString("backButtonURL", chrome::kChromeUISettingsURL);
131 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
133 // TODO(gene): Use LocalDiscoveryUIHandler to send updated to the devices
134 // page. For example
135 web_ui->AddMessageHandler(new local_discovery::LocalDiscoveryUIHandler());
136 web_ui->AddMessageHandler(new MetricsHandler());
139 void LocalDiscoveryUI::RegisterProfilePrefs(
140 user_prefs::PrefRegistrySyncable* registry) {
141 registry->RegisterBooleanPref(
142 prefs::kLocalDiscoveryNotificationsEnabled,
143 #if defined(OS_WIN)
144 false,
145 #else
146 true,
147 #endif
148 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);