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

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 namespace content {
19 class BrowserContext;
20 class WebContents;
21 }
22
23 class WebAuthFlowTest;
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
50 // Interceptor interface for testing.
51 class InterceptorForTests {
52 public:
53 virtual GURL DoIntercept(const GURL& provider_url) = 0;
54 };
55 static void SetInterceptorForTests(InterceptorForTests* interceptor);
56
57 // Creates an instance with the given parameters.
58 // Caller owns |delegate|.
59 WebAuthFlow(Delegate* delegate,
60 content::BrowserContext* browser_context,
61 const std::string& extension_id,
62 const GURL& provider_url);
63 virtual ~WebAuthFlow();
64
65 // Starts the flow.
66 // Delegate will be called when the flow is done.
67 virtual void Start();
68
69 protected:
70 virtual content::WebContents* CreateWebContents();
71 virtual WebAuthFlowWindow* CreateAuthWindow();
72
73 private:
74 friend class WebAuthFlowTest;
75
76 // WebContentsDelegate implementation.
77 virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE;
78 virtual void NavigationStateChanged(
79 const content::WebContents* source, unsigned changed_flags) OVERRIDE;
80
81 // WebAuthFlowWindow::Delegate implementation.
82 virtual void OnClose() OVERRIDE;
83
84 static InterceptorForTests* interceptor;
85
86 void OnUrlLoaded();
87 // Reports the results back to the delegate.
88 void ReportResult(const GURL& result);
89 // Helper to initialize valid extensions URLs vector.
90 void InitValidRedirectUrlPrefixes(const std::string& extension_id);
91 // Checks if |url| is a valid redirect URL for the extension.
92 bool IsValidRedirectUrl(const GURL& url) const;
93
94 Delegate* delegate_;
95 content::BrowserContext* browser_context_;
96 GURL provider_url_;
97 // List of valid redirect URL prefixes.
98 std::vector<std::string> valid_prefixes_;
99
100 content::WebContents* contents_;
101 WebAuthFlowWindow* window_;
102
103 DISALLOW_COPY_AND_ASSIGN(WebAuthFlow);
104 };
105
106 } // namespace extensions
107
108 #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