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 3// found in the LICENSE file. 4 5#import "chrome/browser/ui/cocoa/applescript/bookmark_item_applescript.h" 6 7#include "base/sys_string_conversions.h" 8#include "chrome/browser/bookmarks/bookmark_model.h" 9#include "chrome/browser/profiles/profile_manager.h" 10#import "chrome/browser/ui/cocoa/applescript/error_applescript.h" 11 12@interface BookmarkItemAppleScript() 13@property (nonatomic, copy) NSString* tempURL; 14@end 15 16@implementation BookmarkItemAppleScript 17 18@synthesize tempURL = tempURL_; 19 20- (id)init { 21 if ((self = [super init])) { 22 [self setTempURL:@""]; 23 } 24 return self; 25} 26 27- (void)dealloc { 28 [tempURL_ release]; 29 [super dealloc]; 30} 31 32- (void)setBookmarkNode:(const BookmarkNode*)aBookmarkNode { 33 [super setBookmarkNode:aBookmarkNode]; 34 [self setURL:[self tempURL]]; 35} 36 37- (NSString*)URL { 38 if (!bookmarkNode_) 39 return tempURL_; 40 41 const GURL& url = bookmarkNode_->GetURL(); 42 return base::SysUTF8ToNSString(url.spec()); 43} 44 45- (void)setURL:(NSString*)aURL { 46 // If a scripter sets a URL before the node is added, URL is saved at a 47 // temporary location. 48 if (!bookmarkNode_) { 49 [self setTempURL:aURL]; 50 return; 51 } 52 53 BookmarkModel* model = [self bookmarkModel]; 54 if (!model) 55 return; 56 57 GURL url(base::SysNSStringToUTF8(aURL)); 58 if (!url.is_valid()) { 59 AppleScript::SetError(AppleScript::errInvalidURL); 60 return; 61 } 62 63 model->SetURL(bookmarkNode_, url); 64} 65 66@end 67