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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/applescript/bookmark_item_applescript.h"
7 #include "base/strings/sys_string_conversions.h"
8 #include "chrome/browser/profiles/profile_manager.h"
9 #import "chrome/browser/ui/cocoa/applescript/error_applescript.h"
10 #include "components/bookmarks/browser/bookmark_model.h"
12 using bookmarks::BookmarkModel;
13 using bookmarks::BookmarkNode;
15 @interface BookmarkItemAppleScript()
16 @property (nonatomic, copy) NSString* tempURL;
19 @implementation BookmarkItemAppleScript
21 @synthesize tempURL = tempURL_;
24 if ((self = [super init])) {
25 [self setTempURL:@""];
35 - (void)setBookmarkNode:(const BookmarkNode*)aBookmarkNode {
36 [super setBookmarkNode:aBookmarkNode];
37 [self setURL:[self tempURL]];
44 return base::SysUTF8ToNSString(bookmarkNode_->url().spec());
47 - (void)setURL:(NSString*)aURL {
48 // If a scripter sets a URL before the node is added, URL is saved at a
49 // temporary location.
51 [self setTempURL:aURL];
55 BookmarkModel* model = [self bookmarkModel];
59 GURL url(base::SysNSStringToUTF8(aURL));
60 if (!url.is_valid()) {
61 AppleScript::SetError(AppleScript::errInvalidURL);
65 model->SetURL(bookmarkNode_, url);