OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ |
6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ | 6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ |
7 | 7 |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/jni_weak_ref.h" | 9 #include "base/android/jni_weak_ref.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" |
11 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 12 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
12 #include "content/public/browser/web_contents_observer.h" | 13 #include "content/public/browser/web_contents_observer.h" |
| 14 #include "content/public/common/manifest.h" |
13 | 15 |
14 namespace content { | 16 namespace content { |
15 struct FrameNavigateParams; | 17 struct FrameNavigateParams; |
16 struct LoadCommittedDetails; | 18 struct LoadCommittedDetails; |
17 struct Manifest; | 19 struct Manifest; |
18 } // namespace content | 20 } // namespace content |
19 | 21 |
20 /** | 22 /** |
21 * Manages when an app banner is created or dismissed. | 23 * Manages when an app banner is created or dismissed. |
22 * | 24 * |
(...skipping 28 matching lines...) Expand all Loading... |
51 * | 53 * |
52 * Because of the asynchronous nature of this pipeline, it's entirely possible | 54 * Because of the asynchronous nature of this pipeline, it's entirely possible |
53 * that a request to show a banner is interrupted by another request. The | 55 * that a request to show a banner is interrupted by another request. The |
54 * Java side manages what happens in these situations, which will usually result | 56 * Java side manages what happens in these situations, which will usually result |
55 * in dropping the old banner request on the floor. | 57 * in dropping the old banner request on the floor. |
56 */ | 58 */ |
57 | 59 |
58 namespace banners { | 60 namespace banners { |
59 | 61 |
60 class AppBannerManager : public chrome::BitmapFetcherDelegate, | 62 class AppBannerManager : public chrome::BitmapFetcherDelegate, |
61 public content::WebContentsObserver { | 63 public content::WebContentsObserver, |
| 64 public AppBannerInfoBarDelegate::AppDelegate { |
62 public: | 65 public: |
63 AppBannerManager(JNIEnv* env, jobject obj); | 66 AppBannerManager(JNIEnv* env, jobject obj); |
64 virtual ~AppBannerManager(); | 67 virtual ~AppBannerManager(); |
65 | 68 |
66 // Destroys the AppBannerManager. | 69 // Destroys the AppBannerManager. |
67 void Destroy(JNIEnv* env, jobject obj); | 70 void Destroy(JNIEnv* env, jobject obj); |
68 | 71 |
69 // Blocks a banner for |package_name| from appearing on the domain for |url|. | 72 // Blocks a banner for |package_name| from appearing on the domain for |url|. |
70 void BlockBanner(JNIEnv* env, jobject obj, jstring jurl, jstring jpackage); | 73 void BlockBanner(JNIEnv* env, jobject obj, jstring jurl, jstring jpackage); |
71 | 74 |
72 // Observes a new WebContents, if necessary. | 75 // Observes a new WebContents, if necessary. |
73 void ReplaceWebContents(JNIEnv* env, | 76 void ReplaceWebContents(JNIEnv* env, |
74 jobject obj, | 77 jobject obj, |
75 jobject jweb_contents); | 78 jobject jweb_contents); |
76 | 79 |
77 // Fetches the icon at the give URL. | 80 // Fetches the icon at the given URL asynchronously. |
78 // Returns |false| if this couldn't be kicked off. | 81 // Returns |false| if this couldn't be kicked off. |
79 bool FetchIcon(JNIEnv* env, | 82 bool FetchIcon(JNIEnv* env, |
80 jobject obj, | 83 jobject obj, |
81 jstring jimage_url); | 84 jstring jimage_url); |
82 | 85 |
| 86 // Fetches the icon at the given URL asynchronously. |
| 87 // Returns |false| if this couldn't be kicked off. |
| 88 bool FetchIcon(const GURL& image_url); |
| 89 |
83 // WebContentsObserver overrides. | 90 // WebContentsObserver overrides. |
84 virtual void DidNavigateMainFrame( | 91 virtual void DidNavigateMainFrame( |
85 const content::LoadCommittedDetails& details, | 92 const content::LoadCommittedDetails& details, |
86 const content::FrameNavigateParams& params) override; | 93 const content::FrameNavigateParams& params) override; |
87 virtual void DidFinishLoad(content::RenderFrameHost* render_frame_host, | 94 virtual void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
88 const GURL& validated_url) override; | 95 const GURL& validated_url) override; |
89 virtual bool OnMessageReceived(const IPC::Message& message) override; | 96 virtual bool OnMessageReceived(const IPC::Message& message) override; |
90 | 97 |
91 | |
92 // BitmapFetcherDelegate overrides. | 98 // BitmapFetcherDelegate overrides. |
93 virtual void OnFetchComplete(const GURL url, const SkBitmap* bitmap) override; | 99 virtual void OnFetchComplete(const GURL url, const SkBitmap* bitmap) override; |
94 | 100 |
| 101 // AppBannerInfoBarDelegate::AppDelegate overrides. |
| 102 virtual void Block() const override; |
| 103 virtual void Install() const override; |
| 104 virtual gfx::Image GetIcon() const override; |
| 105 |
95 private: | 106 private: |
| 107 // Gets the preferred icon size for the banner icons. |
| 108 int GetPreferredIconSize(); |
| 109 |
96 // Called when the manifest has been retrieved, or if there is no manifest to | 110 // Called when the manifest has been retrieved, or if there is no manifest to |
97 // retrieve. | 111 // retrieve. |
98 void OnDidGetManifest(const content::Manifest& manifest); | 112 void OnDidGetManifest(const content::Manifest& manifest); |
99 | 113 |
100 // Called when the renderer has returned information about the meta tag. | 114 // Called when the renderer has returned information about the meta tag. |
101 // If there is some metadata for the play store tag, this kicks off the | 115 // If there is some metadata for the play store tag, this kicks off the |
102 // process of showing a banner for the package designated by |tag_content| on | 116 // process of showing a banner for the package designated by |tag_content| on |
103 // the page at the |expected_url|. | 117 // the page at the |expected_url|. |
104 void OnDidRetrieveMetaTagContent(bool success, | 118 void OnDidRetrieveMetaTagContent(bool success, |
105 const std::string& tag_name, | 119 const std::string& tag_name, |
106 const std::string& tag_content, | 120 const std::string& tag_content, |
107 const GURL& expected_url); | 121 const GURL& expected_url); |
108 | 122 |
109 // Fetches the icon for an app. | 123 // Fetches the icon for an app. |
110 scoped_ptr<chrome::BitmapFetcher> fetcher_; | 124 scoped_ptr<chrome::BitmapFetcher> fetcher_; |
111 GURL validated_url_; | 125 GURL validated_url_; |
| 126 content::Manifest manifest_; |
| 127 scoped_ptr<SkBitmap> app_icon_; |
112 | 128 |
113 // AppBannerManager on the Java side. | 129 // AppBannerManager on the Java side. |
114 JavaObjectWeakGlobalRef weak_java_banner_view_manager_; | 130 JavaObjectWeakGlobalRef weak_java_banner_view_manager_; |
115 | 131 |
116 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); | 132 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); |
117 }; // class AppBannerManager | 133 }; // class AppBannerManager |
118 | 134 |
119 // Register native methods | 135 // Register native methods |
120 bool RegisterAppBannerManager(JNIEnv* env); | 136 bool RegisterAppBannerManager(JNIEnv* env); |
121 | 137 |
122 } // namespace banners | 138 } // namespace banners |
123 | 139 |
124 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ | 140 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_MANAGER_H_ |
OLD | NEW |