Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brave url scheme android #1007

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions android/chromium_src/components/url_formatter/url_fixer.cc
@@ -0,0 +1,33 @@
/* 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/. */

#define IsEquivalentScheme IsEquivalentScheme_ChromiumImpl
#include "../../../../../../components/url_formatter/url_fixer.cc"
#undef IsEquivalentScheme

namespace url_formatter {

namespace {

const char kBraveUIScheme[] = "brave";

bool IsEquivalentScheme_BraveImpl(const std::string& scheme1,
const std::string& scheme2) {
return (scheme1 == kBraveUIScheme && scheme2 == kChromeUIScheme) ||
(scheme1 == kChromeUIScheme && scheme2 == kBraveUIScheme) ||
(scheme1 == url::kAboutScheme && scheme2 == kBraveUIScheme) ||
(scheme1 == kBraveUIScheme && scheme2 == url::kAboutScheme);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe you need to compare about and chrome schemes here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I need this also, as I need to compare for equality all the pairs from <brave, chrome, about>:

brave<->chrome 
brave<->about
chrome<->about

But chrome<->about comparison is already done in IsEquivalentScheme_ChromiumImpl , https://cs.chromium.org/chromium/src/components/url_formatter/url_fixer.cc?type=cs&q=IsEquivalentScheme&g=0&l=683

bool IsEquivalentScheme(const std::string& scheme1,
                        const std::string& scheme2) {
  return scheme1 == scheme2 ||
         (scheme1 == url::kAboutScheme && scheme2 == kChromeUIScheme) ||
         (scheme1 == kChromeUIScheme && scheme2 == url::kAboutScheme);
}

So I used compare chrome<->about by invoking IsEquivalentScheme_ChromiumImp .

}

}

bool IsEquivalentScheme(const std::string& scheme1,
const std::string& scheme2) {
if (IsEquivalentScheme_ChromiumImpl(scheme1, scheme2)) {
return true;
}
return IsEquivalentScheme_BraveImpl(scheme1, scheme2);
}

} // namespace url_formatter
25 changes: 25 additions & 0 deletions android/chromium_src/content/common/url_schemes.cc
@@ -0,0 +1,25 @@
/* 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/common/url_constants.h"
#define RegisterContentSchemes RegisterContentSchemes_ChromiumImpl
#include "../../../../../content/common/url_schemes.cc"
#undef RegisterContentSchemes

namespace {

void RegisterContentSchemes_BraveImpl(bool lock_schemes) {
url::AddStandardScheme(kBraveUIScheme, url::SCHEME_WITH_HOST);
}

}

namespace content {

void RegisterContentSchemes(bool lock_schemes) {
RegisterContentSchemes_BraveImpl(lock_schemes);
RegisterContentSchemes_ChromiumImpl(lock_schemes);
}

} // namespace content
14 changes: 10 additions & 4 deletions browser/autocomplete/brave_autocomplete_scheme_classifier.cc
Expand Up @@ -6,9 +6,12 @@

#include "base/strings/string_util.h"
#include "brave/common/url_constants.h"
#include "brave/components/brave_webtorrent/browser/webtorrent_util.h"
#include "chrome/browser/profiles/profile.h"

#if !defined(OS_ANDROID)
#include "brave/components/brave_webtorrent/browser/webtorrent_util.h"
#endif

// See the BraveAutocompleteProviderClient why GetOriginalProfile() is fetched.
// All services except TemplateURLService exposed from AutocompleteClassifier
// uses original profile. So, |profile_| should be original profile same as
Expand All @@ -30,9 +33,12 @@ BraveAutocompleteSchemeClassifier::GetInputTypeForScheme(
return metrics::OmniboxInputType::INVALID;
}
if (base::IsStringASCII(scheme) &&
(base::LowerCaseEqualsASCII(scheme, kBraveUIScheme) ||
(webtorrent::IsWebtorrentEnabled(profile_) &&
base::LowerCaseEqualsASCII(scheme, kMagnetScheme)))) {
(base::LowerCaseEqualsASCII(scheme, kBraveUIScheme)
#if !defined(OS_ANDROID)
|| (webtorrent::IsWebtorrentEnabled(profile_) &&
base::LowerCaseEqualsASCII(scheme, kMagnetScheme))
#endif
)) {
return metrics::OmniboxInputType::URL;
}

Expand Down
Expand Up @@ -2,16 +2,25 @@
* 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/autocomplete/brave_autocomplete_provider_client.h"
#include "brave/browser/autocomplete/brave_autocomplete_scheme_classifier.h"
#include "brave/components/omnibox/browser/brave_autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_controller.h"

#if !defined(OS_ANDROID)
#include "brave/browser/autocomplete/brave_autocomplete_provider_client.h"
#include "brave/components/omnibox/browser/brave_autocomplete_controller.h"
#endif

#if !defined(OS_ANDROID)
#define AutocompleteController BraveAutocompleteController
#define ChromeAutocompleteProviderClient BraveAutocompleteProviderClient
#endif

#define ChromeAutocompleteSchemeClassifier BraveAutocompleteSchemeClassifier
#include "../../../../../chrome/browser/autocomplete/autocomplete_classifier_factory.cc"
#undef ChromeAutocompleteSchemeClassifier

#if !defined(OS_ANDROID)
#undef ChromeAutocompleteProviderClient
#undef AutocompleteController
#endif
@@ -0,0 +1,8 @@
/* 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/components/toolbar/brave_toolbar_model_impl.h"
#define ToolbarModelImpl BraveToolbarModelImpl
#include "../../../../../../../chrome/browser/ui/android/toolbar/toolbar_model_android.cc"
#undef ToolbarModelImpl
6 changes: 3 additions & 3 deletions common/BUILD.gn
Expand Up @@ -14,7 +14,7 @@ source_set("channel_info") {
}

source_set("common") {

sources = [
"brave_switches.cc",
"brave_switches.h",
Expand All @@ -26,6 +26,8 @@ source_set("common") {
"pref_names.h",
"webui_url_constants.cc",
"webui_url_constants.h",
"url_constants.cc",
"url_constants.h",
]

if (!is_android) {
Expand Down Expand Up @@ -53,8 +55,6 @@ source_set("common") {
"resource_bundle_helper.h",
"shield_exceptions.cc",
"shield_exceptions.h",
"url_constants.cc",
"url_constants.h",
]

public_deps = [
Expand Down
5 changes: 5 additions & 0 deletions components/toolbar/brave_toolbar_model_impl.cc
Expand Up @@ -20,8 +20,13 @@ const base::string16 replacement_scheme_part =

}

#if defined(OS_ANDROID)
base::string16 BraveToolbarModelImpl::GetFormattedFullURL() const {
base::string16 formatted_text = ToolbarModelImpl::GetFormattedFullURL();
#else
base::string16 BraveToolbarModelImpl::GetURLForDisplay() const {
base::string16 formatted_text = ToolbarModelImpl::GetURLForDisplay();
#endif

const GURL url(GetURL());
// Only replace chrome:// with brave:// if scheme is "chrome" and
Expand Down
6 changes: 6 additions & 0 deletions components/toolbar/brave_toolbar_model_impl.h
Expand Up @@ -10,7 +10,13 @@
class BraveToolbarModelImpl : public ToolbarModelImpl {
public:
using ToolbarModelImpl::ToolbarModelImpl;
#if defined(OS_ANDROID)
// On Android GetURLForDisplay is not invoked as on brave-core,
// but GetFormattedFullURL is invoked instead
base::string16 GetFormattedFullURL() const override;
#else
base::string16 GetURLForDisplay() const override;
#endif
private:
DISALLOW_COPY_AND_ASSIGN(BraveToolbarModelImpl);
};
Expand Down