OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_ | 5 #ifndef CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_ |
6 #define CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_ | 6 #define CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 return embedder_web_contents_; | 75 return embedder_web_contents_; |
76 } | 76 } |
77 | 77 |
78 // Returns the guest WebContents. | 78 // Returns the guest WebContents. |
79 content::WebContents* guest_web_contents() const { | 79 content::WebContents* guest_web_contents() const { |
80 return guest_web_contents_; | 80 return guest_web_contents_; |
81 } | 81 } |
82 | 82 |
83 virtual Type GetViewType() const; | 83 virtual Type GetViewType() const; |
84 | 84 |
85 // Returns a WebViewGuest if this GuestView belongs to a <webview>. | 85 // Returns a *ViewGuest if this GuestView is of the given view type. |
86 virtual WebViewGuest* AsWebView() = 0; | 86 template <class T> |
Xi Han
2014/04/15 21:35:37
We do not want a bunch of As*View functions, e.g.,
| |
87 | 87 T* As() { |
88 // Returns an AdViewGuest if the GuestView belongs to an <adview>. | 88 if (GetViewType() == T::Type()) { |
89 virtual AdViewGuest* AsAdView() = 0; | 89 return static_cast<T*>(this); |
90 } | |
91 return NULL; | |
92 } | |
90 | 93 |
91 // Returns whether this guest has an associated embedder. | 94 // Returns whether this guest has an associated embedder. |
92 bool attached() const { return !!embedder_web_contents_; } | 95 bool attached() const { return !!embedder_web_contents_; } |
93 | 96 |
94 // Returns the instance ID of the <*view> element. | 97 // Returns the instance ID of the <*view> element. |
95 int view_instance_id() const { return view_instance_id_; } | 98 int view_instance_id() const { return view_instance_id_; } |
96 | 99 |
97 // Returns the instance ID of the guest WebContents. | 100 // Returns the instance ID of the guest WebContents. |
98 int guest_instance_id() const { return guest_instance_id_; } | 101 int guest_instance_id() const { return guest_instance_id_; } |
99 | 102 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 std::queue<Event*> pending_events_; | 144 std::queue<Event*> pending_events_; |
142 | 145 |
143 // This is used to ensure pending tasks will not fire after this object is | 146 // This is used to ensure pending tasks will not fire after this object is |
144 // destroyed. | 147 // destroyed. |
145 base::WeakPtrFactory<GuestView> weak_ptr_factory_; | 148 base::WeakPtrFactory<GuestView> weak_ptr_factory_; |
146 | 149 |
147 DISALLOW_COPY_AND_ASSIGN(GuestView); | 150 DISALLOW_COPY_AND_ASSIGN(GuestView); |
148 }; | 151 }; |
149 | 152 |
150 #endif // CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_ | 153 #endif // CHROME_BROWSER_GUESTVIEW_GUESTVIEW_H_ |
OLD | NEW |