| 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/location.h" | 10 #include "base/location.h" |
| 11 #include "base/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/task_runner_util.h" | 13 #include "base/task_runner_util.h" |
| 14 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/threading/sequenced_worker_pool.h" |
| 15 #include "chrome/browser/android/offline_pages/offline_page_utils.h" | 15 #include "chrome/browser/android/offline_pages/offline_page_utils.h" |
| 16 #include "chrome/browser/android/shortcut_helper.h" | 16 #include "chrome/browser/android/shortcut_helper.h" |
| 17 #include "chrome/browser/android/webapk/webapk_web_manifest_checker.h" | 17 #include "chrome/browser/android/webapk/webapk_web_manifest_checker.h" |
| 18 #include "chrome/browser/favicon/favicon_service_factory.h" | 18 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 19 #include "chrome/browser/installable/installable_manager.h" | 19 #include "chrome/browser/installable/installable_manager.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
| 22 #include "chrome/common/render_messages.h" | 22 #include "chrome/common/render_messages.h" |
| 23 #include "chrome/common/web_application_info.h" | 23 #include "chrome/common/web_application_info.h" |
| 24 #include "components/dom_distiller/core/url_utils.h" | 24 #include "components/dom_distiller/core/url_utils.h" |
| 25 #include "components/favicon/core/favicon_service.h" | 25 #include "components/favicon/core/favicon_service.h" |
| 26 #include "components/favicon_base/favicon_types.h" | 26 #include "components/favicon_base/favicon_types.h" |
| 27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/manifest_icon_selector.h" | 28 #include "content/public/browser/manifest_icon_selector.h" |
| 29 #include "content/public/browser/render_frame_host.h" |
| 29 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 30 #include "content/public/browser/web_contents_observer.h" | 31 #include "content/public/browser/web_contents_observer.h" |
| 31 #include "content/public/common/manifest.h" | 32 #include "content/public/common/manifest.h" |
| 32 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" | 33 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" |
| 33 #include "ui/gfx/codec/png_codec.h" | 34 #include "ui/gfx/codec/png_codec.h" |
| 34 #include "ui/gfx/favicon_size.h" | 35 #include "ui/gfx/favicon_size.h" |
| 35 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px), | 91 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px), |
| 91 badge_size_in_px_(badge_size_in_px), | 92 badge_size_in_px_(badge_size_in_px), |
| 92 check_webapk_compatibility_(check_webapk_compatibility), | 93 check_webapk_compatibility_(check_webapk_compatibility), |
| 93 is_waiting_for_web_application_info_(true), | 94 is_waiting_for_web_application_info_(true), |
| 94 is_installable_check_complete_(false), | 95 is_installable_check_complete_(false), |
| 95 is_icon_saved_(false) { | 96 is_icon_saved_(false) { |
| 96 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px); | 97 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px); |
| 97 DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px); | 98 DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px); |
| 98 | 99 |
| 99 // Send a message to the renderer to retrieve information about the page. | 100 // Send a message to the renderer to retrieve information about the page. |
| 100 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); | 101 content::RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
| 102 main_frame->Send( |
| 103 new ChromeFrameMsg_GetWebApplicationInfo(main_frame->GetRoutingID())); |
| 101 } | 104 } |
| 102 | 105 |
| 103 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo( | 106 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo( |
| 104 const WebApplicationInfo& received_web_app_info) { | 107 const WebApplicationInfo& received_web_app_info) { |
| 105 is_waiting_for_web_application_info_ = false; | 108 is_waiting_for_web_application_info_ = false; |
| 106 if (!web_contents() || !weak_observer_) | 109 if (!web_contents() || !weak_observer_) |
| 107 return; | 110 return; |
| 108 | 111 |
| 109 // Sanitize received_web_app_info. | 112 // Sanitize received_web_app_info. |
| 110 WebApplicationInfo web_app_info = received_web_app_info; | 113 WebApplicationInfo web_app_info = received_web_app_info; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 check_webapk_compatibility_), | 162 check_webapk_compatibility_), |
| 160 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, | 163 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, |
| 161 this)); | 164 this)); |
| 162 } | 165 } |
| 163 | 166 |
| 164 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { | 167 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { |
| 165 DCHECK(!weak_observer_); | 168 DCHECK(!weak_observer_); |
| 166 } | 169 } |
| 167 | 170 |
| 168 bool AddToHomescreenDataFetcher::OnMessageReceived( | 171 bool AddToHomescreenDataFetcher::OnMessageReceived( |
| 169 const IPC::Message& message) { | 172 const IPC::Message& message, |
| 173 content::RenderFrameHost* sender) { |
| 170 if (!is_waiting_for_web_application_info_) | 174 if (!is_waiting_for_web_application_info_) |
| 171 return false; | 175 return false; |
| 172 | 176 |
| 173 bool handled = true; | 177 bool handled = true; |
| 174 | 178 |
| 175 IPC_BEGIN_MESSAGE_MAP(AddToHomescreenDataFetcher, message) | 179 IPC_BEGIN_MESSAGE_MAP(AddToHomescreenDataFetcher, message) |
| 176 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidGetWebApplicationInfo, | 180 IPC_MESSAGE_HANDLER(ChromeFrameHostMsg_DidGetWebApplicationInfo, |
| 177 OnDidGetWebApplicationInfo) | 181 OnDidGetWebApplicationInfo) |
| 178 IPC_MESSAGE_UNHANDLED(handled = false) | 182 IPC_MESSAGE_UNHANDLED(handled = false) |
| 179 IPC_END_MESSAGE_MAP() | 183 IPC_END_MESSAGE_MAP() |
| 180 | 184 |
| 181 return handled; | 185 return handled; |
| 182 } | 186 } |
| 183 | 187 |
| 184 void AddToHomescreenDataFetcher::OnDataTimedout() { | 188 void AddToHomescreenDataFetcher::OnDataTimedout() { |
| 185 if (!web_contents() || !weak_observer_) | 189 if (!web_contents() || !weak_observer_) |
| 186 return; | 190 return; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 342 |
| 339 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { | 343 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { |
| 340 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 344 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 341 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 345 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
| 342 return; | 346 return; |
| 343 | 347 |
| 344 is_icon_saved_ = true; | 348 is_icon_saved_ = true; |
| 345 primary_icon_ = primary_icon; | 349 primary_icon_ = primary_icon; |
| 346 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); | 350 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); |
| 347 } | 351 } |
| OLD | NEW |