Skip to content

Commit a8409b6

Browse files
committedJan 3, 2018
Add about:payments and basic web ui handler
1 parent a565208 commit a8409b6

14 files changed

+175
-9
lines changed
 

‎browser/resources/resource_ids

+3
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44
"brave/common/extensions/api/brave_api_resources.grd": {
55
"includes": [32000],
66
},
7+
"brave/components/resources/brave_components_resources.grd": {
8+
"includes": [32001],
9+
},
710
}

‎browser/ui/BUILD.gn

+5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import("//build/config/features.gni")
22

33
source_set("ui") {
44
sources = [
5+
"webui/basic_ui.cc",
6+
"webui/basic_ui.h",
57
"webui/brave_web_ui_controller_factory.cc",
68
"webui/brave_web_ui_controller_factory.h",
79
]
10+
public_deps = [
11+
"//content/public/browser",
12+
]
813
}

‎browser/ui/webui/basic_ui.cc

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
#include "brave/browser/ui/webui/basic_ui.h"
6+
7+
#include "brave/common/url_constants.h"
8+
#include "chrome/browser/profiles/profile.h"
9+
#include "components/grit/brave_components_resources.h"
10+
#include "content/public/browser/web_ui_data_source.h"
11+
#include "content/public/browser/web_ui_message_handler.h"
12+
#include "ui/base/resource/resource_bundle.h"
13+
14+
using content::WebContents;
15+
using content::WebUIMessageHandler;
16+
17+
namespace {
18+
19+
content::WebUIDataSource* CreateBasicUIHTMLSource(const std::string& name) {
20+
content::WebUIDataSource* source =
21+
content::WebUIDataSource::Create(kPaymentsHost);
22+
23+
if (name == kPaymentsHost) {
24+
source->AddResourcePath(kPaymentsJS, IDR_BRAVE_PAYMENTS_JS);
25+
source->SetDefaultResource(IDR_BRAVE_PAYMENTS_HTML);
26+
}
27+
28+
return source;
29+
}
30+
31+
// The handler for Javascript messages for Brave about: pages
32+
class BasicDOMHandler : public WebUIMessageHandler {
33+
public:
34+
BasicDOMHandler() {
35+
}
36+
~BasicDOMHandler() override {}
37+
38+
void Init();
39+
40+
// WebUIMessageHandler implementation.
41+
void RegisterMessages() override;
42+
43+
private:
44+
DISALLOW_COPY_AND_ASSIGN(BasicDOMHandler);
45+
};
46+
47+
void BasicDOMHandler::RegisterMessages() {
48+
}
49+
50+
void BasicDOMHandler::Init() {
51+
}
52+
53+
} // namespace
54+
55+
BasicUI::BasicUI(content::WebUI* web_ui, const std::string& name)
56+
: WebUIController(web_ui) {
57+
Profile* profile = Profile::FromWebUI(web_ui);
58+
59+
auto handler_owner = base::MakeUnique<BasicDOMHandler>();
60+
BasicDOMHandler* handler = handler_owner.get();
61+
web_ui->AddMessageHandler(std::move(handler_owner));
62+
handler->Init();
63+
content::WebUIDataSource::Add(profile, CreateBasicUIHTMLSource(name));
64+
}

‎browser/ui/webui/basic_ui.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
#ifndef BRAVE_BROWSER_UI_WEBUI_BASIC_UI_H_
6+
#define BRAVE_BROWSER_UI_WEBUI_BASIC_UI_H_
7+
8+
#include <string>
9+
10+
#include "base/compiler_specific.h"
11+
#include "base/macros.h"
12+
#include "content/public/browser/web_ui_controller.h"
13+
14+
class BasicUI : public content::WebUIController {
15+
public:
16+
explicit BasicUI(content::WebUI* web_ui, const std::string& host);
17+
~BasicUI() override {}
18+
19+
private:
20+
DISALLOW_COPY_AND_ASSIGN(BasicUI);
21+
};
22+
23+
namespace basic_ui {
24+
25+
} // namespace basic_ui
26+
27+
#endif // BRAVE_BROWSER_UI_WEBUI_BASIC_UI_H_

‎browser/ui/webui/brave_web_ui_controller_factory.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#include "brave/browser/ui/webui/brave_web_ui_controller_factory.h"
66

77
#include "brave/common/url_constants.h"
8-
#include "chrome/browser/ui/webui/about_ui.h"
8+
#include "brave/browser/ui/webui/basic_ui.h"
9+
#include "url/gurl.h"
910

1011
using content::WebUI;
1112
using content::WebUIController;
@@ -24,8 +25,8 @@ WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) {
2425
}
2526

