summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/greasemonkey_slave.cc17
-rw-r--r--chrome/renderer/greasemonkey_slave.h20
2 files changed, 23 insertions, 14 deletions
diff --git a/chrome/renderer/greasemonkey_slave.cc b/chrome/renderer/greasemonkey_slave.cc
index 7a23017..cba48d1 100644
--- a/chrome/renderer/greasemonkey_slave.cc
+++ b/chrome/renderer/greasemonkey_slave.cc
@@ -39,12 +39,16 @@ bool GreasemonkeySlave::UpdateScripts(SharedMemoryHandle shared_memory) {
pickle.ReadInt(&iter, &num_scripts);
for (int i = 0; i < num_scripts; ++i) {
- const char* data = NULL;
- int data_length = 0;
- pickle.ReadData(&iter, &data, &data_length);
+ const char* url = NULL;
+ int url_length = 0;
+ const char* body = NULL;
+ int body_length = 0;
- GreasemonkeyScript script;
- if (script.Parse(StringPiece(data, data_length))) {
+ pickle.ReadData(&iter, &url, &url_length);
+ pickle.ReadData(&iter, &body, &body_length);
+
+ GreasemonkeyScript script(StringPiece(url, url_length));
+ if (script.Parse(StringPiece(body, body_length))) {
scripts_.push_back(script);
}
}
@@ -57,9 +61,8 @@ bool GreasemonkeySlave::InjectScripts(WebFrame* frame) {
for (std::vector<GreasemonkeyScript>::iterator script = scripts_.begin();
script != scripts_.end(); ++script) {
- // TODO(aa): Pass in URL to script when we have it.
frame->ExecuteJavaScript(script->GetBody().as_string(),
- "Greasemonkey Script");
+ script->GetURL().as_string());
}
return true;
diff --git a/chrome/renderer/greasemonkey_slave.h b/chrome/renderer/greasemonkey_slave.h
index 7f35cec..a6bec2f2 100644
--- a/chrome/renderer/greasemonkey_slave.h
+++ b/chrome/renderer/greasemonkey_slave.h
@@ -5,8 +5,6 @@
#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"
@@ -15,14 +13,17 @@
// 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() {}
+ GreasemonkeyScript(const StringPiece& script_url)
+ : url_(script_url) {}
const StringPiece& GetBody() const {
return body_;
}
+ const StringPiece& GetURL() const {
+ return url_;
+ }
+
bool Parse(const StringPiece& script_text) {
// TODO(aa): Parse out includes, convert to regexes.
body_ = script_text;
@@ -30,9 +31,14 @@ class GreasemonkeyScript {
}
private:
- // References the body of the script in shared memory. The underlying memory
- // is valid until shared_memory_ is either deleted or Unmap()'d.
+ // 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.
StringPiece body_;
+
+ // 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_;
};