OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/webshare/NavigatorShare.h" | 5 #include "modules/webshare/NavigatorShare.h" |
6 | 6 |
7 #include "core/dom/DOMException.h" | 7 #include "core/dom/DOMException.h" |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/dom/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
| 10 #include "core/dom/ExecutionContext.h" |
10 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
11 #include "core/frame/Navigator.h" | 12 #include "core/frame/Navigator.h" |
12 #include "modules/webshare/ShareData.h" | 13 #include "modules/webshare/ShareData.h" |
13 #include "platform/UserGestureIndicator.h" | 14 #include "platform/UserGestureIndicator.h" |
14 #include "platform/mojo/MojoHelper.h" | 15 #include "platform/mojo/MojoHelper.h" |
15 #include "public/platform/InterfaceProvider.h" | 16 #include "public/platform/InterfaceProvider.h" |
16 #include "public/platform/Platform.h" | 17 #include "public/platform/Platform.h" |
17 | 18 |
18 namespace blink { | 19 namespace blink { |
19 | 20 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 98 |
98 NavigatorShare::NavigatorShare() {} | 99 NavigatorShare::NavigatorShare() {} |
99 | 100 |
100 const char* NavigatorShare::SupplementName() { | 101 const char* NavigatorShare::SupplementName() { |
101 return "NavigatorShare"; | 102 return "NavigatorShare"; |
102 } | 103 } |
103 | 104 |
104 ScriptPromise NavigatorShare::share(ScriptState* script_state, | 105 ScriptPromise NavigatorShare::share(ScriptState* script_state, |
105 const ShareData& share_data) { | 106 const ShareData& share_data) { |
106 String error_message; | 107 String error_message; |
107 if (!script_state->GetExecutionContext()->IsSecureContext(error_message)) { | 108 if (!ExecutionContext::From(script_state)->IsSecureContext(error_message)) { |
108 DOMException* error = DOMException::Create(kSecurityError, error_message); | 109 DOMException* error = DOMException::Create(kSecurityError, error_message); |
109 return ScriptPromise::RejectWithDOMException(script_state, error); | 110 return ScriptPromise::RejectWithDOMException(script_state, error); |
110 } | 111 } |
111 if (!UserGestureIndicator::UtilizeUserGesture()) { | 112 if (!UserGestureIndicator::UtilizeUserGesture()) { |
112 DOMException* error = DOMException::Create( | 113 DOMException* error = DOMException::Create( |
113 kSecurityError, | 114 kSecurityError, |
114 "Must be handling a user gesture to perform a share request."); | 115 "Must be handling a user gesture to perform a share request."); |
115 return ScriptPromise::RejectWithDOMException(script_state, error); | 116 return ScriptPromise::RejectWithDOMException(script_state, error); |
116 } | 117 } |
117 | 118 |
118 Document* doc = ToDocument(script_state->GetExecutionContext()); | 119 Document* doc = ToDocument(ExecutionContext::From(script_state)); |
119 DCHECK(doc); | 120 DCHECK(doc); |
120 if (!service_) { | 121 if (!service_) { |
121 LocalFrame* frame = doc->GetFrame(); | 122 LocalFrame* frame = doc->GetFrame(); |
122 DCHECK(frame); | 123 DCHECK(frame); |
123 frame->GetInterfaceProvider()->GetInterface(mojo::MakeRequest(&service_)); | 124 frame->GetInterfaceProvider()->GetInterface(mojo::MakeRequest(&service_)); |
124 service_.set_connection_error_handler(ConvertToBaseCallback(WTF::Bind( | 125 service_.set_connection_error_handler(ConvertToBaseCallback(WTF::Bind( |
125 &NavigatorShare::OnConnectionError, WrapWeakPersistent(this)))); | 126 &NavigatorShare::OnConnectionError, WrapWeakPersistent(this)))); |
126 DCHECK(service_); | 127 DCHECK(service_); |
127 } | 128 } |
128 | 129 |
(...skipping 19 matching lines...) Expand all Loading... |
148 | 149 |
149 void NavigatorShare::OnConnectionError() { | 150 void NavigatorShare::OnConnectionError() { |
150 for (auto& client : clients_) { | 151 for (auto& client : clients_) { |
151 client->OnConnectionError(); | 152 client->OnConnectionError(); |
152 } | 153 } |
153 clients_.Clear(); | 154 clients_.Clear(); |
154 service_.reset(); | 155 service_.reset(); |
155 } | 156 } |
156 | 157 |
157 } // namespace blink | 158 } // namespace blink |
OLD | NEW |