Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Unified Diff: components/plugins/renderer/plugin_placeholder.cc

Issue 69953006: Bind plugin placeholder directly to v8 instead of over CppBoundClass (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/plugins/renderer/plugin_placeholder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/plugins/renderer/plugin_placeholder.cc
diff --git a/components/plugins/renderer/plugin_placeholder.cc b/components/plugins/renderer/plugin_placeholder.cc
index aa82135446bb68a8b2c8b0a2faf53188aa3249aa..5194b83c244cf33214e0cda38df7422d9bccf311 100644
--- a/components/plugins/renderer/plugin_placeholder.cc
+++ b/components/plugins/renderer/plugin_placeholder.cc
@@ -34,8 +34,6 @@ using blink::WebPluginContainer;
using blink::WebPluginParams;
using blink::WebScriptSource;
using blink::WebURLRequest;
-using webkit_glue::CppArgumentList;
-using webkit_glue::CppVariant;
namespace plugins {
@@ -58,17 +56,39 @@ PluginPlaceholder::PluginPlaceholder(content::RenderView* render_view,
PluginPlaceholder::~PluginPlaceholder() {}
+void PluginPlaceholder::InstallAdditionalCallbacks(
+ v8::Handle<v8::Template> prototype) {}
+
void PluginPlaceholder::BindWebFrame(WebFrame* frame) {
- BindToJavascript(frame, "plugin");
- BindCallback(
- "load",
- base::Bind(&PluginPlaceholder::LoadCallback, base::Unretained(this)));
- BindCallback(
- "hide",
- base::Bind(&PluginPlaceholder::HideCallback, base::Unretained(this)));
- BindCallback("didFinishLoading",
- base::Bind(&PluginPlaceholder::DidFinishLoadingCallback,
- base::Unretained(this)));
+ v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
+ v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
+
+ if (context.IsEmpty())
+ return;
+
+ v8::Context::Scope context_scope(context);
+
+ v8::Handle<v8::FunctionTemplate> plugin_template =
+ v8::FunctionTemplate::New();
+ v8::Handle<v8::Template> prototype = plugin_template->PrototypeTemplate();
+ prototype->Set(
+ v8::String::New("load"),
+ v8::FunctionTemplate::New(&PluginPlaceholder::LoadCallback,
+ v8::External::New(this))->GetFunction());
+ prototype->Set(
+ v8::String::New("hide"),
+ v8::FunctionTemplate::New(&PluginPlaceholder::HideCallback,
+ v8::External::New(this))->GetFunction());
+ prototype->Set(
+ v8::String::New("didFinishLoading"),
+ v8::FunctionTemplate::New(&PluginPlaceholder::DidFinishLoadingCallback,
+ v8::External::New(this))->GetFunction());
+
+ InstallAdditionalCallbacks(prototype);
+
+ v8::Handle<v8::Object> global = context->Global();
+ global->Set(v8::String::New("plugin"),
+ plugin_template->GetFunction()->NewInstance());
}
void PluginPlaceholder::ReplacePlugin(WebPlugin* new_plugin) {
@@ -206,23 +226,32 @@ void PluginPlaceholder::LoadPlugin() {
ReplacePlugin(plugin);
}
-void PluginPlaceholder::LoadCallback(const CppArgumentList& args,
- CppVariant* result) {
+// static
+void PluginPlaceholder::LoadCallback(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ PluginPlaceholder* plugin = reinterpret_cast<PluginPlaceholder*>(
Bernhard Bauer 2013/11/12 16:37:20 This reinterpret_cast business looks kinda messy.
+ v8::External::Cast(*args.Data())->Value());
RenderThread::Get()->RecordUserMetrics("Plugin_Load_Click");
- LoadPlugin();
+ plugin->LoadPlugin();
}
-void PluginPlaceholder::HideCallback(const CppArgumentList& args,
- CppVariant* result) {
+// static
+void PluginPlaceholder::HideCallback(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ PluginPlaceholder* plugin = reinterpret_cast<PluginPlaceholder*>(
+ v8::External::Cast(*args.Data())->Value());
RenderThread::Get()->RecordUserMetrics("Plugin_Hide_Click");
- HidePlugin();
+ plugin->HidePlugin();
}
-void PluginPlaceholder::DidFinishLoadingCallback(const CppArgumentList& args,
- CppVariant* result) {
- finished_loading_ = true;
- if (message_.length() > 0)
- UpdateMessage();
+// static
+void PluginPlaceholder::DidFinishLoadingCallback(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ PluginPlaceholder* plugin = reinterpret_cast<PluginPlaceholder*>(
+ v8::External::Cast(*args.Data())->Value());
+ plugin->finished_loading_ = true;
+ if (plugin->message_.length() > 0)
+ plugin->UpdateMessage();
}
void PluginPlaceholder::SetPluginInfo(
« no previous file with comments | « components/plugins/renderer/plugin_placeholder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698