Chromium Code Reviews| 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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/credentialmanager/CredentialsContainer.h" | 6 #include "modules/credentialmanager/CredentialsContainer.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/Dictionary.h" | 8 #include "bindings/core/v8/Dictionary.h" |
| 9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
| 10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 11 #include "core/dom/DOMException.h" | 11 #include "core/dom/DOMException.h" |
| 12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 13 #include "core/dom/ExecutionContext.h" | 13 #include "core/dom/ExecutionContext.h" |
| 14 #include "modules/credentialmanager/Credential.h" | 14 #include "modules/credentialmanager/Credential.h" |
| 15 #include "modules/credentialmanager/CredentialManagerClient.h" | |
| 16 #include "modules/credentialmanager/LocalCredential.h" | |
| 15 #include "platform/weborigin/SecurityOrigin.h" | 17 #include "platform/weborigin/SecurityOrigin.h" |
| 16 #include "public/platform/Platform.h" | 18 #include "public/platform/Platform.h" |
| 17 #include "public/platform/WebCredential.h" | 19 #include "public/platform/WebCredential.h" |
| 18 #include "public/platform/WebCredentialManagerClient.h" | 20 #include "public/platform/WebCredentialManagerClient.h" |
| 19 #include "public/platform/WebCredentialManagerError.h" | 21 #include "public/platform/WebCredentialManagerError.h" |
| 22 #include "public/platform/WebLocalCredential.h" | |
| 20 | 23 |
| 21 namespace blink { | 24 namespace blink { |
| 22 | 25 |
| 23 static void rejectDueToCredentialManagerError(PassRefPtr<ScriptPromiseResolver> resolver, WebCredentialManagerError* reason) | 26 static void rejectDueToCredentialManagerError(PassRefPtr<ScriptPromiseResolver> resolver, WebCredentialManagerError* reason) |
| 24 { | 27 { |
| 25 | 28 |
| 26 switch (reason->errorType) { | 29 switch (reason->errorType) { |
| 27 case WebCredentialManagerError::ErrorTypeDisabled: | 30 case WebCredentialManagerError::ErrorTypeDisabled: |
| 28 resolver->reject(DOMException::create(InvalidStateError, "The credential manager is disabled.")); | 31 resolver->reject(DOMException::create(InvalidStateError, "The credential manager is disabled.")); |
| 29 break; | 32 break; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 55 }; | 58 }; |
| 56 | 59 |
| 57 class RequestCallbacks : public WebCredentialManagerClient::RequestCallbacks { | 60 class RequestCallbacks : public WebCredentialManagerClient::RequestCallbacks { |
| 58 WTF_MAKE_NONCOPYABLE(RequestCallbacks); | 61 WTF_MAKE_NONCOPYABLE(RequestCallbacks); |
| 59 public: | 62 public: |
| 60 explicit RequestCallbacks(PassRefPtr<ScriptPromiseResolver> resolver) : m_re solver(resolver) { } | 63 explicit RequestCallbacks(PassRefPtr<ScriptPromiseResolver> resolver) : m_re solver(resolver) { } |
| 61 virtual ~RequestCallbacks() { } | 64 virtual ~RequestCallbacks() { } |
| 62 | 65 |
| 63 virtual void onSuccess(WebCredential* credential) OVERRIDE | 66 virtual void onSuccess(WebCredential* credential) OVERRIDE |
| 64 { | 67 { |
| 65 // FIXME: Split this into Local/Federated types. | 68 if (!credential) { |
| 66 m_resolver->resolve(Credential::create(credential->id(), credential->nam e(), credential->avatarURL())); | 69 m_resolver->resolve(); |
| 70 return; | |
| 71 } | |
| 72 | |
| 73 // FIXME: Split this into Local/Federated types. Right now it's hard-cod ed to be a LocalCredential. :( | |
| 74 m_resolver->resolve(LocalCredential::create(credential->id(), credential ->name(), credential->avatarURL(), static_cast<WebLocalCredential*>(credential)- >password())); | |
| 67 } | 75 } |
| 68 | 76 |
| 69 virtual void onError(WebCredentialManagerError* reason) OVERRIDE | 77 virtual void onError(WebCredentialManagerError* reason) OVERRIDE |
| 70 { | 78 { |
| 71 rejectDueToCredentialManagerError(m_resolver, reason); | 79 rejectDueToCredentialManagerError(m_resolver, reason); |
| 72 } | 80 } |
| 73 | 81 |
| 74 private: | 82 private: |
| 75 const RefPtr<ScriptPromiseResolver> m_resolver; | 83 const RefPtr<ScriptPromiseResolver> m_resolver; |
| 76 }; | 84 }; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 89 { | 97 { |
| 90 SecurityOrigin* securityOrigin = scriptState->executionContext()->securityOr igin(); | 98 SecurityOrigin* securityOrigin = scriptState->executionContext()->securityOr igin(); |
| 91 String errorMessage; | 99 String errorMessage; |
| 92 if (!securityOrigin->canAccessFeatureRequiringSecureOrigin(errorMessage)) { | 100 if (!securityOrigin->canAccessFeatureRequiringSecureOrigin(errorMessage)) { |
| 93 resolver->reject(DOMException::create(SecurityError, errorMessage)); | 101 resolver->reject(DOMException::create(SecurityError, errorMessage)); |
| 94 return false; | 102 return false; |
| 95 } | 103 } |
| 96 return true; | 104 return true; |
| 97 } | 105 } |
| 98 | 106 |
| 99 static ScriptPromise stubImplementation(ScriptState* scriptState) | 107 ScriptPromise CredentialsContainer::request(ScriptState* scriptState, const Dict ionary&) |
| 100 { | 108 { |
| 109 CredentialManagerClient* client = CredentialManagerClient::from(scriptState) ; | |
| 110 if (!client) | |
| 111 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Could not establish connection to the credential mana ger.")); | |
| 112 | |
| 101 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | 113 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); |
| 102 ScriptPromise promise = resolver->promise(); | 114 ScriptPromise promise = resolver->promise(); |
| 103 | 115 |
| 104 if (!canAccessCredentialManagerAPI(scriptState, resolver)) | 116 if (!canAccessCredentialManagerAPI(scriptState, resolver)) |
| 105 return promise; | 117 return promise; |
| 106 | 118 |
| 107 resolver->resolve(); | 119 WebVector<WebURL> tempVector; |
| 120 client->dispatchRequest(false, tempVector, new RequestCallbacks(resolver)); | |
| 108 return promise; | 121 return promise; |
| 109 } | 122 } |
| 110 | 123 |
| 111 ScriptPromise CredentialsContainer::request(ScriptState* scriptState, const Dict ionary&) | |
| 112 { | |
| 113 return stubImplementation(scriptState); | |
| 114 } | |
| 115 | |
| 116 ScriptPromise CredentialsContainer::notifySignedIn(ScriptState* scriptState, Cre dential* credential) | 124 ScriptPromise CredentialsContainer::notifySignedIn(ScriptState* scriptState, Cre dential* credential) |
| 117 { | 125 { |
| 118 return stubImplementation(scriptState); | 126 CredentialManagerClient* client = CredentialManagerClient::from(scriptState) ; |
|
sof
2014/09/15 07:57:17
There's a fair bit of duplicated code in these met
| |
| 127 if (!client) | |
| 128 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Could not establish connection to the credential mana ger.")); | |
| 129 | |
| 130 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | |
| 131 ScriptPromise promise = resolver->promise(); | |
| 132 | |
| 133 if (!canAccessCredentialManagerAPI(scriptState, resolver)) | |
| 134 return promise; | |
| 135 | |
| 136 client->dispatchSignedIn(WebCredential(credential->platformCredential()), ne w NotificationCallbacks(resolver)); | |
| 137 return promise; | |
| 119 } | 138 } |
| 120 | 139 |
| 121 ScriptPromise CredentialsContainer::notifyFailedSignIn(ScriptState* scriptState, Credential* credential) | 140 ScriptPromise CredentialsContainer::notifyFailedSignIn(ScriptState* scriptState, Credential* credential) |
| 122 { | 141 { |
| 123 return stubImplementation(scriptState); | 142 CredentialManagerClient* client = CredentialManagerClient::from(scriptState) ; |
| 143 if (!client) | |
| 144 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Could not establish connection to the credential mana ger.")); | |
| 145 | |
| 146 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | |
| 147 ScriptPromise promise = resolver->promise(); | |
| 148 | |
| 149 if (!canAccessCredentialManagerAPI(scriptState, resolver)) | |
| 150 return promise; | |
| 151 | |
| 152 client->dispatchFailedSignIn(WebCredential(credential->platformCredential()) , new NotificationCallbacks(resolver)); | |
| 153 return promise; | |
| 124 } | 154 } |
| 125 | 155 |
| 126 ScriptPromise CredentialsContainer::notifySignedOut(ScriptState* scriptState) | 156 ScriptPromise CredentialsContainer::notifySignedOut(ScriptState* scriptState) |
| 127 { | 157 { |
| 128 return stubImplementation(scriptState); | 158 CredentialManagerClient* client = CredentialManagerClient::from(scriptState) ; |
| 159 if (!client) | |
| 160 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Could not establish connection to the credential mana ger.")); | |
| 161 | |
| 162 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | |
| 163 ScriptPromise promise = resolver->promise(); | |
| 164 | |
| 165 if (!canAccessCredentialManagerAPI(scriptState, resolver)) | |
| 166 return promise; | |
| 167 | |
| 168 client->dispatchSignedOut(new NotificationCallbacks(resolver)); | |
| 169 return promise; | |
| 129 } | 170 } |
| 130 | 171 |
| 131 } // namespace blink | 172 } // namespace blink |
| OLD | NEW |