Chromium Code Reviews| Index: ios/shared/chrome/browser/tabs/web_state_list_observer_bridge.h |
| diff --git a/ios/shared/chrome/browser/tabs/web_state_list_observer_bridge.h b/ios/shared/chrome/browser/tabs/web_state_list_observer_bridge.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6ccfb323fa44ce68c5b350760b1d22a62464b68a |
| --- /dev/null |
| +++ b/ios/shared/chrome/browser/tabs/web_state_list_observer_bridge.h |
| @@ -0,0 +1,75 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_OBSERVER_BRIDGE_H_ |
| +#define IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_OBSERVER_BRIDGE_H_ |
| + |
| +#import <Foundation/Foundation.h> |
| + |
| +#include "base/macros.h" |
| +#import "ios/shared/chrome/browser/tabs/web_state_list_observer.h" |
| + |
| +// Protocol that correspond to WebStateListObserver API. Allows registering |
| +// Objective-C objects to listen to WebStateList events. |
| +@protocol WebStateListObserver<NSObject> |
|
rohitrao (ping after 24h)
2017/02/14 13:01:26
How does this compile? You can have a protocol wi
marq (ping after 24h)
2017/02/14 13:11:48
Protocols aren't types, so there's no compilation
sdefresne
2017/02/14 13:39:57
Done.
|
| + |
| +@optional |
| + |
| +// Invoked when a new WebState has been added to the WebStateList at the |
| +// specified index. |
| +- (void)webStateList:(WebStateList*)webStateList |
| + webStateInserted:(web::WebState*)webState |
|
rohitrao (ping after 24h)
2017/02/13 20:54:29
To match cocoa touch conventions, consider naming
marq (ping after 24h)
2017/02/14 13:11:48
Yeah, I should have caught this. +1.
sdefresne
2017/02/14 13:39:57
Done.
|
| + atIndex:(NSUInteger)index; |
| + |
| +// Invoked when the WebState at the specified index is moved to another index. |
| +- (void)webStateList:(WebStateList*)webStateList |
| + webStateMoved:(web::WebState*)webState |
| + fromIndex:(NSUInteger)fromIndex |
| + toIndex:(NSUInteger)toIndex; |
| + |
| +// Invoked when the WebState at the specified index is replaced by another |
| +// WebState. |
| +- (void)webStateList:(WebStateList*)webStateList |
| + webStateReplaced:(web::WebState*)oldWebState |
|
rohitrao (ping after 24h)
2017/02/13 20:54:29
didReplaceWebState:withWebState:
sdefresne
2017/02/14 13:39:57
Done.
|
| + byWebState:(web::WebState*)newWebState |
| + atIndex:(NSUInteger)index; |
| + |
| +// Invoked when the WebState at the specified index is being removed. The |
| +// WebState is still valid but is no longer in the WebStateList. |
| +- (void)webStateList:(WebStateList*)webStateList |
| + webStateRemoved:(web::WebState*)webState |
| + atIndex:(NSUInteger)index; |
| + |
| +@end |
| + |
| +// Observer that bridges WebStateList events to an Objective-C observer that |
| +// implements the WebStateListObserver protocol (the observer is owned). |
| +class WebStateListObserverBridge : public WebStateListObserver { |
| + public: |
| + explicit WebStateListObserverBridge(id<WebStateListObserver> observer); |
| + ~WebStateListObserverBridge() override; |
| + |
| + private: |
| + // WebStateListObserver implementation. |
| + void WebStateInsertedAt(WebStateList* web_state_list, |
| + web::WebState* web_state, |
| + size_t index) override; |
| + void WebStateMoved(WebStateList* web_state_list, |
| + web::WebState* web_state, |
| + size_t from_index, |
| + size_t to_index) override; |
| + void WebStateReplacedAt(WebStateList* web_state_list, |
| + web::WebState* old_web_state, |
| + web::WebState* new_web_state, |
| + size_t index) override; |
| + void WebStateRemovedAt(WebStateList* web_state_list, |
| + web::WebState* web_state, |
| + size_t index) override; |
| + |
| + id<WebStateListObserver> observer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WebStateListObserverBridge); |
| +}; |
| + |
| +#endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_OBSERVER_BRIDGE_H_ |