| 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/task/cancelable_task_tracker.h" | 10 #include "base/task/cancelable_task_tracker.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 public content::WebContentsObserver { | 37 public content::WebContentsObserver { |
| 38 public: | 38 public: |
| 39 class Observer { | 39 class Observer { |
| 40 public: | 40 public: |
| 41 // Called when the title of the page is available. | 41 // Called when the title of the page is available. |
| 42 virtual void OnUserTitleAvailable(const base::string16& title) = 0; | 42 virtual void OnUserTitleAvailable(const base::string16& title) = 0; |
| 43 | 43 |
| 44 // Converts the icon into one that can be used on the Android Home screen. | 44 // Converts the icon into one that can be used on the Android Home screen. |
| 45 // |is_generated| is an out-param that indicates whether the icon was | 45 // |is_generated| is an out-param that indicates whether the icon was |
| 46 // generated by Chrome. | 46 // generated by Chrome. |
| 47 virtual SkBitmap FinalizeLauncherIcon(const SkBitmap& icon, | 47 virtual SkBitmap FinalizeLauncherIconInBackground(const SkBitmap& icon, |
| 48 const GURL& url, | 48 const GURL& url, |
| 49 bool* is_generated) = 0; | 49 bool* is_generated) = 0; |
| 50 | 50 |
| 51 // Called when all the data needed to create a shortcut is available. | 51 // Called when all the data needed to create a shortcut is available. |
| 52 virtual void OnDataAvailable(const ShortcutInfo& info, | 52 virtual void OnDataAvailable(const ShortcutInfo& info, |
| 53 const SkBitmap& icon) = 0; | 53 const SkBitmap& icon) = 0; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // Initialize the fetcher by requesting the information about the page to the | 56 // Initialize the fetcher by requesting the information about the page to the |
| 57 // renderer process. The initialization is asynchronous and | 57 // renderer process. The initialization is asynchronous and |
| 58 // OnDidGetWebApplicationInfo is expected to be called when finished. | 58 // OnDidGetWebApplicationInfo is expected to be called when finished. |
| 59 AddToHomescreenDataFetcher(content::WebContents* web_contents, | 59 AddToHomescreenDataFetcher(content::WebContents* web_contents, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 84 bool OnMessageReceived(const IPC::Message& message) override; | 84 bool OnMessageReceived(const IPC::Message& message) override; |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 ~AddToHomescreenDataFetcher() override; | 87 ~AddToHomescreenDataFetcher() override; |
| 88 | 88 |
| 89 // Grabs the favicon for the current URL. | 89 // Grabs the favicon for the current URL. |
| 90 void FetchFavicon(); | 90 void FetchFavicon(); |
| 91 void OnFaviconFetched( | 91 void OnFaviconFetched( |
| 92 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 92 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
| 93 | 93 |
| 94 // Creates the launcher icon from the given bitmap. | 94 // Creates the launcher icon from the given bitmap and page URL. The page URL |
| 95 void CreateLauncherIcon( | 95 // is used to generate an icon if there is no bitmap in |bitmap_result| or the |
| 96 // bitmap is not large enough. |
| 97 void CreateLauncherIconInBackground( |
| 98 const GURL& page_url, |
| 96 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 99 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
| 97 | 100 |
| 98 // Callback run after an attempt to download manifest icon has been made. May | 101 // 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). | 102 // 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); | 103 void OnManifestIconFetched(const GURL& icon_url, const SkBitmap& icon); |
| 101 | 104 |
| 102 // Notifies the observer that the shortcut data is all available. | 105 // Notifies the observer that the shortcut data is all available. |
| 103 void NotifyObserver(const SkBitmap& icon); | 106 void NotifyObserver(const GURL& icon_url, const SkBitmap& icon); |
| 104 | 107 |
| 105 // Looks up the original, online URL of the site requested. The URL from the | 108 // 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 | 109 // WebContents may be an offline page or a distilled article which is not |
| 107 // appropriate for a home screen shortcut. | 110 // appropriate for a home screen shortcut. |
| 108 GURL GetShortcutUrl(const GURL& original_url); | 111 GURL GetShortcutUrl(const GURL& original_url); |
| 109 | 112 |
| 110 Observer* weak_observer_; | 113 Observer* weak_observer_; |
| 111 | 114 |
| 112 bool is_waiting_for_web_application_info_; | 115 bool is_waiting_for_web_application_info_; |
| 113 bool is_icon_saved_; | 116 bool is_icon_saved_; |
| 114 bool is_ready_; | 117 bool is_ready_; |
| 115 base::Timer icon_timeout_timer_; | 118 base::Timer icon_timeout_timer_; |
| 116 ShortcutInfo shortcut_info_; | 119 ShortcutInfo shortcut_info_; |
| 117 GURL splash_screen_url_; | 120 GURL splash_screen_url_; |
| 118 | 121 |
| 119 // The icon must only be set on the UI thread for thread safety. | 122 // The icon must only be set on the UI thread for thread safety. |
| 120 SkBitmap shortcut_icon_; | 123 SkBitmap shortcut_icon_; |
| 121 base::CancelableTaskTracker favicon_task_tracker_; | 124 base::CancelableTaskTracker favicon_task_tracker_; |
| 122 | 125 |
| 123 const int ideal_icon_size_in_dp_; | 126 const int ideal_icon_size_in_dp_; |
| 124 const int minimum_icon_size_in_dp_; | 127 const int minimum_icon_size_in_dp_; |
| 125 const int ideal_splash_image_size_in_dp_; | 128 const int ideal_splash_image_size_in_dp_; |
| 126 const int minimum_splash_image_size_in_dp_; | 129 const int minimum_splash_image_size_in_dp_; |
| 127 | 130 |
| 128 friend class base::RefCounted<AddToHomescreenDataFetcher>; | 131 friend class base::RefCounted<AddToHomescreenDataFetcher>; |
| 129 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); | 132 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); |
| 130 }; | 133 }; |
| 131 | 134 |
| 132 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ | 135 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
| OLD | NEW |