Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Unified Diff: ios/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm

Issue 2588733002: Upstream Chrome on iOS source code [9/11]. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm
diff --git a/ios/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm b/ios/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm
new file mode 100644
index 0000000000000000000000000000000000000000..5a826f7c5557a17fde74f0e9ae050b1bfd0ea81d
--- /dev/null
+++ b/ios/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm
@@ -0,0 +1,133 @@
+// Copyright 2016 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.
+
+// ====== New Architecture =====
+// = This code is only used in the new iOS Chrome architecture. =
+// ============================================================================
+
+#import "ios/chrome/browser/ui/tab_grid/tab_grid_coordinator.h"
+
+#include <memory>
+
+#include "base/strings/sys_string_conversions.h"
+#import "ios/chrome/browser/browser_coordinator+internal.h"
+#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
+#import "ios/chrome/browser/ui/settings/settings_coordinator.h"
+#import "ios/chrome/browser/ui/tab/tab_coordinator.h"
+#import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h"
+#import "ios/web/public/navigation_manager.h"
+#include "ios/web/public/web_state/web_state.h"
+#import "net/base/mac/url_conversions.h"
+#include "ui/base/page_transition_types.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+@interface TabGridCoordinator ()<TabGridDataSource,
+ TabGridActionDelegate,
+ SettingsActionDelegate>
+@property(nonatomic, strong) TabGridViewController* viewController;
+@property(nonatomic, weak) SettingsCoordinator* settingsCoordinator;
+@end
+
+@implementation TabGridCoordinator {
+ std::unique_ptr<web::WebState> _placeholderWebState;
+}
+
+@synthesize viewController = _viewController;
+@synthesize settingsCoordinator = _settingsCoordinator;
+
+#pragma mark - BrowserCoordinator
+
+- (void)start {
+ self.viewController = [[TabGridViewController alloc] init];
+ self.viewController.dataSource = self;
+ self.viewController.actionDelegate = self;
+
+ // |rootViewController| is nullable, so this is by design a no-op if it hasn't
+ // been set. This may be true in a unit test, or if this coordinator is being
+ // used as a root coordinator.
+ [self.rootViewController presentViewController:self.viewController
+ animated:YES
+ completion:nil];
+}
+
+#pragma mark - TabGridDataSource
+
+- (NSUInteger)numberOfTabsInTabGrid {
+ return 1;
+}
+
+- (NSString*)titleAtIndex:(NSInteger)index {
+ // Placeholder implementation: ignore |index| and return the placeholder
+ // web state, lazily creating it if needed.
+ if (!_placeholderWebState.get()) {
+ web::WebState::CreateParams webStateCreateParams(self.browserState);
+ _placeholderWebState = web::WebState::Create(webStateCreateParams);
+ _placeholderWebState->SetWebUsageEnabled(true);
+ }
+ GURL url = _placeholderWebState.get()->GetVisibleURL();
+ NSString* urlText = @"<New Tab>";
+ if (!url.is_valid()) {
+ urlText = base::SysUTF8ToNSString(url.spec());
+ }
+ return urlText;
+}
+
+#pragma mark - TabGridActionDelegate
+
+- (void)showTabAtIndexPath:(NSIndexPath*)indexPath {
+ DCHECK(_placeholderWebState);
+
+ TabCoordinator* tabCoordinator = [[TabCoordinator alloc] init];
+ tabCoordinator.webState = _placeholderWebState.get();
+ tabCoordinator.presentationKey = indexPath;
+ [self addChildCoordinator:tabCoordinator];
+ [tabCoordinator start];
+}
+
+- (void)showTabGrid {
+ // This object should only ever have at most one child.
+ DCHECK_LE(self.children.count, 1UL);
+ BrowserCoordinator* child = [self.children anyObject];
+ [child stop];
+ [self removeChildCoordinator:child];
+}
+
+#pragma mark - TabGridActionDelegate
+
+- (void)showSettings {
+ SettingsCoordinator* settingsCoordinator = [[SettingsCoordinator alloc] init];
+ settingsCoordinator.actionDelegate = self;
+ [self addOverlayCoordinator:settingsCoordinator];
+ self.settingsCoordinator = settingsCoordinator;
+ [settingsCoordinator start];
+}
+
+#pragma mark - SettingsActionDelegate
+
+- (void)closeSettings {
+ [self.settingsCoordinator stop];
+ [self.settingsCoordinator.parentCoordinator
+ removeChildCoordinator:self.settingsCoordinator];
+ // self.settingsCoordinator should be presumed to be nil after this point.
+}
+
+#pragma mark - URLOpening
+
+- (void)openURL:(NSURL*)URL {
+ [self.overlayCoordinator stop];
+ [self removeOverlayCoordinator];
+ web::NavigationManager::WebLoadParams params(net::GURLWithNSURL(URL));
+ params.transition_type = ui::PAGE_TRANSITION_LINK;
+ _placeholderWebState->GetNavigationManager()->LoadURLWithParams(params);
+ if (!self.children.count) {
+ // Placeholder — since there's only one tab in the grid, just open
+ // the tab at index path (0,0).
+ [self showTabAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
+ }
+}
+
+@end
« no previous file with comments | « ios/chrome/browser/ui/tab_grid/tab_grid_coordinator.h ('k') | ios/chrome/browser/ui/tab_grid/tab_grid_tab_cell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698