| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/renderer/guest_view/extensions_guest_view_container.h" | 5 #include "extensions/renderer/guest_view/extensions_guest_view_container.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 8 #include "content/public/common/content_switches.h" |
| 7 #include "content/public/renderer/render_frame.h" | 9 #include "content/public/renderer/render_frame.h" |
| 10 #include "extensions/common/guest_view/extensions_guest_view_messages.h" |
| 8 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" | 11 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
| 9 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
| 10 | 13 |
| 11 namespace extensions { | 14 namespace extensions { |
| 12 | 15 |
| 13 ExtensionsGuestViewContainer::ExtensionsGuestViewContainer( | 16 ExtensionsGuestViewContainer::ExtensionsGuestViewContainer( |
| 14 content::RenderFrame* render_frame) | 17 content::RenderFrame* render_frame) |
| 15 : GuestViewContainer(render_frame), | 18 : GuestViewContainer(render_frame), |
| 16 destruction_isolate_(nullptr), | 19 destruction_isolate_(nullptr), |
| 17 element_resize_isolate_(nullptr), | 20 element_resize_isolate_(nullptr), |
| 18 weak_ptr_factory_(this) { | 21 weak_ptr_factory_(this) { |
| 22 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 23 switches::kSitePerProcess)) { |
| 24 // There is no BrowserPluginDelegate to wait for. |
| 25 ready_ = true; |
| 26 } |
| 19 } | 27 } |
| 20 | 28 |
| 21 ExtensionsGuestViewContainer::~ExtensionsGuestViewContainer() { | 29 ExtensionsGuestViewContainer::~ExtensionsGuestViewContainer() { |
| 22 // Call the destruction callback, if one is registered. | 30 // Call the destruction callback, if one is registered. |
| 23 if (!destruction_callback_.IsEmpty()) { | 31 if (!destruction_callback_.IsEmpty()) { |
| 24 v8::HandleScope handle_scope(destruction_isolate_); | 32 v8::HandleScope handle_scope(destruction_isolate_); |
| 25 v8::Local<v8::Function> callback = v8::Local<v8::Function>::New( | 33 v8::Local<v8::Function> callback = v8::Local<v8::Function>::New( |
| 26 destruction_isolate_, destruction_callback_); | 34 destruction_isolate_, destruction_callback_); |
| 27 v8::Local<v8::Context> context = callback->CreationContext(); | 35 v8::Local<v8::Context> context = callback->CreationContext(); |
| 28 if (context.IsEmpty()) | 36 if (context.IsEmpty()) |
| 29 return; | 37 return; |
| 30 | 38 |
| 31 v8::Context::Scope context_scope(context); | 39 v8::Context::Scope context_scope(context); |
| 32 blink::WebScopedMicrotaskSuppression suppression; | 40 blink::WebScopedMicrotaskSuppression suppression; |
| 33 | 41 |
| 34 callback->Call(context->Global(), 0 /* argc */, nullptr); | 42 callback->Call(context->Global(), 0 /* argc */, nullptr); |
| 35 } | 43 } |
| 36 } | 44 } |
| 37 | 45 |
| 38 void ExtensionsGuestViewContainer::RegisterDestructionCallback( | 46 void ExtensionsGuestViewContainer::RegisterDestructionCallback( |
| 39 v8::Local<v8::Function> callback, | 47 v8::Local<v8::Function> callback, |
| 40 v8::Isolate* isolate) { | 48 v8::Isolate* isolate) { |
| 41 destruction_callback_.Reset(isolate, callback); | 49 destruction_callback_.Reset(isolate, callback); |
| 42 destruction_isolate_ = isolate; | 50 destruction_isolate_ = isolate; |
| 43 } | 51 } |
| 44 | 52 |
| 53 bool ExtensionsGuestViewContainer::OnMessage(const IPC::Message& message) { |
| 54 if (message.type() != ExtensionsGuestViewMsg_GuestReady::ID) |
| 55 return false; |
| 56 |
| 57 OnHandleCallback(message); |
| 58 return true; |
| 59 } |
| 60 |
| 45 void ExtensionsGuestViewContainer::RegisterElementResizeCallback( | 61 void ExtensionsGuestViewContainer::RegisterElementResizeCallback( |
| 46 v8::Local<v8::Function> callback, | 62 v8::Local<v8::Function> callback, |
| 47 v8::Isolate* isolate) { | 63 v8::Isolate* isolate) { |
| 48 element_resize_callback_.Reset(isolate, callback); | 64 element_resize_callback_.Reset(isolate, callback); |
| 49 element_resize_isolate_ = isolate; | 65 element_resize_isolate_ = isolate; |
| 50 } | 66 } |
| 51 | 67 |
| 52 void ExtensionsGuestViewContainer::DidResizeElement(const gfx::Size& new_size) { | 68 void ExtensionsGuestViewContainer::DidResizeElement(const gfx::Size& new_size) { |
| 53 // Call the element resize callback, if one is registered. | 69 // Call the element resize callback, if one is registered. |
| 54 if (element_resize_callback_.IsEmpty()) | 70 if (element_resize_callback_.IsEmpty()) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 74 v8::Integer::New(element_resize_isolate_, new_size.width()), | 90 v8::Integer::New(element_resize_isolate_, new_size.width()), |
| 75 v8::Integer::New(element_resize_isolate_, new_size.height())}; | 91 v8::Integer::New(element_resize_isolate_, new_size.height())}; |
| 76 | 92 |
| 77 v8::Context::Scope context_scope(context); | 93 v8::Context::Scope context_scope(context); |
| 78 blink::WebScopedMicrotaskSuppression suppression; | 94 blink::WebScopedMicrotaskSuppression suppression; |
| 79 | 95 |
| 80 callback->Call(context->Global(), argc, argv); | 96 callback->Call(context->Global(), argc, argv); |
| 81 } | 97 } |
| 82 | 98 |
| 83 } // namespace extensions | 99 } // namespace extensions |
| OLD | NEW |