Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.h" | 5 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.h" |
| 6 | 6 |
| 7 #include "base/mac/bind_objc_block.h" | |
| 7 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 8 #include "base/scoped_observer.h" | 9 #include "base/scoped_observer.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #import "ios/chrome/browser/snapshots/snapshot_cache.h" | |
| 12 #import "ios/chrome/browser/snapshots/snapshot_constants.h" | |
| 10 #import "ios/chrome/browser/web/tab_id_tab_helper.h" | 13 #import "ios/chrome/browser/web/tab_id_tab_helper.h" |
| 11 #import "ios/chrome/browser/web_state_list/web_state_list.h" | 14 #import "ios/chrome/browser/web_state_list/web_state_list.h" |
| 12 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_consumer.h" | 15 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_consumer.h" |
| 13 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_item.h" | 16 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_item.h" |
| 14 #include "ios/web/public/web_state/web_state.h" | 17 #include "ios/web/public/web_state/web_state.h" |
| 15 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 18 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
| 19 #include "ui/gfx/image/image.h" | |
|
danakj
2017/07/11 19:14:15
I thought IOS cant depend on skia?
| |
| 16 | 20 |
| 17 #if !defined(__has_feature) || !__has_feature(objc_arc) | 21 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 18 #error "This file requires ARC support." | 22 #error "This file requires ARC support." |
| 19 #endif | 23 #endif |
| 20 | 24 |
| 21 @interface TabCollectionMediator ()<CRWWebStateObserver> | 25 @interface TabCollectionMediator ()<CRWWebStateObserver> |
| 22 @end | 26 @end |
| 23 | 27 |
| 24 @implementation TabCollectionMediator { | 28 @implementation TabCollectionMediator { |
| 25 std::unique_ptr<WebStateListObserverBridge> _webStateListObserver; | 29 std::unique_ptr<WebStateListObserverBridge> _webStateListObserver; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 41 } | 45 } |
| 42 return self; | 46 return self; |
| 43 } | 47 } |
| 44 | 48 |
| 45 - (void)dealloc { | 49 - (void)dealloc { |
| 46 [self disconnect]; | 50 [self disconnect]; |
| 47 } | 51 } |
| 48 | 52 |
| 49 #pragma mark - Public | 53 #pragma mark - Public |
| 50 | 54 |
| 55 - (void)takeSnapshotWithCache:(SnapshotCache*)snapshotCache { | |
| 56 web::WebState* webState = self.webStateList->GetActiveWebState(); | |
| 57 TabIdTabHelper* tabHelper = TabIdTabHelper::FromWebState(webState); | |
| 58 DCHECK(tabHelper); | |
| 59 NSString* tabID = tabHelper->tab_id(); | |
| 60 int index = self.webStateList->active_index(); | |
| 61 __weak TabCollectionMediator* weakSelf = self; | |
| 62 webState->TakeSnapshot(base::BindBlockArc(^(const gfx::Image& snapshot) { | |
| 63 [snapshotCache setImage:snapshot.ToUIImage() | |
| 64 withSessionID:tabID]; | |
| 65 [weakSelf.consumer updateSnapshotAtIndex:index]; | |
| 66 }), | |
| 67 kSnapshotThumbnailSize); | |
| 68 } | |
| 69 | |
| 51 - (void)disconnect { | 70 - (void)disconnect { |
| 52 _webStateList = nullptr; | 71 _webStateList = nullptr; |
| 53 _webStateObserver.reset(); | 72 _webStateObserver.reset(); |
| 54 _scopedWebStateListObserver->RemoveAll(); | 73 _scopedWebStateListObserver->RemoveAll(); |
| 55 } | 74 } |
| 56 | 75 |
| 57 #pragma mark - Properties | 76 #pragma mark - Properties |
| 58 | 77 |
| 59 - (void)setWebStateList:(WebStateList*)webStateList { | 78 - (void)setWebStateList:(WebStateList*)webStateList { |
| 60 DCHECK(webStateList); | 79 DCHECK(webStateList); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 - (void)populateConsumerItems { | 184 - (void)populateConsumerItems { |
| 166 if (self.consumer && self.webStateList) { | 185 if (self.consumer && self.webStateList) { |
| 167 [self.consumer | 186 [self.consumer |
| 168 populateItems:[self | 187 populateItems:[self |
| 169 tabCollectionItemsFromWebStateList:self.webStateList] | 188 tabCollectionItemsFromWebStateList:self.webStateList] |
| 170 selectedIndex:self.webStateList->active_index()]; | 189 selectedIndex:self.webStateList->active_index()]; |
| 171 } | 190 } |
| 172 } | 191 } |
| 173 | 192 |
| 174 @end | 193 @end |
| OLD | NEW |