Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / password_manager / content / renderer / credential_manager_client.cc
index c753023..e694158 100644 (file)
@@ -9,6 +9,8 @@
 #include "content/public/renderer/render_view.h"
 #include "third_party/WebKit/public/platform/WebCredential.h"
 #include "third_party/WebKit/public/platform/WebCredentialManagerError.h"
+#include "third_party/WebKit/public/platform/WebFederatedCredential.h"
+#include "third_party/WebKit/public/platform/WebLocalCredential.h"
 #include "third_party/WebKit/public/web/WebView.h"
 
 namespace password_manager {
@@ -20,8 +22,7 @@ void ClearCallbacksMapWithErrors(T* callbacks_map) {
   typename T::iterator iter(callbacks_map);
   while (!iter.IsAtEnd()) {
     blink::WebCredentialManagerError reason(
-        blink::WebCredentialManagerError::ErrorTypeUnknown,
-        "An unknown error occurred.");
+        blink::WebCredentialManagerError::ErrorTypeUnknown);
     iter.GetCurrentValue()->onError(&reason);
     callbacks_map->Remove(iter.GetCurrentKey());
     iter.Advance();
@@ -56,6 +57,8 @@ bool CredentialManagerClient::OnMessageReceived(const IPC::Message& message) {
     IPC_MESSAGE_HANDLER(CredentialManagerMsg_AcknowledgeSignedOut,
                         OnAcknowledgeSignedOut)
     IPC_MESSAGE_HANDLER(CredentialManagerMsg_SendCredential, OnSendCredential)
+    IPC_MESSAGE_HANDLER(CredentialManagerMsg_RejectCredentialRequest,
+                        OnRejectCredentialRequest)
     IPC_MESSAGE_UNHANDLED(handled = false)
   IPC_END_MESSAGE_MAP()
   return handled;
@@ -77,9 +80,32 @@ void CredentialManagerClient::OnSendCredential(int request_id,
                                                const CredentialInfo& info) {
   RequestCallbacks* callbacks = request_callbacks_.Lookup(request_id);
   DCHECK(callbacks);
-  // TODO(mkwst): Split into local/federated credentials.
-  blink::WebCredential credential(info.id, info.name, info.avatar);
-  callbacks->onSuccess(&credential);
+  scoped_ptr<blink::WebCredential> credential = nullptr;
+  switch (info.type) {
+  case CREDENTIAL_TYPE_FEDERATED:
+    credential.reset(new blink::WebFederatedCredential(
+        info.id, info.name, info.avatar, info.federation));
+    break;
+  case CREDENTIAL_TYPE_LOCAL:
+    credential.reset(new blink::WebLocalCredential(info.id, info.name,
+                                                   info.avatar, info.password));
+    break;
+  case CREDENTIAL_TYPE_EMPTY:
+    // Intentionally empty; we'll send nullptr to the onSuccess call below.
+    break;
+  }
+  callbacks->onSuccess(credential.get());
+  request_callbacks_.Remove(request_id);
+}
+
+void CredentialManagerClient::OnRejectCredentialRequest(
+    int request_id,
+    blink::WebCredentialManagerError::ErrorType error_type) {
+  RequestCallbacks* callbacks = request_callbacks_.Lookup(request_id);
+  DCHECK(callbacks);
+  scoped_ptr<blink::WebCredentialManagerError> error(
+      new blink::WebCredentialManagerError(error_type));
+  callbacks->onError(error.get());
   request_callbacks_.Remove(request_id);
 }
 
@@ -90,8 +116,7 @@ void CredentialManagerClient::dispatchFailedSignIn(
     const blink::WebCredential& credential,
     blink::WebCredentialManagerClient::NotificationCallbacks* callbacks) {
   int request_id = failed_sign_in_callbacks_.Add(callbacks);
-  CredentialInfo info(
-      credential.id(), credential.name(), credential.avatarURL());
+  CredentialInfo info(credential);
   Send(new CredentialManagerHostMsg_NotifyFailedSignIn(
       routing_id(), request_id, info));
 }
@@ -100,8 +125,7 @@ void CredentialManagerClient::dispatchSignedIn(
     const blink::WebCredential& credential,
     blink::WebCredentialManagerClient::NotificationCallbacks* callbacks) {
   int request_id = signed_in_callbacks_.Add(callbacks);
-  CredentialInfo info(
-      credential.id(), credential.name(), credential.avatarURL());
+  CredentialInfo info(credential);
   Send(new CredentialManagerHostMsg_NotifySignedIn(
       routing_id(), request_id, info));
 }