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

use brave:// for the virtual url and chrome:// for the internal u… #1385

Merged
merged 2 commits into from
Jan 31, 2019

Conversation

bridiver
Copy link
Collaborator

@bridiver bridiver commented Jan 18, 2019

…rl to load

fix brave/brave-browser#1616

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Verified that these changes build without errors on
    • Windows
    • macOS
    • Linux
  • Verified that these changes pass automated tests (npm test brave_unit_tests && npm test brave_browser_tests) on
    • Windows
    • macOS
    • Linux
  • Ran git rebase master (if needed).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed.
  • Add appropriate QA labels (QA/Yes or QA/No) to include the closed issue in milestone

Test Plan:

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

@bridiver bridiver self-assigned this Jan 18, 2019
@bridiver bridiver requested a review from bbondy January 18, 2019 03:54
bbondy
bbondy previously approved these changes Jan 18, 2019
Copy link
Member

@bbondy bbondy left a comment

Choose a reason for hiding this comment

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

nice cleanup

@simonhong
Copy link
Member

It would be good to have a test that checks virtual url is brave url for chrome or brave webui navigation.

@bridiver
Copy link
Collaborator Author

bridiver commented Jan 18, 2019

yep, I'm going to look to see what tests already exist and see what others make sense. It looks like some tests are broken now, but haven't looked at them yet so not sure if it's a code or test issue

@simonhong
Copy link
Member

simonhong commented Jan 21, 2019

I think only fixup handler should be executed when original url is chrome.

This PR adds unnecessary mapping from brave to chrome url in URLHandler when |original_url| is chrome url. When |original_url| is chrome url, we just want to set brave url as a virtual url and original chrome url should be passed to |load_to_url|.

In the near future, we want to delete mapping code in URLHandler because we want to move mapping timing from URLHandler to more earlier. So, URLHandler should not be executed when chrome url is original url.

void RewriteUrlForNavigation(const GURL& original_url,
                             BrowserContext* browser_context,
                             GURL* url_to_load,
                             GURL* virtual_url,
                             bool* reverse_on_redirect) {
  // Fix up the given URL before letting it be rewritten, so that any minor
  // cleanup (e.g., removing leading dots) will not lead to a virtual URL.
  *virtual_url = original_url;
  BrowserURLHandlerImpl::GetInstance()->FixupURLBeforeRewrite(virtual_url,
                                                              browser_context);

  // Allow the browser URL handler to rewrite the URL. This will, for example,
  // remove "view-source:" from the beginning of the URL to get the URL that
  // will actually be loaded. This real URL won't be shown to the user, just
  // used internally.
  *url_to_load = *virtual_url;
  BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary(
      url_to_load, browser_context, reverse_on_redirect);
}

@bridiver
Copy link
Collaborator Author

@simonhong what unnecessary mapping is happening? We are mapping the virtual url to brave:// and the url_to_load to chrome://

@simonhong
Copy link
Member

simonhong commented Jan 22, 2019

@bridiver Yep, that's the result of URLHandler.
I mean URLHandler doesn't need to be involved when original url is chrome url.
If original url is chrome url, we just need to set brave url as a virtual url by fixup. I think that's all what we need when original url is chrome url.
However, load_to_url is initialized with fixed virtual url(brave url).
So, additional mapping from brave to chrome should be done.

@@ -109,9 +123,9 @@ void BraveContentBrowserClient::BrowserURLHandlerCreated(
content::BrowserURLHandler::null_handler());
handler->AddHandlerPair(&webtorrent::HandleTorrentURLRewrite,
&webtorrent::HandleTorrentURLReverseRewrite);
ChromeContentBrowserClient::BrowserURLHandlerCreated(handler);
Copy link
Member

Choose a reason for hiding this comment

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

This point is what I worried.
When user types chrome url, load to url is initialized with brave url.
Then, I think brave url is the input of URLHandler before it is re-written our handler by below.
If so, that could cause skipping upstream URLHandler that checks chrome scheme.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see your point, but we may need to add two handers then because we have to run after ChromeContentBrowserClient to fix kChromeUISyncInternalsHost. I'll look at the upstream code to try to find something it breaks and update either way to convert back to chrome before the superclass method

content::BrowserContext* browser_context) {
// redirect sync-internals
if (url->host() == chrome::kChromeUISyncInternalsHost ||
url->host() == chrome::kChromeUISyncHost) {
Copy link
Member

@simonhong simonhong Jan 23, 2019

Choose a reason for hiding this comment

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

nit: I think this second condition in if clause can be removed.

// no special win10 welcome page
if (url->host() == chrome::kChromeUIWelcomeWin10Host ||
url->host() == chrome::kChromeUIWelcomeHost) {
*url = GURL(chrome::kChromeUIWelcomeURL);
Copy link
Member

Choose a reason for hiding this comment

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

Q) Why do you make rest handler skip for these two hosts (sync and welcome) by returning true?
Do you think upstream url handler doesn't need to handle them?

Copy link
Member

Choose a reason for hiding this comment

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

Ah! I saw upstream code tries to rewritten it. Ignore my above comment.

ChromeContentBrowserClient::BrowserURLHandlerCreated(handler);
handler->AddHandlerPair(&HandleURLOverrideRewrite,
&HandleURLReverseOverrideRewrite);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to add new pair after adding super class' handlers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, the order is critical because of rewriting that the superclass does

return FixupBrowserAboutURL_ChromiumImpl(url, browser_context);
}
if (url->SchemeIs(content::kChromeUIScheme) &&
url->host() != chrome::kChromeUINewTabHost) {
Copy link
Member

Choose a reason for hiding this comment

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

Just curiosity, any particular reason about excluding newtab host?

Copy link
Collaborator Author

@bridiver bridiver Jan 31, 2019

Choose a reason for hiding this comment

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

yes, it breaks the extension newtab override functionality

@yodaross

This comment was marked as abuse.

@fmarier
Copy link
Member

fmarier commented Jan 29, 2019

I'm going to remove myself from the list of reviewers since I don't think I'll have much useful feedback to provide here.

@bridiver bridiver merged commit bf338a5 into master Jan 31, 2019
@bridiver bridiver deleted the issues/1616 branch January 31, 2019 21:19
@bbondy bbondy added this to the 0.62.x - Nightly milestone Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"chrome://" still being displayed when editing URL bar
5 participants