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

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

Issue 2815313002: Reland of Move ScriptState::GetExecutionContext (Part 5) (Closed)
Patch Set: Created 3 years, 8 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 "modules/push_messaging/PushManager.h" 5 #include "modules/push_messaging/PushManager.h"
6 6
7 #include "bindings/core/v8/ScriptPromise.h" 7 #include "bindings/core/v8/ScriptPromise.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "bindings/core/v8/ScriptState.h" 9 #include "bindings/core/v8/ScriptState.h"
10 #include "core/dom/DOMException.h" 10 #include "core/dom/DOMException.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 PushSubscriptionOptions::ToWeb(options, exception_state); 55 PushSubscriptionOptions::ToWeb(options, exception_state);
56 if (exception_state.HadException()) 56 if (exception_state.HadException())
57 return ScriptPromise(); 57 return ScriptPromise();
58 58
59 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); 59 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
60 ScriptPromise promise = resolver->Promise(); 60 ScriptPromise promise = resolver->Promise();
61 61
62 // The document context is the only reasonable context from which to ask the 62 // The document context is the only reasonable context from which to ask the
63 // user for permission to use the Push API. The embedder should persist the 63 // user for permission to use the Push API. The embedder should persist the
64 // permission so that later calls in different contexts can succeed. 64 // permission so that later calls in different contexts can succeed.
65 if (script_state->GetExecutionContext()->IsDocument()) { 65 if (ExecutionContext::From(script_state)->IsDocument()) {
66 Document* document = ToDocument(script_state->GetExecutionContext()); 66 Document* document = ToDocument(ExecutionContext::From(script_state));
67 if (!document->domWindow() || !document->GetFrame()) 67 if (!document->domWindow() || !document->GetFrame())
68 return ScriptPromise::RejectWithDOMException( 68 return ScriptPromise::RejectWithDOMException(
69 script_state, 69 script_state,
70 DOMException::Create(kInvalidStateError, 70 DOMException::Create(kInvalidStateError,
71 "Document is detached from window.")); 71 "Document is detached from window."));
72 PushController::ClientFrom(document->GetFrame()) 72 PushController::ClientFrom(document->GetFrame())
73 .Subscribe(registration_->WebRegistration(), web_options, 73 .Subscribe(registration_->WebRegistration(), web_options,
74 WTF::MakeUnique<PushSubscriptionCallbacks>(resolver, 74 WTF::MakeUnique<PushSubscriptionCallbacks>(resolver,
75 registration_)); 75 registration_));
76 } else { 76 } else {
(...skipping 12 matching lines...) Expand all
89 PushProvider()->GetSubscription( 89 PushProvider()->GetSubscription(
90 registration_->WebRegistration(), 90 registration_->WebRegistration(),
91 WTF::MakeUnique<PushSubscriptionCallbacks>(resolver, registration_)); 91 WTF::MakeUnique<PushSubscriptionCallbacks>(resolver, registration_));
92 return promise; 92 return promise;
93 } 93 }
94 94
95 ScriptPromise PushManager::permissionState( 95 ScriptPromise PushManager::permissionState(
96 ScriptState* script_state, 96 ScriptState* script_state,
97 const PushSubscriptionOptionsInit& options, 97 const PushSubscriptionOptionsInit& options,
98 ExceptionState& exception_state) { 98 ExceptionState& exception_state) {
99 if (script_state->GetExecutionContext()->IsDocument()) { 99 if (ExecutionContext::From(script_state)->IsDocument()) {
100 Document* document = ToDocument(script_state->GetExecutionContext()); 100 Document* document = ToDocument(ExecutionContext::From(script_state));
101 if (!document->domWindow() || !document->GetFrame()) 101 if (!document->domWindow() || !document->GetFrame())
102 return ScriptPromise::RejectWithDOMException( 102 return ScriptPromise::RejectWithDOMException(
103 script_state, 103 script_state,
104 DOMException::Create(kInvalidStateError, 104 DOMException::Create(kInvalidStateError,
105 "Document is detached from window.")); 105 "Document is detached from window."));
106 } 106 }
107 107
108 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); 108 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
109 ScriptPromise promise = resolver->Promise(); 109 ScriptPromise promise = resolver->Promise();
110 110
111 PushProvider()->GetPermissionStatus( 111 PushProvider()->GetPermissionStatus(
112 registration_->WebRegistration(), 112 registration_->WebRegistration(),
113 PushSubscriptionOptions::ToWeb(options, exception_state), 113 PushSubscriptionOptions::ToWeb(options, exception_state),
114 WTF::MakeUnique<PushPermissionStatusCallbacks>(resolver)); 114 WTF::MakeUnique<PushPermissionStatusCallbacks>(resolver));
115 return promise; 115 return promise;
116 } 116 }
117 117
118 DEFINE_TRACE(PushManager) { 118 DEFINE_TRACE(PushManager) {
119 visitor->Trace(registration_); 119 visitor->Trace(registration_);
120 } 120 }
121 121
122 } // namespace blink 122 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698