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

Side by Side Diff: third_party/WebKit/Source/modules/notifications/NotificationResourcesLoader.cpp

Issue 1901133002: Move the notification constants to Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "modules/notifications/NotificationResourcesLoader.h" 5 #include "modules/notifications/NotificationResourcesLoader.h"
6 6
7 #include "platform/weborigin/KURL.h" 7 #include "platform/weborigin/KURL.h"
8 #include "public/platform/modules/notifications/WebNotificationConstants.h"
8 #include "public/platform/modules/notifications/WebNotificationData.h" 9 #include "public/platform/modules/notifications/WebNotificationData.h"
9 #include "public/platform/modules/notifications/WebNotificationResources.h" 10 #include "public/platform/modules/notifications/WebNotificationResources.h"
10 #include "skia/ext/image_operations.h" 11 #include "skia/ext/image_operations.h"
11 #include "third_party/skia/include/core/SkBitmap.h" 12 #include "third_party/skia/include/core/SkBitmap.h"
12 13
13 namespace blink { 14 namespace blink {
14 15
15 namespace { 16 namespace {
16 17
17 // TODO(mvanouwerkerk): Get icon dimensions from the embedder.
18
19 // The maximum reasonable notification icon size, scaled from dip units to
20 // pixels using the largest supported scaling factor.
21 static const int kMaxIconSizePx = 320; // 80 dip * 4
22
23 // The maximum reasonable badge size, scaled from dip units to pixels using the
24 // largest supported scaling factor.
25 static const int kMaxBadgeSizePx = 96; // 24 dip * 4
26
27 // The maximum reasonable action icon size, scaled from dip units to pixels
28 // using the largest supported scaling factor.
29 static const int kMaxActionIconSizePx = 128; // 32 dip * 4
30
31 // Scales down |image| to fit within |maxSizePx| if its width or height is 18 // Scales down |image| to fit within |maxSizePx| if its width or height is
32 // larger than |maxSizePx| and returns the result. Otherwise does nothing and 19 // larger than |maxSizePx| and returns the result. Otherwise does nothing and
33 // returns |image| unchanged. 20 // returns |image| unchanged.
34 // TODO(mvanouwerkerk): Explore doing the scaling on a background thread. 21 // TODO(mvanouwerkerk): Explore doing the scaling on a background thread.
35 SkBitmap scaleDownIfNeeded(const SkBitmap& image, int maxSizePx) 22 SkBitmap scaleDownIfNeeded(const SkBitmap& image, int maxSizePx)
36 { 23 {
37 if (image.width() > maxSizePx || image.height() > maxSizePx) 24 if (image.width() > maxSizePx || image.height() > maxSizePx)
38 return skia::ImageOperations::Resize(image, skia::ImageOperations::RESIZ E_BEST, std::min(image.width(), maxSizePx), std::min(image.height(), maxSizePx)) ; 25 return skia::ImageOperations::Resize(image, skia::ImageOperations::RESIZ E_BEST, std::min(image.width(), maxSizePx), std::min(image.height(), maxSizePx)) ;
39 return image; 26 return image;
40 } 27 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 return; 82 return;
96 } 83 }
97 84
98 NotificationImageLoader* imageLoader = new NotificationImageLoader(); 85 NotificationImageLoader* imageLoader = new NotificationImageLoader();
99 m_imageLoaders.append(imageLoader); 86 m_imageLoaders.append(imageLoader);
100 imageLoader->start(executionContext, url, imageCallback); 87 imageLoader->start(executionContext, url, imageCallback);
101 } 88 }
102 89
103 void NotificationResourcesLoader::didLoadIcon(const SkBitmap& image) 90 void NotificationResourcesLoader::didLoadIcon(const SkBitmap& image)
104 { 91 {
105 m_icon = scaleDownIfNeeded(image, kMaxIconSizePx); 92 m_icon = scaleDownIfNeeded(image, kWebNotificationMaxIconSizePx);
106 didFinishRequest(); 93 didFinishRequest();
107 } 94 }
108 95
109 void NotificationResourcesLoader::didLoadBadge(const SkBitmap& image) 96 void NotificationResourcesLoader::didLoadBadge(const SkBitmap& image)
110 { 97 {
111 m_badge = scaleDownIfNeeded(image, kMaxBadgeSizePx); 98 m_badge = scaleDownIfNeeded(image, kWebNotificationMaxBadgeSizePx);
112 didFinishRequest(); 99 didFinishRequest();
113 } 100 }
114 101
115 void NotificationResourcesLoader::didLoadActionIcon(size_t actionIndex, const Sk Bitmap& image) 102 void NotificationResourcesLoader::didLoadActionIcon(size_t actionIndex, const Sk Bitmap& image)
116 { 103 {
117 DCHECK_LT(actionIndex, m_actionIcons.size()); 104 DCHECK_LT(actionIndex, m_actionIcons.size());
118 105
119 m_actionIcons[actionIndex] = scaleDownIfNeeded(image, kMaxActionIconSizePx); 106 m_actionIcons[actionIndex] = scaleDownIfNeeded(image, kWebNotificationMaxAct ionIconSizePx);
120 didFinishRequest(); 107 didFinishRequest();
121 } 108 }
122 109
123 void NotificationResourcesLoader::didFinishRequest() 110 void NotificationResourcesLoader::didFinishRequest()
124 { 111 {
125 DCHECK_GT(m_pendingRequestCount, 0); 112 DCHECK_GT(m_pendingRequestCount, 0);
126 m_pendingRequestCount--; 113 m_pendingRequestCount--;
127 if (!m_pendingRequestCount) { 114 if (!m_pendingRequestCount) {
128 stop(); 115 stop();
129 (*m_completionCallback)(this); 116 (*m_completionCallback)(this);
130 // The |this| pointer may have been deleted now. 117 // The |this| pointer may have been deleted now.
131 } 118 }
132 } 119 }
133 120
134 } // namespace blink 121 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698