Skip to content

Commit

Permalink
Add about:payments and basic web ui handler
Browse files Browse the repository at this point in the history
  • Loading branch information
bbondy committed Jan 3, 2018
1 parent a565208 commit a8409b6
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 9 deletions.
3 changes: 3 additions & 0 deletions browser/resources/resource_ids
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
"brave/common/extensions/api/brave_api_resources.grd": {
"includes": [32000],
},
"brave/components/resources/brave_components_resources.grd": {
"includes": [32001],
},
}
5 changes: 5 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import("//build/config/features.gni")

source_set("ui") {
sources = [
"webui/basic_ui.cc",
"webui/basic_ui.h",
"webui/brave_web_ui_controller_factory.cc",
"webui/brave_web_ui_controller_factory.h",
]
public_deps = [
"//content/public/browser",
]
}
64 changes: 64 additions & 0 deletions browser/ui/webui/basic_ui.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/webui/basic_ui.h"

#include "brave/common/url_constants.h"
#include "chrome/browser/profiles/profile.h"
#include "components/grit/brave_components_resources.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "ui/base/resource/resource_bundle.h"

using content::WebContents;
using content::WebUIMessageHandler;

namespace {

content::WebUIDataSource* CreateBasicUIHTMLSource(const std::string& name) {
content::WebUIDataSource* source =
content::WebUIDataSource::Create(kPaymentsHost);

if (name == kPaymentsHost) {
source->AddResourcePath(kPaymentsJS, IDR_BRAVE_PAYMENTS_JS);
source->SetDefaultResource(IDR_BRAVE_PAYMENTS_HTML);
}

return source;
}

// The handler for Javascript messages for Brave about: pages
class BasicDOMHandler : public WebUIMessageHandler {
public:
BasicDOMHandler() {
}
~BasicDOMHandler() override {}

void Init();

// WebUIMessageHandler implementation.
void RegisterMessages() override;

private:
DISALLOW_COPY_AND_ASSIGN(BasicDOMHandler);
};

void BasicDOMHandler::RegisterMessages() {
}

void BasicDOMHandler::Init() {
}

} // namespace

BasicUI::BasicUI(content::WebUI* web_ui, const std::string& name)
: WebUIController(web_ui) {
Profile* profile = Profile::FromWebUI(web_ui);

auto handler_owner = base::MakeUnique<BasicDOMHandler>();
BasicDOMHandler* handler = handler_owner.get();
web_ui->AddMessageHandler(std::move(handler_owner));
handler->Init();
content::WebUIDataSource::Add(profile, CreateBasicUIHTMLSource(name));
}
27 changes: 27 additions & 0 deletions browser/ui/webui/basic_ui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_UI_WEBUI_BASIC_UI_H_
#define BRAVE_BROWSER_UI_WEBUI_BASIC_UI_H_

#include <string>

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "content/public/browser/web_ui_controller.h"

class BasicUI : public content::WebUIController {
public:
explicit BasicUI(content::WebUI* web_ui, const std::string& host);
~BasicUI() override {}

private:
DISALLOW_COPY_AND_ASSIGN(BasicUI);
};

namespace basic_ui {

} // namespace basic_ui

#endif // BRAVE_BROWSER_UI_WEBUI_BASIC_UI_H_
9 changes: 5 additions & 4 deletions browser/ui/webui/brave_web_ui_controller_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include "brave/browser/ui/webui/brave_web_ui_controller_factory.h"

#include "brave/common/url_constants.h"
#include "chrome/browser/ui/webui/about_ui.h"
#include "brave/browser/ui/webui/basic_ui.h"
#include "url/gurl.h"

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

template<>
WebUIController* NewWebUI<AboutUI>(WebUI* web_ui, const GURL& url) {
return new AboutUI(web_ui, url.host());
WebUIController* NewWebUI<BasicUI>(WebUI* web_ui, const GURL& url) {
return new BasicUI(web_ui, url.host());
}

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

return nullptr;
Expand Down
8 changes: 3 additions & 5 deletions browser/ui/webui/brave_web_ui_controller_factory.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_UI_WEBUI_CHROME_WEB_UI_CONTROLLER_FACTORY_H_
#define BRAVE_BROWSER_UI_WEBUI_CHROME_WEB_UI_CONTROLLER_FACTORY_H_

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

class Profile;

namespace base {
class RefCountedMemory;
}
Expand Down
2 changes: 2 additions & 0 deletions common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ source_set("common") {
sources = [
"common_message_generator.cc",
"common_message_generator.h",
"resource_bundle_helper.cc",
"resource_bundle_helper.h",
"url_constants.cc",
"url_constants.h",
]
Expand Down
1 change: 1 addition & 0 deletions common/url_constants.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "brave/common/url_constants.h"

const char kPaymentsHost[] = "payments";
const char kPaymentsJS[] = "brave_payments.js";
1 change: 1 addition & 0 deletions common/url_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define BRAVE_COMMON_URL_CONSTANTS_H_

extern const char kPaymentsHost[];
extern const char kPaymentsJS[];

#endif // BRAVE_COMMON_URL_CONSTANTS_H_

12 changes: 12 additions & 0 deletions components/brave_payments_ui/brave_payments.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Payments</title>
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
<script src="chrome://payments/brave_payments.js"></script>
<body>
Brave Payments
</body>
</html>
1 change: 1 addition & 0 deletions components/brave_payments_ui/brave_payments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('brave_payments.js loaded')
15 changes: 15 additions & 0 deletions components/resources/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import("//printing/features/features.gni")
import("//tools/grit/grit_rule.gni")

grit("brave_components_resources_grit") {
source = "brave_components_resources.grd"

output_name = "brave_components_resources_new"
outputs = [
"grit/brave_components_resources.h",
"brave_components_resources.pak",
]
output_dir = "$root_gen_dir/components"
resource_ids = "//brave/browser/resources/resource_ids"
}

15 changes: 15 additions & 0 deletions components/resources/brave_components_resources.grd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<grit latest_public_release="0" current_release="1" output_all_resource_defines="false">
<outputs>
<output filename="grit/brave_components_resources.h" type="rc_header">
<emit emit_type='prepend'></emit>
</output>
<output filename="brave_components_resources.pak" type="data_package" />
</outputs>
<release seq="1">
<includes>
<include name="IDR_BRAVE_PAYMENTS_HTML" file="../brave_payments_ui/brave_payments.html" type="BINDATA" />
<include name="IDR_BRAVE_PAYMENTS_JS" file="../brave_payments_ui/brave_payments.js" type="BINDATA" />
</includes>
</release>
</grit>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
index 6d3b59691af1d5d05024dc37e8a4a2c8a023a700..4dac0261acaadebe8daf5dbe8a0aabdf07eb0b32 100644
--- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
+++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
@@ -11,6 +11,7 @@
#include "base/bind.h"
#include "base/location.h"
#include "base/threading/thread_task_runner_handle.h"
+#include "brave/browser/ui/webui/brave_web_ui_controller_factory.h"
#include "build/build_config.h"
#include "chrome/browser/about_flags.h"
#include "chrome/browser/devtools/devtools_ui_bindings.h"
@@ -726,7 +727,7 @@ void ChromeWebUIControllerFactory::GetFaviconForURL(

// static
ChromeWebUIControllerFactory* ChromeWebUIControllerFactory::GetInstance() {
- return base::Singleton<ChromeWebUIControllerFactory>::get();
+ return BraveWebUIControllerFactory::GetInstance();
}

ChromeWebUIControllerFactory::ChromeWebUIControllerFactory() {

0 comments on commit a8409b6

Please sign in to comment.