Chromium Code Reviews| Index: chrome/browser/android/instantapps/instant_apps_settings.cc |
| diff --git a/chrome/browser/android/instantapps/instant_apps_settings.cc b/chrome/browser/android/instantapps/instant_apps_settings.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f07253b2d644aa167998b7498fae0040c6022c6c |
| --- /dev/null |
| +++ b/chrome/browser/android/instantapps/instant_apps_settings.cc |
| @@ -0,0 +1,104 @@ |
| +// Copyright 2016 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/instantapps/instant_apps_settings.h" |
| + |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_string.h" |
| +#include "base/memory/ptr_util.h" |
|
dominickn
2016/09/29 07:22:05
Nit: ptr_util.h isn't used?
Maria
2016/09/30 17:24:40
Done.
|
| +#include "base/time/time.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/banners/app_banner_settings_helper.h" |
| +#include "chrome/browser/installable/installable_logging.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "jni/InstantAppsSettings_jni.h" |
| +#include "url/gurl.h" |
| + |
| +using base::android::JavaParamRef; |
| +using base::android::ConvertJavaStringToUTF8; |
| + |
| +const char InstantAppsSettings::kInstantAppsKey[] = "instantapps"; |
| + |
| +void InstantAppsSettings::RecordInfoBarShowEvent( |
| + content::WebContents* web_contents, |
| + const std::string& url) { |
| + AppBannerSettingsHelper::RecordBannerEvent( |
| + web_contents, |
| + GURL(url).GetOrigin(), |
|
dominickn
2016/09/29 07:22:05
Nit: the GetOrigin() call isn't necessary - it wil
Maria
2016/09/30 17:24:40
Done.
|
| + std::string(kInstantAppsKey), |
|
dominickn
2016/09/29 07:22:05
Nit: the std::string shouldn't be necessary - I th
Maria
2016/09/30 17:24:40
Done.
|
| + AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, |
| + base::Time::Now()); |
| +} |
| + |
| +void InstantAppsSettings::RecordInfoBarDismissEvent( |
| + content::WebContents* web_contents, |
| + const std::string& url) { |
| + AppBannerSettingsHelper::RecordBannerEvent( |
| + web_contents, |
| + GURL(url).GetOrigin(), |
|
dominickn
2016/09/29 07:22:05
Nit: remove GetOrigin() and std::string
Maria
2016/09/30 17:24:40
Done.
|
| + std::string(kInstantAppsKey), |
| + AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, |
| + base::Time::Now()); |
| +} |
| + |
| +static void SetInstantAppDefault( |
| + JNIEnv* env, |
| + const JavaParamRef<jclass>& clazz, |
| + const JavaParamRef<jobject>& jweb_contents, |
| + const JavaParamRef<jstring>& jurl) { |
| + content::WebContents* web_contents = |
| + content::WebContents::FromJavaWebContents(jweb_contents); |
| + DCHECK(web_contents); |
| + |
| + std::string url(ConvertJavaStringToUTF8(env, jurl)); |
| + |
| + AppBannerSettingsHelper::RecordBannerEvent( |
| + web_contents, |
| + GURL(url).GetOrigin(), |
|
dominickn
2016/09/29 07:22:05
Nit: remove GetOrigin() and std::string.
Maria
2016/09/30 17:24:41
Done.
|
| + std::string(InstantAppsSettings::kInstantAppsKey), |
| + AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, |
| + base::Time::Now()); |
| +} |
| + |
| +static jboolean GetInstantAppDefault( |
| + JNIEnv* env, |
| + const JavaParamRef<jclass>& clazz, |
| + const JavaParamRef<jobject>& jweb_contents, |
| + const JavaParamRef<jstring>& jurl) { |
| + content::WebContents* web_contents = |
| + content::WebContents::FromJavaWebContents(jweb_contents); |
| + DCHECK(web_contents); |
| + |
| + std::string url(ConvertJavaStringToUTF8(env, jurl)); |
| + |
| + // Don't show if it has been added to the homescreen. |
| + base::Time added_time = AppBannerSettingsHelper::GetSingleBannerEvent( |
| + web_contents, |
| + GURL(url).GetOrigin(), |
| + std::string(InstantAppsSettings::kInstantAppsKey), |
|
dominickn
2016/09/29 07:22:05
Nit: remove GetOrigin() and std::string
Maria
2016/09/30 17:24:40
Done.
|
| + AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN); |
| + |
| + return !added_time.is_null(); |
| +} |
| + |
| +static jboolean ShouldShowBanner(JNIEnv* env, |
| + const JavaParamRef<jclass>& clazz, |
| + const JavaParamRef<jobject>& jweb_contents, |
| + const JavaParamRef<jstring>& jurl) { |
| + content::WebContents* web_contents = |
| + content::WebContents::FromJavaWebContents(jweb_contents); |
| + DCHECK(web_contents); |
| + |
| + std::string url(ConvertJavaStringToUTF8(env, jurl)); |
| + |
| + return AppBannerSettingsHelper::ShouldShowBanner( |
| + web_contents, |
| + GURL(url).GetOrigin(), |
|
dominickn
2016/09/29 07:22:05
Nit: Nit: remove GetOrigin() and std::string
Maria
2016/09/30 17:24:41
Done.
|
| + std::string(InstantAppsSettings::kInstantAppsKey), |
| + base::Time::Now()) == InstallableStatusCode::NO_ERROR_DETECTED; |
| +} |
| + |
| +bool RegisterInstantAppsSettings(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |