Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 #include "chrome/common/web_application_info.h" | 22 #include "chrome/common/web_application_info.h" |
| 23 #include "components/dom_distiller/core/url_utils.h" | 23 #include "components/dom_distiller/core/url_utils.h" |
| 24 #include "components/favicon/core/favicon_service.h" | 24 #include "components/favicon/core/favicon_service.h" |
| 25 #include "components/favicon_base/favicon_types.h" | 25 #include "components/favicon_base/favicon_types.h" |
| 26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/user_metrics.h" | 27 #include "content/public/browser/user_metrics.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/browser/web_contents_observer.h" | 29 #include "content/public/browser/web_contents_observer.h" |
| 30 #include "content/public/common/manifest.h" | 30 #include "content/public/common/manifest.h" |
| 31 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" | 31 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" |
| 32 #include "ui/display/display.h" | 32 #include "ui/display/display.h" |
|
dominickn
2016/12/19 06:23:32
Nit: remove display.h and screen.h includes.
| |
| 33 #include "ui/display/screen.h" | 33 #include "ui/display/screen.h" |
| 34 #include "ui/gfx/codec/png_codec.h" | 34 #include "ui/gfx/codec/png_codec.h" |
| 35 #include "ui/gfx/favicon_size.h" | 35 #include "ui/gfx/favicon_size.h" |
| 36 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 // Looks up the original, online URL of the site requested. The URL from the | 40 // Looks up the original, online URL of the site requested. The URL from the |
| 41 // WebContents may be a distilled article which is not appropriate for a home | 41 // WebContents may be a distilled article which is not appropriate for a home |
| 42 // screen shortcut. | 42 // screen shortcut. |
| 43 GURL GetShortcutUrl(content::BrowserContext* browser_context, | 43 GURL GetShortcutUrl(content::BrowserContext* browser_context, |
| 44 const GURL& actual_url) { | 44 const GURL& actual_url) { |
| 45 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); | 45 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); |
| 46 } | 46 } |
| 47 | 47 |
| 48 InstallableParams ParamsToPerformInstallableCheck(int ideal_icon_size_in_dp, | 48 InstallableParams ParamsToPerformInstallableCheck(int ideal_icon_size_in_px, |
| 49 int minimum_icon_size_in_dp, | 49 int minimum_icon_size_in_px, |
| 50 bool check_installable) { | 50 bool check_installable) { |
| 51 InstallableParams params; | 51 InstallableParams params; |
| 52 params.ideal_icon_size_in_dp = ideal_icon_size_in_dp; | 52 params.ideal_icon_size_in_px = ideal_icon_size_in_px; |
| 53 params.minimum_icon_size_in_dp = minimum_icon_size_in_dp; | 53 params.minimum_icon_size_in_px = minimum_icon_size_in_px; |
| 54 params.check_installable = check_installable; | 54 params.check_installable = check_installable; |
| 55 params.fetch_valid_icon = true; | 55 params.fetch_valid_icon = true; |
| 56 return params; | 56 return params; |
| 57 } | 57 } |
| 58 | 58 |
| 59 } // namespace | 59 } // namespace |
| 60 | 60 |
| 61 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( | 61 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( |
| 62 content::WebContents* web_contents, | 62 content::WebContents* web_contents, |
| 63 int ideal_icon_size_in_dp, | 63 int ideal_icon_size_in_px, |
| 64 int minimum_icon_size_in_dp, | 64 int minimum_icon_size_in_px, |
| 65 int ideal_splash_image_size_in_dp, | 65 int ideal_splash_image_size_in_px, |
| 66 int minimum_splash_image_size_in_dp, | 66 int minimum_splash_image_size_in_px, |
| 67 bool check_webapk_compatibility, | 67 bool check_webapk_compatibility, |
| 68 Observer* observer) | 68 Observer* observer) |
| 69 : WebContentsObserver(web_contents), | 69 : WebContentsObserver(web_contents), |
| 70 weak_observer_(observer), | 70 weak_observer_(observer), |
| 71 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(), | 71 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(), |
| 72 web_contents->GetLastCommittedURL())), | 72 web_contents->GetLastCommittedURL())), |
| 73 data_timeout_timer_(false, false), | 73 data_timeout_timer_(false, false), |
| 74 ideal_icon_size_in_dp_(ideal_icon_size_in_dp), | 74 ideal_icon_size_in_px_(ideal_icon_size_in_px), |
| 75 minimum_icon_size_in_dp_(minimum_icon_size_in_dp), | 75 minimum_icon_size_in_px_(minimum_icon_size_in_px), |
| 76 ideal_splash_image_size_in_dp_(ideal_splash_image_size_in_dp), | 76 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px), |
| 77 minimum_splash_image_size_in_dp_(minimum_splash_image_size_in_dp), | 77 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px), |
| 78 check_webapk_compatibility_(check_webapk_compatibility), | 78 check_webapk_compatibility_(check_webapk_compatibility), |
| 79 is_waiting_for_web_application_info_(true), | 79 is_waiting_for_web_application_info_(true), |
| 80 is_installable_check_complete_(false), | 80 is_installable_check_complete_(false), |
| 81 is_icon_saved_(false), | 81 is_icon_saved_(false), |
| 82 is_ready_(false) { | 82 is_ready_(false) { |
| 83 DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp); | 83 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px); |
| 84 DCHECK(minimum_splash_image_size_in_dp <= ideal_splash_image_size_in_dp); | 84 DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px); |
| 85 | 85 |
| 86 // Send a message to the renderer to retrieve information about the page. | 86 // Send a message to the renderer to retrieve information about the page. |
| 87 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); | 87 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); |
| 88 } | 88 } |
| 89 | 89 |
| 90 base::Closure AddToHomescreenDataFetcher::FetchSplashScreenImageCallback( | 90 base::Closure AddToHomescreenDataFetcher::FetchSplashScreenImageCallback( |
| 91 const std::string& webapp_id) { | 91 const std::string& webapp_id) { |
| 92 return base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents(), | 92 return base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents(), |
| 93 splash_screen_url_, ideal_splash_image_size_in_dp_, | 93 splash_screen_url_, ideal_splash_image_size_in_px_, |
| 94 minimum_splash_image_size_in_dp_, webapp_id); | 94 minimum_splash_image_size_in_px_, webapp_id); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo( | 97 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo( |
| 98 const WebApplicationInfo& received_web_app_info) { | 98 const WebApplicationInfo& received_web_app_info) { |
| 99 is_waiting_for_web_application_info_ = false; | 99 is_waiting_for_web_application_info_ = false; |
| 100 if (!web_contents() || !weak_observer_) | 100 if (!web_contents() || !weak_observer_) |
| 101 return; | 101 return; |
| 102 | 102 |
| 103 // Sanitize received_web_app_info. | 103 // Sanitize received_web_app_info. |
| 104 WebApplicationInfo web_app_info = received_web_app_info; | 104 WebApplicationInfo web_app_info = received_web_app_info; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 InstallableManager::FromWebContents(web_contents()); | 140 InstallableManager::FromWebContents(web_contents()); |
| 141 DCHECK(manager); | 141 DCHECK(manager); |
| 142 | 142 |
| 143 // Kick off a timeout for downloading data. If we haven't finished within the | 143 // Kick off a timeout for downloading data. If we haven't finished within the |
| 144 // timeout, fall back to using a dynamically-generated launcher icon. | 144 // timeout, fall back to using a dynamically-generated launcher icon. |
| 145 data_timeout_timer_.Start( | 145 data_timeout_timer_.Start( |
| 146 FROM_HERE, base::TimeDelta::FromMilliseconds(4000), | 146 FROM_HERE, base::TimeDelta::FromMilliseconds(4000), |
| 147 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this)); | 147 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this)); |
| 148 | 148 |
| 149 manager->GetData( | 149 manager->GetData( |
| 150 ParamsToPerformInstallableCheck(ideal_icon_size_in_dp_, | 150 ParamsToPerformInstallableCheck(ideal_icon_size_in_px_, |
| 151 minimum_icon_size_in_dp_, | 151 minimum_icon_size_in_px_, |
| 152 check_webapk_compatibility_), | 152 check_webapk_compatibility_), |
| 153 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, | 153 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, |
| 154 this)); | 154 this)); |
| 155 } | 155 } |
| 156 | 156 |
| 157 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { | 157 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { |
| 158 DCHECK(!weak_observer_); | 158 DCHECK(!weak_observer_); |
| 159 } | 159 } |
| 160 | 160 |
| 161 bool AddToHomescreenDataFetcher::OnMessageReceived( | 161 bool AddToHomescreenDataFetcher::OnMessageReceived( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 | 205 |
| 206 if (!data.manifest.IsEmpty()) { | 206 if (!data.manifest.IsEmpty()) { |
| 207 content::RecordAction( | 207 content::RecordAction( |
| 208 base::UserMetricsAction("webapps.AddShortcut.Manifest")); | 208 base::UserMetricsAction("webapps.AddShortcut.Manifest")); |
| 209 shortcut_info_.UpdateFromManifest(data.manifest); | 209 shortcut_info_.UpdateFromManifest(data.manifest); |
| 210 shortcut_info_.manifest_url = data.manifest_url; | 210 shortcut_info_.manifest_url = data.manifest_url; |
| 211 } | 211 } |
| 212 | 212 |
| 213 // Save the splash screen URL for the later download. | 213 // Save the splash screen URL for the later download. |
| 214 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon( | 214 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon( |
| 215 data.manifest.icons, ideal_splash_image_size_in_dp_, | 215 data.manifest.icons, ideal_splash_image_size_in_px_, |
| 216 minimum_splash_image_size_in_dp_); | 216 minimum_splash_image_size_in_px_); |
| 217 | 217 |
| 218 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); | 218 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); |
| 219 | 219 |
| 220 if (data.icon) { | 220 if (data.icon) { |
| 221 shortcut_info_.best_icon_url = data.icon_url; | 221 shortcut_info_.best_icon_url = data.icon_url; |
| 222 | 222 |
| 223 CreateLauncherIcon(*(data.icon)); | 223 CreateLauncherIcon(*(data.icon)); |
| 224 return; | 224 return; |
| 225 } | 225 } |
| 226 | 226 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 238 favicon_base::FAVICON, | 238 favicon_base::FAVICON, |
| 239 favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON}; | 239 favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON}; |
| 240 | 240 |
| 241 favicon::FaviconService* favicon_service = | 241 favicon::FaviconService* favicon_service = |
| 242 FaviconServiceFactory::GetForProfile( | 242 FaviconServiceFactory::GetForProfile( |
| 243 Profile::FromBrowserContext(web_contents()->GetBrowserContext()), | 243 Profile::FromBrowserContext(web_contents()->GetBrowserContext()), |
| 244 ServiceAccessType::EXPLICIT_ACCESS); | 244 ServiceAccessType::EXPLICIT_ACCESS); |
| 245 | 245 |
| 246 // Using favicon if its size is not smaller than platform required size, | 246 // Using favicon if its size is not smaller than platform required size, |
| 247 // otherwise using the largest icon among all avaliable icons. | 247 // otherwise using the largest icon among all avaliable icons. |
| 248 int ideal_icon_size_in_px = | 248 int threshold_to_get_any_largest_icon = ideal_icon_size_in_px_ - 1; |
| 249 ideal_icon_size_in_dp_ * | |
| 250 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(); | |
| 251 int threshold_to_get_any_largest_icon = ideal_icon_size_in_px - 1; | |
| 252 favicon_service->GetLargestRawFaviconForPageURL( | 249 favicon_service->GetLargestRawFaviconForPageURL( |
| 253 shortcut_info_.url, icon_types, threshold_to_get_any_largest_icon, | 250 shortcut_info_.url, icon_types, threshold_to_get_any_largest_icon, |
| 254 base::Bind(&AddToHomescreenDataFetcher::OnFaviconFetched, this), | 251 base::Bind(&AddToHomescreenDataFetcher::OnFaviconFetched, this), |
| 255 &favicon_task_tracker_); | 252 &favicon_task_tracker_); |
| 256 } | 253 } |
| 257 | 254 |
| 258 void AddToHomescreenDataFetcher::OnFaviconFetched( | 255 void AddToHomescreenDataFetcher::OnFaviconFetched( |
| 259 const favicon_base::FaviconRawBitmapResult& bitmap_result) { | 256 const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
| 260 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 257 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
| 261 return; | 258 return; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) { | 311 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) { |
| 315 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 312 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 316 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 313 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
| 317 return; | 314 return; |
| 318 | 315 |
| 319 is_icon_saved_ = true; | 316 is_icon_saved_ = true; |
| 320 shortcut_icon_ = icon; | 317 shortcut_icon_ = icon; |
| 321 is_ready_ = true; | 318 is_ready_ = true; |
| 322 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); | 319 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); |
| 323 } | 320 } |
| OLD | NEW |