| 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 "components/password_manager/content/renderer/credential_manager_client
.h" | 5 #include "components/password_manager/content/renderer/credential_manager_client
.h" |
| 6 | 6 |
| 7 #include "components/password_manager/content/common/credential_manager_messages
.h" | 7 #include "components/password_manager/content/common/credential_manager_messages
.h" |
| 8 #include "components/password_manager/content/common/credential_manager_types.h" | 8 #include "components/password_manager/content/common/credential_manager_types.h" |
| 9 #include "content/public/renderer/render_thread.h" | |
| 10 #include "content/public/renderer/render_view.h" | 9 #include "content/public/renderer/render_view.h" |
| 11 #include "third_party/WebKit/public/platform/WebCredential.h" | 10 #include "third_party/WebKit/public/platform/WebCredential.h" |
| 12 #include "third_party/WebKit/public/platform/WebCredentialManagerError.h" | 11 #include "third_party/WebKit/public/platform/WebCredentialManagerError.h" |
| 13 #include "third_party/WebKit/public/web/WebView.h" | 12 #include "third_party/WebKit/public/web/WebView.h" |
| 14 | 13 |
| 15 namespace password_manager { | 14 namespace password_manager { |
| 16 | 15 |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 template <typename T> | 18 template <typename T> |
| 20 void ClearCallbacksMapWithErrors(T* callbacks_map) { | 19 void ClearCallbacksMapWithErrors(T* callbacks_map) { |
| 21 typename T::iterator iter(callbacks_map); | 20 typename T::iterator iter(callbacks_map); |
| 22 while (!iter.IsAtEnd()) { | 21 while (!iter.IsAtEnd()) { |
| 23 blink::WebCredentialManagerError reason( | 22 blink::WebCredentialManagerError reason( |
| 24 blink::WebCredentialManagerError::ErrorTypeUnknown, | 23 blink::WebCredentialManagerError::ErrorTypeUnknown, |
| 25 "An unknown error occurred."); | 24 "An unknown error occurred."); |
| 26 iter.GetCurrentValue()->onError(&reason); | 25 iter.GetCurrentValue()->onError(&reason); |
| 27 callbacks_map->Remove(iter.GetCurrentKey()); | 26 callbacks_map->Remove(iter.GetCurrentKey()); |
| 28 iter.Advance(); | 27 iter.Advance(); |
| 29 } | 28 } |
| 30 } | 29 } |
| 31 | 30 |
| 32 } // namespace | 31 } // namespace |
| 33 | 32 |
| 34 CredentialManagerClient::CredentialManagerClient() | 33 CredentialManagerClient::CredentialManagerClient( |
| 35 : routing_id_(MSG_ROUTING_NONE), | 34 content::RenderView* render_view) |
| 36 render_thread_(content::RenderThread::Get()) { | 35 : content::RenderViewObserver(render_view) { |
| 37 DCHECK(render_thread_); | 36 render_view->GetWebView()->setCredentialManagerClient(this); |
| 38 } | 37 } |
| 39 | 38 |
| 40 CredentialManagerClient::~CredentialManagerClient() { | 39 CredentialManagerClient::~CredentialManagerClient() { |
| 41 DisconnectFromRenderThread(); | |
| 42 | |
| 43 ClearCallbacksMapWithErrors(&failed_sign_in_callbacks_); | 40 ClearCallbacksMapWithErrors(&failed_sign_in_callbacks_); |
| 44 ClearCallbacksMapWithErrors(&signed_in_callbacks_); | 41 ClearCallbacksMapWithErrors(&signed_in_callbacks_); |
| 45 ClearCallbacksMapWithErrors(&signed_out_callbacks_); | 42 ClearCallbacksMapWithErrors(&signed_out_callbacks_); |
| 46 ClearCallbacksMapWithErrors(&request_callbacks_); | 43 ClearCallbacksMapWithErrors(&request_callbacks_); |
| 47 } | 44 } |
| 48 | 45 |
| 49 void CredentialManagerClient::OnRenderViewCreated( | |
| 50 content::RenderView* render_view) { | |
| 51 render_view->GetWebView()->setCredentialManagerClient(this); | |
| 52 } | |
| 53 | |
| 54 void CredentialManagerClient::OnRenderProcessShutdown() { | |
| 55 DisconnectFromRenderThread(); | |
| 56 } | |
| 57 | |
| 58 int CredentialManagerClient::GetRoutingID() { | |
| 59 if (render_thread_ && routing_id_ == MSG_ROUTING_NONE) { | |
| 60 routing_id_ = render_thread_->GenerateRoutingID(); | |
| 61 render_thread_->AddRoute(routing_id_, this); | |
| 62 } | |
| 63 return routing_id_; | |
| 64 } | |
| 65 | |
| 66 void CredentialManagerClient::DisconnectFromRenderThread() { | |
| 67 if (render_thread_ && routing_id_ != MSG_ROUTING_NONE) | |
| 68 render_thread_->RemoveRoute(routing_id_); | |
| 69 render_thread_ = NULL; | |
| 70 routing_id_ = MSG_ROUTING_NONE; | |
| 71 } | |
| 72 | |
| 73 // ----------------------------------------------------------------------------- | 46 // ----------------------------------------------------------------------------- |
| 74 // Handle messages from the browser. | 47 // Handle messages from the browser. |
| 75 | 48 |
| 76 bool CredentialManagerClient::OnMessageReceived(const IPC::Message& message) { | 49 bool CredentialManagerClient::OnMessageReceived(const IPC::Message& message) { |
| 77 bool handled = true; | 50 bool handled = true; |
| 78 IPC_BEGIN_MESSAGE_MAP(CredentialManagerClient, message) | 51 IPC_BEGIN_MESSAGE_MAP(CredentialManagerClient, message) |
| 79 IPC_MESSAGE_HANDLER(CredentialManagerMsg_AcknowledgeFailedSignIn, | 52 IPC_MESSAGE_HANDLER(CredentialManagerMsg_AcknowledgeFailedSignIn, |
| 80 OnAcknowledgeFailedSignIn) | 53 OnAcknowledgeFailedSignIn) |
| 81 IPC_MESSAGE_HANDLER(CredentialManagerMsg_AcknowledgeSignedIn, | 54 IPC_MESSAGE_HANDLER(CredentialManagerMsg_AcknowledgeSignedIn, |
| 82 OnAcknowledgeSignedIn) | 55 OnAcknowledgeSignedIn) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 112 | 85 |
| 113 // ----------------------------------------------------------------------------- | 86 // ----------------------------------------------------------------------------- |
| 114 // Dispatch messages from the renderer to the browser. | 87 // Dispatch messages from the renderer to the browser. |
| 115 | 88 |
| 116 void CredentialManagerClient::dispatchFailedSignIn( | 89 void CredentialManagerClient::dispatchFailedSignIn( |
| 117 const blink::WebCredential& credential, | 90 const blink::WebCredential& credential, |
| 118 blink::WebCredentialManagerClient::NotificationCallbacks* callbacks) { | 91 blink::WebCredentialManagerClient::NotificationCallbacks* callbacks) { |
| 119 int request_id = failed_sign_in_callbacks_.Add(callbacks); | 92 int request_id = failed_sign_in_callbacks_.Add(callbacks); |
| 120 CredentialInfo info( | 93 CredentialInfo info( |
| 121 credential.id(), credential.name(), credential.avatarURL()); | 94 credential.id(), credential.name(), credential.avatarURL()); |
| 122 if (render_thread_) { | 95 Send(new CredentialManagerHostMsg_NotifyFailedSignIn( |
| 123 render_thread_->Send(new CredentialManagerHostMsg_NotifyFailedSignIn( | 96 routing_id(), request_id, info)); |
| 124 GetRoutingID(), request_id, info)); | |
| 125 } | |
| 126 } | 97 } |
| 127 | 98 |
| 128 void CredentialManagerClient::dispatchSignedIn( | 99 void CredentialManagerClient::dispatchSignedIn( |
| 129 const blink::WebCredential& credential, | 100 const blink::WebCredential& credential, |
| 130 blink::WebCredentialManagerClient::NotificationCallbacks* callbacks) { | 101 blink::WebCredentialManagerClient::NotificationCallbacks* callbacks) { |
| 131 int request_id = signed_in_callbacks_.Add(callbacks); | 102 int request_id = signed_in_callbacks_.Add(callbacks); |
| 132 CredentialInfo info( | 103 CredentialInfo info( |
| 133 credential.id(), credential.name(), credential.avatarURL()); | 104 credential.id(), credential.name(), credential.avatarURL()); |
| 134 if (render_thread_) { | 105 Send(new CredentialManagerHostMsg_NotifySignedIn( |
| 135 render_thread_->Send(new CredentialManagerHostMsg_NotifySignedIn( | 106 routing_id(), request_id, info)); |
| 136 GetRoutingID(), request_id, info)); | |
| 137 } | |
| 138 } | 107 } |
| 139 | 108 |
| 140 void CredentialManagerClient::dispatchSignedOut( | 109 void CredentialManagerClient::dispatchSignedOut( |
| 141 NotificationCallbacks* callbacks) { | 110 NotificationCallbacks* callbacks) { |
| 142 int request_id = signed_out_callbacks_.Add(callbacks); | 111 int request_id = signed_out_callbacks_.Add(callbacks); |
| 143 if (render_thread_) { | 112 Send(new CredentialManagerHostMsg_NotifySignedOut(routing_id(), request_id)); |
| 144 render_thread_->Send(new CredentialManagerHostMsg_NotifySignedOut( | |
| 145 GetRoutingID(), request_id)); | |
| 146 } | |
| 147 } | 113 } |
| 148 | 114 |
| 149 void CredentialManagerClient::dispatchRequest( | 115 void CredentialManagerClient::dispatchRequest( |
| 150 bool zeroClickOnly, | 116 bool zeroClickOnly, |
| 151 const blink::WebVector<blink::WebURL>& federations, | 117 const blink::WebVector<blink::WebURL>& federations, |
| 152 RequestCallbacks* callbacks) { | 118 RequestCallbacks* callbacks) { |
| 153 int request_id = request_callbacks_.Add(callbacks); | 119 int request_id = request_callbacks_.Add(callbacks); |
| 154 std::vector<GURL> federation_vector; | 120 std::vector<GURL> federation_vector; |
| 155 for (size_t i = 0; i < std::min(federations.size(), kMaxFederations); ++i) | 121 for (size_t i = 0; i < std::min(federations.size(), kMaxFederations); ++i) |
| 156 federation_vector.push_back(federations[i]); | 122 federation_vector.push_back(federations[i]); |
| 157 if (render_thread_) { | 123 Send(new CredentialManagerHostMsg_RequestCredential( |
| 158 render_thread_->Send(new CredentialManagerHostMsg_RequestCredential( | 124 routing_id(), request_id, zeroClickOnly, federation_vector)); |
| 159 GetRoutingID(), request_id, zeroClickOnly, federation_vector)); | |
| 160 } | |
| 161 } | 125 } |
| 162 | 126 |
| 163 void CredentialManagerClient::RespondToNotificationCallback( | 127 void CredentialManagerClient::RespondToNotificationCallback( |
| 164 int request_id, | 128 int request_id, |
| 165 CredentialManagerClient::NotificationCallbacksMap* map) { | 129 CredentialManagerClient::NotificationCallbacksMap* map) { |
| 166 blink::WebCredentialManagerClient::NotificationCallbacks* callbacks = | 130 blink::WebCredentialManagerClient::NotificationCallbacks* callbacks = |
| 167 map->Lookup(request_id); | 131 map->Lookup(request_id); |
| 168 DCHECK(callbacks); | 132 DCHECK(callbacks); |
| 169 callbacks->onSuccess(); | 133 callbacks->onSuccess(); |
| 170 map->Remove(request_id); | 134 map->Remove(request_id); |
| 171 } | 135 } |
| 172 | 136 |
| 173 } // namespace password_manager | 137 } // namespace password_manager |
| OLD | NEW |