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 18 matching lines...) Expand all Loading... |
60 | 60 |
61 // Initialize the fetcher by requesting the information about the page from | 61 // Initialize the fetcher by requesting the information about the page from |
62 // the renderer process. The initialization is asynchronous and | 62 // the renderer process. The initialization is asynchronous and |
63 // OnDidGetWebApplicationInfo is expected to be called when finished. | 63 // OnDidGetWebApplicationInfo is expected to be called when finished. |
64 AddToHomescreenDataFetcher(content::WebContents* web_contents, | 64 AddToHomescreenDataFetcher(content::WebContents* web_contents, |
65 int ideal_icon_size_in_px, | 65 int ideal_icon_size_in_px, |
66 int minimum_icon_size_in_px, | 66 int minimum_icon_size_in_px, |
67 int ideal_splash_image_size_in_px, | 67 int ideal_splash_image_size_in_px, |
68 int minimum_splash_image_size_in_px, | 68 int minimum_splash_image_size_in_px, |
69 int badge_size_in_px, | 69 int badge_size_in_px, |
| 70 int data_timeout_ms, |
70 bool check_webapk_compatible, | 71 bool check_webapk_compatible, |
71 Observer* observer); | 72 Observer* observer); |
72 | 73 |
73 // IPC message received when the initialization is finished. | 74 // IPC message received when the initialization is finished. |
74 void OnDidGetWebApplicationInfo(const WebApplicationInfo& web_app_info); | 75 void OnDidGetWebApplicationInfo(const WebApplicationInfo& web_app_info); |
75 | 76 |
76 // Accessors, etc. | 77 // Accessors, etc. |
77 void set_weak_observer(Observer* observer) { weak_observer_ = observer; } | 78 void set_weak_observer(Observer* observer) { weak_observer_ = observer; } |
78 const SkBitmap& badge_icon() const { return badge_icon_; } | 79 const SkBitmap& badge_icon() const { return badge_icon_; } |
79 const SkBitmap& primary_icon() const { return primary_icon_; } | 80 const SkBitmap& primary_icon() const { return primary_icon_; } |
80 ShortcutInfo& shortcut_info() { return shortcut_info_; } | 81 ShortcutInfo& shortcut_info() { return shortcut_info_; } |
81 | 82 |
82 private: | 83 private: |
83 friend class base::RefCounted<AddToHomescreenDataFetcher>; | 84 friend class base::RefCounted<AddToHomescreenDataFetcher>; |
84 | 85 |
85 ~AddToHomescreenDataFetcher() override; | 86 ~AddToHomescreenDataFetcher() override; |
86 | 87 |
87 // WebContentsObserver: | 88 // WebContentsObserver: |
88 bool OnMessageReceived(const IPC::Message& message, | 89 bool OnMessageReceived(const IPC::Message& message, |
89 content::RenderFrameHost* sender) override; | 90 content::RenderFrameHost* sender) override; |
90 | 91 |
91 // Called if either InstallableManager or the favicon fetch takes too long. | 92 // Called if either InstallableManager or the favicon fetch takes too long. |
92 void OnDataTimedout(); | 93 void OnDataTimedout(); |
93 | 94 |
94 // Called when InstallableManager finishes looking for a manifest and icon. | 95 // Called when InstallableManager finishes looking for a manifest and icon. |
| 96 void OnDidGetManifestAndIcons(const InstallableData& data); |
| 97 |
| 98 // Called when InstallableManager finishes checking for installability. |
95 void OnDidPerformInstallableCheck(const InstallableData& data); | 99 void OnDidPerformInstallableCheck(const InstallableData& data); |
96 | 100 |
97 // Grabs the favicon for the current URL. | 101 // Grabs the favicon for the current URL. |
98 void FetchFavicon(); | 102 void FetchFavicon(); |
99 void OnFaviconFetched( | 103 void OnFaviconFetched( |
100 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 104 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
101 | 105 |
102 // Creates the launcher icon from the given bitmap. shortcut_info_.url is | 106 // 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 | 107 // used to generate an icon if there is no bitmap in |bitmap_result| or the |
104 // bitmap is not large enough. | 108 // bitmap is not large enough. |
105 SkBitmap CreateLauncherIconFromFaviconInBackground( | 109 SkBitmap CreateLauncherIconFromFaviconInBackground( |
106 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 110 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
107 | 111 |
108 // Creates the launcher icon from the given |raw_icon|. | 112 // Creates the primary launcher icon from the given |icon|. |
109 void CreateLauncherIcon(const SkBitmap& raw_icon); | 113 void CreateLauncherIcon(const SkBitmap& icon); |
110 SkBitmap CreateLauncherIconInBackground(const SkBitmap& raw_icon); | 114 SkBitmap CreateLauncherIconInBackground(const SkBitmap& icon); |
111 | 115 |
112 // Notifies the observer that the shortcut data is all available. | 116 // Notifies the observer that the shortcut data is all available. |
113 void NotifyObserver(const SkBitmap& icon); | 117 void NotifyObserver(const SkBitmap& icon); |
114 | 118 |
| 119 InstallableManager* installable_manager_; |
115 Observer* weak_observer_; | 120 Observer* weak_observer_; |
116 | 121 |
117 // The icons must only be set on the UI thread for thread safety. | 122 // The icons must only be set on the UI thread for thread safety. |
| 123 SkBitmap raw_primary_icon_; |
118 SkBitmap badge_icon_; | 124 SkBitmap badge_icon_; |
119 SkBitmap primary_icon_; | 125 SkBitmap primary_icon_; |
120 ShortcutInfo shortcut_info_; | 126 ShortcutInfo shortcut_info_; |
121 | 127 |
122 base::CancelableTaskTracker favicon_task_tracker_; | 128 base::CancelableTaskTracker favicon_task_tracker_; |
123 base::OneShotTimer data_timeout_timer_; | 129 base::OneShotTimer data_timeout_timer_; |
124 | 130 |
125 const int ideal_icon_size_in_px_; | 131 const int ideal_icon_size_in_px_; |
126 const int minimum_icon_size_in_px_; | 132 const int minimum_icon_size_in_px_; |
127 const int ideal_splash_image_size_in_px_; | 133 const int ideal_splash_image_size_in_px_; |
128 const int minimum_splash_image_size_in_px_; | 134 const int minimum_splash_image_size_in_px_; |
129 const int badge_size_in_px_; | 135 const int badge_size_in_px_; |
| 136 const int data_timeout_ms_; |
130 | 137 |
131 // Indicates whether to check WebAPK compatibility. | 138 // Indicates whether to check WebAPK compatibility. |
132 bool check_webapk_compatibility_; | 139 bool check_webapk_compatibility_; |
133 bool is_waiting_for_web_application_info_; | 140 bool is_waiting_for_web_application_info_; |
134 bool is_installable_check_complete_; | 141 bool is_installable_check_complete_; |
135 bool is_icon_saved_; | 142 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 |