OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_EXTENSIONS_BOOKMARK_APP_HELPER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_HELPER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_HELPER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_HELPER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 16 matching lines...) Expand all Loading... | |
27 class WebContents; | 27 class WebContents; |
28 } | 28 } |
29 | 29 |
30 namespace extensions { | 30 namespace extensions { |
31 class CrxInstaller; | 31 class CrxInstaller; |
32 class Extension; | 32 class Extension; |
33 | 33 |
34 // A helper class for creating bookmark apps from a WebContents. | 34 // A helper class for creating bookmark apps from a WebContents. |
35 class BookmarkAppHelper : public content::NotificationObserver { | 35 class BookmarkAppHelper : public content::NotificationObserver { |
36 public: | 36 public: |
37 struct BitmapAndSource { | |
38 BitmapAndSource(); | |
39 BitmapAndSource(const GURL& source_url_p, const SkBitmap& bitmap_p); | |
40 ~BitmapAndSource(); | |
41 | |
42 GURL source_url; | |
43 SkBitmap bitmap; | |
44 }; | |
45 | |
37 typedef base::Callback<void(const Extension*, const WebApplicationInfo&)> | 46 typedef base::Callback<void(const Extension*, const WebApplicationInfo&)> |
38 CreateBookmarkAppCallback; | 47 CreateBookmarkAppCallback; |
39 | 48 |
40 // This helper class will create a bookmark app out of |web_app_info| and | 49 // This helper class will create a bookmark app out of |web_app_info| and |
41 // install it to |service|. Icons will be downloaded from the URLs in | 50 // install it to |service|. Icons will be downloaded from the URLs in |
42 // |web_app_info.icons| using |contents| if |contents| is not NULL. | 51 // |web_app_info.icons| using |contents| if |contents| is not NULL. |
43 // All existing icons from WebApplicationInfo will also be used. The user | 52 // All existing icons from WebApplicationInfo will also be used. The user |
44 // will then be prompted to edit the creation information via a bubble and | 53 // will then be prompted to edit the creation information via a bubble and |
45 // will have a chance to cancel the operation. | 54 // will have a chance to cancel the operation. |
46 BookmarkAppHelper(Profile* profile, | 55 BookmarkAppHelper(Profile* profile, |
47 WebApplicationInfo web_app_info, | 56 WebApplicationInfo web_app_info, |
48 content::WebContents* contents); | 57 content::WebContents* contents); |
49 ~BookmarkAppHelper() override; | 58 ~BookmarkAppHelper() override; |
50 | 59 |
51 // Update the given WebApplicationInfo with information from the manifest. | 60 // Update the given WebApplicationInfo with information from the manifest. |
52 static void UpdateWebAppInfoFromManifest(const content::Manifest& manifest, | 61 static void UpdateWebAppInfoFromManifest(const content::Manifest& manifest, |
53 WebApplicationInfo* web_app_info); | 62 WebApplicationInfo* web_app_info); |
54 | 63 |
55 // This finds the closest not-smaller bitmap in |bitmaps| for each size in | 64 // This finds the closest not-smaller bitmap in |bitmaps| for each size in |
56 // |sizes| and resizes it to that size. This returns a map of sizes to bitmaps | 65 // |sizes| and resizes it to that size. This returns a map of sizes to bitmaps |
57 // which contains only bitmaps of a size in |sizes| and at most one bitmap of | 66 // which contains only bitmaps of a size in |sizes| and at most one bitmap of |
58 // each size. | 67 // each size. |
59 static std::map<int, SkBitmap> ConstrainBitmapsToSizes( | 68 static std::map<int, BitmapAndSource> ConstrainBitmapsToSizes( |
60 const std::vector<SkBitmap>& bitmaps, | 69 const std::vector<BitmapAndSource>& bitmaps, |
61 const std::set<int>& sizes); | 70 const std::set<int>& sizes); |
62 | 71 |
63 // Adds a square container icon of |output_size| pixels to |bitmaps| by | 72 // Adds a square container icon of |output_size| pixels to |bitmaps| by |
64 // drawing the given |letter| into a rounded background of |color|. | 73 // drawing the given |letter| into a rounded background of |color|. |
65 // Does nothing if an icon of |output_size| already exists in |bitmaps|. | 74 // Does nothing if an icon of |output_size| already exists in |bitmaps|. |
66 static void GenerateIcon(std::map<int, SkBitmap>* bitmaps, | 75 static void GenerateIcon(std::map<int, BitmapAndSource>* bitmaps, |
67 int output_size, | 76 int output_size, |
68 SkColor color, | 77 SkColor color, |
69 char letter); | 78 char letter); |
70 | 79 |
80 // Resize icons to the accepted sizes, and generate any that are missing. Does | |
81 // not update |web_app_info| except to update |generated_icon_color|. | |
82 static std::map<int, BitmapAndSource> ResizeIconsAndGenerateMissing( | |
83 std::vector<BitmapAndSource> icons, | |
84 WebApplicationInfo* web_app_info); | |
85 | |
86 // It is important that the linked app information in any extension that | |
87 // gets created from sync matches the linked app information that came from | |
88 // sync. If there are any changes, they will be synced back to other devices | |
89 // and could potentially create a never ending sync cycle. | |
90 // This function updates |web_app_info| by copying over the image data of any | |
91 // icon from | |
calamity
2015/04/28 06:56:35
Nit: sentence fragment.
benwells
2015/04/28 08:10:56
Done.
| |
92 static void UpdateWebAppIconsWithoutChangingLinks( | |
93 std::map<int, BookmarkAppHelper::BitmapAndSource> bitmap_map, | |
94 WebApplicationInfo* web_app_info); | |
95 | |
71 // Begins the asynchronous bookmark app creation. | 96 // Begins the asynchronous bookmark app creation. |
72 void Create(const CreateBookmarkAppCallback& callback); | 97 void Create(const CreateBookmarkAppCallback& callback); |
73 | 98 |
74 private: | 99 private: |
75 friend class TestBookmarkAppHelper; | 100 friend class TestBookmarkAppHelper; |
76 | 101 |
77 // Called by the WebContents when the manifest has been downloaded. If there | 102 // Called by the WebContents when the manifest has been downloaded. If there |
78 // is no manifest, or the WebContents is destroyed before the manifest could | 103 // is no manifest, or the WebContents is destroyed before the manifest could |
79 // be downloaded, this is called with an empty manifest. | 104 // be downloaded, this is called with an empty manifest. |
80 void OnDidGetManifest(const content::Manifest& manifest); | 105 void OnDidGetManifest(const content::Manifest& manifest); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 content::BrowserContext* browser_context, | 157 content::BrowserContext* browser_context, |
133 const extensions::Extension* extension, | 158 const extensions::Extension* extension, |
134 const base::Callback<void(const WebApplicationInfo&)> callback); | 159 const base::Callback<void(const WebApplicationInfo&)> callback); |
135 | 160 |
136 // Returns whether the given |url| is a valid bookmark app url. | 161 // Returns whether the given |url| is a valid bookmark app url. |
137 bool IsValidBookmarkAppUrl(const GURL& url); | 162 bool IsValidBookmarkAppUrl(const GURL& url); |
138 | 163 |
139 } // namespace extensions | 164 } // namespace extensions |
140 | 165 |
141 #endif // CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_HELPER_H_ | 166 #endif // CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_HELPER_H_ |
OLD | NEW |