| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/firefox_importer_utils.h" | 5 #include "chrome/browser/importer/firefox_importer_utils.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <shlobj.h> | 10 #include <shlobj.h> |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // Sets the SetDllDirectory function pointer to activates this object. | 76 // Sets the SetDllDirectory function pointer to activates this object. |
| 77 void set_func(SetDllDirectoryFunc func) { func_ = func; } | 77 void set_func(SetDllDirectoryFunc func) { func_ = func; } |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 SetDllDirectoryFunc func_; | 80 SetDllDirectoryFunc func_; |
| 81 }; | 81 }; |
| 82 #endif | 82 #endif |
| 83 | 83 |
| 84 } // namespace | 84 } // namespace |
| 85 | 85 |
| 86 int GetCurrentFirefoxMajorVersion() { | |
| 87 #if defined(OS_WIN) | 86 #if defined(OS_WIN) |
| 87 int GetCurrentFirefoxMajorVersionFromRegistry() { |
| 88 TCHAR ver_buffer[128]; | 88 TCHAR ver_buffer[128]; |
| 89 DWORD ver_buffer_length = sizeof(ver_buffer); | 89 DWORD ver_buffer_length = sizeof(ver_buffer); |
| 90 int highest_version = 0; | 90 int highest_version = 0; |
| 91 // When installing Firefox with admin account, the product keys will be | 91 // When installing Firefox with admin account, the product keys will be |
| 92 // written under HKLM\Mozilla. Otherwise it the keys will be written under | 92 // written under HKLM\Mozilla. Otherwise it the keys will be written under |
| 93 // HKCU\Mozilla. | 93 // HKCU\Mozilla. |
| 94 for (int i = 0; i < arraysize(kFireFoxRegistryPaths); ++i) { | 94 for (int i = 0; i < arraysize(kFireFoxRegistryPaths); ++i) { |
| 95 bool result = ReadFromRegistry(kFireFoxRegistryPaths[i], | 95 bool result = ReadFromRegistry(kFireFoxRegistryPaths[i], |
| 96 L"Software\\Mozilla\\Mozilla Firefox", | 96 L"Software\\Mozilla\\Mozilla Firefox", |
| 97 L"CurrentVersion", ver_buffer, &ver_buffer_length); | 97 L"CurrentVersion", ver_buffer, &ver_buffer_length); |
| 98 if (!result) | 98 if (!result) |
| 99 continue; | 99 continue; |
| 100 highest_version = std::max(highest_version, _wtoi(ver_buffer)); | 100 highest_version = std::max(highest_version, _wtoi(ver_buffer)); |
| 101 } | 101 } |
| 102 return highest_version; | 102 return highest_version; |
| 103 #else | 103 } |
| 104 // TODO(port): Read in firefox configuration. | 104 |
| 105 NOTIMPLEMENTED(); | 105 std::wstring GetFirefoxInstallPathFromRegistry() { |
| 106 return 0; | 106 // Detects the path that Firefox is installed in. |
| 107 std::wstring registry_path = L"Software\\Mozilla\\Mozilla Firefox"; |
| 108 TCHAR buffer[MAX_PATH]; |
| 109 DWORD buffer_length = sizeof(buffer); |
| 110 bool result; |
| 111 result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(), |
| 112 L"CurrentVersion", buffer, &buffer_length); |
| 113 if (!result) |
| 114 return std::wstring(); |
| 115 registry_path += L"\\" + std::wstring(buffer) + L"\\Main"; |
| 116 buffer_length = sizeof(buffer); |
| 117 result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(), |
| 118 L"Install Directory", buffer, &buffer_length); |
| 119 if (!result) |
| 120 return std::wstring(); |
| 121 return buffer; |
| 122 } |
| 107 #endif | 123 #endif |
| 108 } | |
| 109 | 124 |
| 110 #if defined(OS_WIN) || defined(OS_LINUX) | 125 #if defined(OS_WIN) || defined(OS_LINUX) |
| 111 bool GetFirefoxVersionAndPathFromProfile(const std::wstring& profile_path, | 126 bool GetFirefoxVersionAndPathFromProfile(const std::wstring& profile_path, |
| 112 int* version, | 127 int* version, |
| 113 std::wstring* app_path) { | 128 std::wstring* app_path) { |
| 114 bool ret = false; | 129 bool ret = false; |
| 115 std::wstring compatibility_file(profile_path); | 130 std::wstring compatibility_file(profile_path); |
| 116 file_util::AppendToPath(&compatibility_file, L"compatibility.ini"); | 131 file_util::AppendToPath(&compatibility_file, L"compatibility.ini"); |
| 117 std::string content; | 132 std::string content; |
| 118 file_util::ReadFileToString(compatibility_file, &content); | 133 file_util::ReadFileToString(compatibility_file, &content); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 // so we discard them. | 217 // so we discard them. |
| 203 if (current_section.find(L'.') == std::wstring::npos && | 218 if (current_section.find(L'.') == std::wstring::npos && |
| 204 key.find(L'.') == std::wstring::npos) | 219 key.find(L'.') == std::wstring::npos) |
| 205 root->SetString(current_section + L"." + key, value); | 220 root->SetString(current_section + L"." + key, value); |
| 206 } | 221 } |
| 207 } | 222 } |
| 208 } | 223 } |
| 209 } | 224 } |
| 210 #endif | 225 #endif |
| 211 | 226 |
| 212 std::wstring GetFirefoxInstallPath() { | |
| 213 #if defined(OS_WIN) | |
| 214 // Detects the path that Firefox is installed in. | |
| 215 std::wstring registry_path = L"Software\\Mozilla\\Mozilla Firefox"; | |
| 216 TCHAR buffer[MAX_PATH]; | |
| 217 DWORD buffer_length = sizeof(buffer); | |
| 218 bool result; | |
| 219 result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(), | |
| 220 L"CurrentVersion", buffer, &buffer_length); | |
| 221 if (!result) | |
| 222 return std::wstring(); | |
| 223 registry_path += L"\\" + std::wstring(buffer) + L"\\Main"; | |
| 224 buffer_length = sizeof(buffer); | |
| 225 result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(), | |
| 226 L"Install Directory", buffer, &buffer_length); | |
| 227 if (!result) | |
| 228 return std::wstring(); | |
| 229 return buffer; | |
| 230 #else | |
| 231 // TODO(port): Load firefox configuration. | |
| 232 NOTIMPLEMENTED(); | |
| 233 return std::wstring(); | |
| 234 #endif | |
| 235 } | |
| 236 | |
| 237 bool CanImportURL(const GURL& url) { | 227 bool CanImportURL(const GURL& url) { |
| 238 const char* kInvalidSchemes[] = {"wyciwyg", "place", "about", "chrome"}; | 228 const char* kInvalidSchemes[] = {"wyciwyg", "place", "about", "chrome"}; |
| 239 | 229 |
| 240 // The URL is not valid. | 230 // The URL is not valid. |
| 241 if (!url.is_valid()) | 231 if (!url.is_valid()) |
| 242 return false; | 232 return false; |
| 243 | 233 |
| 244 // Filter out the URLs with unsupported schemes. | 234 // Filter out the URLs with unsupported schemes. |
| 245 for (size_t i = 0; i < arraysize(kInvalidSchemes); ++i) { | 235 for (size_t i = 0; i < arraysize(kInvalidSchemes); ++i) { |
| 246 if (url.SchemeIs(kInvalidSchemes[i])) | 236 if (url.SchemeIs(kInvalidSchemes[i])) |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 } | 795 } |
| 806 // Version 3 has an extra line for further use. | 796 // Version 3 has an extra line for further use. |
| 807 if (version == 3) { | 797 if (version == 3) { |
| 808 ++begin; | 798 ++begin; |
| 809 } | 799 } |
| 810 | 800 |
| 811 forms->push_back(form); | 801 forms->push_back(form); |
| 812 } | 802 } |
| 813 } | 803 } |
| 814 } | 804 } |
| OLD | NEW |