 Chromium Code Reviews
 Chromium Code Reviews Issue 1762603002:
  Switch components/password_manager code from IPC messages to Mojo.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1762603002:
  Switch components/password_manager code from IPC messages to Mojo.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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 #ifndef COMPONENTS_PASSWORD_MANAGER_CONTENT_BROWSER_CONTENT_CREDENTIAL_MANAGER_D ISPATCHER_H_ | 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CONTENT_BROWSER_CONTENT_CREDENTIAL_MANAGER_I MPL_H_ | 
| 6 #define COMPONENTS_PASSWORD_MANAGER_CONTENT_BROWSER_CONTENT_CREDENTIAL_MANAGER_D ISPATCHER_H_ | 6 #define COMPONENTS_PASSWORD_MANAGER_CONTENT_BROWSER_CONTENT_CREDENTIAL_MANAGER_I MPL_H_ | 
| 7 | 7 | 
| 8 #include "base/callback.h" | 8 #include "base/callback.h" | 
| 9 #include "base/macros.h" | 9 #include "base/macros.h" | 
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" | 
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" | 
| 12 #include "components/password_manager/content/public/interfaces/credential_manag er.mojom.h" | |
| 12 #include "components/password_manager/core/browser/credential_manager_password_f orm_manager.h" | 13 #include "components/password_manager/core/browser/credential_manager_password_f orm_manager.h" | 
| 13 #include "components/password_manager/core/browser/credential_manager_pending_re quest_task.h" | 14 #include "components/password_manager/core/browser/credential_manager_pending_re quest_task.h" | 
| 14 #include "components/password_manager/core/browser/credential_manager_pending_re quire_user_mediation_task.h" | 15 #include "components/password_manager/core/browser/credential_manager_pending_re quire_user_mediation_task.h" | 
| 15 #include "components/password_manager/core/browser/password_store_consumer.h" | 16 #include "components/password_manager/core/browser/password_store_consumer.h" | 
| 16 #include "components/prefs/pref_member.h" | 17 #include "components/prefs/pref_member.h" | 
| 17 #include "content/public/browser/web_contents_observer.h" | 18 #include "content/public/browser/web_contents_observer.h" | 
| 19 #include "mojo/public/cpp/bindings/binding_set.h" | |
| 18 | 20 | 
| 19 class GURL; | 21 class GURL; | 
| 20 | 22 | 
| 21 namespace autofill { | 23 namespace autofill { | 
| 22 struct PasswordForm; | 24 struct PasswordForm; | 
| 23 } | 25 } | 
| 24 | 26 | 
| 25 namespace content { | 27 namespace content { | 
| 26 class WebContents; | 28 class WebContents; | 
| 27 } | 29 } | 
| 28 | 30 | 
| 29 namespace password_manager { | 31 namespace password_manager { | 
| 30 class CredentialManagerPasswordFormManager; | 32 class CredentialManagerPasswordFormManager; | 
| 31 class PasswordManagerClient; | 33 class PasswordManagerClient; | 
| 32 class PasswordManagerDriver; | 34 class PasswordManagerDriver; | 
| 33 class PasswordStore; | 35 class PasswordStore; | 
| 34 struct CredentialInfo; | 36 struct CredentialInfo; | 
| 35 | 37 | 
| 36 class CredentialManagerDispatcher | 38 // This class implements the Mojo interface mojom::CredentialManager. | 
| 
vabr (Chromium)
2016/03/09 16:26:29
optional: Drop this comment, line 40 says the same
 
leonhsl(Using Gerrit)
2016/03/10 06:42:41
Done.
 | |
| 37 : public content::WebContentsObserver, | 39 class CredentialManagerImpl | 
| 40 : public mojom::CredentialManager, | |
| 41 public content::WebContentsObserver, | |
| 38 public CredentialManagerPasswordFormManagerDelegate, | 42 public CredentialManagerPasswordFormManagerDelegate, | 
| 39 public CredentialManagerPendingRequestTaskDelegate, | 43 public CredentialManagerPendingRequestTaskDelegate, | 
| 40 public CredentialManagerPendingRequireUserMediationTaskDelegate { | 44 public CredentialManagerPendingRequireUserMediationTaskDelegate { | 
| 41 public: | 45 public: | 
| 42 CredentialManagerDispatcher(content::WebContents* web_contents, | 46 CredentialManagerImpl(content::WebContents* web_contents, | 
| 43 PasswordManagerClient* client); | 47 PasswordManagerClient* client); | 
| 44 ~CredentialManagerDispatcher() override; | 48 ~CredentialManagerImpl() override; | 
| 45 | 49 | 
| 46 // Called in response to an IPC from the renderer, triggered by a page's call | 50 void BindRequest(mojom::CredentialManagerRequest request); | 
| 47 // to 'navigator.credentials.store'. | |
| 48 virtual void OnStore(int request_id, const password_manager::CredentialInfo&); | |
| 49 | |
| 50 // Called in response to an IPC from the renderer, triggered by a page's call | |
| 51 // to 'navigator.credentials.requireUserMediation'. | |
| 52 virtual void OnRequireUserMediation(int request_id); | |
| 53 | |
| 54 // Called in response to an IPC from the renderer, triggered by a page's call | |
| 55 // to 'navigator.credentials.request'. | |
| 56 // | |
| 57 // TODO(vabr): Determine if we can drop the `const` here to save some copies | |
| 58 // while processing the request. | |
| 59 virtual void OnRequestCredential(int request_id, | |
| 60 bool zero_click_only, | |
| 61 bool include_passwords, | |
| 62 const std::vector<GURL>& federations); | |
| 63 | |
| 64 // content::WebContentsObserver implementation. | |
| 65 bool OnMessageReceived(const IPC::Message& message) override; | |
| 66 | 51 | 
| 67 // CredentialManagerPendingRequestTaskDelegate: | 52 // CredentialManagerPendingRequestTaskDelegate: | 
| 68 bool IsZeroClickAllowed() const override; | 53 bool IsZeroClickAllowed() const override; | 
| 69 GURL GetOrigin() const override; | 54 GURL GetOrigin() const override; | 
| 70 void SendCredential(int request_id, const CredentialInfo& info) override; | 55 void SendCredential(const SendCredentialCallback& send_callback, | 
| 56 const CredentialInfo& info) override; | |
| 71 PasswordManagerClient* client() const override; | 57 PasswordManagerClient* client() const override; | 
| 72 autofill::PasswordForm GetSynthesizedFormForOrigin() const override; | 58 autofill::PasswordForm GetSynthesizedFormForOrigin() const override; | 
| 73 | 59 | 
| 74 // CredentialManagerPendingSignedOutTaskDelegate: | 60 // CredentialManagerPendingSignedOutTaskDelegate: | 
| 75 PasswordStore* GetPasswordStore() override; | 61 PasswordStore* GetPasswordStore() override; | 
| 76 void DoneRequiringUserMediation() override; | 62 void DoneRequiringUserMediation() override; | 
| 77 | 63 | 
| 78 // CredentialManagerPasswordFormManagerDelegate: | 64 // CredentialManagerPasswordFormManagerDelegate: | 
| 79 void OnProvisionalSaveComplete() override; | 65 void OnProvisionalSaveComplete() override; | 
| 80 | 66 | 
| 81 private: | 67 private: | 
| 68 // mojom::CredentialManager methods: | |
| 69 // Called in response to the request from the renderer, triggered by a page's | |
| 
vabr (Chromium)
2016/03/09 16:26:29
nit: Actually, the comments explaining the methods
 
leonhsl(Using Gerrit)
2016/03/10 06:42:41
Done. Only leave comments in the interface definit
 | |
| 70 // call | |
| 
vabr (Chromium)
2016/03/09 16:26:29
nit: Please indent the comment block properly, do
 
leonhsl(Using Gerrit)
2016/03/10 06:42:41
Done.
 | |
| 71 // to 'navigator.credentials.store'. | |
| 72 void Store(mojom::CredentialInfoPtr credential, | |
| 73 const StoreCallback& callback) override; | |
| 74 | |
| 75 // Called in response to the request from the renderer, triggered by a page's | |
| 76 // call | |
| 77 // to 'navigator.credentials.requireUserMediation'. | |
| 78 void RequireUserMediation( | |
| 79 const RequireUserMediationCallback& callback) override; | |
| 80 | |
| 81 // Called in response to the request from the renderer, triggered by a page's | |
| 82 // call | |
| 83 // to 'navigator.credentials.request'. | |
| 
vabr (Chromium)
2016/03/09 16:26:29
"request" or "get"? The mojom file says "get". The
 
leonhsl(Using Gerrit)
2016/03/10 06:42:41
Done. It should be 'navigator.credentials.get()'.
 | |
| 84 void Get(bool zero_click_only, | |
| 85 bool include_passwords, | |
| 86 mojo::Array<mojo::String> federations, | |
| 87 const GetCallback& callback) override; | |
| 88 | |
| 82 // Returns the driver for the current main frame. | 89 // Returns the driver for the current main frame. | 
| 83 // Virtual for testing. | 90 // Virtual for testing. | 
| 84 virtual base::WeakPtr<PasswordManagerDriver> GetDriver(); | 91 virtual base::WeakPtr<PasswordManagerDriver> GetDriver(); | 
| 85 | 92 | 
| 86 // Schedules a CredentiaManagerPendingRequestTask (during | 93 // Schedules a CredentiaManagerPendingRequestTask (during | 
| 87 // |OnRequestCredential()|) after the PasswordStore's AffiliationMatchHelper | 94 // |OnRequestCredential()|) after the PasswordStore's AffiliationMatchHelper | 
| 88 // grabs a list of realms related to the current web origin. | 95 // grabs a list of realms related to the current web origin. | 
| 89 void ScheduleRequestTask(int request_id, | 96 void ScheduleRequestTask(const GetCallback& callback, | 
| 90 bool zero_click_only, | 97 bool zero_click_only, | 
| 91 bool include_passwords, | 98 bool include_passwords, | 
| 92 const std::vector<GURL>& federations, | 99 const std::vector<GURL>& federations, | 
| 93 const std::vector<std::string>& android_realms); | 100 const std::vector<std::string>& android_realms); | 
| 94 | 101 | 
| 95 // Schedules a CredentialManagerPendingRequireUserMediationTask after the | 102 // Schedules a CredentialManagerPendingRequireUserMediationTask after the | 
| 96 // AffiliationMatchHelper grabs a list of realms related to the current | 103 // AffiliationMatchHelper grabs a list of realms related to the current | 
| 97 // web origin. | 104 // web origin. | 
| 98 void ScheduleRequireMediationTask( | 105 void ScheduleRequireMediationTask( | 
| 99 int request_id, | 106 const RequireUserMediationCallback& callback, | 
| 100 const std::vector<std::string>& android_realms); | 107 const std::vector<std::string>& android_realms); | 
| 101 | 108 | 
| 102 // Returns true iff it's OK to update credentials in the password store. | 109 // Returns true iff it's OK to update credentials in the password store. | 
| 103 bool IsUpdatingCredentialAllowed() const; | 110 bool IsUpdatingCredentialAllowed() const; | 
| 104 | 111 | 
| 105 PasswordManagerClient* client_; | 112 PasswordManagerClient* client_; | 
| 106 scoped_ptr<CredentialManagerPasswordFormManager> form_manager_; | 113 scoped_ptr<CredentialManagerPasswordFormManager> form_manager_; | 
| 107 | 114 | 
| 108 // Set to false to disable automatic signing in. | 115 // Set to false to disable automatic signing in. | 
| 109 BooleanPrefMember auto_signin_enabled_; | 116 BooleanPrefMember auto_signin_enabled_; | 
| 110 | 117 | 
| 111 // When 'OnRequestCredential' is called, it in turn calls out to the | 118 // When 'OnRequestCredential' is called, it in turn calls out to the | 
| 112 // PasswordStore; we push enough data into Pending*Task objects so that | 119 // PasswordStore; we push enough data into Pending*Task objects so that | 
| 113 // they can properly respond to the request once the PasswordStore gives | 120 // they can properly respond to the request once the PasswordStore gives | 
| 114 // us data. | 121 // us data. | 
| 115 scoped_ptr<CredentialManagerPendingRequestTask> pending_request_; | 122 scoped_ptr<CredentialManagerPendingRequestTask> pending_request_; | 
| 116 scoped_ptr<CredentialManagerPendingRequireUserMediationTask> | 123 scoped_ptr<CredentialManagerPendingRequireUserMediationTask> | 
| 117 pending_require_user_mediation_; | 124 pending_require_user_mediation_; | 
| 118 | 125 | 
| 119 base::WeakPtrFactory<CredentialManagerDispatcher> weak_factory_; | 126 mojo::BindingSet<mojom::CredentialManager> bindings_; | 
| 120 | 127 | 
| 121 DISALLOW_COPY_AND_ASSIGN(CredentialManagerDispatcher); | 128 base::WeakPtrFactory<CredentialManagerImpl> weak_factory_; | 
| 129 | |
| 130 DISALLOW_COPY_AND_ASSIGN(CredentialManagerImpl); | |
| 122 }; | 131 }; | 
| 123 | 132 | 
| 124 } // namespace password_manager | 133 } // namespace password_manager | 
| 125 | 134 | 
| 126 #endif // COMPONENTS_PASSWORD_MANAGER_CONTENT_BROWSER_CONTENT_CREDENTIAL_MANAGE R_DISPATCHER_H_ | 135 #endif // COMPONENTS_PASSWORD_MANAGER_CONTENT_BROWSER_CONTENT_CREDENTIAL_MANAGE R_IMPL_H_ | 
| OLD | NEW |