Commit ea6dfd45 authored by Alan Cutter's avatar Alan Cutter Committed by Commit Bot

desktop-pwas: Fix blob URL origins in web app window UI

GURL::GetOrigin() doesn't handle blob:* URLs. Use Origin class instead.
Also update web app window UI to use full URL if we are unable to parse
the origin out of it instead of showing nothing.

Before:
https://bugs.chromium.org/p/chromium/issues/attachment?aid=446212&signed_aid=n--6M0MuMy7reB9rCSzlBQ==&inline=1

After:
https://bugs.chromium.org/p/chromium/issues/attachment?aid=446381&signed_aid=32H8pSYcBHXM7jZ9LMdxEg==&inline=1

Bug: 1080934
Change-Id: Ifd107797a9e6c40ec6dbbd4891e991db5725484a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2198697
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Auto-Submit: Alan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#768761}
parent a6dffe5e
...@@ -346,11 +346,10 @@ void CustomTabBarView::UpdateContents() { ...@@ -346,11 +346,10 @@ void CustomTabBarView::UpdateContents() {
base::string16 title, location; base::string16 title, location;
if (entry) { if (entry) {
title = Browser::FormatTitleForDisplay(entry->GetTitleForDisplay()); title = Browser::FormatTitleForDisplay(entry->GetTitleForDisplay());
if (ShouldDisplayUrl(contents)) if (ShouldDisplayUrl(contents)) {
location = url_formatter::FormatUrl(entry->GetVirtualURL().GetOrigin(), location = web_app::AppBrowserController::FormatUrlOrigin(
url_formatter::kFormatUrlOmitDefaults, contents->GetVisibleURL(), url_formatter::kFormatUrlOmitDefaults);
net::UnescapeRule::NORMAL, nullptr, }
nullptr, nullptr);
} }
title_origin_view_->Update(title, location); title_origin_view_->Update(title, location);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/strings/string_util.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h" #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
...@@ -672,6 +673,33 @@ IN_PROC_BROWSER_TEST_P(CustomTabBarViewBrowserTest, InterstitialCanHideOrigin) { ...@@ -672,6 +673,33 @@ IN_PROC_BROWSER_TEST_P(CustomTabBarViewBrowserTest, InterstitialCanHideOrigin) {
app_view->toolbar()->custom_tab_bar()->IsShowingOriginForTesting()); app_view->toolbar()->custom_tab_bar()->IsShowingOriginForTesting());
} }
// Verify that blob URLs are displayed in the location text.
IN_PROC_BROWSER_TEST_P(CustomTabBarViewBrowserTest, BlobUrlLocation) {
InstallPWA(https_server()->GetURL("/simple.html"));
EXPECT_TRUE(app_browser_);
BrowserView* app_browser_view =
BrowserView::GetBrowserViewForBrowser(app_browser_);
EXPECT_NE(app_browser_view, browser_view_);
content::WebContents* web_contents =
app_browser_->tab_strip_model()->GetActiveWebContents();
content::TestNavigationObserver nav_observer(web_contents,
/*number_of_navigations=*/1);
std::string script =
"window.open("
" URL.createObjectURL("
" new Blob([], {type: 'text/html'})"
" ),"
" '_self');";
EXPECT_TRUE(content::ExecuteScript(web_contents, script));
nav_observer.Wait();
EXPECT_EQ(
app_browser_view->toolbar()->custom_tab_bar()->location_for_testing() +
base::ASCIIToUTF16("/"),
base::ASCIIToUTF16(https_server()->GetURL("/").spec()));
}
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
All, All,
CustomTabBarViewBrowserTest, CustomTabBarViewBrowserTest,
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "url/gurl.h" #include "url/gurl.h"
#include "url/origin.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/crostini/crostini_terminal.h" #include "chrome/browser/chromeos/crostini/crostini_terminal.h"
...@@ -132,15 +133,13 @@ bool AppBrowserController::IsForWebAppBrowser(const Browser* browser, ...@@ -132,15 +133,13 @@ bool AppBrowserController::IsForWebAppBrowser(const Browser* browser,
} }
// static // static
base::string16 AppBrowserController::FormatUrlOrigin(const GURL& url) { base::string16 AppBrowserController::FormatUrlOrigin(
return url_formatter::FormatUrl( const GURL& url,
url.GetOrigin(), url_formatter::FormatUrlTypes format_types) {
url_formatter::kFormatUrlOmitUsernamePassword | auto origin = url::Origin::Create(url);
url_formatter::kFormatUrlOmitHTTPS | return url_formatter::FormatUrl(origin.opaque() ? url : origin.GetURL(),
url_formatter::kFormatUrlOmitHTTP | format_types, net::UnescapeRule::SPACES,
url_formatter::kFormatUrlOmitTrailingSlashOnBareHostname | nullptr, nullptr, nullptr);
url_formatter::kFormatUrlOmitTrivialSubdomains,
net::UnescapeRule::SPACES, nullptr, nullptr, nullptr);
} }
const ui::ThemeProvider* AppBrowserController::GetThemeProvider() const { const ui::ThemeProvider* AppBrowserController::GetThemeProvider() const {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h" #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "chrome/browser/web_applications/components/web_app_id.h" #include "chrome/browser/web_applications/components/web_app_id.h"
#include "components/url_formatter/url_formatter.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
...@@ -56,7 +57,14 @@ class AppBrowserController : public TabStripModelObserver, ...@@ -56,7 +57,14 @@ class AppBrowserController : public TabStripModelObserver,
static bool IsForWebAppBrowser(const Browser* browser, const AppId& app_id); static bool IsForWebAppBrowser(const Browser* browser, const AppId& app_id);
// Renders |url|'s origin as Unicode. // Renders |url|'s origin as Unicode.
static base::string16 FormatUrlOrigin(const GURL& url); static base::string16 FormatUrlOrigin(
const GURL& url,
url_formatter::FormatUrlTypes format_types =
url_formatter::kFormatUrlOmitUsernamePassword |
url_formatter::kFormatUrlOmitHTTPS |
url_formatter::kFormatUrlOmitHTTP |
url_formatter::kFormatUrlOmitTrailingSlashOnBareHostname |
url_formatter::kFormatUrlOmitTrivialSubdomains);
// Returns a theme built from the current page or app's theme color. // Returns a theme built from the current page or app's theme color.
const ui::ThemeProvider* GetThemeProvider() const; const ui::ThemeProvider* GetThemeProvider() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment