Improve performance of registering font preferences
[chromium-blink-merge.git] / base / win / shortcut.h
blobc1e7d5c04f0cd2002f4ec3aca4a607a1d21f68b0
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
3 // found in the LICENSE file.
5 #ifndef BASE_WIN_SHORTCUT_H_
6 #define BASE_WIN_SHORTCUT_H_
8 #include <windows.h>
10 #include "base/logging.h"
11 #include "base/file_path.h"
12 #include "base/string16.h"
14 namespace base {
15 namespace win {
17 enum ShortcutOperation {
18 // Create a new shortcut (overwriting if necessary).
19 SHORTCUT_CREATE_ALWAYS = 0,
20 // Overwrite an existing shortcut (fails if the shortcut doesn't exist).
21 SHORTCUT_REPLACE_EXISTING,
22 // Update specified properties only on an existing shortcut.
23 SHORTCUT_UPDATE_EXISTING,
26 // Properties for shortcuts. Properties set will be applied to the shortcut on
27 // creation/update, others will be ignored.
28 // Callers are encouraged to use the setters provided which take care of
29 // setting |options| as desired.
30 struct ShortcutProperties {
31 enum IndividualProperties {
32 PROPERTIES_TARGET = 1 << 0,
33 PROPERTIES_WORKING_DIR = 1 << 1,
34 PROPERTIES_ARGUMENTS = 1 << 2,
35 PROPERTIES_DESCRIPTION = 1 << 3,
36 PROPERTIES_ICON = 1 << 4,
37 PROPERTIES_APP_ID = 1 << 5,
38 PROPERTIES_DUAL_MODE = 1 << 6,
41 ShortcutProperties() : icon_index(-1), dual_mode(false), options(0U) {}
43 void set_target(const FilePath& target_in) {
44 target = target_in;
45 options |= PROPERTIES_TARGET;
48 void set_working_dir(const FilePath& working_dir_in) {
49 working_dir = working_dir_in;
50 options |= PROPERTIES_WORKING_DIR;
53 void set_arguments(const string16& arguments_in) {
54 // Size restriction as per MSDN at http://goo.gl/TJ7q5.
55 DCHECK(arguments_in.size() < MAX_PATH);
56 arguments = arguments_in;
57 options |= PROPERTIES_ARGUMENTS;
60 void set_description(const string16& description_in) {
61 // Size restriction as per MSDN at http://goo.gl/OdNQq.
62 DCHECK(description_in.size() < MAX_PATH);
63 description = description_in;
64 options |= PROPERTIES_DESCRIPTION;
67 void set_icon(const FilePath& icon_in, int icon_index_in) {
68 icon = icon_in;
69 icon_index = icon_index_in;
70 options |= PROPERTIES_ICON;
73 void set_app_id(const string16& app_id_in) {
74 app_id = app_id_in;
75 options |= PROPERTIES_APP_ID;
78 void set_dual_mode(bool dual_mode_in) {
79 dual_mode = dual_mode_in;
80 options |= PROPERTIES_DUAL_MODE;
83 // The target to launch from this shortcut. This is mandatory when creating
84 // a shortcut.
85 FilePath target;
86 // The name of the working directory when launching the shortcut.
87 FilePath working_dir;
88 // The arguments to be applied to |target| when launching from this shortcut.
89 // The length of this string must be less than MAX_PATH.
90 string16 arguments;
91 // The localized description of the shortcut.
92 // The length of this string must be less than MAX_PATH.
93 string16 description;
94 // The path to the icon (can be a dll or exe, in which case |icon_index| is
95 // the resource id).
96 FilePath icon;
97 int icon_index;
98 // The app model id for the shortcut (Win7+).
99 string16 app_id;
100 // Whether this is a dual mode shortcut (Win8+).
101 bool dual_mode;
102 // Bitfield made of IndividualProperties. Properties set in |options| will be
103 // set on the shortcut, others will be ignored.
104 uint32 options;
107 // This method creates (or updates) a shortcut link at |shortcut_path| using the
108 // information given through |properties|.
109 // Ensure you have initialized COM before calling into this function.
110 // |operation|: a choice from the ShortcutOperation enum.
111 // If |operation| is SHORTCUT_REPLACE_EXISTING or SHORTCUT_UPDATE_EXISTING and
112 // |shortcut_path| does not exist, this method is a no-op and returns false.
113 BASE_EXPORT bool CreateOrUpdateShortcutLink(
114 const FilePath& shortcut_path,
115 const ShortcutProperties& properties,
116 ShortcutOperation operation);
118 // Resolve Windows shortcut (.LNK file)
119 // This methods tries to resolve a shortcut .LNK file. The path of the shortcut
120 // to resolve is in |shortcut_path|. If |target_path| is not NULL, the target
121 // will be resolved and placed in |target_path|. If |args| is not NULL, the
122 // arguments will be retrieved and placed in |args|. The function returns true
123 // if all requested fields are found successfully.
124 // Callers can safely use the same variable for both |shortcut_path| and
125 // |target_path|.
126 BASE_EXPORT bool ResolveShortcut(const FilePath& shortcut_path,
127 FilePath* target_path,
128 string16* args);
130 // Pins a shortcut to the Windows 7 taskbar. The shortcut file must already
131 // exist and be a shortcut that points to an executable.
132 BASE_EXPORT bool TaskbarPinShortcutLink(const wchar_t* shortcut);
134 // Unpins a shortcut from the Windows 7 taskbar. The shortcut must exist and
135 // already be pinned to the taskbar.
136 BASE_EXPORT bool TaskbarUnpinShortcutLink(const wchar_t* shortcut);
138 } // namespace win
139 } // namespace base
141 #endif // BASE_WIN_SHORTCUT_H_