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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/chrome_constrained_window_views_client.h"
7 #include "chrome/browser/platform_util.h"
8 #include "chrome/browser/ui/browser_finder.h"
9 #include "components/web_modal/web_contents_modal_dialog_host.h"
10 #include "extensions/browser/guest_view/guest_view_base.h"
14 class ChromeConstrainedWindowViewsClient
15 : public constrained_window::ConstrainedWindowViewsClient
{
17 ChromeConstrainedWindowViewsClient() {}
18 ~ChromeConstrainedWindowViewsClient() override
{}
21 // ConstrainedWindowViewsClient:
22 content::WebContents
* GetEmbedderWebContents(
23 content::WebContents
* initiator_web_contents
) override
{
24 // |initiator_web_contents| may be embedded within a chain of nested
25 // GuestViews. If it is, follow the chain of embedders to the outermost
26 // WebContents and return it.
27 while (extensions::GuestViewBase
* guest_view
=
28 extensions::GuestViewBase::FromWebContents(
29 initiator_web_contents
)) {
30 if (!guest_view
->embedder_web_contents())
32 initiator_web_contents
= guest_view
->embedder_web_contents();
34 return initiator_web_contents
;
36 web_modal::ModalDialogHost
* GetModalDialogHost(
37 gfx::NativeWindow parent
) override
{
38 // Get the browser dialog management and hosting components from |parent|.
39 Browser
* browser
= chrome::FindBrowserWithWindow(parent
);
41 ChromeWebModalDialogManagerDelegate
* manager
= browser
;
42 return manager
->GetWebContentsModalDialogHost();
46 gfx::NativeView
GetDialogHostView(gfx::NativeWindow parent
) override
{
47 return platform_util::GetViewForWindow(parent
);
50 DISALLOW_COPY_AND_ASSIGN(ChromeConstrainedWindowViewsClient
);
55 scoped_ptr
<constrained_window::ConstrainedWindowViewsClient
>
56 CreateChromeConstrainedWindowViewsClient() {
57 return make_scoped_ptr(new ChromeConstrainedWindowViewsClient
);