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

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

Issue 1644573002: Notification actions may have an icon url. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/NotificationData.h" 5 #include "modules/notifications/NotificationData.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/SerializedScriptValue.h" 8 #include "bindings/core/v8/SerializedScriptValue.h"
9 #include "bindings/core/v8/SerializedScriptValueFactory.h" 9 #include "bindings/core/v8/SerializedScriptValueFactory.h"
10 #include "core/dom/ExecutionContext.h" 10 #include "core/dom/ExecutionContext.h"
11 #include "modules/notifications/Notification.h" 11 #include "modules/notifications/Notification.h"
12 #include "modules/notifications/NotificationOptions.h" 12 #include "modules/notifications/NotificationOptions.h"
13 #include "modules/vibration/NavigatorVibration.h" 13 #include "modules/vibration/NavigatorVibration.h"
14 #include "platform/RuntimeEnabledFeatures.h"
15 #include "platform/weborigin/KURL.h" 14 #include "platform/weborigin/KURL.h"
16 #include "wtf/CurrentTime.h" 15 #include "wtf/CurrentTime.h"
17 16
18 namespace blink { 17 namespace blink {
19 namespace { 18 namespace {
20 19
21 WebNotificationData::Direction toDirectionEnumValue(const String& direction) 20 WebNotificationData::Direction toDirectionEnumValue(const String& direction)
22 { 21 {
23 if (direction == "ltr") 22 if (direction == "ltr")
24 return WebNotificationData::DirectionLeftToRight; 23 return WebNotificationData::DirectionLeftToRight;
(...skipping 16 matching lines...) Expand all
41 WebNotificationData webData; 40 WebNotificationData webData;
42 41
43 webData.title = title; 42 webData.title = title;
44 webData.direction = toDirectionEnumValue(options.dir()); 43 webData.direction = toDirectionEnumValue(options.dir());
45 webData.lang = options.lang(); 44 webData.lang = options.lang();
46 webData.body = options.body(); 45 webData.body = options.body();
47 webData.tag = options.tag(); 46 webData.tag = options.tag();
48 47
49 KURL iconUrl; 48 KURL iconUrl;
50 49
51 // TODO(peter): Apply the appropriate CORS checks on the |iconUrl|.
52 if (options.hasIcon() && !options.icon().isEmpty()) { 50 if (options.hasIcon() && !options.icon().isEmpty()) {
53 iconUrl = executionContext->completeURL(options.icon()); 51 iconUrl = executionContext->completeURL(options.icon());
54 if (!iconUrl.isValid()) 52 if (!iconUrl.isValid())
55 iconUrl = KURL(); 53 iconUrl = KURL();
56 } 54 }
57 55
58 webData.icon = iconUrl; 56 webData.icon = iconUrl;
59 webData.vibrate = NavigatorVibration::sanitizeVibrationPattern(options.vibra te()); 57 webData.vibrate = NavigatorVibration::sanitizeVibrationPattern(options.vibra te());
60 webData.timestamp = options.hasTimestamp() ? static_cast<double>(options.tim estamp()) : WTF::currentTimeMS(); 58 webData.timestamp = options.hasTimestamp() ? static_cast<double>(options.tim estamp()) : WTF::currentTimeMS();
61 webData.silent = options.silent(); 59 webData.silent = options.silent();
(...skipping 14 matching lines...) Expand all
76 74
77 const size_t maxActions = Notification::maxActions(); 75 const size_t maxActions = Notification::maxActions();
78 for (const NotificationAction& action : options.actions()) { 76 for (const NotificationAction& action : options.actions()) {
79 if (actions.size() >= maxActions) 77 if (actions.size() >= maxActions)
80 break; 78 break;
81 79
82 WebNotificationAction webAction; 80 WebNotificationAction webAction;
83 webAction.action = action.action(); 81 webAction.action = action.action();
84 webAction.title = action.title(); 82 webAction.title = action.title();
85 83
84 KURL iconUrl;
85 if (action.hasIcon() && !action.icon().isEmpty()) {
86 iconUrl = executionContext->completeURL(action.icon());
87 if (!iconUrl.isValid())
88 iconUrl = KURL();
89 }
90 webAction.icon = iconUrl;
91
86 actions.append(webAction); 92 actions.append(webAction);
87 } 93 }
88 94
89 webData.actions = actions; 95 webData.actions = actions;
90 96
91 return webData; 97 return webData;
92 } 98 }
93 99
94 } // namespace blink 100 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698