| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chrome/browser/ui/bookmarks/bookmark_interaction_controller.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_interaction_controller.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #import "base/ios/weak_nsobject.h" | 9 #import "base/ios/weak_nsobject.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/mac/bind_objc_block.h" | 11 #include "base/mac/bind_objc_block.h" |
| 12 #include "base/mac/objc_property_releaser.h" | 12 #include "base/mac/objc_release_properties.h" |
| 13 #include "base/mac/scoped_nsobject.h" | 13 #include "base/mac/scoped_nsobject.h" |
| 14 #include "base/metrics/user_metrics.h" | 14 #include "base/metrics/user_metrics.h" |
| 15 #include "base/metrics/user_metrics_action.h" | 15 #include "base/metrics/user_metrics_action.h" |
| 16 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "components/bookmarks/browser/bookmark_model.h" | 19 #include "components/bookmarks/browser/bookmark_model.h" |
| 20 #include "components/bookmarks/browser/bookmark_utils.h" | 20 #include "components/bookmarks/browser/bookmark_utils.h" |
| 21 #include "components/pref_registry/pref_registry_syncable.h" | 21 #include "components/pref_registry/pref_registry_syncable.h" |
| 22 #include "components/prefs/pref_service.h" | 22 #include "components/prefs/pref_service.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 52 | 52 |
| 53 // The browser state to use, might be different from _currentBrowserState if | 53 // The browser state to use, might be different from _currentBrowserState if |
| 54 // it is incognito. | 54 // it is incognito. |
| 55 ios::ChromeBrowserState* _browserState; // weak | 55 ios::ChromeBrowserState* _browserState; // weak |
| 56 | 56 |
| 57 // The designated url loader. | 57 // The designated url loader. |
| 58 base::WeakNSProtocol<id<UrlLoader>> _loader; | 58 base::WeakNSProtocol<id<UrlLoader>> _loader; |
| 59 | 59 |
| 60 // The parent controller on top of which the UI needs to be presented. | 60 // The parent controller on top of which the UI needs to be presented. |
| 61 base::WeakNSObject<UIViewController> _parentController; | 61 base::WeakNSObject<UIViewController> _parentController; |
| 62 | |
| 63 base::mac::ObjCPropertyReleaser | |
| 64 _propertyReleaser_BookmarkInteractionController; | |
| 65 } | 62 } |
| 66 | 63 |
| 67 // The bookmark model in use. | 64 // The bookmark model in use. |
| 68 @property(nonatomic, assign) BookmarkModel* bookmarkModel; | 65 @property(nonatomic, assign) BookmarkModel* bookmarkModel; |
| 69 | 66 |
| 70 // A reference to the potentially presented bookmark browser. | 67 // A reference to the potentially presented bookmark browser. |
| 71 @property(nonatomic, retain) BookmarkHomeViewController* bookmarkBrowser; | 68 @property(nonatomic, retain) BookmarkHomeViewController* bookmarkBrowser; |
| 72 | 69 |
| 73 // A reference to the potentially presented single bookmark editor. | 70 // A reference to the potentially presented single bookmark editor. |
| 74 @property(nonatomic, retain) BookmarkEditViewController* bookmarkEditor; | 71 @property(nonatomic, retain) BookmarkEditViewController* bookmarkEditor; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 DCHECK(folder && folder->is_folder()); | 119 DCHECK(folder && folder->is_folder()); |
| 123 browserState->GetPrefs()->SetInt64(prefs::kIosBookmarkFolderDefault, | 120 browserState->GetPrefs()->SetInt64(prefs::kIosBookmarkFolderDefault, |
| 124 folder->id()); | 121 folder->id()); |
| 125 } | 122 } |
| 126 | 123 |
| 127 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState | 124 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState |
| 128 loader:(id<UrlLoader>)loader | 125 loader:(id<UrlLoader>)loader |
| 129 parentController:(UIViewController*)parentController { | 126 parentController:(UIViewController*)parentController { |
| 130 self = [super init]; | 127 self = [super init]; |
| 131 if (self) { | 128 if (self) { |
| 132 _propertyReleaser_BookmarkInteractionController.Init( | |
| 133 self, [BookmarkInteractionController class]); | |
| 134 // Bookmarks are always opened with the main browser state, even in | 129 // Bookmarks are always opened with the main browser state, even in |
| 135 // incognito mode. | 130 // incognito mode. |
| 136 _currentBrowserState = browserState; | 131 _currentBrowserState = browserState; |
| 137 _browserState = browserState->GetOriginalChromeBrowserState(); | 132 _browserState = browserState->GetOriginalChromeBrowserState(); |
| 138 _loader.reset(loader); | 133 _loader.reset(loader); |
| 139 _parentController.reset(parentController); | 134 _parentController.reset(parentController); |
| 140 _bookmarkModel = | 135 _bookmarkModel = |
| 141 ios::BookmarkModelFactory::GetForBrowserState(_browserState); | 136 ios::BookmarkModelFactory::GetForBrowserState(_browserState); |
| 142 DCHECK(_bookmarkModel); | 137 DCHECK(_bookmarkModel); |
| 143 DCHECK(_parentController); | 138 DCHECK(_parentController); |
| 144 } | 139 } |
| 145 return self; | 140 return self; |
| 146 } | 141 } |
| 147 | 142 |
| 148 - (void)dealloc { | 143 - (void)dealloc { |
| 149 _bookmarkBrowser.delegate = nil; | 144 _bookmarkBrowser.delegate = nil; |
| 150 _bookmarkEditor.delegate = nil; | 145 _bookmarkEditor.delegate = nil; |
| 146 base::mac::ReleaseProperties(self); |
| 151 [super dealloc]; | 147 [super dealloc]; |
| 152 } | 148 } |
| 153 | 149 |
| 154 - (void)addBookmarkForTab:(Tab*)tab { | 150 - (void)addBookmarkForTab:(Tab*)tab { |
| 155 base::RecordAction(base::UserMetricsAction("BookmarkAdded")); | 151 base::RecordAction(base::UserMetricsAction("BookmarkAdded")); |
| 156 const BookmarkNode* defaultFolder = | 152 const BookmarkNode* defaultFolder = |
| 157 [[self class] folderForNewBookmarksInBrowserState:_browserState]; | 153 [[self class] folderForNewBookmarksInBrowserState:_browserState]; |
| 158 self.bookmarkModel->AddURL(defaultFolder, defaultFolder->child_count(), | 154 self.bookmarkModel->AddURL(defaultFolder, defaultFolder->child_count(), |
| 159 base::SysNSStringToUTF16(tab.title), tab.url); | 155 base::SysNSStringToUTF16(tab.title), tab.url); |
| 160 | 156 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } else { | 300 } else { |
| 305 [_loader loadURL:url | 301 [_loader loadURL:url |
| 306 referrer:web::Referrer() | 302 referrer:web::Referrer() |
| 307 transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK | 303 transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK |
| 308 rendererInitiated:NO]; | 304 rendererInitiated:NO]; |
| 309 } | 305 } |
| 310 } | 306 } |
| 311 } | 307 } |
| 312 | 308 |
| 313 @end | 309 @end |
| OLD | NEW |