ie_importer.cc revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
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
3// found in the LICENSE file.
4
5#include "chrome/browser/importer/ie_importer.h"
6
7#include <ole2.h>
8#include <intshcut.h>
9#include <pstore.h>
10#include <shlobj.h>
11#include <urlhist.h>
12
13#include <algorithm>
14#include <map>
15#include <string>
16#include <vector>
17
18#include "app/win/scoped_co_mem.h"
19#include "app/win/scoped_com_initializer.h"
20#include "base/file_path.h"
21#include "base/file_util.h"
22#include "base/scoped_comptr_win.h"
23#include "base/string_split.h"
24#include "base/string_util.h"
25#include "base/time.h"
26#include "base/values.h"
27#include "base/utf_string_conversions.h"
28#include "base/win/registry.h"
29#include "base/win/scoped_handle.h"
30#include "base/win/windows_version.h"
31#include "chrome/browser/bookmarks/bookmark_model.h"
32#include "chrome/browser/importer/importer_bridge.h"
33#include "chrome/browser/importer/importer_data_types.h"
34#include "chrome/browser/password_manager/ie7_password.h"
35#include "chrome/browser/search_engines/template_url.h"
36#include "chrome/browser/search_engines/template_url_model.h"
37#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
38#include "chrome/common/time_format.h"
39#include "chrome/common/url_constants.h"
40#include "googleurl/src/gurl.h"
41#include "grit/generated_resources.h"
42#include "ui/base/l10n/l10n_util.h"
43#include "webkit/glue/password_form.h"
44
45using base::Time;
46using webkit_glue::PasswordForm;
47
48namespace {
49
50// Gets the creation time of the given file or directory.
51static Time GetFileCreationTime(const std::wstring& file) {
52  Time creation_time;
53  base::win::ScopedHandle file_handle(
54      CreateFile(file.c_str(), GENERIC_READ,
55                 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
56                 NULL, OPEN_EXISTING,
57                 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL));
58  FILETIME creation_filetime;
59  if (GetFileTime(file_handle, &creation_filetime, NULL, NULL))
60    creation_time = Time::FromFileTime(creation_filetime);
61  return creation_time;
62}
63
64}  // namespace
65
66// static
67// {E161255A-37C3-11D2-BCAA-00C04fD929DB}
68const GUID IEImporter::kPStoreAutocompleteGUID = {0xe161255a, 0x37c3, 0x11d2,
69    {0xbc, 0xaa, 0x00, 0xc0, 0x4f, 0xd9, 0x29, 0xdb}};
70// {A79029D6-753E-4e27-B807-3D46AB1545DF}
71const GUID IEImporter::kUnittestGUID = { 0xa79029d6, 0x753e, 0x4e27,
72    {0xb8, 0x7, 0x3d, 0x46, 0xab, 0x15, 0x45, 0xdf}};
73
74void IEImporter::StartImport(const ProfileInfo& profile_info,
75                             uint16 items,
76                             ImporterBridge* bridge) {
77  bridge_ = bridge;
78  source_path_ = profile_info.source_path.value();
79
80  bridge_->NotifyStarted();
81
82  // Some IE settings (such as Protected Storage) are obtained via COM APIs.
83  app::win::ScopedCOMInitializer com_initializer;
84
85  if ((items & importer::HOME_PAGE) && !cancelled())
86    ImportHomepage();  // Doesn't have a UI item.
87  // The order here is important!
88  if ((items & importer::HISTORY) && !cancelled()) {
89    bridge_->NotifyItemStarted(importer::HISTORY);
90    ImportHistory();
91    bridge_->NotifyItemEnded(importer::HISTORY);
92  }
93  if ((items & importer::FAVORITES) && !cancelled()) {
94    bridge_->NotifyItemStarted(importer::FAVORITES);
95    ImportFavorites();
96    bridge_->NotifyItemEnded(importer::FAVORITES);
97  }
98  if ((items & importer::SEARCH_ENGINES) && !cancelled()) {
99    bridge_->NotifyItemStarted(importer::SEARCH_ENGINES);
100    ImportSearchEngines();
101    bridge_->NotifyItemEnded(importer::SEARCH_ENGINES);
102  }
103  if ((items & importer::PASSWORDS) && !cancelled()) {
104    bridge_->NotifyItemStarted(importer::PASSWORDS);
105    // Always import IE6 passwords.
106    ImportPasswordsIE6();
107
108    if (CurrentIEVersion() >= 7)
109      ImportPasswordsIE7();
110    bridge_->NotifyItemEnded(importer::PASSWORDS);
111  }
112  bridge_->NotifyEnded();
113}
114
115void IEImporter::ImportFavorites() {
116  std::wstring path;
117
118  FavoritesInfo info;
119  if (!GetFavoritesInfo(&info))
120    return;
121
122  BookmarkVector bookmarks;
123  ParseFavoritesFolder(info, &bookmarks);
124
125  if (!bookmarks.empty() && !cancelled()) {
126    const std::wstring& first_folder_name =
127        UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOKMARK_GROUP_FROM_IE));
128    int options = 0;
129    if (import_to_bookmark_bar())
130      options = ProfileWriter::IMPORT_TO_BOOKMARK_BAR;
131    bridge_->AddBookmarkEntries(bookmarks, first_folder_name, options);
132  }
133}
134
135void IEImporter::ImportPasswordsIE6() {
136  GUID AutocompleteGUID = kPStoreAutocompleteGUID;
137  if (!source_path_.empty()) {
138    // We supply a fake GUID for testting.
139    AutocompleteGUID = kUnittestGUID;
140  }
141
142  // The PStoreCreateInstance function retrieves an interface pointer
143  // to a storage provider. But this function has no associated import
144  // library or header file, we must call it using the LoadLibrary()
145  // and GetProcAddress() functions.
146  typedef HRESULT (WINAPI *PStoreCreateFunc)(IPStore**, DWORD, DWORD, DWORD);
147  HMODULE pstorec_dll = LoadLibrary(L"pstorec.dll");
148  if (!pstorec_dll)
149    return;
150  PStoreCreateFunc PStoreCreateInstance =
151      (PStoreCreateFunc)GetProcAddress(pstorec_dll, "PStoreCreateInstance");
152  if (!PStoreCreateInstance) {
153    FreeLibrary(pstorec_dll);
154    return;
155  }
156
157  ScopedComPtr<IPStore, &IID_IPStore> pstore;
158  HRESULT result = PStoreCreateInstance(pstore.Receive(), 0, 0, 0);
159  if (result != S_OK) {
160    FreeLibrary(pstorec_dll);
161    return;
162  }
163
164  std::vector<AutoCompleteInfo> ac_list;
165
166  // Enumerates AutoComplete items in the protected database.
167  ScopedComPtr<IEnumPStoreItems, &IID_IEnumPStoreItems> item;
168  result = pstore->EnumItems(0, &AutocompleteGUID,
169                             &AutocompleteGUID, 0, item.Receive());
170  if (result != PST_E_OK) {
171    pstore.Release();
172    FreeLibrary(pstorec_dll);
173    return;
174  }
175
176  wchar_t* item_name;
177  while (!cancelled() && SUCCEEDED(item->Next(1, &item_name, 0))) {
178    DWORD length = 0;
179    unsigned char* buffer = NULL;
180    result = pstore->ReadItem(0, &AutocompleteGUID, &AutocompleteGUID,
181                              item_name, &length, &buffer, NULL, 0);
182    if (SUCCEEDED(result)) {
183      AutoCompleteInfo ac;
184      ac.key = item_name;
185      std::wstring data;
186      data.insert(0, reinterpret_cast<wchar_t*>(buffer),
187                  length / sizeof(wchar_t));
188
189      // The key name is always ended with ":StringData".
190      const wchar_t kDataSuffix[] = L":StringData";
191      size_t i = ac.key.rfind(kDataSuffix);
192      if (i != std::wstring::npos && ac.key.substr(i) == kDataSuffix) {
193        ac.key.erase(i);
194        ac.is_url = (ac.key.find(L"://") != std::wstring::npos);
195        ac_list.push_back(ac);
196        base::SplitString(data, L'\0', &ac_list[ac_list.size() - 1].data);
197      }
198      CoTaskMemFree(buffer);
199    }
200    CoTaskMemFree(item_name);
201  }
202  // Releases them before unload the dll.
203  item.Release();
204  pstore.Release();
205  FreeLibrary(pstorec_dll);
206
207  size_t i;
208  for (i = 0; i < ac_list.size(); i++) {
209    if (!ac_list[i].is_url || ac_list[i].data.size() < 2)
210      continue;
211
212    GURL url(ac_list[i].key.c_str());
213    if (!(LowerCaseEqualsASCII(url.scheme(), chrome::kHttpScheme) ||
214        LowerCaseEqualsASCII(url.scheme(), chrome::kHttpsScheme))) {
215      continue;
216    }
217
218    PasswordForm form;
219    GURL::Replacements rp;
220    rp.ClearUsername();
221    rp.ClearPassword();
222    rp.ClearQuery();
223    rp.ClearRef();
224    form.origin = url.ReplaceComponents(rp);
225    form.username_value = ac_list[i].data[0];
226    form.password_value = ac_list[i].data[1];
227    form.signon_realm = url.GetOrigin().spec();
228
229    // This is not precise, because a scheme of https does not imply a valid
230    // certificate was presented; however we assign it this way so that if we
231    // import a password from IE whose scheme is https, we give it the benefit
232    // of the doubt and DONT auto-fill it unless the form appears under
233    // valid SSL conditions.
234    form.ssl_valid = url.SchemeIsSecure();
235
236    // Goes through the list to find out the username field
237    // of the web page.
238    size_t list_it, item_it;
239    for (list_it = 0; list_it < ac_list.size(); ++list_it) {
240      if (ac_list[list_it].is_url)
241        continue;
242
243      for (item_it = 0; item_it < ac_list[list_it].data.size(); ++item_it)
244        if (ac_list[list_it].data[item_it] == form.username_value) {
245          form.username_element = ac_list[list_it].key;
246          break;
247        }
248    }
249
250    bridge_->SetPasswordForm(form);
251  }
252}
253
254void IEImporter::ImportPasswordsIE7() {
255  if (!source_path_.empty()) {
256    // We have been called from the unit tests. Don't import real passwords.
257    return;
258  }
259
260  const wchar_t kStorage2Path[] =
261      L"Software\\Microsoft\\Internet Explorer\\IntelliForms\\Storage2";
262
263  base::win::RegKey key(HKEY_CURRENT_USER, kStorage2Path, KEY_READ);
264  base::win::RegistryValueIterator reg_iterator(HKEY_CURRENT_USER,
265                                                kStorage2Path);
266  IE7PasswordInfo password_info;
267  while (reg_iterator.Valid() && !cancelled()) {
268    // Get the size of the encrypted data.
269    DWORD value_len = 0;
270    key.ReadValue(reg_iterator.Name(), NULL, &value_len, NULL);
271    if (value_len) {
272      // Query the encrypted data.
273      password_info.encrypted_data.resize(value_len);
274      if (key.ReadValue(reg_iterator.Name(),
275                        &password_info.encrypted_data.front(),
276                        &value_len, NULL) == ERROR_SUCCESS) {
277        password_info.url_hash = reg_iterator.Name();
278        password_info.date_created = Time::Now();
279
280        bridge_->AddIE7PasswordInfo(password_info);
281      }
282    }
283
284    ++reg_iterator;
285  }
286}
287
288// Reads history information from COM interface.
289void IEImporter::ImportHistory() {
290  const std::string kSchemes[] = {chrome::kHttpScheme,
291                                  chrome::kHttpsScheme,
292                                  chrome::kFtpScheme,
293                                  chrome::kFileScheme};
294  int total_schemes = arraysize(kSchemes);
295
296  ScopedComPtr<IUrlHistoryStg2> url_history_stg2;
297  HRESULT result;
298  result = url_history_stg2.CreateInstance(CLSID_CUrlHistory, NULL,
299                                           CLSCTX_INPROC_SERVER);
300  if (FAILED(result))
301    return;
302  ScopedComPtr<IEnumSTATURL> enum_url;
303  if (SUCCEEDED(result = url_history_stg2->EnumUrls(enum_url.Receive()))) {
304    std::vector<history::URLRow> rows;
305    STATURL stat_url;
306    ULONG fetched;
307    while (!cancelled() &&
308           (result = enum_url->Next(1, &stat_url, &fetched)) == S_OK) {
309      std::wstring url_string;
310      std::wstring title_string;
311      if (stat_url.pwcsUrl) {
312        url_string = stat_url.pwcsUrl;
313        CoTaskMemFree(stat_url.pwcsUrl);
314      }
315      if (stat_url.pwcsTitle) {
316        title_string = stat_url.pwcsTitle;
317        CoTaskMemFree(stat_url.pwcsTitle);
318      }
319
320      GURL url(url_string);
321      // Skips the URLs that are invalid or have other schemes.
322      if (!url.is_valid() ||
323          (std::find(kSchemes, kSchemes + total_schemes, url.scheme()) ==
324           kSchemes + total_schemes))
325        continue;
326
327      history::URLRow row(url);
328      row.set_title(title_string);
329      row.set_last_visit(Time::FromFileTime(stat_url.ftLastVisited));
330      if (stat_url.dwFlags == STATURL_QUERYFLAG_TOPLEVEL) {
331        row.set_visit_count(1);
332        row.set_hidden(false);
333      } else {
334        row.set_hidden(true);
335      }
336
337      rows.push_back(row);
338    }
339
340    if (!rows.empty() && !cancelled()) {
341      bridge_->SetHistoryItems(rows, history::SOURCE_IE_IMPORTED);
342    }
343  }
344}
345
346void IEImporter::ImportSearchEngines() {
347  // On IE, search engines are stored in the registry, under:
348  // Software\Microsoft\Internet Explorer\SearchScopes
349  // Each key represents a search engine. The URL value contains the URL and
350  // the DisplayName the name.
351  // The default key's name is contained under DefaultScope.
352  const wchar_t kSearchScopePath[] =
353      L"Software\\Microsoft\\Internet Explorer\\SearchScopes";
354
355  base::win::RegKey key(HKEY_CURRENT_USER, kSearchScopePath, KEY_READ);
356  std::wstring default_search_engine_name;
357  const TemplateURL* default_search_engine = NULL;
358  std::map<std::string, TemplateURL*> search_engines_map;
359  key.ReadValue(L"DefaultScope", &default_search_engine_name);
360  base::win::RegistryKeyIterator key_iterator(HKEY_CURRENT_USER,
361                                              kSearchScopePath);
362  while (key_iterator.Valid()) {
363    std::wstring sub_key_name = kSearchScopePath;
364    sub_key_name.append(L"\\").append(key_iterator.Name());
365    base::win::RegKey sub_key(HKEY_CURRENT_USER, sub_key_name.c_str(),
366                              KEY_READ);
367    std::wstring wide_url;
368    if ((sub_key.ReadValue(L"URL", &wide_url) != ERROR_SUCCESS) ||
369        wide_url.empty()) {
370      VLOG(1) << "No URL for IE search engine at " << key_iterator.Name();
371      ++key_iterator;
372      continue;
373    }
374    // For the name, we try the default value first (as Live Search uses a
375    // non displayable name in DisplayName, and the readable name under the
376    // default value).
377    std::wstring name;
378    if ((sub_key.ReadValue(NULL, &name) != ERROR_SUCCESS) || name.empty()) {
379      // Try the displayable name.
380      if ((sub_key.ReadValue(L"DisplayName", &name) != ERROR_SUCCESS) ||
381          name.empty()) {
382        VLOG(1) << "No name for IE search engine at " << key_iterator.Name();
383        ++key_iterator;
384        continue;
385      }
386    }
387
388    std::string url(WideToUTF8(wide_url));
389    std::map<std::string, TemplateURL*>::iterator t_iter =
390        search_engines_map.find(url);
391    TemplateURL* template_url =
392        (t_iter != search_engines_map.end()) ? t_iter->second : NULL;
393    if (!template_url) {
394      // First time we see that URL.
395      template_url = new TemplateURL();
396      template_url->set_short_name(name);
397      template_url->SetURL(url, 0, 0);
398      // Give this a keyword to facilitate tab-to-search, if possible.
399      GURL gurl = GURL(url);
400      template_url->set_keyword(TemplateURLModel::GenerateKeyword(gurl,
401                                                                  false));
402      template_url->set_logo_id(
403          TemplateURLPrepopulateData::GetSearchEngineLogo(gurl));
404      template_url->set_show_in_default_list(true);
405      search_engines_map[url] = template_url;
406    }
407    if (template_url && key_iterator.Name() == default_search_engine_name) {
408      DCHECK(!default_search_engine);
409      default_search_engine = template_url;
410    }
411    ++key_iterator;
412  }
413
414  // ProfileWriter::AddKeywords() requires a vector and we have a map.
415  std::map<std::string, TemplateURL*>::iterator t_iter;
416  std::vector<TemplateURL*> search_engines;
417  int default_search_engine_index = -1;
418  for (t_iter = search_engines_map.begin(); t_iter != search_engines_map.end();
419       ++t_iter) {
420    search_engines.push_back(t_iter->second);
421    if (default_search_engine == t_iter->second) {
422      default_search_engine_index =
423          static_cast<int>(search_engines.size()) - 1;
424    }
425  }
426  bridge_->SetKeywords(search_engines, default_search_engine_index, true);
427}
428
429void IEImporter::ImportHomepage() {
430  const wchar_t kIESettingsMain[] =
431      L"Software\\Microsoft\\Internet Explorer\\Main";
432  const wchar_t kIEHomepage[] = L"Start Page";
433  const wchar_t kIEDefaultHomepage[] = L"Default_Page_URL";
434
435  base::win::RegKey key(HKEY_CURRENT_USER, kIESettingsMain, KEY_READ);
436  std::wstring homepage_url;
437  if (key.ReadValue(kIEHomepage, &homepage_url) != ERROR_SUCCESS ||
438      homepage_url.empty())
439    return;
440
441  GURL homepage = GURL(homepage_url);
442  if (!homepage.is_valid())
443    return;
444
445  // Check to see if this is the default website and skip import.
446  base::win::RegKey keyDefault(HKEY_LOCAL_MACHINE, kIESettingsMain, KEY_READ);
447  std::wstring default_homepage_url;
448  LONG result = keyDefault.ReadValue(kIEDefaultHomepage, &default_homepage_url);
449  if (result == ERROR_SUCCESS && !default_homepage_url.empty()) {
450    if (homepage.spec() == GURL(default_homepage_url).spec())
451      return;
452  }
453
454  bridge_->AddHomePage(homepage);
455}
456
457bool IEImporter::GetFavoritesInfo(IEImporter::FavoritesInfo *info) {
458  if (!source_path_.empty()) {
459    // Source path exists during testing.
460    info->path = source_path_;
461    file_util::AppendToPath(&info->path, L"Favorites");
462    info->links_folder = L"Links";
463    return true;
464  }
465
466  // IE stores the favorites in the Favorites under user profile's folder.
467  wchar_t buffer[MAX_PATH];
468  if (FAILED(SHGetFolderPath(NULL, CSIDL_FAVORITES, NULL,
469                             SHGFP_TYPE_CURRENT, buffer)))
470    return false;
471  info->path = buffer;
472
473  // There is a Links folder under Favorites folder in Windows Vista, but it
474  // is not recording in Vista's registry. So in Vista, we assume the Links
475  // folder is under Favorites folder since it looks like there is not name
476  // different in every language version of Windows Vista.
477  if (base::win::GetVersion() < base::win::VERSION_VISTA) {
478    // The Link folder name is stored in the registry.
479    DWORD buffer_length = sizeof(buffer);
480    base::win::RegKey reg_key(HKEY_CURRENT_USER,
481        L"Software\\Microsoft\\Internet Explorer\\Toolbar", KEY_READ);
482    if (reg_key.ReadValue(L"LinksFolderName", buffer,
483                          &buffer_length, NULL) != ERROR_SUCCESS)
484      return false;
485    info->links_folder = buffer;
486  } else {
487    info->links_folder = L"Links";
488  }
489
490  return true;
491}
492
493void IEImporter::ParseFavoritesFolder(const FavoritesInfo& info,
494                                      BookmarkVector* bookmarks) {
495  std::wstring ie_folder =
496      UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOKMARK_GROUP_FROM_IE));
497  BookmarkVector toolbar_bookmarks;
498  FilePath file;
499  std::vector<FilePath::StringType> file_list;
500  FilePath favorites_path(info.path);
501  // Favorites path length.  Make sure it doesn't include the trailing \.
502  size_t favorites_path_len =
503      favorites_path.StripTrailingSeparators().value().size();
504  file_util::FileEnumerator file_enumerator(
505      favorites_path, true, file_util::FileEnumerator::FILES);
506  while (!(file = file_enumerator.Next()).value().empty() && !cancelled())
507    file_list.push_back(file.value());
508
509  // Keep the bookmarks in alphabetical order.
510  std::sort(file_list.begin(), file_list.end());
511
512  for (std::vector<FilePath::StringType>::iterator it = file_list.begin();
513       it != file_list.end(); ++it) {
514    FilePath shortcut(*it);
515    if (!LowerCaseEqualsASCII(shortcut.Extension(), ".url"))
516      continue;
517
518    // Skip the bookmark with invalid URL.
519    GURL url = GURL(ResolveInternetShortcut(*it));
520    if (!url.is_valid())
521      continue;
522
523    // Make the relative path from the Favorites folder, without the basename.
524    // ex. Suppose that the Favorites folder is C:\Users\Foo\Favorites.
525    //   C:\Users\Foo\Favorites\Foo.url -> ""
526    //   C:\Users\Foo\Favorites\Links\Bar\Baz.url -> "Links\Bar"
527    FilePath::StringType relative_string =
528        shortcut.DirName().value().substr(favorites_path_len);
529    if (relative_string.size() > 0 && FilePath::IsSeparator(relative_string[0]))
530      relative_string = relative_string.substr(1);
531    FilePath relative_path(relative_string);
532
533    ProfileWriter::BookmarkEntry entry;
534    // Remove the dot, the file extension, and the directory path.
535    entry.title = shortcut.RemoveExtension().BaseName().value();
536    entry.url = url;
537    entry.creation_time = GetFileCreationTime(*it);
538    if (!relative_path.empty())
539      relative_path.GetComponents(&entry.path);
540
541    // Flatten the bookmarks in Link folder onto bookmark toolbar. Otherwise,
542    // put it into "Other bookmarks".
543    if (import_to_bookmark_bar() &&
544        (entry.path.size() > 0 && entry.path[0] == info.links_folder)) {
545      entry.in_toolbar = true;
546      entry.path.erase(entry.path.begin());
547      toolbar_bookmarks.push_back(entry);
548    } else {
549      // We put the bookmarks in a "Imported From IE"
550      // folder, so that we don't mess up the "Other bookmarks".
551      if (!import_to_bookmark_bar())
552        entry.path.insert(entry.path.begin(), ie_folder);
553      bookmarks->push_back(entry);
554    }
555  }
556  bookmarks->insert(bookmarks->begin(), toolbar_bookmarks.begin(),
557                    toolbar_bookmarks.end());
558}
559
560std::wstring IEImporter::ResolveInternetShortcut(const std::wstring& file) {
561  app::win::ScopedCoMem<wchar_t> url;
562  ScopedComPtr<IUniformResourceLocator> url_locator;
563  HRESULT result = url_locator.CreateInstance(CLSID_InternetShortcut, NULL,
564                                              CLSCTX_INPROC_SERVER);
565  if (FAILED(result))
566    return std::wstring();
567
568  ScopedComPtr<IPersistFile> persist_file;
569  result = persist_file.QueryFrom(url_locator);
570  if (FAILED(result))
571    return std::wstring();
572
573  // Loads the Internet Shortcut from persistent storage.
574  result = persist_file->Load(file.c_str(), STGM_READ);
575  if (FAILED(result))
576    return std::wstring();
577
578  result = url_locator->GetURL(&url);
579  // GetURL can return S_FALSE (FAILED(S_FALSE) is false) when url == NULL.
580  if (FAILED(result) || (url == NULL))
581    return std::wstring();
582
583  return std::wstring(url);
584}
585
586int IEImporter::CurrentIEVersion() const {
587  static int version = -1;
588  if (version < 0) {
589    wchar_t buffer[128];
590    DWORD buffer_length = sizeof(buffer);
591    base::win::RegKey reg_key(HKEY_LOCAL_MACHINE,
592        L"Software\\Microsoft\\Internet Explorer", KEY_READ);
593    LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL);
594    version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0);
595  }
596  return version;
597}
598