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 "content/public/renderer/render_frame.h" | 7 #include "content/public/renderer/render_frame.h" |
8 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" | 8 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
9 #include "ui/gfx/geometry/size.h" | 9 #include "ui/gfx/geometry/size.h" |
10 | 10 |
11 namespace extensions { | 11 namespace extensions { |
12 | 12 |
13 ExtensionsGuestViewContainer::ExtensionsGuestViewContainer( | 13 ExtensionsGuestViewContainer::ExtensionsGuestViewContainer( |
14 content::RenderFrame* render_frame) | 14 content::RenderFrame* render_frame) |
15 : GuestViewContainer(render_frame), | 15 : GuestViewContainer(render_frame), |
16 destruction_isolate_(nullptr), | |
17 element_resize_isolate_(nullptr), | 16 element_resize_isolate_(nullptr), |
18 weak_ptr_factory_(this) { | 17 weak_ptr_factory_(this) { |
19 } | 18 } |
20 | 19 |
21 ExtensionsGuestViewContainer::~ExtensionsGuestViewContainer() { | 20 ExtensionsGuestViewContainer::~ExtensionsGuestViewContainer() { |
22 } | 21 } |
23 | 22 |
24 void ExtensionsGuestViewContainer::OnDestroy(bool embedder_frame_destroyed) { | 23 void ExtensionsGuestViewContainer::OnDestroy(bool embedder_frame_destroyed) { |
25 // Do not attempt to run |destruction_callback_| if the embedder frame was | |
26 // destroyed. Trying to invoke callback on RenderFrame destruction results in | |
27 // assertion failure when calling WebScopedMicrotaskSuppression. | |
28 if (embedder_frame_destroyed) | |
29 return; | |
30 | |
31 // Call the destruction callback, if one is registered. | |
32 if (!destruction_callback_.IsEmpty()) { | |
33 v8::HandleScope handle_scope(destruction_isolate_); | |
34 v8::Local<v8::Function> callback = v8::Local<v8::Function>::New( | |
35 destruction_isolate_, destruction_callback_); | |
36 v8::Local<v8::Context> context = callback->CreationContext(); | |
37 if (context.IsEmpty()) | |
38 return; | |
39 | |
40 v8::Context::Scope context_scope(context); | |
41 blink::WebScopedMicrotaskSuppression suppression; | |
42 | |
43 callback->Call(context->Global(), 0 /* argc */, nullptr); | |
44 } | |
45 } | |
46 | |
47 void ExtensionsGuestViewContainer::RegisterDestructionCallback( | |
48 v8::Local<v8::Function> callback, | |
49 v8::Isolate* isolate) { | |
50 destruction_callback_.Reset(isolate, callback); | |
51 destruction_isolate_ = isolate; | |
52 } | 24 } |
53 | 25 |
54 void ExtensionsGuestViewContainer::RegisterElementResizeCallback( | 26 void ExtensionsGuestViewContainer::RegisterElementResizeCallback( |
55 v8::Local<v8::Function> callback, | 27 v8::Local<v8::Function> callback, |
56 v8::Isolate* isolate) { | 28 v8::Isolate* isolate) { |
57 element_resize_callback_.Reset(isolate, callback); | 29 element_resize_callback_.Reset(isolate, callback); |
58 element_resize_isolate_ = isolate; | 30 element_resize_isolate_ = isolate; |
59 } | 31 } |
60 | 32 |
61 void ExtensionsGuestViewContainer::DidResizeElement(const gfx::Size& new_size) { | 33 void ExtensionsGuestViewContainer::DidResizeElement(const gfx::Size& new_size) { |
(...skipping 21 matching lines...) Expand all Loading... |
83 v8::Integer::New(element_resize_isolate_, new_size.width()), | 55 v8::Integer::New(element_resize_isolate_, new_size.width()), |
84 v8::Integer::New(element_resize_isolate_, new_size.height())}; | 56 v8::Integer::New(element_resize_isolate_, new_size.height())}; |
85 | 57 |
86 v8::Context::Scope context_scope(context); | 58 v8::Context::Scope context_scope(context); |
87 blink::WebScopedMicrotaskSuppression suppression; | 59 blink::WebScopedMicrotaskSuppression suppression; |
88 | 60 |
89 callback->Call(context->Global(), argc, argv); | 61 callback->Call(context->Global(), argc, argv); |
90 } | 62 } |
91 | 63 |
92 } // namespace extensions | 64 } // namespace extensions |
OLD | NEW |