summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/greasemonkey_slave.h
diff options
context:
space:
mode:
authoraa@google.com <aa@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-16 23:57:47 +0000
committeraa@google.com <aa@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-16 23:57:47 +0000
commit1e0f70402b410a9e274e8d23eeab236b43810a00 (patch)
tree43ebd89055f4666ab3104554551a2177413382db /chrome/renderer/greasemonkey_slave.h
parentc2dacc9ec41232903ba700c6aef5ef98bfcb8af8 (diff)
downloadchromium_src-1e0f70402b410a9e274e8d23eeab236b43810a00.zip
chromium_src-1e0f70402b410a9e274e8d23eeab236b43810a00.tar.gz
chromium_src-1e0f70402b410a9e274e8d23eeab236b43810a00.tar.bz2
Adds a bit of Greasemonkey support hidden behind the --enable-greasemonkey flag. Implementation follows the pattern of the visited links system.
Things still to be done: - stop using a hardcoded script directory - watch script directory and update shared memory when necessary - move file io to background thread - support for @include patterns -- now, all scripts are applied to all pages Review URL: http://codereview.chromium.org/7254 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3496 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/greasemonkey_slave.h')
-rw-r--r--chrome/renderer/greasemonkey_slave.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/chrome/renderer/greasemonkey_slave.h b/chrome/renderer/greasemonkey_slave.h
new file mode 100644
index 0000000..7f35cec
--- /dev/null
+++ b/chrome/renderer/greasemonkey_slave.h
@@ -0,0 +1,62 @@
+// Copyright (c) 2008 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_RENDERER_GREASEMONKEY_SLAVE_H__
+#define CHROME_RENDERER_GREASEMONKEY_SLAVE_H__
+
+#include <vector>
+
+#include "base/scoped_ptr.h"
+#include "base/shared_memory.h"
+#include "base/string_piece.h"
+#include "webkit/glue/webframe.h"
+
+// Parsed representation of a Greasemonkey script.
+class GreasemonkeyScript {
+ public:
+ // TODO(aa): Pass in filename script came from, for errors. Needs to be in
+ // shared memory.
+ GreasemonkeyScript() {}
+
+ const StringPiece& GetBody() const {
+ return body_;
+ }
+
+ bool Parse(const StringPiece& script_text) {
+ // TODO(aa): Parse out includes, convert to regexes.
+ body_ = script_text;
+ return true;
+ }
+
+ private:
+ // References the body of the script in shared memory. The underlying memory
+ // is valid until shared_memory_ is either deleted or Unmap()'d.
+ StringPiece body_;
+};
+
+
+// Manages installed GreasemonkeyScripts for a render process.
+class GreasemonkeySlave {
+ public:
+ GreasemonkeySlave();
+
+ // Update the parsed scripts from shared memory.
+ bool UpdateScripts(SharedMemoryHandle shared_memory);
+
+ // Inject the appropriate scripts into a frame based on its URL.
+ // TODO(aa): Extract a GreasemonkeyFrame interface out of this to improve
+ // testability.
+ bool InjectScripts(WebFrame* frame);
+
+ private:
+ // Shared memory containing raw script data.
+ scoped_ptr<SharedMemory> shared_memory_;
+
+ // Parsed script data.
+ std::vector<GreasemonkeyScript> scripts_;
+
+ DISALLOW_COPY_AND_ASSIGN(GreasemonkeySlave);
+};
+
+#endif // CHROME_RENDERER_GREASEMONKEY_SLAVE_H__