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 <stddef.h> | 10 #include <stddef.h> |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 // representing it. | 289 // representing it. |
290 bool LoadInternetShortcut( | 290 bool LoadInternetShortcut( |
291 const base::string16& file, | 291 const base::string16& file, |
292 base::win::ScopedComPtr<IUniformResourceLocator>* shortcut) { | 292 base::win::ScopedComPtr<IUniformResourceLocator>* shortcut) { |
293 base::win::ScopedComPtr<IUniformResourceLocator> url_locator; | 293 base::win::ScopedComPtr<IUniformResourceLocator> url_locator; |
294 if (FAILED(url_locator.CreateInstance(CLSID_InternetShortcut, NULL, | 294 if (FAILED(url_locator.CreateInstance(CLSID_InternetShortcut, NULL, |
295 CLSCTX_INPROC_SERVER))) | 295 CLSCTX_INPROC_SERVER))) |
296 return false; | 296 return false; |
297 | 297 |
298 base::win::ScopedComPtr<IPersistFile> persist_file; | 298 base::win::ScopedComPtr<IPersistFile> persist_file; |
299 if (FAILED(persist_file.QueryFrom(url_locator.get()))) | 299 if (FAILED(persist_file.QueryFrom(url_locator.Get()))) |
300 return false; | 300 return false; |
301 | 301 |
302 // Loads the Internet Shortcut from persistent storage. | 302 // Loads the Internet Shortcut from persistent storage. |
303 if (FAILED(persist_file->Load(file.c_str(), STGM_READ))) | 303 if (FAILED(persist_file->Load(file.c_str(), STGM_READ))) |
304 return false; | 304 return false; |
305 | 305 |
306 std::swap(url_locator, *shortcut); | 306 std::swap(url_locator, *shortcut); |
307 return true; | 307 return true; |
308 } | 308 } |
309 | 309 |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 for (std::vector<base::FilePath::StringType>::iterator it = file_list.begin(); | 849 for (std::vector<base::FilePath::StringType>::iterator it = file_list.begin(); |
850 it != file_list.end(); ++it) { | 850 it != file_list.end(); ++it) { |
851 base::FilePath shortcut(*it); | 851 base::FilePath shortcut(*it); |
852 if (!base::LowerCaseEqualsASCII(shortcut.Extension(), ".url")) | 852 if (!base::LowerCaseEqualsASCII(shortcut.Extension(), ".url")) |
853 continue; | 853 continue; |
854 | 854 |
855 // Skip the bookmark with invalid URL. | 855 // Skip the bookmark with invalid URL. |
856 base::win::ScopedComPtr<IUniformResourceLocator> url_locator; | 856 base::win::ScopedComPtr<IUniformResourceLocator> url_locator; |
857 if (!LoadInternetShortcut(*it, &url_locator)) | 857 if (!LoadInternetShortcut(*it, &url_locator)) |
858 continue; | 858 continue; |
859 GURL url = ReadURLFromInternetShortcut(url_locator.get()); | 859 GURL url = ReadURLFromInternetShortcut(url_locator.Get()); |
860 if (!url.is_valid()) | 860 if (!url.is_valid()) |
861 continue; | 861 continue; |
862 // Skip default bookmarks. go.microsoft.com redirects to | 862 // Skip default bookmarks. go.microsoft.com redirects to |
863 // search.microsoft.com, and http://go.microsoft.com/fwlink/?LinkId=XXX, | 863 // search.microsoft.com, and http://go.microsoft.com/fwlink/?LinkId=XXX, |
864 // which URLs IE has as default, to some another sites. | 864 // which URLs IE has as default, to some another sites. |
865 // We expect that users will never themselves create bookmarks having this | 865 // We expect that users will never themselves create bookmarks having this |
866 // hostname. | 866 // hostname. |
867 if (url.host() == "go.microsoft.com") | 867 if (url.host() == "go.microsoft.com") |
868 continue; | 868 continue; |
869 // Read favicon. | 869 // Read favicon. |
870 UpdateFaviconMap(*it, url, url_locator.get(), &favicon_map); | 870 UpdateFaviconMap(*it, url, url_locator.Get(), &favicon_map); |
871 | 871 |
872 // Make the relative path from the Favorites folder, without the basename. | 872 // Make the relative path from the Favorites folder, without the basename. |
873 // ex. Suppose that the Favorites folder is C:\Users\Foo\Favorites. | 873 // ex. Suppose that the Favorites folder is C:\Users\Foo\Favorites. |
874 // C:\Users\Foo\Favorites\Foo.url -> "" | 874 // C:\Users\Foo\Favorites\Foo.url -> "" |
875 // C:\Users\Foo\Favorites\Links\Bar\Baz.url -> "Links\Bar" | 875 // C:\Users\Foo\Favorites\Links\Bar\Baz.url -> "Links\Bar" |
876 base::FilePath::StringType relative_string = | 876 base::FilePath::StringType relative_string = |
877 shortcut.DirName().value().substr(favorites_path_len); | 877 shortcut.DirName().value().substr(favorites_path_len); |
878 if (!relative_string.empty() && | 878 if (!relative_string.empty() && |
879 base::FilePath::IsSeparator(relative_string[0])) | 879 base::FilePath::IsSeparator(relative_string[0])) |
880 relative_string = relative_string.substr(1); | 880 relative_string = relative_string.substr(1); |
(...skipping 30 matching lines...) Expand all Loading... |
911 static int version = -1; | 911 static int version = -1; |
912 if (version < 0) { | 912 if (version < 0) { |
913 wchar_t buffer[128]; | 913 wchar_t buffer[128]; |
914 DWORD buffer_length = sizeof(buffer); | 914 DWORD buffer_length = sizeof(buffer); |
915 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); | 915 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); |
916 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 916 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
917 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); | 917 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
918 } | 918 } |
919 return version; | 919 return version; |
920 } | 920 } |
OLD | NEW |