OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_ANDROID_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_ANDROID_H_ |
6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_ANDROID_H_ | 6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_ANDROID_H_ |
7 | 7 |
8 #include "base/android/jni_android.h" | 8 #include "base/android/scoped_java_ref.h" |
9 #include "base/android/jni_weak_ref.h" | 9 #include "base/callback_forward.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | |
12 #include "chrome/browser/android/banners/app_banner_data_fetcher_android.h" | |
13 #include "chrome/browser/banners/app_banner_debug_log.h" | |
14 #include "chrome/browser/banners/app_banner_manager.h" | 11 #include "chrome/browser/banners/app_banner_manager.h" |
15 #include "content/public/browser/web_contents_user_data.h" | 12 #include "content/public/browser/web_contents_user_data.h" |
16 | 13 |
17 namespace banners { | 14 namespace banners { |
18 class AppBannerDataFetcherAndroid; | |
19 | 15 |
20 // Extends the AppBannerManager to support native Android apps. | 16 // Extends the AppBannerManager to support native Android apps. |
| 17 // This class owns a Java-side AppBannerManager which is used to interface with |
| 18 // the Java runtime for fetching native app data and installing them when |
| 19 // requested. |
| 20 // A site requests a native app banner by setting "prefer_related_applications" |
| 21 // to true in its manifest, and providing at least one related application for |
| 22 // the "play" platform with a Play Store ID. |
| 23 // This class uses that information to request the app's metadata, including an |
| 24 // icon. If successful, the icon is downloaded and the native app banner shown. |
| 25 // Otherwise, if no related applications were detected, or their manifest |
| 26 // entries were invalid, this class falls back to trying to verify if a web app |
| 27 // banner is suitable. |
21 class AppBannerManagerAndroid | 28 class AppBannerManagerAndroid |
22 : public AppBannerManager, | 29 : public AppBannerManager, |
23 public content::WebContentsUserData<AppBannerManagerAndroid> { | 30 public content::WebContentsUserData<AppBannerManagerAndroid> { |
24 public: | 31 public: |
25 explicit AppBannerManagerAndroid(content::WebContents* web_contents); | 32 explicit AppBannerManagerAndroid(content::WebContents* web_contents); |
26 ~AppBannerManagerAndroid() override; | 33 ~AppBannerManagerAndroid() override; |
27 | 34 |
| 35 // Returns a reference to the Java-side AppBannerManager owned by this object. |
28 const base::android::ScopedJavaGlobalRef<jobject>& GetJavaBannerManager() | 36 const base::android::ScopedJavaGlobalRef<jobject>& GetJavaBannerManager() |
29 const; | 37 const; |
30 | 38 |
31 // Return whether a BitmapFetcher is active. | 39 // Returns true if this object is currently active. |
32 bool IsFetcherActive(JNIEnv* env, | 40 bool IsActiveForTesting(JNIEnv* env, |
33 const base::android::JavaParamRef<jobject>& jobj); | 41 const base::android::JavaParamRef<jobject>& jobj); |
34 | 42 |
35 // Called when the Java-side has retrieved information for the app. | 43 // Called when the Java-side has retrieved information for the app. |
36 // Returns |false| if an icon fetch couldn't be kicked off. | 44 // Returns |false| if an icon fetch couldn't be kicked off. |
37 bool OnAppDetailsRetrieved( | 45 bool OnAppDetailsRetrieved( |
38 JNIEnv* env, | 46 JNIEnv* env, |
39 const base::android::JavaParamRef<jobject>& obj, | 47 const base::android::JavaParamRef<jobject>& obj, |
40 const base::android::JavaParamRef<jobject>& japp_data, | 48 const base::android::JavaParamRef<jobject>& japp_data, |
41 const base::android::JavaParamRef<jstring>& japp_title, | 49 const base::android::JavaParamRef<jstring>& japp_title, |
42 const base::android::JavaParamRef<jstring>& japp_package, | 50 const base::android::JavaParamRef<jstring>& japp_package, |
43 const base::android::JavaParamRef<jstring>& jicon_url); | 51 const base::android::JavaParamRef<jstring>& jicon_url); |
44 | 52 |
| 53 // AppBannerManager overrides. |
45 void RequestAppBanner(const GURL& validated_url, bool is_debug_mode) override; | 54 void RequestAppBanner(const GURL& validated_url, bool is_debug_mode) override; |
46 | 55 |
| 56 // Returns a callback which fetches the splash screen image and stores it in |
| 57 // a WebappDataStorage. |
| 58 base::Closure FetchWebappSplashScreenImageCallback( |
| 59 const std::string& webapp_id) override; |
| 60 |
47 // Registers native methods. | 61 // Registers native methods. |
48 static bool Register(JNIEnv* env); | 62 static bool Register(JNIEnv* env); |
49 | 63 |
50 protected: | 64 protected: |
51 AppBannerDataFetcher* CreateAppBannerDataFetcher( | 65 // AppBannerManager overrides. |
52 base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate, | 66 std::string GetAppIdentifier() override; |
53 bool is_debug_mode) override; | 67 std::string GetBannerType() override; |
| 68 int GetIdealIconSizeInDp() override; |
| 69 int GetMinimumIconSizeInDp() override; |
| 70 bool IsWebAppInstalled(content::BrowserContext* browser_context, |
| 71 const GURL& start_url) override; |
| 72 |
| 73 void PerformInstallableCheck() override; |
| 74 void OnAppIconFetched(const SkBitmap& bitmap) override; |
| 75 void ShowBanner() override; |
54 | 76 |
55 private: | 77 private: |
56 friend class content::WebContentsUserData<AppBannerManagerAndroid>; | 78 friend class content::WebContentsUserData<AppBannerManagerAndroid>; |
57 | 79 |
58 // AppBannerDataFetcher::Delegate overrides. | 80 // Creates the Java-side AppBannerManager. |
59 bool HandleNonWebApp(const std::string& platform, | |
60 const GURL& url, | |
61 const std::string& id, | |
62 bool is_debug_mode) override; | |
63 | |
64 void CreateJavaBannerManager(); | 81 void CreateJavaBannerManager(); |
65 | 82 |
66 bool CheckFetcherMatchesContents(bool is_debug_mode); | 83 // Returns true if |platform| and |id| are valid for querying the Play Store. |
67 bool CheckPlatformAndId(const std::string& platform, | 84 bool CheckPlatformAndId(const std::string& platform, |
68 const std::string& id, | 85 const std::string& id); |
69 bool is_debug_mode); | |
70 | 86 |
| 87 // Returns the query value for |name| in |url|, e.g. example.com?name=value. |
71 std::string ExtractQueryValueForName(const GURL& url, | 88 std::string ExtractQueryValueForName(const GURL& url, |
72 const std::string& name); | 89 const std::string& name); |
73 | 90 |
74 // AppBannerManager on the Java side. | 91 // Returns true if |platform|, |url|, and |id| are consistent and can be used |
| 92 // to query the Play Store for a native app. The query may not necessarily |
| 93 // succeed (e.g. |id| doesn't map to anything), but if this method returns |
| 94 // true, only a native app banner may be shown, and the web app banner flow |
| 95 // will not be run. |
| 96 bool CanHandleNonWebApp(const std::string& platform, |
| 97 const GURL& url, |
| 98 const std::string& id); |
| 99 |
| 100 // The Java-side AppBannerManager. |
75 base::android::ScopedJavaGlobalRef<jobject> java_banner_manager_; | 101 base::android::ScopedJavaGlobalRef<jobject> java_banner_manager_; |
76 | 102 |
| 103 // Java-side object containing data about a native app. |
| 104 base::android::ScopedJavaGlobalRef<jobject> native_app_data_; |
| 105 |
| 106 // App package name for a native app banner. |
| 107 std::string native_app_package_; |
| 108 |
77 DISALLOW_COPY_AND_ASSIGN(AppBannerManagerAndroid); | 109 DISALLOW_COPY_AND_ASSIGN(AppBannerManagerAndroid); |
78 }; // class AppBannerManagerAndroid | 110 }; |
79 | 111 |
80 } // namespace banners | 112 } // namespace banners |
81 | 113 |
82 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_ANDROID_H_ | 114 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_ANDROID_H_ |
OLD | NEW |