OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/guestview/guestview.h" | 5 #include "chrome/browser/guestview/guestview.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "chrome/browser/guestview/adview/adview_guest.h" | 8 #include "chrome/browser/guestview/adview/adview_guest.h" |
9 #include "chrome/browser/guestview/guestview_constants.h" | 9 #include "chrome/browser/guestview/guestview_constants.h" |
10 #include "chrome/browser/guestview/webview/webview_guest.h" | 10 #include "chrome/browser/guestview/webview/webview_guest.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 } | 38 } |
39 | 39 |
40 GuestView::Event::~Event() { | 40 GuestView::Event::~Event() { |
41 } | 41 } |
42 | 42 |
43 scoped_ptr<base::DictionaryValue> GuestView::Event::GetArguments() { | 43 scoped_ptr<base::DictionaryValue> GuestView::Event::GetArguments() { |
44 return args_.Pass(); | 44 return args_.Pass(); |
45 } | 45 } |
46 | 46 |
47 GuestView::GuestView(WebContents* guest_web_contents, | 47 GuestView::GuestView(WebContents* guest_web_contents, |
48 const std::string& embedder_extension_id) | 48 const std::string& embedder_extension_id, |
| 49 const base::WeakPtr<GuestView>& opener) |
49 : guest_web_contents_(guest_web_contents), | 50 : guest_web_contents_(guest_web_contents), |
50 embedder_web_contents_(NULL), | 51 embedder_web_contents_(NULL), |
51 embedder_extension_id_(embedder_extension_id), | 52 embedder_extension_id_(embedder_extension_id), |
52 embedder_render_process_id_(0), | 53 embedder_render_process_id_(0), |
53 browser_context_(guest_web_contents->GetBrowserContext()), | 54 browser_context_(guest_web_contents->GetBrowserContext()), |
54 guest_instance_id_(guest_web_contents->GetEmbeddedInstanceID()), | 55 guest_instance_id_(guest_web_contents->GetEmbeddedInstanceID()), |
55 view_instance_id_(guestview::kInstanceIDNone), | 56 view_instance_id_(guestview::kInstanceIDNone), |
| 57 opener_(opener), |
56 weak_ptr_factory_(this) { | 58 weak_ptr_factory_(this) { |
57 webcontents_guestview_map.Get().insert( | 59 webcontents_guestview_map.Get().insert( |
58 std::make_pair(guest_web_contents, this)); | 60 std::make_pair(guest_web_contents, this)); |
59 } | 61 } |
60 | 62 |
61 // static | 63 // static |
62 GuestView::Type GuestView::GetViewTypeFromString(const std::string& api_type) { | 64 GuestView::Type GuestView::GetViewTypeFromString(const std::string& api_type) { |
63 if (api_type == "adview") { | 65 if (api_type == "adview") { |
64 return GuestView::ADVIEW; | 66 return GuestView::ADVIEW; |
65 } else if (api_type == "webview") { | 67 } else if (api_type == "webview") { |
66 return GuestView::WEBVIEW; | 68 return GuestView::WEBVIEW; |
67 } | 69 } |
68 return GuestView::UNKNOWN; | 70 return GuestView::UNKNOWN; |
69 } | 71 } |
70 | 72 |
71 // static | 73 // static |
72 GuestView* GuestView::Create(WebContents* guest_web_contents, | 74 GuestView* GuestView::Create(WebContents* guest_web_contents, |
73 const std::string& embedder_extension_id, | 75 const std::string& embedder_extension_id, |
74 GuestView::Type view_type) { | 76 GuestView::Type view_type, |
| 77 const base::WeakPtr<GuestView>& opener) { |
75 switch (view_type) { | 78 switch (view_type) { |
76 case GuestView::WEBVIEW: | 79 case GuestView::WEBVIEW: |
77 return new WebViewGuest(guest_web_contents, embedder_extension_id); | 80 return new WebViewGuest(guest_web_contents, |
| 81 embedder_extension_id, |
| 82 opener); |
78 case GuestView::ADVIEW: | 83 case GuestView::ADVIEW: |
79 return new AdViewGuest(guest_web_contents, embedder_extension_id); | 84 return new AdViewGuest(guest_web_contents, embedder_extension_id); |
80 default: | 85 default: |
81 NOTREACHED(); | 86 NOTREACHED(); |
82 return NULL; | 87 return NULL; |
83 } | 88 } |
84 } | 89 } |
85 | 90 |
86 // static | 91 // static |
87 GuestView* GuestView::FromWebContents(WebContents* web_contents) { | 92 GuestView* GuestView::FromWebContents(WebContents* web_contents) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // 'loadstop') fire in embedder after the contentWindow is available. | 162 // 'loadstop') fire in embedder after the contentWindow is available. |
158 if (!in_extension()) | 163 if (!in_extension()) |
159 return; | 164 return; |
160 | 165 |
161 base::MessageLoop::current()->PostTask( | 166 base::MessageLoop::current()->PostTask( |
162 FROM_HERE, | 167 FROM_HERE, |
163 base::Bind(&GuestView::SendQueuedEvents, | 168 base::Bind(&GuestView::SendQueuedEvents, |
164 weak_ptr_factory_.GetWeakPtr())); | 169 weak_ptr_factory_.GetWeakPtr())); |
165 } | 170 } |
166 | 171 |
| 172 WebContents* GuestView::GetOpener() const { |
| 173 if (!opener_) |
| 174 return NULL; |
| 175 return opener_->guest_web_contents(); |
| 176 } |
| 177 |
| 178 void GuestView::SetOpener(WebContents* web_contents) { |
| 179 GuestView* guest = FromWebContents(web_contents); |
| 180 if (guest) { |
| 181 opener_ = guest->AsWeakPtr(); |
| 182 return; |
| 183 } |
| 184 opener_ = base::WeakPtr<GuestView>(); |
| 185 } |
| 186 |
167 GuestView::Type GuestView::GetViewType() const { | 187 GuestView::Type GuestView::GetViewType() const { |
168 return GuestView::UNKNOWN; | 188 return GuestView::UNKNOWN; |
169 } | 189 } |
170 | 190 |
| 191 base::WeakPtr<GuestView> GuestView::AsWeakPtr() { |
| 192 return weak_ptr_factory_.GetWeakPtr(); |
| 193 } |
| 194 |
171 WebViewGuest* GuestView::AsWebView() { | 195 WebViewGuest* GuestView::AsWebView() { |
172 return NULL; | 196 return NULL; |
173 } | 197 } |
174 | 198 |
175 AdViewGuest* GuestView::AsAdView() { | 199 AdViewGuest* GuestView::AsAdView() { |
176 return NULL; | 200 return NULL; |
177 } | 201 } |
178 | 202 |
179 GuestView::~GuestView() { | 203 GuestView::~GuestView() { |
180 std::pair<int, int> key(embedder_render_process_id_, guest_instance_id_); | 204 std::pair<int, int> key(embedder_render_process_id_, guest_instance_id_); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 void GuestView::SendQueuedEvents() { | 238 void GuestView::SendQueuedEvents() { |
215 if (!attached()) | 239 if (!attached()) |
216 return; | 240 return; |
217 | 241 |
218 while (!pending_events_.empty()) { | 242 while (!pending_events_.empty()) { |
219 linked_ptr<Event> event_ptr = pending_events_.front(); | 243 linked_ptr<Event> event_ptr = pending_events_.front(); |
220 pending_events_.pop_front(); | 244 pending_events_.pop_front(); |
221 DispatchEvent(event_ptr.release()); | 245 DispatchEvent(event_ptr.release()); |
222 } | 246 } |
223 } | 247 } |
OLD | NEW |