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_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
6 #define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ | 6 #define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/task/cancelable_task_tracker.h" | 11 #include "base/task/cancelable_task_tracker.h" |
12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
13 #include "chrome/browser/android/shortcut_info.h" | 13 #include "chrome/browser/android/shortcut_info.h" |
14 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
15 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
16 | 16 |
17 namespace favicon_base { | 17 namespace favicon_base { |
18 struct FaviconRawBitmapResult; | 18 struct FaviconRawBitmapResult; |
19 } | 19 } |
20 | 20 |
21 class GURL; | 21 class GURL; |
| 22 class InstallableManager; |
22 struct InstallableData; | 23 struct InstallableData; |
23 struct WebApplicationInfo; | 24 struct WebApplicationInfo; |
24 | 25 |
25 // Aysnchronously fetches and processes data needed to create a shortcut for an | 26 // Aysnchronously fetches and processes data needed to create a shortcut for an |
26 // Android Home screen launcher. | 27 // Android Home screen launcher. |
27 // | 28 // |
28 // Because of the various asynchronous calls made by this class, it is | 29 // Because of the various asynchronous calls made by this class, it is |
29 // refcounted to prevent the class from being prematurely deleted. If the | 30 // refcounted to prevent the class from being prematurely deleted. If the |
30 // pointer to the ShortcutHelper becomes invalid, the pipeline should kill | 31 // |weak_observer_| pointer becomes invalid, the pipeline should kill itself. |
31 // itself. | |
32 class AddToHomescreenDataFetcher | 32 class AddToHomescreenDataFetcher |
33 : public base::RefCounted<AddToHomescreenDataFetcher>, | 33 : public base::RefCounted<AddToHomescreenDataFetcher>, |
34 public content::WebContentsObserver { | 34 public content::WebContentsObserver { |
35 public: | 35 public: |
36 class Observer { | 36 class Observer { |
37 public: | 37 public: |
38 // Callded when the installable check is compelte. | 38 // Callded when the installable check is compelte. |
39 virtual void OnDidDetermineWebApkCompatibility( | 39 virtual void OnDidDetermineWebApkCompatibility( |
40 bool is_webapk_compatible) = 0; | 40 bool is_webapk_compatible) = 0; |
41 | 41 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 ~AddToHomescreenDataFetcher() override; | 85 ~AddToHomescreenDataFetcher() override; |
86 | 86 |
87 // WebContentsObserver: | 87 // WebContentsObserver: |
88 bool OnMessageReceived(const IPC::Message& message, | 88 bool OnMessageReceived(const IPC::Message& message, |
89 content::RenderFrameHost* sender) override; | 89 content::RenderFrameHost* sender) override; |
90 | 90 |
91 // Called if either InstallableManager or the favicon fetch takes too long. | 91 // Called if either InstallableManager or the favicon fetch takes too long. |
92 void OnDataTimedout(); | 92 void OnDataTimedout(); |
93 | 93 |
94 // Called when InstallableManager finishes looking for a manifest and icon. | 94 // Called when InstallableManager finishes looking for a manifest and icon. |
| 95 void OnDidGetManifestAndIcons(const InstallableData& data); |
| 96 |
| 97 // Called when InstallableManager finishes checking for installability. |
95 void OnDidPerformInstallableCheck(const InstallableData& data); | 98 void OnDidPerformInstallableCheck(const InstallableData& data); |
96 | 99 |
97 // Grabs the favicon for the current URL. | 100 // Grabs the favicon for the current URL. |
98 void FetchFavicon(); | 101 void FetchFavicon(); |
99 void OnFaviconFetched( | 102 void OnFaviconFetched( |
100 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 103 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
101 | 104 |
102 // Creates the launcher icon from the given bitmap. shortcut_info_.url is | 105 // Creates the launcher icon from the given bitmap. shortcut_info_.url is |
103 // used to generate an icon if there is no bitmap in |bitmap_result| or the | 106 // used to generate an icon if there is no bitmap in |bitmap_result| or the |
104 // bitmap is not large enough. | 107 // bitmap is not large enough. |
105 SkBitmap CreateLauncherIconFromFaviconInBackground( | 108 SkBitmap CreateLauncherIconFromFaviconInBackground( |
106 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 109 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
107 | 110 |
108 // Creates the launcher icon from the given |raw_icon|. | 111 // Creates the primary launcher icon from the given |icon|. |
109 void CreateLauncherIcon(const SkBitmap& raw_icon); | 112 void CreateLauncherIcon(const SkBitmap& icon); |
110 SkBitmap CreateLauncherIconInBackground(const SkBitmap& raw_icon); | 113 SkBitmap CreateLauncherIconInBackground(const SkBitmap& icon); |
111 | 114 |
112 // Notifies the observer that the shortcut data is all available. | 115 // Notifies the observer that the shortcut data is all available. |
113 void NotifyObserver(const SkBitmap& icon); | 116 void NotifyObserver(const SkBitmap& icon); |
114 | 117 |
| 118 InstallableManager* installable_manager_; |
115 Observer* weak_observer_; | 119 Observer* weak_observer_; |
116 | 120 |
117 // The icons must only be set on the UI thread for thread safety. | 121 // The icons must only be set on the UI thread for thread safety. |
| 122 SkBitmap raw_primary_icon_; |
118 SkBitmap badge_icon_; | 123 SkBitmap badge_icon_; |
119 SkBitmap primary_icon_; | 124 SkBitmap primary_icon_; |
120 ShortcutInfo shortcut_info_; | 125 ShortcutInfo shortcut_info_; |
121 | 126 |
122 base::CancelableTaskTracker favicon_task_tracker_; | 127 base::CancelableTaskTracker favicon_task_tracker_; |
123 base::OneShotTimer data_timeout_timer_; | 128 base::OneShotTimer data_timeout_timer_; |
124 | 129 |
125 const int ideal_icon_size_in_px_; | 130 const int ideal_icon_size_in_px_; |
126 const int minimum_icon_size_in_px_; | 131 const int minimum_icon_size_in_px_; |
127 const int ideal_splash_image_size_in_px_; | 132 const int ideal_splash_image_size_in_px_; |
128 const int minimum_splash_image_size_in_px_; | 133 const int minimum_splash_image_size_in_px_; |
129 const int badge_size_in_px_; | 134 const int badge_size_in_px_; |
130 | 135 |
131 // Indicates whether to check WebAPK compatibility. | 136 // Indicates whether to check WebAPK compatibility. |
132 bool check_webapk_compatibility_; | 137 bool check_webapk_compatibility_; |
133 bool is_waiting_for_web_application_info_; | 138 bool is_waiting_for_web_application_info_; |
134 bool is_installable_check_complete_; | 139 bool is_installable_check_complete_; |
135 bool is_icon_saved_; | 140 bool is_icon_saved_; |
136 | 141 |
137 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); | 142 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); |
138 }; | 143 }; |
139 | 144 |
140 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ | 145 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
OLD | NEW |