summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/user_script.h
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-05 22:51:54 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-05 22:51:54 +0000
commitd2a69e2fccc65e8c74b770343cecad7a1136f9fd (patch)
treeefc684e21d7ef65d72dcb31fba6a01184df8407b /chrome/common/extensions/user_script.h
parenta60551c712b36d6241c234cd81ae2a847f323ec5 (diff)
downloadchromium_src-d2a69e2fccc65e8c74b770343cecad7a1136f9fd.zip
chromium_src-d2a69e2fccc65e8c74b770343cecad7a1136f9fd.tar.gz
chromium_src-d2a69e2fccc65e8c74b770343cecad7a1136f9fd.tar.bz2
Integrate URLPattern with Extension user scripts.
Also refactored the UserScript class in UserScriptSlave and the UserScriptInfo structure in UserScriptMaster into a common location. Review URL: http://codereview.chromium.org/21070 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9270 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/user_script.h')
-rw-r--r--chrome/common/extensions/user_script.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/chrome/common/extensions/user_script.h b/chrome/common/extensions/user_script.h
new file mode 100644
index 0000000..6453c8e
--- /dev/null
+++ b/chrome/common/extensions/user_script.h
@@ -0,0 +1,74 @@
+// Copyright 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_
+#define CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_
+
+#include <vector>
+#include <string>
+
+#include "base/file_path.h"
+#include "base/pickle.h"
+#include "chrome/common/extensions/url_pattern.h"
+#include "googleurl/src/gurl.h"
+
+// Represents a user script, either a standalone one, or one that is part of an
+// extension.
+class UserScript {
+ public:
+ UserScript(){}
+
+ // The URL to retrieve the content of this script at.
+ const GURL& url() const { return url_; }
+ void set_url(const GURL& url) { url_ = url; }
+
+ // The path to find the script at.
+ const FilePath& path() const { return path_; }
+ void set_path(const FilePath& path) { path_ = path; }
+
+ // The globs, if any, that determine which pages this script runs against.
+ // These are only used with "standalone" Greasemonkey-like user scripts.
+ const std::vector<std::string>& globs() const { return globs_; }
+ void add_glob(const std::string& glob) { globs_.push_back(glob); }
+ void clear_globs() { globs_.clear(); }
+
+ // The URLPatterns, if any, that determine which pages this script runs
+ // against.
+ const std::vector<URLPattern>& url_patterns() const { return url_patterns_; }
+ void add_url_pattern(const URLPattern& pattern) {
+ url_patterns_.push_back(pattern);
+ }
+ void clear_url_patterns() { url_patterns_.clear(); }
+
+ // Returns true if the script should be applied to the specified URL, false
+ // otherwise.
+ bool MatchesUrl(const GURL& url);
+
+ // Serialize the script into a pickle.
+ void Pickle(::Pickle* pickle);
+
+ // Deserialize the script from a pickle. Note that this always succeeds
+ // because presumably we were the one that pickled it, and we did it
+ // correctly.
+ void Unpickle(const ::Pickle& pickle, void** iter);
+
+ private:
+ // The URL to the content of the script.
+ GURL url_;
+
+ // The path to the content of the script.
+ FilePath path_;
+
+ // Greasemonkey-style globs that determine pages to inject the script into.
+ // These are only used with standalone scripts.
+ std::vector<std::string> globs_;
+
+ // URLPatterns that determine pages to inject the script into. These are
+ // only used with scripts that are part of extensions.
+ std::vector<URLPattern> url_patterns_;
+};
+
+typedef std::vector<UserScript> UserScriptList;
+
+#endif // CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_