| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "webkit/extensions/v8/gears_extension.h" |
| 6 #include "Gears.h" | |
| 7 | 6 |
| 8 namespace WebCore { | 7 namespace extensions_v8 { |
| 9 | 8 |
| 10 const char* kGearsExtensionName = "v8/Gears"; | 9 const char* kGearsExtensionName = "v8/Gears"; |
| 11 | 10 |
| 12 // Note: when a page touches the "google.gears.factory" object, this script | 11 // Note: when a page touches the "google.gears.factory" object, this script |
| 13 // touches the DOM. We expect the DOM to be available at that time. | 12 // touches the DOM. We expect the DOM to be available at that time. |
| 14 const char* kGearsExtensionScript = | 13 const char* kGearsExtensionScript = |
| 15 "var google;" | 14 "var google;" |
| 16 "if (!google)" | 15 "if (!google)" |
| 17 " google = {};" | 16 " google = {};" |
| 18 "if (!google.gears)" | 17 "if (!google.gears)" |
| 19 " google.gears = {};" | 18 " google.gears = {};" |
| 20 "(function() {" | 19 "(function() {" |
| 21 " var factory = null;" | 20 " var factory = null;" |
| 22 " google.gears.__defineGetter__('factory', function() {" | 21 " google.gears.__defineGetter__('factory', function() {" |
| 23 " if (!factory) {" | 22 " if (!factory) {" |
| 24 " factory = document.createElement('object');" | 23 " factory = document.createElement('object');" |
| 25 " factory.width = 0;" | 24 " factory.width = 0;" |
| 26 " factory.height = 0;" | 25 " factory.height = 0;" |
| 27 " factory.style.visibility = 'hidden';" | 26 " factory.style.visibility = 'hidden';" |
| 28 " factory.type = 'application/x-googlegears';" | 27 " factory.type = 'application/x-googlegears';" |
| 29 " document.documentElement.appendChild(factory);" | 28 " document.documentElement.appendChild(factory);" |
| 30 " }" | 29 " }" |
| 31 " return factory;" | 30 " return factory;" |
| 32 " });" | 31 " });" |
| 33 "})();"; | 32 "})();"; |
| 34 | 33 |
| 35 class GearsExtensionWrapper : public v8::Extension { | 34 class GearsExtensionWrapper : public v8::Extension { |
| 36 public: | 35 public: |
| 37 GearsExtensionWrapper() : | 36 GearsExtensionWrapper() |
| 38 v8::Extension(kGearsExtensionName, kGearsExtensionScript) {} | 37 : v8::Extension(kGearsExtensionName, kGearsExtensionScript) {} |
| 39 }; | 38 }; |
| 40 | 39 |
| 41 v8::Extension* GearsExtension::Get() { | 40 v8::Extension* GearsExtension::Get() { |
| 42 return new GearsExtensionWrapper(); | 41 return new GearsExtensionWrapper(); |
| 43 } | 42 } |
| 44 | 43 |
| 45 } | 44 } // namespace extensions_v8 |
| OLD | NEW |