| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_JUMPLIST_UPDATER_WIN_H_ | |
| 6 #define CHROME_BROWSER_JUMPLIST_UPDATER_WIN_H_ | |
| 7 | |
| 8 #include <windows.h> | |
| 9 #include <shobjidl.h> | |
| 10 #include <stddef.h> | |
| 11 | |
| 12 #include <string> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "base/command_line.h" | |
| 16 #include "base/macros.h" | |
| 17 #include "base/memory/ref_counted.h" | |
| 18 #include "base/win/scoped_comptr.h" | |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | |
| 20 | |
| 21 // Represents a class used for creating an IShellLink object. | |
| 22 // Even though an IShellLink also needs the absolute path to an application to | |
| 23 // be executed, this class does not have any variables for it because current | |
| 24 // users always use "chrome.exe" as the application. | |
| 25 class ShellLinkItem : public base::RefCountedThreadSafe<ShellLinkItem> { | |
| 26 public: | |
| 27 ShellLinkItem(); | |
| 28 | |
| 29 const std::wstring& title() const { return title_; } | |
| 30 const std::wstring& icon_path() const { return icon_path_; } | |
| 31 int icon_index() const { return icon_index_; } | |
| 32 const SkBitmap& icon_data() const { return icon_data_; } | |
| 33 | |
| 34 std::wstring GetArguments() const; | |
| 35 base::CommandLine* GetCommandLine(); | |
| 36 | |
| 37 void set_title(const std::wstring& title) { | |
| 38 title_ = title; | |
| 39 } | |
| 40 | |
| 41 void set_icon(const std::wstring& path, int index) { | |
| 42 icon_path_ = path; | |
| 43 icon_index_ = index; | |
| 44 } | |
| 45 | |
| 46 void set_icon_data(const SkBitmap& data) { | |
| 47 icon_data_ = data; | |
| 48 } | |
| 49 | |
| 50 private: | |
| 51 friend class base::RefCountedThreadSafe<ShellLinkItem>; | |
| 52 ~ShellLinkItem(); | |
| 53 | |
| 54 // Used for storing and appending command-line arguments. | |
| 55 base::CommandLine command_line_; | |
| 56 | |
| 57 // The string to be displayed in a JumpList. | |
| 58 std::wstring title_; | |
| 59 | |
| 60 // The absolute path to an icon to be displayed in a JumpList. | |
| 61 std::wstring icon_path_; | |
| 62 | |
| 63 // The icon index in the icon file. If an icon file consists of two or more | |
| 64 // icons, set this value to identify the icon. If an icon file consists of | |
| 65 // one icon, this value is 0. | |
| 66 int icon_index_; | |
| 67 | |
| 68 // Icon bitmap. Used by the browser JumpList. | |
| 69 // Note that an icon path must be supplied to IShellLink, so users of this | |
| 70 // class must save icon data to disk. | |
| 71 SkBitmap icon_data_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(ShellLinkItem); | |
| 74 }; | |
| 75 | |
| 76 typedef std::vector<scoped_refptr<ShellLinkItem> > ShellLinkItemList; | |
| 77 | |
| 78 | |
| 79 // A utility class that hides the boilerplate for updating Windows JumpLists. | |
| 80 // Note that JumpLists are available in Windows 7 and later only. | |
| 81 // | |
| 82 // Example of usage: | |
| 83 // | |
| 84 // JumpListUpdater updater(app_id); | |
| 85 // if (updater.BeginUpdate()) { | |
| 86 // updater.AddTasks(...); | |
| 87 // updater.AddCustomCategory(...); | |
| 88 // updater.CommitUpdate(); | |
| 89 // } | |
| 90 // | |
| 91 // Note: | |
| 92 // - Each JumpListUpdater instance is expected to be used once only. | |
| 93 // - The JumpList must be updated in its entirety, i.e. even if a category has | |
| 94 // not changed, all its items must be added in each update. | |
| 95 class JumpListUpdater { | |
| 96 public: | |
| 97 explicit JumpListUpdater(const std::wstring& app_user_model_id); | |
| 98 ~JumpListUpdater(); | |
| 99 | |
| 100 // Returns true if JumpLists are enabled on this OS. | |
| 101 static bool IsEnabled(); | |
| 102 | |
| 103 // Returns the current user setting for the maximum number of items to display | |
| 104 // in JumpLists. The setting is retrieved in BeginUpdate(). | |
| 105 size_t user_max_items() const { return user_max_items_; } | |
| 106 | |
| 107 // Starts a transaction that updates the JumpList of this application. | |
| 108 // This must be called prior to updating the JumpList. If this function | |
| 109 // returns false, this instance should not be used. | |
| 110 bool BeginUpdate(); | |
| 111 | |
| 112 // Commits the update. | |
| 113 bool CommitUpdate(); | |
| 114 | |
| 115 // Updates the predefined "Tasks" category of the JumpList. | |
| 116 bool AddTasks(const ShellLinkItemList& link_items); | |
| 117 | |
| 118 // Updates an unregistered category of the JumpList. | |
| 119 // This function cannot update registered categories (such as "Tasks") | |
| 120 // because special steps are required for updating them. | |
| 121 // |max_items| specifies the maximum number of items from |link_items| to add | |
| 122 // to the JumpList. | |
| 123 bool AddCustomCategory(const std::wstring& category_name, | |
| 124 const ShellLinkItemList& link_items, | |
| 125 size_t max_items); | |
| 126 | |
| 127 private: | |
| 128 // The app ID. | |
| 129 std::wstring app_user_model_id_; | |
| 130 | |
| 131 // Windows API interface used to modify JumpLists. | |
| 132 base::win::ScopedComPtr<ICustomDestinationList> destination_list_; | |
| 133 | |
| 134 // The current user setting for "Number of recent items to display in Jump | |
| 135 // Lists" option in the "Taskbar and Start Menu Properties". | |
| 136 size_t user_max_items_; | |
| 137 | |
| 138 DISALLOW_COPY_AND_ASSIGN(JumpListUpdater); | |
| 139 }; | |
| 140 | |
| 141 #endif // CHROME_BROWSER_JUMPLIST_UPDATER_WIN_H_ | |
| OLD | NEW |