Fix breakages in https://codereview.chromium.org/1155713003/
[chromium-blink-merge.git] / ios / web / web_state / web_state_observer_bridge.mm
blobfe1f6dbf258c95de3b0640ab87f5e0c45e90a6fd
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 #import "ios/web/public/web_state/web_state_observer_bridge.h"
7 namespace web {
9 WebStateObserverBridge::WebStateObserverBridge(web::WebState* webState,
10                                                id<CRWWebStateObserver> observer)
11     : web::WebStateObserver(webState), observer_(observer) {
14 WebStateObserverBridge::~WebStateObserverBridge() {
17 void WebStateObserverBridge::ProvisionalNavigationStarted(const GURL& url) {
18   SEL selector = @selector(webState:didStartProvisionalNavigationForURL:);
19   if ([observer_ respondsToSelector:selector]) {
20     [observer_ webState:web_state() didStartProvisionalNavigationForURL:url];
21   }
24 void WebStateObserverBridge::NavigationItemCommitted(
25     const web::LoadCommittedDetails& load_detatils) {
26   SEL selector = @selector(webState:didCommitNavigationWithDetails:);
27   if ([observer_ respondsToSelector:selector]) {
28     [observer_ webState:web_state()
29         didCommitNavigationWithDetails:load_detatils];
30   }
33 void WebStateObserverBridge::DidStartLoading() {
34   SEL selector = @selector(webStateDidStartLoading:);
35   if ([observer_ respondsToSelector:selector]) {
36     [observer_ webStateDidStartLoading:web_state()];
37   }
40 void WebStateObserverBridge::DidStopLoading() {
41   SEL selector = @selector(webStateDidStopLoading:);
42   if ([observer_ respondsToSelector:selector]) {
43     [observer_ webStateDidStopLoading:web_state()];
44   }
47 void WebStateObserverBridge::PageLoaded(
48     web::PageLoadCompletionStatus load_completion_status) {
49   SEL selector = @selector(webStateDidLoadPage:);
50   if ([observer_ respondsToSelector:selector])
51     [observer_ webStateDidLoadPage:web_state()];
54 void WebStateObserverBridge::InsterstitialDismissed() {
55   SEL selector = @selector(webStateDidDismissInterstitial:);
56   if ([observer_ respondsToSelector:selector])
57     [observer_ webStateDidDismissInterstitial:web_state()];
60 void WebStateObserverBridge::UrlHashChanged() {
61   SEL selector = @selector(webStateDidChangeURLHash:);
62   if ([observer_ respondsToSelector:selector])
63     [observer_ webStateDidChangeURLHash:web_state()];
66 void WebStateObserverBridge::HistoryStateChanged() {
67   SEL selector = @selector(webStateDidChangeHistoryState:);
68   if ([observer_ respondsToSelector:selector])
69     [observer_ webStateDidChangeHistoryState:web_state()];
72 void WebStateObserverBridge::DocumentSubmitted(const std::string& form_name,
73                                                bool user_initiated) {
74   SEL selector =
75       @selector(webState:didSubmitDocumentWithFormNamed:userInitiated:);
76   if ([observer_ respondsToSelector:selector]) {
77     [observer_ webState:web_state()
78         didSubmitDocumentWithFormNamed:form_name
79                          userInitiated:user_initiated];
80   }
83 void WebStateObserverBridge::FormActivityRegistered(
84     const std::string& form_name,
85     const std::string& field_name,
86     const std::string& type,
87     const std::string& value,
88     int key_code,
89     bool input_missing) {
90   SEL selector = @selector(webState:
91       didRegisterFormActivityWithFormNamed:
92                                  fieldName:
93                                       type:
94                                      value:
95                                    keyCode:
96                               inputMissing:);
97   if ([observer_ respondsToSelector:selector]) {
98     [observer_ webState:web_state()
99         didRegisterFormActivityWithFormNamed:form_name
100                                    fieldName:field_name
101                                         type:type
102                                        value:value
103                                      keyCode:key_code
104                                 inputMissing:input_missing];
105   }
108 void WebStateObserverBridge::AutocompleteRequested(const GURL& source_url,
109                                                    const std::string& form_name,
110                                                    bool user_initiated) {
111   SEL selector = @selector(webState:
112       requestAutocompleteForFormNamed:
113                             sourceURL:
114                         userInitiated:);
115   if ([observer_ respondsToSelector:selector]) {
116     [observer_ webState:web_state()
117         requestAutocompleteForFormNamed:form_name
118                               sourceURL:source_url
119                           userInitiated:user_initiated];
120   }
123 void WebStateObserverBridge::FaviconUrlUpdated(
124     const std::vector<FaviconURL>& candidates) {
125   SEL selector = @selector(webState:didUpdateFaviconURLCandidates:);
126   if ([observer_ respondsToSelector:selector])
127     [observer_ webState:web_state() didUpdateFaviconURLCandidates:candidates];
130 void WebStateObserverBridge::WebStateDestroyed() {
131   SEL selector = @selector(webStateDestroyed:);
132   if ([observer_ respondsToSelector:selector]) {
133     // |webStateDestroyed:| may delete |this|, so don't expect |this| to be
134     // valid afterwards.
135     [observer_ webStateDestroyed:web_state()];
136   }
139 }  // namespace web