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 <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 primary icon in the manifest conforming to the |
|
dominickn
2017/01/16 02:10:06
Nit: we're not checking for a primary icon in the
F
2017/01/16 14:37:52
Done. Thanks!
| |
| 40 // parameters, and that the icon can be fetched and isn't an empty bitmap. | 42 // primary icon size parameters, and that the primary icon can be fetched and |
| 41 bool fetch_valid_icon = false; | 43 // isn't an empty bitmap. |
| 44 bool fetch_valid_primary_icon = false; | |
| 42 }; | 45 }; |
| 43 | 46 |
| 44 // This struct is passed to an InstallableCallback when the InstallableManager | 47 // This struct is passed to an InstallableCallback when the InstallableManager |
| 45 // has finished working. Each reference is owned by InstallableManager, and | 48 // has finished working. Each reference is owned by InstallableManager, and |
| 46 // callers should copy any objects which they wish to use later. Non-requested | 49 // callers should copy any objects which they wish to use later. Non-requested |
| 47 // fields will be set to null, empty, or false. | 50 // fields will be set to null, empty, or false. |
| 48 struct InstallableData { | 51 struct InstallableData { |
| 49 // NO_ERROR_DETECTED if there were no issues. | 52 // NO_ERROR_DETECTED if there were no issues. |
| 50 const InstallableStatusCode error_code; | 53 const InstallableStatusCode error_code; |
| 51 | 54 |
| 52 // Empty if the site has no <link rel="manifest"> tag. | 55 // Empty if the site has no <link rel="manifest"> tag. |
| 53 const GURL& manifest_url; | 56 const GURL& manifest_url; |
| 54 | 57 |
| 55 // Empty if the site has an unparseable manifest. | 58 // Empty if the site has an unparseable manifest. |
| 56 const content::Manifest& manifest; | 59 const content::Manifest& manifest; |
| 57 | 60 |
| 58 // Empty if no icon was requested. | 61 // Empty if no primary_icon was requested. |
| 59 const GURL& icon_url; | 62 const GURL& primary_icon_url; |
| 60 | 63 |
| 61 // nullptr if the most appropriate icon couldn't be determined or downloaded. | 64 // nullptr if the most appropriate primary icon couldn't be determined or |
| 62 // The underlying icon is owned by the InstallableManager; clients must copy | 65 // 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 | 66 // 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. | 67 // fetch_valid_primary_icon was true and a primary icon could not be |
| 65 const SkBitmap* icon; | 68 // retrieved, the reason will be in error_code. |
| 69 const SkBitmap* primary_icon; | |
| 66 | 70 |
| 67 // true if the site has a service worker and a viable web app manifest. If | 71 // 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 | 72 // check_installable was true and the site isn't installable, the reason will |
| 69 // be in error_code. | 73 // be in error_code. |
| 70 const bool is_installable; | 74 const bool is_installable; |
| 71 }; | 75 }; |
| 72 | 76 |
| 73 using InstallableCallback = base::Callback<void(const InstallableData&)>; | 77 using InstallableCallback = base::Callback<void(const InstallableData&)>; |
| 74 | 78 |
| 75 // This class is responsible for fetching the resources required to check and | 79 // 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_; | 186 std::map<IconParams, IconProperty> icons_; |
| 183 | 187 |
| 184 bool is_active_; | 188 bool is_active_; |
| 185 | 189 |
| 186 base::WeakPtrFactory<InstallableManager> weak_factory_; | 190 base::WeakPtrFactory<InstallableManager> weak_factory_; |
| 187 | 191 |
| 188 DISALLOW_COPY_AND_ASSIGN(InstallableManager); | 192 DISALLOW_COPY_AND_ASSIGN(InstallableManager); |
| 189 }; | 193 }; |
| 190 | 194 |
| 191 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ | 195 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ |
| OLD | NEW |