OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/utility/importer/ie_importer_win.h" | 5 #include "chrome/utility/importer/ie_importer_win.h" |
6 | 6 |
7 #include <ole2.h> | 7 #include <ole2.h> |
8 #include <intshcut.h> | 8 #include <intshcut.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #include <urlhist.h> | 10 #include <urlhist.h> |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 head += id_cb; | 107 head += id_cb; |
108 } | 108 } |
109 return reinterpret_cast<LPCITEMIDLIST>(&blob[offset]); | 109 return reinterpret_cast<LPCITEMIDLIST>(&blob[offset]); |
110 } | 110 } |
111 | 111 |
112 // Compares the two bookmarks in the order of IE's Favorites menu. | 112 // Compares the two bookmarks in the order of IE's Favorites menu. |
113 // Returns true if rhs should come later than lhs (lhs < rhs). | 113 // Returns true if rhs should come later than lhs (lhs < rhs). |
114 struct IEOrderBookmarkComparator { | 114 struct IEOrderBookmarkComparator { |
115 bool operator()(const ImportedBookmarkEntry& lhs, | 115 bool operator()(const ImportedBookmarkEntry& lhs, |
116 const ImportedBookmarkEntry& rhs) const { | 116 const ImportedBookmarkEntry& rhs) const { |
117 static const uint32 kNotSorted = 0xfffffffb; // IE uses this magic value. | 117 static const uint32 kNotSorted = 0xfffffffb; // IE uses this magic value. |
118 base::FilePath lhs_prefix; | 118 base::FilePath lhs_prefix; |
119 base::FilePath rhs_prefix; | 119 base::FilePath rhs_prefix; |
120 for (size_t i = 0; i <= lhs.path.size() && i <= rhs.path.size(); ++i) { | 120 for (size_t i = 0; i <= lhs.path.size() && i <= rhs.path.size(); ++i) { |
121 const base::FilePath::StringType lhs_i = | 121 const base::FilePath::StringType lhs_i = |
122 (i < lhs.path.size() ? lhs.path[i] : lhs.title + L".url"); | 122 (i < lhs.path.size() ? lhs.path[i] : lhs.title + L".url"); |
123 const base::FilePath::StringType rhs_i = | 123 const base::FilePath::StringType rhs_i = |
124 (i < rhs.path.size() ? rhs.path[i] : rhs.title + L".url"); | 124 (i < rhs.path.size() ? rhs.path[i] : rhs.title + L".url"); |
125 lhs_prefix = lhs_prefix.Append(lhs_i); | 125 lhs_prefix = lhs_prefix.Append(lhs_i); |
126 rhs_prefix = rhs_prefix.Append(rhs_i); | 126 rhs_prefix = rhs_prefix.Append(rhs_i); |
127 if (lhs_i == rhs_i) | 127 if (lhs_i == rhs_i) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // Traverse over the items. | 177 // Traverse over the items. |
178 size_t base_offset = kItemListStartOffset; | 178 size_t base_offset = kItemListStartOffset; |
179 for (uint32 i = 0; i < item_count && !importer->cancelled(); ++i) { | 179 for (uint32 i = 0; i < item_count && !importer->cancelled(); ++i) { |
180 static const int kSizeOffset = 0; | 180 static const int kSizeOffset = 0; |
181 static const int kSortIndexOffset = 4; | 181 static const int kSortIndexOffset = 4; |
182 static const int kItemIDListOffset = 8; | 182 static const int kItemIDListOffset = 8; |
183 | 183 |
184 // Read the size (number of bytes) of the current item. | 184 // Read the size (number of bytes) of the current item. |
185 uint32 item_size = 0; | 185 uint32 item_size = 0; |
186 if (!BinaryRead(&item_size, base_offset + kSizeOffset, blob) || | 186 if (!BinaryRead(&item_size, base_offset + kSizeOffset, blob) || |
187 base_offset + item_size <= base_offset || // checking overflow | 187 base_offset + item_size <= base_offset || // checking overflow |
188 base_offset + item_size > blob.size()) | 188 base_offset + item_size > blob.size()) |
189 return false; | 189 return false; |
190 | 190 |
191 // Read the sort index of the current item. | 191 // Read the sort index of the current item. |
192 uint32 item_sort_index = 0; | 192 uint32 item_sort_index = 0; |
193 if (!BinaryRead(&item_sort_index, base_offset + kSortIndexOffset, blob)) | 193 if (!BinaryRead(&item_sort_index, base_offset + kSortIndexOffset, blob)) |
194 return false; | 194 return false; |
195 | 195 |
196 // Read the file name from the ITEMIDLIST structure. | 196 // Read the file name from the ITEMIDLIST structure. |
197 LPCITEMIDLIST idlist = BinaryReadItemIDList( | 197 LPCITEMIDLIST idlist = BinaryReadItemIDList( |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 285 |
286 std::swap(url_locator, *shortcut); | 286 std::swap(url_locator, *shortcut); |
287 return true; | 287 return true; |
288 } | 288 } |
289 | 289 |
290 // Reads the URL stored in the internet shortcut. | 290 // Reads the URL stored in the internet shortcut. |
291 GURL ReadURLFromInternetShortcut(IUniformResourceLocator* url_locator) { | 291 GURL ReadURLFromInternetShortcut(IUniformResourceLocator* url_locator) { |
292 base::win::ScopedCoMem<wchar_t> url; | 292 base::win::ScopedCoMem<wchar_t> url; |
293 // GetURL can return S_FALSE (FAILED(S_FALSE) is false) when url == NULL. | 293 // GetURL can return S_FALSE (FAILED(S_FALSE) is false) when url == NULL. |
294 return (FAILED(url_locator->GetURL(&url)) || !url) ? | 294 return (FAILED(url_locator->GetURL(&url)) || !url) ? |
295 GURL() : GURL(base::WideToUTF16(std::wstring(url))); | 295 GURL() : GURL(base::WideToUTF16(url.get())); |
296 } | 296 } |
297 | 297 |
298 // Reads the URL of the favicon of the internet shortcut. | 298 // Reads the URL of the favicon of the internet shortcut. |
299 GURL ReadFaviconURLFromInternetShortcut(IUniformResourceLocator* url_locator) { | 299 GURL ReadFaviconURLFromInternetShortcut(IUniformResourceLocator* url_locator) { |
300 base::win::ScopedComPtr<IPropertySetStorage> property_set_storage; | 300 base::win::ScopedComPtr<IPropertySetStorage> property_set_storage; |
301 if (FAILED(property_set_storage.QueryFrom(url_locator))) | 301 if (FAILED(property_set_storage.QueryFrom(url_locator))) |
302 return GURL(); | 302 return GURL(); |
303 | 303 |
304 base::win::ScopedComPtr<IPropertyStorage> property_storage; | 304 base::win::ScopedComPtr<IPropertyStorage> property_storage; |
305 if (FAILED(property_set_storage->Open(FMTID_Intshcut, STGM_READ, | 305 if (FAILED(property_set_storage->Open(FMTID_Intshcut, STGM_READ, |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 static int version = -1; | 874 static int version = -1; |
875 if (version < 0) { | 875 if (version < 0) { |
876 wchar_t buffer[128]; | 876 wchar_t buffer[128]; |
877 DWORD buffer_length = sizeof(buffer); | 877 DWORD buffer_length = sizeof(buffer); |
878 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); | 878 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); |
879 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 879 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
880 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); | 880 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
881 } | 881 } |
882 return version; | 882 return version; |
883 } | 883 } |
OLD | NEW |