summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authormbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-01 16:27:42 +0000
committermbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-01 16:27:42 +0000
commit3c8e3706b7f42bc0fc380ece4a7965539e8e0d65 (patch)
treea5a4ca442cac0e9f6e97313e3663700a89b9a988 /chrome
parent54c89ef568ae71304e7804c75a44fe2f16f859f2 (diff)
downloadchromium_src-3c8e3706b7f42bc0fc380ece4a7965539e8e0d65.zip
chromium_src-3c8e3706b7f42bc0fc380ece4a7965539e8e0d65.tar.gz
chromium_src-3c8e3706b7f42bc0fc380ece4a7965539e8e0d65.tar.bz2
Replace window.external with a v8::extension.
BUG=http://crbug.com/10957 TEST=Verify that the AddSearchProvider logic still works. This dates back to an old bug http://b/1069781 Review URL: http://codereview.chromium.org/99168 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15056 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/chrome.gyp4
-rw-r--r--chrome/renderer/external_extension.cc61
-rw-r--r--chrome/renderer/external_extension.h21
-rw-r--r--chrome/renderer/external_js_object.cc23
-rw-r--r--chrome/renderer/external_js_object.h41
-rw-r--r--chrome/renderer/render_thread.cc2
-rw-r--r--chrome/renderer/render_view.cc2
-rw-r--r--chrome/renderer/render_view.h4
-rw-r--r--chrome/renderer/renderer.vcproj10
9 files changed, 89 insertions, 79 deletions
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 598b577..9fa9f8c 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -1590,8 +1590,8 @@
'renderer/dom_ui_bindings.h',
'renderer/external_host_bindings.cc',
'renderer/external_host_bindings.h',
- 'renderer/external_js_object.cc',
- 'renderer/external_js_object.h',
+ 'renderer/external_extension.cc',
+ 'renderer/external_extension.h',
'renderer/js_only_v8_extensions.cc',
'renderer/js_only_v8_extensions.h',
'renderer/localized_error.cc',
diff --git a/chrome/renderer/external_extension.cc b/chrome/renderer/external_extension.cc
new file mode 100644
index 0000000..378e78e
--- /dev/null
+++ b/chrome/renderer/external_extension.cc
@@ -0,0 +1,61 @@
+// 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 "chrome/renderer/external_extension.h"
+#include "chrome/renderer/render_view.h"
+#include "webkit/glue/webframe.h"
+
+namespace extensions_v8 {
+
+const char* kExternalExtensionName = "v8/External";
+
+class ExternalExtensionWrapper : public v8::Extension {
+ public:
+ ExternalExtensionWrapper()
+ : v8::Extension(
+ kExternalExtensionName,
+ "var external;"
+ "if (!external)"
+ " external = {};"
+ "external.AddSearchProvider = function(name) {"
+ " native function NativeAddSearchProvider();"
+ " NativeAddSearchProvider(name);"
+ "}") {}
+
+ virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
+ v8::Handle<v8::String> name) {
+ if (name->Equals(v8::String::New("NativeAddSearchProvider"))) {
+ return v8::FunctionTemplate::New(AddSearchProvider);
+ }
+ return v8::Handle<v8::FunctionTemplate>();
+ }
+
+ static v8::Handle<v8::Value> AddSearchProvider(const v8::Arguments& args) {
+ if (!args.Length())
+ return v8::Undefined();
+
+ WebFrame* webframe = WebFrame::RetrieveActiveFrame();
+ DCHECK(webframe) << "There should be an active frame since we just got "
+ "a native function called.";
+ if (!webframe) return v8::Undefined();
+
+ WebView* webview = webframe->GetView();
+ if (!webview) return v8::Undefined(); // can happen during closing
+
+ RenderView* renderview = static_cast<RenderView*>(webview->GetDelegate());
+ if (!renderview) return v8::Undefined();
+
+ std::string name = std::string(*v8::String::Utf8Value(args[0]));
+ if (!name.length()) return v8::Undefined();;
+
+ renderview->AddSearchProvider(name);
+ return v8::Undefined();
+ }
+};
+
+v8::Extension* ExternalExtension::Get() {
+ return new ExternalExtensionWrapper();
+}
+
+} // namespace extensions_v8
diff --git a/chrome/renderer/external_extension.h b/chrome/renderer/external_extension.h
new file mode 100644
index 0000000..839aff3
--- /dev/null
+++ b/chrome/renderer/external_extension.h
@@ -0,0 +1,21 @@
+// 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.
+
+// Implements the window.external object.
+
+#ifndef CHROME_RENDERER_EXTENSIONS_V8_EXTERNAL_EXTENSION_H_
+#define CHROME_RENDERER_EXTENSIONS_V8_EXTERNAL_EXTENSION_H_
+
+#include "v8/include/v8.h"
+
+namespace extensions_v8 {
+
+class ExternalExtension {
+ public:
+ static v8::Extension* Get();
+};
+
+} // namespace extensions_v8
+
+#endif // CHROME_RENDERER_EXTENSIONS_V8_EXTERNAL_EXTENSION_H_
diff --git a/chrome/renderer/external_js_object.cc b/chrome/renderer/external_js_object.cc
deleted file mode 100644
index a397b91..0000000
--- a/chrome/renderer/external_js_object.cc
+++ /dev/null
@@ -1,23 +0,0 @@
-// 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 "chrome/renderer/external_js_object.h"
-
-#include "chrome/renderer/render_view.h"
-
-ExternalJSObject::ExternalJSObject() : render_view_(NULL) {
- BindMethod("AddSearchProvider", &ExternalJSObject::AddSearchProvider);
-}
-
-void ExternalJSObject::AddSearchProvider(const CppArgumentList& args,
- CppVariant* result) {
- DCHECK(render_view_);
- result->SetNull();
-
- if (render_view_) {
- if (args.size() < 1 || !args[0].isString())
- return;
- render_view_->AddSearchProvider(args[0].ToString());
- }
-}
diff --git a/chrome/renderer/external_js_object.h b/chrome/renderer/external_js_object.h
deleted file mode 100644
index 738aa7c..0000000
--- a/chrome/renderer/external_js_object.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// 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.
-
-/*
- ExternalJSObject class:
- Bound to a JavaScript window.external object using
- CppBoundClass::BindToJavascript(), this adds methods accessible from JS for
- compatibility with other browsers.
-*/
-
-#ifndef CHROME_RENDERER_EXTERNAL_JS_OBJECT_H__
-#define CHROME_RENDERER_EXTERNAL_JS_OBJECT_H__
-
-#include "base/basictypes.h"
-#include "webkit/glue/cpp_bound_class.h"
-
-class RenderView;
-
-class ExternalJSObject : public CppBoundClass {
- public:
- // Builds the property and method lists needed to bind this class to a JS
- // object.
- ExternalJSObject();
-
- // A RenderView must be set before AddSearchProvider is called, or the call
- // will do nothing.
- void set_render_view(RenderView* rv) { render_view_ = rv; }
-
- // Given a URL to an OpenSearch document in the first argument, adds the
- // corresponding search provider as a keyword search. The nonstandard
- // capitalization is for compatibility with Firefox and IE.
- void AddSearchProvider(const CppArgumentList& args, CppVariant* result);
-
- private:
- RenderView* render_view_;
-
- DISALLOW_EVIL_CONSTRUCTORS(ExternalJSObject);
-};
-
-#endif // CHROME_RENDERER_EXTERNAL_JS_OBJECT_H__
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index da8cc11..5b4dac1 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -29,6 +29,7 @@
#include "chrome/renderer/extensions/event_bindings.h"
#include "chrome/renderer/extensions/extension_process_bindings.h"
#include "chrome/renderer/extensions/renderer_extension_bindings.h"
+#include "chrome/renderer/external_extension.h"
#include "chrome/renderer/js_only_v8_extensions.h"
#include "chrome/renderer/loadtimes_extension_bindings.h"
#include "chrome/renderer/net/render_dns_master.h"
@@ -326,6 +327,7 @@ void RenderThread::EnsureWebKitInitialized() {
WebKit::registerExtension(extensions_v8::GearsExtension::Get());
WebKit::registerExtension(extensions_v8::IntervalExtension::Get());
WebKit::registerExtension(extensions_v8::LoadTimesExtension::Get());
+ WebKit::registerExtension(extensions_v8::ExternalExtension::Get());
WebKit::registerExtension(ExtensionProcessBindings::Get(),
WebKit::WebString::fromUTF8(chrome::kExtensionScheme));
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 174408e..4cf4fde 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -1499,8 +1499,6 @@ void RenderView::BindDOMAutomationController(WebFrame* webframe) {
}
void RenderView::WindowObjectCleared(WebFrame* webframe) {
- external_js_object_.set_render_view(this);
- external_js_object_.BindToJavascript(webframe, L"external");
if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
BindDOMAutomationController(webframe);
if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 6db3a077..b3d0f10 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -21,7 +21,6 @@
#include "chrome/renderer/automation/dom_automation_controller.h"
#include "chrome/renderer/dom_ui_bindings.h"
#include "chrome/renderer/external_host_bindings.h"
-#include "chrome/renderer/external_js_object.h"
#include "chrome/renderer/render_widget.h"
#include "skia/include/SkBitmap.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
@@ -631,9 +630,6 @@ class RenderView : public RenderWidget,
// Chrome page<->browser messaging CppBoundClass.
DOMUIBindings dom_ui_bindings_;
- // window.external object for "built-in" JS extensions
- ExternalJSObject external_js_object_;
-
// External host exposed through automation controller.
ExternalHostBindings external_host_bindings_;
diff --git a/chrome/renderer/renderer.vcproj b/chrome/renderer/renderer.vcproj
index da81a40..d0c9de4 100644
--- a/chrome/renderer/renderer.vcproj
+++ b/chrome/renderer/renderer.vcproj
@@ -278,19 +278,15 @@
>
</File>
<File
- RelativePath=".\external_host_bindings.cc"
+ RelativePath=".\external_extension.cc"
>
</File>
<File
- RelativePath=".\external_host_bindings.h"
+ RelativePath=".\external_extension.h"
>
</File>
<File
- RelativePath=".\external_js_object.cc"
- >
- </File>
- <File
- RelativePath=".\external_js_object.h"
+ RelativePath=".\external_host_bindings.cc"
>
</File>
<File