1 // Copyright 2015 The Chromium Embedded Framework Authors. 2 // Portions copyright 2014 The Chromium Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 6 #include "libcef/browser/extensions/mime_handler_view_guest_delegate.h" 7 8 #include "libcef/browser/alloy/alloy_browser_host_impl.h" 9 #include "libcef/browser/alloy/alloy_content_browser_client.h" 10 #include "libcef/browser/browser_context.h" 11 #include "libcef/browser/browser_info.h" 12 #include "libcef/browser/osr/web_contents_view_osr.h" 13 14 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h" 15 16 namespace extensions { 17 CefMimeHandlerViewGuestDelegate(MimeHandlerViewGuest * guest)18CefMimeHandlerViewGuestDelegate::CefMimeHandlerViewGuestDelegate( 19 MimeHandlerViewGuest* guest) 20 : guest_(guest), owner_web_contents_(guest_->owner_web_contents()) {} 21 ~CefMimeHandlerViewGuestDelegate()22CefMimeHandlerViewGuestDelegate::~CefMimeHandlerViewGuestDelegate() {} 23 OverrideWebContentsCreateParams(content::WebContents::CreateParams * params)24void CefMimeHandlerViewGuestDelegate::OverrideWebContentsCreateParams( 25 content::WebContents::CreateParams* params) { 26 DCHECK(params->guest_delegate); 27 28 CefRefPtr<AlloyBrowserHostImpl> owner_browser = 29 AlloyBrowserHostImpl::GetBrowserForContents(owner_web_contents_); 30 DCHECK(owner_browser); 31 32 if (owner_browser->IsWindowless()) { 33 CefWebContentsViewOSR* view_osr = new CefWebContentsViewOSR( 34 owner_browser->GetBackgroundColor(), false, false); 35 params->view = view_osr; 36 params->delegate_view = view_osr; 37 } 38 } 39 OnGuestAttached()40void CefMimeHandlerViewGuestDelegate::OnGuestAttached() { 41 content::WebContents* web_contents = guest_->web_contents(); 42 DCHECK(web_contents); 43 44 CefRefPtr<AlloyBrowserHostImpl> owner_browser = 45 AlloyBrowserHostImpl::GetBrowserForContents(owner_web_contents_); 46 DCHECK(owner_browser); 47 48 // Associate guest state information with the owner browser. 49 owner_browser->browser_info()->MaybeCreateFrame(web_contents->GetMainFrame(), 50 true /* is_guest_view */); 51 } 52 OnGuestDetached()53void CefMimeHandlerViewGuestDelegate::OnGuestDetached() { 54 content::WebContents* web_contents = guest_->web_contents(); 55 DCHECK(web_contents); 56 57 CefRefPtr<AlloyBrowserHostImpl> owner_browser = 58 AlloyBrowserHostImpl::GetBrowserForContents(owner_web_contents_); 59 DCHECK(owner_browser); 60 61 // Disassociate guest state information with the owner browser. 62 owner_browser->browser_info()->RemoveFrame(web_contents->GetMainFrame()); 63 } 64 HandleContextMenu(content::RenderFrameHost & render_frame_host,const content::ContextMenuParams & params)65bool CefMimeHandlerViewGuestDelegate::HandleContextMenu( 66 content::RenderFrameHost& render_frame_host, 67 const content::ContextMenuParams& params) { 68 CefRefPtr<AlloyBrowserHostImpl> owner_browser = 69 AlloyBrowserHostImpl::GetBrowserForContents(owner_web_contents_); 70 DCHECK(owner_browser); 71 72 return owner_browser->HandleContextMenu( 73 content::WebContents::FromRenderFrameHost(&render_frame_host), params); 74 } 75 76 } // namespace extensions 77