2627
template<>
27-
WebUIController* NewWebUI<AboutUI>(WebUI* web_ui, const GURL& url) {
28-
return new AboutUI(web_ui, url.host());
28+
WebUIController* NewWebUI<BasicUI>(WebUI* web_ui, const GURL& url) {
29+
return new BasicUI(web_ui, url.host());
2930
}
3031

3132
// Returns a function that can be used to create the right type of WebUI for a
@@ -34,7 +35,7 @@ WebUIController* NewWebUI<AboutUI>(WebUI* web_ui, const GURL& url) {
3435
WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
3536
const GURL& url) {
3637
if (url.host_piece() == kPaymentsHost) {
37-
return &NewWebUI<AboutUI>;
38+
return &NewWebUI<BasicUI>;
3839
}
3940

4041
return nullptr;

‎browser/ui/webui/brave_web_ui_controller_factory.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
// Copyright (c) 2012 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.
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
#ifndef BRAVE_BROWSER_UI_WEBUI_CHROME_WEB_UI_CONTROLLER_FACTORY_H_
66
#define BRAVE_BROWSER_UI_WEBUI_CHROME_WEB_UI_CONTROLLER_FACTORY_H_
77

88
#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
99

10-
class Profile;
11-
1210
namespace base {
1311
class RefCountedMemory;
1412
}

‎common/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ source_set("common") {
22
sources = [
33
"common_message_generator.cc",
44
"common_message_generator.h",
5+
"resource_bundle_helper.cc",
6+
"resource_bundle_helper.h",
57
"url_constants.cc",
68
"url_constants.h",
79
]

‎common/url_constants.cc

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#include "brave/common/url_constants.h"
22

33
const char kPaymentsHost[] = "payments";
4+
const char kPaymentsJS[] = "brave_payments.js";

‎common/url_constants.h

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define BRAVE_COMMON_URL_CONSTANTS_H_
33

44
extern const char kPaymentsHost[];
5+
extern const char kPaymentsJS[];
56

67
#endif // BRAVE_COMMON_URL_CONSTANTS_H_
78

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width">
6+
<title>Payments</title>
7+
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
8+
<script src="chrome://payments/brave_payments.js"></script>
9+
<body>
10+
Brave Payments
11+
</body>
12+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('brave_payments.js loaded')

‎components/resources/BUILD.gn

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import("//printing/features/features.gni")
2+
import("//tools/grit/grit_rule.gni")
3+
4+
grit("brave_components_resources_grit") {
5+
source = "brave_components_resources.grd"
6+
7+
output_name = "brave_components_resources_new"
8+
outputs = [
9+
"grit/brave_components_resources.h",
10+
"brave_components_resources.pak",
11+
]
12+
output_dir = "$root_gen_dir/components"
13+
resource_ids = "//brave/browser/resources/resource_ids"
14+
}
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<grit latest_public_release="0" current_release="1" output_all_resource_defines="false">
3+
<outputs>
4+
<output filename="grit/brave_components_resources.h" type="rc_header">
5+
<emit emit_type='prepend'></emit>
6+
</output>
7+
<output filename="brave_components_resources.pak" type="data_package" />
8+
</outputs>
9+
<release seq="1">
10+
<includes>
11+
<include name="IDR_BRAVE_PAYMENTS_HTML" file="../brave_payments_ui/brave_payments.html" type="BINDATA" />
12+
<include name="IDR_BRAVE_PAYMENTS_JS" file="../brave_payments_ui/brave_payments.js" type="BINDATA" />
13+
</includes>
14+
</release>
15+
</grit>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
2+
index 6d3b59691af1d5d05024dc37e8a4a2c8a023a700..4dac0261acaadebe8daf5dbe8a0aabdf07eb0b32 100644
3+
--- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
4+
+++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
5+
@@ -11,6 +11,7 @@
6+
#include "base/bind.h"
7+
#include "base/location.h"
8+
#include "base/threading/thread_task_runner_handle.h"
9+
+#include "brave/browser/ui/webui/brave_web_ui_controller_factory.h"
10+
#include "build/build_config.h"
11+
#include "chrome/browser/about_flags.h"
12+
#include "chrome/browser/devtools/devtools_ui_bindings.h"
13+
@@ -726,7 +727,7 @@ void ChromeWebUIControllerFactory::GetFaviconForURL(
14+
15+
// static
16+
ChromeWebUIControllerFactory* ChromeWebUIControllerFactory::GetInstance() {
17+
- return base::Singleton<ChromeWebUIControllerFactory>::get();
18+
+ return BraveWebUIControllerFactory::GetInstance();
19+
}
20+
21+
ChromeWebUIControllerFactory::ChromeWebUIControllerFactory() {

0 commit comments

Comments
 (0)