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/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/task/cancelable_task_tracker.h" | 9 #include "base/task/cancelable_task_tracker.h" |
10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 class AddToHomescreenDataFetcher | 34 class AddToHomescreenDataFetcher |
35 : public base::RefCounted<AddToHomescreenDataFetcher>, | 35 : public base::RefCounted<AddToHomescreenDataFetcher>, |
36 public content::WebContentsObserver { | 36 public content::WebContentsObserver { |
37 public: | 37 public: |
38 class Observer { | 38 class Observer { |
39 public: | 39 public: |
40 // Called when the title of the page is available. | 40 // Called when the title of the page is available. |
41 virtual void OnUserTitleAvailable(const base::string16& title) = 0; | 41 virtual void OnUserTitleAvailable(const base::string16& title) = 0; |
42 | 42 |
43 // Converts the icon into one that can be used on the Android Home screen. | 43 // Converts the icon into one that can be used on the Android Home screen. |
| 44 // |is_generated| is an out-param that indicates whether the icon was |
| 45 // generated by Chrome. |
44 virtual SkBitmap FinalizeLauncherIcon(const SkBitmap& icon, | 46 virtual SkBitmap FinalizeLauncherIcon(const SkBitmap& icon, |
45 const GURL& url) = 0; | 47 const GURL& url, |
| 48 bool* is_generated) = 0; |
46 | 49 |
47 // Called when all the data needed to create a shortcut is available. | 50 // Called when all the data needed to create a shortcut is available. |
48 virtual void OnDataAvailable(const ShortcutInfo& info, | 51 virtual void OnDataAvailable(const ShortcutInfo& info, |
49 const SkBitmap& icon) = 0; | 52 const SkBitmap& icon) = 0; |
50 }; | 53 }; |
51 | 54 |
52 // Initialize the fetcher by requesting the information about the page to the | 55 // Initialize the fetcher by requesting the information about the page to the |
53 // renderer process. The initialization is asynchronous and | 56 // renderer process. The initialization is asynchronous and |
54 // OnDidGetWebApplicationInfo is expected to be called when finished. | 57 // OnDidGetWebApplicationInfo is expected to be called when finished. |
55 AddToHomescreenDataFetcher(content::WebContents* web_contents, | 58 AddToHomescreenDataFetcher(content::WebContents* web_contents, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 91 |
89 // Creates the launcher icon from the given bitmap. | 92 // Creates the launcher icon from the given bitmap. |
90 void CreateLauncherIcon( | 93 void CreateLauncherIcon( |
91 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 94 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
92 | 95 |
93 // Callback run after an attempt to download manifest icon has been made. May | 96 // Callback run after an attempt to download manifest icon has been made. May |
94 // kick off the download of a favicon if it failed (i.e. the bitmap is empty). | 97 // kick off the download of a favicon if it failed (i.e. the bitmap is empty). |
95 void OnManifestIconFetched(const SkBitmap& icon); | 98 void OnManifestIconFetched(const SkBitmap& icon); |
96 | 99 |
97 // Notifies the observer that the shortcut data is all available. | 100 // Notifies the observer that the shortcut data is all available. |
98 void NotifyObserver(const SkBitmap& icon); | 101 void NotifyObserver(const SkBitmap& icon, bool is_generated); |
99 | 102 |
100 Observer* weak_observer_; | 103 Observer* weak_observer_; |
101 | 104 |
102 bool is_waiting_for_web_application_info_; | 105 bool is_waiting_for_web_application_info_; |
103 bool is_icon_saved_; | 106 bool is_icon_saved_; |
104 bool is_ready_; | 107 bool is_ready_; |
105 base::Timer icon_timeout_timer_; | 108 base::Timer icon_timeout_timer_; |
106 ShortcutInfo shortcut_info_; | 109 ShortcutInfo shortcut_info_; |
107 GURL splash_screen_url_; | 110 GURL splash_screen_url_; |
108 | 111 |
109 // The icon must only be set on the UI thread for thread safety. | 112 // The icon must only be set on the UI thread for thread safety. |
110 SkBitmap shortcut_icon_; | 113 SkBitmap shortcut_icon_; |
111 base::CancelableTaskTracker favicon_task_tracker_; | 114 base::CancelableTaskTracker favicon_task_tracker_; |
112 | 115 |
113 const int ideal_icon_size_in_dp_; | 116 const int ideal_icon_size_in_dp_; |
114 const int minimum_icon_size_in_dp_; | 117 const int minimum_icon_size_in_dp_; |
115 const int ideal_splash_image_size_in_dp_; | 118 const int ideal_splash_image_size_in_dp_; |
116 const int minimum_splash_image_size_in_dp_; | 119 const int minimum_splash_image_size_in_dp_; |
117 | 120 |
118 friend class base::RefCounted<AddToHomescreenDataFetcher>; | 121 friend class base::RefCounted<AddToHomescreenDataFetcher>; |
119 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); | 122 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); |
120 }; | 123 }; |
121 | 124 |
122 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ | 125 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
OLD | NEW |