-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display chrome:// urls as brave:// in the LocationBar
This only affects the DisplayURL in that, when the url is being edited or copied, the actual chrome://*** url will be present. This seems acceptable given: - These urls 99% of the time are for display purposes only, as a result of another UI action, and will not be typed manually - We intend to support brave://*** actual urls, redirecting to chrome://*** actual URLs automatically, which will get displayed as brave://*** URLs (brave/brave-browser#810) Fix brave/brave-browser#1458
- Loading branch information
Showing
9 changed files
with
165 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
source_set("toolbar") { | ||
|
||
sources = [ | ||
"brave_toolbar_model_impl.cc", | ||
"brave_toolbar_model_impl.h", | ||
"constants.cc", | ||
"constants.h", | ||
] | ||
|
||
deps = [ | ||
"//base", | ||
"//components/toolbar" | ||
] | ||
|
||
} | ||
|
||
source_set("unit_tests") { | ||
testonly = true | ||
sources = [ | ||
"toolbar_model_impl_unittest.cc", | ||
] | ||
|
||
deps = [ | ||
":toolbar", | ||
"//base", | ||
"//components/toolbar", | ||
"//testing/gtest", | ||
"//url", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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" | ||
|
||
#include "base/strings/string_util.h" | ||
#include "base/strings/utf_string_conversions.h" | ||
#include "brave/components/toolbar/constants.h" | ||
#include "components/toolbar/toolbar_model_impl.h" | ||
|
||
using namespace brave_toolbar; | ||
|
||
namespace { | ||
|
||
const base::string16 original_scheme_part = | ||
base::ASCIIToUTF16(kOriginalInternalUIScheme); | ||
const base::string16 replacement_scheme_part = | ||
base::ASCIIToUTF16(kInternalUIScheme); | ||
|
||
} | ||
|
||
base::string16 BraveToolbarModelImpl::GetURLForDisplay() const { | ||
base::string16 formatted_text = ToolbarModelImpl::GetURLForDisplay(); | ||
|
||
const GURL url(GetURL()); | ||
// Only replace chrome:// with brave:// if scheme is "chrome" and | ||
// it has not been stripped from the display text | ||
if (url.SchemeIs(kOriginalInternalUIScheme) && | ||
base::StartsWith(formatted_text, original_scheme_part, | ||
base::CompareCase::INSENSITIVE_ASCII)) { | ||
formatted_text.replace(0, original_scheme_part.length(), | ||
replacement_scheme_part); | ||
} | ||
return formatted_text; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// 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_COMPONENTS_TOOLBAR_BRAVE_TOOLBAR_MODEL_IMPL_H_ | ||
#define BRAVE_COMPONENTS_TOOLBAR_BRAVE_TOOLBAR_MODEL_IMPL_H_ | ||
|
||
#include "components/toolbar/toolbar_model_impl.h" | ||
|
||
class BraveToolbarModelImpl : public ToolbarModelImpl { | ||
public: | ||
using ToolbarModelImpl::ToolbarModelImpl; | ||
base::string16 GetURLForDisplay() const override; | ||
private: | ||
DISALLOW_COPY_AND_ASSIGN(BraveToolbarModelImpl); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// 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/constants.h" | ||
|
||
namespace brave_toolbar { | ||
const char kOriginalInternalUIScheme[] = "chrome"; | ||
const char kInternalUIScheme[] = "brave"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// 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_COMPONENTS_TOOLBAR_CONSTANTS_H_ | ||
#define BRAVE_COMPONENTS_TOOLBAR_CONSTANTS_H_ | ||
|
||
namespace brave_toolbar { | ||
extern const char kOriginalInternalUIScheme[]; | ||
extern const char kInternalUIScheme[]; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// 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" | ||
|
||
#include "base/strings/utf_string_conversions.h" | ||
#include "components/toolbar/toolbar_model_delegate.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
#include "url/gurl.h" | ||
|
||
namespace { | ||
|
||
class FakeToolbarModelDelegate : public ToolbarModelDelegate { | ||
public: | ||
void SetURL(const GURL& url) { url_ = url; } | ||
|
||
// ToolbarModelDelegate: | ||
base::string16 FormattedStringWithEquivalentMeaning( | ||
const GURL& url, | ||
const base::string16& formatted_url) const override { | ||
return formatted_url; | ||
} | ||
|
||
bool GetURL(GURL* url) const override { | ||
*url = url_; | ||
return true; | ||
} | ||
|
||
private: | ||
GURL url_; | ||
}; | ||
|
||
TEST(BraveToolbarModelImplTest, | ||
DisplayUrlRewritesScheme) { | ||
FakeToolbarModelDelegate delegate; | ||
auto model = std::make_unique<BraveToolbarModelImpl>(&delegate, 1024); | ||
|
||
delegate.SetURL(GURL("chrome://page")); | ||
|
||
// Verify that both the full formatted URL and the display URL add the test | ||
// suffix. | ||
EXPECT_EQ(base::ASCIIToUTF16("brave://page"), | ||
model->GetURLForDisplay()); | ||
} | ||
|
||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters