summaryrefslogtreecommitdiffstats
path: root/extensions/renderer/guest_view
diff options
context:
space:
mode:
authorlazyboy <lazyboy@chromium.org>2015-06-09 12:34:59 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-09 19:35:23 +0000
commitcb6ba5c2ad69bf9daf896e5d3cd0c252c0ce6da3 (patch)
tree75935f16991db19af74f9f00d1baa8de0afb0852 /extensions/renderer/guest_view
parentff49e7e2d72252d6f7f4c6833421fa6d1fa8c751 (diff)
downloadchromium_src-cb6ba5c2ad69bf9daf896e5d3cd0c252c0ce6da3.zip
chromium_src-cb6ba5c2ad69bf9daf896e5d3cd0c252c0ce6da3.tar.gz
chromium_src-cb6ba5c2ad69bf9daf896e5d3cd0c252c0ce6da3.tar.bz2
Move BrowserPluginDelegate's lifetime mgmt out of content/
This CL makes BrowserPlugin not own BPDelegate (GuestViewContainer) anymore. BrowserPluginDelegate's lifetime has been tied to garbage collection of the shadow root HTML element that contains the plugin. For example, for <webview>, this is the <webview> element. Before registering BPDelegate to GC, there's a brief period while BPDelegate is not owned by anyone directly, this case is covered with the static PostTask that deletes the delegate if we did not tie it to GC (UpdateInternalInstanceIdAndBindDelegateToGC()). To make <webview> run without BrowserPlugin, we need to manage GuestViewContainer's (which is a BPDelegate) lifetime out of content/. BUG=330264 Test=None, internal change only. Review URL: https://codereview.chromium.org/1162053003 Cr-Commit-Position: refs/heads/master@{#333552}
Diffstat (limited to 'extensions/renderer/guest_view')
-rw-r--r--extensions/renderer/guest_view/extensions_guest_view_container.cc3
-rw-r--r--extensions/renderer/guest_view/extensions_guest_view_container.h7
-rw-r--r--extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc27
-rw-r--r--extensions/renderer/guest_view/guest_view_internal_custom_bindings.h3
-rw-r--r--extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h4
5 files changed, 42 insertions, 2 deletions
diff --git a/extensions/renderer/guest_view/extensions_guest_view_container.cc b/extensions/renderer/guest_view/extensions_guest_view_container.cc
index 1bd8575..d100503 100644
--- a/extensions/renderer/guest_view/extensions_guest_view_container.cc
+++ b/extensions/renderer/guest_view/extensions_guest_view_container.cc
@@ -19,6 +19,9 @@ ExtensionsGuestViewContainer::ExtensionsGuestViewContainer(
}
ExtensionsGuestViewContainer::~ExtensionsGuestViewContainer() {
+}
+
+void ExtensionsGuestViewContainer::OnDestroy() {
// Call the destruction callback, if one is registered.
if (!destruction_callback_.IsEmpty()) {
v8::HandleScope handle_scope(destruction_isolate_);
diff --git a/extensions/renderer/guest_view/extensions_guest_view_container.h b/extensions/renderer/guest_view/extensions_guest_view_container.h
index 4e3f3e9..ec569ac 100644
--- a/extensions/renderer/guest_view/extensions_guest_view_container.h
+++ b/extensions/renderer/guest_view/extensions_guest_view_container.h
@@ -19,7 +19,6 @@ namespace extensions {
class ExtensionsGuestViewContainer : public guest_view::GuestViewContainer {
public:
explicit ExtensionsGuestViewContainer(content::RenderFrame* render_frame);
- ~ExtensionsGuestViewContainer() override;
void RegisterDestructionCallback(v8::Local<v8::Function> callback,
v8::Isolate* isolate);
@@ -29,9 +28,15 @@ class ExtensionsGuestViewContainer : public guest_view::GuestViewContainer {
// BrowserPluginDelegate implementation.
void DidResizeElement(const gfx::Size& new_size) override;
+ protected:
+ ~ExtensionsGuestViewContainer() override;
+
private:
void CallElementResizeCallback(const gfx::Size& new_size);
+ // GuestViewContainer implementation.
+ void OnDestroy() override;
+
v8::Global<v8::Function> destruction_callback_;
v8::Isolate* destruction_isolate_;
diff --git a/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc b/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc
index 5a240f8..738f00c 100644
--- a/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc
+++ b/extensions/renderer/guest_view/guest_view_internal_custom_bindings.cc
@@ -47,6 +47,9 @@ GuestViewInternalCustomBindings::GuestViewInternalCustomBindings(
RouteFunction("DetachGuest",
base::Bind(&GuestViewInternalCustomBindings::DetachGuest,
base::Unretained(this)));
+ RouteFunction("DestroyContainer",
+ base::Bind(&GuestViewInternalCustomBindings::DestroyContainer,
+ base::Unretained(this)));
RouteFunction("GetContentWindow",
base::Bind(&GuestViewInternalCustomBindings::GetContentWindow,
base::Unretained(this)));
@@ -174,6 +177,30 @@ void GuestViewInternalCustomBindings::DetachGuest(
args.GetReturnValue().Set(v8::Boolean::New(context()->isolate(), true));
}
+void GuestViewInternalCustomBindings::DestroyContainer(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ args.GetReturnValue().SetNull();
+
+ if (args.Length() != 1)
+ return;
+
+ // Element Instance ID.
+ if (!args[0]->IsInt32())
+ return;
+
+ int element_instance_id = args[0]->Int32Value();
+ auto* guest_view_container =
+ guest_view::GuestViewContainer::FromID(element_instance_id);
+ if (!guest_view_container)
+ return;
+
+ // Note: |guest_view_container| is deleted.
+ // GuestViewContainer::DidDestroyElement() currently also destroys
+ // a GuestViewContainer. That won't be necessary once GuestViewContainer
+ // always runs w/o plugin.
+ guest_view_container->Destroy();
+}
+
void GuestViewInternalCustomBindings::GetContentWindow(
const v8::FunctionCallbackInfo<v8::Value>& args) {
// Default to returning null.
diff --git a/extensions/renderer/guest_view/guest_view_internal_custom_bindings.h b/extensions/renderer/guest_view/guest_view_internal_custom_bindings.h
index 0f84a39..6a6d6c3 100644
--- a/extensions/renderer/guest_view/guest_view_internal_custom_bindings.h
+++ b/extensions/renderer/guest_view/guest_view_internal_custom_bindings.h
@@ -51,6 +51,9 @@ class GuestViewInternalCustomBindings : public ObjectBackedNativeHandler {
// Window JavaScript object for that RenderView.
void GetContentWindow(const v8::FunctionCallbackInfo<v8::Value>& args);
+ // Destroys the GuestViewContainer given an element instance ID in |args|.
+ void DestroyContainer(const v8::FunctionCallbackInfo<v8::Value>& args);
+
// GetViewFromID takes a view ID, and returns the GuestView element associated
// with that ID, if one exists. Otherwise, null is returned.
void GetViewFromID(const v8::FunctionCallbackInfo<v8::Value>& args);
diff --git a/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h
index c39bf93..796358e 100644
--- a/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h
+++ b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h
@@ -41,7 +41,6 @@ class MimeHandlerViewContainer : public guest_view::GuestViewContainer,
MimeHandlerViewContainer(content::RenderFrame* render_frame,
const std::string& mime_type,
const GURL& original_url);
- ~MimeHandlerViewContainer() override;
static std::vector<MimeHandlerViewContainer*> FromRenderFrame(
content::RenderFrame* render_frame);
@@ -74,6 +73,9 @@ class MimeHandlerViewContainer : public guest_view::GuestViewContainer,
// Post |message| to the guest.
void PostMessageFromValue(const base::Value& message);
+ protected:
+ ~MimeHandlerViewContainer() override;
+
private:
// Message handlers.
void OnCreateMimeHandlerViewGuestACK(int element_instance_id);