1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/renderer/guest_view/extensions_guest_view_container.h"
#include "content/public/renderer/render_frame.h"
#include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
#include "ui/gfx/geometry/size.h"
namespace extensions {
ExtensionsGuestViewContainer::ExtensionsGuestViewContainer(
content::RenderFrame* render_frame)
: GuestViewContainer(render_frame),
element_resize_isolate_(nullptr),
weak_ptr_factory_(this) {
}
ExtensionsGuestViewContainer::~ExtensionsGuestViewContainer() {
}
void ExtensionsGuestViewContainer::OnDestroy(bool embedder_frame_destroyed) {
}
void ExtensionsGuestViewContainer::RegisterElementResizeCallback(
v8::Local<v8::Function> callback,
v8::Isolate* isolate) {
element_resize_callback_.Reset(isolate, callback);
element_resize_isolate_ = isolate;
}
void ExtensionsGuestViewContainer::DidResizeElement(const gfx::Size& new_size) {
// 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(), new_size));
}
void ExtensionsGuestViewContainer::CallElementResizeCallback(
const gfx::Size& new_size) {
v8::HandleScope handle_scope(element_resize_isolate_);
v8::Local<v8::Function> callback = v8::Local<v8::Function>::New(
element_resize_isolate_, element_resize_callback_);
v8::Local<v8::Context> context = callback->CreationContext();
if (context.IsEmpty())
return;
const int argc = 2;
v8::Local<v8::Value> argv[argc] = {
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);
}
} // namespace extensions
|