Chromium Code Reviews| 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 OnDidCheckServiceWorkerStatus( |
| 200 content::ServiceWorkerStatus offline_capability); | |
|
dominickn
2017/03/16 06:21:56
Nit: call the variable status
piotrs
2017/03/17 02:21:37
Done.
| |
| 199 | 201 |
| 200 void CheckAndFetchBestIcon(const IconParams& params); | 202 void CheckAndFetchBestIcon(const IconParams& params); |
| 201 void OnIconFetched( | 203 void OnIconFetched( |
| 202 const GURL icon_url, const IconParams& params, const SkBitmap& bitmap); | 204 const GURL icon_url, const IconParams& params, const SkBitmap& bitmap); |
| 203 | 205 |
| 204 // content::WebContentsObserver overrides | 206 // content::WebContentsObserver overrides |
| 205 void DidFinishNavigation(content::NavigationHandle* handle) override; | 207 void DidFinishNavigation(content::NavigationHandle* handle) override; |
| 206 void WebContentsDestroyed() override; | 208 void WebContentsDestroyed() override; |
| 207 | 209 |
| 208 const GURL& manifest_url() const; | 210 const GURL& manifest_url() const; |
| 209 const content::Manifest& manifest() const; | 211 const content::Manifest& manifest() const; |
| 210 bool is_installable() const; | 212 bool is_installable() const; |
| 211 | 213 |
| 212 // The list of <params, callback> pairs that have come from a call to GetData. | 214 // The list of <params, callback> pairs that have come from a call to GetData. |
| 213 std::vector<Task> tasks_; | 215 std::vector<Task> tasks_; |
| 214 | 216 |
| 215 // Installable properties cached on this object. | 217 // Installable properties cached on this object. |
| 216 std::unique_ptr<ManifestProperty> manifest_; | 218 std::unique_ptr<ManifestProperty> manifest_; |
| 217 std::unique_ptr<InstallableProperty> installable_; | 219 std::unique_ptr<InstallableProperty> installable_; |
| 218 std::map<IconParams, IconProperty> icons_; | 220 std::map<IconParams, IconProperty> icons_; |
| 219 | 221 |
| 220 bool is_active_; | 222 bool is_active_; |
| 221 | 223 |
| 222 base::WeakPtrFactory<InstallableManager> weak_factory_; | 224 base::WeakPtrFactory<InstallableManager> weak_factory_; |
| 223 | 225 |
| 224 DISALLOW_COPY_AND_ASSIGN(InstallableManager); | 226 DISALLOW_COPY_AND_ASSIGN(InstallableManager); |
| 225 }; | 227 }; |
| 226 | 228 |
| 227 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ | 229 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ |
| OLD | NEW |