| 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/banners/app_banner_data_fetcher.h" | 5 #include "chrome/browser/banners/app_banner_data_fetcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/banners/app_banner_debug_log.h" | 10 #include "chrome/browser/banners/app_banner_debug_log.h" |
| 11 #include "chrome/browser/banners/app_banner_metrics.h" | 11 #include "chrome/browser/banners/app_banner_metrics.h" |
| 12 #include "chrome/browser/banners/app_banner_settings_helper.h" | 12 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 13 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 13 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/infobars/infobar_service.h" | 15 #include "chrome/browser/infobars/infobar_service.h" |
| 16 #include "chrome/browser/manifest/manifest_icon_selector.h" | 16 #include "chrome/browser/manifest/manifest_icon_selector.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/render_messages.h" | 18 #include "chrome/common/render_messages.h" |
| 19 #include "chrome/common/web_application_info.h" |
| 19 #include "components/infobars/core/infobar.h" | 20 #include "components/infobars/core/infobar.h" |
| 20 #include "components/rappor/rappor_utils.h" | 21 #include "components/rappor/rappor_utils.h" |
| 21 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
| 22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/navigation_details.h" | 24 #include "content/public/browser/navigation_details.h" |
| 24 #include "content/public/browser/render_frame_host.h" | 25 #include "content/public/browser/render_frame_host.h" |
| 25 #include "content/public/browser/service_worker_context.h" | 26 #include "content/public/browser/service_worker_context.h" |
| 26 #include "content/public/browser/storage_partition.h" | 27 #include "content/public/browser/storage_partition.h" |
| 27 #include "net/base/load_flags.h" | 28 #include "net/base/load_flags.h" |
| 28 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" | 29 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" |
| 29 #include "ui/gfx/screen.h" | 30 #include "ui/gfx/screen.h" |
| 30 | 31 |
| 32 #if !defined(OS_ANDROID) |
| 33 #include "chrome/browser/banners/app_banner_infobar_delegate.h" |
| 34 #include "chrome/browser/extensions/bookmark_app_helper.h" |
| 35 #endif |
| 36 |
| 31 namespace { | 37 namespace { |
| 32 | 38 |
| 33 base::TimeDelta gTimeDeltaForTesting; | 39 base::TimeDelta gTimeDeltaForTesting; |
| 34 int gCurrentRequestID = -1; | 40 int gCurrentRequestID = -1; |
| 35 | 41 |
| 36 // The requirement for now is an image/png that is at least 144x144. | 42 // The requirement for now is an image/png that is at least 144x144. |
| 37 const int kIconMinimumSize = 144; | 43 const int kIconMinimumSize = 144; |
| 38 bool DoesManifestContainRequiredIcon(const content::Manifest& manifest) { | 44 bool DoesManifestContainRequiredIcon(const content::Manifest& manifest) { |
| 39 for (const auto& icon : manifest.icons) { | 45 for (const auto& icon : manifest.icons) { |
| 40 if (!EqualsASCII(icon.type.string(), "image/png")) | 46 if (!EqualsASCII(icon.type.string(), "image/png")) |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(AppBannerDataFetcher, message, | 135 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(AppBannerDataFetcher, message, |
| 130 render_frame_host) | 136 render_frame_host) |
| 131 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AppBannerPromptReply, | 137 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AppBannerPromptReply, |
| 132 OnBannerPromptReply) | 138 OnBannerPromptReply) |
| 133 IPC_MESSAGE_UNHANDLED(handled = false) | 139 IPC_MESSAGE_UNHANDLED(handled = false) |
| 134 IPC_END_MESSAGE_MAP() | 140 IPC_END_MESSAGE_MAP() |
| 135 | 141 |
| 136 return handled; | 142 return handled; |
| 137 } | 143 } |
| 138 | 144 |
| 145 void AppBannerDataFetcher::FinishCreateBookmarkApp( |
| 146 const extensions::Extension* extension, |
| 147 const WebApplicationInfo& web_app_info) { |
| 148 content::WebContents* web_contents = GetWebContents(); |
| 149 if (web_contents) { |
| 150 if (extension == nullptr) { |
| 151 AppBannerSettingsHelper::RecordBannerDismissEvent( |
| 152 web_contents, web_app_data_.start_url.spec(), |
| 153 "AppBanner.WebApp.Dismissed", event_request_id_); |
| 154 } else { |
| 155 AppBannerSettingsHelper::RecordBannerWebInstallEvent( |
| 156 web_contents, web_app_data_.start_url.spec(), |
| 157 "AppBanner.WebApp.Installed", event_request_id_); |
| 158 } |
| 159 } |
| 160 } |
| 161 |
| 139 void AppBannerDataFetcher::OnBannerPromptReply( | 162 void AppBannerDataFetcher::OnBannerPromptReply( |
| 140 content::RenderFrameHost* render_frame_host, | 163 content::RenderFrameHost* render_frame_host, |
| 141 int request_id, | 164 int request_id, |
| 142 blink::WebAppBannerPromptReply reply) { | 165 blink::WebAppBannerPromptReply reply) { |
| 143 content::WebContents* web_contents = GetWebContents(); | 166 content::WebContents* web_contents = GetWebContents(); |
| 144 if (!CheckFetcherIsStillAlive(web_contents) || | 167 if (!CheckFetcherIsStillAlive(web_contents) || |
| 145 request_id != event_request_id_) { | 168 request_id != event_request_id_) { |
| 146 Cancel(); | 169 Cancel(); |
| 147 return; | 170 return; |
| 148 } | 171 } |
| 149 | 172 |
| 150 // The renderer might have requested the prompt to be canceled. | 173 // The renderer might have requested the prompt to be canceled. |
| 151 if (reply == blink::WebAppBannerPromptReply::Cancel) { | 174 if (reply == blink::WebAppBannerPromptReply::Cancel) { |
| 152 OutputDeveloperNotShownMessage(web_contents, kRendererRequestCancel); | 175 OutputDeveloperNotShownMessage(web_contents, kRendererRequestCancel); |
| 153 Cancel(); | 176 Cancel(); |
| 154 return; | 177 return; |
| 155 } | 178 } |
| 156 | 179 |
| 157 // Definitely going to show the banner now. | 180 // Definitely going to show the banner now. |
| 158 FOR_EACH_OBSERVER(Observer, observer_list_, | 181 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 159 OnDecidedWhetherToShow(this, true)); | 182 OnDecidedWhetherToShow(this, true)); |
| 160 | 183 |
| 161 infobars::InfoBar* infobar = CreateBanner(app_icon_.get(), app_title_); | 184 CreateBanner(app_icon_.get(), app_title_); |
| 162 if (infobar) { | |
| 163 InfoBarService::FromWebContents(web_contents)->AddInfoBar( | |
| 164 make_scoped_ptr(infobar)); | |
| 165 } | |
| 166 is_active_ = false; | 185 is_active_ = false; |
| 167 } | 186 } |
| 168 | 187 |
| 169 AppBannerDataFetcher::~AppBannerDataFetcher() { | 188 AppBannerDataFetcher::~AppBannerDataFetcher() { |
| 170 FOR_EACH_OBSERVER(Observer, observer_list_, OnFetcherDestroyed(this)); | 189 FOR_EACH_OBSERVER(Observer, observer_list_, OnFetcherDestroyed(this)); |
| 171 } | 190 } |
| 172 | 191 |
| 173 std::string AppBannerDataFetcher::GetBannerType() { | 192 std::string AppBannerDataFetcher::GetBannerType() { |
| 174 return "web"; | 193 return "web"; |
| 175 } | 194 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 198 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 217 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 199 bitmap_fetcher_.reset(new chrome::BitmapFetcher(image_url, this)); | 218 bitmap_fetcher_.reset(new chrome::BitmapFetcher(image_url, this)); |
| 200 bitmap_fetcher_->Start( | 219 bitmap_fetcher_->Start( |
| 201 profile->GetRequestContext(), | 220 profile->GetRequestContext(), |
| 202 std::string(), | 221 std::string(), |
| 203 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 222 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 204 net::LOAD_NORMAL); | 223 net::LOAD_NORMAL); |
| 205 return true; | 224 return true; |
| 206 } | 225 } |
| 207 | 226 |
| 227 // This method is overridden on Android to provide a mobile-specific |
| 228 // implementation. The guards are required to avoid missing references to the |
| 229 // bookmark app helper, which is *not* compiled on Android. |
| 208 infobars::InfoBar* AppBannerDataFetcher::CreateBanner( | 230 infobars::InfoBar* AppBannerDataFetcher::CreateBanner( |
| 209 const SkBitmap* icon, | 231 const SkBitmap* icon, |
| 210 const base::string16& title) { | 232 const base::string16& title) { |
| 211 content::WebContents* web_contents = GetWebContents(); | 233 content::WebContents* web_contents = GetWebContents(); |
| 212 DCHECK(web_contents && !web_app_data_.IsEmpty()); | 234 DCHECK(web_contents && !web_app_data_.IsEmpty()); |
| 235 infobars::InfoBar* infobar = nullptr; |
| 213 | 236 |
| 214 // TODO(dfalcantara): Desktop doesn't display app banners, yet. Just pretend | 237 #if !defined(OS_ANDROID) |
| 215 // that a banner was shown for testing purposes. | 238 Profile* profile = |
| 216 RecordDidShowBanner("AppBanner.WebApp.Shown"); | 239 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 217 return nullptr; | 240 WebApplicationInfo web_app_info; |
| 241 |
| 242 bookmark_app_helper_.reset( |
| 243 new extensions::BookmarkAppHelper(profile, web_app_info, web_contents)); |
| 244 |
| 245 infobar = AppBannerInfoBarDelegate::Create( |
| 246 make_scoped_refptr(this), web_contents, web_app_data(), |
| 247 bookmark_app_helper_.get(), event_request_id()); |
| 248 if (infobar) { |
| 249 RecordDidShowBanner("AppBanner.WebApp.Shown"); |
| 250 } |
| 251 #endif |
| 252 |
| 253 return infobar; |
| 218 } | 254 } |
| 219 | 255 |
| 220 void AppBannerDataFetcher::RecordDidShowBanner(const std::string& event_name) { | 256 void AppBannerDataFetcher::RecordDidShowBanner(const std::string& event_name) { |
| 221 content::WebContents* web_contents = GetWebContents(); | 257 content::WebContents* web_contents = GetWebContents(); |
| 222 DCHECK(web_contents); | 258 DCHECK(web_contents); |
| 223 | 259 |
| 224 AppBannerSettingsHelper::RecordBannerEvent( | 260 AppBannerSettingsHelper::RecordBannerEvent( |
| 225 web_contents, validated_url_, GetAppIdentifier(), | 261 web_contents, validated_url_, GetAppIdentifier(), |
| 226 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, | 262 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, |
| 227 GetCurrentTime()); | 263 GetCurrentTime()); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 return false; | 430 return false; |
| 395 } | 431 } |
| 396 if (!DoesManifestContainRequiredIcon(manifest)) { | 432 if (!DoesManifestContainRequiredIcon(manifest)) { |
| 397 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon); | 433 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon); |
| 398 return false; | 434 return false; |
| 399 } | 435 } |
| 400 return true; | 436 return true; |
| 401 } | 437 } |
| 402 | 438 |
| 403 } // namespace banners | 439 } // namespace banners |
| OLD | NEW |