| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_MENU_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_MENU_MANAGER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_MENU_MANAGER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_MENU_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> |
| 12 #include <set> | 13 #include <set> |
| 13 #include <string> | 14 #include <string> |
| 14 #include <vector> | 15 #include <vector> |
| 15 | 16 |
| 16 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 17 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
| 18 #include "base/macros.h" | 19 #include "base/macros.h" |
| 19 #include "base/memory/scoped_ptr.h" | |
| 20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 21 #include "base/scoped_observer.h" | 21 #include "base/scoped_observer.h" |
| 22 #include "base/strings/string16.h" | 22 #include "base/strings/string16.h" |
| 23 #include "base/values.h" | 23 #include "base/values.h" |
| 24 #include "chrome/browser/extensions/extension_icon_manager.h" | 24 #include "chrome/browser/extensions/extension_icon_manager.h" |
| 25 #include "components/keyed_service/core/keyed_service.h" | 25 #include "components/keyed_service/core/keyed_service.h" |
| 26 #include "content/public/browser/notification_observer.h" | 26 #include "content/public/browser/notification_observer.h" |
| 27 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
| 28 #include "extensions/browser/extension_registry_observer.h" | 28 #include "extensions/browser/extension_registry_observer.h" |
| 29 #include "extensions/common/url_pattern_set.h" | 29 #include "extensions/common/url_pattern_set.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool Contains(Context context) const { | 139 bool Contains(Context context) const { |
| 140 return (value_ & context) > 0; | 140 return (value_ & context) > 0; |
| 141 } | 141 } |
| 142 | 142 |
| 143 void Add(Context context) { | 143 void Add(Context context) { |
| 144 value_ |= context; | 144 value_ |= context; |
| 145 } | 145 } |
| 146 | 146 |
| 147 scoped_ptr<base::Value> ToValue() const { | 147 std::unique_ptr<base::Value> ToValue() const { |
| 148 return scoped_ptr<base::Value>( | 148 return std::unique_ptr<base::Value>( |
| 149 new base::FundamentalValue(static_cast<int>(value_))); | 149 new base::FundamentalValue(static_cast<int>(value_))); |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool Populate(const base::Value& value) { | 152 bool Populate(const base::Value& value) { |
| 153 int int_value; | 153 int int_value; |
| 154 if (!value.GetAsInteger(&int_value) || int_value < 0) | 154 if (!value.GetAsInteger(&int_value) || int_value < 0) |
| 155 return false; | 155 return false; |
| 156 value_ = int_value; | 156 value_ = int_value; |
| 157 return true; | 157 return true; |
| 158 } | 158 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 204 |
| 205 // Returns the title with any instances of %s replaced by |selection|. The | 205 // Returns the title with any instances of %s replaced by |selection|. The |
| 206 // result will be no longer than |max_length|. | 206 // result will be no longer than |max_length|. |
| 207 base::string16 TitleWithReplacement(const base::string16& selection, | 207 base::string16 TitleWithReplacement(const base::string16& selection, |
| 208 size_t max_length) const; | 208 size_t max_length) const; |
| 209 | 209 |
| 210 // Sets the checked state to |checked|. Returns true if successful. | 210 // Sets the checked state to |checked|. Returns true if successful. |
| 211 bool SetChecked(bool checked); | 211 bool SetChecked(bool checked); |
| 212 | 212 |
| 213 // Converts to Value for serialization to preferences. | 213 // Converts to Value for serialization to preferences. |
| 214 scoped_ptr<base::DictionaryValue> ToValue() const; | 214 std::unique_ptr<base::DictionaryValue> ToValue() const; |
| 215 | 215 |
| 216 // Returns a new MenuItem created from |value|, or NULL if there is | 216 // Returns a new MenuItem created from |value|, or NULL if there is |
| 217 // an error. The caller takes ownership of the MenuItem. | 217 // an error. The caller takes ownership of the MenuItem. |
| 218 static MenuItem* Populate(const std::string& extension_id, | 218 static MenuItem* Populate(const std::string& extension_id, |
| 219 const base::DictionaryValue& value, | 219 const base::DictionaryValue& value, |
| 220 std::string* error); | 220 std::string* error); |
| 221 | 221 |
| 222 // Sets any document and target URL patterns from |properties|. | 222 // Sets any document and target URL patterns from |properties|. |
| 223 bool PopulateURLPatterns(std::vector<std::string>* document_url_patterns, | 223 bool PopulateURLPatterns(std::vector<std::string>* document_url_patterns, |
| 224 std::vector<std::string>* target_url_patterns, | 224 std::vector<std::string>* target_url_patterns, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 255 bool checked_; | 255 bool checked_; |
| 256 | 256 |
| 257 // If the item is enabled or not. | 257 // If the item is enabled or not. |
| 258 bool enabled_; | 258 bool enabled_; |
| 259 | 259 |
| 260 // In what contexts should the item be shown? | 260 // In what contexts should the item be shown? |
| 261 ContextList contexts_; | 261 ContextList contexts_; |
| 262 | 262 |
| 263 // If this item is a child of another item, the unique id of its parent. If | 263 // If this item is a child of another item, the unique id of its parent. If |
| 264 // this is a top-level item with no parent, this will be NULL. | 264 // this is a top-level item with no parent, this will be NULL. |
| 265 scoped_ptr<Id> parent_id_; | 265 std::unique_ptr<Id> parent_id_; |
| 266 | 266 |
| 267 // Patterns for restricting what documents this item will appear for. This | 267 // Patterns for restricting what documents this item will appear for. This |
| 268 // applies to the frame where the click took place. | 268 // applies to the frame where the click took place. |
| 269 URLPatternSet document_url_patterns_; | 269 URLPatternSet document_url_patterns_; |
| 270 | 270 |
| 271 // Patterns for restricting where items appear based on the src/href | 271 // Patterns for restricting where items appear based on the src/href |
| 272 // attribute of IMAGE/AUDIO/VIDEO/LINK tags. | 272 // attribute of IMAGE/AUDIO/VIDEO/LINK tags. |
| 273 URLPatternSet target_url_patterns_; | 273 URLPatternSet target_url_patterns_; |
| 274 | 274 |
| 275 // Any children this item may have. | 275 // Any children this item may have. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 const Extension* extension, | 362 const Extension* extension, |
| 363 UnloadedExtensionInfo::Reason reason) override; | 363 UnloadedExtensionInfo::Reason reason) override; |
| 364 | 364 |
| 365 // Stores the menu items for the extension in the state storage. | 365 // Stores the menu items for the extension in the state storage. |
| 366 void WriteToStorage(const Extension* extension, | 366 void WriteToStorage(const Extension* extension, |
| 367 const MenuItem::ExtensionKey& extension_key); | 367 const MenuItem::ExtensionKey& extension_key); |
| 368 | 368 |
| 369 // Reads menu items for the extension from the state storage. Any invalid | 369 // Reads menu items for the extension from the state storage. Any invalid |
| 370 // items are ignored. | 370 // items are ignored. |
| 371 void ReadFromStorage(const std::string& extension_id, | 371 void ReadFromStorage(const std::string& extension_id, |
| 372 scoped_ptr<base::Value> value); | 372 std::unique_ptr<base::Value> value); |
| 373 | 373 |
| 374 // Removes all "incognito" "split" mode context items. | 374 // Removes all "incognito" "split" mode context items. |
| 375 void RemoveAllIncognitoContextItems(); | 375 void RemoveAllIncognitoContextItems(); |
| 376 | 376 |
| 377 private: | 377 private: |
| 378 FRIEND_TEST_ALL_PREFIXES(MenuManagerTest, DeleteParent); | 378 FRIEND_TEST_ALL_PREFIXES(MenuManagerTest, DeleteParent); |
| 379 FRIEND_TEST_ALL_PREFIXES(MenuManagerTest, RemoveOneByOne); | 379 FRIEND_TEST_ALL_PREFIXES(MenuManagerTest, RemoveOneByOne); |
| 380 | 380 |
| 381 // This is a helper function which takes care of de-selecting any other radio | 381 // This is a helper function which takes care of de-selecting any other radio |
| 382 // items in the same group (i.e. that are adjacent in the list). | 382 // items in the same group (i.e. that are adjacent in the list). |
| (...skipping 29 matching lines...) Expand all Loading... |
| 412 | 412 |
| 413 // Owned by ExtensionSystem. | 413 // Owned by ExtensionSystem. |
| 414 StateStore* store_; | 414 StateStore* store_; |
| 415 | 415 |
| 416 DISALLOW_COPY_AND_ASSIGN(MenuManager); | 416 DISALLOW_COPY_AND_ASSIGN(MenuManager); |
| 417 }; | 417 }; |
| 418 | 418 |
| 419 } // namespace extensions | 419 } // namespace extensions |
| 420 | 420 |
| 421 #endif // CHROME_BROWSER_EXTENSIONS_MENU_MANAGER_H_ | 421 #endif // CHROME_BROWSER_EXTENSIONS_MENU_MANAGER_H_ |
| OLD | NEW |