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