| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/applescript/window_applescript.h" | 5 #import "chrome/browser/cocoa/applescript/window_applescript.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/scoped_nsobject.h" | 8 #import "base/scoped_nsobject.h" |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/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 #include "chrome/browser/browser.h" | 12 #include "chrome/browser/browser.h" |
| 13 #include "chrome/browser/browser_list.h" | 13 #include "chrome/browser/browser_list.h" |
| 14 #include "chrome/browser/browser_window.h" | 14 #include "chrome/browser/browser_window.h" |
| 15 #import "chrome/browser/chrome_browser_application_mac.h" | 15 #import "chrome/browser/chrome_browser_application_mac.h" |
| 16 #include "chrome/browser/cocoa/applescript/constants_applescript.h" | 16 #include "chrome/browser/cocoa/applescript/constants_applescript.h" |
| 17 #include "chrome/browser/cocoa/applescript/error_applescript.h" | 17 #include "chrome/browser/cocoa/applescript/error_applescript.h" |
| 18 #import "chrome/browser/cocoa/applescript/tab_applescript.h" | 18 #import "chrome/browser/cocoa/applescript/tab_applescript.h" |
| 19 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
| 20 #include "chrome/browser/tab_contents/tab_contents.h" | 20 #include "chrome/browser/tab_contents/tab_contents.h" |
| 21 #include "chrome/browser/tab_contents_wrapper.h" |
| 21 #include "chrome/browser/tabs/tab_strip_model.h" | 22 #include "chrome/browser/tabs/tab_strip_model.h" |
| 22 #include "chrome/browser/ui/browser_navigator.h" | 23 #include "chrome/browser/ui/browser_navigator.h" |
| 23 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 24 | 25 |
| 25 @interface WindowAppleScript(WindowAppleScriptPrivateMethods) | 26 @interface WindowAppleScript(WindowAppleScriptPrivateMethods) |
| 26 // The NSWindow that corresponds to this window. | 27 // The NSWindow that corresponds to this window. |
| 27 - (NSWindow*)nativeHandle; | 28 - (NSWindow*)nativeHandle; |
| 28 @end | 29 @end |
| 29 | 30 |
| 30 @implementation WindowAppleScript | 31 @implementation WindowAppleScript |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } | 164 } |
| 164 | 165 |
| 165 - (void)insertInTabs:(TabAppleScript*)aTab { | 166 - (void)insertInTabs:(TabAppleScript*)aTab { |
| 166 // This method gets called when a new tab is created so | 167 // This method gets called when a new tab is created so |
| 167 // the container and property are set here. | 168 // the container and property are set here. |
| 168 [aTab setContainer:self | 169 [aTab setContainer:self |
| 169 property:AppleScript::kTabsProperty]; | 170 property:AppleScript::kTabsProperty]; |
| 170 | 171 |
| 171 // Set how long it takes a tab to be created. | 172 // Set how long it takes a tab to be created. |
| 172 base::TimeTicks newTabStartTime = base::TimeTicks::Now(); | 173 base::TimeTicks newTabStartTime = base::TimeTicks::Now(); |
| 173 TabContents* contents = | 174 TabContentsWrapper* contents = |
| 174 browser_->AddSelectedTabWithURL(GURL(chrome::kChromeUINewTabURL), | 175 browser_->AddSelectedTabWithURL(GURL(chrome::kChromeUINewTabURL), |
| 175 PageTransition::TYPED); | 176 PageTransition::TYPED); |
| 176 contents->set_new_tab_start_time(newTabStartTime); | 177 contents->tab_contents()->set_new_tab_start_time(newTabStartTime); |
| 177 | 178 [aTab setTabContent:contents->tab_contents()]; |
| 178 [aTab setTabContent:contents]; | |
| 179 } | 179 } |
| 180 | 180 |
| 181 - (void)insertInTabs:(TabAppleScript*)aTab atIndex:(int)index { | 181 - (void)insertInTabs:(TabAppleScript*)aTab atIndex:(int)index { |
| 182 // This method gets called when a new tab is created so | 182 // This method gets called when a new tab is created so |
| 183 // This method gets called when a new tab is created so |
| 183 // the container and property are set here. | 184 // the container and property are set here. |
| 184 [aTab setContainer:self | 185 [aTab setContainer:self |
| 185 property:AppleScript::kTabsProperty]; | 186 property:AppleScript::kTabsProperty]; |
| 186 | 187 |
| 187 // Set how long it takes a tab to be created. | 188 // Set how long it takes a tab to be created. |
| 188 base::TimeTicks newTabStartTime = base::TimeTicks::Now(); | 189 base::TimeTicks newTabStartTime = base::TimeTicks::Now(); |
| 189 browser::NavigateParams params(browser_, | 190 browser::NavigateParams params(browser_, |
| 190 GURL(chrome::kChromeUINewTabURL), | 191 GURL(chrome::kChromeUINewTabURL), |
| 191 PageTransition::TYPED); | 192 PageTransition::TYPED); |
| 192 params.disposition = NEW_FOREGROUND_TAB; | 193 params.disposition = NEW_FOREGROUND_TAB; |
| 193 params.tabstrip_index = index; | 194 params.tabstrip_index = index; |
| 194 browser::Navigate(¶ms); | 195 browser::Navigate(¶ms); |
| 195 params.target_contents->set_new_tab_start_time(newTabStartTime); | 196 params.target_contents->tab_contents()->set_new_tab_start_time( |
| 197 newTabStartTime); |
| 196 | 198 |
| 197 [aTab setTabContent:params.target_contents]; | 199 [aTab setTabContent:params.target_contents->tab_contents()]; |
| 198 } | 200 } |
| 199 | 201 |
| 200 - (void)removeFromTabsAtIndex:(int)index { | 202 - (void)removeFromTabsAtIndex:(int)index { |
| 201 browser_->tabstrip_model()->DetachTabContentsAt(index); | 203 browser_->tabstrip_model()->DetachTabContentsAt(index); |
| 202 } | 204 } |
| 203 | 205 |
| 204 - (NSNumber*)orderedIndex{ | 206 - (NSNumber*)orderedIndex{ |
| 205 return [NSNumber numberWithInt:[[self nativeHandle] orderedIndex]]; | 207 return [NSNumber numberWithInt:[[self nativeHandle] orderedIndex]]; |
| 206 } | 208 } |
| 207 | 209 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 235 [[self nativeHandle] setValue:(id)value forKey:key]; | 237 [[self nativeHandle] setValue:(id)value forKey:key]; |
| 236 } | 238 } |
| 237 | 239 |
| 238 - (void)handlesCloseScriptCommand:(NSCloseCommand*)command { | 240 - (void)handlesCloseScriptCommand:(NSCloseCommand*)command { |
| 239 // window() can be NULL during startup. | 241 // window() can be NULL during startup. |
| 240 if (browser_->window()) | 242 if (browser_->window()) |
| 241 browser_->window()->Close(); | 243 browser_->window()->Close(); |
| 242 } | 244 } |
| 243 | 245 |
| 244 @end | 246 @end |
| OLD | NEW |