| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tab_applescript.h" | 5 #import "chrome/browser/ui/cocoa/applescript/tab_applescript.h" |
| 6 | 6 |
| 7 #import <Carbon/Carbon.h> | 7 #import <Carbon/Carbon.h> |
| 8 #import <Foundation/NSAppleEventDescriptor.h> | 8 #import <Foundation/NSAppleEventDescriptor.h> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #import "base/memory/scoped_nsobject.h" | 12 #import "base/memory/scoped_nsobject.h" |
| 13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/printing/print_view_manager.h" | 15 #include "chrome/browser/printing/print_view_manager.h" |
| 16 #include "chrome/browser/sessions/restore_tab_helper.h" | 16 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 17 #include "chrome/browser/sessions/session_id.h" | 17 #include "chrome/browser/sessions/session_id.h" |
| 18 #include "chrome/browser/ui/cocoa/applescript/error_applescript.h" | 18 #include "chrome/browser/ui/cocoa/applescript/error_applescript.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 21 #include "content/browser/download/save_package.h" | 21 #include "content/browser/download/save_package.h" |
| 22 #include "content/browser/renderer_host/render_view_host.h" | 22 #include "content/browser/renderer_host/render_view_host.h" |
| 23 #include "content/browser/tab_contents/navigation_controller.h" | 23 #include "content/browser/tab_contents/navigation_controller.h" |
| 24 #include "content/browser/tab_contents/tab_contents.h" | 24 #include "content/browser/tab_contents/tab_contents.h" |
| 25 #include "content/public/browser/navigation_entry.h" | 25 #include "content/public/browser/navigation_entry.h" |
| 26 #include "content/public/browser/web_contents_delegate.h" | 26 #include "content/public/browser/web_contents_delegate.h" |
| 27 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
| 28 | 28 |
| 29 using content::NavigationEntry; |
| 29 using content::OpenURLParams; | 30 using content::OpenURLParams; |
| 30 using content::Referrer; | 31 using content::Referrer; |
| 31 | 32 |
| 32 @interface AnyResultValue : NSObject { | 33 @interface AnyResultValue : NSObject { |
| 33 @private | 34 @private |
| 34 scoped_nsobject<NSAppleEventDescriptor> descriptor; | 35 scoped_nsobject<NSAppleEventDescriptor> descriptor; |
| 35 } | 36 } |
| 36 - (id)initWithDescriptor:(NSAppleEventDescriptor*)desc; | 37 - (id)initWithDescriptor:(NSAppleEventDescriptor*)desc; |
| 37 - (NSAppleEventDescriptor *)scriptingAnyDescriptor; | 38 - (NSAppleEventDescriptor *)scriptingAnyDescriptor; |
| 38 @end | 39 @end |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 183 |
| 183 if ([self tempURL]) | 184 if ([self tempURL]) |
| 184 [self setURL:[self tempURL]]; | 185 [self setURL:[self tempURL]]; |
| 185 } | 186 } |
| 186 | 187 |
| 187 - (NSString*)URL { | 188 - (NSString*)URL { |
| 188 if (!tabContents_) { | 189 if (!tabContents_) { |
| 189 return nil; | 190 return nil; |
| 190 } | 191 } |
| 191 | 192 |
| 192 content::NavigationEntry* entry = | 193 NavigationEntry* entry = |
| 193 tabContents_->tab_contents()->GetController().GetActiveEntry(); | 194 tabContents_->tab_contents()->GetController().GetActiveEntry(); |
| 194 if (!entry) { | 195 if (!entry) { |
| 195 return nil; | 196 return nil; |
| 196 } | 197 } |
| 197 const GURL& url = entry->GetVirtualURL(); | 198 const GURL& url = entry->GetVirtualURL(); |
| 198 return base::SysUTF8ToNSString(url.spec()); | 199 return base::SysUTF8ToNSString(url.spec()); |
| 199 } | 200 } |
| 200 | 201 |
| 201 - (void)setURL:(NSString*)aURL { | 202 - (void)setURL:(NSString*)aURL { |
| 202 // If a scripter sets a URL before the node is added save it at a temporary | 203 // If a scripter sets a URL before the node is added save it at a temporary |
| 203 // location. | 204 // location. |
| 204 if (!tabContents_) { | 205 if (!tabContents_) { |
| 205 [self setTempURL:aURL]; | 206 [self setTempURL:aURL]; |
| 206 return; | 207 return; |
| 207 } | 208 } |
| 208 | 209 |
| 209 GURL url(base::SysNSStringToUTF8(aURL)); | 210 GURL url(base::SysNSStringToUTF8(aURL)); |
| 210 // check for valid url. | 211 // check for valid url. |
| 211 if (!url.is_empty() && !url.is_valid()) { | 212 if (!url.is_empty() && !url.is_valid()) { |
| 212 AppleScript::SetError(AppleScript::errInvalidURL); | 213 AppleScript::SetError(AppleScript::errInvalidURL); |
| 213 return; | 214 return; |
| 214 } | 215 } |
| 215 | 216 |
| 216 content::NavigationEntry* entry = | 217 NavigationEntry* entry = |
| 217 tabContents_->tab_contents()->GetController().GetActiveEntry(); | 218 tabContents_->tab_contents()->GetController().GetActiveEntry(); |
| 218 if (!entry) | 219 if (!entry) |
| 219 return; | 220 return; |
| 220 | 221 |
| 221 const GURL& previousURL = entry->GetVirtualURL(); | 222 const GURL& previousURL = entry->GetVirtualURL(); |
| 222 tabContents_->tab_contents()->OpenURL(OpenURLParams( | 223 tabContents_->tab_contents()->OpenURL(OpenURLParams( |
| 223 url, | 224 url, |
| 224 content::Referrer(previousURL, WebKit::WebReferrerPolicyDefault), | 225 content::Referrer(previousURL, WebKit::WebReferrerPolicyDefault), |
| 225 CURRENT_TAB, | 226 CURRENT_TAB, |
| 226 content::PAGE_TRANSITION_TYPED, | 227 content::PAGE_TRANSITION_TYPED, |
| 227 false)); | 228 false)); |
| 228 } | 229 } |
| 229 | 230 |
| 230 - (NSString*)title { | 231 - (NSString*)title { |
| 231 content::NavigationEntry* entry = | 232 NavigationEntry* entry = |
| 232 tabContents_->tab_contents()->GetController().GetActiveEntry(); | 233 tabContents_->tab_contents()->GetController().GetActiveEntry(); |
| 233 if (!entry) | 234 if (!entry) |
| 234 return nil; | 235 return nil; |
| 235 | 236 |
| 236 std::wstring title; | 237 std::wstring title; |
| 237 if (entry != NULL) { | 238 if (entry != NULL) { |
| 238 title = UTF16ToWideHack(entry->GetTitle()); | 239 title = UTF16ToWideHack(entry->GetTitle()); |
| 239 } | 240 } |
| 240 | 241 |
| 241 return base::SysWideToNSString(title); | 242 return base::SysWideToNSString(title); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 directoryPath, | 384 directoryPath, |
| 384 savePackageType); | 385 savePackageType); |
| 385 } | 386 } |
| 386 | 387 |
| 387 - (void)handlesCloseScriptCommand:(NSScriptCommand*)command { | 388 - (void)handlesCloseScriptCommand:(NSScriptCommand*)command { |
| 388 TabContents* contents = tabContents_->tab_contents(); | 389 TabContents* contents = tabContents_->tab_contents(); |
| 389 contents->GetDelegate()->CloseContents(contents); | 390 contents->GetDelegate()->CloseContents(contents); |
| 390 } | 391 } |
| 391 | 392 |
| 392 - (void)handlesViewSourceScriptCommand:(NSScriptCommand*)command { | 393 - (void)handlesViewSourceScriptCommand:(NSScriptCommand*)command { |
| 393 content::NavigationEntry* entry = | 394 NavigationEntry* entry = |
| 394 tabContents_->tab_contents()->GetController().GetLastCommittedEntry(); | 395 tabContents_->tab_contents()->GetController().GetLastCommittedEntry(); |
| 395 if (entry) { | 396 if (entry) { |
| 396 tabContents_->tab_contents()->OpenURL(OpenURLParams( | 397 tabContents_->tab_contents()->OpenURL(OpenURLParams( |
| 397 GURL(chrome::kViewSourceScheme + std::string(":") + | 398 GURL(chrome::kViewSourceScheme + std::string(":") + |
| 398 entry->GetURL().spec()), | 399 entry->GetURL().spec()), |
| 399 Referrer(), | 400 Referrer(), |
| 400 NEW_FOREGROUND_TAB, | 401 NEW_FOREGROUND_TAB, |
| 401 content::PAGE_TRANSITION_LINK, | 402 content::PAGE_TRANSITION_LINK, |
| 402 false)); | 403 false)); |
| 403 } | 404 } |
| 404 } | 405 } |
| 405 | 406 |
| 406 - (id)handlesExecuteJavascriptScriptCommand:(NSScriptCommand*)command { | 407 - (id)handlesExecuteJavascriptScriptCommand:(NSScriptCommand*)command { |
| 407 RenderViewHost* view = tabContents_->tab_contents()->GetRenderViewHost(); | 408 RenderViewHost* view = tabContents_->tab_contents()->GetRenderViewHost(); |
| 408 if (!view) { | 409 if (!view) { |
| 409 NOTREACHED(); | 410 NOTREACHED(); |
| 410 return nil; | 411 return nil; |
| 411 } | 412 } |
| 412 | 413 |
| 413 string16 script = base::SysNSStringToUTF16( | 414 string16 script = base::SysNSStringToUTF16( |
| 414 [[command evaluatedArguments] objectForKey:@"javascript"]); | 415 [[command evaluatedArguments] objectForKey:@"javascript"]); |
| 415 Value* value = view->ExecuteJavascriptAndGetValue(string16(), script); | 416 Value* value = view->ExecuteJavascriptAndGetValue(string16(), script); |
| 416 NSAppleEventDescriptor* descriptor = valueToDescriptor(value); | 417 NSAppleEventDescriptor* descriptor = valueToDescriptor(value); |
| 417 return [[[AnyResultValue alloc] initWithDescriptor:descriptor] autorelease]; | 418 return [[[AnyResultValue alloc] initWithDescriptor:descriptor] autorelease]; |
| 418 } | 419 } |
| 419 | 420 |
| 420 @end | 421 @end |
| OLD | NEW |