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/tab_applescript.h" | 5 #import "chrome/browser/ui/cocoa/applescript/tab_applescript.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 AppleScript::SetError(AppleScript::errInvalidURL); | 139 AppleScript::SetError(AppleScript::errInvalidURL); |
140 return; | 140 return; |
141 } | 141 } |
142 | 142 |
143 NavigationEntry* entry = webContents_->GetController().GetActiveEntry(); | 143 NavigationEntry* entry = webContents_->GetController().GetActiveEntry(); |
144 if (!entry) | 144 if (!entry) |
145 return; | 145 return; |
146 | 146 |
147 const GURL& previousURL = entry->GetVirtualURL(); | 147 const GURL& previousURL = entry->GetVirtualURL(); |
148 webContents_->OpenURL(OpenURLParams( | 148 webContents_->OpenURL(OpenURLParams( |
149 url, | 149 url, content::Referrer(previousURL, blink::WebReferrerPolicyDefault), |
150 content::Referrer(previousURL, blink::WebReferrerPolicyDefault), | 150 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); |
151 CURRENT_TAB, | |
152 ui::PAGE_TRANSITION_TYPED, | |
153 false)); | |
154 } | 151 } |
155 | 152 |
156 - (NSString*)title { | 153 - (NSString*)title { |
157 NavigationEntry* entry = webContents_->GetController().GetActiveEntry(); | 154 NavigationEntry* entry = webContents_->GetController().GetActiveEntry(); |
158 if (!entry) | 155 if (!entry) |
159 return nil; | 156 return nil; |
160 | 157 |
161 base::string16 title = entry ? entry->GetTitle() : base::string16(); | 158 base::string16 title = entry ? entry->GetTitle() : base::string16(); |
162 return base::SysUTF16ToNSString(title); | 159 return base::SysUTF16ToNSString(title); |
163 } | 160 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 274 |
278 - (void)handlesViewSourceScriptCommand:(NSScriptCommand*)command { | 275 - (void)handlesViewSourceScriptCommand:(NSScriptCommand*)command { |
279 AppleScript::LogAppleScriptUMA( | 276 AppleScript::LogAppleScriptUMA( |
280 AppleScript::AppleScriptCommand::TAB_VIEW_SOURCE); | 277 AppleScript::AppleScriptCommand::TAB_VIEW_SOURCE); |
281 NavigationEntry* entry = | 278 NavigationEntry* entry = |
282 webContents_->GetController().GetLastCommittedEntry(); | 279 webContents_->GetController().GetLastCommittedEntry(); |
283 if (entry) { | 280 if (entry) { |
284 webContents_->OpenURL( | 281 webContents_->OpenURL( |
285 OpenURLParams(GURL(content::kViewSourceScheme + std::string(":") + | 282 OpenURLParams(GURL(content::kViewSourceScheme + std::string(":") + |
286 entry->GetURL().spec()), | 283 entry->GetURL().spec()), |
287 Referrer(), | 284 Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, |
288 NEW_FOREGROUND_TAB, | 285 ui::PAGE_TRANSITION_LINK, false)); |
289 ui::PAGE_TRANSITION_LINK, | |
290 false)); | |
291 } | 286 } |
292 } | 287 } |
293 | 288 |
294 - (id)handlesExecuteJavascriptScriptCommand:(NSScriptCommand*)command { | 289 - (id)handlesExecuteJavascriptScriptCommand:(NSScriptCommand*)command { |
295 AppleScript::LogAppleScriptUMA( | 290 AppleScript::LogAppleScriptUMA( |
296 AppleScript::AppleScriptCommand::TAB_EXECUTE_JAVASCRIPT); | 291 AppleScript::AppleScriptCommand::TAB_EXECUTE_JAVASCRIPT); |
297 content::RenderFrameHost* frame = webContents_->GetMainFrame(); | 292 content::RenderFrameHost* frame = webContents_->GetMainFrame(); |
298 if (!frame) { | 293 if (!frame) { |
299 NOTREACHED(); | 294 NOTREACHED(); |
300 return nil; | 295 return nil; |
301 } | 296 } |
302 | 297 |
303 NSAppleEventManager* manager = [NSAppleEventManager sharedAppleEventManager]; | 298 NSAppleEventManager* manager = [NSAppleEventManager sharedAppleEventManager]; |
304 NSAppleEventManagerSuspensionID suspensionID = | 299 NSAppleEventManagerSuspensionID suspensionID = |
305 [manager suspendCurrentAppleEvent]; | 300 [manager suspendCurrentAppleEvent]; |
306 content::RenderFrameHost::JavaScriptResultCallback callback = | 301 content::RenderFrameHost::JavaScriptResultCallback callback = |
307 base::Bind(&ResumeAppleEventAndSendReply, suspensionID); | 302 base::Bind(&ResumeAppleEventAndSendReply, suspensionID); |
308 | 303 |
309 base::string16 script = base::SysNSStringToUTF16( | 304 base::string16 script = base::SysNSStringToUTF16( |
310 [[command evaluatedArguments] objectForKey:@"javascript"]); | 305 [[command evaluatedArguments] objectForKey:@"javascript"]); |
311 frame->ExecuteJavaScriptInIsolatedWorld( | 306 frame->ExecuteJavaScriptInIsolatedWorld( |
312 script, callback, chrome::ISOLATED_WORLD_ID_APPLESCRIPT); | 307 script, callback, chrome::ISOLATED_WORLD_ID_APPLESCRIPT); |
313 | 308 |
314 return nil; | 309 return nil; |
315 } | 310 } |
316 | 311 |
317 @end | 312 @end |
OLD | NEW |