| 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(); |
| 40 |
| 41 GURL source_url; |
| 42 SkBitmap bitmap; |
| 43 }; |
| 44 |
| 37 typedef base::Callback<void(const Extension*, const WebApplicationInfo&)> | 45 typedef base::Callback<void(const Extension*, const WebApplicationInfo&)> |
| 38 CreateBookmarkAppCallback; | 46 CreateBookmarkAppCallback; |
| 39 | 47 |
| 40 // This helper class will create a bookmark app out of |web_app_info| and | 48 // 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 | 49 // install it to |service|. Icons will be downloaded from the URLs in |
| 42 // |web_app_info.icons| using |contents| if |contents| is not NULL. | 50 // |web_app_info.icons| using |contents| if |contents| is not NULL. |
| 43 // All existing icons from WebApplicationInfo will also be used. The user | 51 // 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 | 52 // will then be prompted to edit the creation information via a bubble and |
| 45 // will have a chance to cancel the operation. | 53 // will have a chance to cancel the operation. |
| 46 BookmarkAppHelper(Profile* profile, | 54 BookmarkAppHelper(Profile* profile, |
| 47 WebApplicationInfo web_app_info, | 55 WebApplicationInfo web_app_info, |
| 48 content::WebContents* contents); | 56 content::WebContents* contents); |
| 49 ~BookmarkAppHelper() override; | 57 ~BookmarkAppHelper() override; |
| 50 | 58 |
| 51 // Update the given WebApplicationInfo with information from the manifest. | 59 // Update the given WebApplicationInfo with information from the manifest. |
| 52 static void UpdateWebAppInfoFromManifest(const content::Manifest& manifest, | 60 static void UpdateWebAppInfoFromManifest(const content::Manifest& manifest, |
| 53 WebApplicationInfo* web_app_info); | 61 WebApplicationInfo* web_app_info); |
| 54 | 62 |
| 55 // This finds the closest not-smaller bitmap in |bitmaps| for each size in | 63 // 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 | 64 // |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 | 65 // which contains only bitmaps of a size in |sizes| and at most one bitmap of |
| 58 // each size. | 66 // each size. |
| 59 static std::map<int, SkBitmap> ConstrainBitmapsToSizes( | 67 static std::map<int, BitmapAndSource> ConstrainBitmapsToSizes( |
| 60 const std::vector<SkBitmap>& bitmaps, | 68 const std::vector<BitmapAndSource>& bitmaps, |
| 61 const std::set<int>& sizes); | 69 const std::set<int>& sizes); |
| 62 | 70 |
| 63 // Adds a square container icon of |output_size| pixels to |bitmaps| by | 71 // Adds a square container icon of |output_size| pixels to |bitmaps| by |
| 64 // drawing the given |letter| into a rounded background of |color|. | 72 // drawing the given |letter| into a rounded background of |color|. |
| 65 // Does nothing if an icon of |output_size| already exists in |bitmaps|. | 73 // Does nothing if an icon of |output_size| already exists in |bitmaps|. |
| 66 static void GenerateIcon(std::map<int, SkBitmap>* bitmaps, | 74 static void GenerateIcon(std::map<int, BitmapAndSource>* bitmaps, |
| 67 int output_size, | 75 int output_size, |
| 68 SkColor color, | 76 SkColor color, |
| 69 char letter); | 77 char letter); |
| 70 | 78 |
| 71 // Begins the asynchronous bookmark app creation. | 79 // Begins the asynchronous bookmark app creation. |
| 72 void Create(const CreateBookmarkAppCallback& callback); | 80 void Create(const CreateBookmarkAppCallback& callback); |
| 73 | 81 |
| 74 private: | 82 private: |
| 75 friend class TestBookmarkAppHelper; | 83 friend class TestBookmarkAppHelper; |
| 76 | 84 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 content::BrowserContext* browser_context, | 140 content::BrowserContext* browser_context, |
| 133 const extensions::Extension* extension, | 141 const extensions::Extension* extension, |
| 134 const base::Callback<void(const WebApplicationInfo&)> callback); | 142 const base::Callback<void(const WebApplicationInfo&)> callback); |
| 135 | 143 |
| 136 // Returns whether the given |url| is a valid bookmark app url. | 144 // Returns whether the given |url| is a valid bookmark app url. |
| 137 bool IsValidBookmarkAppUrl(const GURL& url); | 145 bool IsValidBookmarkAppUrl(const GURL& url); |
| 138 | 146 |
| 139 } // namespace extensions | 147 } // namespace extensions |
| 140 | 148 |
| 141 #endif // CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_HELPER_H_ | 149 #endif // CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_HELPER_H_ |
| OLD | NEW |