Commit f44dbc17 authored by jamescook's avatar jamescook Committed by Commit bot

chromeos: Make network enrollment and SIM unlock dialogs work with mash

Chrome running in mash cannot directly access the ash aura window hierarchy.
Instead it must pass an ash window container id when a new window is being
opened.

* Convert dialogs to use container id when no explicit parent is available
* Remove ash dependencies from NetworkConnectDelegateChromeos, including
GetNativeWindow()
* Add DEPS to restrict access to ash from chrome/browser/chromeos/net

Also do some cleanup:
* Add class comments for captive portal and HaTS dialogs, which I audited.
They do not need to be fixed for mash because they are always displayed in the
default container.
* Fix include-what-you-use.

BUG=657021
TEST=chrome browser_tests

Review-Url: https://codereview.chromium.org/2452283003
Cr-Commit-Position: refs/heads/master@{#428569}
parent 67fe9b92
......@@ -5,11 +5,13 @@
#include "chrome/browser/chromeos/enrollment_dialog_view.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/system_tray_client.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_params.h"
......@@ -103,7 +105,12 @@ void EnrollmentDialogView::ShowDialog(gfx::NativeWindow owning_window,
const base::Closure& connect) {
EnrollmentDialogView* dialog_view =
new EnrollmentDialogView(network_name, profile, target_uri, connect);
views::DialogDelegate::CreateDialogWidget(dialog_view, NULL, owning_window);
if (owning_window) {
views::DialogDelegate::CreateDialogWidget(dialog_view, nullptr,
owning_window);
} else {
SystemTrayClient::CreateUnownedDialogWidget(dialog_view);
}
dialog_view->InitDialog();
views::Widget* widget = dialog_view->GetWidget();
DCHECK(widget);
......
......@@ -6,17 +6,16 @@
#define CHROME_BROWSER_CHROMEOS_ENROLLMENT_DIALOG_VIEW_H_
#include <string>
#include <vector>
#include "base/callback_forward.h"
#include "ui/gfx/native_widget_types.h"
class Profile;
namespace chromeos {
namespace enrollment {
// Returns true if a dialog was successfully created.
// Creates and shows the dialog for certificate-based network enrollment. If the
// |owning_window| is null the dialog is placed in the appropriate modal dialog
// dialog container on the primary display. Returns true if a dialog was
// successfully created.
bool CreateEnrollmentDialog(const std::string& network_id,
gfx::NativeWindow owning_window);
......
// Copyright (c) 2016 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.
......@@ -7,14 +7,13 @@
#include <string>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/values.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/web_dialogs/web_dialog_delegate.h"
namespace chromeos {
// Happiness tracking survey dialog. Sometimes appears after login to ask the
// user how satisfied they are with their Chromebook.
class HatsDialog : public ui::WebDialogDelegate {
public:
HatsDialog();
......
include_rules = [
# Chrome under mustash cannot call directly into ash internals.
"-ash",
"+ash/public",
"+components/captive_portal",
]
specific_include_rules = {
# TODO(jamescook): Eliminate these.
"network_portal_notification_controller\.cc": [
"+ash/common/system/system_notifier.h",
"+ash/common/system/tray/system_tray_notifier.h",
"+ash/common/wm_shell.h",
],
"network_state_notifier\.cc": [
"+ash/common/system/system_notifier.h",
"+ash/resources/grit/ash_resources.h",
],
}
......@@ -4,32 +4,25 @@
#include "chrome/browser/chromeos/net/network_connect_delegate_chromeos.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/wm_shell.h"
#include "ash/shell.h"
#include "chrome/browser/chromeos/enrollment_dialog_view.h"
#include "chrome/browser/chromeos/login/lock/screen_locker.h"
#include "chrome/browser/chromeos/net/network_state_notifier.h"
#include "chrome/browser/chromeos/sim_dialog_delegate.h"
#include "chrome/browser/ui/ash/system_tray_client.h"
#include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h"
namespace chromeos {
namespace {
bool IsUIAvailable() {
return ash::WmShell::HasInstance() &&
!ash::WmShell::Get()->GetSessionStateDelegate()->IsScreenLocked();
}
gfx::NativeWindow GetNativeWindow() {
int container_id = SystemTrayClient::GetDialogParentContainerId();
return ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(),
container_id);
// UI is available when screen is unlocked.
return !ScreenLocker::default_screen_locker() ||
!ScreenLocker::default_screen_locker()->locked();
}
} // namespace
namespace chromeos {
NetworkConnectDelegateChromeOS::NetworkConnectDelegateChromeOS()
: network_state_notifier_(new NetworkStateNotifier()) {}
......@@ -53,13 +46,14 @@ bool NetworkConnectDelegateChromeOS::ShowEnrollNetwork(
const std::string& network_id) {
if (!IsUIAvailable())
return false;
return enrollment::CreateEnrollmentDialog(network_id, GetNativeWindow());
return enrollment::CreateEnrollmentDialog(network_id,
nullptr /* owning_window */);
}
void NetworkConnectDelegateChromeOS::ShowMobileSimDialog() {
if (!IsUIAvailable())
return;
SimDialogDelegate::ShowDialog(GetNativeWindow(),
SimDialogDelegate::ShowDialog(nullptr /* owning_window */,
SimDialogDelegate::SIM_DIALOG_UNLOCK);
}
......
......@@ -24,6 +24,8 @@ class NetworkState;
class NetworkPortalWebDialog;
class NetworkPortalNotificationControllerTest;
// Shows a message center notification when the networking stack detects a
// captive portal.
class NetworkPortalNotificationController
: public NetworkStateHandlerObserver,
public NetworkPortalDetector::Observer {
......
......@@ -6,6 +6,7 @@
#include "base/strings/stringprintf.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/system_tray_client.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/common/url_constants.h"
#include "ui/gfx/geometry/size.h"
......@@ -35,9 +36,14 @@ namespace chromeos {
// static
void SimDialogDelegate::ShowDialog(gfx::NativeWindow owning_window,
SimDialogMode mode) {
chrome::ShowWebDialog(owning_window,
ProfileManager::GetActiveUserProfile(),
new SimDialogDelegate(mode));
Profile* profile = ProfileManager::GetActiveUserProfile();
if (owning_window) {
chrome::ShowWebDialog(owning_window, profile, new SimDialogDelegate(mode));
} else {
chrome::ShowWebDialogInContainer(
SystemTrayClient::GetDialogParentContainerId(), profile,
new SimDialogDelegate(mode));
}
}
SimDialogDelegate::SimDialogDelegate(SimDialogMode dialog_mode)
......
......@@ -5,7 +5,6 @@
#ifndef CHROME_BROWSER_CHROMEOS_SIM_DIALOG_DELEGATE_H_
#define CHROME_BROWSER_CHROMEOS_SIM_DIALOG_DELEGATE_H_
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/web_dialogs/web_dialog_delegate.h"
......@@ -25,7 +24,9 @@ class SimDialogDelegate : public ui::WebDialogDelegate {
explicit SimDialogDelegate(SimDialogMode dialog_mode);
// Shows the SIM unlock dialog box with one of the specified modes.
// Shows the SIM unlock dialog box with one of the specified modes. If the
// |owning_window| is null the dialog is placed in the appropriate modal
// dialog container on the primary display.
static void ShowDialog(gfx::NativeWindow owning_window, SimDialogMode mode);
private:
......
......@@ -8,6 +8,7 @@
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/wm_shell.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/shell.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/logging.h"
......@@ -32,10 +33,15 @@
#include "content/public/common/service_manager_connection.h"
#include "net/base/escape.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/ui/public/cpp/property_type_converters.h"
#include "services/ui/public/interfaces/window_manager.mojom.h"
#include "third_party/cros_system_api/dbus/shill/dbus-constants.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"
using chromeos::DBusThreadManager;
using chromeos::LoginState;
using views::Widget;
namespace {
......@@ -129,6 +135,28 @@ int SystemTrayClient::GetDialogParentContainerId() {
return ash::kShellWindowId_SystemModalContainer;
}
// static
Widget* SystemTrayClient::CreateUnownedDialogWidget(
views::WidgetDelegate* widget_delegate) {
DCHECK(widget_delegate);
Widget::InitParams params = views::DialogDelegate::GetDialogWidgetInitParams(
widget_delegate, nullptr, nullptr, gfx::Rect());
// Place the dialog in the appropriate modal dialog container, either above
// or below the lock screen, based on the login state.
int container_id = GetDialogParentContainerId();
if (chrome::IsRunningInMash()) {
using ui::mojom::WindowManager;
params.mus_properties[WindowManager::kInitialContainerId_Property] =
mojo::ConvertTo<std::vector<uint8_t>>(container_id);
} else {
params.parent = ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(),
container_id);
}
Widget* widget = new Widget; // Owned by native widget.
widget->Init(params);
return widget;
}
////////////////////////////////////////////////////////////////////////////////
// ash::mojom::SystemTrayClient:
......
......@@ -14,6 +14,11 @@ namespace ash {
enum class LoginStatus;
}
namespace views {
class Widget;
class WidgetDelegate;
}
// Handles method calls delegated back to chrome from ash. Also notifies ash of
// relevant state changes in chrome.
// TODO: Consider renaming this to SystemTrayClientChromeOS.
......@@ -32,6 +37,12 @@ class SystemTrayClient : public ash::mojom::SystemTrayClient,
// varies based on the current login and lock screen state.
static int GetDialogParentContainerId();
// Creates a modal dialog in the parent window for new dialogs on the primary
// display. See GetDialogParentContainerId() and views::CreateDialogWidget().
// The returned widget is owned by its native widget.
static views::Widget* CreateUnownedDialogWidget(
views::WidgetDelegate* widget_delegate);
// ash::mojom::SystemTrayClient:
void ShowSettings() override;
void ShowDateSettings() override;
......
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