diff options
author | paulmeyer <paulmeyer@chromium.org> | 2015-02-24 11:15:10 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-24 19:16:05 +0000 |
commit | 9ef6e446e6621ea47df1eebabae2747fdf4a2290 (patch) | |
tree | 176e9ddf635992af875edee8f28ed03783eeb982 /extensions/renderer/guest_view | |
parent | 355ef6861a0af7fdf163615abe04bd00cd640f1e (diff) | |
download | chromium_src-9ef6e446e6621ea47df1eebabae2747fdf4a2290.zip chromium_src-9ef6e446e6621ea47df1eebabae2747fdf4a2290.tar.gz chromium_src-9ef6e446e6621ea47df1eebabae2747fdf4a2290.tar.bz2 |
All guestview sizing now utilizes the new sizing infrastructure from https://codereview.chromium.org/856563002/ and https://codereview.chromium.org/857093003/. The existing sizing code in BrowserPluginGuest was removed, which allowed for a large amount of plumbing that went into and out of BrowserPluginGuest to be removed as well.
BUG=434226
TBR=rockot@chromium.org
Review URL: https://codereview.chromium.org/889303003
Cr-Commit-Position: refs/heads/master@{#317849}
Diffstat (limited to 'extensions/renderer/guest_view')
3 files changed, 40 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 77456ab..5936ee8 100644 --- a/extensions/renderer/guest_view/extensions_guest_view_container.cc +++ b/extensions/renderer/guest_view/extensions_guest_view_container.cc @@ -147,7 +147,8 @@ ExtensionsGuestViewContainer::ExtensionsGuestViewContainer( : GuestViewContainer(render_frame), ready_(false), destruction_isolate_(nullptr), - element_resize_isolate_(nullptr) { + element_resize_isolate_(nullptr), + weak_ptr_factory_(this) { } ExtensionsGuestViewContainer::~ExtensionsGuestViewContainer() { @@ -200,7 +201,14 @@ void ExtensionsGuestViewContainer::RegisterElementResizeCallback( void ExtensionsGuestViewContainer::DidResizeElement(const gfx::Size& old_size, const gfx::Size& new_size) { - // TODO(paulmeyer): Call the |element_resize_callback_| callback here. + // Call the element resize callback, if one is registered. + if (element_resize_callback_.IsEmpty()) + return; + + base::MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&ExtensionsGuestViewContainer::CallElementResizeCallback, + weak_ptr_factory_.GetWeakPtr(), old_size, new_size)); } bool ExtensionsGuestViewContainer::OnMessageReceived( @@ -233,6 +241,29 @@ void ExtensionsGuestViewContainer::OnHandleCallback( PerformPendingRequest(); } +void ExtensionsGuestViewContainer::CallElementResizeCallback( + const gfx::Size& old_size, + const gfx::Size& new_size) { + v8::HandleScope handle_scope(element_resize_isolate_); + v8::Handle<v8::Function> callback = + element_resize_callback_.NewHandle(element_resize_isolate_); + v8::Handle<v8::Context> context = callback->CreationContext(); + if (context.IsEmpty()) + return; + + const int argc = 4; + v8::Handle<v8::Value> argv[argc] = { + v8::Integer::New(element_resize_isolate_, old_size.width()), + v8::Integer::New(element_resize_isolate_, old_size.height()), + v8::Integer::New(element_resize_isolate_, new_size.width()), + v8::Integer::New(element_resize_isolate_, new_size.height())}; + + v8::Context::Scope context_scope(context); + blink::WebScopedMicrotaskSuppression suppression; + + callback->Call(context->Global(), argc, argv); +} + void ExtensionsGuestViewContainer::EnqueueRequest(linked_ptr<Request> request) { pending_requests_.push_back(request); } diff --git a/extensions/renderer/guest_view/extensions_guest_view_container.h b/extensions/renderer/guest_view/extensions_guest_view_container.h index 6a5f9cc..df257f1 100644 --- a/extensions/renderer/guest_view/extensions_guest_view_container.h +++ b/extensions/renderer/guest_view/extensions_guest_view_container.h @@ -99,6 +99,8 @@ class ExtensionsGuestViewContainer : public GuestViewContainer { private: void OnHandleCallback(const IPC::Message& message); + void CallElementResizeCallback(const gfx::Size& old_size, + const gfx::Size& new_size); void EnqueueRequest(linked_ptr<Request> request); void PerformPendingRequest(); void HandlePendingResponseCallback(const IPC::Message& message); @@ -114,6 +116,9 @@ class ExtensionsGuestViewContainer : public GuestViewContainer { ScopedPersistent<v8::Function> element_resize_callback_; v8::Isolate* element_resize_isolate_; + // Weak pointer factory used for calling the element resize callback. + base::WeakPtrFactory<ExtensionsGuestViewContainer> weak_ptr_factory_; + DISALLOW_COPY_AND_ASSIGN(ExtensionsGuestViewContainer); }; diff --git a/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc index ada23f9..b50d5ad 100644 --- a/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc +++ b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc @@ -168,6 +168,8 @@ bool MimeHandlerViewContainer::OnMessageReceived(const IPC::Message& message) { void MimeHandlerViewContainer::DidResizeElement(const gfx::Size& old_size, const gfx::Size& new_size) { element_size_ = new_size; + render_frame()->Send(new GuestViewHostMsg_ResizeGuest( + render_frame()->GetRoutingID(), element_instance_id(), new_size)); } v8::Local<v8::Object> MimeHandlerViewContainer::V8ScriptableObject( |