| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 5 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
| 6 #include "chrome/browser/ui/browser_dialogs.h" | 6 #include "chrome/browser/ui/browser_dialogs.h" |
| 7 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" | 7 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" |
| 8 #include "ui/views/controls/webview/web_dialog_view.h" | 8 #include "ui/views/controls/webview/web_dialog_view.h" |
| 9 #include "ui/views/widget/widget.h" | 9 #include "ui/views/widget/widget.h" |
| 10 | 10 |
| 11 #if defined(USE_ASH) |
| 12 #include "ash/public/cpp/shell_window_ids.h" // nogncheck |
| 13 #include "ash/shell.h" // nogncheck |
| 14 #include "chrome/browser/ui/ash/ash_util.h" |
| 15 #include "services/ui/public/cpp/property_type_converters.h" |
| 16 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 17 #include "ui/aura/mus/mus_util.h" |
| 18 #endif // defined(USE_ASH) |
| 19 |
| 11 namespace chrome { | 20 namespace chrome { |
| 21 namespace { |
| 22 |
| 23 gfx::NativeWindow ShowWebDialogWidget(const views::Widget::InitParams& params, |
| 24 views::WebDialogView* view) { |
| 25 views::Widget* widget = new views::Widget; |
| 26 widget->Init(params); |
| 27 |
| 28 // Observer is needed for ChromeVox extension to send messages between content |
| 29 // and background scripts. |
| 30 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
| 31 view->web_contents()); |
| 32 |
| 33 widget->Show(); |
| 34 return widget->GetNativeWindow(); |
| 35 } |
| 36 |
| 37 } // namespace |
| 12 | 38 |
| 13 // Declared in browser_dialogs.h so that others don't need to depend on our .h. | 39 // Declared in browser_dialogs.h so that others don't need to depend on our .h. |
| 14 gfx::NativeWindow ShowWebDialog(gfx::NativeView parent, | 40 gfx::NativeWindow ShowWebDialog(gfx::NativeView parent, |
| 15 content::BrowserContext* context, | 41 content::BrowserContext* context, |
| 16 ui::WebDialogDelegate* delegate) { | 42 ui::WebDialogDelegate* delegate) { |
| 17 views::WebDialogView* view = | 43 views::WebDialogView* view = |
| 18 new views::WebDialogView(context, delegate, new ChromeWebContentsHandler); | 44 new views::WebDialogView(context, delegate, new ChromeWebContentsHandler); |
| 45 views::Widget::InitParams params; |
| 46 params.delegate = view; |
| 19 // NOTE: The |parent| may be null, which will result in the default window | 47 // NOTE: The |parent| may be null, which will result in the default window |
| 20 // placement on Aura. | 48 // placement on Aura. |
| 21 views::Widget* widget = views::Widget::CreateWindowWithParent(view, parent); | 49 params.parent = parent; |
| 22 | 50 #if defined(USE_ASH) |
| 23 // Observer is needed for ChromeVox extension to send messages between content | 51 if (chrome::IsRunningInMash()) |
| 24 // and background scripts. | 52 params.parent_mus = aura::GetMusWindow(parent); |
| 25 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 53 #endif // defined(USE_ASH) |
| 26 view->web_contents()); | 54 return ShowWebDialogWidget(params, view); |
| 27 | |
| 28 widget->Show(); | |
| 29 return widget->GetNativeWindow(); | |
| 30 } | 55 } |
| 31 | 56 |
| 57 #if defined(USE_ASH) |
| 58 void ShowWebDialogInContainer(int container_id, |
| 59 content::BrowserContext* context, |
| 60 ui::WebDialogDelegate* delegate) { |
| 61 DCHECK(container_id != ash::kShellWindowId_Invalid); |
| 62 views::WebDialogView* view = |
| 63 new views::WebDialogView(context, delegate, new ChromeWebContentsHandler); |
| 64 views::Widget::InitParams params; |
| 65 params.delegate = view; |
| 66 if (chrome::IsRunningInMash()) { |
| 67 using ui::mojom::WindowManager; |
| 68 params.mus_properties[WindowManager::kInitialContainerId_Property] = |
| 69 mojo::ConvertTo<std::vector<uint8_t>>(container_id); |
| 70 } else { |
| 71 params.parent = ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(), |
| 72 container_id); |
| 73 } |
| 74 ShowWebDialogWidget(params, view); |
| 75 } |
| 76 #endif // defined(USE_ASH) |
| 77 |
| 32 } // namespace chrome | 78 } // namespace chrome |
| OLD | NEW |