Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1126)

Side by Side Diff: ios/chrome/browser/ui/webui/physical_web_ui.cc

Issue 2248913007: Add a Physical Web WebUI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/ui/webui/physical_web_ui.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 "ios/chrome/browser/ui/webui/physical_web_ui.h"
6
7 #include "base/bind.h"
8 #include "base/macros.h"
9 #include "base/metrics/user_metrics.h"
10 #include "base/values.h"
11 #include "components/grit/components_resources.h"
12 #include "components/physical_web/data_source/physical_web_data_source.h"
13 #include "components/physical_web/webui/physical_web_ui_constants.h"
14 #include "components/strings/grit/components_strings.h"
15 #include "ios/chrome/browser/application_context.h"
16 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
17 #include "ios/chrome/browser/chrome_url_constants.h"
18 #include "ios/web/public/web_ui_ios_data_source.h"
19 #include "ios/web/public/webui/web_ui_ios.h"
20 #include "ios/web/public/webui/web_ui_ios_message_handler.h"
21
22 namespace {
23
24 web::WebUIIOSDataSource* CreatePhysicalWebUIDataSource() {
25 web::WebUIIOSDataSource* html_source =
26 web::WebUIIOSDataSource::Create(kChromeUIPhysicalWebHost);
27
28 // Localized and data strings.
29 html_source->AddLocalizedString(physical_web_ui::kTitle,
30 IDS_PHYSICAL_WEB_UI_TITLE);
31
32 html_source->SetJsonPath("strings.js");
33 html_source->AddResourcePath(physical_web_ui::kPhysicalWebJS,
34 IDR_PHYSICAL_WEB_UI_JS);
35 html_source->AddResourcePath(physical_web_ui::kPhysicalWebCSS,
36 IDR_PHYSICAL_WEB_UI_CSS);
37 html_source->SetDefaultResource(IDR_PHYSICAL_WEB_UI_HTML);
38 return html_source;
39 }
40
41 ////////////////////////////////////////////////////////////////////////////////
42 //
43 // PhysicalWebDOMHandler
44 //
45 ////////////////////////////////////////////////////////////////////////////////
46
47 // The handler for Javascript messages for the chrome:physical-web page.
48 class PhysicalWebDOMHandler : public web::WebUIIOSMessageHandler {
49 public:
50 PhysicalWebDOMHandler() {}
51 ~PhysicalWebDOMHandler() override {}
52
53 void RegisterMessages() override;
54
55 void HandleRequestNearbyURLs(const base::ListValue* args);
56
57 private:
58 DISALLOW_COPY_AND_ASSIGN(PhysicalWebDOMHandler);
59 };
60
61 void PhysicalWebDOMHandler::RegisterMessages() {
62 web_ui()->RegisterMessageCallback(
63 physical_web_ui::kRequestNearbyUrls,
64 base::Bind(&PhysicalWebDOMHandler::HandleRequestNearbyURLs,
65 base::Unretained(this)));
66 }
67
68 void PhysicalWebDOMHandler::HandleRequestNearbyURLs(
69 const base::ListValue* args) {
70 base::DictionaryValue results;
71
72 std::unique_ptr<base::ListValue> metadata =
73 GetApplicationContext()->GetPhysicalWebDataSource()->GetMetadata();
74
75 results.Set(physical_web_ui::kMetadata, metadata.release());
76
77 web_ui()->CallJavascriptFunction(physical_web_ui::kReturnNearbyUrls, results);
78 }
79
80 } // namespace
81
82 ////////////////////////////////////////////////////////////////////////////////
83 //
84 // PhysicalWebUI
85 //
86 ////////////////////////////////////////////////////////////////////////////////
87
88 PhysicalWebUI::PhysicalWebUI(web::WebUIIOS* web_ui)
89 : web::WebUIIOSController(web_ui) {
90 PhysicalWebDOMHandler* handler = new PhysicalWebDOMHandler();
91 web_ui->AddMessageHandler(handler);
92
93 web::WebUIIOSDataSource::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui),
94 CreatePhysicalWebUIDataSource());
95
96 base::RecordAction(base::UserMetricsAction("PhysicalWeb.WebUI.Open"));
97 }
98
99 PhysicalWebUI::~PhysicalWebUI() {}
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/webui/physical_web_ui.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698