| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; |
| 105 web_app_info.title = | 105 web_app_info.title = |
| 106 web_app_info.title.substr(0, chrome::kMaxMetaTagAttributeLength); | 106 web_app_info.title.substr(0, chrome::kMaxMetaTagAttributeLength); |
| 107 web_app_info.description = | |
| 108 web_app_info.description.substr(0, chrome::kMaxMetaTagAttributeLength); | |
| 109 | 107 |
| 110 // Simply set the user-editable title to be the page's title | 108 // Simply set the user-editable title to be the page's title |
| 111 shortcut_info_.user_title = web_app_info.title.empty() | 109 shortcut_info_.user_title = web_app_info.title.empty() |
| 112 ? web_contents()->GetTitle() | 110 ? web_contents()->GetTitle() |
| 113 : web_app_info.title; | 111 : web_app_info.title; |
| 114 shortcut_info_.short_name = shortcut_info_.user_title; | 112 shortcut_info_.short_name = shortcut_info_.user_title; |
| 115 shortcut_info_.name = shortcut_info_.user_title; | 113 shortcut_info_.name = shortcut_info_.user_title; |
| 116 | 114 |
| 117 if (web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE || | 115 if (web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE || |
| 118 web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE_APPLE) { | 116 web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE_APPLE) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 if (!web_contents() || !weak_observer_) | 192 if (!web_contents() || !weak_observer_) |
| 195 return; | 193 return; |
| 196 | 194 |
| 197 is_installable_check_complete_ = true; | 195 is_installable_check_complete_ = true; |
| 198 | 196 |
| 199 if (check_webapk_compatibility_) { | 197 if (check_webapk_compatibility_) { |
| 200 bool webapk_compatible = | 198 bool webapk_compatible = |
| 201 (data.error_code == NO_ERROR_DETECTED && | 199 (data.error_code == NO_ERROR_DETECTED && |
| 202 AreWebManifestUrlsWebApkCompatible(data.manifest)); | 200 AreWebManifestUrlsWebApkCompatible(data.manifest)); |
| 203 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); | 201 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); |
| 202 |
| 203 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag |
| 204 // data received in OnDidGetWebApplicationInfo(). |
| 205 if (webapk_compatible) |
| 206 shortcut_info_ = ShortcutInfo(GURL()); |
| 204 } | 207 } |
| 205 | 208 |
| 206 if (!data.manifest.IsEmpty()) { | 209 if (!data.manifest.IsEmpty()) { |
| 207 content::RecordAction( | 210 content::RecordAction( |
| 208 base::UserMetricsAction("webapps.AddShortcut.Manifest")); | 211 base::UserMetricsAction("webapps.AddShortcut.Manifest")); |
| 209 shortcut_info_.UpdateFromManifest(data.manifest); | 212 shortcut_info_.UpdateFromManifest(data.manifest); |
| 210 shortcut_info_.manifest_url = data.manifest_url; | 213 shortcut_info_.manifest_url = data.manifest_url; |
| 211 } | 214 } |
| 212 | 215 |
| 213 // Save the splash screen URL for the later download. | 216 // Save the splash screen URL for the later download. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) { | 317 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) { |
| 315 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 318 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 316 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 319 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
| 317 return; | 320 return; |
| 318 | 321 |
| 319 is_icon_saved_ = true; | 322 is_icon_saved_ = true; |
| 320 shortcut_icon_ = icon; | 323 shortcut_icon_ = icon; |
| 321 is_ready_ = true; | 324 is_ready_ = true; |
| 322 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); | 325 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); |
| 323 } | 326 } |
| OLD | NEW |