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

Side by Side Diff: Source/modules/push_messaging/PushManager.cpp

Issue 783423003: Make ScriptPromiseResolver RefCountedWillBeRefCountedGarbageCollected. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years 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 "config.h" 5 #include "config.h"
6 #include "modules/push_messaging/PushManager.h" 6 #include "modules/push_messaging/PushManager.h"
7 7
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" 8 #include "bindings/core/v8/CallbackPromiseAdapter.h"
9 #include "bindings/core/v8/ScriptPromise.h" 9 #include "bindings/core/v8/ScriptPromise.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
(...skipping 29 matching lines...) Expand all
40 : m_registration(registration) 40 : m_registration(registration)
41 { 41 {
42 ASSERT(registration); 42 ASSERT(registration);
43 } 43 }
44 44
45 ScriptPromise PushManager::registerPushMessaging(ScriptState* scriptState) 45 ScriptPromise PushManager::registerPushMessaging(ScriptState* scriptState)
46 { 46 {
47 if (!m_registration->active()) 47 if (!m_registration->active())
48 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "Registration failed - no active Service Worker")); 48 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "Registration failed - no active Service Worker"));
49 49
50 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); 50 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
51 ScriptPromise promise = resolver->promise(); 51 ScriptPromise promise = resolver->promise();
52 52
53 // The document context is the only reasonable context from which to ask the user for permission 53 // The document context is the only reasonable context from which to ask the user for permission
54 // to use the Push API. The embedder should persist the permission so that l ater calls in 54 // to use the Push API. The embedder should persist the permission so that l ater calls in
55 // different contexts can succeed. 55 // different contexts can succeed.
56 if (scriptState->executionContext()->isDocument()) { 56 if (scriptState->executionContext()->isDocument()) {
57 Document* document = toDocument(scriptState->executionContext()); 57 Document* document = toDocument(scriptState->executionContext());
58 // FIXME: add test coverage for this condition - https://crbug.com/44043 1 58 // FIXME: add test coverage for this condition - https://crbug.com/44043 1
59 if (!document->domWindow() || !document->frame()) 59 if (!document->domWindow() || !document->frame())
60 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti on::create(InvalidStateError, "Document is detached from window.")); 60 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti on::create(InvalidStateError, "Document is detached from window."));
61 PushController::clientFrom(document->frame()).registerPushMessaging(m_re gistration->webRegistration(), new PushRegistrationCallbacks(resolver, m_registr ation)); 61 PushController::clientFrom(document->frame()).registerPushMessaging(m_re gistration->webRegistration(), new PushRegistrationCallbacks(resolver, m_registr ation));
62 } else { 62 } else {
63 pushProvider()->registerPushMessaging(m_registration->webRegistration(), new PushRegistrationCallbacks(resolver, m_registration)); 63 pushProvider()->registerPushMessaging(m_registration->webRegistration(), new PushRegistrationCallbacks(resolver, m_registration));
64 } 64 }
65 65
66 return promise; 66 return promise;
67 } 67 }
68 68
69 ScriptPromise PushManager::hasPermission(ScriptState* scriptState) 69 ScriptPromise PushManager::hasPermission(ScriptState* scriptState)
70 { 70 {
71 if (scriptState->executionContext()->isDocument()) { 71 if (scriptState->executionContext()->isDocument()) {
72 Document* document = toDocument(scriptState->executionContext()); 72 Document* document = toDocument(scriptState->executionContext());
73 // FIXME: add test coverage for this condition - https://crbug.com/44043 1 73 // FIXME: add test coverage for this condition - https://crbug.com/44043 1
74 if (!document->domWindow() || !document->frame()) 74 if (!document->domWindow() || !document->frame())
75 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti on::create(InvalidStateError, "Document is detached from window.")); 75 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti on::create(InvalidStateError, "Document is detached from window."));
76 } 76 }
77 77
78 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); 78 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
79 ScriptPromise promise = resolver->promise(); 79 ScriptPromise promise = resolver->promise();
80 pushProvider()->getPermissionStatus(m_registration->webRegistration(), new P ushPermissionStatusCallback(resolver)); 80 pushProvider()->getPermissionStatus(m_registration->webRegistration(), new P ushPermissionStatusCallback(resolver));
81 return promise; 81 return promise;
82 } 82 }
83 83
84 void PushManager::trace(Visitor* visitor) 84 void PushManager::trace(Visitor* visitor)
85 { 85 {
86 visitor->trace(m_registration); 86 visitor->trace(m_registration);
87 } 87 }
88 88
89 } // namespace blink 89 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698