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

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, 7 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 20 matching lines...) Expand all
237 downloaded_icons.push_back(*bitmap_it); 244 downloaded_icons.push_back(*bitmap_it);
238 } 245 }
239 } 246 }
240 247
241 // If there are icons that don't match the accepted icon sizes, find the 248 // 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 249 // 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. 250 // icon will be resized and used for at most one size.
244 std::map<int, SkBitmap> resized_bitmaps( 251 std::map<int, SkBitmap> resized_bitmaps(
245 ConstrainBitmapsToSizes(downloaded_icons, allowed_sizes)); 252 ConstrainBitmapsToSizes(downloaded_icons, allowed_sizes));
246 253
254 // Add the existing icon from WebApplicationInfo if there is no resized icon.
255 if (resized_bitmaps.empty() &&
256 web_app_info_.icons.size() &&
257 !web_app_info_.icons[0].data.drawsNothing()) {
258 SkBitmap* icon = &web_app_info_.icons[0].data;
calamity 2014/05/27 05:32:12 Just use a const SkBitmap& here.
wjywbs 2014/05/27 06:22:32 Done.
259 DCHECK_EQ(icon->width(), icon->height());
260 resized_bitmaps[icon->width()] = *icon;
261 }
262
calamity 2014/05/27 05:32:12 It seems a little messy to just take the first ico
wjywbs 2014/05/27 06:22:32 Done, but can we clear the web_app_info_.icons? It
calamity 2014/05/27 07:18:48 Clearing the icons should be fine. The icon URL i
wjywbs 2014/05/27 22:20:21 I added "web_app_info_.icons.clear();".
247 // Generate container icons from smaller icons. 263 // Generate container icons from smaller icons.
248 const int kIconSizesToGenerate[] = {extension_misc::EXTENSION_ICON_SMALL, 264 const int kIconSizesToGenerate[] = {extension_misc::EXTENSION_ICON_SMALL,
249 extension_misc::EXTENSION_ICON_MEDIUM, }; 265 extension_misc::EXTENSION_ICON_MEDIUM, };
250 const std::set<int> generate_sizes( 266 const std::set<int> generate_sizes(
251 kIconSizesToGenerate, 267 kIconSizesToGenerate,
252 kIconSizesToGenerate + arraysize(kIconSizesToGenerate)); 268 kIconSizesToGenerate + arraysize(kIconSizesToGenerate));
253 269
254 // Only generate icons if larger icons don't exist. This means the app 270 // Only generate icons if larger icons don't exist. This means the app
255 // launcher and the taskbar will do their best downsizing large icons and 271 // launcher and the taskbar will do their best downsizing large icons and
256 // these icons are only generated as a last resort against upscaling a smaller 272 // these icons are only generated as a last resort against upscaling a smaller
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 extension, info_list, base::Bind(&OnIconsLoaded, web_app_info, callback)); 389 extension, info_list, base::Bind(&OnIconsLoaded, web_app_info, callback));
374 } 390 }
375 391
376 bool IsValidBookmarkAppUrl(const GURL& url) { 392 bool IsValidBookmarkAppUrl(const GURL& url) {
377 URLPattern origin_only_pattern(Extension::kValidWebExtentSchemes); 393 URLPattern origin_only_pattern(Extension::kValidWebExtentSchemes);
378 origin_only_pattern.SetMatchAllURLs(true); 394 origin_only_pattern.SetMatchAllURLs(true);
379 return url.is_valid() && origin_only_pattern.MatchesURL(url); 395 return url.is_valid() && origin_only_pattern.MatchesURL(url);
380 } 396 }
381 397
382 } // namespace extensions 398 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/bookmark_app_helper.h ('k') | chrome/common/extensions/api/_api_features.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698