local_discovery_ui.cc revision 58537e28ecd584eab876aee8be7156509866d23a
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::kChromeUIDevicesFrameHost);
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
65
66  source->SetJsonPath("strings.js");
67
68  source->DisableDenyXFrameOptions();
69
70  return source;
71}
72
73}  // namespace
74
75LocalDiscoveryUI::LocalDiscoveryUI(content::WebUI* web_ui)
76    : WebUIController(web_ui) {
77  // Set up the chrome://devices/ source.
78  Profile* profile = Profile::FromWebUI(web_ui);
79  content::WebUIDataSource::Add(profile, CreateLocalDiscoveryHTMLSource());
80
81  // TODO(gene): Use LocalDiscoveryUIHandler to send updated to the devices
82  // page. For example
83  web_ui->AddMessageHandler(local_discovery::LocalDiscoveryUIHandler::Create());
84  web_ui->AddMessageHandler(new MetricsHandler());
85}
86