OLD | NEW |
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 #include "chrome/browser/importer/firefox3_importer.h" | 5 #include "chrome/browser/importer/firefox3_importer.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "app/sql/connection.h" | 9 #include "app/sql/connection.h" |
10 #include "app/sql/statement.h" | 10 #include "app/sql/statement.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 NOTREACHED(); | 201 NOTREACHED(); |
202 return; | 202 return; |
203 } | 203 } |
204 | 204 |
205 string16 firefox_folder = | 205 string16 firefox_folder = |
206 bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_FIREFOX); | 206 bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_FIREFOX); |
207 for (size_t i = 0; i < list.size(); ++i) { | 207 for (size_t i = 0; i < list.size(); ++i) { |
208 BookmarkItem* item = list[i]; | 208 BookmarkItem* item = list[i]; |
209 | 209 |
210 if (item->type == TYPE_FOLDER) { | 210 if (item->type == TYPE_FOLDER) { |
211 // Folders are added implicitly on adding children, | 211 // Folders are added implicitly on adding children, so we only explicitly |
212 // so now we pass only empty folders to add them explicitly. | 212 // add empty folders. |
213 if (!item->empty_folder) | 213 if (!item->empty_folder) |
214 continue; | 214 continue; |
215 } else if (item->type == TYPE_BOOKMARK) { | 215 } else if (item->type == TYPE_BOOKMARK) { |
216 // Import only valid bookmarks | 216 // Import only valid bookmarks |
217 if (!CanImportURL(item->url)) | 217 if (!CanImportURL(item->url)) |
218 continue; | 218 continue; |
219 } else { | 219 } else { |
220 continue; | 220 continue; |
221 } | 221 } |
222 | 222 |
223 // Skip the default bookmarks and unwanted URLs. | 223 // Skip the default bookmarks and unwanted URLs. |
224 if (default_urls.find(item->url) != default_urls.end() || | 224 if (default_urls.find(item->url) != default_urls.end() || |
225 post_keyword_ids.find(item->id) != post_keyword_ids.end()) | 225 post_keyword_ids.find(item->id) != post_keyword_ids.end()) |
226 continue; | 226 continue; |
227 | 227 |
228 // Find the bookmark path by tracing their links to parent folders. | 228 // Find the bookmark path by tracing their links to parent folders. |
229 std::vector<string16> path; | 229 std::vector<string16> path; |
230 BookmarkItem* child = item; | 230 BookmarkItem* child = item; |
231 bool found_path = false; | 231 bool found_path = false; |
232 bool is_in_toolbar = false; | 232 bool is_in_toolbar = false; |
233 while (child->parent >= 0) { | 233 while (child->parent >= 0) { |
234 BookmarkItem* parent = list[child->parent]; | 234 BookmarkItem* parent = list[child->parent]; |
235 if (parent->id == toolbar_folder_id) { | 235 if (livemark_id.find(parent->id) != livemark_id.end()) { |
236 // This bookmark entry should be put in the bookmark bar. | 236 // Don't import live bookmarks. |
237 // But we put it in the Firefox group after first run, so | 237 break; |
238 // that do not mess up the bookmark bar. | 238 } |
239 if (import_to_bookmark_bar()) { | 239 |
240 is_in_toolbar = true; | 240 if (parent->id != menu_folder_id) { |
241 } else { | 241 // To avoid excessive nesting, omit the name for the bookmarks menu |
242 path.insert(path.begin(), parent->title); | 242 // folder. |
243 path.insert(path.begin(), firefox_folder); | 243 path.insert(path.begin(), parent->title); |
244 } | 244 } |
| 245 |
| 246 if (parent->id == toolbar_folder_id) |
| 247 is_in_toolbar = true; |
| 248 |
| 249 if (parent->id == toolbar_folder_id || |
| 250 parent->id == menu_folder_id || |
| 251 parent->id == unsorted_folder_id) { |
| 252 // We've reached a root node, hooray! |
245 found_path = true; | 253 found_path = true; |
246 break; | 254 break; |
247 } else if (parent->id == menu_folder_id || | |
248 parent->id == unsorted_folder_id) { | |
249 // After the first run, the item will be placed in a folder in | |
250 // the "Other bookmarks". | |
251 if (!import_to_bookmark_bar()) | |
252 path.insert(path.begin(), firefox_folder); | |
253 found_path = true; | |
254 break; | |
255 } else if (livemark_id.find(parent->id) != livemark_id.end()) { | |
256 // If the entry is under a livemark folder, we don't import it. | |
257 break; | |
258 } | 255 } |
259 path.insert(path.begin(), parent->title); | 256 |
260 child = parent; | 257 child = parent; |
261 } | 258 } |
262 | 259 |
263 if (!found_path) | 260 if (!found_path) |
264 continue; | 261 continue; |
265 | 262 |
266 ProfileWriter::BookmarkEntry entry; | 263 ProfileWriter::BookmarkEntry entry; |
267 entry.creation_time = item->date_added; | 264 entry.creation_time = item->date_added; |
268 entry.title = item->title; | 265 entry.title = item->title; |
269 entry.url = item->url; | 266 entry.url = item->url; |
(...skipping 14 matching lines...) Expand all Loading... |
284 template_urls.push_back(t_url); | 281 template_urls.push_back(t_url); |
285 } | 282 } |
286 } | 283 } |
287 | 284 |
288 STLDeleteContainerPointers(list.begin(), list.end()); | 285 STLDeleteContainerPointers(list.begin(), list.end()); |
289 | 286 |
290 // Write into profile. | 287 // Write into profile. |
291 if (!bookmarks.empty() && !cancelled()) { | 288 if (!bookmarks.empty() && !cancelled()) { |
292 const string16& first_folder_name = | 289 const string16& first_folder_name = |
293 bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_FIREFOX); | 290 bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_FIREFOX); |
294 int options = 0; | 291 bridge_->AddBookmarks(bookmarks, first_folder_name); |
295 if (import_to_bookmark_bar()) | |
296 options = ProfileWriter::IMPORT_TO_BOOKMARK_BAR; | |
297 bridge_->AddBookmarks(bookmarks, first_folder_name, options); | |
298 } | 292 } |
299 if (!template_urls.empty() && !cancelled()) { | 293 if (!template_urls.empty() && !cancelled()) { |
300 bridge_->SetKeywords(template_urls, -1, false); | 294 bridge_->SetKeywords(template_urls, -1, false); |
301 } else { | 295 } else { |
302 STLDeleteContainerPointers(template_urls.begin(), template_urls.end()); | 296 STLDeleteContainerPointers(template_urls.begin(), template_urls.end()); |
303 } | 297 } |
304 if (!favicon_map.empty() && !cancelled()) { | 298 if (!favicon_map.empty() && !cancelled()) { |
305 std::vector<history::ImportedFaviconUsage> favicons; | 299 std::vector<history::ImportedFaviconUsage> favicons; |
306 LoadFavicons(&db, favicon_map, &favicons); | 300 LoadFavicons(&db, favicon_map, &favicons); |
307 bridge_->SetFavicons(favicons); | 301 bridge_->SetFavicons(favicons); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 | 571 |
578 if (!ReencodeFavicon(&data[0], data.size(), &usage.png_data)) | 572 if (!ReencodeFavicon(&data[0], data.size(), &usage.png_data)) |
579 continue; // Unable to decode. | 573 continue; // Unable to decode. |
580 | 574 |
581 usage.urls = i->second; | 575 usage.urls = i->second; |
582 favicons->push_back(usage); | 576 favicons->push_back(usage); |
583 } | 577 } |
584 s.Reset(); | 578 s.Reset(); |
585 } | 579 } |
586 } | 580 } |
OLD | NEW |