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