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

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

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, 2 months 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
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 #include "chrome/browser/extensions/bookmark_app_helper.h" 5 #include "chrome/browser/extensions/bookmark_app_helper.h"
6 6
7 #include <cctype> 7 #include <cctype>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/extensions/crx_installer.h" 10 #include "chrome/browser/extensions/crx_installer.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 web_app_info.icons.push_back(icon_info); 110 web_app_info.icons.push_back(icon_info);
111 } 111 }
112 callback.Run(web_app_info); 112 callback.Run(web_app_info);
113 } 113 }
114 114
115 } // namespace 115 } // namespace
116 116
117 namespace extensions { 117 namespace extensions {
118 118
119 // static 119 // static
120 void BookmarkAppHelper::UpdateWebAppInfoFromManifest(
121 const content::Manifest& manifest,
122 WebApplicationInfo* web_app_info) {
123 if (!manifest.short_name.is_null())
124 web_app_info->title = manifest.short_name.string();
125
126 // Give the full length name priority.
127 if (!manifest.name.is_null())
128 web_app_info->title = manifest.name.string();
129
130 // Set the url based on the manifest value, if any.
131 if (manifest.start_url.is_valid())
132 web_app_info->app_url = manifest.start_url;
133 }
134
135 // static
120 std::map<int, SkBitmap> BookmarkAppHelper::ConstrainBitmapsToSizes( 136 std::map<int, SkBitmap> BookmarkAppHelper::ConstrainBitmapsToSizes(
121 const std::vector<SkBitmap>& bitmaps, 137 const std::vector<SkBitmap>& bitmaps,
122 const std::set<int>& sizes) { 138 const std::set<int>& sizes) {
123 std::map<int, SkBitmap> output_bitmaps; 139 std::map<int, SkBitmap> output_bitmaps;
124 std::map<int, SkBitmap> ordered_bitmaps; 140 std::map<int, SkBitmap> ordered_bitmaps;
125 for (std::vector<SkBitmap>::const_iterator it = bitmaps.begin(); 141 for (std::vector<SkBitmap>::const_iterator it = bitmaps.begin();
126 it != bitmaps.end(); 142 it != bitmaps.end();
127 ++it) { 143 ++it) {
128 DCHECK(it->width() == it->height()); 144 DCHECK(it->width() == it->height());
129 ordered_bitmaps[it->width()] = *it; 145 ordered_bitmaps[it->width()] = *it;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 179
164 gfx::ImageSkia icon_image( 180 gfx::ImageSkia icon_image(
165 new GeneratedIconImageSource(letter, color, output_size), 181 new GeneratedIconImageSource(letter, color, output_size),
166 gfx::Size(output_size, output_size)); 182 gfx::Size(output_size, output_size));
167 icon_image.bitmap()->deepCopyTo(&(*bitmaps)[output_size]); 183 icon_image.bitmap()->deepCopyTo(&(*bitmaps)[output_size]);
168 } 184 }
169 185
170 BookmarkAppHelper::BookmarkAppHelper(ExtensionService* service, 186 BookmarkAppHelper::BookmarkAppHelper(ExtensionService* service,
171 WebApplicationInfo web_app_info, 187 WebApplicationInfo web_app_info,
172 content::WebContents* contents) 188 content::WebContents* contents)
173 : web_app_info_(web_app_info), 189 : contents_(contents),
190 web_app_info_(web_app_info),
174 crx_installer_(extensions::CrxInstaller::CreateSilent(service)) { 191 crx_installer_(extensions::CrxInstaller::CreateSilent(service)) {
175 registrar_.Add(this, 192 registrar_.Add(this,
176 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 193 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
177 content::Source<CrxInstaller>(crx_installer_.get())); 194 content::Source<CrxInstaller>(crx_installer_.get()));
178 195
179 registrar_.Add(this, 196 registrar_.Add(this,
180 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR, 197 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR,
181 content::Source<CrxInstaller>(crx_installer_.get())); 198 content::Source<CrxInstaller>(crx_installer_.get()));
182 199
183 crx_installer_->set_error_on_unsupported_requirements(true); 200 crx_installer_->set_error_on_unsupported_requirements(true);
(...skipping 16 matching lines...) Expand all
200 web_app_info_icon_urls, 217 web_app_info_icon_urls,
201 base::Bind(&BookmarkAppHelper::OnIconsDownloaded, 218 base::Bind(&BookmarkAppHelper::OnIconsDownloaded,
202 base::Unretained(this)))); 219 base::Unretained(this))));
203 } 220 }
204 221
205 BookmarkAppHelper::~BookmarkAppHelper() {} 222 BookmarkAppHelper::~BookmarkAppHelper() {}
206 223
207 void BookmarkAppHelper::Create(const CreateBookmarkAppCallback& callback) { 224 void BookmarkAppHelper::Create(const CreateBookmarkAppCallback& callback) {
208 callback_ = callback; 225 callback_ = callback;
209 226
210 if (favicon_downloader_.get()) 227 if (contents_) {
211 favicon_downloader_->Start(); 228 contents_->GetManifest(base::Bind(&BookmarkAppHelper::OnDidGetManifest,
212 else 229 base::Unretained(this)));
230 } else {
213 OnIconsDownloaded(true, std::map<GURL, std::vector<SkBitmap> >()); 231 OnIconsDownloaded(true, std::map<GURL, std::vector<SkBitmap> >());
232 }
233 }
234
235 void BookmarkAppHelper::OnDidGetManifest(const content::Manifest& manifest) {
236 if (contents_->IsBeingDestroyed())
237 return;
238
239 UpdateWebAppInfoFromManifest(manifest, &web_app_info_);
240
241 DCHECK(favicon_downloader_.get());
242 favicon_downloader_->Start();
214 } 243 }
215 244
216 void BookmarkAppHelper::OnIconsDownloaded( 245 void BookmarkAppHelper::OnIconsDownloaded(
217 bool success, 246 bool success,
218 const std::map<GURL, std::vector<SkBitmap> >& bitmaps) { 247 const std::map<GURL, std::vector<SkBitmap> >& bitmaps) {
219 // The tab has navigated away during the icon download. Cancel the bookmark 248 // The tab has navigated away during the icon download. Cancel the bookmark
220 // app creation. 249 // app creation.
221 if (!success) { 250 if (!success) {
222 favicon_downloader_.reset(); 251 favicon_downloader_.reset();
223 callback_.Run(NULL, web_app_info_); 252 callback_.Run(NULL, web_app_info_);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 extension, info_list, base::Bind(&OnIconsLoaded, web_app_info, callback)); 417 extension, info_list, base::Bind(&OnIconsLoaded, web_app_info, callback));
389 } 418 }
390 419
391 bool IsValidBookmarkAppUrl(const GURL& url) { 420 bool IsValidBookmarkAppUrl(const GURL& url) {
392 URLPattern origin_only_pattern(Extension::kValidWebExtentSchemes); 421 URLPattern origin_only_pattern(Extension::kValidWebExtentSchemes);
393 origin_only_pattern.SetMatchAllURLs(true); 422 origin_only_pattern.SetMatchAllURLs(true);
394 return url.is_valid() && origin_only_pattern.MatchesURL(url); 423 return url.is_valid() && origin_only_pattern.MatchesURL(url);
395 } 424 }
396 425
397 } // namespace extensions 426 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/bookmark_app_helper.h ('k') | chrome/browser/extensions/bookmark_app_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698