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

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

Issue 229553003: Implement syncing of bookmark apps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test Created 6 years, 8 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 "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/extensions/crx_installer.h" 9 #include "chrome/browser/extensions/crx_installer.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/favicon_downloader.h" 11 #include "chrome/browser/extensions/favicon_downloader.h"
12 #include "chrome/browser/extensions/image_loader.h"
12 #include "chrome/browser/extensions/tab_helper.h" 13 #include "chrome/browser/extensions/tab_helper.h"
13 #include "chrome/common/extensions/extension_constants.h" 14 #include "chrome/common/extensions/extension_constants.h"
14 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 15 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
15 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/notification_source.h" 17 #include "content/public/browser/notification_source.h"
17 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
18 #include "extensions/common/extension.h" 19 #include "extensions/common/extension.h"
19 #include "extensions/common/manifest_handlers/icons_handler.h" 20 #include "extensions/common/manifest_handlers/icons_handler.h"
20 #include "extensions/common/url_pattern.h" 21 #include "extensions/common/url_pattern.h"
21 #include "skia/ext/image_operations.h" 22 #include "skia/ext/image_operations.h"
22 #include "skia/ext/platform_canvas.h" 23 #include "skia/ext/platform_canvas.h"
23 #include "third_party/skia/include/core/SkBitmap.h" 24 #include "third_party/skia/include/core/SkBitmap.h"
24 #include "ui/gfx/color_analysis.h" 25 #include "ui/gfx/color_analysis.h"
25 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
27 #include "ui/gfx/image/image_family.h"
28
29 namespace {
30
31 void OnIconsLoaded(
32 WebApplicationInfo web_app_info,
33 const base::Callback<void(const WebApplicationInfo&)> callback,
34 const gfx::ImageFamily& image_family) {
35 for (gfx::ImageFamily::const_iterator it = image_family.begin();
36 it != image_family.end();
37 ++it) {
38 WebApplicationInfo::IconInfo icon_info;
39 icon_info.data = *it->ToSkBitmap();
40 icon_info.width = icon_info.data.width();
41 icon_info.height = icon_info.data.height();
42 web_app_info.icons.push_back(icon_info);
43 }
44 callback.Run(web_app_info);
45 }
46
47 } // namespace
26 48
27 namespace extensions { 49 namespace extensions {
28 50
29 // static 51 // static
30 std::map<int, SkBitmap> BookmarkAppHelper::ConstrainBitmapsToSizes( 52 std::map<int, SkBitmap> BookmarkAppHelper::ConstrainBitmapsToSizes(
31 const std::vector<SkBitmap>& bitmaps, 53 const std::vector<SkBitmap>& bitmaps,
32 const std::set<int>& sizes) { 54 const std::set<int>& sizes) {
33 std::map<int, SkBitmap> output_bitmaps; 55 std::map<int, SkBitmap> output_bitmaps;
34 std::map<int, SkBitmap> ordered_bitmaps; 56 std::map<int, SkBitmap> ordered_bitmaps;
35 for (std::vector<SkBitmap>::const_iterator it = bitmaps.begin(); 57 for (std::vector<SkBitmap>::const_iterator it = bitmaps.begin();
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 307 }
286 308
287 void CreateOrUpdateBookmarkApp(ExtensionService* service, 309 void CreateOrUpdateBookmarkApp(ExtensionService* service,
288 WebApplicationInfo& web_app_info) { 310 WebApplicationInfo& web_app_info) {
289 scoped_refptr<extensions::CrxInstaller> installer( 311 scoped_refptr<extensions::CrxInstaller> installer(
290 extensions::CrxInstaller::CreateSilent(service)); 312 extensions::CrxInstaller::CreateSilent(service));
291 installer->set_error_on_unsupported_requirements(true); 313 installer->set_error_on_unsupported_requirements(true);
292 installer->InstallWebApp(web_app_info); 314 installer->InstallWebApp(web_app_info);
293 } 315 }
294 316
317 void GetWebApplicationInfoFromApp(
318 content::BrowserContext* browser_context,
319 const extensions::Extension* extension,
320 const base::Callback<void(const WebApplicationInfo&)> callback) {
321 if (!extension->from_bookmark()) {
322 callback.Run(WebApplicationInfo());
323 return;
324 }
325
326 WebApplicationInfo web_app_info;
327 web_app_info.app_url = AppLaunchInfo::GetLaunchWebURL(extension);
328 web_app_info.title = base::UTF8ToUTF16(extension->non_localized_name());
329 web_app_info.description = base::UTF8ToUTF16(extension->description());
330
331 std::vector<extensions::ImageLoader::ImageRepresentation> info_list;
332 for (size_t i = 0; i < extension_misc::kNumExtensionIconSizes; ++i) {
333 int size = extension_misc::kExtensionIconSizes[i];
334 extensions::ExtensionResource resource =
335 extensions::IconsInfo::GetIconResource(
336 extension, size, ExtensionIconSet::MATCH_EXACTLY);
337 if (!resource.empty()) {
338 info_list.push_back(extensions::ImageLoader::ImageRepresentation(
339 resource,
340 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE,
341 gfx::Size(size, size),
342 ui::SCALE_FACTOR_100P));
343 }
344 }
345
346 extensions::ImageLoader::Get(browser_context)->LoadImageFamilyAsync(
347 extension, info_list, base::Bind(&OnIconsLoaded, web_app_info, callback));
348 }
349
295 bool IsValidBookmarkAppUrl(const GURL& url) { 350 bool IsValidBookmarkAppUrl(const GURL& url) {
296 URLPattern origin_only_pattern(Extension::kValidWebExtentSchemes); 351 URLPattern origin_only_pattern(Extension::kValidWebExtentSchemes);
297 origin_only_pattern.SetMatchAllURLs(true); 352 origin_only_pattern.SetMatchAllURLs(true);
298 return url.is_valid() && origin_only_pattern.MatchesURL(url); 353 return url.is_valid() && origin_only_pattern.MatchesURL(url);
299 } 354 }
300 355
301 } // namespace extensions 356 } // 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