Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / ios / web / public / web_state / web_state_observer.h
blob519e5b6f47fe7a238b86803cea4c9fc0a60b60bf
1 // Copyright 2014 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 IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_OBSERVER_H_
6 #define IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_OBSERVER_H_
8 #include <string>
9 #include <vector>
11 #include "base/macros.h"
13 class GURL;
15 namespace web {
17 struct Credential;
18 struct FaviconURL;
19 struct LoadCommittedDetails;
20 class WebState;
21 class WebStateImpl;
23 enum class PageLoadCompletionStatus : bool { SUCCESS = 0, FAILURE = 1 };
25 // An observer API implemented by classes which are interested in various page
26 // load events from WebState.
27 class WebStateObserver {
28 public:
29 // Key code associated to form events for which the key code is missing or
30 // irrelevant.
31 static int kInvalidFormKeyCode;
33 // Returns the web state associated with this observer.
34 WebState* web_state() const { return web_state_; }
36 // This method is invoked when a load request is registered.
37 virtual void ProvisionalNavigationStarted(const GURL& url) {}
39 // This method is invoked when a new non-pending navigation item is created.
40 // This corresponds to one NavigationManager item being created
41 // (in the case of new navigations) or renavigated to (for back/forward
42 // navigations).
43 virtual void NavigationItemCommitted(
44 const LoadCommittedDetails& load_details) {}
46 // Called when the current page has started loading.
47 virtual void DidStartLoading() {}
49 // Called when the current page has stopped loading.
50 virtual void DidStopLoading() {}
52 // Called when the current page is loaded.
53 virtual void PageLoaded(PageLoadCompletionStatus load_completion_status) {}
55 // Called when the interstitial is dismissed by the user.
56 virtual void InsterstitialDismissed() {}
58 // Called on URL hash change events.
59 virtual void UrlHashChanged() {}
61 // Called on history state change events.
62 virtual void HistoryStateChanged() {}
64 // Called on form submission. |user_initiated| is true if the user
65 // interacted with the page.
66 virtual void DocumentSubmitted(const std::string& form_name,
67 bool user_initiated) {}
69 // Called when the user is typing on a form field, with |error| indicating if
70 // there is any error when parsing the form field information.
71 // |key_code| may be kInvalidFormKeyCode if there is no key code.
72 virtual void FormActivityRegistered(const std::string& form_name,
73 const std::string& field_name,
74 const std::string& type,
75 const std::string& value,
76 int key_code,
77 bool input_missing) {}
79 // Notifies the observer that the requestAutocomplete API was invoked from
80 // |source_url| for the form with the specified |form_name|.
81 // |user_initiated| indicates whether the API was invoked in response to a
82 // user interaction.
83 virtual void AutocompleteRequested(const GURL& source_url,
84 const std::string& form_name,
85 bool user_initiated) {}
87 // Invoked when new favicon URL candidates are received.
88 virtual void FaviconUrlUpdated(const std::vector<FaviconURL>& candidates) {}
90 // Notifies the observer that the credential manager API was invoked from
91 // |source_url| to request a credential from the browser. If |suppress_ui|
92 // is true, the browser MUST NOT show any UI to the user. If this means that
93 // no credential will be returned to the page, so be it. Otherwise, the
94 // browser may show the user any UI that is necessary to get a Credential and
95 // return it to the page. |federations| specifies a list of acceptable
96 // federation providers. |user_interaction| indicates whether the API was
97 // invoked in response to a user interaction. Responses to the page should
98 // provide the specified |request_id|.
99 virtual void CredentialsRequested(int request_id,
100 const GURL& source_url,
101 bool suppress_ui,
102 const std::vector<std::string>& federations,
103 bool is_user_initiated) {}
105 // Notifies the observer that the credential manager API was invoked from
106 // |source_url| to notify the browser that the user signed in. |credential|
107 // specifies the credential that was used to sign in. Responses to the page
108 // should provide the specified |request_id|.
109 virtual void SignedIn(int request_id,
110 const GURL& source_url,
111 const web::Credential& credential) {}
113 // Notifies the observer that the credential manager API was invoked from
114 // |source_url| to notify the browser that the user signed in without
115 // specifying the credential that was used. Responses to the page should
116 // provide the specified |request_id|.
117 virtual void SignedIn(int request_id, const GURL& source_url) {}
119 // Notifies the observer that the credential manager API was invoked from
120 // |source_url| to notify the browser that the user signed out. Responses
121 // to the page should provide the specified |request_id|.
122 virtual void SignedOut(int request_id, const GURL& source_url) {}
124 // Notifies the observer that the credential manager API was invoked from
125 // |source_url| to notify the browser that the user failed to sign in.
126 // |credential| specifies the credential that failed to sign in. Responses
127 // to the page should provide the specified |request_id|.
128 virtual void SignInFailed(int request_id,
129 const GURL& source_url,
130 const web::Credential& credential) {}
132 // Notifies the observer that the credential manager API was invoked from
133 // |source_url| to notify the browser that the user failed to sign in without
134 // specifying the credential that failed. Responses to the page should provide
135 // the specified |request_id|.
136 virtual void SignInFailed(int request_id, const GURL& source_url) {}
138 // Invoked when the WebState is being destroyed. Gives subclasses a chance
139 // to cleanup.
140 virtual void WebStateDestroyed() {}
142 protected:
143 // Use this constructor when the object is tied to a single WebState for
144 // its entire lifetime.
145 explicit WebStateObserver(WebState* web_state);
147 // Use this constructor when the object wants to observe a WebState for
148 // part of its lifetime. It can then call Observe() to start and stop
149 // observing.
150 WebStateObserver();
152 virtual ~WebStateObserver();
154 // Start observing a different WebState; used with the default constructor.
155 void Observe(WebState* web_state);
157 private:
158 friend class WebStateImpl;
160 // Stops observing the current web state.
161 void ResetWebState();
163 WebState* web_state_;
165 DISALLOW_COPY_AND_ASSIGN(WebStateObserver);
168 } // namespace web
170 #endif // IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_OBSERVER_H_