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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_CONTAINER_H_
6 #define COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_CONTAINER_H_
8 #include "base/memory/linked_ptr.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/public/renderer/browser_plugin_delegate.h"
11 #include "ipc/ipc_message.h"
12 #include "v8/include/v8.h"
14 namespace guest_view
{
16 class GuestViewRequest
;
18 class GuestViewContainer
: public content::BrowserPluginDelegate
{
20 explicit GuestViewContainer(content::RenderFrame
* render_frame
);
22 static GuestViewContainer
* FromID(int element_instance_id
);
24 // IssueRequest queues up a |request| until the container is ready and
25 // the browser process has responded to the last request if it's still
27 void IssueRequest(linked_ptr
<GuestViewRequest
> request
);
29 int element_instance_id() const { return element_instance_id_
; }
30 content::RenderFrame
* render_frame() const { return render_frame_
; }
32 // Called by GuestViewContainerDispatcher to dispatch message to this
34 bool OnMessageReceived(const IPC::Message
& message
);
36 // Destroys this GuestViewContainer after performing necessary cleanup.
37 // |embedder_frame_destroyed| is true if this destruction is due to the
38 // embedding frame of the container being destroyed.
39 void Destroy(bool embedder_frame_destroyed
);
41 void RegisterDestructionCallback(v8::Local
<v8::Function
> callback
,
42 v8::Isolate
* isolate
);
44 // Called when the embedding RenderFrame is destroyed.
45 virtual void OnRenderFrameDestroyed() {}
47 // Called to respond to IPCs from the browser process that have not been
48 // handled by GuestViewContainer.
49 virtual bool OnMessage(const IPC::Message
& message
);
51 // Called to perform actions when a GuestViewContainer gets a geometry.
52 virtual void OnReady() {}
54 // Called to perform actions when a GuestViewContainer is about to be
56 // Note that this should be called exactly once.
57 virtual void OnDestroy(bool embedder_frame_destroyed
) {}
59 // BrowserPluginGuestDelegate public implementation.
60 void SetElementInstanceID(int element_instance_id
) final
;
63 ~GuestViewContainer() override
;
67 void OnHandleCallback(const IPC::Message
& message
);
70 class RenderFrameLifetimeObserver
;
71 friend class RenderFrameLifetimeObserver
;
73 void RenderFrameDestroyed();
75 void EnqueueRequest(linked_ptr
<GuestViewRequest
> request
);
76 void PerformPendingRequest();
77 void HandlePendingResponseCallback(const IPC::Message
& message
);
78 void RunDestructionCallback(bool embedder_frame_destroyed
);
80 // BrowserPluginDelegate implementation.
82 void DidDestroyElement() final
;
83 base::WeakPtr
<BrowserPluginDelegate
> GetWeakPtr() final
;
85 int element_instance_id_
;
86 content::RenderFrame
* render_frame_
;
87 scoped_ptr
<RenderFrameLifetimeObserver
> render_frame_lifetime_observer_
;
91 std::deque
<linked_ptr
<GuestViewRequest
> > pending_requests_
;
92 linked_ptr
<GuestViewRequest
> pending_response_
;
94 v8::Global
<v8::Function
> destruction_callback_
;
95 v8::Isolate
* destruction_isolate_
;
97 base::WeakPtrFactory
<GuestViewContainer
> weak_ptr_factory_
;
99 DISALLOW_COPY_AND_ASSIGN(GuestViewContainer
);
102 } // namespace guest_view
104 #endif // COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_CONTAINER_H_