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

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

Issue 15897006: Identity API: switch WebAuthFlow dialog to component app (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase to ToT Created 7 years, 6 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 {
19 class NotificationDetails; 21 class NotificationDetails;
20 class NotificationSource; 22 class NotificationSource;
21 class RenderViewHost; 23 class RenderViewHost;
22 class WebContents; 24 class WebContents;
23 } 25 }
24 26
25 namespace extensions { 27 namespace extensions {
26 28
27 // Controller class for web based auth flows. The WebAuthFlow starts 29 // Controller class for web based auth flows. The WebAuthFlow creates
28 // by navigating a WebContents to a URL specificed by the caller. Any 30 // a dialog window in the scope approval component app by firing an
29 // time the WebContents navigates to a new URL, the flow's delegate is 31 // event. A webview embedded in the dialog will navigate to the
30 // notified. The delegate is expected to delete the flow when 32 // |provider_url| passed to the WebAuthFlow constructor.
31 // navigation reaches a known target URL.
32 // 33 //
33 // The WebContents is not displayed until the first page load 34 // The WebAuthFlow monitors the WebContents of the webview, and
35 // notifies its delegate interface any time the WebContents navigates
36 // to a new URL or changes title. The delegate is expected to delete
37 // the flow when navigation reaches a known target location.
38 //
39 // The window is not displayed until the first page load
34 // completes. This allows the flow to complete without flashing a 40 // completes. This allows the flow to complete without flashing a
35 // window on screen if the provider immediately redirects to the 41 // window on screen if the provider immediately redirects to the
36 // target URL. 42 // target URL.
37 // 43 //
38 // A WebAuthFlow can be started in Mode::SILENT, which never displays 44 // A WebAuthFlow can be started in Mode::SILENT, which never displays
39 // a window. If a window would be required, the flow fails. 45 // a window. If a window would be required, the flow fails.
40 class WebAuthFlow : public content::NotificationObserver, 46 class WebAuthFlow : public content::NotificationObserver,
41 public content::WebContentsObserver { 47 public content::WebContentsObserver,
48 public ShellWindowRegistry::Observer {
42 public: 49 public:
43 enum Mode { 50 enum Mode {
44 INTERACTIVE, // Show UI to the user if necessary. 51 INTERACTIVE, // Show UI to the user if necessary.
45 SILENT // No UI should be shown. 52 SILENT // No UI should be shown.
46 }; 53 };
47 54
48 enum Failure { 55 enum Failure {
49 WINDOW_CLOSED, // Window closed by user. 56 WINDOW_CLOSED, // Window closed by user.
50 INTERACTION_REQUIRED // Non-redirect page load in silent mode. 57 INTERACTION_REQUIRED, // Non-redirect page load in silent mode.
58 LOAD_FAILED
51 }; 59 };
52 60
53 class Delegate { 61 class Delegate {
54 public: 62 public:
55 // Called when the auth flow fails. This means that the flow did not result 63 // Called when the auth flow fails. This means that the flow did not result
56 // in a successful redirect to a valid redirect URL. 64 // in a successful redirect to a valid redirect URL.
57 virtual void OnAuthFlowFailure(Failure failure) = 0; 65 virtual void OnAuthFlowFailure(Failure failure) = 0;
58 // Called on redirects and other navigations to see if the URL should stop 66 // Called on redirects and other navigations to see if the URL should stop
59 // the flow. 67 // the flow.
60 virtual void OnAuthFlowURLChange(const GURL& redirect_url) = 0; 68 virtual void OnAuthFlowURLChange(const GURL& redirect_url) = 0;
61 // Called when the title of the current page changes. 69 // Called when the title of the current page changes.
62 virtual void OnAuthFlowTitleChange(const std::string& title) = 0; 70 virtual void OnAuthFlowTitleChange(const std::string& title) = 0;
63 71
64 protected: 72 protected:
65 virtual ~Delegate() {} 73 virtual ~Delegate() {}
66 }; 74 };
67 75
68 // Creates an instance with the given parameters. 76 // Creates an instance with the given parameters.
69 // Caller owns |delegate|. 77 // Caller owns |delegate|.
70 WebAuthFlow(Delegate* delegate, 78 WebAuthFlow(Delegate* delegate,
71 Profile* profile, 79 Profile* profile,
72 const GURL& provider_url, 80 const GURL& provider_url,
73 Mode mode, 81 Mode mode);
74 const gfx::Rect& initial_bounds,
75 chrome::HostDesktopType host_desktop_type);
76 82
77 virtual ~WebAuthFlow(); 83 virtual ~WebAuthFlow();
78 84
79 // Starts the flow. 85 // Starts the flow.
80 virtual void Start(); 86 virtual void Start();
81 87
82 // Prevents further calls to the delegate and deletes the flow. 88 // Prevents further calls to the delegate and deletes the flow.
83 void DetachDelegateAndDelete(); 89 void DetachDelegateAndDelete();
84 90
85 protected:
86 // Overridable for testing.
87 virtual content::WebContents* CreateWebContents();
88 virtual void ShowAuthFlowPopup();
89
90 private: 91 private:
91 friend class ::WebAuthFlowTest; 92 friend class ::WebAuthFlowTest;
92 93
94 // ShellWindowRegistry::Observer implementation.
95 virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE;
96 virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE {}
97 virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE;
98
93 // NotificationObserver implementation. 99 // NotificationObserver implementation.
94 virtual void Observe(int type, 100 virtual void Observe(int type,
95 const content::NotificationSource& source, 101 const content::NotificationSource& source,
96 const content::NotificationDetails& details) OVERRIDE; 102 const content::NotificationDetails& details) OVERRIDE;
97 103
98 // WebContentsObserver implementation. 104 // WebContentsObserver implementation.
99 virtual void ProvisionalChangeToMainFrameUrl( 105 virtual void DidStopLoading(content::RenderViewHost* render_view_host)
100 const GURL& url, 106 OVERRIDE;
107 virtual void DidNavigateMainFrame(
108 const content::LoadCommittedDetails& details,
109 const content::FrameNavigateParams& params) OVERRIDE;
110 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
111 virtual void DidStartProvisionalLoadForFrame(
112 int64 frame_id,
113 int64 parent_frame_id,
114 bool is_main_frame,
115 const GURL& validated_url,
116 bool is_error_page,
117 bool is_iframe_srcdoc,
101 content::RenderViewHost* render_view_host) OVERRIDE; 118 content::RenderViewHost* render_view_host) OVERRIDE;
102 virtual void DidStopLoading( 119 virtual void DidFailProvisionalLoad(int64 frame_id,
103 content::RenderViewHost* render_view_host) OVERRIDE; 120 bool is_main_frame,
104 virtual void WebContentsDestroyed( 121 const GURL& validated_url,
105 content::WebContents* web_contents) OVERRIDE; 122 int error_code,
123 const string16& error_description,
124 content::RenderViewHost* render_view_host)
125 OVERRIDE;
106 126
107 void BeforeUrlLoaded(const GURL& url); 127 void BeforeUrlLoaded(const GURL& url);
108 void AfterUrlLoaded(); 128 void AfterUrlLoaded();
109 129
110 Delegate* delegate_; 130 Delegate* delegate_;
111 Profile* profile_; 131 Profile* profile_;
112 GURL provider_url_; 132 GURL provider_url_;
113 Mode mode_; 133 Mode mode_;
114 gfx::Rect initial_bounds_;
115 chrome::HostDesktopType host_desktop_type_;
116 bool popup_shown_;
117 134
118 content::WebContents* contents_; 135 ShellWindow* shell_window_;
136 std::string shell_window_key_;
137 bool embedded_window_created_;
138
119 content::NotificationRegistrar registrar_; 139 content::NotificationRegistrar registrar_;
120 140
121 DISALLOW_COPY_AND_ASSIGN(WebAuthFlow); 141 DISALLOW_COPY_AND_ASSIGN(WebAuthFlow);
122 }; 142 };
123 143
124 } // namespace extensions 144 } // namespace extensions
125 145
126 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_WEB_AUTH_FLOW_H_ 146 #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