Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chrome/browser/ui/cocoa/applescript/tab_applescript.mm

Issue 8892011: Clean up TCW, make it solely a hub for 1:1 observer/helper objects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/navigation_entry.h" 24 #include "content/browser/tab_contents/navigation_entry.h"
25 #include "content/browser/tab_contents/tab_contents.h"
25 #include "content/browser/tab_contents/tab_contents_delegate.h" 26 #include "content/browser/tab_contents/tab_contents_delegate.h"
26 #include "googleurl/src/gurl.h" 27 #include "googleurl/src/gurl.h"
27 28
28 @interface AnyResultValue : NSObject { 29 @interface AnyResultValue : NSObject {
29 @private 30 @private
30 scoped_nsobject<NSAppleEventDescriptor> descriptor; 31 scoped_nsobject<NSAppleEventDescriptor> descriptor;
31 } 32 }
32 - (id)initWithDescriptor:(NSAppleEventDescriptor*)desc; 33 - (id)initWithDescriptor:(NSAppleEventDescriptor*)desc;
33 - (NSAppleEventDescriptor *)scriptingAnyDescriptor; 34 - (NSAppleEventDescriptor *)scriptingAnyDescriptor;
34 @end 35 @end
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 179
179 if ([self tempURL]) 180 if ([self tempURL])
180 [self setURL:[self tempURL]]; 181 [self setURL:[self tempURL]];
181 } 182 }
182 183
183 - (NSString*)URL { 184 - (NSString*)URL {
184 if (!tabContents_) { 185 if (!tabContents_) {
185 return nil; 186 return nil;
186 } 187 }
187 188
188 NavigationEntry* entry = tabContents_->controller().GetActiveEntry(); 189 NavigationEntry* entry =
190 tabContents_->tab_contents()->controller().GetActiveEntry();
189 if (!entry) { 191 if (!entry) {
190 return nil; 192 return nil;
191 } 193 }
192 const GURL& url = entry->virtual_url(); 194 const GURL& url = entry->virtual_url();
193 return base::SysUTF8ToNSString(url.spec()); 195 return base::SysUTF8ToNSString(url.spec());
194 } 196 }
195 197
196 - (void)setURL:(NSString*)aURL { 198 - (void)setURL:(NSString*)aURL {
197 // If a scripter sets a URL before the node is added save it at a temporary 199 // If a scripter sets a URL before the node is added save it at a temporary
198 // location. 200 // location.
199 if (!tabContents_) { 201 if (!tabContents_) {
200 [self setTempURL:aURL]; 202 [self setTempURL:aURL];
201 return; 203 return;
202 } 204 }
203 205
204 GURL url(base::SysNSStringToUTF8(aURL)); 206 GURL url(base::SysNSStringToUTF8(aURL));
205 // check for valid url. 207 // check for valid url.
206 if (!url.is_empty() && !url.is_valid()) { 208 if (!url.is_empty() && !url.is_valid()) {
207 AppleScript::SetError(AppleScript::errInvalidURL); 209 AppleScript::SetError(AppleScript::errInvalidURL);
208 return; 210 return;
209 } 211 }
210 212
211 NavigationEntry* entry = tabContents_->controller().GetActiveEntry(); 213 NavigationEntry* entry =
214 tabContents_->tab_contents()->controller().GetActiveEntry();
212 if (!entry) 215 if (!entry)
213 return; 216 return;
214 217
215 const GURL& previousURL = entry->virtual_url(); 218 const GURL& previousURL = entry->virtual_url();
216 tabContents_->tab_contents()->OpenURL(OpenURLParams( 219 tabContents_->tab_contents()->OpenURL(OpenURLParams(
217 url, 220 url,
218 content::Referrer(previousURL, WebKit::WebReferrerPolicyDefault), 221 content::Referrer(previousURL, WebKit::WebReferrerPolicyDefault),
219 CURRENT_TAB, 222 CURRENT_TAB,
220 content::PAGE_TRANSITION_TYPED, 223 content::PAGE_TRANSITION_TYPED,
221 false)); 224 false));
222 } 225 }
223 226
224 - (NSString*)title { 227 - (NSString*)title {
225 NavigationEntry* entry = tabContents_->controller().GetActiveEntry(); 228 NavigationEntry* entry =
229 tabContents_->tab_contents()->controller().GetActiveEntry();
226 if (!entry) 230 if (!entry)
227 return nil; 231 return nil;
228 232
229 std::wstring title; 233 std::wstring title;
230 if (entry != NULL) { 234 if (entry != NULL) {
231 title = UTF16ToWideHack(entry->title()); 235 title = UTF16ToWideHack(entry->title());
232 } 236 }
233 237
234 return base::SysWideToNSString(title); 238 return base::SysWideToNSString(title);
235 } 239 }
236 240
237 - (NSNumber*)loading { 241 - (NSNumber*)loading {
238 BOOL loadingValue = tabContents_->tab_contents()->IsLoading() ? YES : NO; 242 BOOL loadingValue = tabContents_->tab_contents()->IsLoading() ? YES : NO;
239 return [NSNumber numberWithBool:loadingValue]; 243 return [NSNumber numberWithBool:loadingValue];
240 } 244 }
241 245
242 - (void)handlesUndoScriptCommand:(NSScriptCommand*)command { 246 - (void)handlesUndoScriptCommand:(NSScriptCommand*)command {
243 RenderViewHost* view = tabContents_->render_view_host(); 247 RenderViewHost* view = tabContents_->tab_contents()->render_view_host();
244 if (!view) { 248 if (!view) {
245 NOTREACHED(); 249 NOTREACHED();
246 return; 250 return;
247 } 251 }
248 252
249 view->Undo(); 253 view->Undo();
250 } 254 }
251 255
252 - (void)handlesRedoScriptCommand:(NSScriptCommand*)command { 256 - (void)handlesRedoScriptCommand:(NSScriptCommand*)command {
253 RenderViewHost* view = tabContents_->render_view_host(); 257 RenderViewHost* view = tabContents_->tab_contents()->render_view_host();
254 if (!view) { 258 if (!view) {
255 NOTREACHED(); 259 NOTREACHED();
256 return; 260 return;
257 } 261 }
258 262
259 view->Redo(); 263 view->Redo();
260 } 264 }
261 265
262 - (void)handlesCutScriptCommand:(NSScriptCommand*)command { 266 - (void)handlesCutScriptCommand:(NSScriptCommand*)command {
263 RenderViewHost* view = tabContents_->render_view_host(); 267 RenderViewHost* view = tabContents_->tab_contents()->render_view_host();
264 if (!view) { 268 if (!view) {
265 NOTREACHED(); 269 NOTREACHED();
266 return; 270 return;
267 } 271 }
268 272
269 view->Cut(); 273 view->Cut();
270 } 274 }
271 275
272 - (void)handlesCopyScriptCommand:(NSScriptCommand*)command { 276 - (void)handlesCopyScriptCommand:(NSScriptCommand*)command {
273 RenderViewHost* view = tabContents_->render_view_host(); 277 RenderViewHost* view = tabContents_->tab_contents()->render_view_host();
274 if (!view) { 278 if (!view) {
275 NOTREACHED(); 279 NOTREACHED();
276 return; 280 return;
277 } 281 }
278 282
279 view->Copy(); 283 view->Copy();
280 } 284 }
281 285
282 - (void)handlesPasteScriptCommand:(NSScriptCommand*)command { 286 - (void)handlesPasteScriptCommand:(NSScriptCommand*)command {
283 RenderViewHost* view = tabContents_->render_view_host(); 287 RenderViewHost* view = tabContents_->tab_contents()->render_view_host();
284 if (!view) { 288 if (!view) {
285 NOTREACHED(); 289 NOTREACHED();
286 return; 290 return;
287 } 291 }
288 292
289 view->Paste(); 293 view->Paste();
290 } 294 }
291 295
292 - (void)handlesSelectAllScriptCommand:(NSScriptCommand*)command { 296 - (void)handlesSelectAllScriptCommand:(NSScriptCommand*)command {
293 RenderViewHost* view = tabContents_->render_view_host(); 297 RenderViewHost* view = tabContents_->tab_contents()->render_view_host();
294 if (!view) { 298 if (!view) {
295 NOTREACHED(); 299 NOTREACHED();
296 return; 300 return;
297 } 301 }
298 302
299 view->SelectAll(); 303 view->SelectAll();
300 } 304 }
301 305
302 - (void)handlesGoBackScriptCommand:(NSScriptCommand*)command { 306 - (void)handlesGoBackScriptCommand:(NSScriptCommand*)command {
303 NavigationController& navigationController = tabContents_->controller(); 307 NavigationController& navigationController =
308 tabContents_->tab_contents()->controller();
304 if (navigationController.CanGoBack()) 309 if (navigationController.CanGoBack())
305 navigationController.GoBack(); 310 navigationController.GoBack();
306 } 311 }
307 312
308 - (void)handlesGoForwardScriptCommand:(NSScriptCommand*)command { 313 - (void)handlesGoForwardScriptCommand:(NSScriptCommand*)command {
309 NavigationController& navigationController = tabContents_->controller(); 314 NavigationController& navigationController =
315 tabContents_->tab_contents()->controller();
310 if (navigationController.CanGoForward()) 316 if (navigationController.CanGoForward())
311 navigationController.GoForward(); 317 navigationController.GoForward();
312 } 318 }
313 319
314 - (void)handlesReloadScriptCommand:(NSScriptCommand*)command { 320 - (void)handlesReloadScriptCommand:(NSScriptCommand*)command {
315 NavigationController& navigationController = tabContents_->controller(); 321 NavigationController& navigationController =
322 tabContents_->tab_contents()->controller();
316 const bool checkForRepost = true; 323 const bool checkForRepost = true;
317 navigationController.Reload(checkForRepost); 324 navigationController.Reload(checkForRepost);
318 } 325 }
319 326
320 - (void)handlesStopScriptCommand:(NSScriptCommand*)command { 327 - (void)handlesStopScriptCommand:(NSScriptCommand*)command {
321 RenderViewHost* view = tabContents_->render_view_host(); 328 RenderViewHost* view = tabContents_->tab_contents()->render_view_host();
322 if (!view) { 329 if (!view) {
323 // We tolerate Stop being called even before a view has been created. 330 // We tolerate Stop being called even before a view has been created.
324 // So just log a warning instead of a NOTREACHED(). 331 // So just log a warning instead of a NOTREACHED().
325 DLOG(WARNING) << "Stop: no view for handle "; 332 DLOG(WARNING) << "Stop: no view for handle ";
326 return; 333 return;
327 } 334 }
328 335
329 view->Stop(); 336 view->Stop();
330 } 337 }
331 338
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 directoryPath, 380 directoryPath,
374 savePackageType); 381 savePackageType);
375 } 382 }
376 383
377 - (void)handlesCloseScriptCommand:(NSScriptCommand*)command { 384 - (void)handlesCloseScriptCommand:(NSScriptCommand*)command {
378 TabContents* contents = tabContents_->tab_contents(); 385 TabContents* contents = tabContents_->tab_contents();
379 contents->delegate()->CloseContents(contents); 386 contents->delegate()->CloseContents(contents);
380 } 387 }
381 388
382 - (void)handlesViewSourceScriptCommand:(NSScriptCommand*)command { 389 - (void)handlesViewSourceScriptCommand:(NSScriptCommand*)command {
383 NavigationEntry* entry = tabContents_->controller().GetLastCommittedEntry(); 390 NavigationEntry* entry =
391 tabContents_->tab_contents()->controller().GetLastCommittedEntry();
384 if (entry) { 392 if (entry) {
385 tabContents_->tab_contents()->OpenURL( 393 tabContents_->tab_contents()->OpenURL(
386 GURL(chrome::kViewSourceScheme + std::string(":") + 394 GURL(chrome::kViewSourceScheme + std::string(":") +
387 entry->url().spec()), 395 entry->url().spec()),
388 GURL(), 396 GURL(),
389 NEW_FOREGROUND_TAB, 397 NEW_FOREGROUND_TAB,
390 content::PAGE_TRANSITION_LINK); 398 content::PAGE_TRANSITION_LINK);
391 } 399 }
392 } 400 }
393 401
394 - (id)handlesExecuteJavascriptScriptCommand:(NSScriptCommand*)command { 402 - (id)handlesExecuteJavascriptScriptCommand:(NSScriptCommand*)command {
395 RenderViewHost* view = tabContents_->render_view_host(); 403 RenderViewHost* view = tabContents_->tab_contents()->render_view_host();
396 if (!view) { 404 if (!view) {
397 NOTREACHED(); 405 NOTREACHED();
398 return nil; 406 return nil;
399 } 407 }
400 408
401 string16 script = base::SysNSStringToUTF16( 409 string16 script = base::SysNSStringToUTF16(
402 [[command evaluatedArguments] objectForKey:@"javascript"]); 410 [[command evaluatedArguments] objectForKey:@"javascript"]);
403 Value* value = view->ExecuteJavascriptAndGetValue(string16(), script); 411 Value* value = view->ExecuteJavascriptAndGetValue(string16(), script);
404 NSAppleEventDescriptor* descriptor = valueToDescriptor(value); 412 NSAppleEventDescriptor* descriptor = valueToDescriptor(value);
405 return [[[AnyResultValue alloc] initWithDescriptor:descriptor] autorelease]; 413 return [[[AnyResultValue alloc] initWithDescriptor:descriptor] autorelease];
406 } 414 }
407 415
408 @end 416 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_list_unittest.cc ('k') | chrome/browser/ui/cocoa/constrained_window_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698