OLD | NEW |
---|---|
(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" | |
13 #include "content/public/browser/web_contents.h" | |
Mihai Parparita -not on Chrome
2012/05/04 22:37:18
Seems like you can just forward-declare WebContent
Munjal (Google)
2012/05/08 19:26:35
Done. I started out using scoped_ptr (which I thin
| |
14 #include "content/public/browser/web_contents_delegate.h" | |
15 #include "googleurl/src/gurl.h" | |
16 #include "ui/views/controls/webview/webview.h" | |
Mihai Parparita -not on Chrome
2012/05/04 22:37:18
Ditto for WebView and Widget.
Mihai Parparita -not on Chrome
2012/05/04 22:37:18
Also, this is views-only code, so you'll need to h
Munjal (Google)
2012/05/08 19:26:35
Done.
Munjal (Google)
2012/05/08 19:26:35
I didn't realize I am using Windows / ChromeOS spe
| |
17 #include "ui/views/widget/widget.h" | |
18 #include "ui/views/widget/widget_delegate.h" | |
19 | |
20 namespace content { | |
21 class BrowserContext; | |
22 } | |
23 | |
24 namespace extensions { | |
25 | |
26 // Controller class to perform an auth flow with a provider. | |
27 // This is the class to start the auth flow and it takes care of all the | |
28 // details. It behaves the following way: | |
29 // Given a provider URL, load the URL and perform usual web navigation | |
Mihai Parparita -not on Chrome
2012/05/04 22:37:18
To make this clearer, perhaps mention that the pro
Munjal (Google)
2012/05/08 19:26:35
Actually I added a TODo to add a link to the desig
| |
30 // until it results in redirection to a valid extension redirect URL. | |
31 // The provider can show a web page to the user if needed before redirecting | |
32 // to an appropriate URL. | |
33 class ExtensionAuthFlow : public content::WebContentsDelegate, | |
Mihai Parparita -not on Chrome
2012/05/04 22:37:18
"ExtensionAuthFlow" isn't that descriptive. Generi
Munjal (Google)
2012/05/08 19:26:35
How about WebAuthFlow?
Mihai Parparita -not on Chrome
2012/05/08 21:33:30
Sounds good.
| |
34 public views::WidgetDelegate { | |
35 public: | |
36 class Delegate { | |
37 public: | |
38 // Called when the auth flow is completed successfully. | |
39 // |redirect_url| is the full URL the provider redirected to at the end | |
40 // of the flow. | |
41 virtual void OnAuthFlowCompleted(const std::string& redirect_url) = 0; | |
42 // Called when the auth flow fails. This means that the flow did not result | |
43 // in a successful redirect to a valid redirect URL or the user canceled | |
44 // the flow. | |
45 virtual void OnAuthFlowFailed() = 0; | |
46 }; | |
47 | |
48 // Creates an instance with the given parameters. | |
49 ExtensionAuthFlow(Delegate* delegate, | |
50 content::BrowserContext* browser_context, | |
51 const std::string& extension_id, | |
52 const GURL& provider_url); | |
53 ~ExtensionAuthFlow(); | |
54 | |
55 // Starts the flow. | |
56 // Delegate will be called when the flow is done. | |
57 void Start(); | |
58 | |
59 private: | |
60 // WebContentsDelegate implementation. | |
61 virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; | |
62 virtual void NavigationStateChanged( | |
63 const content::WebContents* source, unsigned changed_flags) OVERRIDE; | |
64 | |
65 // WidgetDelegate implementation. | |
66 virtual views::View* GetContentsView() OVERRIDE; | |
67 virtual views::Widget* GetWidget() OVERRIDE; | |
68 virtual const views::Widget* GetWidget() const OVERRIDE; | |
69 virtual views::View* GetInitiallyFocusedView() OVERRIDE; | |
70 virtual void DeleteDelegate() OVERRIDE; | |
71 | |
72 void OnUrlLoaded(); | |
73 // Reports the results back to the delegate. | |
74 void ReportResult(); | |
75 // Checks if |url| is a valid redirect URL for the extension. | |
76 bool IsValidExtensionRedirectUrl(const GURL& url) const; | |
77 | |
78 Delegate* delegate_; | |
Avi (use Gerrit)
2012/05/07 23:31:13
What is the ownership story here? Make sure to use
Munjal (Google)
2012/05/08 19:26:35
Caller owns it. Added comment to the constructor (
| |
79 content::BrowserContext* browser_context_; | |
80 GURL provider_url_; | |
81 std::string extension_id_; | |
82 GURL result_; | |
83 // List of valid redirect URL prefixes. | |
84 std::vector<std::string> valid_prefixes_; | |
85 | |
86 content::WebContents* contents_; | |
87 views::Widget* widget_; | |
88 views::WebView* web_view_; | |
89 | |
90 DISALLOW_COPY_AND_ASSIGN(ExtensionAuthFlow); | |
91 }; | |
92 | |
93 } // namespace extensions | |
94 | |
95 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_EXTENSION_AUTH_FLOW_H_ | |
OLD | NEW |