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_
11 #include "base/macros.h"
16 struct LoadCommittedDetails
;
20 enum class PageLoadCompletionStatus
: bool { SUCCESS
= 0, FAILURE
= 1 };
22 // An observer API implemented by classes which are interested in various page
23 // load events from WebState.
24 class WebStateObserver
{
26 // Key code associated to form events for which the key code is missing or
28 static int kInvalidFormKeyCode
;
30 // Returns the web state associated with this observer.
31 WebState
* web_state() const { return web_state_
; }
33 // This method is invoked when a new non-pending navigation item is created.
34 // This corresponds to one NavigationManager item being created
35 // (in the case of new navigations) or renavigated to (for back/forward
37 virtual void NavigationItemCommitted(
38 const LoadCommittedDetails
& load_details
) {}
40 // Called when the current page is loaded.
41 virtual void PageLoaded(PageLoadCompletionStatus load_completion_status
) {}
43 // Called when the interstitial is dismissed by the user.
44 virtual void InsterstitialDismissed() {}
46 // Called on URL hash change events.
47 virtual void URLHashChanged() {}
49 // Called on history state change events.
50 virtual void HistoryStateChanged() {}
52 // Called on form submission. |user_interaction| is true if the user
53 // interacted with the page.
54 virtual void DocumentSubmitted(const std::string
& form_name
,
55 bool user_interaction
) {}
57 // Called when the user is typing on a form field, with |error| indicating if
58 // there is any error when parsing the form field information.
59 // |key_code| may be kInvalidFormKeyCode if there is no key code.
60 virtual void FormActivityRegistered(const std::string
& form_name
,
61 const std::string
& field_name
,
62 const std::string
& type
,
63 const std::string
& value
,
67 // Invoked when new FaviconURL candidates are received.
68 virtual void FaviconURLUpdated(const std::vector
<FaviconURL
>& candidates
) {}
70 // Invoked when the WebState is being destroyed. Gives subclasses a chance
72 virtual void WebStateDestroyed() {}
75 // Use this constructor when the object is tied to a single WebState for
76 // its entire lifetime.
77 explicit WebStateObserver(WebState
* web_state
);
79 // Use this constructor when the object wants to observe a WebState for
80 // part of its lifetime. It can then call Observe() to start and stop
84 virtual ~WebStateObserver();
86 // Start observing a different WebState; used with the default constructor.
87 void Observe(WebState
* web_state
);
90 friend class WebStateImpl
;
92 // Stops observing the current web state.
97 DISALLOW_COPY_AND_ASSIGN(WebStateObserver
);
102 #endif // IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_OBSERVER_H_