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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 if ([self tempURL]) | 107 if ([self tempURL]) |
108 [self setURL:[self tempURL]]; | 108 [self setURL:[self tempURL]]; |
109 } | 109 } |
110 | 110 |
111 - (NSString*)URL { | 111 - (NSString*)URL { |
112 if (!webContents_) { | 112 if (!webContents_) { |
113 return nil; | 113 return nil; |
114 } | 114 } |
115 | 115 |
116 NavigationEntry* entry = webContents_->GetController().GetActiveEntry(); | 116 NavigationEntry* entry = webContents_->GetController().GetVisibleEntry(); |
117 if (!entry) { | 117 if (!entry) { |
118 return nil; | 118 return nil; |
119 } | 119 } |
120 const GURL& url = entry->GetVirtualURL(); | 120 const GURL& url = entry->GetVirtualURL(); |
121 return base::SysUTF8ToNSString(url.spec()); | 121 return base::SysUTF8ToNSString(url.spec()); |
122 } | 122 } |
123 | 123 |
124 - (void)setURL:(NSString*)aURL { | 124 - (void)setURL:(NSString*)aURL { |
125 // If a scripter sets a URL before the node is added save it at a temporary | 125 // If a scripter sets a URL before the node is added save it at a temporary |
126 // location. | 126 // location. |
127 if (!webContents_) { | 127 if (!webContents_) { |
128 [self setTempURL:aURL]; | 128 [self setTempURL:aURL]; |
129 return; | 129 return; |
130 } | 130 } |
131 | 131 |
132 GURL url(base::SysNSStringToUTF8(aURL)); | 132 GURL url(base::SysNSStringToUTF8(aURL)); |
133 // check for valid url. | 133 // check for valid url. |
134 if (!url.is_empty() && !url.is_valid()) { | 134 if (!url.is_empty() && !url.is_valid()) { |
135 AppleScript::SetError(AppleScript::errInvalidURL); | 135 AppleScript::SetError(AppleScript::errInvalidURL); |
136 return; | 136 return; |
137 } | 137 } |
138 | 138 |
139 NavigationEntry* entry = webContents_->GetController().GetActiveEntry(); | 139 NavigationEntry* entry = |
| 140 webContents_->GetController().GetLastCommittedEntry(); |
140 if (!entry) | 141 if (!entry) |
141 return; | 142 return; |
142 | 143 |
143 const GURL& previousURL = entry->GetVirtualURL(); | 144 const GURL& previousURL = entry->GetVirtualURL(); |
144 webContents_->OpenURL(OpenURLParams( | 145 webContents_->OpenURL(OpenURLParams( |
145 url, | 146 url, |
146 content::Referrer(previousURL, blink::WebReferrerPolicyDefault), | 147 content::Referrer(previousURL, blink::WebReferrerPolicyDefault), |
147 CURRENT_TAB, | 148 CURRENT_TAB, |
148 content::PAGE_TRANSITION_TYPED, | 149 content::PAGE_TRANSITION_TYPED, |
149 false)); | 150 false)); |
150 } | 151 } |
151 | 152 |
152 - (NSString*)title { | 153 - (NSString*)title { |
153 NavigationEntry* entry = webContents_->GetController().GetActiveEntry(); | 154 NavigationEntry* entry = |
| 155 webContents_->GetController().GetVisibleEntry(); |
154 if (!entry) | 156 if (!entry) |
155 return nil; | 157 return nil; |
156 | 158 |
157 string16 title = entry ? entry->GetTitle() : string16(); | 159 string16 title = entry ? entry->GetTitle() : string16(); |
158 return base::SysUTF16ToNSString(title); | 160 return base::SysUTF16ToNSString(title); |
159 } | 161 } |
160 | 162 |
161 - (NSNumber*)loading { | 163 - (NSNumber*)loading { |
162 BOOL loadingValue = webContents_->IsLoading() ? YES : NO; | 164 BOOL loadingValue = webContents_->IsLoading() ? YES : NO; |
163 return [NSNumber numberWithBool:loadingValue]; | 165 return [NSNumber numberWithBool:loadingValue]; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 string16 script = base::SysNSStringToUTF16( | 332 string16 script = base::SysNSStringToUTF16( |
331 [[command evaluatedArguments] objectForKey:@"javascript"]); | 333 [[command evaluatedArguments] objectForKey:@"javascript"]); |
332 view->ExecuteJavascriptInWebFrameCallbackResult(string16(), // frame_xpath | 334 view->ExecuteJavascriptInWebFrameCallbackResult(string16(), // frame_xpath |
333 script, | 335 script, |
334 callback); | 336 callback); |
335 | 337 |
336 return nil; | 338 return nil; |
337 } | 339 } |
338 | 340 |
339 @end | 341 @end |
OLD | NEW |