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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/greasemonkey_slave.h ('k') | chrome/renderer/render_thread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/greasemonkey_slave.h"
6
7 #include "base/logging.h"
8 #include "base/pickle.h"
9 #include "base/shared_memory.h"
10
11 GreasemonkeySlave::GreasemonkeySlave() : shared_memory_(NULL) {
12 }
13
14 bool GreasemonkeySlave::UpdateScripts(SharedMemoryHandle shared_memory) {
15 scripts_.clear();
16
17 // Create the shared memory object.
18 shared_memory_.reset(new SharedMemory(shared_memory, true)); // read-only
19 if (!shared_memory_.get())
20 return false;
21
22 // First get the size of the memory block.
23 if (!shared_memory_->Map(sizeof(Pickle::Header)))
24 return false;
25 Pickle::Header* pickle_header =
26 reinterpret_cast<Pickle::Header*>(shared_memory_->memory());
27
28 // Now map in the rest of the block.
29 int pickle_size = sizeof(Pickle::Header) + pickle_header->payload_size;
30 shared_memory_->Unmap();
31 if (!shared_memory_->Map(pickle_size))
32 return false;
33
34 // Unpickle scripts.
35 void* iter = NULL;
36 int num_scripts = 0;
37 Pickle pickle(reinterpret_cast<char*>(shared_memory_->memory()),
38 pickle_size);
39 pickle.ReadInt(&iter, &num_scripts);
40
41 for (int i = 0; i < num_scripts; ++i) {
42 const char* data = NULL;
43 int data_length = 0;
44 pickle.ReadData(&iter, &data, &data_length);
45
46 GreasemonkeyScript script;
47 if (script.Parse(StringPiece(data, data_length))) {
48 scripts_.push_back(script);
49 }
50 }
51
52 return true;
53 }
54
55 bool GreasemonkeySlave::InjectScripts(WebFrame* frame) {
56 // TODO(aa): Check script patterns here
57
58 for (std::vector<GreasemonkeyScript>::iterator script = scripts_.begin();
59 script != scripts_.end(); ++script) {
60 // TODO(aa): Pass in URL to script when we have it.
61 frame->ExecuteJavaScript(script->GetBody().as_string(),
62 "Greasemonkey Script");
63 }
64
65 return true;
66 }
OLDNEW
« 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