|
| 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 | +} |
0 commit comments