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

Side by Side Diff: Source/modules/serviceworkers/ServiceWorkerClients.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/serviceworkers/ServiceWorkerClients.h" 6 #include "modules/serviceworkers/ServiceWorkerClients.h"
7 7
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" 8 #include "bindings/core/v8/CallbackPromiseAdapter.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "core/dom/DOMException.h" 10 #include "core/dom/DOMException.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 { 70 {
71 } 71 }
72 72
73 ScriptPromise ServiceWorkerClients::matchAll(ScriptState* scriptState, const Cli entQueryOptions& options) 73 ScriptPromise ServiceWorkerClients::matchAll(ScriptState* scriptState, const Cli entQueryOptions& options)
74 { 74 {
75 ExecutionContext* executionContext = scriptState->executionContext(); 75 ExecutionContext* executionContext = scriptState->executionContext();
76 // FIXME: May be null due to worker termination: http://crbug.com/413518. 76 // FIXME: May be null due to worker termination: http://crbug.com/413518.
77 if (!executionContext) 77 if (!executionContext)
78 return ScriptPromise(); 78 return ScriptPromise();
79 79
80 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 80 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
81 ScriptPromise promise = resolver->promise(); 81 ScriptPromise promise = resolver->promise();
82 82
83 WebServiceWorkerClientQueryOptions webOptions; 83 WebServiceWorkerClientQueryOptions webOptions;
84 webOptions.clientType = getClientType(options.type()); 84 webOptions.clientType = getClientType(options.type());
85 webOptions.includeUncontrolled = options.includeUncontrolled(); 85 webOptions.includeUncontrolled = options.includeUncontrolled();
86 ServiceWorkerGlobalScopeClient::from(executionContext)->getClients(webOption s, new CallbackPromiseAdapter<ClientArray, ServiceWorkerError>(resolver)); 86 ServiceWorkerGlobalScopeClient::from(executionContext)->getClients(webOption s, new CallbackPromiseAdapter<ClientArray, ServiceWorkerError>(resolver));
87 return promise; 87 return promise;
88 } 88 }
89 89
90 ScriptPromise ServiceWorkerClients::claim(ScriptState* scriptState) 90 ScriptPromise ServiceWorkerClients::claim(ScriptState* scriptState)
91 { 91 {
92 ExecutionContext* executionContext = scriptState->executionContext(); 92 ExecutionContext* executionContext = scriptState->executionContext();
93 93
94 // FIXME: May be null due to worker termination: http://crbug.com/413518. 94 // FIXME: May be null due to worker termination: http://crbug.com/413518.
95 if (!executionContext) 95 if (!executionContext)
96 return ScriptPromise(); 96 return ScriptPromise();
97 97
98 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 98 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
99 ScriptPromise promise = resolver->promise(); 99 ScriptPromise promise = resolver->promise();
100 100
101 WebServiceWorkerClientsClaimCallbacks* callbacks = new CallbackPromiseAdapte r<void, ServiceWorkerError>(resolver); 101 WebServiceWorkerClientsClaimCallbacks* callbacks = new CallbackPromiseAdapte r<void, ServiceWorkerError>(resolver);
102 ServiceWorkerGlobalScopeClient::from(executionContext)->claim(callbacks); 102 ServiceWorkerGlobalScopeClient::from(executionContext)->claim(callbacks);
103 return promise; 103 return promise;
104 } 104 }
105 105
106 ScriptPromise ServiceWorkerClients::openWindow(ScriptState* scriptState, const S tring& url) 106 ScriptPromise ServiceWorkerClients::openWindow(ScriptState* scriptState, const S tring& url)
107 { 107 {
108 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 108 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
109 ScriptPromise promise = resolver->promise(); 109 ScriptPromise promise = resolver->promise();
110 ExecutionContext* context = scriptState->executionContext(); 110 ExecutionContext* context = scriptState->executionContext();
111 111
112 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url); 112 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url);
113 if (!parsedUrl.isValid()) { 113 if (!parsedUrl.isValid()) {
114 resolver->reject(V8ThrowException::createTypeError(scriptState->isolate( ), "'" + url + "' is not a valid URL.")); 114 resolver->reject(V8ThrowException::createTypeError(scriptState->isolate( ), "'" + url + "' is not a valid URL."));
115 return promise; 115 return promise;
116 } 116 }
117 117
118 if (!context->securityOrigin()->canDisplay(parsedUrl)) { 118 if (!context->securityOrigin()->canDisplay(parsedUrl)) {
119 resolver->reject(DOMException::create(SecurityError, "'" + parsedUrl.eli dedString() + "' cannot be opened.")); 119 resolver->reject(DOMException::create(SecurityError, "'" + parsedUrl.eli dedString() + "' cannot be opened."));
120 return promise; 120 return promise;
121 } 121 }
122 122
123 if (!context->isWindowInteractionAllowed()) { 123 if (!context->isWindowInteractionAllowed()) {
124 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o open a window.")); 124 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o open a window."));
125 return promise; 125 return promise;
126 } 126 }
127 context->consumeWindowInteraction(); 127 context->consumeWindowInteraction();
128 128
129 ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedUrl, new Cal lbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolver)); 129 ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedUrl, new Cal lbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolver));
130 return promise; 130 return promise;
131 } 131 }
132 132
133 } // namespace blink 133 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientation.cpp ('k') | Source/modules/serviceworkers/ServiceWorkerContainer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698