summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/greasemonkey_master.cc26
-rw-r--r--chrome/browser/greasemonkey_master.h2
-rw-r--r--chrome/renderer/greasemonkey_slave.cc17
-rw-r--r--chrome/renderer/greasemonkey_slave.h20
4 files changed, 39 insertions, 26 deletions
diff --git a/chrome/browser/greasemonkey_master.cc b/chrome/browser/greasemonkey_master.cc
index 829b47b..a69a2ce 100644
--- a/chrome/browser/greasemonkey_master.cc
+++ b/chrome/browser/greasemonkey_master.cc
@@ -4,15 +4,18 @@
#include "chrome/browser/greasemonkey_master.h"
+#include <vector>
+
#include "base/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/pickle.h"
#include "base/string_util.h"
#include "chrome/common/chrome_paths.h"
+#include "net/base/net_util.h"
bool GreasemonkeyMaster::UpdateScripts() {
- std::vector<std::string> scripts;
+ std::vector<std::wstring> scripts;
std::wstring path;
PathService::Get(chrome::DIR_USER_SCRIPTS, &path);
@@ -21,20 +24,23 @@ bool GreasemonkeyMaster::UpdateScripts() {
L"*.user.js");
for (std::wstring file = enumerator.Next(); !file.empty();
file = enumerator.Next()) {
- // TODO(aa): Support unicode script files.
- std::string contents;
- file_util::ReadFileToString(file, &contents);
- scripts.push_back(contents);
+ scripts.push_back(file);
}
// Pickle scripts data.
Pickle pickle;
pickle.WriteSize(scripts.size());
- for (std::vector<std::string>::iterator script = scripts.begin();
- script != scripts.end(); ++script) {
- // Write script body as 'data' so that we can read it out in the slave
- // without allocating a new string.
- pickle.WriteData(script->c_str(), script->size());
+ for (std::vector<std::wstring>::iterator path = scripts.begin();
+ path != scripts.end(); ++path) {
+ std::string file_url = net::FilePathToFileURL(*path).spec();
+ std::string contents;
+ // TODO(aa): Support unicode script files.
+ file_util::ReadFileToString(*path, &contents);
+
+ // Write scripts as 'data' so that we can read it out in the slave without
+ // allocating a new string.
+ pickle.WriteData(file_url.c_str(), file_url.length());
+ pickle.WriteData(contents.c_str(), contents.length());
}
// Create the shared memory object.
diff --git a/chrome/browser/greasemonkey_master.h b/chrome/browser/greasemonkey_master.h
index 6dcbc6e..9e3a789 100644
--- a/chrome/browser/greasemonkey_master.h
+++ b/chrome/browser/greasemonkey_master.h
@@ -5,8 +5,6 @@
#ifndef CHROME_BROWSER_GREASEMONKEY_MASTER_H__
#define CHROME_BROWSER_GREASEMONKEY_MASTER_H__
-#include <vector>
-
#include "base/process.h"
#include "base/scoped_ptr.h"
#include "base/shared_memory.h"
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_;
};