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" |
11 #import "chrome/browser/app_controller_mac.h" | 11 #import "chrome/browser/app_controller_mac.h" |
12 #import "chrome/browser/chrome_browser_application_mac.h" | 12 #import "chrome/browser/chrome_browser_application_mac.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_commands.h" | 15 #include "chrome/browser/ui/browser_commands.h" |
16 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
17 #include "chrome/browser/ui/browser_navigator.h" | 17 #include "chrome/browser/ui/browser_navigator.h" |
| 18 #include "chrome/browser/ui/browser_tabstrip.h" |
18 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
19 #include "chrome/browser/ui/cocoa/applescript/constants_applescript.h" | 20 #include "chrome/browser/ui/cocoa/applescript/constants_applescript.h" |
20 #include "chrome/browser/ui/cocoa/applescript/error_applescript.h" | 21 #include "chrome/browser/ui/cocoa/applescript/error_applescript.h" |
21 #import "chrome/browser/ui/cocoa/applescript/tab_applescript.h" | 22 #import "chrome/browser/ui/cocoa/applescript/tab_applescript.h" |
22 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 23 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
26 | 27 |
27 @interface WindowAppleScript(WindowAppleScriptPrivateMethods) | 28 @interface WindowAppleScript(WindowAppleScriptPrivateMethods) |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 if (!activeTabIndex) { | 111 if (!activeTabIndex) { |
111 return nil; | 112 return nil; |
112 } | 113 } |
113 return [NSNumber numberWithInt:activeTabIndex]; | 114 return [NSNumber numberWithInt:activeTabIndex]; |
114 } | 115 } |
115 | 116 |
116 - (void)setActiveTabIndex:(NSNumber*)anActiveTabIndex { | 117 - (void)setActiveTabIndex:(NSNumber*)anActiveTabIndex { |
117 // 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. |
118 int atIndex = [anActiveTabIndex intValue] - 1; | 119 int atIndex = [anActiveTabIndex intValue] - 1; |
119 if (atIndex >= 0 && atIndex < browser_->tab_count()) | 120 if (atIndex >= 0 && atIndex < browser_->tab_count()) |
120 browser_->ActivateTabAt(atIndex, true); | 121 chrome::ActivateTabAt(browser_, atIndex, true); |
121 else | 122 else |
122 AppleScript::SetError(AppleScript::errInvalidTabIndex); | 123 AppleScript::SetError(AppleScript::errInvalidTabIndex); |
123 } | 124 } |
124 | 125 |
125 - (NSString*)mode { | 126 - (NSString*)mode { |
126 Profile* profile = browser_->profile(); | 127 Profile* profile = browser_->profile(); |
127 if (profile->IsOffTheRecord()) | 128 if (profile->IsOffTheRecord()) |
128 return AppleScript::kIncognitoWindowMode; | 129 return AppleScript::kIncognitoWindowMode; |
129 return AppleScript::kNormalWindowMode; | 130 return AppleScript::kNormalWindowMode; |
130 } | 131 } |
131 | 132 |
132 - (void)setMode:(NSString*)theMode { | 133 - (void)setMode:(NSString*)theMode { |
133 // cannot set mode after window is created. | 134 // cannot set mode after window is created. |
134 if (theMode) { | 135 if (theMode) { |
135 AppleScript::SetError(AppleScript::errSetMode); | 136 AppleScript::SetError(AppleScript::errSetMode); |
136 } | 137 } |
137 } | 138 } |
138 | 139 |
139 - (TabAppleScript*)activeTab { | 140 - (TabAppleScript*)activeTab { |
140 TabAppleScript* currentTab = | 141 TabAppleScript* currentTab = |
141 [[[TabAppleScript alloc] | 142 [[[TabAppleScript alloc] |
142 initWithTabContent:browser_->GetActiveTabContents()] | 143 initWithTabContent:chrome::GetActiveTabContents(browser_)] |
143 autorelease]; | 144 autorelease]; |
144 [currentTab setContainer:self | 145 [currentTab setContainer:self |
145 property:AppleScript::kTabsProperty]; | 146 property:AppleScript::kTabsProperty]; |
146 return currentTab; | 147 return currentTab; |
147 } | 148 } |
148 | 149 |
149 - (NSArray*)tabs { | 150 - (NSArray*)tabs { |
150 NSMutableArray* tabs = [NSMutableArray | 151 NSMutableArray* tabs = [NSMutableArray |
151 arrayWithCapacity:browser_->tab_count()]; | 152 arrayWithCapacity:browser_->tab_count()]; |
152 | 153 |
153 for (int i = 0; i < browser_->tab_count(); ++i) { | 154 for (int i = 0; i < browser_->tab_count(); ++i) { |
154 // Check to see if tab is closing. | 155 // Check to see if tab is closing. |
155 TabContents* tab_contents = browser_->GetTabContentsAt(i); | 156 TabContents* tab_contents = chrome::GetTabContentsAt(browser_, i); |
156 if (tab_contents->in_destructor()) { | 157 if (tab_contents->in_destructor()) { |
157 continue; | 158 continue; |
158 } | 159 } |
159 | 160 |
160 scoped_nsobject<TabAppleScript> tab( | 161 scoped_nsobject<TabAppleScript> tab( |
161 [[TabAppleScript alloc] initWithTabContent:tab_contents]); | 162 [[TabAppleScript alloc] initWithTabContent:tab_contents]); |
162 [tab setContainer:self | 163 [tab setContainer:self |
163 property:AppleScript::kTabsProperty]; | 164 property:AppleScript::kTabsProperty]; |
164 [tabs addObject:tab]; | 165 [tabs addObject:tab]; |
165 } | 166 } |
166 return tabs; | 167 return tabs; |
167 } | 168 } |
168 | 169 |
169 - (void)insertInTabs:(TabAppleScript*)aTab { | 170 - (void)insertInTabs:(TabAppleScript*)aTab { |
170 // This method gets called when a new tab is created so | 171 // This method gets called when a new tab is created so |
171 // the container and property are set here. | 172 // the container and property are set here. |
172 [aTab setContainer:self | 173 [aTab setContainer:self |
173 property:AppleScript::kTabsProperty]; | 174 property:AppleScript::kTabsProperty]; |
174 | 175 |
175 // Set how long it takes a tab to be created. | 176 // Set how long it takes a tab to be created. |
176 base::TimeTicks newTabStartTime = base::TimeTicks::Now(); | 177 base::TimeTicks newTabStartTime = base::TimeTicks::Now(); |
177 TabContents* contents = | 178 TabContents* contents = chrome::AddSelectedTabWithURL( |
178 browser_->AddSelectedTabWithURL(GURL(chrome::kChromeUINewTabURL), | 179 browser_, |
179 content::PAGE_TRANSITION_TYPED); | 180 GURL(chrome::kChromeUINewTabURL), |
| 181 content::PAGE_TRANSITION_TYPED); |
180 contents->web_contents()->SetNewTabStartTime(newTabStartTime); | 182 contents->web_contents()->SetNewTabStartTime(newTabStartTime); |
181 [aTab setTabContent:contents]; | 183 [aTab setTabContent:contents]; |
182 } | 184 } |
183 | 185 |
184 - (void)insertInTabs:(TabAppleScript*)aTab atIndex:(int)index { | 186 - (void)insertInTabs:(TabAppleScript*)aTab atIndex:(int)index { |
185 // This method gets called when a new tab is created so | 187 // This method gets called when a new tab is created so |
186 // the container and property are set here. | 188 // the container and property are set here. |
187 [aTab setContainer:self | 189 [aTab setContainer:self |
188 property:AppleScript::kTabsProperty]; | 190 property:AppleScript::kTabsProperty]; |
189 | 191 |
190 // Set how long it takes a tab to be created. | 192 // Set how long it takes a tab to be created. |
191 base::TimeTicks newTabStartTime = base::TimeTicks::Now(); | 193 base::TimeTicks newTabStartTime = base::TimeTicks::Now(); |
192 browser::NavigateParams params(browser_, | 194 browser::NavigateParams params(browser_, |
193 GURL(chrome::kChromeUINewTabURL), | 195 GURL(chrome::kChromeUINewTabURL), |
194 content::PAGE_TRANSITION_TYPED); | 196 content::PAGE_TRANSITION_TYPED); |
195 params.disposition = NEW_FOREGROUND_TAB; | 197 params.disposition = NEW_FOREGROUND_TAB; |
196 params.tabstrip_index = index; | 198 params.tabstrip_index = index; |
197 browser::Navigate(¶ms); | 199 browser::Navigate(¶ms); |
198 params.target_contents->web_contents()->SetNewTabStartTime( | 200 params.target_contents->web_contents()->SetNewTabStartTime( |
199 newTabStartTime); | 201 newTabStartTime); |
200 | 202 |
201 [aTab setTabContent:params.target_contents]; | 203 [aTab setTabContent:params.target_contents]; |
202 } | 204 } |
203 | 205 |
204 - (void)removeFromTabsAtIndex:(int)index { | 206 - (void)removeFromTabsAtIndex:(int)index { |
205 browser_->CloseTabContents(browser_->GetWebContentsAt(index)); | 207 chrome::CloseWebContents(browser_, chrome::GetWebContentsAt(browser_, index)); |
206 } | 208 } |
207 | 209 |
208 - (NSNumber*)orderedIndex { | 210 - (NSNumber*)orderedIndex { |
209 return [NSNumber numberWithInt:[[self nativeHandle] orderedIndex]]; | 211 return [NSNumber numberWithInt:[[self nativeHandle] orderedIndex]]; |
210 } | 212 } |
211 | 213 |
212 - (void)setOrderedIndex:(NSNumber*)anIndex { | 214 - (void)setOrderedIndex:(NSNumber*)anIndex { |
213 int index = [anIndex intValue] - 1; | 215 int index = [anIndex intValue] - 1; |
214 if (index < 0 || index >= (int)BrowserList::size()) { | 216 if (index < 0 || index >= (int)BrowserList::size()) { |
215 AppleScript::SetError(AppleScript::errWrongIndex); | 217 AppleScript::SetError(AppleScript::errWrongIndex); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 GURL(), FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION); | 260 GURL(), FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION); |
259 } | 261 } |
260 } | 262 } |
261 | 263 |
262 - (void)handlesExitPresentationMode:(NSScriptCommand*)command { | 264 - (void)handlesExitPresentationMode:(NSScriptCommand*)command { |
263 if (browser_->window()) | 265 if (browser_->window()) |
264 browser_->window()->ExitPresentationMode(); | 266 browser_->window()->ExitPresentationMode(); |
265 } | 267 } |
266 | 268 |
267 @end | 269 @end |
OLD | NEW |