Chromium Code Reviews| Index: chrome/browser/file_associations_win.cc |
| diff --git a/chrome/browser/file_associations_win.cc b/chrome/browser/file_associations_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..38e9f7ec67c896efcd0d31140869c79eea099dd7 |
| --- /dev/null |
| +++ b/chrome/browser/file_associations_win.cc |
| @@ -0,0 +1,45 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/file_associations_win.h" |
| + |
| +#include <shlobj.h> |
| + |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "chrome/installer/util/shell_util.h" |
| + |
| +bool AddWindowsFileAssociations(const std::string& progid, |
| + const base::CommandLine& command_line, |
| + const std::string& file_type_name, |
| + const base::FilePath& icon_path, |
| + const std::set<std::string>& file_extensions) { |
| + std::set<base::string16> file_extensions_16; |
| + for (std::set<std::string>::const_iterator it = file_extensions.begin(); |
| + it != file_extensions.end(); |
| + ++it) { |
| + file_extensions_16.insert(base::UTF8ToUTF16(*it)); |
| + } |
| + if (!ShellUtil::AddFileAssociations(base::UTF8ToUTF16(progid), |
| + command_line, |
| + base::UTF8ToUTF16(file_type_name), |
| + icon_path, |
| + file_extensions_16)) { |
| + return false; |
| + } |
| + |
| + // Success. Tell Windows Explorer to update its cache. |
| + SHChangeNotify( |
| + SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, NULL, NULL); |
|
gab
2014/09/12 13:32:36
IIRC this will also produce a fly-in on Win8 telli
gab
2014/09/18 01:16:14
ping.
Matt Giuca
2014/09/30 10:21:12
I tried this on Windows 8 and I didn't see any fly
gab
2014/10/01 14:31:11
The default is for the notification to be buffered
Matt Giuca
2014/10/02 09:36:33
Thanks for the summary. Makes sense.
|
| + return true; |
| +} |
| + |
| +bool DeleteWindowsFileAssociations(const std::string& progid) { |
| + if (!ShellUtil::DeleteFileAssociations(base::UTF8ToUTF16(progid))) |
| + return false; |
| + |
| + // Success. Tell Windows Explorer to update its cache. |
| + SHChangeNotify( |
| + SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, NULL, NULL); |
| + return true; |
| +} |