| 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/memory/ref_counted.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 // Converts the icon into one that can be used on the Android Home screen. | 53 // Converts the icon into one that can be used on the Android Home screen. |
| 54 // |is_generated| is an out-param that indicates whether the icon was | 54 // |is_generated| is an out-param that indicates whether the icon was |
| 55 // generated by Chrome. | 55 // generated by Chrome. |
| 56 virtual SkBitmap FinalizeLauncherIconInBackground(const SkBitmap& icon, | 56 virtual SkBitmap FinalizeLauncherIconInBackground(const SkBitmap& icon, |
| 57 const GURL& url, | 57 const GURL& url, |
| 58 bool* is_generated) = 0; | 58 bool* is_generated) = 0; |
| 59 | 59 |
| 60 // Called when all the data needed to create a shortcut is available. | 60 // Called when all the data needed to create a shortcut is available. |
| 61 virtual void OnDataAvailable(const ShortcutInfo& info, | 61 virtual void OnDataAvailable(const ShortcutInfo& info, |
| 62 const SkBitmap& icon) = 0; | 62 const SkBitmap& primary_icon, |
| 63 const SkBitmap& badge_icon) = 0; |
| 63 | 64 |
| 64 protected: | 65 protected: |
| 65 virtual ~Observer() {} | 66 virtual ~Observer() {} |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 // Initialize the fetcher by requesting the information about the page from | 69 // Initialize the fetcher by requesting the information about the page from |
| 69 // the renderer process. The initialization is asynchronous and | 70 // the renderer process. The initialization is asynchronous and |
| 70 // OnDidGetWebApplicationInfo is expected to be called when finished. | 71 // OnDidGetWebApplicationInfo is expected to be called when finished. |
| 71 AddToHomescreenDataFetcher(content::WebContents* web_contents, | 72 AddToHomescreenDataFetcher(content::WebContents* web_contents, |
| 72 int ideal_icon_size_in_px, | 73 int ideal_icon_size_in_px, |
| 73 int minimum_icon_size_in_px, | 74 int minimum_icon_size_in_px, |
| 74 int ideal_splash_image_size_in_px, | 75 int ideal_splash_image_size_in_px, |
| 75 int minimum_splash_image_size_in_px, | 76 int minimum_splash_image_size_in_px, |
| 77 int badge_size_in_px, |
| 76 bool check_webapk_compatible, | 78 bool check_webapk_compatible, |
| 77 Observer* observer); | 79 Observer* observer); |
| 78 | 80 |
| 79 // Returns a callback which fetches the splash screen image to be stored for | 81 // Returns a callback which fetches the splash screen image to be stored for |
| 80 // the webapp with the specified |id|. | 82 // the webapp with the specified |id|. |
| 81 base::Closure FetchSplashScreenImageCallback(const std::string& id); | 83 base::Closure FetchSplashScreenImageCallback(const std::string& id); |
| 82 | 84 |
| 83 // IPC message received when the initialization is finished. | 85 // IPC message received when the initialization is finished. |
| 84 void OnDidGetWebApplicationInfo(const WebApplicationInfo& web_app_info); | 86 void OnDidGetWebApplicationInfo(const WebApplicationInfo& web_app_info); |
| 85 | 87 |
| 86 // Accessors, etc. | 88 // Accessors, etc. |
| 87 void set_weak_observer(Observer* observer) { weak_observer_ = observer; } | 89 void set_weak_observer(Observer* observer) { weak_observer_ = observer; } |
| 88 bool is_ready() const { return is_ready_; } | 90 bool is_ready() const { return is_ready_; } |
| 91 const SkBitmap& badge_icon() const { return badge_icon_; } |
| 92 const SkBitmap& primary_icon() const { return primary_icon_; } |
| 89 ShortcutInfo& shortcut_info() { return shortcut_info_; } | 93 ShortcutInfo& shortcut_info() { return shortcut_info_; } |
| 90 const SkBitmap& shortcut_icon() const { return shortcut_icon_; } | |
| 91 | 94 |
| 92 private: | 95 private: |
| 93 friend class base::RefCounted<AddToHomescreenDataFetcher>; | 96 friend class base::RefCounted<AddToHomescreenDataFetcher>; |
| 94 | 97 |
| 95 ~AddToHomescreenDataFetcher() override; | 98 ~AddToHomescreenDataFetcher() override; |
| 96 | 99 |
| 97 // WebContentsObserver: | 100 // WebContentsObserver: |
| 98 bool OnMessageReceived(const IPC::Message& message) override; | 101 bool OnMessageReceived(const IPC::Message& message) override; |
| 99 | 102 |
| 100 // Called if either InstallableManager or the favicon fetch takes too long. | 103 // Called if either InstallableManager or the favicon fetch takes too long. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 116 | 119 |
| 117 // Creates the launcher icon from the given |raw_icon|. | 120 // Creates the launcher icon from the given |raw_icon|. |
| 118 void CreateLauncherIcon(const SkBitmap& raw_icon); | 121 void CreateLauncherIcon(const SkBitmap& raw_icon); |
| 119 void CreateLauncherIconInBackground(const SkBitmap& raw_icon); | 122 void CreateLauncherIconInBackground(const SkBitmap& raw_icon); |
| 120 | 123 |
| 121 // Notifies the observer that the shortcut data is all available. | 124 // Notifies the observer that the shortcut data is all available. |
| 122 void NotifyObserver(const SkBitmap& icon); | 125 void NotifyObserver(const SkBitmap& icon); |
| 123 | 126 |
| 124 Observer* weak_observer_; | 127 Observer* weak_observer_; |
| 125 | 128 |
| 126 // The icon must only be set on the UI thread for thread safety. | 129 // The icons must only be set on the UI thread for thread safety. |
| 127 SkBitmap shortcut_icon_; | 130 SkBitmap badge_icon_; |
| 131 SkBitmap primary_icon_; |
| 128 ShortcutInfo shortcut_info_; | 132 ShortcutInfo shortcut_info_; |
| 129 GURL splash_screen_url_; | 133 GURL splash_screen_url_; |
| 130 | 134 |
| 131 base::CancelableTaskTracker favicon_task_tracker_; | 135 base::CancelableTaskTracker favicon_task_tracker_; |
| 132 base::Timer data_timeout_timer_; | 136 base::Timer data_timeout_timer_; |
| 133 | 137 |
| 134 const int ideal_icon_size_in_px_; | 138 const int ideal_icon_size_in_px_; |
| 135 const int minimum_icon_size_in_px_; | 139 const int minimum_icon_size_in_px_; |
| 136 const int ideal_splash_image_size_in_px_; | 140 const int ideal_splash_image_size_in_px_; |
| 137 const int minimum_splash_image_size_in_px_; | 141 const int minimum_splash_image_size_in_px_; |
| 142 const int badge_size_in_px_; |
| 138 | 143 |
| 139 // Indicates whether to check WebAPK compatibility. | 144 // Indicates whether to check WebAPK compatibility. |
| 140 bool check_webapk_compatibility_; | 145 bool check_webapk_compatibility_; |
| 141 bool is_waiting_for_web_application_info_; | 146 bool is_waiting_for_web_application_info_; |
| 142 bool is_installable_check_complete_; | 147 bool is_installable_check_complete_; |
| 143 bool is_icon_saved_; | 148 bool is_icon_saved_; |
| 144 bool is_ready_; | 149 bool is_ready_; |
| 145 | 150 |
| 146 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); | 151 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); |
| 147 }; | 152 }; |
| 148 | 153 |
| 149 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ | 154 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
| OLD | NEW |