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

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

Issue 1233173002: Have ScriptPromiseResolver on the Oilpan heap always. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix webusb ScriptPromiseResolver usage Created 5 years, 4 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 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/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/ScriptState.h" 10 #include "bindings/core/v8/ScriptState.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 : m_registration(registration) 48 : m_registration(registration)
49 { 49 {
50 ASSERT(registration); 50 ASSERT(registration);
51 } 51 }
52 52
53 ScriptPromise PushManager::subscribe(ScriptState* scriptState, const PushSubscri ptionOptions& options) 53 ScriptPromise PushManager::subscribe(ScriptState* scriptState, const PushSubscri ptionOptions& options)
54 { 54 {
55 if (!m_registration->active()) 55 if (!m_registration->active())
56 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "Subscription failed - no active Service Worker")); 56 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "Subscription failed - no active Service Worker"));
57 57
58 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 58 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
59 ScriptPromise promise = resolver->promise(); 59 ScriptPromise promise = resolver->promise();
60 60
61 // The document context is the only reasonable context from which to ask the user for permission 61 // The document context is the only reasonable context from which to ask the user for permission
62 // to use the Push API. The embedder should persist the permission so that l ater calls in 62 // to use the Push API. The embedder should persist the permission so that l ater calls in
63 // different contexts can succeed. 63 // different contexts can succeed.
64 if (scriptState->executionContext()->isDocument()) { 64 if (scriptState->executionContext()->isDocument()) {
65 Document* document = toDocument(scriptState->executionContext()); 65 Document* document = toDocument(scriptState->executionContext());
66 // FIXME: add test coverage for this condition - https://crbug.com/44043 1 66 // FIXME: add test coverage for this condition - https://crbug.com/44043 1
67 if (!document->domWindow() || !document->frame()) 67 if (!document->domWindow() || !document->frame())
68 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti on::create(InvalidStateError, "Document is detached from window.")); 68 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti on::create(InvalidStateError, "Document is detached from window."));
69 PushController::clientFrom(document->frame()).subscribe(m_registration-> webRegistration(), toWebPushSubscriptionOptions(options), new PushSubscriptionCa llbacks(resolver, m_registration)); 69 PushController::clientFrom(document->frame()).subscribe(m_registration-> webRegistration(), toWebPushSubscriptionOptions(options), new PushSubscriptionCa llbacks(resolver, m_registration));
70 } else { 70 } else {
71 pushProvider()->subscribe(m_registration->webRegistration(), toWebPushSu bscriptionOptions(options), new PushSubscriptionCallbacks(resolver, m_registrati on)); 71 pushProvider()->subscribe(m_registration->webRegistration(), toWebPushSu bscriptionOptions(options), new PushSubscriptionCallbacks(resolver, m_registrati on));
72 } 72 }
73 73
74 return promise; 74 return promise;
75 } 75 }
76 76
77 ScriptPromise PushManager::getSubscription(ScriptState* scriptState) 77 ScriptPromise PushManager::getSubscription(ScriptState* scriptState)
78 { 78 {
79 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 79 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
80 ScriptPromise promise = resolver->promise(); 80 ScriptPromise promise = resolver->promise();
81 81
82 pushProvider()->getSubscription(m_registration->webRegistration(), new PushS ubscriptionCallbacks(resolver, m_registration)); 82 pushProvider()->getSubscription(m_registration->webRegistration(), new PushS ubscriptionCallbacks(resolver, m_registration));
83 return promise; 83 return promise;
84 } 84 }
85 85
86 ScriptPromise PushManager::permissionState(ScriptState* scriptState, const PushS ubscriptionOptions& options) 86 ScriptPromise PushManager::permissionState(ScriptState* scriptState, const PushS ubscriptionOptions& options)
87 { 87 {
88 if (scriptState->executionContext()->isDocument()) { 88 if (scriptState->executionContext()->isDocument()) {
89 Document* document = toDocument(scriptState->executionContext()); 89 Document* document = toDocument(scriptState->executionContext());
90 // FIXME: add test coverage for this condition - https://crbug.com/44043 1 90 // FIXME: add test coverage for this condition - https://crbug.com/44043 1
91 if (!document->domWindow() || !document->frame()) 91 if (!document->domWindow() || !document->frame())
92 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti on::create(InvalidStateError, "Document is detached from window.")); 92 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti on::create(InvalidStateError, "Document is detached from window."));
93 } 93 }
94 94
95 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 95 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
96 ScriptPromise promise = resolver->promise(); 96 ScriptPromise promise = resolver->promise();
97 97
98 pushProvider()->getPermissionStatus(m_registration->webRegistration(), toWeb PushSubscriptionOptions(options), new PushPermissionStatusCallbacks(resolver)); 98 pushProvider()->getPermissionStatus(m_registration->webRegistration(), toWeb PushSubscriptionOptions(options), new PushPermissionStatusCallbacks(resolver));
99 return promise; 99 return promise;
100 } 100 }
101 101
102 DEFINE_TRACE(PushManager) 102 DEFINE_TRACE(PushManager)
103 { 103 {
104 visitor->trace(m_registration); 104 visitor->trace(m_registration);
105 } 105 }
106 106
107 } // namespace blink 107 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/presentation/PresentationRequest.cpp ('k') | Source/modules/push_messaging/PushPermissionStatusCallbacks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698