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

Side by Side Diff: chrome/browser/extensions/api/identity/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_WEB_AUTH_FLOW_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_WEB_AUTH_FLOW_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_WEB_AUTH_FLOW_H_
7 7
8 #include "chrome/browser/ui/host_desktop.h" 8 #include <string>
9
10 #include "chrome/browser/extensions/shell_window_registry.h"
9 #include "content/public/browser/notification_observer.h" 11 #include "content/public/browser/notification_observer.h"
10 #include "content/public/browser/notification_registrar.h" 12 #include "content/public/browser/notification_registrar.h"
11 #include "content/public/browser/web_contents_observer.h" 13 #include "content/public/browser/web_contents_observer.h"
12 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
13 #include "ui/gfx/rect.h" 15 #include "ui/gfx/rect.h"
14 16
15 class Profile; 17 class Profile;
16 class WebAuthFlowTest; 18 class WebAuthFlowTest;
17 19
18 namespace content { 20 namespace content {
(...skipping 12 matching lines...) Expand all
31 // navigation reaches a known target URL. 33 // navigation reaches a known target URL.
32 // 34 //
33 // The WebContents is not displayed until the first page load 35 // The WebContents is not displayed until the first page load
34 // completes. This allows the flow to complete without flashing a 36 // completes. This allows the flow to complete without flashing a
35 // window on screen if the provider immediately redirects to the 37 // window on screen if the provider immediately redirects to the
36 // target URL. 38 // target URL.
37 // 39 //
38 // A WebAuthFlow can be started in Mode::SILENT, which never displays 40 // A WebAuthFlow can be started in Mode::SILENT, which never displays
39 // a window. If a window would be required, the flow fails. 41 // a window. If a window would be required, the flow fails.
40 class WebAuthFlow : public content::NotificationObserver, 42 class WebAuthFlow : public content::NotificationObserver,
41 public content::WebContentsObserver { 43 public content::WebContentsObserver,
44 public ShellWindowRegistry::Observer {
42 public: 45 public:
43 enum Mode { 46 enum Mode {
44 INTERACTIVE, // Show UI to the user if necessary. 47 INTERACTIVE, // Show UI to the user if necessary.
45 SILENT // No UI should be shown. 48 SILENT // No UI should be shown.
46 }; 49 };
47 50
48 enum Failure { 51 enum Failure {
49 WINDOW_CLOSED, // Window closed by user. 52 WINDOW_CLOSED, // Window closed by user.
50 INTERACTION_REQUIRED // Non-redirect page load in silent mode. 53 INTERACTION_REQUIRED, // Non-redirect page load in silent mode.
54 LOAD_FAILED // A page failed to load.
51 }; 55 };
52 56
57 // Clients of the WebAuthFlow implement this interface to learn the
58 // outcome of the flow.
53 class Delegate { 59 class Delegate {
54 public: 60 public:
55 // Called when the auth flow fails. This means that the flow did not result 61 // Called when the auth flow fails. This means that the flow did not result
56 // in a successful redirect to a valid redirect URL. 62 // in a successful redirect to a valid redirect URL.
57 virtual void OnAuthFlowFailure(Failure failure) = 0; 63 virtual void OnAuthFlowFailure(Failure failure) = 0;
58 // Called on redirects and other navigations to see if the URL should stop 64 // Called on redirects and other navigations to see if the URL should stop
59 // the flow. 65 // the flow.
60 virtual void OnAuthFlowURLChange(const GURL& redirect_url) = 0; 66 virtual void OnAuthFlowURLChange(const GURL& redirect_url) = 0;
67 // Called when the flow has been completely closed and it is safe to
68 // delete the object.
69 virtual void OnAuthFlowClosed() = 0;
61 70
62 protected: 71 protected:
63 virtual ~Delegate() {} 72 virtual ~Delegate() {}
64 }; 73 };
65 74
66 // Creates an instance with the given parameters. 75 // Creates an instance with the given parameters.
67 // Caller owns |delegate|. 76 // Caller owns |delegate|.
68 WebAuthFlow(Delegate* delegate, 77 WebAuthFlow(Delegate* delegate,
69 Profile* profile, 78 Profile* profile,
70 const GURL& provider_url, 79 const GURL& provider_url,
71 Mode mode, 80 Mode mode);
72 const gfx::Rect& initial_bounds,
73 chrome::HostDesktopType host_desktop_type);
74 virtual ~WebAuthFlow(); 81 virtual ~WebAuthFlow();
75 82
76 // Starts the flow. 83 // Starts the flow.
77 virtual void Start(); 84 virtual void Start();
78 85
79 protected: 86 // Stops the flow and closes the window. After this function returns, the
80 // Overridable for testing. 87 // delegate will not be called again, except for a final call to
81 virtual content::WebContents* CreateWebContents(); 88 // OnAuthFlowClosed.
82 virtual void ShowAuthFlowPopup(); 89 virtual void Close();
83 90
84 private: 91 private:
85 friend class ::WebAuthFlowTest; 92 friend class ::WebAuthFlowTest;
86 93
87 // NotificationObserver implementation. 94 // NotificationObserver implementation.
88 virtual void Observe(int type, 95 virtual void Observe(int type,
89 const content::NotificationSource& source, 96 const content::NotificationSource& source,
90 const content::NotificationDetails& details) OVERRIDE; 97 const content::NotificationDetails& details) OVERRIDE;
91 98
92 // WebContentsObserver implementation. 99 // WebContentsObserver implementation.
93 virtual void ProvisionalChangeToMainFrameUrl( 100 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
94 const GURL& url, 101 virtual void DidStartProvisionalLoadForFrame(
102 int64 frame_id,
103 int64 parent_frame_id,
104 bool is_main_frame,
105 const GURL& validated_url,
106 bool is_error_page,
107 bool is_iframe_srcdoc,
95 content::RenderViewHost* render_view_host) OVERRIDE; 108 content::RenderViewHost* render_view_host) OVERRIDE;
109 virtual void DidFailProvisionalLoad(
110 int64 frame_id,
111 bool is_main_frame,
112 const GURL& validated_url,
113 int error_code,
114 const string16& error_description,
115 content::RenderViewHost* render_view_host) OVERRIDE;
116 virtual void DidFailLoad(int64 frame_id,
117 const GURL& validated_url,
118 bool is_main_frame,
119 int error_code,
120 const string16& error_description,
121 content::RenderViewHost* render_view_host) OVERRIDE;
96 virtual void DidStopLoading( 122 virtual void DidStopLoading(
97 content::RenderViewHost* render_view_host) OVERRIDE; 123 content::RenderViewHost* render_view_host) OVERRIDE;
98 virtual void WebContentsDestroyed( 124
99 content::WebContents* web_contents) OVERRIDE; 125 // ShellWindowRegistry::Observer implementation.
126 virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE;
127 virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE {}
128 virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE;
100 129
101 void BeforeUrlLoaded(const GURL& url); 130 void BeforeUrlLoaded(const GURL& url);
102 void AfterUrlLoaded(); 131 void AfterUrlLoaded();
132 void DeferredClose();
103 133
104 Delegate* delegate_; 134 Delegate* delegate_;
135 bool closed_;
105 Profile* profile_; 136 Profile* profile_;
106 GURL provider_url_; 137 GURL provider_url_;
107 Mode mode_; 138 Mode mode_;
108 gfx::Rect initial_bounds_; 139 bool shell_window_loaded_;
109 chrome::HostDesktopType host_desktop_type_;
110 bool popup_shown_;
111 140
112 content::WebContents* contents_; 141 ShellWindow* shell_window_;
142 std::string shell_window_key_;
143
113 content::NotificationRegistrar registrar_; 144 content::NotificationRegistrar registrar_;
114 145
115 DISALLOW_COPY_AND_ASSIGN(WebAuthFlow); 146 DISALLOW_COPY_AND_ASSIGN(WebAuthFlow);
116 }; 147 };
117 148
118 } // namespace extensions 149 } // namespace extensions
119 150
120 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_WEB_AUTH_FLOW_H_ 151 #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