Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / signin / inline_login_handler_impl.h
blobddb6894aafaa7a2781482814de5fe00b9b5d6458
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_HANDLER_IMPL_H_
6 #define CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_HANDLER_IMPL_H_
8 #include <string>
10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
14 #include "chrome/browser/ui/webui/signin/inline_login_handler.h"
16 // Implementation for the inline login WebUI handler on desktop Chrome. Once
17 // CrOS migrates to the same webview approach as desktop Chrome, much of the
18 // code in this class should move to its base class |InlineLoginHandler|.
19 class InlineLoginHandlerImpl : public InlineLoginHandler,
20 public content::WebContentsObserver {
21 public:
22 InlineLoginHandlerImpl();
23 ~InlineLoginHandlerImpl() override;
25 using InlineLoginHandler::web_ui;
27 base::WeakPtr<InlineLoginHandlerImpl> GetWeakPtr() {
28 return weak_factory_.GetWeakPtr();
31 Browser* GetDesktopBrowser();
32 void SyncStarterCallback(OneClickSigninSyncStarter::SyncSetupResult result);
33 // Closes the current tab and shows the account management view of the avatar
34 // bubble if |show_account_management| is true.
35 void CloseTab(bool show_account_management);
36 void HandleLoginError(const std::string& error_msg);
38 private:
39 friend class InlineLoginUIBrowserTest;
40 FRIEND_TEST_ALL_PREFIXES(InlineLoginUIBrowserTest, CanOfferNoProfile);
41 FRIEND_TEST_ALL_PREFIXES(InlineLoginUIBrowserTest, CanOffer);
42 FRIEND_TEST_ALL_PREFIXES(InlineLoginUIBrowserTest, CanOfferProfileConnected);
43 FRIEND_TEST_ALL_PREFIXES(InlineLoginUIBrowserTest,
44 CanOfferUsernameNotAllowed);
45 FRIEND_TEST_ALL_PREFIXES(InlineLoginUIBrowserTest, CanOfferWithRejectedEmail);
46 FRIEND_TEST_ALL_PREFIXES(InlineLoginUIBrowserTest, CanOfferNoSigninCookies);
48 // Argument to CanOffer().
49 enum CanOfferFor {
50 CAN_OFFER_FOR_ALL,
51 CAN_OFFER_FOR_SECONDARY_ACCOUNT
54 static bool CanOffer(Profile* profile,
55 CanOfferFor can_offer_for,
56 const std::string& gaia_id,
57 const std::string& email,
58 std::string* error_message);
60 // InlineLoginHandler overrides:
61 void SetExtraInitParams(base::DictionaryValue& params) override;
62 void CompleteLogin(const base::ListValue* args) override;
64 // This struct exists to pass paramters to the FinishCompleteLogin() method,
65 // since the base::Bind() call does not support this many template args.
66 struct FinishCompleteLoginParams {
67 public:
68 FinishCompleteLoginParams(InlineLoginHandlerImpl* handler,
69 content::StoragePartition* partition,
70 const GURL& url,
71 const base::FilePath& profile_path,
72 bool confirm_untrusted_signin,
73 const std::string& email,
74 const std::string& gaia_id,
75 const std::string& password,
76 const std::string& session_index,
77 bool choose_what_to_sync);
78 ~FinishCompleteLoginParams();
80 // Pointer to WebUI handler. May be nullptr.
81 InlineLoginHandlerImpl* handler;
82 // The isolate storage partition containing sign in cookies.
83 content::StoragePartition* partition;
84 // URL of sign in containing parameters such as email, source, etc.
85 GURL url;
86 // Path to profile being signed in. Non empty only when signing
87 // in to the profile from the user manager.
88 base::FilePath profile_path;
89 // When true, an extra prompt will be shown to the user before sign in
90 // completes.
91 bool confirm_untrusted_signin;
92 // Email address of the account used to sign in.
93 std::string email;
94 // Obfustcated gaia id of the account used to sign in.
95 std::string gaia_id;
96 // Password of the account used to sign in.
97 std::string password;
98 // Index within gaia cookie of the account used to sign in.
99 std::string session_index;
100 // True if the user wants to configure sync before signing in.
101 bool choose_what_to_sync;
104 static void FinishCompleteLogin(const FinishCompleteLoginParams& params,
105 Profile* profile,
106 Profile::CreateStatus status);
108 // Overridden from content::WebContentsObserver overrides.
109 void DidCommitProvisionalLoadForFrame(
110 content::RenderFrameHost* render_frame_host,
111 const GURL& url,
112 ui::PageTransition transition_type) override;
114 // True if the user has navigated to untrusted domains during the signin
115 // process.
116 bool confirm_untrusted_signin_;
118 base::WeakPtrFactory<InlineLoginHandlerImpl> weak_factory_;
120 DISALLOW_COPY_AND_ASSIGN(InlineLoginHandlerImpl);
123 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_INLINE_LOGIN_HANDLER_IMPL_H_