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/guest_view/guest_view_base.h" | 5 #include "chrome/browser/guest_view/guest_view_base.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/guest_view/app_view/app_view_guest.h" | 9 #include "chrome/browser/guest_view/app_view/app_view_guest.h" |
10 #include "chrome/browser/guest_view/guest_view_constants.h" | 10 #include "chrome/browser/guest_view/guest_view_constants.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 webcontents_guestview_map.Get().insert( | 136 webcontents_guestview_map.Get().insert( |
137 std::make_pair(guest_web_contents, this)); | 137 std::make_pair(guest_web_contents, this)); |
138 GuestViewManager::FromBrowserContext(browser_context_)-> | 138 GuestViewManager::FromBrowserContext(browser_context_)-> |
139 AddGuest(guest_instance_id_, guest_web_contents); | 139 AddGuest(guest_instance_id_, guest_web_contents); |
140 | 140 |
141 // Give the derived class an opportunity to perform additional initialization. | 141 // Give the derived class an opportunity to perform additional initialization. |
142 DidInitialize(); | 142 DidInitialize(); |
143 } | 143 } |
144 | 144 |
145 // static | 145 // static |
146 void GuestViewBase::RegisterGuestViewTypes() { | |
147 GuestView<WebViewGuest>::Register(); | |
148 GuestView<AppViewGuest>::Register(); | |
149 } | |
150 | |
151 // static | |
152 void GuestViewBase::RegisterGuestViewType( | 146 void GuestViewBase::RegisterGuestViewType( |
153 const std::string& view_type, | 147 const std::string& view_type, |
154 const GuestCreationCallback& callback) { | 148 const GuestCreationCallback& callback) { |
155 GuestViewCreationMap::iterator it = | 149 GuestViewCreationMap::iterator it = |
156 guest_view_registry.Get().find(view_type); | 150 guest_view_registry.Get().find(view_type); |
157 DCHECK(it == guest_view_registry.Get().end()); | 151 DCHECK(it == guest_view_registry.Get().end()); |
158 guest_view_registry.Get()[view_type] = callback; | 152 guest_view_registry.Get()[view_type] = callback; |
159 } | 153 } |
160 | 154 |
161 // static | 155 // static |
162 GuestViewBase* GuestViewBase::Create( | 156 GuestViewBase* GuestViewBase::Create( |
163 content::BrowserContext* browser_context, | 157 content::BrowserContext* browser_context, |
164 int guest_instance_id, | 158 int guest_instance_id, |
165 const std::string& view_type) { | 159 const std::string& view_type) { |
| 160 if (guest_view_registry.Get().empty()) |
| 161 RegisterGuestViewTypes(); |
| 162 |
166 GuestViewCreationMap::iterator it = | 163 GuestViewCreationMap::iterator it = |
167 guest_view_registry.Get().find(view_type); | 164 guest_view_registry.Get().find(view_type); |
168 if (it == guest_view_registry.Get().end()) { | 165 if (it == guest_view_registry.Get().end()) { |
169 NOTREACHED(); | 166 NOTREACHED(); |
170 return NULL; | 167 return NULL; |
171 } | 168 } |
172 return it->second.Run(browser_context, guest_instance_id); | 169 return it->second.Run(browser_context, guest_instance_id); |
173 } | 170 } |
174 | 171 |
175 // static | 172 // static |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 // purpose. Let's self-destruct. | 376 // purpose. Let's self-destruct. |
380 delete this; | 377 delete this; |
381 callback.Run(NULL); | 378 callback.Run(NULL); |
382 return; | 379 return; |
383 } | 380 } |
384 InitWithWebContents(embedder_extension_id, | 381 InitWithWebContents(embedder_extension_id, |
385 embedder_render_process_id, | 382 embedder_render_process_id, |
386 guest_web_contents); | 383 guest_web_contents); |
387 callback.Run(guest_web_contents); | 384 callback.Run(guest_web_contents); |
388 } | 385 } |
| 386 |
| 387 // static |
| 388 void GuestViewBase::RegisterGuestViewTypes() { |
| 389 AppViewGuest::Register(); |
| 390 WebViewGuest::Register(); |
| 391 } |
OLD | NEW |