| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo( | 107 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo( |
| 108 const WebApplicationInfo& received_web_app_info) { | 108 const WebApplicationInfo& received_web_app_info) { |
| 109 is_waiting_for_web_application_info_ = false; | 109 is_waiting_for_web_application_info_ = false; |
| 110 if (!web_contents() || !weak_observer_) | 110 if (!web_contents() || !weak_observer_) |
| 111 return; | 111 return; |
| 112 | 112 |
| 113 // Sanitize received_web_app_info. | 113 // Sanitize received_web_app_info. |
| 114 WebApplicationInfo web_app_info = received_web_app_info; | 114 WebApplicationInfo web_app_info = received_web_app_info; |
| 115 web_app_info.title = | 115 web_app_info.title = |
| 116 web_app_info.title.substr(0, chrome::kMaxMetaTagAttributeLength); | 116 web_app_info.title.substr(0, chrome::kMaxMetaTagAttributeLength); |
| 117 web_app_info.description = |
| 118 web_app_info.description.substr(0, chrome::kMaxMetaTagAttributeLength); |
| 117 | 119 |
| 118 // Simply set the user-editable title to be the page's title | 120 // Simply set the user-editable title to be the page's title |
| 119 shortcut_info_.user_title = web_app_info.title.empty() | 121 shortcut_info_.user_title = web_app_info.title.empty() |
| 120 ? web_contents()->GetTitle() | 122 ? web_contents()->GetTitle() |
| 121 : web_app_info.title; | 123 : web_app_info.title; |
| 122 shortcut_info_.short_name = shortcut_info_.user_title; | 124 shortcut_info_.short_name = shortcut_info_.user_title; |
| 123 shortcut_info_.name = shortcut_info_.user_title; | 125 shortcut_info_.name = shortcut_info_.user_title; |
| 124 | 126 |
| 125 if (web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE || | 127 if (web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE || |
| 126 web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE_APPLE) { | 128 web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE_APPLE) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 if (!web_contents() || !weak_observer_) | 204 if (!web_contents() || !weak_observer_) |
| 203 return; | 205 return; |
| 204 | 206 |
| 205 is_installable_check_complete_ = true; | 207 is_installable_check_complete_ = true; |
| 206 | 208 |
| 207 if (check_webapk_compatibility_) { | 209 if (check_webapk_compatibility_) { |
| 208 bool webapk_compatible = | 210 bool webapk_compatible = |
| 209 (data.error_code == NO_ERROR_DETECTED && | 211 (data.error_code == NO_ERROR_DETECTED && |
| 210 AreWebManifestUrlsWebApkCompatible(data.manifest)); | 212 AreWebManifestUrlsWebApkCompatible(data.manifest)); |
| 211 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); | 213 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); |
| 212 | |
| 213 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag | |
| 214 // data received in OnDidGetWebApplicationInfo(). | |
| 215 if (webapk_compatible) | |
| 216 shortcut_info_ = ShortcutInfo(GURL()); | |
| 217 } | 214 } |
| 218 | 215 |
| 219 if (!data.manifest.IsEmpty()) { | 216 if (!data.manifest.IsEmpty()) { |
| 220 content::RecordAction( | 217 content::RecordAction( |
| 221 base::UserMetricsAction("webapps.AddShortcut.Manifest")); | 218 base::UserMetricsAction("webapps.AddShortcut.Manifest")); |
| 222 shortcut_info_.UpdateFromManifest(data.manifest); | 219 shortcut_info_.UpdateFromManifest(data.manifest); |
| 223 shortcut_info_.manifest_url = data.manifest_url; | 220 shortcut_info_.manifest_url = data.manifest_url; |
| 224 } | 221 } |
| 225 | 222 |
| 226 // Save the splash screen URL for the later download. | 223 // Save the splash screen URL for the later download. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) { | 324 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) { |
| 328 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 325 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 329 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 326 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
| 330 return; | 327 return; |
| 331 | 328 |
| 332 is_icon_saved_ = true; | 329 is_icon_saved_ = true; |
| 333 shortcut_icon_ = icon; | 330 shortcut_icon_ = icon; |
| 334 is_ready_ = true; | 331 is_ready_ = true; |
| 335 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); | 332 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); |
| 336 } | 333 } |
| OLD | NEW |