Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/extensions/api/identity/web_auth_flow.h

Issue 10178020: Start implementing an auth flow for platform apps to be able to do auth (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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_EXTENSIONS_API_IDENTITY_WEB_AUTH_FLOW_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_WEB_AUTH_FLOW_H_
7 #pragma once
8
9 #include <string>
10 #include <vector>
11
12 #include "base/compiler_specific.h"
13 #include "base/gtest_prod_util.h"
14 #include "chrome/browser/ui/extensions/web_auth_flow_window.h"
15 #include "content/public/browser/web_contents_delegate.h"
16 #include "googleurl/src/gurl.h"
17
18 class WebAuthFlowTest;
19
20 namespace content {
21 class BrowserContext;
22 class WebContents;
23 }
24
25 namespace extensions {
26
27 // Controller class to perform an auth flow with a provider.
28 // This is the class to start the auth flow and it takes care of all the
29 // details. It behaves the following way:
30 // Given a provider URL, load the URL and perform usual web navigation
31 // until it results in redirection to a valid extension redirect URL.
32 // The provider can show any UI to the user if needed before redirecting
33 // to an appropriate URL.
34 // TODO(munjal): Add link to the design doc here.
35 class WebAuthFlow : public content::WebContentsDelegate,
36 public WebAuthFlowWindow::Delegate {
37 public:
38 class Delegate {
39 public:
40 // Called when the auth flow is completed successfully.
41 // |redirect_url| is the full URL the provider redirected to at the end
42 // of the flow.
43 virtual void OnAuthFlowSuccess(const std::string& redirect_url) = 0;
44 // Called when the auth flow fails. This means that the flow did not result
45 // in a successful redirect to a valid redirect URL or the user canceled
46 // the flow.
47 virtual void OnAuthFlowFailure() = 0;
48
49 virtual ~Delegate() { }
50 };
51
52 // Interceptor interface for testing.
53 class InterceptorForTests {
54 public:
55 virtual GURL DoIntercept(const GURL& provider_url) = 0;
56 virtual ~InterceptorForTests() { }
57 };
58 static void SetInterceptorForTests(InterceptorForTests* interceptor);
59
60 // Creates an instance with the given parameters.
61 // Caller owns |delegate|.
62 WebAuthFlow(Delegate* delegate,
63 content::BrowserContext* browser_context,
64 const std::string& extension_id,
65 const GURL& provider_url);
66 virtual ~WebAuthFlow();
67
68 // Starts the flow.
69 // Delegate will be called when the flow is done.
70 virtual void Start();
71
72 protected:
73 virtual content::WebContents* CreateWebContents();
74 virtual WebAuthFlowWindow* CreateAuthWindow();
75
76 private:
77 friend class ::WebAuthFlowTest;
78
79 // WebContentsDelegate implementation.
80 virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE;
81 virtual void NavigationStateChanged(
82 const content::WebContents* source, unsigned changed_flags) OVERRIDE;
83
84 // WebAuthFlowWindow::Delegate implementation.
85 virtual void OnClose() OVERRIDE;
86
87 static InterceptorForTests* interceptor;
88
89 void OnUrlLoaded();
90 // Reports the results back to the delegate.
91 void ReportResult(const GURL& result);
92 // Helper to initialize valid extensions URLs vector.
93 void InitValidRedirectUrlPrefixes(const std::string& extension_id);
94 // Checks if |url| is a valid redirect URL for the extension.
95 bool IsValidRedirectUrl(const GURL& url) const;
96
97 Delegate* delegate_;
98 content::BrowserContext* browser_context_;
99 GURL provider_url_;
100 // List of valid redirect URL prefixes.
101 std::vector<std::string> valid_prefixes_;
102
103 content::WebContents* contents_;
104 WebAuthFlowWindow* window_;
105
106 DISALLOW_COPY_AND_ASSIGN(WebAuthFlow);
107 };
108
109 } // namespace extensions
110
111 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_WEB_AUTH_FLOW_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_apitest.cc ('k') | chrome/browser/extensions/api/identity/web_auth_flow.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698