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

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

Issue 14081014: Identity API: Change WebAuthFlow to use <webview> instead of a normal browser pop-up. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: chrome.identity side-by-side with chrome.experimental.identity Created 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_WEB_AUTH_FLOW_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_EXPERIMENTAL_WEB_AUTH_FLOW_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_WEB_AUTH_FLOW_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_EXPERIMENTAL_WEB_AUTH_FLOW_H_
7 7
8 #include "chrome/browser/ui/host_desktop.h" 8 #include "chrome/browser/ui/host_desktop.h"
9 #include "content/public/browser/notification_observer.h" 9 #include "content/public/browser/notification_observer.h"
10 #include "content/public/browser/notification_registrar.h" 10 #include "content/public/browser/notification_registrar.h"
11 #include "content/public/browser/web_contents_observer.h" 11 #include "content/public/browser/web_contents_observer.h"
12 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
13 #include "ui/gfx/rect.h" 13 #include "ui/gfx/rect.h"
14 14
15 class Profile; 15 class Profile;
16 class WebAuthFlowTest; 16 class ExperimentalWebAuthFlowTest;
17 17
18 namespace content { 18 namespace content {
19 class NotificationDetails; 19 class NotificationDetails;
20 class NotificationSource; 20 class NotificationSource;
21 class RenderViewHost; 21 class RenderViewHost;
22 class WebContents; 22 class WebContents;
23 } 23 }
24 24
25 namespace extensions { 25 namespace extensions {
26 26
27 // Controller class for web based auth flows. The WebAuthFlow starts 27 // Controller class for web based auth flows. The
28 // by navigating a WebContents to a URL specificed by the caller. Any 28 // ExperimentalWebAuthFlow starts by navigating a WebContents to a URL
29 // time the WebContents navigates to a new URL, the flow's delegate is 29 // specificed by the caller. Any time the WebContents navigates to a
30 // notified. The delegate is expected to delete the flow when 30 // new URL, the flow's delegate is notified. The delegate is expected
31 // navigation reaches a known target URL. 31 // to delete the flow when navigation reaches a known target URL.
32 // 32 //
33 // The WebContents is not displayed until the first page load 33 // The WebContents is not displayed until the first page load
34 // completes. This allows the flow to complete without flashing a 34 // completes. This allows the flow to complete without flashing a
35 // window on screen if the provider immediately redirects to the 35 // window on screen if the provider immediately redirects to the
36 // target URL. 36 // target URL.
37 // 37 //
38 // A WebAuthFlow can be started in Mode::SILENT, which never displays 38 // A ExperimentalWebAuthFlow can be started in Mode::SILENT, which
39 // a window. If a window would be required, the flow fails. 39 // never displays a window. If a window would be required, the flow
40 class WebAuthFlow : public content::NotificationObserver, 40 // fails.
41 class ExperimentalWebAuthFlow : public content::NotificationObserver,
41 public content::WebContentsObserver { 42 public content::WebContentsObserver {
42 public: 43 public:
43 enum Mode { 44 enum Mode {
44 INTERACTIVE, // Show UI to the user if necessary. 45 INTERACTIVE, // Show UI to the user if necessary.
45 SILENT // No UI should be shown. 46 SILENT // No UI should be shown.
46 }; 47 };
47 48
48 enum Failure { 49 enum Failure {
49 WINDOW_CLOSED, // Window closed by user. 50 WINDOW_CLOSED, // Window closed by user.
50 INTERACTION_REQUIRED // Non-redirect page load in silent mode. 51 INTERACTION_REQUIRED // Non-redirect page load in silent mode.
51 }; 52 };
52 53
53 class Delegate { 54 class Delegate {
54 public: 55 public:
55 // Called when the auth flow fails. This means that the flow did not result 56 // Called when the auth flow fails. This means that the flow did not result
56 // in a successful redirect to a valid redirect URL. 57 // in a successful redirect to a valid redirect URL.
57 virtual void OnAuthFlowFailure(Failure failure) = 0; 58 virtual void OnAuthFlowFailure(Failure failure) = 0;
58 // Called on redirects and other navigations to see if the URL should stop 59 // Called on redirects and other navigations to see if the URL should stop
59 // the flow. 60 // the flow.
60 virtual void OnAuthFlowURLChange(const GURL& redirect_url) = 0; 61 virtual void OnAuthFlowURLChange(const GURL& redirect_url) = 0;
61 62
62 protected: 63 protected:
63 virtual ~Delegate() {} 64 virtual ~Delegate() {}
64 }; 65 };
65 66
66 // Creates an instance with the given parameters. 67 // Creates an instance with the given parameters.
67 // Caller owns |delegate|. 68 // Caller owns |delegate|.
68 WebAuthFlow(Delegate* delegate, 69 ExperimentalWebAuthFlow(Delegate* delegate,
69 Profile* profile, 70 Profile* profile,
70 const GURL& provider_url, 71 const GURL& provider_url,
71 Mode mode, 72 Mode mode,
72 const gfx::Rect& initial_bounds, 73 const gfx::Rect& initial_bounds,
73 chrome::HostDesktopType host_desktop_type); 74 chrome::HostDesktopType host_desktop_type);
74 virtual ~WebAuthFlow(); 75 virtual ~ExperimentalWebAuthFlow();
75 76
76 // Starts the flow. 77 // Starts the flow.
77 virtual void Start(); 78 virtual void Start();
78 79
79 protected: 80 protected:
80 // Overridable for testing. 81 // Overridable for testing.
81 virtual content::WebContents* CreateWebContents(); 82 virtual content::WebContents* CreateWebContents();
82 virtual void ShowAuthFlowPopup(); 83 virtual void ShowAuthFlowPopup();
83 84
84 private: 85 private:
85 friend class ::WebAuthFlowTest; 86 friend class ::ExperimentalWebAuthFlowTest;
86 87
87 // NotificationObserver implementation. 88 // NotificationObserver implementation.
88 virtual void Observe(int type, 89 virtual void Observe(int type,
89 const content::NotificationSource& source, 90 const content::NotificationSource& source,
90 const content::NotificationDetails& details) OVERRIDE; 91 const content::NotificationDetails& details) OVERRIDE;
91 92
92 // WebContentsObserver implementation. 93 // WebContentsObserver implementation.
93 virtual void ProvisionalChangeToMainFrameUrl( 94 virtual void ProvisionalChangeToMainFrameUrl(
94 const GURL& url, 95 const GURL& url,
95 content::RenderViewHost* render_view_host) OVERRIDE; 96 content::RenderViewHost* render_view_host) OVERRIDE;
96 virtual void DidStopLoading( 97 virtual void DidStopLoading(
97 content::RenderViewHost* render_view_host) OVERRIDE; 98 content::RenderViewHost* render_view_host) OVERRIDE;
98 virtual void WebContentsDestroyed( 99 virtual void WebContentsDestroyed(
99 content::WebContents* web_contents) OVERRIDE; 100 content::WebContents* web_contents) OVERRIDE;
100 101
101 void BeforeUrlLoaded(const GURL& url); 102 void BeforeUrlLoaded(const GURL& url);
102 void AfterUrlLoaded(); 103 void AfterUrlLoaded();
103 104
104 Delegate* delegate_; 105 Delegate* delegate_;
105 Profile* profile_; 106 Profile* profile_;
106 GURL provider_url_; 107 GURL provider_url_;
107 Mode mode_; 108 Mode mode_;
108 gfx::Rect initial_bounds_; 109 gfx::Rect initial_bounds_;
109 chrome::HostDesktopType host_desktop_type_; 110 chrome::HostDesktopType host_desktop_type_;
110 bool popup_shown_; 111 bool popup_shown_;
111 112
112 content::WebContents* contents_; 113 content::WebContents* contents_;
113 content::NotificationRegistrar registrar_; 114 content::NotificationRegistrar registrar_;
114 115
115 DISALLOW_COPY_AND_ASSIGN(WebAuthFlow); 116 DISALLOW_COPY_AND_ASSIGN(ExperimentalWebAuthFlow);
116 }; 117 };
117 118
118 } // namespace extensions 119 } // namespace extensions
119 120
120 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_WEB_AUTH_FLOW_H_ 121 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_EXPERIMENTAL_WEB_AUTH_FLOW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698