| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL(
options.icon()); | 65 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL(
options.icon()); |
| 66 if (!iconUrl.isEmpty() && iconUrl.isValid()) | 66 if (!iconUrl.isEmpty() && iconUrl.isValid()) |
| 67 notification->setIconUrl(iconUrl); | 67 notification->setIconUrl(iconUrl); |
| 68 } | 68 } |
| 69 | 69 |
| 70 String insecureOriginMessage; | 70 String insecureOriginMessage; |
| 71 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq
uiringSecureOrigin(insecureOriginMessage) | 71 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq
uiringSecureOrigin(insecureOriginMessage) |
| 72 ? UseCounter::NotificationSecureOrigin : UseCounter::NotificationInsecur
eOrigin; | 72 ? UseCounter::NotificationSecureOrigin : UseCounter::NotificationInsecur
eOrigin; |
| 73 UseCounter::count(context, feature); | 73 UseCounter::count(context, feature); |
| 74 | 74 |
| 75 notification->scheduleShow(); |
| 75 notification->suspendIfNeeded(); | 76 notification->suspendIfNeeded(); |
| 76 return notification; | 77 return notification; |
| 77 } | 78 } |
| 79 |
| 80 Notification* Notification::create(ExecutionContext* context, const String& pers
istentId, const WebNotificationData& data) |
| 81 { |
| 82 Notification* notification = new Notification(data.title, context); |
| 83 |
| 84 notification->setPersistentId(persistentId); |
| 85 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR
ight ? "ltr" : "rtl"); |
| 86 notification->setLang(data.lang); |
| 87 notification->setBody(data.body); |
| 88 notification->setTag(data.tag); |
| 89 |
| 90 if (!data.icon.isEmpty()) |
| 91 notification->setIconUrl(data.icon); |
| 92 |
| 93 notification->setState(NotificationStateShowing); |
| 94 notification->suspendIfNeeded(); |
| 95 return notification; |
| 96 } |
| 78 | 97 |
| 79 Notification::Notification(const String& title, ExecutionContext* context) | 98 Notification::Notification(const String& title, ExecutionContext* context) |
| 80 : ActiveDOMObject(context) | 99 : ActiveDOMObject(context) |
| 81 , m_title(title) | 100 , m_title(title) |
| 82 , m_dir("auto") | 101 , m_dir("auto") |
| 83 , m_state(NotificationStateIdle) | 102 , m_state(NotificationStateIdle) |
| 84 , m_asyncRunner(this, &Notification::show) | 103 , m_asyncRunner(this, &Notification::show) |
| 85 { | 104 { |
| 86 ASSERT(notificationManager()); | 105 ASSERT(notificationManager()); |
| 87 | |
| 88 m_asyncRunner.runAsync(); | |
| 89 } | 106 } |
| 90 | 107 |
| 91 Notification::~Notification() | 108 Notification::~Notification() |
| 92 { | 109 { |
| 93 } | 110 } |
| 94 | 111 |
| 112 void Notification::scheduleShow() |
| 113 { |
| 114 ASSERT(m_state == NotificationStateIdle); |
| 115 ASSERT(!m_asyncRunner.isActive()); |
| 116 |
| 117 m_asyncRunner.runAsync(); |
| 118 } |
| 119 |
| 95 void Notification::show() | 120 void Notification::show() |
| 96 { | 121 { |
| 97 ASSERT(m_state == NotificationStateIdle); | 122 ASSERT(m_state == NotificationStateIdle); |
| 98 if (Notification::checkPermission(executionContext()) != WebNotificationPerm
issionAllowed) { | 123 if (Notification::checkPermission(executionContext()) != WebNotificationPerm
issionAllowed) { |
| 99 dispatchErrorEvent(); | 124 dispatchErrorEvent(); |
| 100 return; | 125 return; |
| 101 } | 126 } |
| 102 | 127 |
| 103 SecurityOrigin* origin = executionContext()->securityOrigin(); | 128 SecurityOrigin* origin = executionContext()->securityOrigin(); |
| 104 ASSERT(origin); | 129 ASSERT(origin); |
| 105 | 130 |
| 106 // FIXME: Associate the appropriate text direction with the notification. | 131 // FIXME: Associate the appropriate text direction with the notification. |
| 107 // FIXME: Do CSP checks on the associated notification icon. | 132 // FIXME: Do CSP checks on the associated notification icon. |
| 108 WebNotificationData notificationData(m_title, WebNotificationData::Direction
LeftToRight, m_lang, m_body, m_tag, m_iconUrl); | 133 WebNotificationData notificationData(m_title, WebNotificationData::Direction
LeftToRight, m_lang, m_body, m_tag, m_iconUrl); |
| 109 notificationManager()->show(WebSerializedOrigin(*origin), notificationData,
this); | 134 notificationManager()->show(WebSerializedOrigin(*origin), notificationData,
this); |
| 110 | 135 |
| 111 m_state = NotificationStateShowing; | 136 m_state = NotificationStateShowing; |
| 112 } | 137 } |
| 113 | 138 |
| 114 void Notification::close() | 139 void Notification::close() |
| 115 { | 140 { |
| 116 if (m_state != NotificationStateShowing) | 141 if (m_state != NotificationStateShowing) |
| 117 return; | 142 return; |
| 118 | 143 |
| 119 m_state = NotificationStateClosed; | 144 m_state = NotificationStateClosed; |
| 120 notificationManager()->close(this); | 145 if (!m_persistentId.isEmpty()) |
| 146 notificationManager()->closePersistent(m_persistentId); |
| 147 else |
| 148 notificationManager()->close(this); |
| 121 } | 149 } |
| 122 | 150 |
| 123 void Notification::dispatchShowEvent() | 151 void Notification::dispatchShowEvent() |
| 124 { | 152 { |
| 125 dispatchEvent(Event::create(EventTypeNames::show)); | 153 dispatchEvent(Event::create(EventTypeNames::show)); |
| 126 } | 154 } |
| 127 | 155 |
| 128 void Notification::dispatchClickEvent() | 156 void Notification::dispatchClickEvent() |
| 129 { | 157 { |
| 130 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); | 158 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 236 |
| 209 m_asyncRunner.stop(); | 237 m_asyncRunner.stop(); |
| 210 } | 238 } |
| 211 | 239 |
| 212 bool Notification::hasPendingActivity() const | 240 bool Notification::hasPendingActivity() const |
| 213 { | 241 { |
| 214 return m_state == NotificationStateShowing || m_asyncRunner.isActive(); | 242 return m_state == NotificationStateShowing || m_asyncRunner.isActive(); |
| 215 } | 243 } |
| 216 | 244 |
| 217 } // namespace blink | 245 } // namespace blink |
| OLD | NEW |