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