diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-08 22:55:22 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-08 22:55:22 +0000 |
commit | a0820d24d4f20fbc5f1c4fbe51c29b096cce6403 (patch) | |
tree | b1184f774de27154e7be6e2911fe35908a413306 /components/plugins | |
parent | 9dcbadfa6c23e301a8c21da4cc98b990847ed34f (diff) | |
download | chromium_src-a0820d24d4f20fbc5f1c4fbe51c29b096cce6403.zip chromium_src-a0820d24d4f20fbc5f1c4fbe51c29b096cce6403.tar.gz chromium_src-a0820d24d4f20fbc5f1c4fbe51c29b096cce6403.tar.bz2 |
Move the plugin placeholder from CppBoundClass to gin::Wrappable
BUG=297480
R=aa@chromium.org,bauerb@chromium.org
Review URL: https://codereview.chromium.org/116163008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243682 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/plugins')
-rw-r--r-- | components/plugins/renderer/DEPS | 2 | ||||
-rw-r--r-- | components/plugins/renderer/mobile_youtube_plugin.cc | 29 | ||||
-rw-r--r-- | components/plugins/renderer/mobile_youtube_plugin.h | 9 | ||||
-rw-r--r-- | components/plugins/renderer/plugin_placeholder.cc | 44 | ||||
-rw-r--r-- | components/plugins/renderer/plugin_placeholder.h | 27 | ||||
-rw-r--r-- | components/plugins/renderer/webview_plugin.cc | 4 | ||||
-rw-r--r-- | components/plugins/renderer/webview_plugin.h | 10 |
7 files changed, 70 insertions, 55 deletions
diff --git a/components/plugins/renderer/DEPS b/components/plugins/renderer/DEPS index 088d9e6..e86eecb 100644 --- a/components/plugins/renderer/DEPS +++ b/components/plugins/renderer/DEPS @@ -1,4 +1,5 @@ include_rules = [ + "+gin", "+net", "+content/public/renderer", @@ -8,6 +9,5 @@ include_rules = [ "+third_party/re2", "+skia", "+webkit/common", - "+webkit/renderer", "+ui/base/webui", ] diff --git a/components/plugins/renderer/mobile_youtube_plugin.cc b/components/plugins/renderer/mobile_youtube_plugin.cc index dd4688a..0fc3d4a7 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; @@ -81,6 +84,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 +97,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 +106,23 @@ 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()); +} + +gin::ObjectTemplateBuilder MobileYouTubePlugin::GetObjectTemplateBuilder( + v8::Isolate* isolate) { + return PluginPlaceholder::GetObjectTemplateBuilder(isolate) + .SetMethod("openYoutubeURL", &MobileYouTubePlugin::OpenYoutubeUrlCallback); } } // namespace plugins diff --git a/components/plugins/renderer/mobile_youtube_plugin.h b/components/plugins/renderer/mobile_youtube_plugin.h index 2fad63a..a7654da 100644 --- a/components/plugins/renderer/mobile_youtube_plugin.h +++ b/components/plugins/renderer/mobile_youtube_plugin.h @@ -26,13 +26,18 @@ class MobileYouTubePlugin : public PluginPlaceholder { static bool IsYouTubeURL(const GURL& url, const std::string& mime_type); private: + virtual ~MobileYouTubePlugin(); + // Opens a youtube app in the current tab. - void OpenYoutubeUrlCallback(const webkit_glue::CppArgumentList& args, - webkit_glue::CppVariant* result); + void OpenYoutubeUrlCallback(); // WebViewPlugin::Delegate (via PluginPlaceholder) method virtual void BindWebFrame(blink::WebFrame* frame) OVERRIDE; + // gin::Wrappable (via PluginPlaceholder) method + virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder( + v8::Isolate* isolate) OVERRIDE; + DISALLOW_COPY_AND_ASSIGN(MobileYouTubePlugin); }; diff --git a/components/plugins/renderer/plugin_placeholder.cc b/components/plugins/renderer/plugin_placeholder.cc index 405ac86..343c7ad 100644 --- a/components/plugins/renderer/plugin_placeholder.cc +++ b/components/plugins/renderer/plugin_placeholder.cc @@ -15,6 +15,7 @@ #include "content/public/common/context_menu_params.h" #include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_thread.h" +#include "gin/object_template_builder.h" #include "third_party/WebKit/public/web/WebDocument.h" #include "third_party/WebKit/public/web/WebElement.h" #include "third_party/WebKit/public/web/WebFrame.h" @@ -35,11 +36,11 @@ using blink::WebPluginContainer; using blink::WebPluginParams; using blink::WebScriptSource; using blink::WebURLRequest; -using webkit_glue::CppArgumentList; -using webkit_glue::CppVariant; namespace plugins { +gin::WrapperInfo PluginPlaceholder::kWrapperInfo = {gin::kEmbedderNativeGin}; + PluginPlaceholder::PluginPlaceholder(content::RenderFrame* render_frame, WebFrame* frame, const WebPluginParams& params, @@ -59,17 +60,13 @@ PluginPlaceholder::PluginPlaceholder(content::RenderFrame* render_frame, PluginPlaceholder::~PluginPlaceholder() {} -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))); +gin::ObjectTemplateBuilder PluginPlaceholder::GetObjectTemplateBuilder( + v8::Isolate* isolate) { + return gin::Wrappable<PluginPlaceholder>::GetObjectTemplateBuilder(isolate) + .SetMethod("load", &PluginPlaceholder::LoadCallback) + .SetMethod("hide", &PluginPlaceholder::HideCallback) + .SetMethod("didFinishLoading", + &PluginPlaceholder::DidFinishLoadingCallback); } void PluginPlaceholder::ReplacePlugin(WebPlugin* new_plugin) { @@ -87,10 +84,11 @@ void PluginPlaceholder::ReplacePlugin(WebPlugin* new_plugin) { return; } - // The plug-in has been removed from the page. Destroy the old plug-in - // (which will destroy us). + // The plug-in has been removed from the page. Destroy the old plug-in. We + // will be destroyed as soon as V8 garbage collects us. if (!element.pluginContainer()) { plugin_->destroy(); + plugin_ = NULL; return; } @@ -104,6 +102,7 @@ void PluginPlaceholder::ReplacePlugin(WebPlugin* new_plugin) { container->reportGeometry(); plugin_->ReplayReceivedData(new_plugin); plugin_->destroy(); + plugin_ = NULL; } void PluginPlaceholder::HidePlugin() { @@ -152,8 +151,6 @@ void PluginPlaceholder::HidePlugin() { } } -void PluginPlaceholder::WillDestroyPlugin() { delete this; } - void PluginPlaceholder::SetMessage(const base::string16& message) { message_ = message; if (finished_loading_) @@ -173,6 +170,10 @@ void PluginPlaceholder::ShowContextMenu(const WebMouseEvent& event) { return; } +void PluginPlaceholder::OnDestruct() { + frame_ = NULL; +} + void PluginPlaceholder::OnLoadBlockedPlugins(const std::string& identifier) { if (!identifier.empty() && identifier != identifier_) return; @@ -207,20 +208,17 @@ void PluginPlaceholder::LoadPlugin() { ReplacePlugin(plugin); } -void PluginPlaceholder::LoadCallback(const CppArgumentList& args, - CppVariant* result) { +void PluginPlaceholder::LoadCallback() { RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); LoadPlugin(); } -void PluginPlaceholder::HideCallback(const CppArgumentList& args, - CppVariant* result) { +void PluginPlaceholder::HideCallback() { RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Hide_Click")); HidePlugin(); } -void PluginPlaceholder::DidFinishLoadingCallback(const CppArgumentList& args, - CppVariant* result) { +void PluginPlaceholder::DidFinishLoadingCallback() { finished_loading_ = true; if (message_.length() > 0) UpdateMessage(); diff --git a/components/plugins/renderer/plugin_placeholder.h b/components/plugins/renderer/plugin_placeholder.h index d8b7d1a..c1cbbce 100644 --- a/components/plugins/renderer/plugin_placeholder.h +++ b/components/plugins/renderer/plugin_placeholder.h @@ -10,8 +10,8 @@ #include "content/public/renderer/context_menu_client.h" #include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_process_observer.h" +#include "gin/wrappable.h" #include "third_party/WebKit/public/web/WebPluginParams.h" -#include "webkit/renderer/cpp_bound_class.h" namespace content { struct WebPluginInfo; @@ -21,9 +21,10 @@ namespace plugins { // Placeholders can be used if a plug-in is missing or not available // (blocked or disabled). class PluginPlaceholder : public content::RenderFrameObserver, - public webkit_glue::CppBoundClass, - public WebViewPlugin::Delegate { + public WebViewPlugin::Delegate, + public gin::Wrappable<PluginPlaceholder> { public: + static gin::WrapperInfo kWrapperInfo; WebViewPlugin* plugin() { return plugin_; } @@ -65,28 +66,26 @@ class PluginPlaceholder : public content::RenderFrameObserver, // Load the blocked plugin. void LoadPlugin(); - // WebViewPlugin::Delegate method: - virtual void BindWebFrame(blink::WebFrame* frame) OVERRIDE; + // gin::Wrappable method: + virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder( + v8::Isolate* isolate) OVERRIDE; private: // WebViewPlugin::Delegate methods: - virtual void WillDestroyPlugin() OVERRIDE; virtual void ShowContextMenu(const blink::WebMouseEvent&) OVERRIDE; + // RenderFrameObserver methods: + virtual void OnDestruct() OVERRIDE; + // Javascript callbacks: - // All ignore arguments (which are, however, required by caller) and return - // nothing. // Load the blocked plugin by calling LoadPlugin(). - void LoadCallback(const webkit_glue::CppArgumentList& args, - webkit_glue::CppVariant* result); + void LoadCallback(); // Hide the blocked plugin by calling HidePlugin(). - void HideCallback(const webkit_glue::CppArgumentList& args, - webkit_glue::CppVariant* result); + void HideCallback(); - void DidFinishLoadingCallback(const webkit_glue::CppArgumentList& args, - webkit_glue::CppVariant* result); + void DidFinishLoadingCallback(); void UpdateMessage(); diff --git a/components/plugins/renderer/webview_plugin.cc b/components/plugins/renderer/webview_plugin.cc index ccacc06..22c7ed2 100644 --- a/components/plugins/renderer/webview_plugin.cc +++ b/components/plugins/renderer/webview_plugin.cc @@ -107,10 +107,8 @@ bool WebViewPlugin::initialize(WebPluginContainer* container) { } void WebViewPlugin::destroy() { - if (delegate_) { - delegate_->WillDestroyPlugin(); + if (delegate_) delegate_ = NULL; - } container_ = NULL; base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); } diff --git a/components/plugins/renderer/webview_plugin.h b/components/plugins/renderer/webview_plugin.h index 8ec76c4..4f463a7 100644 --- a/components/plugins/renderer/webview_plugin.h +++ b/components/plugins/renderer/webview_plugin.h @@ -40,10 +40,6 @@ class WebViewPlugin : public blink::WebPlugin, // This method is called from WebFrameClient::didClearWindowObject. virtual void BindWebFrame(blink::WebFrame* frame) = 0; - // Called before the WebViewPlugin is destroyed. The delegate should delete - // itself here. - virtual void WillDestroyPlugin() = 0; - // Called upon a context menu event. virtual void ShowContextMenu(const blink::WebMouseEvent&) = 0; }; @@ -136,13 +132,17 @@ class WebViewPlugin : public blink::WebPlugin, friend class base::DeleteHelper<WebViewPlugin>; virtual ~WebViewPlugin(); + // Manages its own lifetime. Delegate* delegate_; - // Destroys itself. + blink::WebCursorInfo current_cursor_; + // Owns us. blink::WebPluginContainer* container_; + // Owned by us, deleted via |close()|. blink::WebView* web_view_; + // Owned by us, deleted via |close()|. blink::WebFrame* web_frame_; gfx::Rect rect_; |