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 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h" | 5 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 is_waiting_for_web_application_info_(true), | 89 is_waiting_for_web_application_info_(true), |
90 is_icon_saved_(false), | 90 is_icon_saved_(false), |
91 is_ready_(false) { | 91 is_ready_(false) { |
92 DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp); | 92 DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp); |
93 DCHECK(minimum_splash_image_size_in_dp <= ideal_splash_image_size_in_dp); | 93 DCHECK(minimum_splash_image_size_in_dp <= ideal_splash_image_size_in_dp); |
94 | 94 |
95 // Send a message to the renderer to retrieve information about the page. | 95 // Send a message to the renderer to retrieve information about the page. |
96 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); | 96 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); |
97 } | 97 } |
98 | 98 |
| 99 base::Closure AddToHomescreenDataFetcher::FetchSplashScreenImageCallback( |
| 100 const std::string& webapp_id) { |
| 101 return base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents(), |
| 102 splash_screen_url_, ideal_splash_image_size_in_dp_, |
| 103 minimum_splash_image_size_in_dp_, webapp_id); |
| 104 } |
| 105 |
99 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo( | 106 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo( |
100 const WebApplicationInfo& received_web_app_info) { | 107 const WebApplicationInfo& received_web_app_info) { |
101 is_waiting_for_web_application_info_ = false; | 108 is_waiting_for_web_application_info_ = false; |
102 if (!web_contents() || !weak_observer_) | 109 if (!web_contents() || !weak_observer_) |
103 return; | 110 return; |
104 | 111 |
105 // Sanitize received_web_app_info. | 112 // Sanitize received_web_app_info. |
106 WebApplicationInfo web_app_info = received_web_app_info; | 113 WebApplicationInfo web_app_info = received_web_app_info; |
107 web_app_info.title = | 114 web_app_info.title = |
108 web_app_info.title.substr(0, chrome::kMaxMetaTagAttributeLength); | 115 web_app_info.title.substr(0, chrome::kMaxMetaTagAttributeLength); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 favicon_base::FaviconRawBitmapResult())); | 157 favicon_base::FaviconRawBitmapResult())); |
151 | 158 |
152 manager->GetData( | 159 manager->GetData( |
153 ParamsToPerformInstallableCheck(ideal_icon_size_in_dp_, | 160 ParamsToPerformInstallableCheck(ideal_icon_size_in_dp_, |
154 minimum_icon_size_in_dp_, | 161 minimum_icon_size_in_dp_, |
155 check_installable_), | 162 check_installable_), |
156 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, | 163 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, |
157 this)); | 164 this)); |
158 } | 165 } |
159 | 166 |
| 167 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { |
| 168 DCHECK(!weak_observer_); |
| 169 } |
| 170 |
| 171 bool AddToHomescreenDataFetcher::OnMessageReceived( |
| 172 const IPC::Message& message) { |
| 173 if (!is_waiting_for_web_application_info_) |
| 174 return false; |
| 175 |
| 176 bool handled = true; |
| 177 |
| 178 IPC_BEGIN_MESSAGE_MAP(AddToHomescreenDataFetcher, message) |
| 179 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidGetWebApplicationInfo, |
| 180 OnDidGetWebApplicationInfo) |
| 181 IPC_MESSAGE_UNHANDLED(handled = false) |
| 182 IPC_END_MESSAGE_MAP() |
| 183 |
| 184 return handled; |
| 185 } |
| 186 |
| 187 |
160 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( | 188 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( |
161 const InstallableData& data) { | 189 const InstallableData& data) { |
162 if (!web_contents() || !weak_observer_) | 190 if (!web_contents() || !weak_observer_) |
163 return; | 191 return; |
164 | 192 |
165 if (check_installable_) { | 193 if (check_installable_) { |
166 is_waiting_for_installable_check_ = false; | 194 is_waiting_for_installable_check_ = false; |
167 weak_observer_->OnDidDetermineWebApkCompatibility(data.is_installable); | 195 weak_observer_->OnDidDetermineWebApkCompatibility(data.is_installable); |
168 } | 196 } |
169 | 197 |
(...skipping 22 matching lines...) Expand all Loading... |
192 base::Bind( | 220 base::Bind( |
193 &AddToHomescreenDataFetcher::CreateLauncherIconInBackground, | 221 &AddToHomescreenDataFetcher::CreateLauncherIconInBackground, |
194 this, *(data.icon)), | 222 this, *(data.icon)), |
195 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 223 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
196 return; | 224 return; |
197 } | 225 } |
198 | 226 |
199 FetchFavicon(); | 227 FetchFavicon(); |
200 } | 228 } |
201 | 229 |
202 bool AddToHomescreenDataFetcher::OnMessageReceived( | |
203 const IPC::Message& message) { | |
204 if (!is_waiting_for_web_application_info_) | |
205 return false; | |
206 | |
207 bool handled = true; | |
208 | |
209 IPC_BEGIN_MESSAGE_MAP(AddToHomescreenDataFetcher, message) | |
210 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidGetWebApplicationInfo, | |
211 OnDidGetWebApplicationInfo) | |
212 IPC_MESSAGE_UNHANDLED(handled = false) | |
213 IPC_END_MESSAGE_MAP() | |
214 | |
215 return handled; | |
216 } | |
217 | |
218 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { | |
219 DCHECK(!weak_observer_); | |
220 } | |
221 | |
222 base::Closure AddToHomescreenDataFetcher::FetchSplashScreenImageCallback( | |
223 const std::string& webapp_id) { | |
224 return base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents(), | |
225 splash_screen_url_, ideal_splash_image_size_in_dp_, | |
226 minimum_splash_image_size_in_dp_, webapp_id); | |
227 } | |
228 | |
229 void AddToHomescreenDataFetcher::FetchFavicon() { | 230 void AddToHomescreenDataFetcher::FetchFavicon() { |
230 if (!web_contents() || !weak_observer_) | 231 if (!web_contents() || !weak_observer_) |
231 return; | 232 return; |
232 | 233 |
233 if (check_installable_ && is_waiting_for_installable_check_) { | 234 if (check_installable_ && is_waiting_for_installable_check_) { |
234 is_waiting_for_installable_check_ = false; | 235 is_waiting_for_installable_check_ = false; |
235 weak_observer_->OnDidDetermineWebApkCompatibility(false); | 236 weak_observer_->OnDidDetermineWebApkCompatibility(false); |
236 } | 237 } |
237 | 238 |
238 // Grab the best, largest icon we can find to represent this bookmark. | 239 // Grab the best, largest icon we can find to represent this bookmark. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) { | 308 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) { |
308 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 309 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
309 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 310 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
310 return; | 311 return; |
311 | 312 |
312 is_icon_saved_ = true; | 313 is_icon_saved_ = true; |
313 shortcut_icon_ = icon; | 314 shortcut_icon_ = icon; |
314 is_ready_ = true; | 315 is_ready_ = true; |
315 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); | 316 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); |
316 } | 317 } |
OLD | NEW |