| OLD | NEW |
| 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/credentialmanager/CredentialsContainer.h" | 5 #include "modules/credentialmanager/CredentialsContainer.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/Dictionary.h" | 7 #include "bindings/core/v8/Dictionary.h" |
| 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 "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| 11 #include "core/dom/Document.h" |
| 11 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 12 #include "core/dom/ExecutionContext.h" | 13 #include "core/dom/ExecutionContext.h" |
| 14 #include "core/frame/Frame.h" |
| 13 #include "core/frame/UseCounter.h" | 15 #include "core/frame/UseCounter.h" |
| 16 #include "core/page/FrameTree.h" |
| 14 #include "modules/credentialmanager/Credential.h" | 17 #include "modules/credentialmanager/Credential.h" |
| 15 #include "modules/credentialmanager/CredentialManagerClient.h" | 18 #include "modules/credentialmanager/CredentialManagerClient.h" |
| 16 #include "modules/credentialmanager/CredentialRequestOptions.h" | 19 #include "modules/credentialmanager/CredentialRequestOptions.h" |
| 17 #include "modules/credentialmanager/FederatedCredential.h" | 20 #include "modules/credentialmanager/FederatedCredential.h" |
| 18 #include "modules/credentialmanager/FederatedCredentialRequestOptions.h" | 21 #include "modules/credentialmanager/FederatedCredentialRequestOptions.h" |
| 19 #include "modules/credentialmanager/PasswordCredential.h" | 22 #include "modules/credentialmanager/PasswordCredential.h" |
| 20 #include "platform/weborigin/SecurityOrigin.h" | 23 #include "platform/weborigin/SecurityOrigin.h" |
| 21 #include "public/platform/Platform.h" | 24 #include "public/platform/Platform.h" |
| 22 #include "public/platform/WebCredential.h" | 25 #include "public/platform/WebCredential.h" |
| 23 #include "public/platform/WebCredentialManagerClient.h" | 26 #include "public/platform/WebCredentialManagerClient.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 44 } | 47 } |
| 45 | 48 |
| 46 class NotificationCallbacks : public WebCredentialManagerClient::NotificationCal
lbacks { | 49 class NotificationCallbacks : public WebCredentialManagerClient::NotificationCal
lbacks { |
| 47 WTF_MAKE_NONCOPYABLE(NotificationCallbacks); | 50 WTF_MAKE_NONCOPYABLE(NotificationCallbacks); |
| 48 public: | 51 public: |
| 49 explicit NotificationCallbacks(ScriptPromiseResolver* resolver) : m_resolver
(resolver) { } | 52 explicit NotificationCallbacks(ScriptPromiseResolver* resolver) : m_resolver
(resolver) { } |
| 50 ~NotificationCallbacks() override { } | 53 ~NotificationCallbacks() override { } |
| 51 | 54 |
| 52 void onSuccess() override | 55 void onSuccess() override |
| 53 { | 56 { |
| 57 Frame* frame = toDocument(m_resolver->getScriptState()->getExecutionCont
ext())->frame(); |
| 58 SECURITY_CHECK(frame == frame->tree().top()); |
| 59 |
| 54 m_resolver->resolve(); | 60 m_resolver->resolve(); |
| 55 } | 61 } |
| 56 | 62 |
| 57 void onError(WebCredentialManagerError reason) override | 63 void onError(WebCredentialManagerError reason) override |
| 58 { | 64 { |
| 59 rejectDueToCredentialManagerError(m_resolver, reason); | 65 rejectDueToCredentialManagerError(m_resolver, reason); |
| 60 } | 66 } |
| 61 | 67 |
| 62 private: | 68 private: |
| 63 const Persistent<ScriptPromiseResolver> m_resolver; | 69 const Persistent<ScriptPromiseResolver> m_resolver; |
| 64 }; | 70 }; |
| 65 | 71 |
| 66 class RequestCallbacks : public WebCredentialManagerClient::RequestCallbacks { | 72 class RequestCallbacks : public WebCredentialManagerClient::RequestCallbacks { |
| 67 WTF_MAKE_NONCOPYABLE(RequestCallbacks); | 73 WTF_MAKE_NONCOPYABLE(RequestCallbacks); |
| 68 public: | 74 public: |
| 69 explicit RequestCallbacks(ScriptPromiseResolver* resolver) : m_resolver(reso
lver) { } | 75 explicit RequestCallbacks(ScriptPromiseResolver* resolver) : m_resolver(reso
lver) { } |
| 70 ~RequestCallbacks() override { } | 76 ~RequestCallbacks() override { } |
| 71 | 77 |
| 72 void onSuccess(WebPassOwnPtr<WebCredential> webCredential) override | 78 void onSuccess(WebPassOwnPtr<WebCredential> webCredential) override |
| 73 { | 79 { |
| 80 Frame* frame = toDocument(m_resolver->getScriptState()->getExecutionCont
ext())->frame(); |
| 81 SECURITY_CHECK(frame == frame->tree().top()); |
| 82 |
| 74 OwnPtr<WebCredential> credential = webCredential.release(); | 83 OwnPtr<WebCredential> credential = webCredential.release(); |
| 75 if (!credential) { | 84 if (!credential) { |
| 76 m_resolver->resolve(); | 85 m_resolver->resolve(); |
| 77 return; | 86 return; |
| 78 } | 87 } |
| 79 | 88 |
| 80 ASSERT(credential->isPasswordCredential() || credential->isFederatedCred
ential()); | 89 ASSERT(credential->isPasswordCredential() || credential->isFederatedCred
ential()); |
| 81 if (credential->isPasswordCredential()) | 90 if (credential->isPasswordCredential()) |
| 82 m_resolver->resolve(PasswordCredential::create(static_cast<WebPasswo
rdCredential*>(credential.get()))); | 91 m_resolver->resolve(PasswordCredential::create(static_cast<WebPasswo
rdCredential*>(credential.get()))); |
| 83 else | 92 else |
| (...skipping 14 matching lines...) Expand all Loading... |
| 98 { | 107 { |
| 99 return new CredentialsContainer(); | 108 return new CredentialsContainer(); |
| 100 } | 109 } |
| 101 | 110 |
| 102 CredentialsContainer::CredentialsContainer() | 111 CredentialsContainer::CredentialsContainer() |
| 103 { | 112 { |
| 104 } | 113 } |
| 105 | 114 |
| 106 static bool checkBoilerplate(ScriptPromiseResolver* resolver) | 115 static bool checkBoilerplate(ScriptPromiseResolver* resolver) |
| 107 { | 116 { |
| 108 CredentialManagerClient* client = CredentialManagerClient::from(resolver->ge
tScriptState()->getExecutionContext()); | 117 Frame* frame = toDocument(resolver->getScriptState()->getExecutionContext())
->frame(); |
| 109 if (!client) { | 118 if (!frame || frame != frame->tree().top()) { |
| 110 resolver->reject(DOMException::create(InvalidStateError, "Could not esta
blish connection to the credential manager.")); | 119 resolver->reject(DOMException::create(SecurityError, "CredentialContaine
r methods may only be executed in a top-level document.")); |
| 111 return false; | 120 return false; |
| 112 } | 121 } |
| 113 | 122 |
| 114 String errorMessage; | 123 String errorMessage; |
| 115 if (!resolver->getScriptState()->getExecutionContext()->isSecureContext(erro
rMessage)) { | 124 if (!resolver->getScriptState()->getExecutionContext()->isSecureContext(erro
rMessage)) { |
| 116 resolver->reject(DOMException::create(SecurityError, errorMessage)); | 125 resolver->reject(DOMException::create(SecurityError, errorMessage)); |
| 117 return false; | 126 return false; |
| 118 } | 127 } |
| 119 | 128 |
| 129 CredentialManagerClient* client = CredentialManagerClient::from(resolver->ge
tScriptState()->getExecutionContext()); |
| 130 if (!client) { |
| 131 resolver->reject(DOMException::create(InvalidStateError, "Could not esta
blish connection to the credential manager.")); |
| 132 return false; |
| 133 } |
| 134 |
| 120 return true; | 135 return true; |
| 121 } | 136 } |
| 122 | 137 |
| 123 ScriptPromise CredentialsContainer::get(ScriptState* scriptState, const Credenti
alRequestOptions& options) | 138 ScriptPromise CredentialsContainer::get(ScriptState* scriptState, const Credenti
alRequestOptions& options) |
| 124 { | 139 { |
| 125 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 140 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 126 ScriptPromise promise = resolver->promise(); | 141 ScriptPromise promise = resolver->promise(); |
| 127 if (!checkBoilerplate(resolver)) | 142 if (!checkBoilerplate(resolver)) |
| 128 return promise; | 143 return promise; |
| 129 | 144 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 179 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 165 ScriptPromise promise = resolver->promise(); | 180 ScriptPromise promise = resolver->promise(); |
| 166 if (!checkBoilerplate(resolver)) | 181 if (!checkBoilerplate(resolver)) |
| 167 return promise; | 182 return promise; |
| 168 | 183 |
| 169 CredentialManagerClient::from(scriptState->getExecutionContext())->dispatchR
equireUserMediation(new NotificationCallbacks(resolver)); | 184 CredentialManagerClient::from(scriptState->getExecutionContext())->dispatchR
equireUserMediation(new NotificationCallbacks(resolver)); |
| 170 return promise; | 185 return promise; |
| 171 } | 186 } |
| 172 | 187 |
| 173 } // namespace blink | 188 } // namespace blink |
| OLD | NEW |