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> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "chrome/common/web_application_info.h" | 15 #include "chrome/common/web_application_info.h" |
16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
18 #include "content/public/common/manifest.h" | 18 #include "content/public/common/manifest.h" |
19 | 19 |
20 class ExtensionService; | 20 class ExtensionService; |
21 class FaviconDownloader; | 21 class FaviconDownloader; |
| 22 class Profile; |
22 class SkBitmap; | 23 class SkBitmap; |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 class BrowserContext; | 26 class BrowserContext; |
26 class WebContents; | 27 class WebContents; |
27 } | 28 } |
28 | 29 |
29 namespace extensions { | 30 namespace extensions { |
30 class CrxInstaller; | 31 class CrxInstaller; |
31 class Extension; | 32 class Extension; |
32 | 33 |
33 // A helper class for creating bookmark apps from a WebContents. | 34 // A helper class for creating bookmark apps from a WebContents. |
34 class BookmarkAppHelper : public content::NotificationObserver { | 35 class BookmarkAppHelper : public content::NotificationObserver { |
35 public: | 36 public: |
36 typedef base::Callback<void(const Extension*, const WebApplicationInfo&)> | 37 typedef base::Callback<void(const Extension*, const WebApplicationInfo&)> |
37 CreateBookmarkAppCallback; | 38 CreateBookmarkAppCallback; |
38 | 39 |
39 // This helper class will create a bookmark app out of |web_app_info| and | 40 // This helper class will create a bookmark app out of |web_app_info| and |
40 // install it to |service|. Icons will be downloaded from the URLs in | 41 // install it to |service|. Icons will be downloaded from the URLs in |
41 // |web_app_info.icons| using |contents| if |contents| is not NULL. | 42 // |web_app_info.icons| using |contents| if |contents| is not NULL. |
42 // All existing icons from WebApplicationInfo will also be used. | 43 // All existing icons from WebApplicationInfo will also be used. The user |
43 BookmarkAppHelper(ExtensionService* service, | 44 // will then be prompted to edit the creation information via a bubble and |
| 45 // will have a chance to cancel the operation. |
| 46 BookmarkAppHelper(Profile* profile, |
44 WebApplicationInfo web_app_info, | 47 WebApplicationInfo web_app_info, |
45 content::WebContents* contents); | 48 content::WebContents* contents); |
46 ~BookmarkAppHelper() override; | 49 ~BookmarkAppHelper() override; |
47 | 50 |
48 // Update the given WebApplicationInfo with information from the manifest. | 51 // Update the given WebApplicationInfo with information from the manifest. |
49 static void UpdateWebAppInfoFromManifest(const content::Manifest& manifest, | 52 static void UpdateWebAppInfoFromManifest(const content::Manifest& manifest, |
50 WebApplicationInfo* web_app_info); | 53 WebApplicationInfo* web_app_info); |
51 | 54 |
52 // This finds the closest not-smaller bitmap in |bitmaps| for each size in | 55 // This finds the closest not-smaller bitmap in |bitmaps| for each size in |
53 // |sizes| and resizes it to that size. This returns a map of sizes to bitmaps | 56 // |sizes| and resizes it to that size. This returns a map of sizes to bitmaps |
(...skipping 19 matching lines...) Expand all Loading... |
73 | 76 |
74 // Called by the WebContents when the manifest has been downloaded. If there | 77 // Called by the WebContents when the manifest has been downloaded. If there |
75 // is no manifest, or the WebContents is destroyed before the manifest could | 78 // is no manifest, or the WebContents is destroyed before the manifest could |
76 // be downloaded, this is called with an empty manifest. | 79 // be downloaded, this is called with an empty manifest. |
77 void OnDidGetManifest(const content::Manifest& manifest); | 80 void OnDidGetManifest(const content::Manifest& manifest); |
78 | 81 |
79 // Performs post icon download tasks including installing the bookmark app. | 82 // Performs post icon download tasks including installing the bookmark app. |
80 void OnIconsDownloaded(bool success, | 83 void OnIconsDownloaded(bool success, |
81 const std::map<GURL, std::vector<SkBitmap> >& bitmaps); | 84 const std::map<GURL, std::vector<SkBitmap> >& bitmaps); |
82 | 85 |
| 86 // Called after the bubble has been shown, and the user has either accepted or |
| 87 // the dialog was dismissed. |
| 88 void OnBubbleCompleted(bool user_accepted, |
| 89 const WebApplicationInfo& web_app_info); |
| 90 |
| 91 // Called when the installation of the app is complete to perform the final |
| 92 // installation steps. |
| 93 void FinishInstallation(const Extension* extension); |
| 94 |
83 // Overridden from content::NotificationObserver: | 95 // Overridden from content::NotificationObserver: |
84 void Observe(int type, | 96 void Observe(int type, |
85 const content::NotificationSource& source, | 97 const content::NotificationSource& source, |
86 const content::NotificationDetails& details) override; | 98 const content::NotificationDetails& details) override; |
87 | 99 |
| 100 // The profile that the bookmark app is being added to. |
| 101 Profile* profile_; |
| 102 |
88 // The web contents that the bookmark app is being created for. | 103 // The web contents that the bookmark app is being created for. |
89 content::WebContents* contents_; | 104 content::WebContents* contents_; |
90 | 105 |
91 // The WebApplicationInfo that the bookmark app is being created for. | 106 // The WebApplicationInfo that the bookmark app is being created for. |
92 WebApplicationInfo web_app_info_; | 107 WebApplicationInfo web_app_info_; |
93 | 108 |
94 // Called on app creation or failure. | 109 // Called on app creation or failure. |
95 CreateBookmarkAppCallback callback_; | 110 CreateBookmarkAppCallback callback_; |
96 | 111 |
97 // Downloads icons from the given WebApplicationInfo using the given | 112 // Downloads icons from the given WebApplicationInfo using the given |
(...skipping 19 matching lines...) Expand all Loading... |
117 content::BrowserContext* browser_context, | 132 content::BrowserContext* browser_context, |
118 const extensions::Extension* extension, | 133 const extensions::Extension* extension, |
119 const base::Callback<void(const WebApplicationInfo&)> callback); | 134 const base::Callback<void(const WebApplicationInfo&)> callback); |
120 | 135 |
121 // Returns whether the given |url| is a valid bookmark app url. | 136 // Returns whether the given |url| is a valid bookmark app url. |
122 bool IsValidBookmarkAppUrl(const GURL& url); | 137 bool IsValidBookmarkAppUrl(const GURL& url); |
123 | 138 |
124 } // namespace extensions | 139 } // namespace extensions |
125 | 140 |
126 #endif // CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_HELPER_H_ | 141 #endif // CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_HELPER_H_ |
OLD | NEW |