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

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

Issue 266353006: Add generateAppForLink function in chrome.management (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
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/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 registrar_.Add(this, 175 registrar_.Add(this,
176 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 176 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
177 content::Source<CrxInstaller>(crx_installer_.get())); 177 content::Source<CrxInstaller>(crx_installer_.get()));
178 178
179 registrar_.Add(this, 179 registrar_.Add(this,
180 chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, 180 chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR,
181 content::Source<CrxInstaller>(crx_installer_.get())); 181 content::Source<CrxInstaller>(crx_installer_.get()));
182 182
183 crx_installer_->set_error_on_unsupported_requirements(true); 183 crx_installer_->set_error_on_unsupported_requirements(true);
184 184
185 if (!contents)
186 return;
187
185 // Add urls from the WebApplicationInfo. 188 // Add urls from the WebApplicationInfo.
186 std::vector<GURL> web_app_info_icon_urls; 189 std::vector<GURL> web_app_info_icon_urls;
187 for (std::vector<WebApplicationInfo::IconInfo>::const_iterator it = 190 for (std::vector<WebApplicationInfo::IconInfo>::const_iterator it =
188 web_app_info_.icons.begin(); 191 web_app_info_.icons.begin();
189 it != web_app_info_.icons.end(); 192 it != web_app_info_.icons.end();
190 ++it) { 193 ++it) {
191 if (it->url.is_valid()) 194 if (it->url.is_valid())
192 web_app_info_icon_urls.push_back(it->url); 195 web_app_info_icon_urls.push_back(it->url);
193 } 196 }
194 197
195 favicon_downloader_.reset( 198 favicon_downloader_.reset(
196 new FaviconDownloader(contents, 199 new FaviconDownloader(contents,
197 web_app_info_icon_urls, 200 web_app_info_icon_urls,
198 base::Bind(&BookmarkAppHelper::OnIconsDownloaded, 201 base::Bind(&BookmarkAppHelper::OnIconsDownloaded,
199 base::Unretained(this)))); 202 base::Unretained(this))));
200 } 203 }
201 204
202 BookmarkAppHelper::~BookmarkAppHelper() {} 205 BookmarkAppHelper::~BookmarkAppHelper() {}
203 206
204 void BookmarkAppHelper::Create(const CreateBookmarkAppCallback& callback) { 207 void BookmarkAppHelper::Create(const CreateBookmarkAppCallback& callback) {
205 callback_ = callback; 208 callback_ = callback;
206 favicon_downloader_->Start(); 209
210 if (favicon_downloader_.get())
211 favicon_downloader_->Start();
212 else
213 OnIconsDownloaded(true, std::map<GURL, std::vector<SkBitmap> >());
207 } 214 }
208 215
209 void BookmarkAppHelper::OnIconsDownloaded( 216 void BookmarkAppHelper::OnIconsDownloaded(
210 bool success, 217 bool success,
211 const std::map<GURL, std::vector<SkBitmap> >& bitmaps) { 218 const std::map<GURL, std::vector<SkBitmap> >& bitmaps) {
212 // The tab has navigated away during the icon download. Cancel the bookmark 219 // The tab has navigated away during the icon download. Cancel the bookmark
213 // app creation. 220 // app creation.
214 if (!success) { 221 if (!success) {
215 favicon_downloader_.reset(); 222 favicon_downloader_.reset();
216 callback_.Run(NULL, web_app_info_); 223 callback_.Run(NULL, web_app_info_);
(...skipping 14 matching lines...) Expand all
231 map_it->second.begin(); 238 map_it->second.begin();
232 bitmap_it != map_it->second.end(); 239 bitmap_it != map_it->second.end();
233 ++bitmap_it) { 240 ++bitmap_it) {
234 if (bitmap_it->empty() || bitmap_it->width() != bitmap_it->height()) 241 if (bitmap_it->empty() || bitmap_it->width() != bitmap_it->height())
235 continue; 242 continue;
236 243
237 downloaded_icons.push_back(*bitmap_it); 244 downloaded_icons.push_back(*bitmap_it);
238 } 245 }
239 } 246 }
240 247
248 // Add all existing icons from WebApplicationInfo.
249 for (std::vector<WebApplicationInfo::IconInfo>::const_iterator it =
250 web_app_info_.icons.begin();
251 it != web_app_info_.icons.end();
252 ++it) {
253 const SkBitmap& icon = it->data;
254 if (!icon.drawsNothing() && icon.width() == icon.height())
255 downloaded_icons.push_back(icon);
256 }
257
258 web_app_info_.icons.clear();
259
241 // If there are icons that don't match the accepted icon sizes, find the 260 // If there are icons that don't match the accepted icon sizes, find the
242 // closest bigger icon to the accepted sizes and resize the icon to it. An 261 // closest bigger icon to the accepted sizes and resize the icon to it. An
243 // icon will be resized and used for at most one size. 262 // icon will be resized and used for at most one size.
244 std::map<int, SkBitmap> resized_bitmaps( 263 std::map<int, SkBitmap> resized_bitmaps(
245 ConstrainBitmapsToSizes(downloaded_icons, allowed_sizes)); 264 ConstrainBitmapsToSizes(downloaded_icons, allowed_sizes));
246 265
247 // Generate container icons from smaller icons. 266 // Generate container icons from smaller icons.
248 const int kIconSizesToGenerate[] = {extension_misc::EXTENSION_ICON_SMALL, 267 const int kIconSizesToGenerate[] = {extension_misc::EXTENSION_ICON_SMALL,
249 extension_misc::EXTENSION_ICON_MEDIUM, }; 268 extension_misc::EXTENSION_ICON_MEDIUM, };
250 const std::set<int> generate_sizes( 269 const std::set<int> generate_sizes(
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 extension, info_list, base::Bind(&OnIconsLoaded, web_app_info, callback)); 392 extension, info_list, base::Bind(&OnIconsLoaded, web_app_info, callback));
374 } 393 }
375 394
376 bool IsValidBookmarkAppUrl(const GURL& url) { 395 bool IsValidBookmarkAppUrl(const GURL& url) {
377 URLPattern origin_only_pattern(Extension::kValidWebExtentSchemes); 396 URLPattern origin_only_pattern(Extension::kValidWebExtentSchemes);
378 origin_only_pattern.SetMatchAllURLs(true); 397 origin_only_pattern.SetMatchAllURLs(true);
379 return url.is_valid() && origin_only_pattern.MatchesURL(url); 398 return url.is_valid() && origin_only_pattern.MatchesURL(url);
380 } 399 }
381 400
382 } // namespace extensions 401 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698