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_SHORTCUT_DATA_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
6 #define CHROME_BROWSER_ANDROID_SHORTCUT_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" |
11 #include "chrome/browser/android/shortcut_info.h" | 11 #include "chrome/browser/android/shortcut_info.h" |
12 #include "chrome/common/web_application_info.h" | 12 #include "chrome/common/web_application_info.h" |
13 #include "components/favicon_base/favicon_types.h" | 13 #include "components/favicon_base/favicon_types.h" |
14 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
15 #include "content/public/common/manifest.h" | 15 #include "content/public/common/manifest.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 class WebContents; | 18 class WebContents; |
19 } // namespace content | 19 } // namespace content |
20 | 20 |
21 namespace IPC { | 21 namespace IPC { |
22 class Message; | 22 class Message; |
23 } | 23 } |
24 | 24 |
25 class GURL; | 25 class GURL; |
26 | 26 |
27 // Aysnchronously fetches and processes data needed to create a shortcut for an | 27 // Aysnchronously fetches and processes data needed to create a shortcut for an |
28 // Android Home screen launcher. | 28 // Android Home screen launcher. |
29 // | 29 // |
30 // Because of the various asynchronous calls made by this class, it is | 30 // Because of the various asynchronous calls made by this class, it is |
31 // refcounted to prevent the class from being prematurely deleted. If the | 31 // refcounted to prevent the class from being prematurely deleted. If the |
32 // pointer to the ShortcutHelper becomes invalid, the pipeline should kill | 32 // pointer to the ShortcutHelper becomes invalid, the pipeline should kill |
33 // itself. | 33 // itself. |
34 class ShortcutDataFetcher | 34 class AddToHomescreenDataFetcher |
35 : public base::RefCounted<ShortcutDataFetcher>, | 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 virtual SkBitmap FinalizeLauncherIcon(const SkBitmap& icon, | 44 virtual SkBitmap FinalizeLauncherIcon(const SkBitmap& icon, |
45 const GURL& url) = 0; | 45 const GURL& url) = 0; |
46 | 46 |
47 // Called when all the data needed to create a shortcut is available. | 47 // Called when all the data needed to create a shortcut is available. |
48 virtual void OnDataAvailable(const ShortcutInfo& info, | 48 virtual void OnDataAvailable(const ShortcutInfo& info, |
49 const SkBitmap& icon) = 0; | 49 const SkBitmap& icon) = 0; |
50 }; | 50 }; |
51 | 51 |
52 // Initialize the fetcher by requesting the information about the page to the | 52 // Initialize the fetcher by requesting the information about the page to the |
53 // renderer process. The initialization is asynchronous and | 53 // renderer process. The initialization is asynchronous and |
54 // OnDidGetWebApplicationInfo is expected to be called when finished. | 54 // OnDidGetWebApplicationInfo is expected to be called when finished. |
55 ShortcutDataFetcher(content::WebContents* web_contents, Observer* observer); | 55 AddToHomescreenDataFetcher(content::WebContents* web_contents, |
| 56 Observer* observer); |
56 | 57 |
57 // IPC message received when the initialization is finished. | 58 // IPC message received when the initialization is finished. |
58 void OnDidGetWebApplicationInfo(const WebApplicationInfo& web_app_info); | 59 void OnDidGetWebApplicationInfo(const WebApplicationInfo& web_app_info); |
59 | 60 |
60 // Called when the Manifest has been parsed, or if no Manifest was found. | 61 // Called when the Manifest has been parsed, or if no Manifest was found. |
61 void OnDidGetManifest(const content::Manifest& manifest); | 62 void OnDidGetManifest(const content::Manifest& manifest); |
62 | 63 |
63 // Accessors, etc. | 64 // Accessors, etc. |
64 void set_weak_observer(Observer* observer) { weak_observer_ = observer; } | 65 void set_weak_observer(Observer* observer) { weak_observer_ = observer; } |
65 bool is_ready() { return is_ready_; } | 66 bool is_ready() { return is_ready_; } |
66 ShortcutInfo& shortcut_info() { return shortcut_info_; } | 67 ShortcutInfo& shortcut_info() { return shortcut_info_; } |
67 const SkBitmap& shortcut_icon() { return shortcut_icon_; } | 68 const SkBitmap& shortcut_icon() { return shortcut_icon_; } |
68 | 69 |
69 // WebContentsObserver | 70 // WebContentsObserver |
70 bool OnMessageReceived(const IPC::Message& message) override; | 71 bool OnMessageReceived(const IPC::Message& message) override; |
71 | 72 |
72 private: | 73 private: |
73 ~ShortcutDataFetcher() override; | 74 ~AddToHomescreenDataFetcher() override; |
74 | 75 |
75 // Grabs the favicon for the current URL. | 76 // Grabs the favicon for the current URL. |
76 void FetchFavicon(); | 77 void FetchFavicon(); |
77 void OnFaviconFetched( | 78 void OnFaviconFetched( |
78 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 79 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
79 | 80 |
80 // Creates the launcher icon from the given bitmap. | 81 // Creates the launcher icon from the given bitmap. |
81 void CreateLauncherIcon( | 82 void CreateLauncherIcon( |
82 const favicon_base::FaviconRawBitmapResult& bitmap_result); | 83 const favicon_base::FaviconRawBitmapResult& bitmap_result); |
83 | 84 |
(...skipping 16 matching lines...) Expand all Loading... |
100 base::Timer icon_timeout_timer_; | 101 base::Timer icon_timeout_timer_; |
101 ShortcutInfo shortcut_info_; | 102 ShortcutInfo shortcut_info_; |
102 | 103 |
103 // The icon must only be set on the UI thread for thread safety. | 104 // The icon must only be set on the UI thread for thread safety. |
104 SkBitmap shortcut_icon_; | 105 SkBitmap shortcut_icon_; |
105 base::CancelableTaskTracker favicon_task_tracker_; | 106 base::CancelableTaskTracker favicon_task_tracker_; |
106 | 107 |
107 const int preferred_icon_size_in_px_; | 108 const int preferred_icon_size_in_px_; |
108 static const int kPreferredIconSizeInDp; | 109 static const int kPreferredIconSizeInDp; |
109 | 110 |
110 friend class base::RefCounted<ShortcutDataFetcher>; | 111 friend class base::RefCounted<AddToHomescreenDataFetcher>; |
111 DISALLOW_COPY_AND_ASSIGN(ShortcutDataFetcher); | 112 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcher); |
112 }; | 113 }; |
113 | 114 |
114 #endif // CHROME_BROWSER_ANDROID_SHORTCUT_DATA_FETCHER_H_ | 115 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DATA_FETCHER_H_ |
OLD | NEW |