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

Side by Side Diff: chrome/browser/greasemonkey_master.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/browser/greasemonkey_master.h ('k') | chrome/browser/render_process_host.cc » ('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/browser/greasemonkey_master.h"
6
7 #include "base/file_util.h"
8 #include "base/logging.h"
9 #include "base/path_service.h"
10 #include "base/pickle.h"
11 #include "base/string_util.h"
12 #include "chrome/common/chrome_paths.h"
13
14 bool GreasemonkeyMaster::UpdateScripts() {
15 std::vector<std::string> scripts;
16 std::wstring path;
17
18 PathService::Get(chrome::DIR_USER_SCRIPTS, &path);
19 file_util::FileEnumerator enumerator(path, false,
20 file_util::FileEnumerator::FILES,
21 L"*.user.js");
22 for (std::wstring file = enumerator.Next(); !file.empty();
23 file = enumerator.Next()) {
24 // TODO(aa): Support unicode script files.
25 std::string contents;
26 file_util::ReadFileToString(file, &contents);
27 scripts.push_back(contents);
28 }
29
30 // Pickle scripts data.
31 Pickle pickle;
32 pickle.WriteSize(scripts.size());
33 for (std::vector<std::string>::iterator script = scripts.begin();
34 script != scripts.end(); ++script) {
35 // Write script body as 'data' so that we can read it out in the slave
36 // without allocating a new string.
37 pickle.WriteData(script->c_str(), script->size());
38 }
39
40 // Create the shared memory object.
41 scoped_ptr<SharedMemory> temp_shared_memory(new SharedMemory());
42 if (!temp_shared_memory.get()) {
43 return false;
44 }
45
46 shared_memory_serial_++;
47 if (!temp_shared_memory->Create(std::wstring(), // anonymous
48 false, // read-only
49 false, // open existing
50 pickle.size())) {
51 return false;
52 }
53
54 // Map into our process.
55 if (!temp_shared_memory->Map(pickle.size())) {
56 return false;
57 }
58
59 // Copy the pickle to shared memory.
60 memcpy(temp_shared_memory->memory(), pickle.data(), pickle.size());
61
62 shared_memory_.reset(temp_shared_memory.release());
63 return true;
64 }
65
66 bool GreasemonkeyMaster::ShareToProcess(ProcessHandle process,
67 SharedMemoryHandle* new_handle) {
68 if (shared_memory_.get())
69 return shared_memory_->ShareToProcess(process, new_handle);
70
71 NOTREACHED();
72 return false;
73 }
OLDNEW
« no previous file with comments | « chrome/browser/greasemonkey_master.h ('k') | chrome/browser/render_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698