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"
13 namespace guest_view
{
15 class GuestViewRequest
;
17 class GuestViewContainer
: public content::BrowserPluginDelegate
{
19 explicit GuestViewContainer(content::RenderFrame
* render_frame
);
21 static GuestViewContainer
* FromID(int element_instance_id
);
23 // IssueRequest queues up a |request| until the container is ready and
24 // the browser process has responded to the last request if it's still
26 void IssueRequest(linked_ptr
<GuestViewRequest
> request
);
28 int element_instance_id() const { return element_instance_id_
; }
29 content::RenderFrame
* render_frame() const { return render_frame_
; }
31 // Called by GuestViewContainerDispatcher to dispatch message to this
33 bool OnMessageReceived(const IPC::Message
& message
);
35 // Destroys this GuestViewContainer after performing necessary cleanup.
36 // |embedder_frame_destroyed| is true if this destruction is due to the
37 // embedding frame of the container being destroyed.
38 void Destroy(bool embedder_frame_destroyed
);
40 // Called when the embedding RenderFrame is destroyed.
41 virtual void OnRenderFrameDestroyed() {}
43 // Called to respond to IPCs from the browser process that have not been
44 // handled by GuestViewContainer.
45 virtual bool OnMessage(const IPC::Message
& message
);
47 // Called to perform actions when a GuestViewContainer gets a geometry.
48 virtual void OnReady() {}
50 // Called to perform actions when a GuestViewContainer is about to be
52 // Note that this should be called exactly once.
53 virtual void OnDestroy(bool embedder_frame_destroyed
) {}
56 ~GuestViewContainer() override
;
59 class RenderFrameLifetimeObserver
;
60 friend class RenderFrameLifetimeObserver
;
62 void RenderFrameDestroyed();
64 void EnqueueRequest(linked_ptr
<GuestViewRequest
> request
);
65 void PerformPendingRequest();
66 void HandlePendingResponseCallback(const IPC::Message
& message
);
68 void OnHandleCallback(const IPC::Message
& message
);
70 // BrowserPluginDelegate implementation.
72 void SetElementInstanceID(int element_instance_id
) final
;
73 void DidDestroyElement() final
;
74 base::WeakPtr
<BrowserPluginDelegate
> GetWeakPtr() final
;
76 int element_instance_id_
;
77 content::RenderFrame
* render_frame_
;
78 scoped_ptr
<RenderFrameLifetimeObserver
> render_frame_lifetime_observer_
;
83 std::deque
<linked_ptr
<GuestViewRequest
> > pending_requests_
;
84 linked_ptr
<GuestViewRequest
> pending_response_
;
86 base::WeakPtrFactory
<GuestViewContainer
> weak_ptr_factory_
;
88 DISALLOW_COPY_AND_ASSIGN(GuestViewContainer
);
91 } // namespace guest_view
93 #endif // COMPONENTS_GUEST_VIEW_RENDERER_GUEST_VIEW_CONTAINER_H_