| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 is_ready_(false) { | 97 is_ready_(false) { |
| 97 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px); | 98 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px); |
| 98 DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px); | 99 DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px); |
| 99 | 100 |
| 100 // Send a message to the renderer to retrieve information about the page. | 101 // Send a message to the renderer to retrieve information about the page. |
| 101 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); | 102 content::RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
| 103 main_frame->Send( |
| 104 new ChromeFrameMsg_GetWebApplicationInfo(main_frame->GetRoutingID())); |
| 102 } | 105 } |
| 103 | 106 |
| 104 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo( | 107 void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo( |
| 105 const WebApplicationInfo& received_web_app_info) { | 108 const WebApplicationInfo& received_web_app_info) { |
| 106 is_waiting_for_web_application_info_ = false; | 109 is_waiting_for_web_application_info_ = false; |
| 107 if (!web_contents() || !weak_observer_) | 110 if (!web_contents() || !weak_observer_) |
| 108 return; | 111 return; |
| 109 | 112 |
| 110 // Sanitize received_web_app_info. | 113 // Sanitize received_web_app_info. |
| 111 WebApplicationInfo web_app_info = received_web_app_info; | 114 WebApplicationInfo web_app_info = received_web_app_info; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 check_webapk_compatibility_), | 163 check_webapk_compatibility_), |
| 161 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, | 164 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, |
| 162 this)); | 165 this)); |
| 163 } | 166 } |
| 164 | 167 |
| 165 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { | 168 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { |
| 166 DCHECK(!weak_observer_); | 169 DCHECK(!weak_observer_); |
| 167 } | 170 } |
| 168 | 171 |
| 169 bool AddToHomescreenDataFetcher::OnMessageReceived( | 172 bool AddToHomescreenDataFetcher::OnMessageReceived( |
| 170 const IPC::Message& message) { | 173 const IPC::Message& message, |
| 174 content::RenderFrameHost* sender) { |
| 171 if (!is_waiting_for_web_application_info_) | 175 if (!is_waiting_for_web_application_info_) |
| 172 return false; | 176 return false; |
| 173 | 177 |
| 174 bool handled = true; | 178 bool handled = true; |
| 175 | 179 |
| 176 IPC_BEGIN_MESSAGE_MAP(AddToHomescreenDataFetcher, message) | 180 IPC_BEGIN_MESSAGE_MAP(AddToHomescreenDataFetcher, message) |
| 177 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidGetWebApplicationInfo, | 181 IPC_MESSAGE_HANDLER(ChromeFrameHostMsg_DidGetWebApplicationInfo, |
| 178 OnDidGetWebApplicationInfo) | 182 OnDidGetWebApplicationInfo) |
| 179 IPC_MESSAGE_UNHANDLED(handled = false) | 183 IPC_MESSAGE_UNHANDLED(handled = false) |
| 180 IPC_END_MESSAGE_MAP() | 184 IPC_END_MESSAGE_MAP() |
| 181 | 185 |
| 182 return handled; | 186 return handled; |
| 183 } | 187 } |
| 184 | 188 |
| 185 void AddToHomescreenDataFetcher::OnDataTimedout() { | 189 void AddToHomescreenDataFetcher::OnDataTimedout() { |
| 186 if (!web_contents() || !weak_observer_) | 190 if (!web_contents() || !weak_observer_) |
| 187 return; | 191 return; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { | 344 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { |
| 341 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 345 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 342 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 346 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
| 343 return; | 347 return; |
| 344 | 348 |
| 345 is_icon_saved_ = true; | 349 is_icon_saved_ = true; |
| 346 primary_icon_ = primary_icon; | 350 primary_icon_ = primary_icon; |
| 347 is_ready_ = true; | 351 is_ready_ = true; |
| 348 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); | 352 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); |
| 349 } | 353 } |
| OLD | NEW |