Commit cf95a7c5 authored by Evan Stade's avatar Evan Stade Committed by Chromium LUCI CQ

Add WebappsClient::CanShowAppBanners

This removes a dependency on TabAndroid.

Bug: 1147268
Change-Id: Icbfa0ab7c0853b1935cf6bf9d9a52a4054302226
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2613535Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840861}
parent 838ef3b2
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/android/chrome_jni_headers/AppBannerManagerHelper_jni.h" #include "chrome/android/chrome_jni_headers/AppBannerManagerHelper_jni.h"
#include "chrome/browser/android/tab_android.h"
#include "chrome/browser/android/tab_web_contents_delegate_android.h"
#include "chrome/browser/android/webapk/webapk_metrics.h" #include "chrome/browser/android/webapk/webapk_metrics.h"
#include "chrome/browser/android/webapk/webapk_ukm_recorder.h" #include "chrome/browser/android/webapk/webapk_ukm_recorder.h"
#include "chrome/browser/android/webapps/add_to_homescreen_coordinator.h" #include "chrome/browser/android/webapps/add_to_homescreen_coordinator.h"
...@@ -68,14 +66,6 @@ constexpr char kIphReplacesToolbar[] = "x_iph_replaces_toolbar"; ...@@ -68,14 +66,6 @@ constexpr char kIphReplacesToolbar[] = "x_iph_replaces_toolbar";
// Whether to ignore the Chrome channel in QueryNativeApp() for testing. // Whether to ignore the Chrome channel in QueryNativeApp() for testing.
bool gIgnoreChromeChannelForTesting = false; bool gIgnoreChromeChannelForTesting = false;
bool CanShowAppBanners(TabAndroid* tab) {
if (!tab)
return false;
return static_cast<android::TabWebContentsDelegateAndroid*>(
tab->web_contents()->GetDelegate())
->CanShowAppBanners();
}
} // anonymous namespace } // anonymous namespace
AppBannerManagerAndroid::AppBannerManagerAndroid( AppBannerManagerAndroid::AppBannerManagerAndroid(
...@@ -127,12 +117,10 @@ bool AppBannerManagerAndroid::OnAppDetailsRetrieved( ...@@ -127,12 +117,10 @@ bool AppBannerManagerAndroid::OnAppDetailsRetrieved(
void AppBannerManagerAndroid::RequestAppBanner(const GURL& validated_url) { void AppBannerManagerAndroid::RequestAppBanner(const GURL& validated_url) {
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
if (!Java_AppBannerManagerHelper_isEnabledForTab(env)) if (!Java_AppBannerManagerHelper_isEnabledForTab(env) ||
return; !WebappsClient::Get()->CanShowAppBanners(web_contents())) {
TabAndroid* tab = TabAndroid::FromWebContents(web_contents());
if (!CanShowAppBanners(tab))
return; return;
}
AppBannerManager::RequestAppBanner(validated_url); AppBannerManager::RequestAppBanner(validated_url);
} }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "chrome/browser/webapps/chrome_webapps_client.h" #include "chrome/browser/webapps/chrome_webapps_client.h"
#include "base/logging.h" #include "base/logging.h"
#include "build/build_config.h"
#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/ssl/security_state_tab_helper.h" #include "chrome/browser/ssl/security_state_tab_helper.h"
#include "components/webapps/installable/installable_metrics.h" #include "components/webapps/installable/installable_metrics.h"
...@@ -70,16 +69,21 @@ WebappInstallSource ChromeWebappsClient::GetInstallSource( ...@@ -70,16 +69,21 @@ WebappInstallSource ChromeWebappsClient::GetInstallSource(
return WebappInstallSource::COUNT; return WebappInstallSource::COUNT;
} }
#if defined(OS_ANDROID)
bool ChromeWebappsClient::IsInstallationInProgress( bool ChromeWebappsClient::IsInstallationInProgress(
content::WebContents* web_contents, content::WebContents* web_contents,
const GURL& manifest_url) { const GURL& manifest_url) {
#if defined(OS_ANDROID)
return WebApkInstallService::Get(web_contents->GetBrowserContext()) return WebApkInstallService::Get(web_contents->GetBrowserContext())
->IsInstallInProgress(manifest_url); ->IsInstallInProgress(manifest_url);
#else
NOTREACHED();
return false;
#endif
} }
bool ChromeWebappsClient::CanShowAppBanners(
content::WebContents* web_contents) {
TabAndroid* tab = TabAndroid::FromWebContents(web_contents);
return tab && static_cast<android::TabWebContentsDelegateAndroid*>(
tab->web_contents()->GetDelegate())
->CanShowAppBanners();
}
#endif
} // namespace webapps } // namespace webapps
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CHROME_BROWSER_WEBAPPS_CHROME_WEBAPPS_CLIENT_H_ #define CHROME_BROWSER_WEBAPPS_CHROME_WEBAPPS_CLIENT_H_
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "build/build_config.h"
#include "components/webapps/webapps_client.h" #include "components/webapps/webapps_client.h"
namespace webapps { namespace webapps {
...@@ -24,8 +25,11 @@ class ChromeWebappsClient : public WebappsClient { ...@@ -24,8 +25,11 @@ class ChromeWebappsClient : public WebappsClient {
content::WebContents* web_contents) override; content::WebContents* web_contents) override;
WebappInstallSource GetInstallSource(content::WebContents* web_contents, WebappInstallSource GetInstallSource(content::WebContents* web_contents,
InstallTrigger trigger) override; InstallTrigger trigger) override;
#if defined(OS_ANDROID)
bool IsInstallationInProgress(content::WebContents* web_contents, bool IsInstallationInProgress(content::WebContents* web_contents,
const GURL& manifest_url) override; const GURL& manifest_url) override;
bool CanShowAppBanners(content::WebContents* web_contents) override;
#endif
private: private:
friend base::NoDestructor<ChromeWebappsClient>; friend base::NoDestructor<ChromeWebappsClient>;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef COMPONENTS_WEBAPPS_WEBAPPS_CLIENT_H_ #ifndef COMPONENTS_WEBAPPS_WEBAPPS_CLIENT_H_
#define COMPONENTS_WEBAPPS_WEBAPPS_CLIENT_H_ #define COMPONENTS_WEBAPPS_WEBAPPS_CLIENT_H_
#include "build/build_config.h"
#include "components/security_state/core/security_state.h" #include "components/security_state/core/security_state.h"
class GURL; class GURL;
...@@ -44,8 +45,12 @@ class WebappsClient { ...@@ -44,8 +45,12 @@ class WebappsClient {
content::WebContents* web_contents, content::WebContents* web_contents,
InstallTrigger trigger) = 0; InstallTrigger trigger) = 0;
#if defined(OS_ANDROID)
virtual bool IsInstallationInProgress(content::WebContents* web_contents, virtual bool IsInstallationInProgress(content::WebContents* web_contents,
const GURL& manifest_url) = 0; const GURL& manifest_url) = 0;
virtual bool CanShowAppBanners(content::WebContents* web_contents) = 0;
#endif
}; };
} // namespace webapps } // namespace webapps
......
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