diff --git a/browser/brave_content_browser_client.cc b/browser/brave_content_browser_client.cc index a552f2d1478f..004dd52850e6 100644 --- a/browser/brave_content_browser_client.cc +++ b/browser/brave_content_browser_client.cc @@ -92,25 +92,14 @@ bool HandleURLOverrideRewrite(GURL* url, bool HandleURLReverseOverrideRewrite(GURL* url, content::BrowserContext* browser_context) { - if (url->host() == chrome::kChromeUIWelcomeHost || - url->host() == chrome::kChromeUISyncHost) { - GURL::Replacements replacements; - replacements.SetSchemeStr(kBraveUIScheme); - *url = url->ReplaceComponents(replacements); + if (HandleURLOverrideRewrite(url, browser_context)) return true; - } return false; } bool HandleURLRewrite(GURL* url, content::BrowserContext* browser_context) { - if (url->SchemeIs(kBraveUIScheme)) { - GURL::Replacements replacements; - replacements.SetSchemeStr(content::kChromeUIScheme); - *url = url->ReplaceComponents(replacements); - } - if (HandleURLOverrideRewrite(url, browser_context)) return true; diff --git a/browser/brave_content_browser_client_browsertest.cc b/browser/brave_content_browser_client_browsertest.cc index 2c180790a7c1..f4b551478811 100644 --- a/browser/brave_content_browser_client_browsertest.cc +++ b/browser/brave_content_browser_client_browsertest.cc @@ -6,6 +6,7 @@ #include #include "base/path_service.h" +#include "base/strings/utf_string_conversions.h" #include "brave/browser/brave_content_browser_client.h" #include "brave/common/brave_paths.h" #include "brave/common/extensions/extension_constants.h" @@ -133,9 +134,12 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, CanLoadChromeURL) { ui_test_utils::NavigateToURL(browser(), GURL(scheme + page + "/")); ASSERT_TRUE(WaitForLoadStop(contents)); + EXPECT_STREQ(base::UTF16ToUTF8(browser()->location_bar_model() + ->GetFormattedFullURL()).c_str(), + ("brave://" + page).c_str()); EXPECT_STREQ(contents->GetController().GetLastCommittedEntry() ->GetVirtualURL().spec().c_str(), - ("brave://" + page + "/").c_str()); + ("chrome://" + page + "/").c_str()); EXPECT_STREQ(contents->GetController().GetLastCommittedEntry() ->GetURL().spec().c_str(), ("chrome://" + page + "/").c_str()); @@ -164,9 +168,12 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, CanLoadCustomBravePages) { ui_test_utils::NavigateToURL(browser(), GURL(scheme + page + "/")); ASSERT_TRUE(WaitForLoadStop(contents)); + EXPECT_STREQ(base::UTF16ToUTF8(browser()->location_bar_model() + ->GetFormattedFullURL()).c_str(), + ("brave://" + page).c_str()); EXPECT_STREQ(contents->GetController().GetLastCommittedEntry() ->GetVirtualURL().spec().c_str(), - ("brave://" + page + "/").c_str()); + ("chrome://" + page + "/").c_str()); EXPECT_STREQ(contents->GetController().GetLastCommittedEntry() ->GetURL().spec().c_str(), ("chrome://" + page + "/").c_str()); @@ -186,9 +193,12 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, CanLoadAboutHost) { ui_test_utils::NavigateToURL(browser(), GURL(scheme + "about/")); ASSERT_TRUE(WaitForLoadStop(contents)); + EXPECT_STREQ(base::UTF16ToUTF8(browser()->location_bar_model() + ->GetFormattedFullURL()).c_str(), + "brave://about"); EXPECT_STREQ(contents->GetController().GetLastCommittedEntry() ->GetVirtualURL().spec().c_str(), - "brave://about/"); + "chrome://about/"); EXPECT_STREQ(contents->GetController().GetLastCommittedEntry() ->GetURL().spec().c_str(), "chrome://chrome-urls/"); @@ -205,15 +215,46 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, for (const std::string& scheme : schemes) { content::WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); - ui_test_utils::NavigateToURL(browser(), GURL(scheme + "sync-internals/")); - ASSERT_TRUE(WaitForLoadStop(contents)); + ui_test_utils::NavigateToURL( + browser(), GURL(scheme + chrome::kChromeUISyncInternalsHost)); + ASSERT_TRUE(WaitForLoadStop(contents)); - EXPECT_STREQ(contents->GetController().GetLastCommittedEntry() - ->GetVirtualURL().spec().c_str(), - "brave://sync/"); - EXPECT_STREQ(contents->GetController().GetLastCommittedEntry() - ->GetURL().spec().c_str(), - "chrome://sync/"); + EXPECT_STREQ(base::UTF16ToUTF8(browser()->location_bar_model() + ->GetFormattedFullURL()).c_str(), + "brave://sync"); + EXPECT_STREQ(contents->GetController().GetLastCommittedEntry() + ->GetVirtualURL().spec().c_str(), + "chrome://sync/"); + EXPECT_STREQ(contents->GetController().GetLastCommittedEntry() + ->GetURL().spec().c_str(), + "chrome://sync/"); + } +} + +IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, + RewriteWelcomeWin10Host) { + std::vector schemes { + "brave://", + "chrome://", + }; + + for (const std::string& scheme : schemes) { + content::WebContents* contents = + browser()->tab_strip_model()->GetActiveWebContents(); + ui_test_utils::NavigateToURL( + browser(), + GURL(scheme + chrome::kChromeUIWelcomeWin10Host)); + ASSERT_TRUE(WaitForLoadStop(contents)); + + EXPECT_STREQ(base::UTF16ToUTF8(browser()->location_bar_model() + ->GetFormattedFullURL()).c_str(), + "brave://welcome"); + EXPECT_STREQ(contents->GetController().GetLastCommittedEntry() + ->GetVirtualURL().spec().c_str(), + "chrome://welcome/"); + EXPECT_STREQ(contents->GetController().GetLastCommittedEntry() + ->GetURL().spec().c_str(), + "chrome://welcome/"); } } @@ -230,9 +271,12 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, ui_test_utils::NavigateToURL(browser(), GURL(scheme + "welcome-win10/")); ASSERT_TRUE(WaitForLoadStop(contents)); + EXPECT_STREQ(base::UTF16ToUTF8(browser()->location_bar_model() + ->GetFormattedFullURL()).c_str(), + "brave://welcome"); EXPECT_STREQ(contents->GetController().GetLastCommittedEntry() ->GetVirtualURL().spec().c_str(), - "brave://welcome/"); + "chrome://welcome/"); EXPECT_STREQ(contents->GetController().GetLastCommittedEntry() ->GetURL().spec().c_str(), "chrome://welcome/"); diff --git a/browser/brave_scheme_load_browsertest.cc b/browser/brave_scheme_load_browsertest.cc index c067d2642644..06dd218a5e98 100644 --- a/browser/brave_scheme_load_browsertest.cc +++ b/browser/brave_scheme_load_browsertest.cc @@ -5,6 +5,7 @@ #include "base/path_service.h" #include "base/strings/pattern.h" +#include "base/strings/utf_string_conversions.h" #include "brave/common/brave_paths.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" @@ -59,7 +60,7 @@ class BraveSchemeLoadBrowserTest : public InProcessBrowserTest, // Check loading |url| in private window is redirected to normal // window. - void TestURLIsNotLoadedInPrivateWindow(const GURL& url) { + void TestURLIsNotLoadedInPrivateWindow(const std::string& url) { Browser* private_browser = CreateIncognitoBrowser(nullptr); TabStripModel* private_model = private_browser->tab_strip_model(); @@ -73,12 +74,16 @@ class BraveSchemeLoadBrowserTest : public InProcessBrowserTest, browser()->tab_strip_model()->AddObserver(this); // Load url to private window. - NavigateParams params(private_browser, url, ui::PAGE_TRANSITION_TYPED); + NavigateParams params( + private_browser, GURL(url), ui::PAGE_TRANSITION_TYPED); Navigate(¶ms); browser()->tab_strip_model()->RemoveObserver(this); - EXPECT_EQ(url, active_contents()->GetVisibleURL()); + EXPECT_STREQ(url.c_str(), + base::UTF16ToUTF8(browser()->location_bar_model() + ->GetFormattedFullURL()).c_str()); + // EXPECT_EQ(url, active_contents()->GetVisibleURL()); EXPECT_EQ(2, browser()->tab_strip_model()->count()); // Private window stays as initial state. EXPECT_EQ("about:blank", @@ -232,15 +237,15 @@ IN_PROC_BROWSER_TEST_F(BraveSchemeLoadBrowserTest, // window. IN_PROC_BROWSER_TEST_F(BraveSchemeLoadBrowserTest, SettingsPageIsNotAllowedInPrivateWindow) { - TestURLIsNotLoadedInPrivateWindow(GURL("brave://settings/")); + TestURLIsNotLoadedInPrivateWindow("brave://settings"); } IN_PROC_BROWSER_TEST_F(BraveSchemeLoadBrowserTest, SyncPageIsNotAllowedInPrivateWindow) { - TestURLIsNotLoadedInPrivateWindow(GURL("brave://sync/")); + TestURLIsNotLoadedInPrivateWindow("brave://sync"); } IN_PROC_BROWSER_TEST_F(BraveSchemeLoadBrowserTest, RewardsPageIsNotAllowedInPrivateWindow) { - TestURLIsNotLoadedInPrivateWindow(GURL("brave://rewards/")); + TestURLIsNotLoadedInPrivateWindow("brave://rewards"); } diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index 910bb02be00c..e8e7a604524e 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -31,6 +31,8 @@ source_set("ui") { "omnibox/brave_omnibox_client.h", "toolbar/brave_app_menu_model.cc", "toolbar/brave_app_menu_model.h", + "toolbar/brave_location_bar_model_delegate.cc", + "toolbar/brave_location_bar_model_delegate.h", "toolbar/brave_toolbar_actions_model.cc", "toolbar/brave_toolbar_actions_model.h", "views/brave_layout_provider.cc", diff --git a/browser/ui/toolbar/brave_location_bar_model_delegate.cc b/browser/ui/toolbar/brave_location_bar_model_delegate.cc new file mode 100644 index 000000000000..42d93f91141d --- /dev/null +++ b/browser/ui/toolbar/brave_location_bar_model_delegate.cc @@ -0,0 +1,32 @@ +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * 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/toolbar/brave_location_bar_model_delegate.h" + +#include "base/strings/utf_string_conversions.h" + +BraveLocationBarModelDelegate::BraveLocationBarModelDelegate( + Browser* browser) : BrowserLocationBarModelDelegate(browser) {} + +BraveLocationBarModelDelegate::~BraveLocationBarModelDelegate() {} + +base::string16 +BraveLocationBarModelDelegate::FormattedStringWithEquivalentMeaning( + const GURL& url, + const base::string16& formatted_url) const { + base::string16 new_formatted_url = + BrowserLocationBarModelDelegate::FormattedStringWithEquivalentMeaning( + url, formatted_url); + + if (url.SchemeIs("chrome")) { + base::ReplaceFirstSubstringAfterOffset( + &new_formatted_url, + 0, + base::UTF8ToUTF16("chrome://"), + base::UTF8ToUTF16("brave://")); + } + + return new_formatted_url; +} diff --git a/browser/ui/toolbar/brave_location_bar_model_delegate.h b/browser/ui/toolbar/brave_location_bar_model_delegate.h new file mode 100644 index 000000000000..bdf0fa86cde3 --- /dev/null +++ b/browser/ui/toolbar/brave_location_bar_model_delegate.h @@ -0,0 +1,28 @@ +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * 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_TOOLBAR_BRAVE_LOCATION_BAR_MODEL_DELEGATE_H_ +#define BRAVE_BROWSER_UI_TOOLBAR_BRAVE_LOCATION_BAR_MODEL_DELEGATE_H_ + +#include "base/compiler_specific.h" +#include "base/macros.h" +#include "chrome/browser/ui/browser_location_bar_model_delegate.h" + +class Browser; + +class BraveLocationBarModelDelegate : public BrowserLocationBarModelDelegate { + public: + explicit BraveLocationBarModelDelegate(Browser* browser); + ~BraveLocationBarModelDelegate() override; + + private: + base::string16 FormattedStringWithEquivalentMeaning( + const GURL& url, + const base::string16& formatted_url) const override; + + DISALLOW_COPY_AND_ASSIGN(BraveLocationBarModelDelegate); +}; + +#endif // BRAVE_BROWSER_UI_TOOLBAR_BRAVE_LOCATION_BAR_MODEL_DELEGATE_H_ diff --git a/browser/ui/webui/brave_welcome_ui_browsertest.cc b/browser/ui/webui/brave_welcome_ui_browsertest.cc index b3aecd8e08ea..8cd817514854 100644 --- a/browser/ui/webui/brave_welcome_ui_browsertest.cc +++ b/browser/ui/webui/brave_welcome_ui_browsertest.cc @@ -40,7 +40,7 @@ IN_PROC_BROWSER_TEST_F(BraveWelcomeUIBrowserTest, PRE_StartupURLTest) { content::WebContents* web_contents = tab_strip->GetWebContentsAt(0); content::TestNavigationObserver observer(web_contents, 1); observer.Wait(); - EXPECT_STREQ("brave://welcome/", + EXPECT_STREQ("chrome://welcome/", tab_strip->GetWebContentsAt(0) ->GetController().GetLastCommittedEntry() ->GetVirtualURL().possibly_invalid_spec().c_str()); diff --git a/chromium_src/chrome/browser/browser_about_handler.cc b/chromium_src/chrome/browser/browser_about_handler.cc index a0cf98a0a22a..307415b97abc 100644 --- a/chromium_src/chrome/browser/browser_about_handler.cc +++ b/chromium_src/chrome/browser/browser_about_handler.cc @@ -25,10 +25,9 @@ bool FixupBrowserAboutURL(GURL* url, *url = url->ReplaceComponents(replacements); } - if (url->SchemeIs(content::kChromeUIScheme) && - url->host() != chrome::kChromeUINewTabHost) { + if (url->SchemeIs(kBraveUIScheme)) { GURL::Replacements replacements; - replacements.SetSchemeStr(kBraveUIScheme); + replacements.SetSchemeStr(content::kChromeUIScheme); *url = url->ReplaceComponents(replacements); } diff --git a/chromium_src/chrome/browser/ui/browser.cc b/chromium_src/chrome/browser/ui/browser.cc index 56fa9b9c3fc1..1127b2c1fdf4 100644 --- a/chromium_src/chrome/browser/ui/browser.cc +++ b/chromium_src/chrome/browser/ui/browser.cc @@ -7,10 +7,13 @@ #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" #include "brave/browser/ui/brave_browser_content_setting_bubble_model_delegate.h" #include "brave/browser/ui/brave_browser_command_controller.h" +#include "brave/browser/ui/toolbar/brave_location_bar_model_delegate.h" #define BrowserContentSettingBubbleModelDelegate \ BraveBrowserContentSettingBubbleModelDelegate #define BrowserCommandController BraveBrowserCommandController +#define BrowserLocationBarModelDelegate BraveLocationBarModelDelegate #include "../../../../../chrome/browser/ui/browser.cc" // NOLINT +#undef BrowserLocationBarModelDelegate #undef BrowserContentSettingBubbleModelDelegate #undef BrowserCommandController diff --git a/components/brave_rewards/browser/rewards_service_browsertest.cc b/components/brave_rewards/browser/rewards_service_browsertest.cc index c3cfbea164d6..f3b4bdeaae87 100644 --- a/components/brave_rewards/browser/rewards_service_browsertest.cc +++ b/components/brave_rewards/browser/rewards_service_browsertest.cc @@ -1,4 +1,5 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * 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/. */ @@ -30,7 +31,7 @@ namespace brave_test_resp { namespace brave_net { class BraveURLFetcher : public net::TestURLFetcher { - public: + public: BraveURLFetcher(bool success, const GURL& url, const std::string& results, @@ -48,19 +49,19 @@ class BraveURLFetcher : public net::TestURLFetcher { DISALLOW_COPY_AND_ASSIGN(BraveURLFetcher); }; -void split(std::vector& tmp, std::string query, char delimiter) { +void split(std::vector* tmp, std::string query, char delimiter) { std::stringstream ss(query); std::string item; while (std::getline(ss, item, delimiter)) { if (query[0] != '\n') { - tmp.push_back(item); + tmp->push_back(item); } } } void BraveURLFetcher::DetermineURLResponsePath(std::string url) { std::vector tmp; - brave_net::split(tmp, url, '/'); + brave_net::split(&tmp, url, '/'); if (url.find(braveledger_bat_helper::buildURL(REGISTER_PERSONA, PREFIX_V2, braveledger_bat_helper::SERVER_TYPES::LEDGER)) == 0 && tmp.size() == 6) { @@ -174,7 +175,7 @@ class BraveRewardsBrowserTest : public InProcessBrowserTest { // Load rewards page ui_test_utils::NavigateToURL(browser(), rewards_url()); WaitForLoadStop(contents()); - //opt in and create wallet to enable rewards + // opt in and create wallet to enable rewards ASSERT_TRUE(ExecJs(contents(), "document.querySelector(\"[data-test-id='optInAction']\").click();", content::EXECUTE_SCRIPT_DEFAULT_OPTIONS, @@ -213,7 +214,8 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, RenderWelcome) { // Enable Rewards EnableRewards(); EXPECT_STREQ(contents()->GetLastCommittedURL().spec().c_str(), - rewards_url().spec().c_str()); + // actual url is always chrome:// + "chrome://rewards/"); } IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, ToggleRewards) { @@ -287,10 +289,12 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, ToggleAutoContribute) { " if (document.querySelector(\"[data-test-id2='autoContribution']\")) {" " if (!toggleClicked) {" " toggleClicked = true;" - " document.querySelector(\"[data-test-id2='autoContribution']\").click();" + " document.querySelector(" + " \"[data-test-id2='autoContribution']\").click();" " } else {" " clearInterval(interval);" - " resolve(document.querySelector(\"[data-test-id2='autoContribution']\")" + " resolve(document.querySelector(" + " \"[data-test-id2='autoContribution']\")" " .getAttribute(\"data-toggled\") === 'false');" " }" " }" @@ -406,8 +410,8 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsSingleArg) { GetReconcileTime(); RunUntilIdle(); - EXPECT_CALL(*this, OnGetShortRetries(true)); // on - EXPECT_CALL(*this, OnGetShortRetries(false)); // off + EXPECT_CALL(*this, OnGetShortRetries(true)); // on + EXPECT_CALL(*this, OnGetShortRetries(false)); // off // Short retries - on rewards_service()->SetShortRetries(false); diff --git a/patches/chrome-browser-ui-toolbar-chrome_location_bar_model_delegate.h.patch b/patches/chrome-browser-ui-toolbar-chrome_location_bar_model_delegate.h.patch new file mode 100644 index 000000000000..0ed97cb9176a --- /dev/null +++ b/patches/chrome-browser-ui-toolbar-chrome_location_bar_model_delegate.h.patch @@ -0,0 +1,12 @@ +diff --git a/chrome/browser/ui/toolbar/chrome_location_bar_model_delegate.h b/chrome/browser/ui/toolbar/chrome_location_bar_model_delegate.h +index 26d74e9c5d80d2c699df1a6ee16f4ed494d563dd..130e4bd112aac15e81e2de967da2d1c419acdae0 100644 +--- a/chrome/browser/ui/toolbar/chrome_location_bar_model_delegate.h ++++ b/chrome/browser/ui/toolbar/chrome_location_bar_model_delegate.h +@@ -37,6 +37,7 @@ class ChromeLocationBarModelDelegate : public LocationBarModelDelegate { + content::NavigationEntry* GetNavigationEntry() const; + + private: ++ friend class BraveLocationBarModelDelegate; + base::string16 FormattedStringWithEquivalentMeaning( + const GURL& url, + const base::string16& formatted_url) const override;