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/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.
| |
10 #include "base/time/time.h" | |
11 #include "base/values.h" | |
12 #include "chrome/browser/banners/app_banner_settings_helper.h" | |
13 #include "chrome/browser/installable/installable_logging.h" | |
14 #include "content/public/browser/web_contents.h" | |
15 #include "jni/InstantAppsSettings_jni.h" | |
16 #include "url/gurl.h" | |
17 | |
18 using base::android::JavaParamRef; | |
19 using base::android::ConvertJavaStringToUTF8; | |
20 | |
21 const char InstantAppsSettings::kInstantAppsKey[] = "instantapps"; | |
22 | |
23 void InstantAppsSettings::RecordInfoBarShowEvent( | |
24 content::WebContents* web_contents, | |
25 const std::string& url) { | |
26 AppBannerSettingsHelper::RecordBannerEvent( | |
27 web_contents, | |
28 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.
| |
29 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.
| |
30 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, | |
31 base::Time::Now()); | |
32 } | |
33 | |
34 void InstantAppsSettings::RecordInfoBarDismissEvent( | |
35 content::WebContents* web_contents, | |
36 const std::string& url) { | |
37 AppBannerSettingsHelper::RecordBannerEvent( | |
38 web_contents, | |
39 GURL(url).GetOrigin(), | |
dominickn
2016/09/29 07:22:05
Nit: remove GetOrigin() and std::string
Maria
2016/09/30 17:24:40
Done.
| |
40 std::string(kInstantAppsKey), | |
41 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, | |
42 base::Time::Now()); | |
43 } | |
44 | |
45 static void SetInstantAppDefault( | |
46 JNIEnv* env, | |
47 const JavaParamRef<jclass>& clazz, | |
48 const JavaParamRef<jobject>& jweb_contents, | |
49 const JavaParamRef<jstring>& jurl) { | |
50 content::WebContents* web_contents = | |
51 content::WebContents::FromJavaWebContents(jweb_contents); | |
52 DCHECK(web_contents); | |
53 | |
54 std::string url(ConvertJavaStringToUTF8(env, jurl)); | |
55 | |
56 AppBannerSettingsHelper::RecordBannerEvent( | |
57 web_contents, | |
58 GURL(url).GetOrigin(), | |
dominickn
2016/09/29 07:22:05
Nit: remove GetOrigin() and std::string.
Maria
2016/09/30 17:24:41
Done.
| |
59 std::string(InstantAppsSettings::kInstantAppsKey), | |
60 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | |
61 base::Time::Now()); | |
62 } | |
63 | |
64 static jboolean GetInstantAppDefault( | |
65 JNIEnv* env, | |
66 const JavaParamRef<jclass>& clazz, | |
67 const JavaParamRef<jobject>& jweb_contents, | |
68 const JavaParamRef<jstring>& jurl) { | |
69 content::WebContents* web_contents = | |
70 content::WebContents::FromJavaWebContents(jweb_contents); | |
71 DCHECK(web_contents); | |
72 | |
73 std::string url(ConvertJavaStringToUTF8(env, jurl)); | |
74 | |
75 // Don't show if it has been added to the homescreen. | |
76 base::Time added_time = AppBannerSettingsHelper::GetSingleBannerEvent( | |
77 web_contents, | |
78 GURL(url).GetOrigin(), | |
79 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.
| |
80 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN); | |
81 | |
82 return !added_time.is_null(); | |
83 } | |
84 | |
85 static jboolean ShouldShowBanner(JNIEnv* env, | |
86 const JavaParamRef<jclass>& clazz, | |
87 const JavaParamRef<jobject>& jweb_contents, | |
88 const JavaParamRef<jstring>& jurl) { | |
89 content::WebContents* web_contents = | |
90 content::WebContents::FromJavaWebContents(jweb_contents); | |
91 DCHECK(web_contents); | |
92 | |
93 std::string url(ConvertJavaStringToUTF8(env, jurl)); | |
94 | |
95 return AppBannerSettingsHelper::ShouldShowBanner( | |
96 web_contents, | |
97 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.
| |
98 std::string(InstantAppsSettings::kInstantAppsKey), | |
99 base::Time::Now()) == InstallableStatusCode::NO_ERROR_DETECTED; | |
100 } | |
101 | |
102 bool RegisterInstantAppsSettings(JNIEnv* env) { | |
103 return RegisterNativesImpl(env); | |
104 } | |
OLD | NEW |