Commit 830124e2 authored by Bernhard Bauer's avatar Bernhard Bauer Committed by Commit Bot

Read publisher URL for trusted CDNs from response headers

The publisher URL is currently ignored. A followup CL will show it in the UI.

Bug: 814365
Change-Id: Id22e423cf5ef756f28b0ab3f92a029267722244b
Reviewed-on: https://chromium-review.googlesource.com/980553Reviewed-by: default avatarEmily Stark <estark@chromium.org>
Commit-Queue: Bernhard Bauer <bauerb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546187}
parent afbebd5b
...@@ -2166,6 +2166,8 @@ jumbo_split_static_library("browser") { ...@@ -2166,6 +2166,8 @@ jumbo_split_static_library("browser") {
"android/thumbnail/thumbnail.h", "android/thumbnail/thumbnail.h",
"android/thumbnail/thumbnail_cache.cc", "android/thumbnail/thumbnail_cache.cc",
"android/thumbnail/thumbnail_cache.h", "android/thumbnail/thumbnail_cache.h",
"android/trusted_cdn.cc",
"android/trusted_cdn.h",
"android/url_utilities.cc", "android/url_utilities.cc",
"android/usb/web_usb_chooser_service_android.cc", "android/usb/web_usb_chooser_service_android.cc",
"android/usb/web_usb_chooser_service_android.h", "android/usb/web_usb_chooser_service_android.h",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "chrome/browser/android/compositor/tab_content_manager.h" #include "chrome/browser/android/compositor/tab_content_manager.h"
#include "chrome/browser/android/metrics/uma_utils.h" #include "chrome/browser/android/metrics/uma_utils.h"
#include "chrome/browser/android/tab_web_contents_delegate_android.h" #include "chrome/browser/android/tab_web_contents_delegate_android.h"
#include "chrome/browser/android/trusted_cdn.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
#include "chrome/browser/browser_about_handler.h" #include "chrome/browser/browser_about_handler.h"
...@@ -45,7 +46,6 @@ ...@@ -45,7 +46,6 @@
#include "chrome/browser/ui/startup/bad_flags_prompt.h" #include "chrome/browser/ui/startup/bad_flags_prompt.h"
#include "chrome/browser/ui/tab_contents/core_tab_helper.h" #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
#include "chrome/browser/ui/tab_helpers.h" #include "chrome/browser/ui/tab_helpers.h"
#include "chrome/common/chrome_render_frame.mojom.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_node.h" #include "components/bookmarks/browser/bookmark_node.h"
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
#include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/interstitial_page.h" #include "content/public/browser/interstitial_page.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
...@@ -102,6 +103,25 @@ using content::WebContents; ...@@ -102,6 +103,25 @@ using content::WebContents;
using navigation_interception::InterceptNavigationDelegate; using navigation_interception::InterceptNavigationDelegate;
using navigation_interception::NavigationParams; using navigation_interception::NavigationParams;
namespace {
GURL GetPublisherURLForTrustedCDN(
content::NavigationHandle* navigation_handle) {
if (!trusted_cdn::IsTrustedCDN(navigation_handle->GetURL()))
return GURL();
const net::HttpResponseHeaders* headers =
navigation_handle->GetResponseHeaders();
DCHECK(headers);
std::string publisher_url;
if (!headers->GetNormalizedHeader("x-amp-cache", &publisher_url))
return GURL();
return GURL(publisher_url);
}
} // namespace
// This class is created and owned by the MediaDownloadInProductHelpManager. // This class is created and owned by the MediaDownloadInProductHelpManager.
class TabAndroid::MediaDownloadInProductHelp class TabAndroid::MediaDownloadInProductHelp
: public blink::mojom::MediaDownloadInProductHelp { : public blink::mojom::MediaDownloadInProductHelp {
...@@ -935,6 +955,25 @@ void TabAndroid::NavigationEntryChanged( ...@@ -935,6 +955,25 @@ void TabAndroid::NavigationEntryChanged(
Java_Tab_onNavEntryChanged(env, weak_java_tab_.get(env)); Java_Tab_onNavEntryChanged(env, weak_java_tab_.get(env));
} }
void TabAndroid::DidFinishNavigation(
content::NavigationHandle* navigation_handle) {
// Skip subframe, same-document, or non-committed navigations (downloads or
// 204/205 responses).
if (!navigation_handle->IsInMainFrame() ||
navigation_handle->IsSameDocument() ||
!navigation_handle->HasCommitted()) {
return;
}
GURL publisher_url = GetPublisherURLForTrustedCDN(navigation_handle);
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jstring> j_publisher_url;
if (publisher_url.is_valid())
j_publisher_url = ConvertUTF8ToJavaString(env, publisher_url.spec());
// TODO(https://crbug.com/814365): Pass publisher URL to Java Tab.
}
void TabAndroid::ShowMediaDownloadInProductHelp( void TabAndroid::ShowMediaDownloadInProductHelp(
const gfx::Rect& rect_in_frame) { const gfx::Rect& rect_in_frame) {
DCHECK(web_contents_); DCHECK(web_contents_);
......
...@@ -45,6 +45,7 @@ class TabContentManager; ...@@ -45,6 +45,7 @@ class TabContentManager;
namespace content { namespace content {
class DevToolsAgentHost; class DevToolsAgentHost;
class NavigationHandle;
class WebContents; class WebContents;
} }
...@@ -299,6 +300,8 @@ class TabAndroid : public CoreTabHelperDelegate, ...@@ -299,6 +300,8 @@ class TabAndroid : public CoreTabHelperDelegate,
void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
void NavigationEntryChanged( void NavigationEntryChanged(
const content::EntryChangedDetails& change_details) override; const content::EntryChangedDetails& change_details) override;
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override;
private: private:
class MediaDownloadInProductHelp; class MediaDownloadInProductHelp;
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/android/trusted_cdn.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/no_destructor.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "url/gurl.h"
namespace trusted_cdn {
constexpr char kDefaultTrustedCDNBaseURL[] = "https://cdn.ampproject.org";
bool IsTrustedCDN(const GURL& url) {
if (!base::FeatureList::IsEnabled(features::kShowTrustedPublisherURL))
return false;
// Use a static local (without destructor) to construct the base URL only
// once. |trusted_cdn_base_url| is initialized with the result of an
// immediately evaluated lambda, which allows wrapping the code in a single
// expression.
static const base::NoDestructor<GURL> trusted_cdn_base_url([]() {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kTrustedCDNBaseURLForTests)) {
GURL base_url(command_line->GetSwitchValueASCII(
switches::kTrustedCDNBaseURLForTests));
LOG_IF(WARNING, !base_url.is_valid()) << "Invalid trusted CDN base URL: "
<< base_url.possibly_invalid_spec();
return base_url;
}
return GURL(kDefaultTrustedCDNBaseURL);
}());
// Allow any subdomain of the base URL.
return url.DomainIs(trusted_cdn_base_url->host_piece()) &&
(url.scheme_piece() == trusted_cdn_base_url->scheme_piece()) &&
(url.EffectiveIntPort() == trusted_cdn_base_url->EffectiveIntPort());
}
} // namespace trusted_cdn
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ANDROID_TRUSTED_CDN_H_
#define CHROME_BROWSER_ANDROID_TRUSTED_CDN_H_
class GURL;
namespace trusted_cdn {
// Returns whether the given URL is hosted by a trusted CDN. This can be turned
// off via a Feature, and the base URL to trust can be set via a command line
// flag for testing.
bool IsTrustedCDN(const GURL& url);
} // namespace trusted_cdn
#endif // CHROME_BROWSER_ANDROID_TRUSTED_CDN_H_
...@@ -513,11 +513,9 @@ const base::Feature kShowAllDialogsWithViewsToolkit{ ...@@ -513,11 +513,9 @@ const base::Feature kShowAllDialogsWithViewsToolkit{
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Enables separate notification channels in Android O for notifications from const base::Feature kShowTrustedPublisherURL{"ShowTrustedPublisherURL",
// different origins, instead of sending them all to a single 'Sites' channel. base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kSiteNotificationChannels{"SiteNotificationChannels", #endif
base::FEATURE_ENABLED_BY_DEFAULT};
#endif // defined(OS_ANDROID)
// Alternative to switches::kSitePerProcess, for turning on full site isolation. // Alternative to switches::kSitePerProcess, for turning on full site isolation.
// Launch bug: https://crbug.com/739418. This is a //chrome-layer feature to // Launch bug: https://crbug.com/739418. This is a //chrome-layer feature to
...@@ -531,6 +529,13 @@ const base::Feature kSitePerProcess{"site-per-process", ...@@ -531,6 +529,13 @@ const base::Feature kSitePerProcess{"site-per-process",
const base::Feature kSimplifiedFullscreenUI{"ViewsSimplifiedFullscreenUI", const base::Feature kSimplifiedFullscreenUI{"ViewsSimplifiedFullscreenUI",
base::FEATURE_ENABLED_BY_DEFAULT}; base::FEATURE_ENABLED_BY_DEFAULT};
#if defined(OS_ANDROID)
// Enables separate notification channels in Android O for notifications from
// different origins, instead of sending them all to a single 'Sites' channel.
const base::Feature kSiteNotificationChannels{"SiteNotificationChannels",
base::FEATURE_ENABLED_BY_DEFAULT};
#endif // defined(OS_ANDROID)
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Enables or disables the ability to add a Samba Share to the Files app // Enables or disables the ability to add a Samba Share to the Files app
const base::Feature kNativeSmb{"NativeSmb", base::FEATURE_DISABLED_BY_DEFAULT}; const base::Feature kNativeSmb{"NativeSmb", base::FEATURE_DISABLED_BY_DEFAULT};
......
...@@ -278,6 +278,10 @@ extern const base::Feature kSecurityKeyAttestationPrompt; ...@@ -278,6 +278,10 @@ extern const base::Feature kSecurityKeyAttestationPrompt;
extern const base::Feature kShowAllDialogsWithViewsToolkit; extern const base::Feature kShowAllDialogsWithViewsToolkit;
#endif #endif
#if defined(OS_ANDROID)
extern const base::Feature kShowTrustedPublisherURL;
#endif
extern const base::Feature kSimplifiedFullscreenUI; extern const base::Feature kSimplifiedFullscreenUI;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
......
...@@ -782,6 +782,9 @@ const char kMarketUrlForTesting[] = "market-url-for-testing"; ...@@ -782,6 +782,9 @@ const char kMarketUrlForTesting[] = "market-url-for-testing";
// Specifies Android phone page loading progress bar animation. // Specifies Android phone page loading progress bar animation.
const char kProgressBarAnimation[] = "progress-bar-animation"; const char kProgressBarAnimation[] = "progress-bar-animation";
// Specifies a base URL for the trusted CDN for tests.
const char kTrustedCDNBaseURLForTests[] = "trusted-cdn-base-url-for-tests";
// Custom WebAPK server URL for the sake of testing. // Custom WebAPK server URL for the sake of testing.
const char kWebApkServerUrl[] = "webapk-server-url"; const char kWebApkServerUrl[] = "webapk-server-url";
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
......
...@@ -240,6 +240,7 @@ extern const char kForceShowUpdateMenuItem[]; ...@@ -240,6 +240,7 @@ extern const char kForceShowUpdateMenuItem[];
extern const char kForceShowUpdateMenuItemCustomSummary[]; extern const char kForceShowUpdateMenuItemCustomSummary[];
extern const char kMarketUrlForTesting[]; extern const char kMarketUrlForTesting[];
extern const char kProgressBarAnimation[]; extern const char kProgressBarAnimation[];
extern const char kTrustedCDNBaseURLForTests[];
extern const char kWebApkServerUrl[]; extern const char kWebApkServerUrl[];
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
......
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