Chromium Code Reviews| Index: extensions/browser/file_highlighter.h |
| diff --git a/extensions/browser/manifest_highlighter.h b/extensions/browser/file_highlighter.h |
| similarity index 59% |
| rename from extensions/browser/manifest_highlighter.h |
| rename to extensions/browser/file_highlighter.h |
| index bb20fef7d835fea2aad8f16c242c6724dee9fb50..34b10a0d505ad0509b8a8056d0592cde16055461 100644 |
| --- a/extensions/browser/manifest_highlighter.h |
| +++ b/extensions/browser/file_highlighter.h |
| @@ -2,18 +2,66 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef EXTENSIONS_BROWSER_MANIFEST_HIGHLIGHTER_H_ |
| -#define EXTENSIONS_BROWSER_MANIFEST_HIGHLIGHTER_H_ |
| +#ifndef EXTENSIONS_BROWSER_FILE_HIGHLIGHTER_H_ |
| +#define EXTENSIONS_BROWSER_FILE_HIGHLIGHTER_H_ |
| #include <string> |
| #include "base/basictypes.h" |
| +namespace base { |
| +class DictionaryValue; |
| +} |
| + |
| namespace extensions { |
| -// Use the ManifestHighlighter class to find the bounds of a feature in the |
| -// manifest. The manifest is parsed for the feature upon construction of the |
| +// The FileHighlighter class is used in order to isolate and highlight a portion |
| +// of a given file (in string form). The Highlighter will split the source into |
| +// three portions: the portion before the highlighted feature, the highlighted |
| +// feature, and the portion following the highlighted feature. |
| +// The file will be parsed for highlighting upon construction of the Highlighter |
| // object. |
| +class FileHighlighter { |
| + public: |
| + virtual ~FileHighlighter(); |
| + |
| + // Get the portion of the manifest which should not be highlighted and is |
| + // before the feature. |
| + std::string GetBeforeFeature() const; |
| + |
| + // Get the feature portion of the manifest, which should be highlighted. |
| + std::string GetFeature() const; |
| + |
| + // Get the portion of the manifest which should not be highlighted and is |
| + // after the feature. |
| + std::string GetAfterFeature() const; |
| + |
| + // Populate a DictionaryValue with the highlighted portions (in UTF16) of the |
| + // source file. |
| + void HighlightDictionary(base::DictionaryValue* dict) const; |
|
Yoyo Zhou
2013/09/04 23:43:39
This name could be better, like SetHighlightedRegi
Devlin
2013/09/05 17:53:55
Done.
|
| + |
| + // The keys used in highlighting a dictionary. |
|
Yoyo Zhou
2013/09/04 23:43:39
These needn't be declared in the header file if th
Devlin
2013/09/05 17:53:55
Done.
|
| + static const char kBeforeHighlightKey[]; |
| + static const char kHighlightKey[]; |
| + static const char kAfterHighlightKey[]; |
| + |
| + protected: |
| + FileHighlighter(const std::string& contents); |
| + |
| + // The contents of the file we are parsing. |
| + std::string contents_; |
| + |
| + // The start of the feature. |
| + size_t start_; |
| + |
| + // The end of the feature. |
| + size_t end_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(FileHighlighter); |
| +}; |
| + |
| +// Use the ManifestHighlighter class to find the bounds of a feature in the |
| +// manifest. |
| // A feature can be at any level in the hierarchy. The "start" of a feature is |
| // the first character of the feature name, or the beginning quote of the name, |
| // if present. The "end" of a feature is wherever the next item at the same |
| @@ -25,23 +73,12 @@ namespace extensions { |
| // manifest, and once we parse it into Values, we lose any formatting the user |
| // may have had. |
| // If a feature cannot be found, the feature will have zero-length. |
| -class ManifestHighlighter { |
| +class ManifestHighlighter : public FileHighlighter { |
| public: |
| ManifestHighlighter(const std::string& manifest, |
| const std::string& key, |
| const std::string& specific /* optional */); |
| - ~ManifestHighlighter(); |
| - |
| - // Get the portion of the manifest which should not be highlighted and is |
| - // before the feature. |
| - std::string GetBeforeFeature() const; |
| - |
| - // Get the feature portion of the manifest, which should be highlighted. |
| - std::string GetFeature() const; |
| - |
| - // Get the portion of the manifest which should not be highlighted and is |
| - // after the feature. |
| - std::string GetAfterFeature() const; |
| + virtual ~ManifestHighlighter(); |
| private: |
| // Called from the constructor; determine the start and end bounds of a |
| @@ -57,18 +94,24 @@ class ManifestHighlighter { |
| // Finds the end of the feature. |
| void FindBoundsEnd(const std::string& feature, size_t local_start); |
| - // The manifest we are parsing. |
| - std::string manifest_; |
| + DISALLOW_COPY_AND_ASSIGN(ManifestHighlighter); |
| +}; |
| - // The start of the feature. |
| - size_t start_; |
| +// Use the SourceHighlighter to highlight a particular line in a given source |
| +// file. |
| +class SourceHighlighter : public FileHighlighter { |
| + public: |
| + SourceHighlighter(const std::string& source, size_t line_number); |
| + virtual ~SourceHighlighter(); |
| - // The end of the feature. |
| - size_t end_; |
| + private: |
| + // Called from the constructor; determine the bounds of the line in the source |
| + // file. |
| + void Parse(size_t line_number); |
| - DISALLOW_COPY_AND_ASSIGN(ManifestHighlighter); |
| + DISALLOW_COPY_AND_ASSIGN(SourceHighlighter); |
| }; |
| } // namespace extensions |
| -#endif // EXTENSIONS_BROWSER_MANIFEST_HIGHLIGHTER_H_ |
| +#endif // EXTENSIONS_BROWSER_FILE_HIGHLIGHTER_H_ |