OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/cocoa/applescript/window_applescript.h" | 5 #import "chrome/browser/ui/cocoa/applescript/window_applescript.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "base/memory/scoped_nsobject.h" | 8 #import "base/memory/scoped_nsobject.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 int activeTabIndex = browser_->active_index() + 1; | 110 int activeTabIndex = browser_->active_index() + 1; |
111 if (!activeTabIndex) { | 111 if (!activeTabIndex) { |
112 return nil; | 112 return nil; |
113 } | 113 } |
114 return [NSNumber numberWithInt:activeTabIndex]; | 114 return [NSNumber numberWithInt:activeTabIndex]; |
115 } | 115 } |
116 | 116 |
117 - (void)setActiveTabIndex:(NSNumber*)anActiveTabIndex { | 117 - (void)setActiveTabIndex:(NSNumber*)anActiveTabIndex { |
118 // Note: applescript is 1-based, that is lists begin with index 1. | 118 // Note: applescript is 1-based, that is lists begin with index 1. |
119 int atIndex = [anActiveTabIndex intValue] - 1; | 119 int atIndex = [anActiveTabIndex intValue] - 1; |
120 if (atIndex >= 0 && atIndex < browser_->tab_count()) | 120 if (atIndex >= 0 && atIndex < browser_->tab_strip_model()->count()) |
121 chrome::ActivateTabAt(browser_, atIndex, true); | 121 browser_->tab_strip_model()->ActivateTabAt(atIndex, true); |
122 else | 122 else |
123 AppleScript::SetError(AppleScript::errInvalidTabIndex); | 123 AppleScript::SetError(AppleScript::errInvalidTabIndex); |
124 } | 124 } |
125 | 125 |
126 - (NSString*)mode { | 126 - (NSString*)mode { |
127 Profile* profile = browser_->profile(); | 127 Profile* profile = browser_->profile(); |
128 if (profile->IsOffTheRecord()) | 128 if (profile->IsOffTheRecord()) |
129 return AppleScript::kIncognitoWindowMode; | 129 return AppleScript::kIncognitoWindowMode; |
130 return AppleScript::kNormalWindowMode; | 130 return AppleScript::kNormalWindowMode; |
131 } | 131 } |
132 | 132 |
133 - (void)setMode:(NSString*)theMode { | 133 - (void)setMode:(NSString*)theMode { |
134 // cannot set mode after window is created. | 134 // cannot set mode after window is created. |
135 if (theMode) { | 135 if (theMode) { |
136 AppleScript::SetError(AppleScript::errSetMode); | 136 AppleScript::SetError(AppleScript::errSetMode); |
137 } | 137 } |
138 } | 138 } |
139 | 139 |
140 - (TabAppleScript*)activeTab { | 140 - (TabAppleScript*)activeTab { |
141 TabAppleScript* currentTab = | 141 TabAppleScript* currentTab = |
142 [[[TabAppleScript alloc] | 142 [[[TabAppleScript alloc] initWithWebContents: |
143 initWithWebContents:chrome::GetActiveWebContents(browser_)] | 143 browser_->tab_strip_model()->GetActiveWebContents()] autorelease]; |
144 autorelease]; | |
145 [currentTab setContainer:self | 144 [currentTab setContainer:self |
146 property:AppleScript::kTabsProperty]; | 145 property:AppleScript::kTabsProperty]; |
147 return currentTab; | 146 return currentTab; |
148 } | 147 } |
149 | 148 |
150 - (NSArray*)tabs { | 149 - (NSArray*)tabs { |
151 NSMutableArray* tabs = [NSMutableArray | 150 NSMutableArray* tabs = [NSMutableArray |
152 arrayWithCapacity:browser_->tab_count()]; | 151 arrayWithCapacity:browser_->tab_count()]; |
153 | 152 |
154 for (int i = 0; i < browser_->tab_count(); ++i) { | 153 for (int i = 0; i < browser_->tab_count(); ++i) { |
155 // Check to see if tab is closing. | 154 // Check to see if tab is closing. |
156 content::WebContents* webContents = chrome::GetWebContentsAt(browser_, i); | 155 content::WebContents* webContents = |
| 156 browser_->tab_strip_model()->GetWebContentsAt(i); |
157 if (webContents->IsBeingDestroyed()) { | 157 if (webContents->IsBeingDestroyed()) { |
158 continue; | 158 continue; |
159 } | 159 } |
160 | 160 |
161 scoped_nsobject<TabAppleScript> tab( | 161 scoped_nsobject<TabAppleScript> tab( |
162 [[TabAppleScript alloc] initWithWebContents:webContents]); | 162 [[TabAppleScript alloc] initWithWebContents:webContents]); |
163 [tab setContainer:self | 163 [tab setContainer:self |
164 property:AppleScript::kTabsProperty]; | 164 property:AppleScript::kTabsProperty]; |
165 [tabs addObject:tab]; | 165 [tabs addObject:tab]; |
166 } | 166 } |
(...skipping 29 matching lines...) Expand all Loading... |
196 params.disposition = NEW_FOREGROUND_TAB; | 196 params.disposition = NEW_FOREGROUND_TAB; |
197 params.tabstrip_index = index; | 197 params.tabstrip_index = index; |
198 chrome::Navigate(¶ms); | 198 chrome::Navigate(¶ms); |
199 params.target_contents->web_contents()->SetNewTabStartTime( | 199 params.target_contents->web_contents()->SetNewTabStartTime( |
200 newTabStartTime); | 200 newTabStartTime); |
201 | 201 |
202 [aTab setWebContents:params.target_contents->web_contents()]; | 202 [aTab setWebContents:params.target_contents->web_contents()]; |
203 } | 203 } |
204 | 204 |
205 - (void)removeFromTabsAtIndex:(int)index { | 205 - (void)removeFromTabsAtIndex:(int)index { |
206 chrome::CloseWebContents(browser_, chrome::GetWebContentsAt(browser_, index)); | 206 chrome::CloseWebContents( |
| 207 browser_, browser_->tab_strip_model()->GetWebContentsAt(index)); |
207 } | 208 } |
208 | 209 |
209 - (NSNumber*)orderedIndex { | 210 - (NSNumber*)orderedIndex { |
210 return [NSNumber numberWithInt:[[self nativeHandle] orderedIndex]]; | 211 return [NSNumber numberWithInt:[[self nativeHandle] orderedIndex]]; |
211 } | 212 } |
212 | 213 |
213 - (void)setOrderedIndex:(NSNumber*)anIndex { | 214 - (void)setOrderedIndex:(NSNumber*)anIndex { |
214 int index = [anIndex intValue] - 1; | 215 int index = [anIndex intValue] - 1; |
215 if (index < 0 || index >= (int)BrowserList::size()) { | 216 if (index < 0 || index >= (int)BrowserList::size()) { |
216 AppleScript::SetError(AppleScript::errWrongIndex); | 217 AppleScript::SetError(AppleScript::errWrongIndex); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 GURL(), FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION); | 260 GURL(), FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION); |
260 } | 261 } |
261 } | 262 } |
262 | 263 |
263 - (void)handlesExitPresentationMode:(NSScriptCommand*)command { | 264 - (void)handlesExitPresentationMode:(NSScriptCommand*)command { |
264 if (browser_->window()) | 265 if (browser_->window()) |
265 browser_->window()->ExitPresentationMode(); | 266 browser_->window()->ExitPresentationMode(); |
266 } | 267 } |
267 | 268 |
268 @end | 269 @end |
OLD | NEW |