OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 EXTENSIONS_BROWSER_MANIFEST_HIGHLIGHTER_H_ |
| 6 #define EXTENSIONS_BROWSER_MANIFEST_HIGHLIGHTER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 |
| 12 namespace extensions { |
| 13 |
| 14 // Use the ManifestHighlighter class to find the bounds of a feature in the |
| 15 // manifest. The manifest is parsed for the feature upon construction of the |
| 16 // object. |
| 17 // A feature can be at any level in the hierarchy. The "start" of a feature is |
| 18 // the first character of the feature name, or the beginning quote of the name, |
| 19 // if present. The "end" of a feature is wherever the next item at the same |
| 20 // level starts. |
| 21 // For instance, the bounds for the 'permissions' feature at the top level could |
| 22 // be '"permissions": { "tabs", "history", "downloads" }', but the feature for |
| 23 // 'tabs' within 'permissions' would just be '"tabs"'. |
| 24 // We can't use the JSONParser to do this, because we want to display the actual |
| 25 // manifest, and once we parse it into Values, we lose any formatting the user |
| 26 // may have had. |
| 27 // If a feature cannot be found, the feature will have zero-length. |
| 28 class ManifestHighlighter { |
| 29 public: |
| 30 ManifestHighlighter(const std::string& manifest, |
| 31 const std::string& key, |
| 32 const std::string& specific /* optional */); |
| 33 ~ManifestHighlighter(); |
| 34 |
| 35 // Get the portion of the manifest which should not be highlighted and is |
| 36 // before the feature. |
| 37 std::string GetBeforeFeature() const; |
| 38 // Get the feature portion of the manifest, which should be highlighted. |
| 39 std::string GetFeature() const; |
| 40 // Get the portion of the manifest which should not be highlighted and is |
| 41 // after the feature. |
| 42 std::string GetAfterFeature() const; |
| 43 |
| 44 private: |
| 45 // Called from the constructor; determine the start and end bounds of a |
| 46 // feature, using both the key and specific information. |
| 47 void Parse(const std::string& key, const std::string& specific); |
| 48 |
| 49 // Find the bounds of any feature, either a full key or a specific item within |
| 50 // the key. |enforce_at_top_level| means that the feature we find must be at |
| 51 // the same level as |start_| (i.e., ignore nested elements). |
| 52 // Returns true on success. |
| 53 bool FindBounds(const std::string& feature, bool enforce_at_top_level); |
| 54 // Finds the end of the feature. |
| 55 void FindBoundsEnd(const std::string& feature, size_t local_start); |
| 56 |
| 57 // The manifest we are parsing. |
| 58 std::string manifest_; |
| 59 // The start of the feature. |
| 60 size_t start_; |
| 61 // The end of the feature. |
| 62 size_t end_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(ManifestHighlighter); |
| 65 }; |
| 66 |
| 67 } // namespace extensions |
| 68 |
| 69 #endif // EXTENSIONS_BROWSER_MANIFEST_HIGHLIGHTER_H_ |
OLD | NEW |