Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Unified Diff: chrome/renderer/greasemonkey_slave.cc

Issue 7254: Initial Greasemonkey support (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/greasemonkey_slave.h ('k') | chrome/renderer/render_thread.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/greasemonkey_slave.cc
===================================================================
--- chrome/renderer/greasemonkey_slave.cc (revision 0)
+++ chrome/renderer/greasemonkey_slave.cc (revision 0)
@@ -0,0 +1,66 @@
+// 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.
+
+#include "chrome/renderer/greasemonkey_slave.h"
+
+#include "base/logging.h"
+#include "base/pickle.h"
+#include "base/shared_memory.h"
+
+GreasemonkeySlave::GreasemonkeySlave() : shared_memory_(NULL) {
+}
+
+bool GreasemonkeySlave::UpdateScripts(SharedMemoryHandle shared_memory) {
+ scripts_.clear();
+
+ // Create the shared memory object.
+ shared_memory_.reset(new SharedMemory(shared_memory, true)); // read-only
+ if (!shared_memory_.get())
+ return false;
+
+ // First get the size of the memory block.
+ if (!shared_memory_->Map(sizeof(Pickle::Header)))
+ return false;
+ Pickle::Header* pickle_header =
+ reinterpret_cast<Pickle::Header*>(shared_memory_->memory());
+
+ // Now map in the rest of the block.
+ int pickle_size = sizeof(Pickle::Header) + pickle_header->payload_size;
+ shared_memory_->Unmap();
+ if (!shared_memory_->Map(pickle_size))
+ return false;
+
+ // Unpickle scripts.
+ void* iter = NULL;
+ int num_scripts = 0;
+ Pickle pickle(reinterpret_cast<char*>(shared_memory_->memory()),
+ pickle_size);
+ 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);
+
+ GreasemonkeyScript script;
+ if (script.Parse(StringPiece(data, data_length))) {
+ scripts_.push_back(script);
+ }
+ }
+
+ return true;
+}
+
+bool GreasemonkeySlave::InjectScripts(WebFrame* frame) {
+ // TODO(aa): Check script patterns here
+
+ 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");
+ }
+
+ return true;
+}
« no previous file with comments | « chrome/renderer/greasemonkey_slave.h ('k') | chrome/renderer/render_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698