diff options
author | aa@google.com <aa@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-03 19:53:13 +0000 |
---|---|---|
committer | aa@google.com <aa@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-03 19:53:13 +0000 |
commit | e66546fb07e258ee2cce63978dccddca70e46aa1 (patch) | |
tree | 31e10e0c16e0825a37814f75cbb3ae69d461cd42 /chrome/renderer/greasemonkey_slave.h | |
parent | 592ea8ca5746b0f4630ea3313a8bc85dbeaba389 (diff) | |
download | chromium_src-e66546fb07e258ee2cce63978dccddca70e46aa1.zip chromium_src-e66546fb07e258ee2cce63978dccddca70e46aa1.tar.gz chromium_src-e66546fb07e258ee2cce63978dccddca70e46aa1.tar.bz2 |
Add support for @include in Greasemonkey scripts.
Review URL: http://codereview.chromium.org/8020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4478 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/greasemonkey_slave.h')
-rw-r--r-- | chrome/renderer/greasemonkey_slave.h | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/chrome/renderer/greasemonkey_slave.h b/chrome/renderer/greasemonkey_slave.h index a6bec2f2..5be3697 100644 --- a/chrome/renderer/greasemonkey_slave.h +++ b/chrome/renderer/greasemonkey_slave.h @@ -8,29 +8,51 @@ #include "base/scoped_ptr.h" #include "base/shared_memory.h" #include "base/string_piece.h" +#include "base/string_util.h" +#include "testing/gtest/include/gtest/gtest_prod.h" #include "webkit/glue/webframe.h" + // Parsed representation of a Greasemonkey script. class GreasemonkeyScript { public: GreasemonkeyScript(const StringPiece& script_url) : url_(script_url) {} + // Gets the script body that should be injected into matching content. const StringPiece& GetBody() const { return body_; } + // Gets a URL where this script can be found. const StringPiece& GetURL() const { return url_; } - bool Parse(const StringPiece& script_text) { - // TODO(aa): Parse out includes, convert to regexes. - body_ = script_text; - return true; - } + // Parses the text content of a user script file. + void Parse(const StringPiece& script_text); + + // Returns true if the script should be applied to the specified URL, false + // otherwise. + bool MatchesUrl(const GURL& url); private: + FRIEND_TEST(GreasemonkeySlaveTest, EscapeGlob); + FRIEND_TEST(GreasemonkeySlaveTest, Parse1); + FRIEND_TEST(GreasemonkeySlaveTest, Parse2); + FRIEND_TEST(GreasemonkeySlaveTest, Parse3); + + // Helper function to convert the Greasemonkey glob format to the patterns + // used internally to test URLs. + static std::string EscapeGlob(const std::string& glob); + + // Parses the metadata block from the script. + void ParseMetadata(const StringPiece& script_text); + + // Adds an include pattern that will be checked to determine whether to + // include a script on a given page. + void AddInclude(const std::string &glob_pattern); + // The body of the script, which will be injected into content pages. This // references shared_memory_, and is valid until that memory is either // deleted or Unmap()'d. @@ -39,6 +61,11 @@ class GreasemonkeyScript { // The url of the file the script came from. This references shared_memory_, // and is valid until that memory is either deleted or Unmap()'d. StringPiece url_; + + // List of patterns to test URLs against for this script. These patterns have + // been escaped for use with MatchPattern() in string_utils ('?' and '\' are + // escaped). + std::vector<std::string> include_patterns_; }; |