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 #include "extensions/renderer/guest_view/guest_view_container.h"
7 #include "content/public/renderer/render_frame.h"
8 #include "content/public/renderer/render_frame_observer.h"
9 #include "content/public/renderer/render_view.h"
10 #include "extensions/common/guest_view/extensions_guest_view_messages.h"
11 #include "extensions/common/guest_view/guest_view_constants.h"
12 #include "extensions/common/guest_view/guest_view_messages.h"
14 namespace extensions
{
16 class GuestViewContainer::RenderFrameLifetimeObserver
17 : public content::RenderFrameObserver
{
19 RenderFrameLifetimeObserver(GuestViewContainer
* container
,
20 content::RenderFrame
* render_frame
);
22 // content::RenderFrameObserver overrides.
23 void OnDestruct() override
;
26 GuestViewContainer
* container_
;
28 DISALLOW_COPY_AND_ASSIGN(RenderFrameLifetimeObserver
);
31 GuestViewContainer::RenderFrameLifetimeObserver::RenderFrameLifetimeObserver(
32 GuestViewContainer
* container
,
33 content::RenderFrame
* render_frame
)
34 : content::RenderFrameObserver(render_frame
),
35 container_(container
) {}
37 void GuestViewContainer::RenderFrameLifetimeObserver::OnDestruct() {
38 container_
->RenderFrameDestroyed();
41 GuestViewContainer::GuestViewContainer(content::RenderFrame
* render_frame
)
42 : element_instance_id_(guestview::kInstanceIDNone
),
43 render_frame_(render_frame
) {
44 render_frame_lifetime_observer_
.reset(
45 new RenderFrameLifetimeObserver(this, render_frame_
));
48 GuestViewContainer::~GuestViewContainer() {}
51 bool GuestViewContainer::HandlesMessage(const IPC::Message
& msg
) {
53 case ExtensionsGuestViewMsg_CreateMimeHandlerViewGuestACK::ID
:
54 case ExtensionsGuestViewMsg_MimeHandlerViewGuestOnLoadCompleted::ID
:
55 case GuestViewMsg_GuestAttached::ID
:
56 case GuestViewMsg_GuestDetached::ID
:
63 void GuestViewContainer::RenderFrameDestroyed() {
64 OnRenderFrameDestroyed();
65 render_frame_
= nullptr;
68 void GuestViewContainer::SetElementInstanceID(int element_instance_id
) {
69 DCHECK_EQ(element_instance_id_
, guestview::kInstanceIDNone
);
70 element_instance_id_
= element_instance_id
;
73 } // namespace extensions