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

Side by Side Diff: Source/modules/notifications/Notification.cpp

Issue 268353004: NotificationController::clientFrom() should return a reference (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
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
OLDNEW
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 25 matching lines...) Expand all
36 #include "core/dom/Document.h" 36 #include "core/dom/Document.h"
37 #include "core/frame/UseCounter.h" 37 #include "core/frame/UseCounter.h"
38 #include "core/page/WindowFocusAllowedIndicator.h" 38 #include "core/page/WindowFocusAllowedIndicator.h"
39 #include "modules/notifications/NotificationClient.h" 39 #include "modules/notifications/NotificationClient.h"
40 #include "modules/notifications/NotificationController.h" 40 #include "modules/notifications/NotificationController.h"
41 41
42 namespace WebCore { 42 namespace WebCore {
43 43
44 Notification* Notification::create(ExecutionContext* context, const String& titl e, const Dictionary& options) 44 Notification* Notification::create(ExecutionContext* context, const String& titl e, const Dictionary& options)
45 { 45 {
46 NotificationClient* client = NotificationController::clientFrom(toDocument(c ontext)->frame()); 46 NotificationClient& client = NotificationController::clientFrom(toDocument(c ontext)->frame());
47 Notification* notification = adoptRefCountedGarbageCollected(new Notificatio n(title, context, client)); 47 Notification* notification = adoptRefCountedGarbageCollected(new Notificatio n(title, context, client));
48 48
49 String argument; 49 String argument;
50 if (options.get("body", argument)) 50 if (options.get("body", argument))
51 notification->setBody(argument); 51 notification->setBody(argument);
52 if (options.get("tag", argument)) 52 if (options.get("tag", argument))
53 notification->setTag(argument); 53 notification->setTag(argument);
54 if (options.get("lang", argument)) 54 if (options.get("lang", argument))
55 notification->setLang(argument); 55 notification->setLang(argument);
56 if (options.get("dir", argument)) 56 if (options.get("dir", argument))
57 notification->setDir(argument); 57 notification->setDir(argument);
58 if (options.get("icon", argument)) { 58 if (options.get("icon", argument)) {
59 KURL iconUrl = argument.isEmpty() ? KURL() : context->completeURL(argume nt); 59 KURL iconUrl = argument.isEmpty() ? KURL() : context->completeURL(argume nt);
60 if (!iconUrl.isEmpty() && iconUrl.isValid()) 60 if (!iconUrl.isEmpty() && iconUrl.isValid())
61 notification->setIconUrl(iconUrl); 61 notification->setIconUrl(iconUrl);
62 } 62 }
63 63
64 notification->suspendIfNeeded(); 64 notification->suspendIfNeeded();
65 return notification; 65 return notification;
66 } 66 }
67 67
68 Notification::Notification(const String& title, ExecutionContext* context, Notif icationClient* client) 68 Notification::Notification(const String& title, ExecutionContext* context, Notif icationClient& client)
69 : ActiveDOMObject(context) 69 : ActiveDOMObject(context)
70 , m_title(title) 70 , m_title(title)
71 , m_dir("auto") 71 , m_dir("auto")
72 , m_state(Idle) 72 , m_state(Idle)
73 , m_client(client) 73 , m_client(client)
74 , m_asyncRunner(adoptPtr(new AsyncMethodRunner<Notification>(this, &Notifica tion::show))) 74 , m_asyncRunner(adoptPtr(new AsyncMethodRunner<Notification>(this, &Notifica tion::show)))
75 { 75 {
76 ASSERT(m_client);
77 ScriptWrappable::init(this); 76 ScriptWrappable::init(this);
78 77
79 m_asyncRunner->runAsync(); 78 m_asyncRunner->runAsync();
80 } 79 }
81 80
82 Notification::~Notification() 81 Notification::~Notification()
83 { 82 {
84 } 83 }
85 84
86 void Notification::show() 85 void Notification::show()
87 { 86 {
88 ASSERT(m_state == Idle); 87 ASSERT(m_state == Idle);
89 if (!toDocument(executionContext())->page()) 88 if (!toDocument(executionContext())->page())
90 return; 89 return;
91 90
92 if (NotificationController::from(toDocument(executionContext())->frame())->c lient()->checkPermission(executionContext()) != NotificationClient::PermissionAl lowed) { 91 if (NotificationController::from(toDocument(executionContext())->frame())->c lient().checkPermission(executionContext()) != NotificationClient::PermissionAll owed) {
Peter Beverloo 2014/05/08 12:59:34 You can use m_client.checkPermission(executionCont
gyuyoung-inactive 2014/05/08 15:50:27 Done.
93 dispatchErrorEvent(); 92 dispatchErrorEvent();
94 return; 93 return;
95 } 94 }
96 95
97 if (m_client->show(this)) 96 if (m_client.show(this))
98 m_state = Showing; 97 m_state = Showing;
99 } 98 }
100 99
101 void Notification::close() 100 void Notification::close()
102 { 101 {
103 switch (m_state) { 102 switch (m_state) {
104 case Idle: 103 case Idle:
105 break; 104 break;
106 case Showing: 105 case Showing:
107 m_client->close(this); 106 m_client.close(this);
108 break; 107 break;
109 case Closed: 108 case Closed:
110 break; 109 break;
111 } 110 }
112 } 111 }
113 112
114 void Notification::dispatchShowEvent() 113 void Notification::dispatchShowEvent()
115 { 114 {
116 dispatchEvent(Event::create(EventTypeNames::show)); 115 dispatchEvent(Event::create(EventTypeNames::show));
117 } 116 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 156
158 ASSERT_NOT_REACHED(); 157 ASSERT_NOT_REACHED();
159 return deniedPermission; 158 return deniedPermission;
160 } 159 }
161 160
162 const String& Notification::permission(ExecutionContext* context) 161 const String& Notification::permission(ExecutionContext* context)
163 { 162 {
164 ASSERT(toDocument(context)->page()); 163 ASSERT(toDocument(context)->page());
165 164
166 UseCounter::count(context, UseCounter::NotificationPermission); 165 UseCounter::count(context, UseCounter::NotificationPermission);
167 return permissionString(NotificationController::from(toDocument(context)->fr ame())->client()->checkPermission(context)); 166 return permissionString(NotificationController::from(toDocument(context)->fr ame())->client().checkPermission(context));
Peter Beverloo 2014/05/08 12:59:34 NotificationController::clientFrom()?
gyuyoung-inactive 2014/05/08 15:50:27 Done.
168 } 167 }
169 168
170 void Notification::requestPermission(ExecutionContext* context, PassOwnPtr<Notif icationPermissionCallback> callback) 169 void Notification::requestPermission(ExecutionContext* context, PassOwnPtr<Notif icationPermissionCallback> callback)
171 { 170 {
172 ASSERT(toDocument(context)->page()); 171 ASSERT(toDocument(context)->page());
173 NotificationController::from(toDocument(context)->frame())->client()->reques tPermission(context, callback); 172 NotificationController::from(toDocument(context)->frame())->client().request Permission(context, callback);
Peter Beverloo 2014/05/08 12:59:34 NotificationController::clientFrom()?
gyuyoung-inactive 2014/05/08 15:50:27 Done.
174 } 173 }
175 174
176 bool Notification::dispatchEvent(PassRefPtrWillBeRawPtr<Event> event) 175 bool Notification::dispatchEvent(PassRefPtrWillBeRawPtr<Event> event)
177 { 176 {
178 ASSERT(m_state != Closed); 177 ASSERT(m_state != Closed);
179 178
180 return EventTarget::dispatchEvent(event); 179 return EventTarget::dispatchEvent(event);
181 } 180 }
182 181
183 const AtomicString& Notification::interfaceName() const 182 const AtomicString& Notification::interfaceName() const
184 { 183 {
185 return EventTargetNames::Notification; 184 return EventTargetNames::Notification;
186 } 185 }
187 186
188 void Notification::stop() 187 void Notification::stop()
189 { 188 {
190 if (m_client) 189 m_client.notificationObjectDestroyed(this);
191 m_client->notificationObjectDestroyed(this);
192 190
193 if (m_asyncRunner) 191 if (m_asyncRunner)
194 m_asyncRunner->stop(); 192 m_asyncRunner->stop();
195 193
196 m_client = 0;
haraken 2014/05/08 05:12:04 I don't understand why you can remove this. I agre
Peter Beverloo 2014/05/08 12:59:34 Are you worried about the case where LocalFrame ge
gyuyoung-inactive 2014/05/08 15:50:27 Though I'm not 100% sure, it looks you guys worry
gyuyoung-inactive 2014/05/09 02:28:49 Peter and Kentaro, any comment ?
197 m_state = Closed; 194 m_state = Closed;
198 } 195 }
199 196
200 bool Notification::hasPendingActivity() const 197 bool Notification::hasPendingActivity() const
201 { 198 {
202 return m_state == Showing || (m_asyncRunner && m_asyncRunner->isActive()); 199 return m_state == Showing || (m_asyncRunner && m_asyncRunner->isActive());
203 } 200 }
204 201
205 } // namespace WebCore 202 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/notifications/Notification.h ('k') | Source/modules/notifications/NotificationController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698