summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-21 00:49:49 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-21 00:49:49 +0000
commit497321cc99a20038cf0251be7e12a9e5f4206e82 (patch)
treedb428779acdf7388fe428b32aec0c3d765175785
parent6be86ad0a99fcc0a717368b320103e6c1d4eab5a (diff)
downloadchromium_src-497321cc99a20038cf0251be7e12a9e5f4206e82.zip
chromium_src-497321cc99a20038cf0251be7e12a9e5f4206e82.tar.gz
chromium_src-497321cc99a20038cf0251be7e12a9e5f4206e82.tar.bz2
Show the path to the Greasemonkey script that caused an error
in the console. Review URL: http://codereview.chromium.org/7533 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3643 0039d316-1c4b-4281-b951-d872f2087c98
-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_;
};