summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorbenwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-10 12:50:11 +0000
committerbenwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-10 12:50:11 +0000
commitc002e757a3ce8027631cd2f22e5ec0f9b1322b14 (patch)
tree3f20648c028edf46c9ed9115af838276ae5a8cd0 /base
parent44cd60e5d3cc1005ac02792cae967af33052a996 (diff)
downloadchromium_src-c002e757a3ce8027631cd2f22e5ec0f9b1322b14.zip
chromium_src-c002e757a3ce8027631cd2f22e5ec0f9b1322b14.tar.gz
chromium_src-c002e757a3ce8027631cd2f22e5ec0f9b1322b14.tar.bz2
Remove packaged app Windows shortcuts when app is uninstalled.
BUG=130456 TEST=Check app shortcuts are removed when the app is uninstalled. Test extension uninstallation in general. Review URL: https://chromiumcodereview.appspot.com/10837034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151021 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/file_util.h14
-rw-r--r--base/file_util_unittest.cc10
-rw-r--r--base/file_util_win.cc63
3 files changed, 56 insertions, 31 deletions
diff --git a/base/file_util.h b/base/file_util.h
index fb6f624..a868112 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -235,10 +235,16 @@ enum ShortcutOptions {
};
// Resolve Windows shortcut (.LNK file)
-// This methods tries to resolve a shortcut .LNK file. If the |path| is valid
-// returns true and puts the target into the |path|, otherwise returns
-// false leaving the path as it is.
-BASE_EXPORT bool ResolveShortcut(FilePath* path);
+// This methods tries to resolve a shortcut .LNK file. The path of the shortcut
+// to resolve is in |shortcut_path|. If |target_path| is not NULL, the target
+// will be resolved and placed in |target_path|. If |args| is not NULL, the
+// arguments will be retrieved and placed in |args|. The function returns true
+// if all requested fields are are found successfully.
+// Callers can safely use the same variable for both |shortcut_path| and
+// |target_path|.
+BASE_EXPORT bool ResolveShortcut(const FilePath& shortcut_path,
+ FilePath* target_path,
+ string16* args);
// Creates (or updates) a Windows shortcut (.LNK file)
// This method creates (or updates) a shortcut link using the information given.
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index 25e2f40..b471f88 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -1617,6 +1617,8 @@ TEST_F(FileUtilTest, ResolveShortcutTest) {
EXPECT_TRUE(SUCCEEDED(result));
result = shell->SetDescription(L"ResolveShortcutTest");
EXPECT_TRUE(SUCCEEDED(result));
+ result = shell->SetArguments(L"--args");
+ EXPECT_TRUE(SUCCEEDED(result));
result = persist->Save(link_file.value().c_str(), TRUE);
EXPECT_TRUE(SUCCEEDED(result));
if (persist)
@@ -1625,8 +1627,10 @@ TEST_F(FileUtilTest, ResolveShortcutTest) {
shell->Release();
bool is_solved;
- is_solved = file_util::ResolveShortcut(&link_file);
+ std::wstring args;
+ is_solved = file_util::ResolveShortcut(link_file, &link_file, &args);
EXPECT_TRUE(is_solved);
+ EXPECT_EQ(L"--args", args);
std::wstring contents;
contents = ReadTextFile(link_file);
EXPECT_EQ(L"This is the target.", contents);
@@ -1649,8 +1653,8 @@ TEST_F(FileUtilTest, CreateShortcutTest) {
target_file.value().c_str(), link_file.value().c_str(), NULL,
NULL, NULL, NULL, 0, NULL,
file_util::SHORTCUT_CREATE_ALWAYS));
- FilePath resolved_name = link_file;
- EXPECT_TRUE(file_util::ResolveShortcut(&resolved_name));
+ FilePath resolved_name;
+ EXPECT_TRUE(file_util::ResolveShortcut(link_file, &resolved_name, NULL));
std::wstring read_contents = ReadTextFile(resolved_name);
EXPECT_EQ(file_contents, read_contents);
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index bf9dd9c..6602121 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -332,38 +332,53 @@ bool GetFileCreationLocalTime(const std::wstring& filename,
return GetFileCreationLocalTimeFromHandle(file_handle.Get(), creation_time);
}
-bool ResolveShortcut(FilePath* path) {
+bool ResolveShortcut(const FilePath& shortcut_path,
+ FilePath* target_path,
+ string16* args) {
base::ThreadRestrictions::AssertIOAllowed();
HRESULT result;
base::win::ScopedComPtr<IShellLink> i_shell_link;
- bool is_resolved = false;
- // Get pointer to the IShellLink interface
+ // Get pointer to the IShellLink interface.
result = i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER);
- if (SUCCEEDED(result)) {
- base::win::ScopedComPtr<IPersistFile> persist;
- // Query IShellLink for the IPersistFile interface
- result = persist.QueryFrom(i_shell_link);
- if (SUCCEEDED(result)) {
- WCHAR temp_path[MAX_PATH];
- // Load the shell link
- result = persist->Load(path->value().c_str(), STGM_READ);
- if (SUCCEEDED(result)) {
- // Try to find the target of a shortcut
- result = i_shell_link->Resolve(0, SLR_NO_UI);
- if (SUCCEEDED(result)) {
- result = i_shell_link->GetPath(temp_path, MAX_PATH,
- NULL, SLGP_UNCPRIORITY);
- *path = FilePath(temp_path);
- is_resolved = true;
- }
- }
- }
+ if (FAILED(result))
+ return false;
+
+ base::win::ScopedComPtr<IPersistFile> persist;
+ // Query IShellLink for the IPersistFile interface.
+ result = persist.QueryFrom(i_shell_link);
+ if (FAILED(result))
+ return false;
+
+ // Load the shell link.
+ result = persist->Load(shortcut_path.value().c_str(), STGM_READ);
+ if (FAILED(result))
+ return false;
+
+ WCHAR temp[MAX_PATH];
+ if (target_path) {
+ // Try to find the target of a shortcut.
+ result = i_shell_link->Resolve(0, SLR_NO_UI);
+ if (FAILED(result))
+ return false;
+
+ result = i_shell_link->GetPath(temp, MAX_PATH, NULL, SLGP_UNCPRIORITY);
+ if (FAILED(result))
+ return false;
+
+ *target_path = FilePath(temp);
}
- return is_resolved;
+ if (args) {
+ result = i_shell_link->GetArguments(temp, MAX_PATH);
+ if (FAILED(result))
+ return false;
+
+ *args = string16(temp);
+ }
+ return true;
}
bool CreateOrUpdateShortcutLink(const wchar_t *source,
@@ -389,7 +404,7 @@ bool CreateOrUpdateShortcutLink(const wchar_t *source,
base::win::ScopedComPtr<IShellLink> i_shell_link;
base::win::ScopedComPtr<IPersistFile> i_persist_file;
- // Get pointer to the IShellLink interface
+ // Get pointer to the IShellLink interface.
if (FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER)) ||
FAILED(i_persist_file.QueryFrom(i_shell_link))) {