| 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 #ifndef CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ | 6 #define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" |
| 10 #include "base/task/cancelable_task_tracker.h" | 11 #include "base/task/cancelable_task_tracker.h" |
| 11 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 12 #include "chrome/browser/android/shortcut_info.h" | 13 #include "chrome/browser/android/shortcut_info.h" |
| 13 #include "chrome/common/web_application_info.h" | |
| 14 #include "components/favicon_base/favicon_types.h" | 14 #include "components/favicon_base/favicon_types.h" |
| 15 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 16 #include "content/public/common/manifest.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 class WebContents; | 19 class WebContents; |
| 20 } // namespace content | 20 } // namespace content |
| 21 | 21 |
| 22 namespace IPC { | 22 namespace IPC { |
| 23 class Message; | 23 class Message; |
| 24 } | 24 } |
| 25 | 25 |
| 26 class GURL; | 26 class GURL; |
| 27 struct InstallableData; |
| 28 struct WebApplicationInfo; |
| 27 | 29 |
| 28 // Aysnchronously fetches and processes data needed to create a shortcut for an | 30 // Aysnchronously fetches and processes data needed to create a shortcut for an |
| 29 // Android Home screen launcher. | 31 // Android Home screen launcher. |
| 30 // | 32 // |
| 31 // Because of the various asynchronous calls made by this class, it is | 33 // Because of the various asynchronous calls made by this class, it is |
| 32 // refcounted to prevent the class from being prematurely deleted. If the | 34 // refcounted to prevent the class from being prematurely deleted. If the |
| 33 // pointer to the ShortcutHelper becomes invalid, the pipeline should kill | 35 // pointer to the ShortcutHelper becomes invalid, the pipeline should kill |
| 34 // itself. | 36 // itself. |
| 35 class AddToHomescreenDataFetcher | 37 class AddToHomescreenDataFetcher |
| 36 : public base::RefCounted<AddToHomescreenDataFetcher>, | 38 : public base::RefCounted<AddToHomescreenDataFetcher>, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 63 int minimum_splash_image_size_in_dp, | 65 int minimum_splash_image_size_in_dp, |
| 64 Observer* observer); | 66 Observer* observer); |
| 65 | 67 |
| 66 // Returns a callback which fetches the splash screen image to be stored for | 68 // Returns a callback which fetches the splash screen image to be stored for |
| 67 // the webapp with the specified |id|. | 69 // the webapp with the specified |id|. |
| 68 base::Closure FetchSplashScreenImageCallback(const std::string& id); | 70 base::Closure FetchSplashScreenImageCallback(const std::string& id); |
| 69 | 71 |
| 70 // IPC message received when the initialization is finished. | 72 // IPC message received when the initialization is finished. |
| 71 void OnDidGetWebApplicationInfo(const WebApplicationInfo& web_app_info); | 73 void OnDidGetWebApplicationInfo(const WebApplicationInfo& web_app_info); |
| 72 | 74 |
| 73 // Called when the Manifest has been parsed, or if no Manifest was found. | |
| 74 void OnDidGetManifest(const GURL& manifest_url, | |
| 75 const content::Manifest& manifest); | |
| 76 | |
| 77 // Accessors, etc. | 75 // Accessors, etc. |
| 78 void set_weak_observer(Observer* observer) { weak_observer_ = observer; } | 76 void set_weak_observer(Observer* observer) { weak_observer_ = observer; } |
| 79 bool is_ready() { return is_ready_; } | 77 bool is_ready() { return is_ready_; } |
| 80 ShortcutInfo& shortcut_info() { return shortcut_info_; } | 78 ShortcutInfo& shortcut_info() { return shortcut_info_; } |
| 81 const SkBitmap& shortcut_icon() { return shortcut_icon_; } | 79 const SkBitmap& shortcut_icon() { return shortcut_icon_; } |
| 82 | 80 |
| 83 // WebContentsObserver | 81 // WebContentsObserver |
| 84 bool OnMessageReceived(const IPC::Message& message) override; | 82 bool OnMessageReceived(const IPC::Message& message) override; |
| 85 | 83 |
| 86 private: | 84 private: |
| 87 ~AddToHomescreenDataFetcher() override; | 85 ~AddToHomescreenDataFetcher() override; |
| 88 | 86 |
| 89 // Grabs the favicon for the current URL. | 87 // Grabs the favicon for the current URL. |
| 90 void FetchFavicon(); | 88 void FetchFavicon(); |
| 91 void OnFaviconFetched( | 89 void OnFaviconFetched( |
| 92 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 90 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
| 93 | 91 |
| 92 // Called when InstallableManager finishes looking for a manifest and icon. |
| 93 void OnDidPerformInstallableCheck(const InstallableData& data); |
| 94 |
| 94 // Creates the launcher icon from the given bitmap. | 95 // Creates the launcher icon from the given bitmap. |
| 95 void CreateLauncherIcon( | 96 void CreateLauncherIcon( |
| 96 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 97 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
| 97 | 98 |
| 98 // Callback run after an attempt to download manifest icon has been made. May | |
| 99 // kick off the download of a favicon if it failed (i.e. the bitmap is empty). | |
| 100 void OnManifestIconFetched(const GURL& icon_url, const SkBitmap& icon); | |
| 101 | |
| 102 // Notifies the observer that the shortcut data is all available. | 99 // Notifies the observer that the shortcut data is all available. |
| 103 void NotifyObserver(const SkBitmap& icon); | 100 void NotifyObserver(const SkBitmap& icon); |
| 104 | 101 |
| 105 // Looks up the original, online URL of the site requested. The URL from the | 102 // Looks up the original, online URL of the site requested. The URL from the |
| 106 // WebContents may be an offline page or a distilled article which is not | 103 // WebContents may be an offline page or a distilled article which is not |
| 107 // appropriate for a home screen shortcut. | 104 // appropriate for a home screen shortcut. |
| 108 GURL GetShortcutUrl(const GURL& original_url); | 105 GURL GetShortcutUrl(const GURL& original_url); |
| 109 | 106 |
| 110 Observer* weak_observer_; | 107 Observer* weak_observer_; |
| 111 | 108 |
| 112 bool is_waiting_for_web_application_info_; | 109 bool is_waiting_for_web_application_info_; |
| 113 bool is_icon_saved_; | 110 bool is_icon_saved_; |
| 114 bool is_ready_; | 111 bool is_ready_; |
| 115 base::Timer icon_timeout_timer_; | 112 base::Timer data_timeout_timer_; |
| 116 ShortcutInfo shortcut_info_; | 113 ShortcutInfo shortcut_info_; |
| 117 GURL splash_screen_url_; | 114 GURL splash_screen_url_; |
| 118 | 115 |
| 119 // The icon must only be set on the UI thread for thread safety. | 116 // The icon must only be set on the UI thread for thread safety. |
| 120 SkBitmap shortcut_icon_; | 117 SkBitmap shortcut_icon_; |
| 121 base::CancelableTaskTracker favicon_task_tracker_; | 118 base::CancelableTaskTracker favicon_task_tracker_; |
| 122 | 119 |
| 123 const int ideal_icon_size_in_dp_; | 120 const int ideal_icon_size_in_dp_; |
| 124 const int minimum_icon_size_in_dp_; | 121 const int minimum_icon_size_in_dp_; |
| 125 const int ideal_splash_image_size_in_dp_; | 122 const int ideal_splash_image_size_in_dp_; |
| 126 const int minimum_splash_image_size_in_dp_; | 123 const int minimum_splash_image_size_in_dp_; |
| 127 | 124 |
| 128 friend class base::RefCounted<AddToHomescreenDataFetcher>; | 125 friend class base::RefCounted<AddToHomescreenDataFetcher>; |
| 129 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); | 126 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); |
| 130 }; | 127 }; |
| 131 | 128 |
| 132 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ | 129 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
| OLD | NEW |