BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / views / chrome_javascript_native_dialog_factory_views.cc
blobe6ebf96c7d69e6eeeb57e0f41f131d22d9b4c927
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"
15 #else
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"
19 #endif
21 #if defined(USE_AURA)
22 #include "ui/aura/window.h"
23 #endif
25 namespace {
27 #if !defined(USE_X11) || defined(OS_CHROMEOS)
28 class ChromeJavaScriptAppModalDialogViews
29 : public app_modal::JavaScriptAppModalDialogViews {
30 public:
31 explicit ChromeJavaScriptAppModalDialogViews(
32 app_modal::JavaScriptAppModalDialog* parent)
33 : app_modal::JavaScriptAppModalDialogViews(parent),
34 helper_(new AppModalDialogHelper(parent->web_contents())) {}
35 ~ChromeJavaScriptAppModalDialogViews() override {}
37 private:
38 scoped_ptr<AppModalDialogHelper> helper_;
40 DISALLOW_COPY_AND_ASSIGN(ChromeJavaScriptAppModalDialogViews);
42 #endif
44 class ChromeJavaScriptNativeDialogViewsFactory
45 : public app_modal::JavaScriptNativeDialogFactory {
46 public:
47 ChromeJavaScriptNativeDialogViewsFactory() {}
48 ~ChromeJavaScriptNativeDialogViewsFactory() override {}
50 private:
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);
56 #else
57 d = new ChromeJavaScriptAppModalDialogViews(dialog);
58 #endif
60 dialog->web_contents()->GetDelegate()->ActivateContents(
61 dialog->web_contents());
62 gfx::NativeWindow parent_window =
63 dialog->web_contents()->GetTopLevelNativeWindow();
64 #if defined(USE_AURA)
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.
68 parent_window = NULL;
70 #endif
71 constrained_window::CreateBrowserModalDialogViews(d, parent_window);
72 return d;
75 DISALLOW_COPY_AND_ASSIGN(ChromeJavaScriptNativeDialogViewsFactory);
78 } // namespace
80 void InstallChromeJavaScriptNativeDialogFactory() {
81 app_modal::JavaScriptDialogManager::GetInstance()->
82 SetNativeDialogFactory(
83 make_scoped_ptr(new ChromeJavaScriptNativeDialogViewsFactory));