| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_OBSERVER_BRIDGE_H_ | 5 #ifndef IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_OBSERVER_BRIDGE_H_ |
| 6 #define IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_OBSERVER_BRIDGE_H_ | 6 #define IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_OBSERVER_BRIDGE_H_ |
| 7 | 7 |
| 8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #import "base/ios/weak_nsobject.h" | 12 #import "base/ios/weak_nsobject.h" |
| 13 #import "ios/web/public/web_state/web_state_observer.h" | 13 #import "ios/web/public/web_state/web_state_observer.h" |
| 14 | 14 |
| 15 class GURL; |
| 16 |
| 15 // Observes page lifecyle events from Objective-C. To use as a | 17 // Observes page lifecyle events from Objective-C. To use as a |
| 16 // web::WebStateObserver, wrap in a web::WebStateObserverBridge. | 18 // web::WebStateObserver, wrap in a web::WebStateObserverBridge. |
| 17 // NOTE: This is far from complete. Add new methods as needed. | |
| 18 @protocol CRWWebStateObserver<NSObject> | 19 @protocol CRWWebStateObserver<NSObject> |
| 19 @optional | 20 @optional |
| 21 // Invoked by WebStateObserverBridge::NavigationItemCommitted. |
| 22 - (void)webState:(web::WebState*)webState |
| 23 didCommitNavigationWithDetails: |
| 24 (const web::LoadCommittedDetails&)load_details; |
| 20 | 25 |
| 21 // Page lifecycle methods. These are equivalent to the corresponding methods | 26 // Invoked by WebStateObserverBridge::PageLoaded. |
| 22 // in web::WebStateObserver. | 27 - (void)webStateDidLoadPage:(web::WebState*)webState; |
| 23 - (void)pageLoaded:(web::WebState*)webState; | 28 |
| 24 - (void)documentSubmitted:(web::WebState*)webState | 29 // Invoked by WebStateObserverBridge::InterstitialDismissed. |
| 25 formName:(const std::string&)formName | 30 - (void)webStateDidDismissInterstitial:(web::WebState*)webState; |
| 26 userInteraction:(BOOL)userInteraction; | 31 |
| 27 - (void)formActivity:(web::WebState*)webState | 32 // Invoked by WebStateObserverBridge::UrlHashChanged. |
| 28 formName:(const std::string&)formName | 33 - (void)webStateDidChangeURLHash:(web::WebState*)webState; |
| 29 fieldName:(const std::string&)fieldName | 34 |
| 30 type:(const std::string&)type | 35 // Invoked by WebStateObserverBridge::HistoryStateChanged. |
| 31 value:(const std::string&)value | 36 - (void)webStateDidChangeHistoryState:(web::WebState*)webState; |
| 32 keyCode:(int)keyCode | 37 |
| 33 error:(BOOL)error; | 38 // Invoked by WebStateObserverBridge::DocumentSubmitted. |
| 39 - (void)webState:(web::WebState*)webState |
| 40 didSubmitDocumentWithFormNamed:(const std::string&)formName |
| 41 userInitiated:(BOOL)userInitiated; |
| 42 |
| 43 // Invoked by WebStateObserverBridge::FormActivityRegistered. |
| 44 // TODO(ios): Method should take data transfer object rather than parameters. |
| 45 - (void)webState:(web::WebState*)webState |
| 46 didRegisterFormActivityWithFormNamed:(const std::string&)formName |
| 47 fieldName:(const std::string&)fieldName |
| 48 type:(const std::string&)type |
| 49 value:(const std::string&)value |
| 50 keyCode:(int)keyCode |
| 51 inputMissing:(BOOL)inputMissing; |
| 52 |
| 53 // Invoked by WebStateObserverBridge::AutocompleteRequested. |
| 54 - (void)webState:(web::WebState*)webState |
| 55 requestAutocompleteForFormNamed:(const std::string&)formName |
| 56 sourceURL:(const GURL&)sourceURL |
| 57 userInitiated:(BOOL)userInitiated; |
| 58 |
| 59 // Invoked by WebStateObserverBridge::FaviconUrlUpdated. |
| 60 - (void)webState:(web::WebState*)webState |
| 61 didUpdateFaviconURLCandidates: |
| 62 (const std::vector<web::FaviconURL>&)candidates; |
| 63 |
| 34 // Note: after |webStateDestroyed:| is invoked, the WebState being observed | 64 // Note: after |webStateDestroyed:| is invoked, the WebState being observed |
| 35 // is no longer valid. | 65 // is no longer valid. |
| 36 - (void)webStateDestroyed:(web::WebState*)webState; | 66 - (void)webStateDestroyed:(web::WebState*)webState; |
| 37 | 67 |
| 38 @end | 68 @end |
| 39 | 69 |
| 40 namespace web { | 70 namespace web { |
| 41 | 71 |
| 42 class WebState; | 72 class WebState; |
| 43 | 73 |
| 44 // Bridge to use an id<CRWWebStateObserver> as a web::WebStateObserver. | 74 // Bridge to use an id<CRWWebStateObserver> as a web::WebStateObserver. |
| 45 // Will be added/removed as an observer of the underlying WebState during | 75 // Will be added/removed as an observer of the underlying WebState during |
| 46 // construction/destruction. Instances should be owned by instances of the | 76 // construction/destruction. Instances should be owned by instances of the |
| 47 // class they're bridging. | 77 // class they're bridging. |
| 48 class WebStateObserverBridge : public web::WebStateObserver { | 78 class WebStateObserverBridge : public web::WebStateObserver { |
| 49 public: | 79 public: |
| 50 WebStateObserverBridge(web::WebState* web_state, | 80 WebStateObserverBridge(web::WebState* web_state, |
| 51 id<CRWWebStateObserver> observer); | 81 id<CRWWebStateObserver> observer); |
| 52 ~WebStateObserverBridge() override; | 82 ~WebStateObserverBridge() override; |
| 53 | 83 |
| 54 // web::WebStateObserver: | 84 // web::WebStateObserver methods. |
| 55 // NOTE: This is far from complete. Add new methods as needed. | 85 void NavigationItemCommitted( |
| 86 const LoadCommittedDetails& load_details) override; |
| 56 void PageLoaded( | 87 void PageLoaded( |
| 57 web::PageLoadCompletionStatus load_completion_status) override; | 88 web::PageLoadCompletionStatus load_completion_status) override; |
| 89 void InsterstitialDismissed() override; |
| 90 void UrlHashChanged() override; |
| 91 void HistoryStateChanged() override; |
| 58 void DocumentSubmitted(const std::string& form_name, | 92 void DocumentSubmitted(const std::string& form_name, |
| 59 bool user_interaction) override; | 93 bool user_initiated) override; |
| 60 void FormActivityRegistered(const std::string& form_name, | 94 void FormActivityRegistered(const std::string& form_name, |
| 61 const std::string& field_name, | 95 const std::string& field_name, |
| 62 const std::string& type, | 96 const std::string& type, |
| 63 const std::string& value, | 97 const std::string& value, |
| 64 int key_code, | 98 int key_code, |
| 65 bool error) override; | 99 bool input_missing) override; |
| 100 void AutocompleteRequested(const GURL& source_url, |
| 101 const std::string& form_name, |
| 102 bool user_initiated) override; |
| 103 void FaviconUrlUpdated(const std::vector<FaviconURL>& candidates) override; |
| 66 void WebStateDestroyed() override; | 104 void WebStateDestroyed() override; |
| 67 | 105 |
| 68 private: | 106 private: |
| 69 base::WeakNSProtocol<id<CRWWebStateObserver>> observer_; | 107 base::WeakNSProtocol<id<CRWWebStateObserver>> observer_; |
| 70 DISALLOW_COPY_AND_ASSIGN(WebStateObserverBridge); | 108 DISALLOW_COPY_AND_ASSIGN(WebStateObserverBridge); |
| 71 }; | 109 }; |
| 72 | 110 |
| 73 } // namespace web | 111 } // namespace web |
| 74 | 112 |
| 75 #endif // IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_OBSERVER_BRIDGE_H_ | 113 #endif // IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_OBSERVER_BRIDGE_H_ |
| OLD | NEW |