• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_H_
6 #define CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_H_
7 
8 #include "chrome/browser/guest_view/guest_view_base.h"
9 #include "content/public/browser/render_frame_host.h"
10 
11 // A GuestView is the templated base class for out-of-process frames in the
12 // chrome layer. GuestView is templated on its derived type to allow for type-
13 // safe access. See GuestViewBase for more information.
14 template <typename T>
15 class GuestView : public GuestViewBase {
16  public:
From(int embedder_process_id,int guest_instance_id)17   static T* From(int embedder_process_id, int guest_instance_id) {
18     GuestViewBase* guest =
19         GuestViewBase::From(embedder_process_id, guest_instance_id);
20     if (!guest)
21       return NULL;
22     return guest->As<T>();
23   }
24 
FromWebContents(content::WebContents * contents)25   static T* FromWebContents(content::WebContents* contents) {
26     GuestViewBase* guest = GuestViewBase::FromWebContents(contents);
27     return guest ? guest->As<T>() : NULL;
28   }
29 
FromFrameID(int render_process_id,int render_frame_id)30   static T* FromFrameID(int render_process_id, int render_frame_id) {
31     content::RenderFrameHost* render_frame_host =
32         content::RenderFrameHost::FromID(render_process_id, render_frame_id);
33     if (!render_frame_host) {
34       return NULL;
35     }
36     content::WebContents* web_contents =
37         content::WebContents::FromRenderFrameHost(render_frame_host);
38     return FromWebContents(web_contents);
39   }
40 
GetOpener()41   T* GetOpener() const {
42     GuestViewBase* guest = GuestViewBase::GetOpener();
43     if (!guest)
44       return NULL;
45     return guest->As<T>();
46   }
47 
SetOpener(T * opener)48   void SetOpener(T* opener) {
49     GuestViewBase::SetOpener(opener);
50   }
51 
52   // GuestViewBase implementation.
GetViewType()53   virtual const char* GetViewType() const OVERRIDE {
54     return T::Type;
55   }
56 
57  protected:
GuestView(int guest_instance_id)58   explicit GuestView(int guest_instance_id)
59       : GuestViewBase(guest_instance_id) {}
~GuestView()60   virtual ~GuestView() {}
61 
62  private:
63   DISALLOW_COPY_AND_ASSIGN(GuestView);
64 };
65 
66 #endif  // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_H_
67