diff options
author | aa@google.com <aa@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-16 23:57:47 +0000 |
---|---|---|
committer | aa@google.com <aa@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-16 23:57:47 +0000 |
commit | 1e0f70402b410a9e274e8d23eeab236b43810a00 (patch) | |
tree | 43ebd89055f4666ab3104554551a2177413382db /chrome/browser/greasemonkey_master.cc | |
parent | c2dacc9ec41232903ba700c6aef5ef98bfcb8af8 (diff) | |
download | chromium_src-1e0f70402b410a9e274e8d23eeab236b43810a00.zip chromium_src-1e0f70402b410a9e274e8d23eeab236b43810a00.tar.gz chromium_src-1e0f70402b410a9e274e8d23eeab236b43810a00.tar.bz2 |
Adds a bit of Greasemonkey support hidden behind the --enable-greasemonkey flag. Implementation follows the pattern of the visited links system.
Things still to be done:
- stop using a hardcoded script directory
- watch script directory and update shared memory when necessary
- move file io to background thread
- support for @include patterns -- now, all scripts are applied to all pages
Review URL: http://codereview.chromium.org/7254
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3496 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/greasemonkey_master.cc')
-rw-r--r-- | chrome/browser/greasemonkey_master.cc | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/chrome/browser/greasemonkey_master.cc b/chrome/browser/greasemonkey_master.cc new file mode 100644 index 0000000..829b47b --- /dev/null +++ b/chrome/browser/greasemonkey_master.cc @@ -0,0 +1,73 @@ +// 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/browser/greasemonkey_master.h" + +#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" + +bool GreasemonkeyMaster::UpdateScripts() { + std::vector<std::string> scripts; + std::wstring path; + + PathService::Get(chrome::DIR_USER_SCRIPTS, &path); + file_util::FileEnumerator enumerator(path, false, + file_util::FileEnumerator::FILES, + 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); + } + + // 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()); + } + + // Create the shared memory object. + scoped_ptr<SharedMemory> temp_shared_memory(new SharedMemory()); + if (!temp_shared_memory.get()) { + return false; + } + + shared_memory_serial_++; + if (!temp_shared_memory->Create(std::wstring(), // anonymous + false, // read-only + false, // open existing + pickle.size())) { + return false; + } + + // Map into our process. + if (!temp_shared_memory->Map(pickle.size())) { + return false; + } + + // Copy the pickle to shared memory. + memcpy(temp_shared_memory->memory(), pickle.data(), pickle.size()); + + shared_memory_.reset(temp_shared_memory.release()); + return true; +} + +bool GreasemonkeyMaster::ShareToProcess(ProcessHandle process, + SharedMemoryHandle* new_handle) { + if (shared_memory_.get()) + return shared_memory_->ShareToProcess(process, new_handle); + + NOTREACHED(); + return false; +} |