summaryrefslogtreecommitdiffstats
path: root/webkit/extensions/v8/gears_extension.cc
blob: 92405ed9c5274a5423473b99b52e358678c2273e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// 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 "config.h"
#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