| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_HANDLER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_HANDLER_IMPL_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_HANDLER_IMPL_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_HANDLER_IMPL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" | 14 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
| 15 #include "chrome/browser/ui/webui/signin/inline_login_handler.h" | 15 #include "chrome/browser/ui/webui/signin/inline_login_handler.h" |
| 16 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 16 | 17 |
| 17 // Implementation for the inline login WebUI handler on desktop Chrome. Once | 18 // Implementation for the inline login WebUI handler on desktop Chrome. Once |
| 18 // CrOS migrates to the same webview approach as desktop Chrome, much of the | 19 // CrOS migrates to the same webview approach as desktop Chrome, much of the |
| 19 // code in this class should move to its base class |InlineLoginHandler|. | 20 // code in this class should move to its base class |InlineLoginHandler|. |
| 20 class InlineLoginHandlerImpl : public InlineLoginHandler, | 21 class InlineLoginHandlerImpl : public InlineLoginHandler, |
| 21 public content::WebContentsObserver { | 22 public content::WebContentsObserver { |
| 22 public: | 23 public: |
| 23 InlineLoginHandlerImpl(); | 24 InlineLoginHandlerImpl(); |
| 24 ~InlineLoginHandlerImpl() override; | 25 ~InlineLoginHandlerImpl() override; |
| 25 | 26 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 public: | 69 public: |
| 69 FinishCompleteLoginParams(InlineLoginHandlerImpl* handler, | 70 FinishCompleteLoginParams(InlineLoginHandlerImpl* handler, |
| 70 content::StoragePartition* partition, | 71 content::StoragePartition* partition, |
| 71 const GURL& url, | 72 const GURL& url, |
| 72 const base::FilePath& profile_path, | 73 const base::FilePath& profile_path, |
| 73 bool confirm_untrusted_signin, | 74 bool confirm_untrusted_signin, |
| 74 const std::string& email, | 75 const std::string& email, |
| 75 const std::string& gaia_id, | 76 const std::string& gaia_id, |
| 76 const std::string& password, | 77 const std::string& password, |
| 77 const std::string& session_index, | 78 const std::string& session_index, |
| 79 const std::string& auth_code, |
| 78 bool choose_what_to_sync); | 80 bool choose_what_to_sync); |
| 79 ~FinishCompleteLoginParams(); | 81 ~FinishCompleteLoginParams(); |
| 80 | 82 |
| 81 // Pointer to WebUI handler. May be nullptr. | 83 // Pointer to WebUI handler. May be nullptr. |
| 82 InlineLoginHandlerImpl* handler; | 84 InlineLoginHandlerImpl* handler; |
| 83 // The isolate storage partition containing sign in cookies. | 85 // The isolate storage partition containing sign in cookies. |
| 84 content::StoragePartition* partition; | 86 content::StoragePartition* partition; |
| 85 // URL of sign in containing parameters such as email, source, etc. | 87 // URL of sign in containing parameters such as email, source, etc. |
| 86 GURL url; | 88 GURL url; |
| 87 // Path to profile being signed in. Non empty only when signing | 89 // Path to profile being signed in. Non empty only when signing |
| 88 // in to the profile from the user manager. | 90 // in to the profile from the user manager. |
| 89 base::FilePath profile_path; | 91 base::FilePath profile_path; |
| 90 // When true, an extra prompt will be shown to the user before sign in | 92 // When true, an extra prompt will be shown to the user before sign in |
| 91 // completes. | 93 // completes. |
| 92 bool confirm_untrusted_signin; | 94 bool confirm_untrusted_signin; |
| 93 // Email address of the account used to sign in. | 95 // Email address of the account used to sign in. |
| 94 std::string email; | 96 std::string email; |
| 95 // Obfustcated gaia id of the account used to sign in. | 97 // Obfustcated gaia id of the account used to sign in. |
| 96 std::string gaia_id; | 98 std::string gaia_id; |
| 97 // Password of the account used to sign in. | 99 // Password of the account used to sign in. |
| 98 std::string password; | 100 std::string password; |
| 99 // Index within gaia cookie of the account used to sign in. | 101 // Index within gaia cookie of the account used to sign in. Used only |
| 102 // with password combined signin flow. |
| 100 std::string session_index; | 103 std::string session_index; |
| 104 // Authentication code used to exchange for a login scoped refresh token |
| 105 // for the account used to sign in. Used only with password separated |
| 106 // signin flow. |
| 107 std::string auth_code; |
| 101 // True if the user wants to configure sync before signing in. | 108 // True if the user wants to configure sync before signing in. |
| 102 bool choose_what_to_sync; | 109 bool choose_what_to_sync; |
| 103 }; | 110 }; |
| 104 | 111 |
| 105 static void FinishCompleteLogin(const FinishCompleteLoginParams& params, | 112 static void FinishCompleteLogin(const FinishCompleteLoginParams& params, |
| 106 Profile* profile, | 113 Profile* profile, |
| 107 Profile::CreateStatus status); | 114 Profile::CreateStatus status); |
| 108 | 115 |
| 109 // Overridden from content::WebContentsObserver overrides. | 116 // Overridden from content::WebContentsObserver overrides. |
| 110 void DidCommitProvisionalLoadForFrame( | 117 void DidCommitProvisionalLoadForFrame( |
| 111 content::RenderFrameHost* render_frame_host, | 118 content::RenderFrameHost* render_frame_host, |
| 112 const GURL& url, | 119 const GURL& url, |
| 113 ui::PageTransition transition_type) override; | 120 ui::PageTransition transition_type) override; |
| 114 | 121 |
| 115 // True if the user has navigated to untrusted domains during the signin | 122 // True if the user has navigated to untrusted domains during the signin |
| 116 // process. | 123 // process. |
| 117 bool confirm_untrusted_signin_; | 124 bool confirm_untrusted_signin_; |
| 118 | 125 |
| 119 base::WeakPtrFactory<InlineLoginHandlerImpl> weak_factory_; | 126 base::WeakPtrFactory<InlineLoginHandlerImpl> weak_factory_; |
| 120 | 127 |
| 121 DISALLOW_COPY_AND_ASSIGN(InlineLoginHandlerImpl); | 128 DISALLOW_COPY_AND_ASSIGN(InlineLoginHandlerImpl); |
| 122 }; | 129 }; |
| 123 | 130 |
| 131 // Handles details of signing the user in with SigninManager and turning on |
| 132 // sync after InlineLoginHandlerImpl has acquired the auth tokens from GAIA. |
| 133 // This is a separate class from InlineLoginHandlerImpl because the full signin |
| 134 // process is asynchronous and can outlive the signin UI. |
| 135 // InlineLoginHandlerImpl is destryed once the UI is closed. |
| 136 class InlineSigninHelper : public GaiaAuthConsumer { |
| 137 public: |
| 138 // Actions that can be taken when the user is asked to confirm their account. |
| 139 enum Action { |
| 140 // The user chose not to sign in to the current profile and wants chrome |
| 141 // to create a new profile instead. |
| 142 CREATE_NEW_USER, |
| 143 |
| 144 // The user chose to sign in and enable sync in the current profile. |
| 145 START_SYNC, |
| 146 |
| 147 // The user chose abort sign in. |
| 148 CLOSE |
| 149 }; |
| 150 |
| 151 InlineSigninHelper( |
| 152 base::WeakPtr<InlineLoginHandlerImpl> handler, |
| 153 net::URLRequestContextGetter* getter, |
| 154 Profile* profile, |
| 155 const GURL& current_url, |
| 156 const std::string& email, |
| 157 const std::string& gaia_id, |
| 158 const std::string& password, |
| 159 const std::string& session_index, |
| 160 const std::string& auth_code, |
| 161 const std::string& signin_scoped_device_id, |
| 162 bool choose_what_to_sync, |
| 163 bool confirm_untrusted_signin); |
| 164 ~InlineSigninHelper() override; |
| 165 |
| 166 private: |
| 167 // Handles cross account sign in error. If the supplied |email| does not match |
| 168 // the last signed in email of the current profile, then Chrome will show a |
| 169 // confirmation dialog before starting sync. It returns true if there is a |
| 170 // cross account error, and false otherwise. |
| 171 bool HandleCrossAccountError( |
| 172 const std::string& refresh_token, |
| 173 signin_metrics::Source source, |
| 174 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, |
| 175 OneClickSigninSyncStarter::StartSyncMode start_mode); |
| 176 |
| 177 // Callback used with ConfirmEmailDialogDelegate. |
| 178 void ConfirmEmailAction( |
| 179 content::WebContents* web_contents, |
| 180 const std::string& refresh_token, |
| 181 signin_metrics::Source source, |
| 182 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, |
| 183 OneClickSigninSyncStarter::StartSyncMode start_mode, |
| 184 Action action); |
| 185 |
| 186 // Overridden from GaiaAuthConsumer. |
| 187 void OnClientOAuthSuccess(const ClientOAuthResult& result) override; |
| 188 void OnClientOAuthFailure(const GoogleServiceAuthError& error) |
| 189 override; |
| 190 |
| 191 // Creates the sync starter. Virtual for tests. Call to exchange oauth code |
| 192 // for tokens. |
| 193 virtual void CreateSyncStarter( |
| 194 Browser* browser, |
| 195 content::WebContents* contents, |
| 196 const GURL& url, |
| 197 const std::string& refresh_token, |
| 198 OneClickSigninSyncStarter::StartSyncMode start_mode, |
| 199 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required); |
| 200 |
| 201 GaiaAuthFetcher gaia_auth_fetcher_; |
| 202 base::WeakPtr<InlineLoginHandlerImpl> handler_; |
| 203 Profile* profile_; |
| 204 GURL current_url_; |
| 205 std::string email_; |
| 206 std::string gaia_id_; |
| 207 std::string password_; |
| 208 std::string session_index_; |
| 209 std::string auth_code_; |
| 210 bool choose_what_to_sync_; |
| 211 bool confirm_untrusted_signin_; |
| 212 |
| 213 DISALLOW_COPY_AND_ASSIGN(InlineSigninHelper); |
| 214 }; |
| 215 |
| 124 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_HANDLER_IMPL_H_ | 216 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_HANDLER_IMPL_H_ |
| OLD | NEW |