| 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 <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "chrome/browser/installable/installable_logging.h" | 17 #include "chrome/browser/installable/installable_logging.h" |
| 18 #include "content/public/browser/web_contents_observer.h" | 18 #include "content/public/browser/web_contents_observer.h" |
| 19 #include "content/public/browser/web_contents_user_data.h" | 19 #include "content/public/browser/web_contents_user_data.h" |
| 20 #include "content/public/common/manifest.h" | 20 #include "content/public/common/manifest.h" |
| 21 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
| 22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 23 | 23 |
| 24 // This struct specifies the work to be done by the InstallableManager. | 24 // This struct specifies the work to be done by the InstallableManager. |
| 25 // Data is cached and fetched in the order specified in this struct. A web app | 25 // Data is cached and fetched in the order specified in this struct. A web app |
| 26 // manifest will always be fetched first. | 26 // manifest will always be fetched first. |
| 27 struct InstallableParams { | 27 struct InstallableParams { |
| 28 // The ideal icon size to fetch. Used only if |fetch_valid_icon| is true. | 28 // The ideal primary icon size to fetch. Used only if |
| 29 int ideal_icon_size_in_px = -1; | 29 // |fetch_valid_primary_icon| is true. |
| 30 int ideal_primary_icon_size_in_px = -1; |
| 30 | 31 |
| 31 // The minimum icon size to fetch. Used only if |fetch_valid_icon| is true. | 32 // The minimum primary icon size to fetch. Used only if |
| 32 int minimum_icon_size_in_px = -1; | 33 // |fetch_valid_primary_icon| is true. |
| 34 int minimum_primary_icon_size_in_px = -1; |
| 33 | 35 |
| 34 // Check whether the site is installable. That is, it has a manifest valid for | 36 // Check whether the site is installable. That is, it has a manifest valid for |
| 35 // a web app and a service worker controlling the manifest start URL and the | 37 // a web app and a service worker controlling the manifest start URL and the |
| 36 // current URL. | 38 // current URL. |
| 37 bool check_installable = false; | 39 bool check_installable = false; |
| 38 | 40 |
| 39 // Check whether there is an icon in the manifest conforming to the icon size | 41 // Check whether there is a fetchable, non-empty icon in the manifest |
| 40 // parameters, and that the icon can be fetched and isn't an empty bitmap. | 42 // conforming to the primary icon size parameters. |
| 41 bool fetch_valid_icon = false; | 43 bool fetch_valid_primary_icon = false; |
| 42 }; | 44 }; |
| 43 | 45 |
| 44 // This struct is passed to an InstallableCallback when the InstallableManager | 46 // This struct is passed to an InstallableCallback when the InstallableManager |
| 45 // has finished working. Each reference is owned by InstallableManager, and | 47 // has finished working. Each reference is owned by InstallableManager, and |
| 46 // callers should copy any objects which they wish to use later. Non-requested | 48 // callers should copy any objects which they wish to use later. Non-requested |
| 47 // fields will be set to null, empty, or false. | 49 // fields will be set to null, empty, or false. |
| 48 struct InstallableData { | 50 struct InstallableData { |
| 49 // NO_ERROR_DETECTED if there were no issues. | 51 // NO_ERROR_DETECTED if there were no issues. |
| 50 const InstallableStatusCode error_code; | 52 const InstallableStatusCode error_code; |
| 51 | 53 |
| 52 // Empty if the site has no <link rel="manifest"> tag. | 54 // Empty if the site has no <link rel="manifest"> tag. |
| 53 const GURL& manifest_url; | 55 const GURL& manifest_url; |
| 54 | 56 |
| 55 // Empty if the site has an unparseable manifest. | 57 // Empty if the site has an unparseable manifest. |
| 56 const content::Manifest& manifest; | 58 const content::Manifest& manifest; |
| 57 | 59 |
| 58 // Empty if no icon was requested. | 60 // Empty if no primary_icon was requested. |
| 59 const GURL& icon_url; | 61 const GURL& primary_icon_url; |
| 60 | 62 |
| 61 // nullptr if the most appropriate icon couldn't be determined or downloaded. | 63 // nullptr if the most appropriate primary icon couldn't be determined or |
| 62 // The underlying icon is owned by the InstallableManager; clients must copy | 64 // downloaded. The underlying primary icon is owned by the InstallableManager; |
| 63 // the bitmap if they want to to use it. If fetch_valid_icon was true and an | 65 // clients must copy the bitmap if they want to to use it. If |
| 64 // icon could not be retrieved, the reason will be in error_code. | 66 // fetch_valid_primary_icon was true and a primary icon could not be |
| 65 const SkBitmap* icon; | 67 // retrieved, the reason will be in error_code. |
| 68 const SkBitmap* primary_icon; |
| 66 | 69 |
| 67 // true if the site has a service worker and a viable web app manifest. If | 70 // true if the site has a service worker and a viable web app manifest. If |
| 68 // check_installable was true and the site isn't installable, the reason will | 71 // check_installable was true and the site isn't installable, the reason will |
| 69 // be in error_code. | 72 // be in error_code. |
| 70 const bool is_installable; | 73 const bool is_installable; |
| 71 }; | 74 }; |
| 72 | 75 |
| 73 using InstallableCallback = base::Callback<void(const InstallableData&)>; | 76 using InstallableCallback = base::Callback<void(const InstallableData&)>; |
| 74 | 77 |
| 75 // This class is responsible for fetching the resources required to check and | 78 // This class is responsible for fetching the resources required to check and |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 std::map<IconParams, IconProperty> icons_; | 185 std::map<IconParams, IconProperty> icons_; |
| 183 | 186 |
| 184 bool is_active_; | 187 bool is_active_; |
| 185 | 188 |
| 186 base::WeakPtrFactory<InstallableManager> weak_factory_; | 189 base::WeakPtrFactory<InstallableManager> weak_factory_; |
| 187 | 190 |
| 188 DISALLOW_COPY_AND_ASSIGN(InstallableManager); | 191 DISALLOW_COPY_AND_ASSIGN(InstallableManager); |
| 189 }; | 192 }; |
| 190 | 193 |
| 191 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ | 194 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ |
| OLD | NEW |