summaryrefslogtreecommitdiffstats
path: root/webkit/extensions
diff options
context:
space:
mode:
authorasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-05 21:39:11 +0000
committerasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-05 21:39:11 +0000
commit06533c0b11ce14b45eb0205fdc28a217eeba763c (patch)
treec2209aab205a7b2216c61be7e1ae6b231b7cb148 /webkit/extensions
parent68acddb6ced1c8d29e84fb1465f331515217e50a (diff)
downloadchromium_src-06533c0b11ce14b45eb0205fdc28a217eeba763c.zip
chromium_src-06533c0b11ce14b45eb0205fdc28a217eeba763c.tar.gz
chromium_src-06533c0b11ce14b45eb0205fdc28a217eeba763c.tar.bz2
Refactor v8 extensions so that they aren't in the WebCore namespace, and can call functions in the rest of Chromium code without having to go through ChromiumBridge (which now lives upstream in the WebKit repository).
R=darin,mbelshe Review URL: http://codereview.chromium.org/40132 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11040 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/extensions')
-rw-r--r--webkit/extensions/v8/gc_extension.cc25
-rw-r--r--webkit/extensions/v8/gc_extension.h23
-rw-r--r--webkit/extensions/v8/gears_extension.cc44
-rw-r--r--webkit/extensions/v8/gears_extension.h24
-rw-r--r--webkit/extensions/v8/interval_extension.cc59
-rw-r--r--webkit/extensions/v8/interval_extension.h23
-rw-r--r--webkit/extensions/v8/playback_extension.cc30
-rw-r--r--webkit/extensions/v8/playback_extension.h31
8 files changed, 259 insertions, 0 deletions
diff --git a/webkit/extensions/v8/gc_extension.cc b/webkit/extensions/v8/gc_extension.cc
new file mode 100644
index 0000000..fb3e978
--- /dev/null
+++ b/webkit/extensions/v8/gc_extension.cc
@@ -0,0 +1,25 @@
+// Copyright (c) 2006-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 "webkit/extensions/v8/gc_extension.h"
+
+namespace extensions_v8 {
+
+const char* kGCExtensionName = "v8/GCController";
+
+v8::Extension* GCExtension::Get() {
+ v8::Extension* extension = new v8::Extension(
+ kGCExtensionName,
+ "(function () {"
+ " var v8_gc;"
+ " if (gc) v8_gc = gc;"
+ " GCController = new Object();"
+ " GCController.collect ="
+ " function() {if (v8_gc) v8_gc(); };"
+ " })();");
+ return extension;
+}
+
+} // namespace extensions_v8
+
diff --git a/webkit/extensions/v8/gc_extension.h b/webkit/extensions/v8/gc_extension.h
new file mode 100644
index 0000000..42dd684
--- /dev/null
+++ b/webkit/extensions/v8/gc_extension.h
@@ -0,0 +1,23 @@
+// Copyright (c) 2006-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.
+
+// The GCExtension is a v8 extension to expose a method into JS for triggering
+// garbage collection. This should only be used for debugging.
+
+#ifndef WEBKIT_EXTENSIONS_V8_GC_EXTENSION_H_
+#define WEBKIT_EXTENSIONS_V8_GC_EXTENSION_H_
+
+#include "v8/include/v8.h"
+
+namespace extensions_v8 {
+
+class GCExtension {
+ public:
+ static v8::Extension* Get();
+};
+
+} // namespace extensions_v8
+
+#endif // WEBKIT_EXTENSIONS_V8_GC_EXTENSION_H_
+
diff --git a/webkit/extensions/v8/gears_extension.cc b/webkit/extensions/v8/gears_extension.cc
new file mode 100644
index 0000000..f36ac61
--- /dev/null
+++ b/webkit/extensions/v8/gears_extension.cc
@@ -0,0 +1,44 @@
+// Copyright (c) 2006-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 "webkit/extensions/v8/gears_extension.h"
+
+namespace extensions_v8 {
+
+const char* kGearsExtensionName = "v8/Gears";
+
+// Note: when a page touches the "google.gears.factory" object, this script
+// touches the DOM. We expect the DOM to be available at that time.
+const char* kGearsExtensionScript =
+ "var google;"
+ "if (!google)"
+ " google = {};"
+ "if (!google.gears)"
+ " google.gears = {};"
+ "(function() {"
+ " var factory = null;"
+ " google.gears.__defineGetter__('factory', function() {"
+ " if (!factory) {"
+ " factory = document.createElement('object');"
+ " factory.width = 0;"
+ " factory.height = 0;"
+ " factory.style.visibility = 'hidden';"
+ " factory.type = 'application/x-googlegears';"
+ " document.documentElement.appendChild(factory);"
+ " }"
+ " return factory;"
+ " });"
+ "})();";
+
+class GearsExtensionWrapper : public v8::Extension {
+ public:
+ GearsExtensionWrapper()
+ : v8::Extension(kGearsExtensionName, kGearsExtensionScript) {}
+};
+
+v8::Extension* GearsExtension::Get() {
+ return new GearsExtensionWrapper();
+}
+
+} // namespace extensions_v8
diff --git a/webkit/extensions/v8/gears_extension.h b/webkit/extensions/v8/gears_extension.h
new file mode 100644
index 0000000..6f62787
--- /dev/null
+++ b/webkit/extensions/v8/gears_extension.h
@@ -0,0 +1,24 @@
+// Copyright (c) 2006-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.
+
+// The GearsExtension is a v8 extension to add a "google.gears.factory" getter
+// on the page, which, when accessed, lazily inserts the gears plugin into
+// the page and attaches it to the factory variable.
+
+#ifndef WEBKIT_EXTENSIONS_V8_GEARS_EXTENSION_H_
+#define WEBKIT_EXTENSIONS_V8_GEARS_EXTENSION_H_
+
+#include "v8/include/v8.h"
+
+namespace extensions_v8 {
+
+class GearsExtension {
+ public:
+ static v8::Extension* Get();
+};
+
+} // namespace extensions_v8
+
+#endif // WEBKIT_EXTENSIONS_V8_GEARS_EXTENSION_H_
+
diff --git a/webkit/extensions/v8/interval_extension.cc b/webkit/extensions/v8/interval_extension.cc
new file mode 100644
index 0000000..4f6072a
--- /dev/null
+++ b/webkit/extensions/v8/interval_extension.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2006-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 "webkit/extensions/v8/interval_extension.h"
+#include "base/time.h"
+
+namespace extensions_v8 {
+
+const char* kIntervalExtensionName = "v8/Interval";
+
+class IntervalExtensionWrapper : public v8::Extension {
+ public:
+ IntervalExtensionWrapper()
+ : v8::Extension(
+ kIntervalExtensionName,
+ "var chromium;"
+ "if (!chromium)"
+ " chromium = {};"
+ "chromium.Interval = function() {"
+ " var start_ = 0;"
+ " var stop_ = 0;"
+ " native function HiResTime();"
+ " this.start = function() {"
+ " stop_ = 0;"
+ " start_ = HiResTime();"
+ " };"
+ " this.stop = function() {"
+ " stop_ = HiResTime();"
+ " if (start_ == 0)"
+ " stop_ = 0;"
+ " };"
+ " this.microseconds = function() {"
+ " var stop = stop_;"
+ " if (stop == 0 && start_ != 0)"
+ " stop = HiResTime();"
+ " return Math.ceil((stop - start_) * 1000000);"
+ " };"
+ "}") {}
+
+ virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
+ v8::Handle<v8::String> name) {
+ if (name->Equals(v8::String::New("HiResTime"))) {
+ return v8::FunctionTemplate::New(HiResTime);
+ }
+ return v8::Handle<v8::FunctionTemplate>();
+ }
+
+ static v8::Handle<v8::Value> HiResTime(const v8::Arguments& args) {
+ return v8::Number::New(base::Time::Now().ToDoubleT());
+ }
+};
+
+v8::Extension* IntervalExtension::Get() {
+ return new IntervalExtensionWrapper();
+}
+
+} // namespace extensions_v8
+
diff --git a/webkit/extensions/v8/interval_extension.h b/webkit/extensions/v8/interval_extension.h
new file mode 100644
index 0000000..36da067
--- /dev/null
+++ b/webkit/extensions/v8/interval_extension.h
@@ -0,0 +1,23 @@
+// Copyright (c) 2006-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.
+
+// The IntervalExtension is a v8 extension to implement a simple interval
+// class for measuring microsecond intervals.
+
+#ifndef WEBKIT_EXTENSIONS_V8_INTERVAL_EXTENSION_H_
+#define WEBKIT_EXTENSIONS_V8_INTERVAL_EXTENSION_H_
+
+#include "v8/include/v8.h"
+
+namespace extensions_v8 {
+
+class IntervalExtension {
+ public:
+ static v8::Extension* Get();
+};
+
+} // namespace extensions_v8
+
+#endif // WEBKIT_EXTENSIONS_V8_INTERVAL_EXTENSION_H_
+
diff --git a/webkit/extensions/v8/playback_extension.cc b/webkit/extensions/v8/playback_extension.cc
new file mode 100644
index 0000000..82d0b8a
--- /dev/null
+++ b/webkit/extensions/v8/playback_extension.cc
@@ -0,0 +1,30 @@
+// Copyright (c) 2006-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 "webkit/extensions/v8/playback_extension.h"
+
+namespace extensions_v8 {
+
+const char* kPlaybackExtensionName = "v8/PlaybackMode";
+
+v8::Extension* PlaybackExtension::Get() {
+ v8::Extension* extension = new v8::Extension(
+ kPlaybackExtensionName,
+ "(function () {"
+ " var orig_date = Date;"
+ " Math.random = function() {"
+ " return 0.5;"
+ " };"
+ " Date.__proto__.now = function() {"
+ " return new orig_date(1204251968254);"
+ " };"
+ " Date = function() {"
+ " return Date.now();"
+ " };"
+ "})()");
+ return extension;
+}
+
+} // namespace extensions_v8
+
diff --git a/webkit/extensions/v8/playback_extension.h b/webkit/extensions/v8/playback_extension.h
new file mode 100644
index 0000000..3e50976
--- /dev/null
+++ b/webkit/extensions/v8/playback_extension.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2006-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.
+
+#ifndef WEBKIT_EXTENSIONS_V8_PLAYBACK_EXTENSION_H_
+#define WEBKIT_EXTENSIONS_V8_PLAYBACK_EXTENSION_H_
+
+#include "v8/include/v8.h"
+
+namespace extensions_v8 {
+
+// Inject code which overrides a few common JS functions for implementing
+// randomness. In order to implement effective record & playback of
+// websites, it is important that the URLs not change. Many popular web
+// based apps use randomness in URLs to unique-ify urls for proxies.
+// Unfortunately, this breaks playback.
+// To work around this, we take the two most common client-side randomness
+// generators and make them constant. They really need to be constant
+// (rather than a constant seed followed by constant change)
+// because the playback mode wants flexibility in how it plays them back
+// and cannot always guarantee that requests for randomness are played back
+// in exactly the same order in which they were recorded.
+class PlaybackExtension {
+ public:
+ static v8::Extension* Get();
+};
+
+} // namespace extensions_v8
+
+#endif // WEBKIT_EXTENSIONS_V8_PLAYBACK_EXTENSION_H_
+