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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_EXPERIMENTAL_WEB_AUTH_FLOW_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_EXPERIMENTAL_WEB_AUTH_FLOW_H_
8 #include "chrome/browser/ui/host_desktop.h"
9 #include "content/public/browser/notification_observer.h"
10 #include "content/public/browser/notification_registrar.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "ui/gfx/rect.h"
16 class ExperimentalWebAuthFlowTest;
19 class NotificationDetails;
20 class NotificationSource;
25 namespace extensions {
27 // Controller class for web based auth flows. The
28 // ExperimentalWebAuthFlow starts by navigating a WebContents to a URL
29 // specificed by the caller. Any time the WebContents navigates to a
30 // new URL, the flow's delegate is notified. The delegate is expected
31 // to delete the flow when navigation reaches a known target URL.
33 // The WebContents is not displayed until the first page load
34 // completes. This allows the flow to complete without flashing a
35 // window on screen if the provider immediately redirects to the
38 // A ExperimentalWebAuthFlow can be started in Mode::SILENT, which
39 // never displays a window. If a window would be required, the flow
41 class ExperimentalWebAuthFlow : public content::NotificationObserver,
42 public content::WebContentsObserver {
45 INTERACTIVE, // Show UI to the user if necessary.
46 SILENT // No UI should be shown.
50 WINDOW_CLOSED, // Window closed by user.
51 INTERACTION_REQUIRED // Non-redirect page load in silent mode.
56 // Called when the auth flow fails. This means that the flow did not result
57 // in a successful redirect to a valid redirect URL.
58 virtual void OnAuthFlowFailure(Failure failure) = 0;
59 // Called on redirects and other navigations to see if the URL should stop
61 virtual void OnAuthFlowURLChange(const GURL& redirect_url) = 0;
64 virtual ~Delegate() {}
67 // Creates an instance with the given parameters.
68 // Caller owns |delegate|.
69 ExperimentalWebAuthFlow(Delegate* delegate,
71 const GURL& provider_url,
73 const gfx::Rect& initial_bounds,
74 chrome::HostDesktopType host_desktop_type);
75 virtual ~ExperimentalWebAuthFlow();
80 // Prevents further calls to the delegate and deletes the flow.
81 void DetachDelegateAndDelete();
84 // Overridable for testing.
85 virtual content::WebContents* CreateWebContents();
86 virtual void ShowAuthFlowPopup();
89 friend class ::ExperimentalWebAuthFlowTest;
91 // NotificationObserver implementation.
92 virtual void Observe(int type,
93 const content::NotificationSource& source,
94 const content::NotificationDetails& details) OVERRIDE;
96 // WebContentsObserver implementation.
97 virtual void ProvisionalChangeToMainFrameUrl(
99 content::RenderViewHost* render_view_host) OVERRIDE;
100 virtual void DidStopLoading(
101 content::RenderViewHost* render_view_host) OVERRIDE;
102 virtual void WebContentsDestroyed(
103 content::WebContents* web_contents) OVERRIDE;
105 void BeforeUrlLoaded(const GURL& url);
106 void AfterUrlLoaded();
112 gfx::Rect initial_bounds_;
113 chrome::HostDesktopType host_desktop_type_;
116 content::WebContents* contents_;
117 content::NotificationRegistrar registrar_;
119 DISALLOW_COPY_AND_ASSIGN(ExperimentalWebAuthFlow);
122 } // namespace extensions
124 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_EXPERIMENTAL_WEB_AUTH_FLOW_H_