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_BANNERS_APP_BANNER_DATA_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ |
6 #define CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ | 6 #define CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h" | 13 #include "chrome/browser/manifest/manifest_icon_downloader.h" |
14 #include "chrome/common/web_application_info.h" | 14 #include "chrome/common/web_application_info.h" |
15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
16 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
17 #include "content/public/common/manifest.h" | 17 #include "content/public/common/manifest.h" |
18 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm ptReply.h" | 18 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm ptReply.h" |
19 | 19 |
20 namespace chrome { | 20 namespace chrome { |
21 class BitmapFetcher; | 21 class BitmapFetcher; |
22 } // namespace chrome | 22 } // namespace chrome |
23 | 23 |
24 namespace infobars { | 24 namespace infobars { |
25 class InfoBar; | 25 class InfoBar; |
26 } // namespace infobars | 26 } // namespace infobars |
27 | 27 |
28 namespace banners { | 28 namespace banners { |
29 class AppBannerDataFetcher; | 29 class AppBannerDataFetcher; |
30 | 30 |
31 // Fetches data required to show a web app banner for the URL currently shown by | 31 // Fetches data required to show a web app banner for the URL currently shown by |
32 // the WebContents. | 32 // the WebContents. |
33 class AppBannerDataFetcher | 33 class AppBannerDataFetcher |
34 : public base::RefCounted<AppBannerDataFetcher>, | 34 : public base::RefCounted<AppBannerDataFetcher>, |
35 public chrome::BitmapFetcherDelegate, | |
36 public content::WebContentsObserver { | 35 public content::WebContentsObserver { |
37 public: | 36 public: |
38 class Observer { | 37 class Observer { |
39 public: | 38 public: |
40 virtual void OnDecidedWhetherToShow(AppBannerDataFetcher* fetcher, | 39 virtual void OnDecidedWhetherToShow(AppBannerDataFetcher* fetcher, |
41 bool will_show) = 0; | 40 bool will_show) = 0; |
42 virtual void OnFetcherDestroyed(AppBannerDataFetcher* fetcher) = 0; | 41 virtual void OnFetcherDestroyed(AppBannerDataFetcher* fetcher) = 0; |
43 }; | 42 }; |
44 | 43 |
45 class Delegate { | 44 class Delegate { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 // opportunity to cancel. | 112 // opportunity to cancel. |
114 void OnBannerPromptReply(content::RenderFrameHost* render_frame_host, | 113 void OnBannerPromptReply(content::RenderFrameHost* render_frame_host, |
115 int request_id, | 114 int request_id, |
116 blink::WebAppBannerPromptReply reply); | 115 blink::WebAppBannerPromptReply reply); |
117 | 116 |
118 // Called when the client has prevented a banner from being shown, and is | 117 // Called when the client has prevented a banner from being shown, and is |
119 // now requesting that it be shown later. | 118 // now requesting that it be shown later. |
120 void OnRequestShowAppBanner(content::RenderFrameHost* render_frame_host, | 119 void OnRequestShowAppBanner(content::RenderFrameHost* render_frame_host, |
121 int request_id); | 120 int request_id); |
122 | 121 |
122 // Called when we know we have a service worker and a manifest. | |
123 void OnHasServiceWorker(content::WebContents* web_contents); | |
gone
2015/07/31 18:09:20
This should be private. Remove the comment; it ma
Lalit Maganti
2015/08/03 08:58:29
protected for future use. Will remove comment.
Lalit Maganti
2015/08/04 17:26:45
Done.
| |
124 | |
123 content::WebContents* GetWebContents(); | 125 content::WebContents* GetWebContents(); |
124 virtual std::string GetAppIdentifier(); | 126 virtual std::string GetAppIdentifier(); |
125 const content::Manifest& web_app_data() { return web_app_data_; } | 127 const content::Manifest& web_app_data() { return web_app_data_; } |
126 void set_app_title(const base::string16& title) { app_title_ = title; } | 128 void set_app_title(const base::string16& title) { app_title_ = title; } |
127 int event_request_id() { return event_request_id_; } | 129 int event_request_id() { return event_request_id_; } |
130 const scoped_ptr<ManifestIconDownloader>& icon_downloader() { return icon_down loader_; } | |
gone
2015/07/31 18:09:20
Why is this accessor necessary? Does anything cal
Lalit Maganti
2015/08/03 08:58:29
For future use.
| |
128 | 131 |
129 // Fetches the icon at the given URL asynchronously, returning |false| if a | 132 // Fetches the icon at the given URL asynchronously, returning |false| if a |
130 // load could not be started. | 133 // load could not be started. |
131 bool FetchIcon(const GURL& image_url); | 134 bool FetchAppIcon(content::WebContents* web_contents, const GURL& url); |
132 | 135 |
133 // Records that a banner was shown. The |event_name| corresponds to the RAPPOR | 136 // Records that a banner was shown. The |event_name| corresponds to the RAPPOR |
134 // metric being recorded. | 137 // metric being recorded. |
135 void RecordDidShowBanner(const std::string& event_name); | 138 void RecordDidShowBanner(const std::string& event_name); |
136 | 139 |
137 private: | 140 private: |
138 // Callbacks for data retrieval. | 141 // Callbacks for data retrieval. |
139 void OnDidGetManifest(const content::Manifest& manifest); | 142 void OnDidGetManifest(const content::Manifest& manifest); |
140 void OnDidCheckHasServiceWorker(bool has_service_worker); | 143 void OnDidCheckHasServiceWorker(bool has_service_worker); |
141 void OnFetchComplete(const GURL& url, const SkBitmap* icon) override; | 144 void OnAppIconFetched(const SkBitmap& bitmap); |
142 | 145 |
143 // Returns whether the given web app has already been installed. | 146 // Returns whether the given web app has already been installed. |
144 // Implemented on desktop platforms only. | 147 // Implemented on desktop platforms only. |
145 virtual bool IsWebAppInstalled(content::BrowserContext* browser_context, | 148 virtual bool IsWebAppInstalled(content::BrowserContext* browser_context, |
146 const GURL& start_url); | 149 const GURL& start_url); |
147 | 150 |
148 // Shows a banner for the app, if the given |icon| is valid. | 151 // Shows a banner for the app, if the given |icon| is valid. |
149 virtual void RequestShowBanner(const SkBitmap* icon); | 152 virtual void RequestShowBanner(content::WebContents* web_contents, |
153 const SkBitmap& icon); | |
150 | 154 |
151 // Record that the banner could be shown at this point, if the triggering | 155 // Record that the banner could be shown at this point, if the triggering |
152 // heuristic allowed. | 156 // heuristic allowed. |
153 void RecordCouldShowBanner(); | 157 void RecordCouldShowBanner(); |
154 | 158 |
155 // Creates a banner for the app using the given |icon|. | 159 // Creates a banner for the app using the given |icon|. |
156 virtual void ShowBanner(const SkBitmap* icon, | 160 virtual void ShowBanner(const SkBitmap* icon, |
157 const base::string16& title) = 0; | 161 const base::string16& title) = 0; |
158 | 162 |
159 // Returns whether the banner should be shown. | 163 // Returns whether the banner should be shown. |
160 bool CheckIfShouldShowBanner(); | 164 bool CheckIfShouldShowBanner(); |
161 | 165 |
162 // Returns whether the fetcher is active and web contents have not been | 166 // Returns whether the fetcher is active and web contents have not been |
163 // closed. | 167 // closed. |
164 bool CheckFetcherIsStillAlive(content::WebContents* web_contents); | 168 bool CheckFetcherIsStillAlive(content::WebContents* web_contents); |
165 | 169 |
166 // Returns whether the given Manifest is following the requirements to show | 170 // Returns whether the given Manifest is following the requirements to show |
167 // a web app banner. | 171 // a web app banner. |
168 static bool IsManifestValidForWebApp(const content::Manifest& manifest, | 172 static bool IsManifestValidForWebApp(const content::Manifest& manifest, |
169 content::WebContents* web_contents); | 173 content::WebContents* web_contents); |
170 | 174 |
171 const int ideal_icon_size_; | 175 const int ideal_icon_size_; |
172 const base::WeakPtr<Delegate> weak_delegate_; | 176 const base::WeakPtr<Delegate> weak_delegate_; |
173 base::ObserverList<Observer> observer_list_; | 177 base::ObserverList<Observer> observer_list_; |
174 bool is_active_; | 178 bool is_active_; |
175 bool was_canceled_by_page_; | 179 bool was_canceled_by_page_; |
176 bool page_requested_prompt_; | 180 bool page_requested_prompt_; |
177 ui::PageTransition transition_type_; | 181 ui::PageTransition transition_type_; |
178 int event_request_id_; | 182 int event_request_id_; |
179 scoped_ptr<chrome::BitmapFetcher> bitmap_fetcher_; | 183 scoped_ptr<ManifestIconDownloader> icon_downloader_; |
180 scoped_ptr<SkBitmap> app_icon_; | 184 scoped_ptr<SkBitmap> app_icon_; |
181 | 185 |
182 GURL validated_url_; | 186 GURL validated_url_; |
183 base::string16 app_title_; | 187 base::string16 app_title_; |
184 content::Manifest web_app_data_; | 188 content::Manifest web_app_data_; |
185 | 189 |
186 friend class AppBannerDataFetcherUnitTest; | 190 friend class AppBannerDataFetcherUnitTest; |
187 friend class base::RefCounted<AppBannerDataFetcher>; | 191 friend class base::RefCounted<AppBannerDataFetcher>; |
188 DISALLOW_COPY_AND_ASSIGN(AppBannerDataFetcher); | 192 DISALLOW_COPY_AND_ASSIGN(AppBannerDataFetcher); |
189 }; | 193 }; |
190 | 194 |
191 } // namespace banners | 195 } // namespace banners |
192 | 196 |
193 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ | 197 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_DATA_FETCHER_H_ |
OLD | NEW |