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 // Called when the installable check is complete. |
39 virtual void OnDidDetermineWebApkCompatibility( | 39 virtual void OnDidDetermineWebApkCompatibility( |
40 bool is_webapk_compatible) = 0; | 40 bool is_webapk_compatible) = 0; |
41 | 41 |
42 // Called when the title of the page is available. | 42 // Called when the title of the page is available. Will be called after |
| 43 // OnDidDetermineWebApkCompatibility. |
43 virtual void OnUserTitleAvailable(const base::string16& title) = 0; | 44 virtual void OnUserTitleAvailable(const base::string16& title) = 0; |
44 | 45 |
45 // Converts the icon into one that can be used on the Android Home screen. | 46 // Converts the icon into one that can be used on the Android Home screen. |
46 // |is_generated| is an out-param that indicates whether the icon was | 47 // |is_generated| is an out-param that indicates whether the icon was |
47 // generated by Chrome. | 48 // generated by Chrome. |
48 virtual SkBitmap FinalizeLauncherIconInBackground(const SkBitmap& icon, | 49 virtual SkBitmap FinalizeLauncherIconInBackground(const SkBitmap& icon, |
49 const GURL& url, | 50 const GURL& url, |
50 bool* is_generated) = 0; | 51 bool* is_generated) = 0; |
51 | 52 |
52 // Called when all the data needed to create a shortcut is available. | 53 // Called when all the data needed to create a shortcut is available. |
53 virtual void OnDataAvailable(const ShortcutInfo& info, | 54 virtual void OnDataAvailable(const ShortcutInfo& info, |
54 const SkBitmap& primary_icon, | 55 const SkBitmap& primary_icon, |
55 const SkBitmap& badge_icon) = 0; | 56 const SkBitmap& badge_icon) = 0; |
56 | 57 |
57 protected: | 58 protected: |
58 virtual ~Observer() {} | 59 virtual ~Observer() {} |
59 }; | 60 }; |
60 | 61 |
61 // Initialize the fetcher by requesting the information about the page from | 62 // Initialize the fetcher by requesting the information about the page from |
62 // the renderer process. The initialization is asynchronous and | 63 // the renderer process. The initialization is asynchronous and |
63 // OnDidGetWebApplicationInfo is expected to be called when finished. | 64 // OnDidGetWebApplicationInfo is expected to be called when finished. |
64 AddToHomescreenDataFetcher(content::WebContents* web_contents, | 65 AddToHomescreenDataFetcher(content::WebContents* web_contents, |
65 int ideal_icon_size_in_px, | 66 int ideal_icon_size_in_px, |
66 int minimum_icon_size_in_px, | 67 int minimum_icon_size_in_px, |
67 int ideal_splash_image_size_in_px, | 68 int ideal_splash_image_size_in_px, |
68 int minimum_splash_image_size_in_px, | 69 int minimum_splash_image_size_in_px, |
69 int badge_size_in_px, | 70 int badge_size_in_px, |
| 71 int data_timeout_ms, |
70 bool check_webapk_compatible, | 72 bool check_webapk_compatible, |
71 Observer* observer); | 73 Observer* observer); |
72 | 74 |
73 // IPC message received when the initialization is finished. | 75 // IPC message received when the initialization is finished. |
74 void OnDidGetWebApplicationInfo(const WebApplicationInfo& web_app_info); | 76 void OnDidGetWebApplicationInfo(const WebApplicationInfo& web_app_info); |
75 | 77 |
76 // Accessors, etc. | 78 // Accessors, etc. |
77 void set_weak_observer(Observer* observer) { weak_observer_ = observer; } | 79 void set_weak_observer(Observer* observer) { weak_observer_ = observer; } |
78 const SkBitmap& badge_icon() const { return badge_icon_; } | 80 const SkBitmap& badge_icon() const { return badge_icon_; } |
79 const SkBitmap& primary_icon() const { return primary_icon_; } | 81 const SkBitmap& primary_icon() const { return primary_icon_; } |
80 ShortcutInfo& shortcut_info() { return shortcut_info_; } | 82 ShortcutInfo& shortcut_info() { return shortcut_info_; } |
81 | 83 |
82 private: | 84 private: |
83 friend class base::RefCounted<AddToHomescreenDataFetcher>; | 85 friend class base::RefCounted<AddToHomescreenDataFetcher>; |
84 | 86 |
85 ~AddToHomescreenDataFetcher() override; | 87 ~AddToHomescreenDataFetcher() override; |
86 | 88 |
87 // WebContentsObserver: | 89 // WebContentsObserver: |
88 bool OnMessageReceived(const IPC::Message& message, | 90 bool OnMessageReceived(const IPC::Message& message, |
89 content::RenderFrameHost* sender) override; | 91 content::RenderFrameHost* sender) override; |
90 | 92 |
91 // Called if either InstallableManager or the favicon fetch takes too long. | 93 // Called if either InstallableManager or the favicon fetch takes too long. |
92 void OnDataTimedout(); | 94 void OnDataTimedout(); |
93 | 95 |
94 // Called when InstallableManager finishes looking for a manifest and icon. | 96 // Called when InstallableManager finishes looking for a manifest and icon. |
| 97 void OnDidGetManifestAndIcons(const InstallableData& data); |
| 98 |
| 99 // Called when InstallableManager finishes checking for installability. |
95 void OnDidPerformInstallableCheck(const InstallableData& data); | 100 void OnDidPerformInstallableCheck(const InstallableData& data); |
96 | 101 |
97 // Grabs the favicon for the current URL. | 102 // Grabs the favicon for the current URL. |
98 void FetchFavicon(); | 103 void FetchFavicon(); |
99 void OnFaviconFetched( | 104 void OnFaviconFetched( |
100 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 105 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
101 | 106 |
102 // Creates the launcher icon from the given bitmap. shortcut_info_.url is | 107 // 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 | 108 // used to generate an icon if there is no bitmap in |bitmap_result| or the |
104 // bitmap is not large enough. | 109 // bitmap is not large enough. |
105 SkBitmap CreateLauncherIconFromFaviconInBackground( | 110 SkBitmap CreateLauncherIconFromFaviconInBackground( |
106 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 111 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
107 | 112 |
108 // Creates the launcher icon from the given |raw_icon|. | 113 // Creates the primary launcher icon from the given |icon|. |
109 void CreateLauncherIcon(const SkBitmap& raw_icon); | 114 void CreateLauncherIcon(const SkBitmap& icon); |
110 SkBitmap CreateLauncherIconInBackground(const SkBitmap& raw_icon); | 115 SkBitmap CreateLauncherIconInBackground(const SkBitmap& icon); |
111 | 116 |
112 // Notifies the observer that the shortcut data is all available. | 117 // Notifies the observer that the shortcut data is all available. |
113 void NotifyObserver(const SkBitmap& icon); | 118 void NotifyObserver(const SkBitmap& icon); |
114 | 119 |
| 120 InstallableManager* installable_manager_; |
115 Observer* weak_observer_; | 121 Observer* weak_observer_; |
116 | 122 |
117 // The icons must only be set on the UI thread for thread safety. | 123 // The icons must only be set on the UI thread for thread safety. |
| 124 SkBitmap raw_primary_icon_; |
118 SkBitmap badge_icon_; | 125 SkBitmap badge_icon_; |
119 SkBitmap primary_icon_; | 126 SkBitmap primary_icon_; |
120 ShortcutInfo shortcut_info_; | 127 ShortcutInfo shortcut_info_; |
121 | 128 |
122 base::CancelableTaskTracker favicon_task_tracker_; | 129 base::CancelableTaskTracker favicon_task_tracker_; |
123 base::OneShotTimer data_timeout_timer_; | 130 base::OneShotTimer data_timeout_timer_; |
124 | 131 |
125 const int ideal_icon_size_in_px_; | 132 const int ideal_icon_size_in_px_; |
126 const int minimum_icon_size_in_px_; | 133 const int minimum_icon_size_in_px_; |
127 const int ideal_splash_image_size_in_px_; | 134 const int ideal_splash_image_size_in_px_; |
128 const int minimum_splash_image_size_in_px_; | 135 const int minimum_splash_image_size_in_px_; |
129 const int badge_size_in_px_; | 136 const int badge_size_in_px_; |
| 137 const int data_timeout_ms_; |
130 | 138 |
131 // Indicates whether to check WebAPK compatibility. | 139 // Indicates whether to check WebAPK compatibility. |
132 bool check_webapk_compatibility_; | 140 bool check_webapk_compatibility_; |
133 bool is_waiting_for_web_application_info_; | 141 bool is_waiting_for_web_application_info_; |
134 bool is_installable_check_complete_; | 142 bool is_installable_check_complete_; |
135 bool is_icon_saved_; | |
136 | 143 |
137 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); | 144 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); |
138 }; | 145 }; |
139 | 146 |
140 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ | 147 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
OLD | NEW |