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/app_modal/chrome_javascript_native_dialog_factory.h"
7 #include "components/app_modal/javascript_dialog_manager.h"
8 #include "components/app_modal/javascript_native_dialog_factory.h"
9 #include "components/constrained_window/constrained_window_views.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/browser/web_contents_delegate.h"
13 #if defined(USE_X11) && !defined(OS_CHROMEOS)
14 #include "chrome/browser/ui/views/javascript_app_modal_dialog_views_x11.h"
16 #include "chrome/browser/ui/blocked_content/app_modal_dialog_helper.h"
17 #include "components/app_modal/javascript_app_modal_dialog.h"
18 #include "components/app_modal/views/javascript_app_modal_dialog_views.h"
22 #include "ui/aura/window.h"
27 #if !defined(USE_X11) || defined(OS_CHROMEOS)
28 class ChromeJavaScriptAppModalDialogViews
29 : public app_modal::JavaScriptAppModalDialogViews
{
31 explicit ChromeJavaScriptAppModalDialogViews(
32 app_modal::JavaScriptAppModalDialog
* parent
)
33 : app_modal::JavaScriptAppModalDialogViews(parent
),
34 helper_(new AppModalDialogHelper(parent
->web_contents())) {}
35 ~ChromeJavaScriptAppModalDialogViews() override
{}
38 scoped_ptr
<AppModalDialogHelper
> helper_
;
40 DISALLOW_COPY_AND_ASSIGN(ChromeJavaScriptAppModalDialogViews
);
44 class ChromeJavaScriptNativeDialogViewsFactory
45 : public app_modal::JavaScriptNativeDialogFactory
{
47 ChromeJavaScriptNativeDialogViewsFactory() {}
48 ~ChromeJavaScriptNativeDialogViewsFactory() override
{}
51 app_modal::NativeAppModalDialog
* CreateNativeJavaScriptDialog(
52 app_modal::JavaScriptAppModalDialog
* dialog
) override
{
53 app_modal::JavaScriptAppModalDialogViews
* d
= nullptr;
54 #if defined(USE_X11) && !defined(OS_CHROMEOS)
55 d
= new JavaScriptAppModalDialogViewsX11(dialog
);
57 d
= new ChromeJavaScriptAppModalDialogViews(dialog
);
60 dialog
->web_contents()->GetDelegate()->ActivateContents(
61 dialog
->web_contents());
62 gfx::NativeWindow parent_window
=
63 dialog
->web_contents()->GetTopLevelNativeWindow();
65 if (!parent_window
->GetRootWindow()) {
66 // When we are part of a WebContents that isn't actually being displayed
67 // on the screen, we can't actually attach to it.
71 constrained_window::CreateBrowserModalDialogViews(d
, parent_window
);
75 DISALLOW_COPY_AND_ASSIGN(ChromeJavaScriptNativeDialogViewsFactory
);
80 void InstallChromeJavaScriptNativeDialogFactory() {
81 app_modal::JavaScriptDialogManager::GetInstance()->
82 SetNativeDialogFactory(
83 make_scoped_ptr(new ChromeJavaScriptNativeDialogViewsFactory
));