forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ios clean] Creates ToolbarWebState Mediator
BUG=683793 Review-Url: https://codereview.chromium.org/2708013002 Cr-Commit-Position: refs/heads/master@{#452059}
- Loading branch information
sczs
authored and
Commit bot
committed
Feb 22, 2017
1 parent
4df731b
commit fe033cc
Showing
9 changed files
with
122 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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_CLEAN_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_CONSUMER_H_ | ||
#define IOS_CLEAN_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_CONSUMER_H_ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
// ToolbarConsumer sets the current appearance of the Toolbar based on | ||
// WebState or other data sources provided by this protocol. | ||
@protocol ToolbarConsumer | ||
// Sets the text for a label appearing in the center of the toolbar. | ||
- (void)setCurrentPageText:(NSString*)text; | ||
@end | ||
|
||
#endif // IOS_CLEAN_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_CONSUMER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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_CLEAN_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MEDIATOR_H_ | ||
#define IOS_CLEAN_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MEDIATOR_H_ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@protocol ToolbarConsumer; | ||
|
||
namespace web { | ||
class WebState; | ||
} | ||
|
||
// A mediator object that provides the relevant properties of a web state | ||
// to a consumer. | ||
@interface ToolbarMediator : NSObject | ||
|
||
// The WebState whose properties this object mediates. This can change during | ||
// the lifetime of this object and may be null. | ||
@property(nonatomic, assign) web::WebState* webState; | ||
|
||
// The consumer for this object. This can change during the lifetime of this | ||
// object and may be nil. | ||
@property(nonatomic, strong) id<ToolbarConsumer> consumer; | ||
|
||
@end | ||
|
||
#endif // IOS_CLEAN_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MEDIATOR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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. | ||
|
||
#import "ios/clean/chrome/browser/ui/toolbar/toolbar_mediator.h" | ||
|
||
#include "base/memory/ptr_util.h" | ||
#include "base/strings/sys_string_conversions.h" | ||
#import "ios/clean/chrome/browser/ui/toolbar/toolbar_consumer.h" | ||
#include "ios/web/public/web_state/web_state.h" | ||
#import "ios/web/public/web_state/web_state_observer_bridge.h" | ||
|
||
@interface ToolbarMediator ()<CRWWebStateObserver> | ||
@end | ||
|
||
@implementation ToolbarMediator { | ||
std::unique_ptr<web::WebStateObserverBridge> _webStateObserver; | ||
} | ||
|
||
@synthesize consumer = _consumer; | ||
@synthesize webState = _webState; | ||
|
||
- (void)dealloc { | ||
_webStateObserver.reset(); | ||
_webState = nullptr; | ||
} | ||
|
||
- (void)setWebState:(web::WebState*)webState { | ||
_webState = webState; | ||
_webStateObserver = | ||
base::MakeUnique<web::WebStateObserverBridge>(self.webState, self); | ||
} | ||
|
||
#pragma mark - CRWWebStateObserver | ||
|
||
- (void)webState:(web::WebState*)webState didLoadPageWithSuccess:(BOOL)success { | ||
const GURL& pageURL = webState->GetVisibleURL(); | ||
[self.consumer setCurrentPageText:base::SysUTF8ToNSString(pageURL.spec())]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters