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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
// 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.
#ifndef EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_
#define EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_
#include <queue>
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "extensions/renderer/guest_view/guest_view_container.h"
#include "v8/include/v8.h"
namespace gfx {
class Size;
}
namespace extensions {
class ExtensionsGuestViewContainer : public GuestViewContainer {
public:
class Request {
public:
Request(GuestViewContainer* container,
v8::Local<v8::Function> callback,
v8::Isolate* isolate);
virtual ~Request();
virtual void PerformRequest() = 0;
virtual void HandleResponse(const IPC::Message& message) = 0;
void ExecuteCallbackIfAvailable(int argc,
scoped_ptr<v8::Local<v8::Value>[]> argv);
GuestViewContainer* container() const { return container_; }
bool HasCallback() const;
v8::Local<v8::Function> GetCallback() const;
v8::Isolate* isolate() const { return isolate_; }
private:
GuestViewContainer* container_;
v8::Global<v8::Function> callback_;
v8::Isolate* const isolate_;
};
// This class represents an AttachGuest request from Javascript. It includes
// the input parameters and the callback function. The Attach operation may
// not execute immediately, if the container is not ready or if there are
// other attach operations in flight.
class AttachRequest : public Request {
public:
AttachRequest(GuestViewContainer* container,
int guest_instance_id,
scoped_ptr<base::DictionaryValue> params,
v8::Local<v8::Function> callback,
v8::Isolate* isolate);
~AttachRequest() override;
void PerformRequest() override;
void HandleResponse(const IPC::Message& message) override;
private:
const int guest_instance_id_;
scoped_ptr<base::DictionaryValue> params_;
};
class DetachRequest : public Request {
public:
DetachRequest(GuestViewContainer* container,
v8::Local<v8::Function> callback,
v8::Isolate* isolate);
~DetachRequest() override;
void PerformRequest() override;
void HandleResponse(const IPC::Message& message) override;
};
explicit ExtensionsGuestViewContainer(content::RenderFrame* render_frame);
~ExtensionsGuestViewContainer() override;
static ExtensionsGuestViewContainer* FromID(int element_instance_id);
void IssueRequest(linked_ptr<Request> request);
void RegisterDestructionCallback(v8::Local<v8::Function> callback,
v8::Isolate* isolate);
void RegisterElementResizeCallback(v8::Local<v8::Function> callback,
v8::Isolate* isolate);
// BrowserPluginDelegate implementation.
bool OnMessageReceived(const IPC::Message& message) override;
void SetElementInstanceID(int element_instance_id) override;
void Ready() override;
void DidResizeElement(const gfx::Size& old_size,
const gfx::Size& new_size) override;
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);
bool ready_;
std::deque<linked_ptr<Request> > pending_requests_;
linked_ptr<Request> pending_response_;
v8::Global<v8::Function> destruction_callback_;
v8::Isolate* destruction_isolate_;
v8::Global<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);
};
} // namespace extensions
#endif // EXTENSIONS_RENDERER_GUEST_VIEW_EXTENSIONS_GUEST_VIEW_CONTAINER_H_
|