1 // Copyright 2015 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_BRIDGE_H_
6 #define IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_OBSERVER_BRIDGE_H_
8 #import <Foundation/Foundation.h>
12 #import "base/ios/weak_nsobject.h"
13 #import "ios/web/public/web_state/web_state_observer.h"
17 // Observes page lifecyle events from Objective-C. To use as a
18 // web::WebStateObserver, wrap in a web::WebStateObserverBridge.
19 @protocol CRWWebStateObserver
<NSObject
>
22 // Invoked by WebStateObserverBridge::ProvisionalNavigationStarted.
23 - (void)webState
:(web::WebState
*)webState
24 didStartProvisionalNavigationForURL
:(const GURL
&)URL
;
26 // Invoked by WebStateObserverBridge::NavigationItemCommitted.
27 - (void)webState
:(web::WebState
*)webState
28 didCommitNavigationWithDetails
:
29 (const web::LoadCommittedDetails
&)load_details
;
31 // Invoked by WebStateObserverBridge::PageLoaded.
32 - (void)webStateDidLoadPage
:(web::WebState
*)webState
;
34 // Invoked by WebStateObserverBridge::InterstitialDismissed.
35 - (void)webStateDidDismissInterstitial
:(web::WebState
*)webState
;
37 // Invoked by WebStateObserverBridge::UrlHashChanged.
38 - (void)webStateDidChangeURLHash
:(web::WebState
*)webState
;
40 // Invoked by WebStateObserverBridge::HistoryStateChanged.
41 - (void)webStateDidChangeHistoryState
:(web::WebState
*)webState
;
43 // Invoked by WebStateObserverBridge::DocumentSubmitted.
44 - (void)webState
:(web::WebState
*)webState
45 didSubmitDocumentWithFormNamed
:(const std::string
&)formName
46 userInitiated
:(BOOL
)userInitiated
;
48 // Invoked by WebStateObserverBridge::FormActivityRegistered.
49 // TODO(ios): Method should take data transfer object rather than parameters.
50 - (void)webState
:(web::WebState
*)webState
51 didRegisterFormActivityWithFormNamed
:(const std::string
&)formName
52 fieldName
:(const std::string
&)fieldName
53 type
:(const std::string
&)type
54 value
:(const std::string
&)value
56 inputMissing
:(BOOL
)inputMissing
;
58 // Invoked by WebStateObserverBridge::FaviconUrlUpdated.
59 - (void)webState
:(web::WebState
*)webState
60 didUpdateFaviconURLCandidates
:
61 (const std::vector
<web::FaviconURL
>&)candidates
;
63 // Note: after |webStateDestroyed:| is invoked, the WebState being observed
64 // is no longer valid.
65 - (void)webStateDestroyed
:(web::WebState
*)webState
;
67 // Invoked by WebStateObserverBridge::DidStopLoading.
68 - (void)webStateDidStopLoading
:(web::WebState
*)webState
;
70 // Invoked by WebStateObserverBridge::DidStartLoading.
71 - (void)webStateDidStartLoading
:(web::WebState
*)webState
;
79 // Bridge to use an id<CRWWebStateObserver> as a web::WebStateObserver.
80 // Will be added/removed as an observer of the underlying WebState during
81 // construction/destruction. Instances should be owned by instances of the
82 // class they're bridging.
83 class WebStateObserverBridge
: public web::WebStateObserver
{
85 WebStateObserverBridge(web::WebState
* web_state
,
86 id
<CRWWebStateObserver
> observer
);
87 ~WebStateObserverBridge() override
;
89 // web::WebStateObserver methods.
90 void ProvisionalNavigationStarted(const GURL
& url
) override
;
91 void NavigationItemCommitted(
92 const LoadCommittedDetails
& load_details
) override
;
94 web::PageLoadCompletionStatus load_completion_status
) override
;
95 void InsterstitialDismissed() override
;
96 void UrlHashChanged() override
;
97 void HistoryStateChanged() override
;
98 void DocumentSubmitted(const std::string
& form_name
,
99 bool user_initiated
) override
;
100 void FormActivityRegistered(const std::string
& form_name
,
101 const std::string
& field_name
,
102 const std::string
& type
,
103 const std::string
& value
,
105 bool input_missing
) override
;
106 void FaviconUrlUpdated(const std::vector
<FaviconURL
>& candidates
) override
;
107 void WebStateDestroyed() override
;
108 void DidStartLoading() override
;
109 void DidStopLoading() override
;
112 base::WeakNSProtocol
<id
<CRWWebStateObserver
>> observer_
;
113 DISALLOW_COPY_AND_ASSIGN(WebStateObserverBridge
);
118 #endif // IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_OBSERVER_BRIDGE_H_