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 "extensions/browser/guest_view/guest_view_base.h" | 5 #include "extensions/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 "components/ui/zoom/page_zoom.h" | 9 #include "components/ui/zoom/page_zoom.h" |
10 #include "components/ui/zoom/zoom_controller.h" | 10 #include "components/ui/zoom/zoom_controller.h" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 rvh->DisableAutoResize(element_size_); | 251 rvh->DisableAutoResize(element_size_); |
252 guest_size_ = element_size_; | 252 guest_size_ = element_size_; |
253 GuestSizeChangedDueToAutoSize(guest_size_, element_size_); | 253 GuestSizeChangedDueToAutoSize(guest_size_, element_size_); |
254 } | 254 } |
255 } | 255 } |
256 | 256 |
257 // static | 257 // static |
258 void GuestViewBase::RegisterGuestViewType( | 258 void GuestViewBase::RegisterGuestViewType( |
259 const std::string& view_type, | 259 const std::string& view_type, |
260 const GuestCreationCallback& callback) { | 260 const GuestCreationCallback& callback) { |
261 GuestViewCreationMap::iterator it = | 261 auto it = guest_view_registry.Get().find(view_type); |
262 guest_view_registry.Get().find(view_type); | |
263 DCHECK(it == guest_view_registry.Get().end()); | 262 DCHECK(it == guest_view_registry.Get().end()); |
264 guest_view_registry.Get()[view_type] = callback; | 263 guest_view_registry.Get()[view_type] = callback; |
265 } | 264 } |
266 | 265 |
267 // static | 266 // static |
268 GuestViewBase* GuestViewBase::Create( | 267 GuestViewBase* GuestViewBase::Create( |
269 content::BrowserContext* browser_context, | 268 content::BrowserContext* browser_context, |
270 content::WebContents* owner_web_contents, | 269 content::WebContents* owner_web_contents, |
271 int guest_instance_id, | 270 int guest_instance_id, |
272 const std::string& view_type) { | 271 const std::string& view_type) { |
273 if (guest_view_registry.Get().empty()) | 272 if (guest_view_registry.Get().empty()) |
274 RegisterGuestViewTypes(); | 273 RegisterGuestViewTypes(); |
275 | 274 |
276 GuestViewCreationMap::iterator it = | 275 auto it = guest_view_registry.Get().find(view_type); |
277 guest_view_registry.Get().find(view_type); | |
278 if (it == guest_view_registry.Get().end()) { | 276 if (it == guest_view_registry.Get().end()) { |
279 NOTREACHED(); | 277 NOTREACHED(); |
280 return NULL; | 278 return NULL; |
281 } | 279 } |
282 return it->second.Run(browser_context, owner_web_contents, guest_instance_id); | 280 return it->second.Run(browser_context, owner_web_contents, guest_instance_id); |
283 } | 281 } |
284 | 282 |
285 // static | 283 // static |
286 GuestViewBase* GuestViewBase::FromWebContents(WebContents* web_contents) { | 284 GuestViewBase* GuestViewBase::FromWebContents(WebContents* web_contents) { |
287 WebContentsGuestViewMap* guest_map = webcontents_guestview_map.Pointer(); | 285 WebContentsGuestViewMap* guest_map = webcontents_guestview_map.Pointer(); |
288 WebContentsGuestViewMap::iterator it = guest_map->find(web_contents); | 286 auto it = guest_map->find(web_contents); |
289 return it == guest_map->end() ? NULL : it->second; | 287 return it == guest_map->end() ? NULL : it->second; |
290 } | 288 } |
291 | 289 |
292 // static | 290 // static |
293 GuestViewBase* GuestViewBase::From(int embedder_process_id, | 291 GuestViewBase* GuestViewBase::From(int owner_process_id, |
294 int guest_instance_id) { | 292 int guest_instance_id) { |
295 content::RenderProcessHost* host = | 293 auto host = content::RenderProcessHost::FromID(owner_process_id); |
296 content::RenderProcessHost::FromID(embedder_process_id); | |
297 if (!host) | 294 if (!host) |
298 return NULL; | 295 return NULL; |
299 | 296 |
300 content::WebContents* guest_web_contents = | 297 content::WebContents* guest_web_contents = |
301 GuestViewManager::FromBrowserContext(host->GetBrowserContext())-> | 298 GuestViewManager::FromBrowserContext(host->GetBrowserContext())-> |
302 GetGuestByInstanceIDSafely(guest_instance_id, embedder_process_id); | 299 GetGuestByInstanceIDSafely(guest_instance_id, owner_process_id); |
303 if (!guest_web_contents) | 300 if (!guest_web_contents) |
304 return NULL; | 301 return NULL; |
305 | 302 |
306 return GuestViewBase::FromWebContents(guest_web_contents); | 303 return GuestViewBase::FromWebContents(guest_web_contents); |
307 } | 304 } |
308 | 305 |
309 // static | 306 // static |
310 bool GuestViewBase::IsGuest(WebContents* web_contents) { | 307 bool GuestViewBase::IsGuest(WebContents* web_contents) { |
311 return !!GuestViewBase::FromWebContents(web_contents); | 308 return !!GuestViewBase::FromWebContents(web_contents); |
312 } | 309 } |
313 | 310 |
314 bool GuestViewBase::IsAutoSizeSupported() const { | 311 bool GuestViewBase::IsAutoSizeSupported() const { |
315 return false; | 312 return false; |
316 } | 313 } |
317 | 314 |
318 bool GuestViewBase::IsPreferredSizeModeEnabled() const { | 315 bool GuestViewBase::IsPreferredSizeModeEnabled() const { |
319 return false; | 316 return false; |
320 } | 317 } |
321 | 318 |
322 bool GuestViewBase::IsDragAndDropEnabled() const { | 319 bool GuestViewBase::IsDragAndDropEnabled() const { |
323 return false; | 320 return false; |
324 } | 321 } |
325 | 322 |
326 bool GuestViewBase::ZoomPropagatesFromEmbedderToGuest() const { | 323 bool GuestViewBase::ZoomPropagatesFromEmbedderToGuest() const { |
327 return true; | 324 return true; |
328 } | 325 } |
329 | 326 |
330 content::WebContents* GuestViewBase::CreateNewGuestWindow( | 327 content::WebContents* GuestViewBase::CreateNewGuestWindow( |
331 const content::WebContents::CreateParams& create_params) { | 328 const content::WebContents::CreateParams& create_params) { |
332 GuestViewManager* guest_manager = | 329 auto guest_manager = GuestViewManager::FromBrowserContext(browser_context()); |
333 GuestViewManager::FromBrowserContext(browser_context()); | |
334 return guest_manager->CreateGuestWithWebContentsParams( | 330 return guest_manager->CreateGuestWithWebContentsParams( |
335 GetViewType(), | 331 GetViewType(), |
336 owner_web_contents(), | 332 owner_web_contents(), |
337 create_params); | 333 create_params); |
338 } | 334 } |
339 | 335 |
340 void GuestViewBase::DidAttach(int guest_proxy_routing_id) { | 336 void GuestViewBase::DidAttach(int guest_proxy_routing_id) { |
341 opener_lifetime_observer_.reset(); | 337 opener_lifetime_observer_.reset(); |
342 | 338 |
343 SetUpAutoSize(*attach_params()); | 339 SetUpAutoSize(*attach_params()); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 // values. | 632 // values. |
637 SetAutoSize(auto_size_enabled, | 633 SetAutoSize(auto_size_enabled, |
638 gfx::Size(min_width, min_height), | 634 gfx::Size(min_width, min_height), |
639 gfx::Size(max_width, max_height)); | 635 gfx::Size(max_width, max_height)); |
640 } | 636 } |
641 | 637 |
642 void GuestViewBase::StartTrackingEmbedderZoomLevel() { | 638 void GuestViewBase::StartTrackingEmbedderZoomLevel() { |
643 if (!ZoomPropagatesFromEmbedderToGuest()) | 639 if (!ZoomPropagatesFromEmbedderToGuest()) |
644 return; | 640 return; |
645 | 641 |
646 ui_zoom::ZoomController* zoom_controller = | 642 auto embedder_zoom_controller = |
647 ui_zoom::ZoomController::FromWebContents(owner_web_contents()); | 643 ui_zoom::ZoomController::FromWebContents(owner_web_contents()); |
648 // Chrome Apps do not have a ZoomController. | 644 // Chrome Apps do not have a ZoomController. |
649 if (!zoom_controller) | 645 if (!embedder_zoom_controller) |
650 return; | 646 return; |
651 // Listen to the embedder's zoom changes. | 647 // Listen to the embedder's zoom changes. |
652 zoom_controller->AddObserver(this); | 648 embedder_zoom_controller->AddObserver(this); |
653 // Set the guest's initial zoom level to be equal to the embedder's. | 649 // Set the guest's initial zoom level to be equal to the embedder's. |
654 ui_zoom::ZoomController::FromWebContents(web_contents()) | 650 ui_zoom::ZoomController::FromWebContents(web_contents()) |
655 ->SetZoomLevel(zoom_controller->GetZoomLevel()); | 651 ->SetZoomLevel(embedder_zoom_controller->GetZoomLevel()); |
656 } | 652 } |
657 | 653 |
658 void GuestViewBase::StopTrackingEmbedderZoomLevel() { | 654 void GuestViewBase::StopTrackingEmbedderZoomLevel() { |
659 if (!attached() || !ZoomPropagatesFromEmbedderToGuest()) | 655 if (!attached() || !ZoomPropagatesFromEmbedderToGuest()) |
660 return; | 656 return; |
661 | 657 |
662 ui_zoom::ZoomController* zoom_controller = | 658 auto embedder_zoom_controller = |
663 ui_zoom::ZoomController::FromWebContents(owner_web_contents()); | 659 ui_zoom::ZoomController::FromWebContents(owner_web_contents()); |
664 if (!zoom_controller) | 660 // Chrome Apps do not have a ZoomController. |
| 661 if (!embedder_zoom_controller) |
665 return; | 662 return; |
666 zoom_controller->RemoveObserver(this); | 663 embedder_zoom_controller->RemoveObserver(this); |
667 } | 664 } |
668 | 665 |
669 // static | 666 // static |
670 void GuestViewBase::RegisterGuestViewTypes() { | 667 void GuestViewBase::RegisterGuestViewTypes() { |
671 AppViewGuest::Register(); | 668 AppViewGuest::Register(); |
672 ExtensionOptionsGuest::Register(); | 669 ExtensionOptionsGuest::Register(); |
673 MimeHandlerViewGuest::Register(); | 670 MimeHandlerViewGuest::Register(); |
674 SurfaceWorkerGuest::Register(); | 671 SurfaceWorkerGuest::Register(); |
675 WebViewGuest::Register(); | 672 WebViewGuest::Register(); |
676 } | 673 } |
677 | 674 |
678 } // namespace extensions | 675 } // namespace extensions |
OLD | NEW |