OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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/cocoa/applescript/bookmark_folder_applescript.h" | 5 #import "chrome/browser/cocoa/applescript/bookmark_folder_applescript.h" |
6 | 6 |
7 #import "base/scoped_nsobject.h" | 7 #import "base/scoped_nsobject.h" |
8 #import "base/string16.h" | 8 #import "base/string16.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 return; | 118 return; |
119 | 119 |
120 GURL url = GURL(base::SysNSStringToUTF8([aBookmarkItem URL])); | 120 GURL url = GURL(base::SysNSStringToUTF8([aBookmarkItem URL])); |
121 if (!url.is_valid()) { | 121 if (!url.is_valid()) { |
122 AppleScript::SetError(AppleScript::errInvalidURL); | 122 AppleScript::SetError(AppleScript::errInvalidURL); |
123 return; | 123 return; |
124 } | 124 } |
125 | 125 |
126 const BookmarkNode* node = model->AddURL(bookmarkNode_, | 126 const BookmarkNode* node = model->AddURL(bookmarkNode_, |
127 bookmarkNode_->GetChildCount(), | 127 bookmarkNode_->GetChildCount(), |
128 std::wstring(), | 128 string16(), |
129 url); | 129 url); |
130 if (!node) { | 130 if (!node) { |
131 AppleScript::SetError(AppleScript::errCreateBookmarkItem); | 131 AppleScript::SetError(AppleScript::errCreateBookmarkItem); |
132 return; | 132 return; |
133 } | 133 } |
134 | 134 |
135 [aBookmarkItem setBookmarkNode:node]; | 135 [aBookmarkItem setBookmarkNode:node]; |
136 } | 136 } |
137 | 137 |
138 - (void)insertInBookmarkItems:(BookmarkItemAppleScript*)aBookmarkItem | 138 - (void)insertInBookmarkItems:(BookmarkItemAppleScript*)aBookmarkItem |
139 atIndex:(int)index { | 139 atIndex:(int)index { |
140 // This method gets called when a new bookmark item is created so | 140 // This method gets called when a new bookmark item is created so |
141 // the container and property are set here. | 141 // the container and property are set here. |
142 [aBookmarkItem setContainer:self | 142 [aBookmarkItem setContainer:self |
143 property:AppleScript::kBookmarkItemsProperty]; | 143 property:AppleScript::kBookmarkItemsProperty]; |
144 int position = [self calculatePositionOfBookmarkItemAt:index]; | 144 int position = [self calculatePositionOfBookmarkItemAt:index]; |
145 | 145 |
146 BookmarkModel* model = [self bookmarkModel]; | 146 BookmarkModel* model = [self bookmarkModel]; |
147 if (!model) | 147 if (!model) |
148 return; | 148 return; |
149 | 149 |
150 GURL url(base::SysNSStringToUTF8([aBookmarkItem URL])); | 150 GURL url(base::SysNSStringToUTF8([aBookmarkItem URL])); |
151 if (!url.is_valid()) { | 151 if (!url.is_valid()) { |
152 AppleScript::SetError(AppleScript::errInvalidURL); | 152 AppleScript::SetError(AppleScript::errInvalidURL); |
153 return; | 153 return; |
154 } | 154 } |
155 | 155 |
156 const BookmarkNode* node = model->AddURL(bookmarkNode_, | 156 const BookmarkNode* node = model->AddURL(bookmarkNode_, |
157 position, | 157 position, |
158 std::wstring(), | 158 string16(), |
159 url); | 159 url); |
160 if (!node) { | 160 if (!node) { |
161 AppleScript::SetError(AppleScript::errCreateBookmarkItem); | 161 AppleScript::SetError(AppleScript::errCreateBookmarkItem); |
162 return; | 162 return; |
163 } | 163 } |
164 | 164 |
165 [aBookmarkItem setBookmarkNode:node]; | 165 [aBookmarkItem setBookmarkNode:node]; |
166 } | 166 } |
167 | 167 |
168 - (void)removeFromBookmarkItemsAtIndex:(int)index { | 168 - (void)removeFromBookmarkItemsAtIndex:(int)index { |
(...skipping 26 matching lines...) Expand all Loading... |
195 ++index; | 195 ++index; |
196 int count = -1; | 196 int count = -1; |
197 while (index) { | 197 while (index) { |
198 if (bookmarkNode_->GetChild(++count)->is_url()) | 198 if (bookmarkNode_->GetChild(++count)->is_url()) |
199 --index; | 199 --index; |
200 } | 200 } |
201 return count; | 201 return count; |
202 } | 202 } |
203 | 203 |
204 @end | 204 @end |
OLD | NEW |