Commit 7a659254 authored by patricialor's avatar patricialor Committed by Commit bot

Move web modal dialog manager files into the constrained_window component.

Currently, the CreateNativeWebModalManager() method declared inside the
web_modal component is defined outside of web_modal, which means linking it as a
shared component will fail. This is a layering violation.

This is now fixed for builds using Views, with constrained_window depending on
web_modal and web_modal providing definitions of all the symbols it declares.
Most unused implementations of CreateNativeWebModalManager() have been deleted,
with two remaining: create_native_web_modal_manager_cocoa.mm for Cocoa, and
test_create_native_web_modal_manager_cocoa.cc to prevent errors compiling
components_unittests, which isn't allowed to depend on the former file's
dependencies.

BUG=522654,492442

Review-Url: https://codereview.chromium.org/2087643003
Cr-Commit-Position: refs/heads/master@{#412730}
parent 30bce6e3
......@@ -8,6 +8,7 @@
#include "chrome/browser/chromeos/login/ui/captive_portal_view.h"
#include "chrome/browser/chromeos/login/ui/proxy_settings_dialog.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "components/constrained_window/constrained_window_views.h"
#include "components/web_modal/web_contents_modal_dialog_host.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
......@@ -81,7 +82,7 @@ void CaptivePortalWindowProxy::Show() {
manager->delegate()->GetWebContentsModalDialogHost()->GetHostView());
portal->Init();
widget_->AddObserver(this);
manager->ShowModalDialog(widget_->GetNativeView());
constrained_window::ShowModalDialog(widget_->GetNativeView(), web_contents_);
}
void CaptivePortalWindowProxy::Close() {
......
......@@ -16,7 +16,7 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "components/constrained_window/constrained_window_views.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
#include "ui/views/window/dialog_delegate.h"
......@@ -39,18 +39,10 @@ class WebContentsModalDialogManagerViewsMacTest : public InProcessBrowserTest,
DCHECK(web_contents);
// Toolkit-views dialogs would use constrained_window::
// ShowWebModalDialogViews(new TestDialog, web_contents), but the
// constrained_window component is not used in Cocoa code (disallowed via
// DEPS). It does basically the following anyway.
Widget* widget = views::DialogDelegate::CreateDialogWidget(
new TestDialog,
nullptr, [browser()->window()->GetNativeWindow() contentView]);
// Show a dialog as a constrained window modal to the current tab.
Widget* widget = constrained_window::ShowWebModalDialogViews(new TestDialog,
web_contents);
widget->AddObserver(this);
web_modal::WebContentsModalDialogManager* manager =
web_modal::WebContentsModalDialogManager::FromWebContents(web_contents);
manager->ShowModalDialog(widget->GetNativeWindow());
return widget;
}
......
......@@ -238,9 +238,8 @@ class ConstrainedWebDialogDelegateViewViews
}
void DocumentOnLoadCompletedInMainFrame() override {
if (!max_size_.IsEmpty() && initiator_observer_.web_contents()) {
web_modal::WebContentsModalDialogManager::FromWebContents(
initiator_observer_.web_contents())
->ShowModalDialog(GetWidget()->GetNativeWindow());
constrained_window::ShowModalDialog(GetWidget()->GetNativeWindow(),
initiator_observer_.web_contents());
}
}
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "chrome/browser/ui/views/native_web_contents_modal_dialog_manager_views.h"
#include "components/web_modal/single_web_contents_dialog_manager.h"
namespace web_modal {
SingleWebContentsDialogManager*
WebContentsModalDialogManager::CreateNativeWebModalManager(
gfx::NativeWindow dialog,
SingleWebContentsDialogManagerDelegate* native_delegate) {
return new NativeWebContentsModalDialogManagerViews(dialog, native_delegate);
}
} // namespace web_modal
......@@ -803,7 +803,7 @@
'browser/ui/webui/chromeos/emulator/device_emulator_ui.cc',
'browser/ui/webui/chromeos/emulator/device_emulator_ui.h',
],
# Mac sources, except when mac_views_browser==1
# Mac sources, except when mac_views_browser==1.
'chrome_browser_ui_cocoa_sources': [
'browser/ui/cocoa/animatable_image.h',
'browser/ui/cocoa/animatable_image.mm',
......@@ -2432,8 +2432,6 @@
'browser/ui/views/location_bar/zoom_bubble_view.h',
'browser/ui/views/location_bar/zoom_view.cc',
'browser/ui/views/location_bar/zoom_view.h',
'browser/ui/views/native_web_contents_modal_dialog_manager_views.cc',
'browser/ui/views/native_web_contents_modal_dialog_manager_views.h',
'browser/ui/views/omnibox/omnibox_popup_contents_view.cc',
'browser/ui/views/omnibox/omnibox_popup_contents_view.h',
'browser/ui/views/omnibox/omnibox_result_view.cc',
......@@ -2551,7 +2549,6 @@
'browser/ui/views/update_recommended_message_box.h',
'browser/ui/views/validation_message_bubble_view.cc',
'browser/ui/views/validation_message_bubble_view.h',
'browser/ui/views/web_contents_modal_dialog_manager_views.cc',
'browser/ui/views/website_settings/chooser_bubble_ui_view.cc',
'browser/ui/views/website_settings/chooser_bubble_ui_view.h',
'browser/ui/views/website_settings/permission_prompt_impl_views.cc',
......
......@@ -2,19 +2,40 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/ui.gni")
static_library("constrained_window") {
sources = [
"constrained_window_views.cc",
"constrained_window_views.h",
"constrained_window_views_client.h",
"native_web_contents_modal_dialog_manager_views.cc",
"native_web_contents_modal_dialog_manager_views.h",
]
if (is_mac && !mac_views_browser) {
sources += [ "show_modal_dialog_cocoa.cc" ]
} else {
sources += [ "show_modal_dialog_views.cc" ]
}
deps = [
"//components/guest_view/browser",
"//components/web_modal",
"//skia",
"//content/public/browser",
"//ui/views",
]
public_deps = [
# Skia headers are exposed in the public API.
"//skia",
]
if (use_aura) {
deps += [
"//ui/aura",
"//ui/wm",
]
}
}
source_set("unit_tests") {
......@@ -23,6 +44,10 @@ source_set("unit_tests") {
"constrained_window_views_unittest.cc",
]
if (is_mac && !mac_views_browser) {
sources += [ "test_create_native_web_modal_manager_cocoa.cc" ]
}
deps = [
":constrained_window",
"//components/web_modal:test_support",
......
include_rules = [
"+components/guest_view",
"+components/web_modal",
"+content/public/browser",
"+ui/aura",
"+ui/base",
"+ui/gfx",
"+ui/views",
"+ui/wm",
]
......@@ -141,8 +141,7 @@ views::Widget* ShowWebModalDialogViews(
content::WebContents* web_contents =
guest_view::GuestViewBase::GetTopLevelWebContents(initiator_web_contents);
views::Widget* widget = CreateWebModalDialogViews(dialog, web_contents);
web_modal::WebContentsModalDialogManager::FromWebContents(web_contents)
->ShowModalDialog(widget->GetNativeWindow());
ShowModalDialog(widget->GetNativeWindow(), web_contents);
return widget;
}
......
......@@ -42,6 +42,11 @@ void UpdateWidgetModalDialogPosition(
views::Widget* widget,
web_modal::ModalDialogHost* dialog_host);
// Shows the dialog with a new SingleWebContentsDialogManager. The dialog will
// notify via WillClose() when it is being destroyed.
void ShowModalDialog(gfx::NativeWindow dialog,
content::WebContents* web_contents);
// Calls CreateWebModalDialogViews, shows the dialog, and returns its widget.
views::Widget* ShowWebModalDialogViews(
views::WidgetDelegate* dialog,
......@@ -59,6 +64,6 @@ views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog,
views::Widget* CreateBrowserModalDialogViews(views::DialogDelegate* dialog,
gfx::NativeWindow parent);
} // namespace constrained window
} // namespace constrained_window
#endif // COMPONENTS_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_VIEWS_H_
......@@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/native_web_contents_modal_dialog_manager_views.h"
#include "components/constrained_window/native_web_contents_modal_dialog_manager_views.h"
#include <memory>
#include "chrome/browser/platform_util.h"
#include "components/constrained_window/constrained_window_views.h"
#include "components/web_modal/web_contents_modal_dialog_host.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
......@@ -31,6 +30,8 @@ using web_modal::SingleWebContentsDialogManagerDelegate;
using web_modal::WebContentsModalDialogHost;
using web_modal::ModalDialogHostObserver;
namespace constrained_window {
NativeWebContentsModalDialogManagerViews::
NativeWebContentsModalDialogManagerViews(
gfx::NativeWindow dialog,
......@@ -67,7 +68,7 @@ void NativeWebContentsModalDialogManagerViews::ManageDialog() {
wm::SetWindowVisibilityAnimationType(
widget->GetNativeWindow(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_ROTATE);
gfx::NativeView parent = platform_util::GetParent(widget->GetNativeView());
gfx::NativeView parent = widget->GetNativeView()->parent();
wm::SetChildWindowVisibilityChangesAnimated(parent);
// No animations should get performed on the window since that will re-order
// the window stack which will then cause many problems.
......@@ -203,7 +204,7 @@ views::Widget* NativeWebContentsModalDialogManagerViews::GetWidget(
void NativeWebContentsModalDialogManagerViews::WidgetClosing(
views::Widget* widget) {
#if defined(USE_AURA)
gfx::NativeView view = platform_util::GetParent(widget->GetNativeView());
gfx::NativeView view = widget->GetNativeView()->parent();
// Allow the parent to animate again.
if (view && view->parent())
view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey);
......@@ -218,3 +219,5 @@ void NativeWebContentsModalDialogManagerViews::WidgetClosing(
// Will cause this object to be deleted.
native_delegate_->WillClose(widget->GetNativeWindow());
}
} // namespace constrained_window
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_VIEWS_H_
#define CHROME_BROWSER_UI_VIEWS_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_VIEWS_H_
#ifndef COMPONENTS_CONSTRAINED_WINDOW_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_VIEWS_H_
#define COMPONENTS_CONSTRAINED_WINDOW_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_VIEWS_H_
#include <set>
......@@ -17,6 +17,8 @@ namespace views {
class Widget;
}
namespace constrained_window {
// Class for parenting a tab-modal views dialog off of a views browser.
class NativeWebContentsModalDialogManagerViews
: public web_modal::SingleWebContentsDialogManager,
......@@ -73,4 +75,6 @@ class NativeWebContentsModalDialogManagerViews
DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViews);
};
#endif // CHROME_BROWSER_UI_VIEWS_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_VIEWS_H_
} // namespace constrained_window
#endif // COMPONENTS_CONSTRAINED_WINDOW_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_VIEWS_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "components/constrained_window/constrained_window_views.h"
#include "components/web_modal/single_web_contents_dialog_manager.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/web_contents.h"
#include "ui/gfx/native_widget_types.h"
// TODO(patricialor): This is a layering violation and should be deleted.
// Currently it's needed because on Cocoa, the dialog needs to be shown with a
// SingleWebContentsDialogManagerViewsMac, which depends on things inside
// chrome/browser/ui/cocoa/constrained_window/* and thus can't be moved out into
// components/constrained_window/*. Instead, to get this to work, the
// CreateNativeWebModalManager() method is declared in the web_modal component,
// but defined outside of that in c/b/u/cocoa/.
namespace constrained_window {
void ShowModalDialog(gfx::NativeWindow dialog,
content::WebContents* initiator_web_contents) {
web_modal::WebContentsModalDialogManager* manager =
web_modal::WebContentsModalDialogManager::FromWebContents(
initiator_web_contents);
std::unique_ptr<web_modal::SingleWebContentsDialogManager> dialog_manager(
web_modal::WebContentsModalDialogManager::CreateNativeWebModalManager(
dialog, manager));
manager->ShowDialogWithManager(dialog, std::move(dialog_manager));
}
} // namespace constrained_window
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "components/constrained_window/constrained_window_views.h"
#include "components/constrained_window/native_web_contents_modal_dialog_manager_views.h"
#include "components/web_modal/single_web_contents_dialog_manager.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/web_contents.h"
#include "ui/gfx/native_widget_types.h"
namespace constrained_window {
void ShowModalDialog(gfx::NativeWindow dialog,
content::WebContents* web_contents) {
web_modal::WebContentsModalDialogManager* manager =
web_modal::WebContentsModalDialogManager::FromWebContents(web_contents);
DCHECK(manager);
std::unique_ptr<web_modal::SingleWebContentsDialogManager> dialog_manager(
new constrained_window::NativeWebContentsModalDialogManagerViews(
dialog, manager));
manager->ShowDialogWithManager(dialog, std::move(dialog_manager));
}
} // namespace constrained_window
// Copyright 2014 The Chromium Authors. All rights reserved.
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -9,10 +9,8 @@ namespace web_modal {
SingleWebContentsDialogManager*
WebContentsModalDialogManager::CreateNativeWebModalManager(
gfx::NativeWindow dialog,
SingleWebContentsDialogManagerDelegate* native_delegate) {
// TODO(oshima): Investigate if we need to implement this.
NOTREACHED();
return NULL;
web_modal::SingleWebContentsDialogManagerDelegate* delegate) {
return nullptr;
}
} // namespace web_modal
......@@ -35,12 +35,6 @@ void WebContentsModalDialogManager::SetDelegate(
}
}
void WebContentsModalDialogManager::ShowModalDialog(gfx::NativeWindow dialog) {
std::unique_ptr<SingleWebContentsDialogManager> mgr(
CreateNativeWebModalManager(dialog, this));
ShowDialogWithManager(dialog, std::move(mgr));
}
// TODO(gbillock): Maybe "ShowBubbleWithManager"?
void WebContentsModalDialogManager::ShowDialogWithManager(
gfx::NativeWindow dialog,
......
......@@ -9,6 +9,7 @@
#include <memory>
#include "base/macros.h"
#include "build/build_config.h"
#include "components/web_modal/single_web_contents_dialog_manager.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
......@@ -29,13 +30,13 @@ class WebContentsModalDialogManager
WebContentsModalDialogManagerDelegate* delegate() const { return delegate_; }
void SetDelegate(WebContentsModalDialogManagerDelegate* d);
#if defined(OS_MACOSX)
// Note: This method is not defined inside components/web_modal/ as its
// definition (needed for Cocoa builds) depends on chrome/browser/ui/cocoa/.
static SingleWebContentsDialogManager* CreateNativeWebModalManager(
gfx::NativeWindow dialog,
SingleWebContentsDialogManagerDelegate* native_delegate);
// Shows the dialog as a web contents modal dialog. The dialog will notify via
// WillClose() when it is being destroyed.
void ShowModalDialog(gfx::NativeWindow dialog);
#endif
// Allow clients to supply their own native dialog manager. Suitable for
// bubble clients.
......
......@@ -123,17 +123,6 @@ class WebContentsModalDialogManagerTest
DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogManagerTest);
};
SingleWebContentsDialogManager*
WebContentsModalDialogManager::CreateNativeWebModalManager(
gfx::NativeWindow dialog,
SingleWebContentsDialogManagerDelegate* native_delegate) {
NOTREACHED();
return new TestNativeWebContentsModalDialogManager(
dialog,
native_delegate,
&unused_tracker);
}
// Test that the dialog is shown immediately when the delegate indicates the web
// contents is visible.
TEST_F(WebContentsModalDialogManagerTest, WebContentsVisible) {
......
......@@ -169,7 +169,6 @@
'renderer/script_context_set_unittest.cc',
'renderer/script_context_unittest.cc',
'renderer/utils_unittest.cc',
'shell/browser/shell_web_contents_modal_dialog_manager.cc',
'test/extensions_unittests_main.cc',
'utility/unpacker_unittest.cc',
],
......
......@@ -79,7 +79,6 @@
'browser/shell_update_query_params_delegate.h',
'browser/shell_url_request_context_getter.cc',
'browser/shell_url_request_context_getter.h',
'browser/shell_web_contents_modal_dialog_manager.cc',
'common/shell_content_client.cc',
'common/shell_content_client.h',
'common/shell_extensions_client.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment