Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Unified Diff: chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc

Issue 1310223002: webapps: initial addition of splash screen icon downloading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webapps-database-exp
Patch Set: Add call to webapp storage Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
diff --git a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
index e989d277320cc6fa501d9e74346637b49c19d8e9..8a3d65ee6a9a911635ceddde828bcffc0e075da2 100644
--- a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
+++ b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
@@ -8,6 +8,7 @@
#include "base/location.h"
#include "base/strings/string16.h"
#include "base/task/cancelable_task_tracker.h"
+#include "chrome/browser/android/shortcut_helper.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/manifest/manifest_icon_downloader.h"
#include "chrome/browser/manifest/manifest_icon_selector.h"
@@ -31,12 +32,10 @@
using content::Manifest;
-// Android's preferred icon size in DP is 48, as defined in
-// http://developer.android.com/design/style/iconography.html
-const int AddToHomescreenDataFetcher::kPreferredIconSizeInDp = 48;
-
AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
content::WebContents* web_contents,
+ int ideal_icon_size_in_dp,
+ int ideal_splash_icon_size_in_dp,
Observer* observer)
: WebContentsObserver(web_contents),
weak_observer_(observer),
@@ -46,9 +45,8 @@ AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
icon_timeout_timer_(false, false),
shortcut_info_(dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(
web_contents->GetURL())),
- preferred_icon_size_in_px_(kPreferredIconSizeInDp *
- gfx::Screen::GetScreenFor(web_contents->GetNativeView())->
- GetPrimaryDisplay().device_scale_factor()) {
+ ideal_icon_size_in_dp_(ideal_icon_size_in_dp),
+ ideal_splash_icon_size_in_dp_(ideal_splash_icon_size_in_dp) {
// Send a message to the renderer to retrieve information about the page.
is_waiting_for_web_application_info_ = true;
Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id()));
@@ -102,6 +100,7 @@ void AddToHomescreenDataFetcher::OnDidGetManifest(
const content::Manifest& manifest) {
if (!web_contents() || !weak_observer_) return;
+ manifest_ = manifest;
if (!manifest.IsEmpty()) {
content::RecordAction(
base::UserMetricsAction("webapps.AddShortcut.Manifest"));
@@ -110,7 +109,7 @@ void AddToHomescreenDataFetcher::OnDidGetManifest(
GURL icon_src = ManifestIconSelector::FindBestMatchingIcon(
manifest.icons,
- kPreferredIconSizeInDp,
+ ideal_icon_size_in_dp_,
gfx::Screen::GetScreenFor(web_contents()->GetNativeView()));
// If fetching the Manifest icon fails, fallback to the best favicon
@@ -118,7 +117,7 @@ void AddToHomescreenDataFetcher::OnDidGetManifest(
if (!ManifestIconDownloader::Download(
web_contents(),
icon_src,
- kPreferredIconSizeInDp,
+ ideal_icon_size_in_dp_,
base::Bind(&AddToHomescreenDataFetcher::OnManifestIconFetched,
this))) {
FetchFavicon();
@@ -155,6 +154,26 @@ AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() {
DCHECK(!weak_observer_);
}
+void AddToHomescreenDataFetcher::FetchSplashscreenIcon(const std::string& id) {
+ if (manifest_.IsEmpty())
+ return;
+
+ GURL icon_src = ManifestIconSelector::FindBestMatchingIcon(
+ manifest_.icons,
+ ideal_splash_icon_size_in_dp_,
+ gfx::Screen::GetScreenFor(web_contents()->GetNativeView()));
+
+ // This is a fire and forget task. It is not vital for the splashscreen icon
+ // to be downloaded so the result of the download is not checked and neither
+ // is there any fallback option.
+ ManifestIconDownloader::Download(
+ web_contents(),
+ icon_src,
+ ideal_splash_icon_size_in_dp_,
+ base::Bind(&ShortcutHelper::AddSplashscreenIconToWebappData,
+ id));
mlamouri (slow - plz ping) 2015/08/24 16:43:54 nit: "id));" doesn't fit in the previous line?
Lalit Maganti 2015/08/25 11:38:44 Changed to webapp_id which doesn't fit :/
+}
+
void AddToHomescreenDataFetcher::FetchFavicon() {
if (!web_contents() || !weak_observer_) return;
@@ -174,7 +193,10 @@ void AddToHomescreenDataFetcher::FetchFavicon() {
// Using favicon if its size is not smaller than platform required size,
// otherwise using the largest icon among all avaliable icons.
- int threshold_to_get_any_largest_icon = preferred_icon_size_in_px_ - 1;
+ int ideal_icon_size_in_px = ideal_icon_size_in_dp_ *
+ gfx::Screen::GetScreenFor(web_contents()->GetNativeView())->
+ GetPrimaryDisplay().device_scale_factor();
+ int threshold_to_get_any_largest_icon = ideal_icon_size_in_px - 1;
favicon_service->GetLargestRawFaviconForPageURL(
shortcut_info_.url,
icon_types,

Powered by Google App Engine
This is Rietveld 408576698