QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / ios / web / public / web_state / web_state_observer.h
blob6530bb85c6707a05de490d402aff82c8ad4351de
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 // Invoked when new favicon URL candidates are received.
80 virtual void FaviconUrlUpdated(const std::vector<FaviconURL>& candidates) {}
82 // Notifies the observer that the credential manager API was invoked from
83 // |source_url| to request a credential from the browser. If |suppress_ui|
84 // is true, the browser MUST NOT show any UI to the user. If this means that
85 // no credential will be returned to the page, so be it. Otherwise, the
86 // browser may show the user any UI that is necessary to get a Credential and
87 // return it to the page. |federations| specifies a list of acceptable
88 // federation providers. |user_interaction| indicates whether the API was
89 // invoked in response to a user interaction. Responses to the page should
90 // provide the specified |request_id|.
91 virtual void CredentialsRequested(int request_id,
92 const GURL& source_url,
93 bool suppress_ui,
94 const std::vector<std::string>& federations,
95 bool is_user_initiated) {}
97 // Notifies the observer that the credential manager API was invoked from
98 // |source_url| to notify the browser that the user signed in. |credential|
99 // specifies the credential that was used to sign in. Responses to the page
100 // should provide the specified |request_id|.
101 virtual void SignedIn(int request_id,
102 const GURL& source_url,
103 const web::Credential& credential) {}
105 // Notifies the observer that the credential manager API was invoked from
106 // |source_url| to notify the browser that the user signed in without
107 // specifying the credential that was used. Responses to the page should
108 // provide the specified |request_id|.
109 virtual void SignedIn(int request_id, const GURL& source_url) {}
111 // Notifies the observer that the credential manager API was invoked from
112 // |source_url| to notify the browser that the user signed out. Responses
113 // to the page should provide the specified |request_id|.
114 virtual void SignedOut(int request_id, const GURL& source_url) {}
116 // Notifies the observer that the credential manager API was invoked from
117 // |source_url| to notify the browser that the user failed to sign in.
118 // |credential| specifies the credential that failed to sign in. Responses
119 // to the page should provide the specified |request_id|.
120 virtual void SignInFailed(int request_id,
121 const GURL& source_url,
122 const web::Credential& credential) {}
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 without
126 // specifying the credential that failed. Responses to the page should provide
127 // the specified |request_id|.
128 virtual void SignInFailed(int request_id, const GURL& source_url) {}
130 // Invoked when the WebState is being destroyed. Gives subclasses a chance
131 // to cleanup.
132 virtual void WebStateDestroyed() {}
134 protected:
135 // Use this constructor when the object is tied to a single WebState for
136 // its entire lifetime.
137 explicit WebStateObserver(WebState* web_state);
139 // Use this constructor when the object wants to observe a WebState for
140 // part of its lifetime. It can then call Observe() to start and stop
141 // observing.
142 WebStateObserver();
144 virtual ~WebStateObserver();
146 // Start observing a different WebState; used with the default constructor.
147 void Observe(WebState* web_state);
149 private:
150 friend class WebStateImpl;
152 // Stops observing the current web state.
153 void ResetWebState();
155 WebState* web_state_;
157 DISALLOW_COPY_AND_ASSIGN(WebStateObserver);
160 } // namespace web
162 #endif // IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_OBSERVER_H_