Index: components/plugins/renderer/mobile_youtube_plugin.cc |
diff --git a/components/plugins/renderer/mobile_youtube_plugin.cc b/components/plugins/renderer/mobile_youtube_plugin.cc |
index dd4688a92384122f5ff22182a619b4dcf1b4bf83..e8afbc61b18aafe23316be921fae68795174bda8 100644 |
--- a/components/plugins/renderer/mobile_youtube_plugin.cc |
+++ b/components/plugins/renderer/mobile_youtube_plugin.cc |
@@ -11,7 +11,10 @@ |
#include "base/values.h" |
#include "content/public/common/content_constants.h" |
#include "content/public/renderer/render_frame.h" |
+#include "gin/handle.h" |
+#include "gin/object_template_builder.h" |
#include "third_party/WebKit/public/web/WebFrame.h" |
+#include "third_party/WebKit/public/web/WebKit.h" |
#include "ui/base/webui/jstemplate_builder.h" |
using blink::WebFrame; |
@@ -70,6 +73,12 @@ bool IsValidYouTubeVideo(const std::string& path) { |
namespace plugins { |
+gin::ObjectTemplateBuilder MobileYouTubePlugin::GetObjectTemplateBuilder( |
+ v8::Isolate* isolate) { |
+ return PluginPlaceholder::GetObjectTemplateBuilder(isolate) |
+ .SetMethod("openYoutubeURL", &MobileYouTubePlugin::OpenYoutubeUrlCallback); |
+} |
+ |
MobileYouTubePlugin::MobileYouTubePlugin(content::RenderFrame* render_frame, |
blink::WebFrame* frame, |
const blink::WebPluginParams& params, |
@@ -81,6 +90,8 @@ MobileYouTubePlugin::MobileYouTubePlugin(content::RenderFrame* render_frame, |
HtmlData(params, template_html), |
placeholderDataUrl) {} |
+MobileYouTubePlugin::~MobileYouTubePlugin() {} |
+ |
// static |
bool MobileYouTubePlugin::IsYouTubeURL(const GURL& url, |
const std::string& mime_type) { |
@@ -92,9 +103,7 @@ bool MobileYouTubePlugin::IsYouTubeURL(const GURL& url, |
LowerCaseEqualsASCII(mime_type, content::kFlashPluginSwfMimeType); |
} |
-void MobileYouTubePlugin::OpenYoutubeUrlCallback( |
- const webkit_glue::CppArgumentList& args, |
- webkit_glue::CppVariant* result) { |
+void MobileYouTubePlugin::OpenYoutubeUrlCallback() { |
std::string youtube("vnd.youtube:"); |
GURL url(youtube.append(GetYoutubeVideoId(GetPluginParams()))); |
WebURLRequest request; |
@@ -103,11 +112,17 @@ void MobileYouTubePlugin::OpenYoutubeUrlCallback( |
render_frame()->LoadURLExternally( |
GetFrame(), request, blink::WebNavigationPolicyNewForegroundTab); |
} |
+ |
void MobileYouTubePlugin::BindWebFrame(WebFrame* frame) { |
- PluginPlaceholder::BindWebFrame(frame); |
- BindCallback("openYoutubeURL", |
- base::Bind(&MobileYouTubePlugin::OpenYoutubeUrlCallback, |
- base::Unretained(this))); |
+ v8::Isolate* isolate = blink::mainThreadIsolate(); |
+ v8::HandleScope handle_scope(isolate); |
+ v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); |
+ DCHECK(!context.IsEmpty()); |
+ |
+ v8::Context::Scope context_scope(context); |
+ v8::Handle<v8::Object> global = context->Global(); |
+ global->Set(gin::StringToV8(isolate, "plugin"), |
+ gin::CreateHandle(isolate, this).ToV8()); |
} |
} // namespace plugins |