local_discovery_ui.cc revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
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/url_constants.h"
11#include "content/public/browser/web_ui.h"
12#include "content/public/browser/web_ui_data_source.h"
13#include "grit/browser_resources.h"
14#include "grit/generated_resources.h"
15
16namespace {
17
18content::WebUIDataSource* CreateLocalDiscoveryHTMLSource() {
19  content::WebUIDataSource* source =
20      content::WebUIDataSource::Create(chrome::kChromeUIDevicesHost);
21
22  source->SetDefaultResource(IDR_LOCAL_DISCOVERY_HTML);
23  source->AddResourcePath("local_discovery.css", IDR_LOCAL_DISCOVERY_CSS);
24  source->AddResourcePath("local_discovery.js", IDR_LOCAL_DISCOVERY_JS);
25  source->AddResourcePath("printer.png", IDR_LOCAL_DISCOVERY_PRINTER_PNG);
26
27  source->SetUseJsonJSFormatV2();
28  source->AddLocalizedString("serviceRegister",
29                             IDS_LOCAL_DISCOVERY_SERVICE_REGISTER);
30
31  source->AddLocalizedString("registerConfirmMessage",
32                             IDS_LOCAL_DISCOVERY_REGISTER_CONFIRMATION);
33  source->AddLocalizedString("registerUser",
34                             IDS_LOCAL_DISCOVERY_REGISTER_USER);
35  source->AddLocalizedString("confirmRegistration",
36                             IDS_LOCAL_DISCOVERY_CONFIRM_REGISTRATION);
37  source->AddLocalizedString("addingPrinter",
38                             IDS_LOCAL_DISCOVERY_ADDING_PRINTER);
39  source->AddLocalizedString("addingError",
40                             IDS_LOCAL_DISCOVERY_ERROR_OCURRED);
41  source->AddLocalizedString("addingErrorMessage",
42                             IDS_LOCAL_DISCOVERY_ERROR_OCURRED_MESSAGE);
43  source->AddLocalizedString("addingMessage1",
44                             IDS_LOCAL_DISCOVERY_ADDING_PRINTER_MESSAGE1);
45  source->AddLocalizedString("addingMessage2",
46                             IDS_LOCAL_DISCOVERY_ADDING_PRINTER_MESSAGE2);
47  source->AddLocalizedString("devicesTitle",
48                             IDS_LOCAL_DISCOVERY_DEVICES_PAGE_TITLE);
49  source->AddLocalizedString("noDescription",
50                             IDS_LOCAL_DISCOVERY_NO_DESCRIPTION);
51  source->AddLocalizedString("printersOnNetworkZero",
52                             IDS_LOCAL_DISCOVERY_PRINTERS_ON_NETWORK_ZERO);
53  source->AddLocalizedString("printersOnNetworkOne",
54                             IDS_LOCAL_DISCOVERY_PRINTERS_ON_NETWORK_ONE);
55  source->AddLocalizedString("printersOnNetworkMultiple",
56                             IDS_LOCAL_DISCOVERY_PRINTERS_ON_NETWORK_MULTIPLE);
57  source->AddLocalizedString("cancel", IDS_CANCEL);
58  source->AddLocalizedString("ok", IDS_OK);
59  source->AddLocalizedString("loading", IDS_LOCAL_DISCOVERY_LOADING);
60  source->AddLocalizedString("addPrinters", IDS_LOCAL_DISCOVERY_ADD_PRINTERS);
61  source->AddLocalizedString(
62      "noPrintersOnNetworkExplanation",
63      IDS_LOCAL_DISCOVERY_NO_PRINTERS_ON_NETWORK_EXPLANATION);
64  source->AddLocalizedString("cloudDevicesUnavailable",
65                             IDS_LOCAL_DISCOVERY_CLOUD_DEVICES_UNAVAILABLE);
66  source->AddLocalizedString("retryLoadCloudDevices",
67                             IDS_LOCAL_DISCOVERY_RETRY_LOAD_CLOUD_DEVICES);
68  source->AddLocalizedString("cloudDevicesNeedLogin",
69                             IDS_LOCAL_DISCOVERY_CLOUD_DEVICES_NEED_LOGIN);
70  source->AddLocalizedString("cloudDevicesLogin",
71                             IDS_LOCAL_DISCOVERY_CLOUD_DEVICES_LOGIN);
72  source->AddLocalizedString("registerNeedLogin",
73                             IDS_LOCAL_DISCOVERY_REGISTER_NEED_LOGIN);
74
75  source->SetJsonPath("strings.js");
76
77  source->DisableDenyXFrameOptions();
78
79  return source;
80}
81
82}  // namespace
83
84LocalDiscoveryUI::LocalDiscoveryUI(content::WebUI* web_ui)
85    : WebUIController(web_ui) {
86  // Set up the chrome://devices/ source.
87  Profile* profile = Profile::FromWebUI(web_ui);
88  content::WebUIDataSource::Add(profile, CreateLocalDiscoveryHTMLSource());
89
90  // TODO(gene): Use LocalDiscoveryUIHandler to send updated to the devices
91  // page. For example
92  web_ui->AddMessageHandler(local_discovery::LocalDiscoveryUIHandler::Create());
93  web_ui->AddMessageHandler(new MetricsHandler());
94}
95