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

Side by Side Diff: chrome/browser/extensions/api/identity/extension_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_EXTENSION_AUTH_FLOW_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_EXTENSION_AUTH_FLOW_H_
7 #pragma once
8
9 #include <string>
10 #include <vector>
11
12 #include "base/memory/scoped_ptr.h"
Mihai Parparita -not on Chrome 2012/05/08 21:33:30 You can remove this.
Munjal (Google) 2012/05/11 18:53:33 Done.
13 #include "content/public/browser/web_contents_delegate.h"
14 #include "googleurl/src/gurl.h"
15 #include "ui/views/widget/widget_delegate.h"
16
17 namespace content {
18 class BrowserContext;
19 class WebContents;
20 }
21
22 namespace views {
23 class WebView;
24 class Widget;
25 }
26
27 namespace extensions {
28
29 // Controller class to perform an auth flow with a provider.
30 // This is the class to start the auth flow and it takes care of all the
31 // details. It behaves the following way:
32 // Given a provider URL, load the URL and perform usual web navigation
33 // until it results in redirection to a valid extension redirect URL.
34 // The provider can show any UI to the user if needed before redirecting
35 // to an appropriate URL.
36 // TODO(munjal): Add link to the design doc here.
37 class ExtensionAuthFlow : public content::WebContentsDelegate,
38 public views::WidgetDelegate {
39 public:
40 class Delegate {
41 public:
42 // Called when the auth flow is completed successfully.
43 // |redirect_url| is the full URL the provider redirected to at the end
44 // of the flow.
45 virtual void OnAuthFlowSuccess(const std::string& redirect_url) = 0;
46 // Called when the auth flow fails. This means that the flow did not result
47 // in a successful redirect to a valid redirect URL or the user canceled
48 // the flow.
49 virtual void OnAuthFlowFailure() = 0;
50 };
51
52 // Creates an instance with the given parameters.
53 // Caller owns |delegate|.
54 ExtensionAuthFlow(Delegate* delegate,
55 content::BrowserContext* browser_context,
56 const std::string& extension_id,
57 const GURL& provider_url);
58 ~ExtensionAuthFlow();
59
60 // Starts the flow.
61 // Delegate will be called when the flow is done.
62 void Start();
63
64 protected:
65 virtual content::WebContents* CreateWebContents();
66
67 private:
68 // WebContentsDelegate implementation.
69 virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE;
70 virtual void NavigationStateChanged(
71 const content::WebContents* source, unsigned changed_flags) OVERRIDE;
72
73 // WidgetDelegate implementation.
74 virtual views::View* GetContentsView() OVERRIDE;
75 virtual views::Widget* GetWidget() OVERRIDE;
76 virtual const views::Widget* GetWidget() const OVERRIDE;
77 virtual views::View* GetInitiallyFocusedView() OVERRIDE;
78 virtual void DeleteDelegate() OVERRIDE;
79
80 void OnUrlLoaded();
81 // Reports the results back to the delegate.
82 void ReportResult(const GURL& result);
83 // Helper to initialize valid extensions URLs vector.
84 void InitValidRedirectUrlPrefixes(const std::string& extension_id);
85 // Checks if |url| is a valid redirect URL for the extension.
86 bool IsValidRedirectUrl(const GURL& url) const;
87
88 Delegate* delegate_;
89 content::BrowserContext* browser_context_;
90 GURL provider_url_;
91 // List of valid redirect URL prefixes.
92 std::vector<std::string> valid_prefixes_;
93
94 content::WebContents* contents_;
95 views::Widget* widget_;
96 views::WebView* web_view_;
97
98 DISALLOW_COPY_AND_ASSIGN(ExtensionAuthFlow);
99 };
100
101 } // namespace extensions
102
103 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_EXTENSION_AUTH_FLOW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698