diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-15 04:30:12 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-15 04:30:12 +0000 |
commit | 919ddc8c4928d69c3db02c68c0dbf573ebc54899 (patch) | |
tree | 74d8d509008427576fddfcf01282b897df23d261 /chrome/renderer | |
parent | 6f317586c5b00ab2196d9f3dbff571bad34b8352 (diff) | |
download | chromium_src-919ddc8c4928d69c3db02c68c0dbf573ebc54899.zip chromium_src-919ddc8c4928d69c3db02c68c0dbf573ebc54899.tar.gz chromium_src-919ddc8c4928d69c3db02c68c0dbf573ebc54899.tar.bz2 |
Various minor fixes:
* --load-extension no longer requires --enable-extensions
* No longer support chrome:// URLs for user scripts
* Remove old unused Greasemonkey test
* Enable Greasemonkey API emulation in linux/mac
BUG=16720,16007,4476
TEST=Added several unit tests
Original review:
http://codereview.chromium.org/149619
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20719 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/extensions/greasemonkey_api_unittest.cc | 86 | ||||
-rw-r--r-- | chrome/renderer/renderer_resources.grd | 2 | ||||
-rw-r--r-- | chrome/renderer/resources/greasemonkey_api.js | 68 | ||||
-rw-r--r-- | chrome/renderer/user_script_slave.cc | 9 |
4 files changed, 6 insertions, 159 deletions
diff --git a/chrome/renderer/extensions/greasemonkey_api_unittest.cc b/chrome/renderer/extensions/greasemonkey_api_unittest.cc deleted file mode 100644 index 2687953..0000000 --- a/chrome/renderer/extensions/greasemonkey_api_unittest.cc +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2009 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 "app/resource_bundle.h" -#include "base/file_util.h" -#include "base/path_service.h" -#include "base/string_util.h" -#include "chrome/common/chrome_paths.h" -#include "chrome/test/v8_unit_test.h" -#include "testing/gtest/include/gtest/gtest.h" - -#include "grit/renderer_resources.h" - -// TODO(port) -#if defined(OS_WIN) - -static const char kGreasemonkeyApi[] = "greasemonkey_api.js"; -static const char kGreasemonkeyApiTest[] = "greasemonkey_api_test.js"; - -class GreasemonkeyApiTest : public V8UnitTest { - public: - GreasemonkeyApiTest() {} - - virtual void SetUp() { - V8UnitTest::SetUp(); - - // Add the greasemonkey api to the context. - StringPiece api_js = - ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_GREASEMONKEY_API_JS); - ExecuteScriptInContext(api_js, kGreasemonkeyApi); - - // Add the test functions to the context. - std::wstring test_js_file_path; - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_js_file_path)); - file_util::AppendToPath(&test_js_file_path, L"extensions"); - file_util::AppendToPath(&test_js_file_path, - UTF8ToWide(kGreasemonkeyApiTest)); - std::string test_js; - ASSERT_TRUE(file_util::ReadFileToString(test_js_file_path, &test_js)); - ExecuteScriptInContext(test_js, kGreasemonkeyApiTest); - } -}; - -TEST_F(GreasemonkeyApiTest, GetSetValue) { - TestFunction("testGetSetValue"); -} - -TEST_F(GreasemonkeyApiTest, DeleteValue) { - TestFunction("testDeleteValue"); -} - -TEST_F(GreasemonkeyApiTest, ListValues) { - TestFunction("testListValues"); -} - -TEST_F(GreasemonkeyApiTest, GetResourceURL) { - TestFunction("testGetResourceURL"); -} - -TEST_F(GreasemonkeyApiTest, GetResourceText) { - TestFunction("testGetResourceText"); -} - -TEST_F(GreasemonkeyApiTest, AddStyle) { - TestFunction("testAddStyle"); -} - -TEST_F(GreasemonkeyApiTest, XmlhttpRequest) { - TestFunction("testXmlhttpRequest"); -} - -TEST_F(GreasemonkeyApiTest, RegisterMenuCommand) { - TestFunction("testRegisterMenuCommand"); -} - -TEST_F(GreasemonkeyApiTest, OpenInTab) { - TestFunction("testOpenInTab"); -} - -TEST_F(GreasemonkeyApiTest, Log) { - TestFunction("testLog"); -} - -#endif // #if defined(OSWIN) diff --git a/chrome/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd index bdba06d..eb128c7 100644 --- a/chrome/renderer/renderer_resources.grd +++ b/chrome/renderer/renderer_resources.grd @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- This comment is only here because changes to resources are not picked up -without changes to the corresponding grd file. mp1 --> +without changes to the corresponding grd file. aa1 --> <grit latest_public_release="0" current_release="1"> <outputs> <output filename="grit/renderer_resources.h" type="rc_header"> diff --git a/chrome/renderer/resources/greasemonkey_api.js b/chrome/renderer/resources/greasemonkey_api.js index 0ad24f0..7b829ad 100644 --- a/chrome/renderer/resources/greasemonkey_api.js +++ b/chrome/renderer/resources/greasemonkey_api.js @@ -7,70 +7,9 @@ // have your change take effect. // ----------------------------------------------------------------------------- -// Implementation of the Greasemonkey API, see: +// Partial implementation of the Greasemonkey API, see: // http://wiki.greasespot.net/Greasemonkey_Manual:APIs -const MIN_INT_32 = -0x80000000; -const MAX_INT_32 = 0x7FFFFFFF; - -// Prefix for user script values that are stored in localStorage. -const STORAGE_NS = "__userscript__."; - -function GM_getValue(name, defaultValue) { - var value = localStorage.getItem(STORAGE_NS + name); - return value ? value : defaultValue; -} - -function GM_setValue(name, value) { - // The values for GM_getValue() and GM_setValue() can only be boolean, - // strings, or 32 bit integers. See the setPrefs function in: - // http://greasemonkey.devjavu.com/browser/trunk/src/chrome/chromeFiles/content/prefmanager.js - var goodType = false; - switch (typeof(value)) { - case "string": - case "boolean": - goodType = true; - break; - case "number": - // Note that "value % 1 == 0" checks that the number is not a float. - if (value % 1 == 0 && value >= MIN_INT_32 && value <= MAX_INT_32) { - goodType = true; - } - break; - } - - if (!goodType) { - throw new Error("Unsupported type for GM_setValue. Supported types " + - "are: string, bool, and 32 bit integers."); - } - - localStorage.setItem(STORAGE_NS + name, value); -} - -function GM_deleteValue(name) { - localStorage.removeItem(STORAGE_NS + name); -} - -function GM_listValues() { - var values = []; - for (var i = 0; i < localStorage.length; i++) { - var key = localStorage.key(i); - if (key.indexOf(STORAGE_NS) == 0) { - key = key.substring(STORAGE_NS.length); - values.push(key); - } - } - return values; -} - -function GM_getResourceURL(resourceName) { - throw new Error("not implemented."); -} - -function GM_getResourceText(resourceName) { - throw new Error("not implemented."); -} - function GM_addStyle(css) { var parent = document.getElementsByTagName("head")[0]; if (!parent) { @@ -121,11 +60,6 @@ function GM_xmlhttpRequest(details) { xhr.send(details.data ? details.data : null); } -function GM_registerMenuCommand(commandName, commandFunc, accelKey, - accelModifiers, accessKey) { - throw new Error("not implemented."); -} - function GM_openInTab(url) { window.open(url, ""); } diff --git a/chrome/renderer/user_script_slave.cc b/chrome/renderer/user_script_slave.cc index afd065f..9692736 100644 --- a/chrome/renderer/user_script_slave.cc +++ b/chrome/renderer/user_script_slave.cc @@ -36,13 +36,8 @@ UserScriptSlave::UserScriptSlave() : shared_memory_(NULL), script_deleter_(&scripts_), user_script_start_line_(0) { - // TODO: Only windows supports resources and only windows supports user - // scrips, so only load the Greasemonkey API on windows. Fix this when - // better cross platofrm support is available. -#if defined(OS_WIN) api_js_ = ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_GREASEMONKEY_API_JS); -#endif // Count the number of lines that will be injected before the user script. StringPiece::size_type pos = 0; @@ -114,6 +109,10 @@ bool UserScriptSlave::UpdateScripts(base::SharedMemoryHandle shared_memory) { bool UserScriptSlave::InjectScripts(WebFrame* frame, UserScript::RunLocation location) { + // Don't bother if this is not a URL we inject script into. + if (!URLPattern::IsValidScheme(frame->GetURL().scheme())) + return true; + PerfTimer timer; int num_matched = 0; |