OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/android/instantapps/instant_apps_settings.h" | |
6 | |
7 #include "base/android/jni_android.h" | |
8 #include "base/android/jni_string.h" | |
9 #include "base/time/time.h" | |
10 #include "base/values.h" | |
11 #include "chrome/browser/banners/app_banner_settings_helper.h" | |
12 #include "chrome/browser/installable/installable_logging.h" | |
13 #include "content/public/browser/web_contents.h" | |
14 #include "jni/InstantAppsSettings_jni.h" | |
15 #include "url/gurl.h" | |
16 | |
17 using base::android::JavaParamRef; | |
18 using base::android::ConvertJavaStringToUTF8; | |
19 | |
20 const char InstantAppsSettings::kInstantAppsKey[] = "instantapps"; | |
21 | |
22 void InstantAppsSettings::RecordInfoBarShowEvent( | |
23 content::WebContents* web_contents, | |
24 const std::string& url) { | |
25 AppBannerSettingsHelper::RecordBannerEvent( | |
26 web_contents, | |
27 GURL(url), | |
28 kInstantAppsKey, | |
29 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, | |
30 base::Time::Now()); | |
31 } | |
32 | |
33 void InstantAppsSettings::RecordInfoBarDismissEvent( | |
34 content::WebContents* web_contents, | |
35 const std::string& url) { | |
36 AppBannerSettingsHelper::RecordBannerEvent( | |
37 web_contents, | |
38 GURL(url), | |
39 kInstantAppsKey, | |
40 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, | |
41 base::Time::Now()); | |
42 } | |
43 | |
44 static void SetInstantAppDefault( | |
45 JNIEnv* env, | |
46 const JavaParamRef<jclass>& clazz, | |
47 const JavaParamRef<jobject>& jweb_contents, | |
48 const JavaParamRef<jstring>& jurl) { | |
49 content::WebContents* web_contents = | |
50 content::WebContents::FromJavaWebContents(jweb_contents); | |
51 DCHECK(web_contents); | |
52 | |
53 std::string url(ConvertJavaStringToUTF8(env, jurl)); | |
54 | |
55 AppBannerSettingsHelper::RecordBannerEvent( | |
56 web_contents, | |
57 GURL(url), | |
58 InstantAppsSettings::kInstantAppsKey, | |
59 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | |
Ted C
2016/09/30 18:01:34
should we have a TODO to change the enum name to A
Maria
2016/09/30 20:35:18
Done.
| |
60 base::Time::Now()); | |
61 } | |
62 | |
63 static jboolean GetInstantAppDefault( | |
64 JNIEnv* env, | |
65 const JavaParamRef<jclass>& clazz, | |
66 const JavaParamRef<jobject>& jweb_contents, | |
67 const JavaParamRef<jstring>& jurl) { | |
68 content::WebContents* web_contents = | |
69 content::WebContents::FromJavaWebContents(jweb_contents); | |
70 DCHECK(web_contents); | |
71 | |
72 std::string url(ConvertJavaStringToUTF8(env, jurl)); | |
73 | |
74 // Don't show if it has been added to the homescreen. | |
Ted C
2016/09/30 18:01:34
comment doesn't seem applicable (or needs further
Maria
2016/09/30 20:35:18
Yeah, I probably copied it
| |
75 base::Time added_time = AppBannerSettingsHelper::GetSingleBannerEvent( | |
76 web_contents, | |
77 GURL(url), | |
78 InstantAppsSettings::kInstantAppsKey, | |
79 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN); | |
80 | |
81 return !added_time.is_null(); | |
82 } | |
83 | |
84 static jboolean ShouldShowBanner(JNIEnv* env, | |
85 const JavaParamRef<jclass>& clazz, | |
86 const JavaParamRef<jobject>& jweb_contents, | |
87 const JavaParamRef<jstring>& jurl) { | |
88 content::WebContents* web_contents = | |
89 content::WebContents::FromJavaWebContents(jweb_contents); | |
90 DCHECK(web_contents); | |
91 | |
92 std::string url(ConvertJavaStringToUTF8(env, jurl)); | |
93 | |
94 return AppBannerSettingsHelper::ShouldShowBanner( | |
95 web_contents, | |
96 GURL(url), | |
97 InstantAppsSettings::kInstantAppsKey, | |
98 base::Time::Now()) == InstallableStatusCode::NO_ERROR_DETECTED; | |
99 } | |
100 | |
101 bool RegisterInstantAppsSettings(JNIEnv* env) { | |
102 return RegisterNativesImpl(env); | |
103 } | |
OLD | NEW |