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_BROWSER_GUEST_VIEW_H_
6 #define COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_H_
8 #include "components/guest_view/browser/guest_view_base.h"
9 #include "components/guest_view/browser/guest_view_manager.h"
10 #include "content/public/browser/render_frame_host.h"
12 namespace guest_view
{
14 // A GuestView is the templated base class for out-of-process frames in the
15 // chrome layer. GuestView is templated on its derived type to allow for type-
16 // safe access. See GuestViewBase for more information.
18 class GuestView
: public GuestViewBase
{
20 static T
* From(int embedder_process_id
, int guest_instance_id
) {
21 auto guest
= GuestViewBase::From(embedder_process_id
, guest_instance_id
);
24 return guest
->As
<T
>();
27 static T
* FromWebContents(const content::WebContents
* contents
) {
28 auto guest
= GuestViewBase::FromWebContents(contents
);
29 return guest
? guest
->As
<T
>() : nullptr;
32 static T
* FromFrameID(int render_process_id
, int render_frame_id
) {
33 auto render_frame_host
=
34 content::RenderFrameHost::FromID(render_process_id
, render_frame_id
);
35 if (!render_frame_host
)
39 content::WebContents::FromRenderFrameHost(render_frame_host
);
40 return FromWebContents(web_contents
);
43 T
* GetOpener() const {
44 GuestViewBase
* guest
= GuestViewBase::GetOpener();
47 return guest
->As
<T
>();
50 void SetOpener(T
* opener
) {
51 GuestViewBase::SetOpener(opener
);
54 // GuestViewBase implementation.
55 const char* GetViewType() const final
{
60 explicit GuestView(content::WebContents
* owner_web_contents
)
61 : GuestViewBase(owner_web_contents
) {}
62 ~GuestView() override
{}
65 DISALLOW_COPY_AND_ASSIGN(GuestView
);
68 } // namespace guest_view
70 #endif // COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_H_