Don't preload rarely seen large images
[chromium-blink-merge.git] / components / guest_view / browser / guest_view.h
blobf99fe83309e83d3dd0bc8efb971cd60f49fda809
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.
17 template <typename T>
18 class GuestView : public GuestViewBase {
19 public:
20 static T* From(int embedder_process_id, int guest_instance_id) {
21 auto guest = GuestViewBase::From(embedder_process_id, guest_instance_id);
22 if (!guest)
23 return nullptr;
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)
36 return nullptr;
38 auto web_contents =
39 content::WebContents::FromRenderFrameHost(render_frame_host);
40 return FromWebContents(web_contents);
43 T* GetOpener() const {
44 GuestViewBase* guest = GuestViewBase::GetOpener();
45 if (!guest)
46 return nullptr;
47 return guest->As<T>();
50 void SetOpener(T* opener) {
51 GuestViewBase::SetOpener(opener);
54 // GuestViewBase implementation.
55 const char* GetViewType() const final {
56 return T::Type;
59 protected:
60 explicit GuestView(content::WebContents* owner_web_contents)
61 : GuestViewBase(owner_web_contents) {}
62 ~GuestView() override {}
64 private:
65 DISALLOW_COPY_AND_ASSIGN(GuestView);
68 } // namespace guest_view
70 #endif // COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_H_