OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_INSTALLABLE_INSTALLABLE_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ |
6 #define CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ | 6 #define CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <tuple> | 10 #include <tuple> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "chrome/browser/installable/installable_logging.h" | 18 #include "chrome/browser/installable/installable_logging.h" |
| 19 #include "content/public/browser/service_worker_context.h" |
19 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
20 #include "content/public/browser/web_contents_user_data.h" | 21 #include "content/public/browser/web_contents_user_data.h" |
21 #include "content/public/common/manifest.h" | 22 #include "content/public/common/manifest.h" |
22 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
24 | 25 |
25 // This struct specifies the work to be done by the InstallableManager. | 26 // This struct specifies the work to be done by the InstallableManager. |
26 // Data is cached and fetched in the order specified in this struct. A web app | 27 // Data is cached and fetched in the order specified in this struct. A web app |
27 // manifest will always be fetched first. | 28 // manifest will always be fetched first. |
28 struct InstallableParams { | 29 struct InstallableParams { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 const GURL& badge_icon_url; | 85 const GURL& badge_icon_url; |
85 | 86 |
86 // nullptr if the most appropriate badge icon couldn't be determined or | 87 // nullptr if the most appropriate badge icon couldn't be determined or |
87 // downloaded. The underlying badge icon is owned by the InstallableManager; | 88 // downloaded. The underlying badge icon is owned by the InstallableManager; |
88 // clients must copy the bitmap if they want to to use it. Since the badge | 89 // clients must copy the bitmap if they want to to use it. Since the badge |
89 // icon is optional, no error code is set if it cannot be fetched, and clients | 90 // icon is optional, no error code is set if it cannot be fetched, and clients |
90 // specifying fetch_valid_badge_icon must check that the bitmap exists before | 91 // specifying fetch_valid_badge_icon must check that the bitmap exists before |
91 // using it. | 92 // using it. |
92 const SkBitmap* badge_icon; | 93 const SkBitmap* badge_icon; |
93 | 94 |
94 // true if the site has a service worker and a viable web app manifest. If | 95 // true if the site has a service worker with a fetch handler and a viable web |
95 // check_installable was true and the site isn't installable, the reason will | 96 // app manifest. If check_installable was true and the site isn't installable, |
96 // be in error_code. | 97 // the reason will be in error_code. |
97 const bool is_installable; | 98 const bool is_installable; |
98 }; | 99 }; |
99 | 100 |
100 using InstallableCallback = base::Callback<void(const InstallableData&)>; | 101 using InstallableCallback = base::Callback<void(const InstallableData&)>; |
101 | 102 |
102 // This class is responsible for fetching the resources required to check and | 103 // This class is responsible for fetching the resources required to check and |
103 // install a site. | 104 // install a site. |
104 class InstallableManager | 105 class InstallableManager |
105 : public content::WebContentsObserver, | 106 : public content::WebContentsObserver, |
106 public content::WebContentsUserData<InstallableManager> { | 107 public content::WebContentsUserData<InstallableManager> { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 void WorkOnTask(); | 189 void WorkOnTask(); |
189 | 190 |
190 // Data retrieval methods. | 191 // Data retrieval methods. |
191 void FetchManifest(); | 192 void FetchManifest(); |
192 void OnDidGetManifest(const GURL& manifest_url, | 193 void OnDidGetManifest(const GURL& manifest_url, |
193 const content::Manifest& manifest); | 194 const content::Manifest& manifest); |
194 | 195 |
195 void CheckInstallable(); | 196 void CheckInstallable(); |
196 bool IsManifestValidForWebApp(const content::Manifest& manifest); | 197 bool IsManifestValidForWebApp(const content::Manifest& manifest); |
197 void CheckServiceWorker(); | 198 void CheckServiceWorker(); |
198 void OnDidCheckHasServiceWorker(bool has_service_worker); | 199 void OnDidCheckHasServiceWorker(content::ServiceWorkerCapability capability); |
199 | 200 |
200 void CheckAndFetchBestIcon(const IconParams& params); | 201 void CheckAndFetchBestIcon(const IconParams& params); |
201 void OnIconFetched( | 202 void OnIconFetched( |
202 const GURL icon_url, const IconParams& params, const SkBitmap& bitmap); | 203 const GURL icon_url, const IconParams& params, const SkBitmap& bitmap); |
203 | 204 |
204 // content::WebContentsObserver overrides | 205 // content::WebContentsObserver overrides |
205 void DidFinishNavigation(content::NavigationHandle* handle) override; | 206 void DidFinishNavigation(content::NavigationHandle* handle) override; |
206 void WebContentsDestroyed() override; | 207 void WebContentsDestroyed() override; |
207 | 208 |
208 const GURL& manifest_url() const; | 209 const GURL& manifest_url() const; |
209 const content::Manifest& manifest() const; | 210 const content::Manifest& manifest() const; |
210 bool is_installable() const; | 211 bool is_installable() const; |
211 | 212 |
212 // The list of <params, callback> pairs that have come from a call to GetData. | 213 // The list of <params, callback> pairs that have come from a call to GetData. |
213 std::vector<Task> tasks_; | 214 std::vector<Task> tasks_; |
214 | 215 |
215 // Installable properties cached on this object. | 216 // Installable properties cached on this object. |
216 std::unique_ptr<ManifestProperty> manifest_; | 217 std::unique_ptr<ManifestProperty> manifest_; |
217 std::unique_ptr<InstallableProperty> installable_; | 218 std::unique_ptr<InstallableProperty> installable_; |
218 std::map<IconParams, IconProperty> icons_; | 219 std::map<IconParams, IconProperty> icons_; |
219 | 220 |
220 bool is_active_; | 221 bool is_active_; |
221 | 222 |
222 base::WeakPtrFactory<InstallableManager> weak_factory_; | 223 base::WeakPtrFactory<InstallableManager> weak_factory_; |
223 | 224 |
224 DISALLOW_COPY_AND_ASSIGN(InstallableManager); | 225 DISALLOW_COPY_AND_ASSIGN(InstallableManager); |
225 }; | 226 }; |
226 | 227 |
227 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ | 228 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ |
OLD | NEW |