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

Merge pull request #2024 from brave/issues/3411 #2033

Merged
merged 1 commit into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,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;

Expand Down
31 changes: 25 additions & 6 deletions browser/brave_content_browser_client_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <vector>

#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"
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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/");
Expand All @@ -209,9 +219,12 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest,
browser(), GURL(scheme + chrome::kChromeUISyncInternalsHost));
ASSERT_TRUE(WaitForLoadStop(contents));

EXPECT_STREQ(base::UTF16ToUTF8(browser()->location_bar_model()
->GetFormattedFullURL()).c_str(),
"brave://sync");
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetVirtualURL().spec().c_str(),
"brave://sync/");
"chrome://sync/");
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetURL().spec().c_str(),
"chrome://sync/");
Expand All @@ -233,9 +246,12 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest,
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(),
"brave://welcome/");
"chrome://welcome/");
EXPECT_STREQ(contents->GetController().GetLastCommittedEntry()
->GetURL().spec().c_str(),
"chrome://welcome/");
Expand All @@ -255,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/");
Expand Down
17 changes: 11 additions & 6 deletions browser/brave_scheme_load_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();

Expand All @@ -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(&params);

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",
Expand Down Expand Up @@ -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");
}
2 changes: 2 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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",
Expand Down
32 changes: 32 additions & 0 deletions browser/ui/toolbar/brave_location_bar_model_delegate.cc
Original file line number Diff line number Diff line change
@@ -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;
}
28 changes: 28 additions & 0 deletions browser/ui/toolbar/brave_location_bar_model_delegate.h
Original file line number Diff line number Diff line change
@@ -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_
2 changes: 1 addition & 1 deletion browser/ui/webui/brave_welcome_ui_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
14 changes: 7 additions & 7 deletions browser/widevine/widevine_permission_request_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ IN_PROC_BROWSER_TEST_F(WidevinePermissionRequestBrowserTest, VisibilityTest) {
// Check permission is requested again after new navigation.
observer.bubble_added_ = false;
EXPECT_TRUE(content::NavigateToURL(GetActiveWebContents(),
GURL("brave://version/")));
GURL("chrome://version/")));
drm_tab_helper->OnWidevineKeySystemAccessRequest();
content::RunAllTasksUntilIdle();
EXPECT_TRUE(observer.bubble_added_);
Expand Down Expand Up @@ -132,7 +132,7 @@ IN_PROC_BROWSER_TEST_F(WidevinePermissionRequestBrowserTest, BubbleTest) {
IN_PROC_BROWSER_TEST_F(WidevinePermissionRequestBrowserTest,
CheckOptedInPrefStateForComponent) {
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
// Before we allow, opted in should be false
// Before we allow, opted in should be false
EXPECT_FALSE(prefs->GetBoolean(kWidevineOptedIn));

GetPermissionRequestManager()->set_auto_response_for_test(
Expand Down Expand Up @@ -186,7 +186,7 @@ class ScriptTriggerWidevinePermissionRequestBrowserTest
ScriptTriggerWidevinePermissionRequestBrowserTest()
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {}

void SetUpOnMainThread() override {
void SetUpOnMainThread() override {
CertVerifierBrowserTest::SetUpOnMainThread();
host_resolver()->AddRule("*", "127.0.0.1");
// Chromium allows the API under test only on HTTPS domains.
Expand All @@ -204,13 +204,13 @@ class ScriptTriggerWidevinePermissionRequestBrowserTest
GetPermissionRequestManager()->RemoveObserver(&observer);
}

void SetUpDefaultCommandLine(base::CommandLine* command_line) override {
void SetUpDefaultCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitchASCII(
"enable-blink-features",
"EncryptedMediaEncryptionSchemeQuery");
}

content::WebContents* active_contents() {
content::WebContents* active_contents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}

Expand All @@ -227,7 +227,7 @@ class ScriptTriggerWidevinePermissionRequestBrowserTest
observer.added_count_ = 0;
}

protected:
protected:
void SetUpMockCertVerifierForHttpsServer(net::CertStatus cert_status,
int net_result) {
scoped_refptr<net::X509Certificate> cert(https_server_.GetCertificate());
Expand Down Expand Up @@ -287,4 +287,4 @@ IN_PROC_BROWSER_TEST_F(ScriptTriggerWidevinePermissionRequestBrowserTest,
EXPECT_TRUE(content::ExecuteScript(active_contents(), widevine_js));
content::RunAllTasksUntilIdle();
EXPECT_TRUE(IsPermissionBubbleShown());
}
}
5 changes: 2 additions & 3 deletions chromium_src/chrome/browser/browser_about_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions chromium_src/chrome/browser/ui/browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading