• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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.
4 
5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_LOGIN_UI_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_LOGIN_UI_H_
7 #pragma once
8 
9 #include <string>
10 
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
13 #include "content/browser/webui/web_ui.h"
14 
15 class Profile;
16 
17 namespace chromeos {
18 
19 class HTMLOperationsInterface;
20 
21 // Boilerplate class that is used to associate the LoginUI code with the URL
22 // "chrome://login"
23 class LoginUIHTMLSource : public ChromeURLDataManager::DataSource {
24  public:
25   explicit LoginUIHTMLSource(MessageLoop* message_loop);
26 
27   virtual void StartDataRequest(const std::string& path,
28                                 bool is_incognito,
29                                 int request_id);
30   virtual std::string GetMimeType(const std::string&) const;
31 
32  private:
33   scoped_ptr<HTMLOperationsInterface> html_operations_;
34 
35   DISALLOW_COPY_AND_ASSIGN(LoginUIHTMLSource);
36 };
37 
38 class LoginUIHandler;
39 class LoginUIHandlerDelegate {
40  public:
LoginUIHandlerDelegate()41   LoginUIHandlerDelegate()
42       : login_handler_(NULL) { }
43   // Sign in using |username| and |password| specified.
44   // Used for both known and new users.
45   virtual void Login(const std::string& username,
46                      const std::string& password) = 0;
47 
48   // Sign in into Guest session.
49   virtual void LoginAsGuest() = 0;
50   // Let the delegate know about the handler it is supposed to be using.
set_login_handler(LoginUIHandler * login_handler)51   virtual void set_login_handler(LoginUIHandler* login_handler) {
52     login_handler_ = login_handler;
53   }
54  protected:
55   // Reference to the DOM handling layer for the login screen
56   LoginUIHandler* login_handler_;
57 
58   virtual ~LoginUIHandlerDelegate();
59 };
60 
61 // Main LoginUI handling function. It handles the WebUI hooks that are supplied
62 // for the login page to use for authentication.
63 class LoginUIHandler : public WebUIMessageHandler {
64  public:
65   LoginUIHandler();
66 
67   // WebUIMessageHandler implementation.
68   virtual WebUIMessageHandler* Attach(WebUI* web_ui);
69   virtual void RegisterMessages();
70 
71   void HandleAuthenticateUser(const ListValue* args);
72   void HandleLaunchIncognito(const ListValue* args);
73   void HandleShutdownSystem(const ListValue* args);
74   void ClearAndEnablePassword();
75 
76  protected:
77   LoginUIHandlerDelegate* delegate_;
78 
79  private:
80   DISALLOW_COPY_AND_ASSIGN(LoginUIHandler);
81 };
82 
83 // Boilerplate class that is used to associate the LoginUI code with the WebUI
84 // code.
85 class LoginUI : public WebUI {
86  public:
87   explicit LoginUI(TabContents* contents);
88 
89   // Return the URL for a given search term.
90   static const GURL GetLoginURLWithSearchText(const string16& text);
91 
92   static RefCountedMemory* GetFaviconResourceBytes();
93 
94  private:
95   DISALLOW_COPY_AND_ASSIGN(LoginUI);
96 };
97 
98 }  // namespace chromeos
99 
100 #endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_LOGIN_UI_H_
101