local_discovery_ui.cc revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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.
4
5#include "chrome/browser/ui/webui/local_discovery/local_discovery_ui.h"
6
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"
16
17namespace {
18
19content::WebUIDataSource* CreateLocalDiscoveryHTMLSource() {
20  content::WebUIDataSource* source =
21      content::WebUIDataSource::Create(chrome::kChromeUIDevicesHost);
22
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);
27
28  source->SetUseJsonJSFormatV2();
29  source->AddLocalizedString("serviceRegister",
30                             IDS_LOCAL_DISCOVERY_SERVICE_REGISTER);
31
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);
83
84
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
98
99  source->SetJsonPath("strings.js");
100
101  source->DisableDenyXFrameOptions();
102
103  return source;
104}
105
106}  // namespace
107
108LocalDiscoveryUI::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());
113
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());
118}
119
120void 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);
130}
131