Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: chrome/browser/extensions/bookmark_app_helper.h

Issue 667053007: Use manifest for streamlined hosted app creation for title and URL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Fix memory leak in manifest_manager_host Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/bookmark_app_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 19
19 class ExtensionService; 20 class ExtensionService;
20 class FaviconDownloader; 21 class FaviconDownloader;
21 class SkBitmap; 22 class SkBitmap;
22 23
23 namespace content { 24 namespace content {
24 class BrowserContext; 25 class BrowserContext;
25 class WebContents; 26 class WebContents;
26 } 27 }
27 28
28 namespace extensions { 29 namespace extensions {
29 class CrxInstaller; 30 class CrxInstaller;
30 class Extension; 31 class Extension;
31 32
32 // A helper class for creating bookmark apps from a WebContents. 33 // A helper class for creating bookmark apps from a WebContents.
33 class BookmarkAppHelper : public content::NotificationObserver { 34 class BookmarkAppHelper : public content::NotificationObserver {
34 public: 35 public:
35 typedef base::Callback<void(const Extension*, const WebApplicationInfo&)> 36 typedef base::Callback<void(const Extension*, const WebApplicationInfo&)>
36 CreateBookmarkAppCallback; 37 CreateBookmarkAppCallback;
37 38
38 // This helper class will create a bookmark app out of |web_app_info| and 39 // This helper class will create a bookmark app out of |web_app_info| and
39 // install it to |service|. Icons will be downloaded from the URLs in 40 // install it to |service|. Icons will be downloaded from the URLs in
40 // |web_app_info.icons| using |contents| if |contents| is not NULL. 41 // |web_app_info.icons| using |contents| if |contents| is not NULL.
41 // All existing icons from WebApplicationInfo will also be used. 42 // All existing icons from WebApplicationInfo will also be used.
42 BookmarkAppHelper(ExtensionService* service, 43 BookmarkAppHelper(ExtensionService* service,
43 WebApplicationInfo web_app_info, 44 WebApplicationInfo web_app_info,
44 content::WebContents* contents); 45 content::WebContents* contents);
45 virtual ~BookmarkAppHelper(); 46 virtual ~BookmarkAppHelper();
46 47
48 // Update the given WebApplicationInfo with information from the manifest.
49 static void UpdateWebAppInfoFromManifest(const content::Manifest& manifest,
50 WebApplicationInfo* web_app_info);
51
47 // This finds the closest not-smaller bitmap in |bitmaps| for each size in 52 // This finds the closest not-smaller bitmap in |bitmaps| for each size in
48 // |sizes| and resizes it to that size. This returns a map of sizes to bitmaps 53 // |sizes| and resizes it to that size. This returns a map of sizes to bitmaps
49 // which contains only bitmaps of a size in |sizes| and at most one bitmap of 54 // which contains only bitmaps of a size in |sizes| and at most one bitmap of
50 // each size. 55 // each size.
51 static std::map<int, SkBitmap> ConstrainBitmapsToSizes( 56 static std::map<int, SkBitmap> ConstrainBitmapsToSizes(
52 const std::vector<SkBitmap>& bitmaps, 57 const std::vector<SkBitmap>& bitmaps,
53 const std::set<int>& sizes); 58 const std::set<int>& sizes);
54 59
55 // Adds a square container icon of |output_size| pixels to |bitmaps| by 60 // Adds a square container icon of |output_size| pixels to |bitmaps| by
56 // drawing the given |letter| into a rounded background of |color|. 61 // drawing the given |letter| into a rounded background of |color|.
57 // Does nothing if an icon of |output_size| already exists in |bitmaps|. 62 // Does nothing if an icon of |output_size| already exists in |bitmaps|.
58 static void GenerateIcon(std::map<int, SkBitmap>* bitmaps, 63 static void GenerateIcon(std::map<int, SkBitmap>* bitmaps,
59 int output_size, 64 int output_size,
60 SkColor color, 65 SkColor color,
61 char letter); 66 char letter);
62 67
63 // Begins the asynchronous bookmark app creation. 68 // Begins the asynchronous bookmark app creation.
64 void Create(const CreateBookmarkAppCallback& callback); 69 void Create(const CreateBookmarkAppCallback& callback);
65 70
66 private: 71 private:
67 friend class TestBookmarkAppHelper; 72 friend class TestBookmarkAppHelper;
68 73
74 // 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
76 // be downloaded, this is called with an empty manifest.
77 void OnDidGetManifest(const content::Manifest& manifest);
78
69 // Performs post icon download tasks including installing the bookmark app. 79 // Performs post icon download tasks including installing the bookmark app.
70 void OnIconsDownloaded(bool success, 80 void OnIconsDownloaded(bool success,
71 const std::map<GURL, std::vector<SkBitmap> >& bitmaps); 81 const std::map<GURL, std::vector<SkBitmap> >& bitmaps);
72 82
73 // Overridden from content::NotificationObserver: 83 // Overridden from content::NotificationObserver:
74 virtual void Observe(int type, 84 virtual void Observe(int type,
75 const content::NotificationSource& source, 85 const content::NotificationSource& source,
76 const content::NotificationDetails& details) override; 86 const content::NotificationDetails& details) override;
77 87
88 // The web contents that the bookmark app is being created for.
89 content::WebContents* contents_;
90
78 // The WebApplicationInfo that the bookmark app is being created for. 91 // The WebApplicationInfo that the bookmark app is being created for.
79 WebApplicationInfo web_app_info_; 92 WebApplicationInfo web_app_info_;
80 93
81 // Called on app creation or failure. 94 // Called on app creation or failure.
82 CreateBookmarkAppCallback callback_; 95 CreateBookmarkAppCallback callback_;
83 96
84 // Downloads icons from the given WebApplicationInfo using the given 97 // Downloads icons from the given WebApplicationInfo using the given
85 // WebContents. 98 // WebContents.
86 scoped_ptr<FaviconDownloader> favicon_downloader_; 99 scoped_ptr<FaviconDownloader> favicon_downloader_;
87 100
(...skipping 16 matching lines...) Expand all
104 content::BrowserContext* browser_context, 117 content::BrowserContext* browser_context,
105 const extensions::Extension* extension, 118 const extensions::Extension* extension,
106 const base::Callback<void(const WebApplicationInfo&)> callback); 119 const base::Callback<void(const WebApplicationInfo&)> callback);
107 120
108 // Returns whether the given |url| is a valid bookmark app url. 121 // Returns whether the given |url| is a valid bookmark app url.
109 bool IsValidBookmarkAppUrl(const GURL& url); 122 bool IsValidBookmarkAppUrl(const GURL& url);
110 123
111 } // namespace extensions 124 } // namespace extensions
112 125
113 #endif // CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_HELPER_H_ 126 #endif // CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_HELPER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/bookmark_app_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698