Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: chrome/browser/chromeos/login/ui/captive_portal_window_proxy.cc

Issue 319013002: Reland Fix Views web-modal dialog widget creation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revert MediaGalleriesScanResultDialogViews::AcceptDialogForTesting. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/chromeos/login/ui/captive_portal_window_proxy.h" 5 #include "chrome/browser/chromeos/login/ui/captive_portal_window_proxy.h"
6 6
7 #include "chrome/browser/chromeos/login/ui/captive_portal_view.h" 7 #include "chrome/browser/chromeos/login/ui/captive_portal_view.h"
8 #include "chrome/browser/chromeos/login/ui/proxy_settings_dialog.h" 8 #include "chrome/browser/chromeos/login/ui/proxy_settings_dialog.h"
9 #include "chrome/browser/chromeos/profiles/profile_helper.h" 9 #include "chrome/browser/chromeos/profiles/profile_helper.h"
10 #include "components/web_modal/web_contents_modal_dialog_host.h" 10 #include "components/web_modal/web_contents_modal_dialog_host.h"
11 #include "components/web_modal/web_contents_modal_dialog_manager.h" 11 #include "components/web_modal/web_contents_modal_dialog_manager.h"
12 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" 12 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
13 #include "ui/views/widget/widget.h" 13 #include "ui/views/widget/widget.h"
14 14
15 using web_modal::WebContentsModalDialogManager; 15 namespace {
16 using web_modal::WebContentsModalDialogManagerDelegate; 16 // The captive portal dialog is system-modal, but uses the web-content-modal
17 // dialog manager (odd) and requires this atypical dialog widget initialization.
18 views::Widget* CreateWindowAsFramelessChild(views::WidgetDelegate* delegate,
19 gfx::NativeView parent) {
20 views::Widget* widget = new views::Widget;
21
22 views::Widget::InitParams params;
23 params.delegate = delegate;
24 params.child = true;
25 params.parent = parent;
26 params.remove_standard_frame = true;
27 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
28
29 widget->Init(params);
30 return widget;
31 }
32
33 } // namespace
17 34
18 namespace chromeos { 35 namespace chromeos {
19 36
20 CaptivePortalWindowProxy::CaptivePortalWindowProxy( 37 CaptivePortalWindowProxy::CaptivePortalWindowProxy(
21 Delegate* delegate, 38 Delegate* delegate,
22 content::WebContents* web_contents) 39 content::WebContents* web_contents)
23 : delegate_(delegate), 40 : delegate_(delegate),
24 widget_(NULL), 41 widget_(NULL),
25 web_contents_(web_contents), 42 web_contents_(web_contents),
26 captive_portal_view_for_testing_(NULL) { 43 captive_portal_view_for_testing_(NULL) {
(...skipping 20 matching lines...) Expand all
47 // ProxySettingsDialog is being shown, don't cover it. 64 // ProxySettingsDialog is being shown, don't cover it.
48 Close(); 65 Close();
49 return; 66 return;
50 } 67 }
51 68
52 if (GetState() == STATE_DISPLAYED) // Dialog is already shown, do nothing. 69 if (GetState() == STATE_DISPLAYED) // Dialog is already shown, do nothing.
53 return; 70 return;
54 71
55 InitCaptivePortalView(); 72 InitCaptivePortalView();
56 73
57 CaptivePortalView* captive_portal_view = captive_portal_view_.release(); 74 CaptivePortalView* portal = captive_portal_view_.release();
58 WebContentsModalDialogManager* web_contents_modal_dialog_manager = 75 web_modal::WebContentsModalDialogManager* manager =
59 WebContentsModalDialogManager::FromWebContents(web_contents_); 76 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents_);
60 DCHECK(web_contents_modal_dialog_manager); 77 const gfx::NativeWindow parent =
61 WebContentsModalDialogManagerDelegate* delegate = 78 manager->delegate()->GetWebContentsModalDialogHost()->GetHostView();
62 web_contents_modal_dialog_manager->delegate(); 79 widget_ = CreateWindowAsFramelessChild(portal, parent);
63 DCHECK(delegate); 80 portal->Init();
64 widget_ = views::Widget::CreateWindowAsFramelessChild(
65 captive_portal_view,
66 delegate->GetWebContentsModalDialogHost()->GetHostView());
67 captive_portal_view->Init();
68 81
69 widget_->AddObserver(this); 82 widget_->AddObserver(this);
70 web_contents_modal_dialog_manager->ShowModalDialog( 83 manager->ShowModalDialog(widget_->GetNativeView());
71 widget_->GetNativeView());
72 DCHECK(GetState() == STATE_DISPLAYED); 84 DCHECK(GetState() == STATE_DISPLAYED);
73 } 85 }
74 86
75 void CaptivePortalWindowProxy::Close() { 87 void CaptivePortalWindowProxy::Close() {
76 if (GetState() == STATE_DISPLAYED) 88 if (GetState() == STATE_DISPLAYED)
77 widget_->Close(); 89 widget_->Close();
78 captive_portal_view_.reset(); 90 captive_portal_view_.reset();
79 captive_portal_view_for_testing_ = NULL; 91 captive_portal_view_for_testing_ = NULL;
80 } 92 }
81 93
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 145 }
134 146
135 void CaptivePortalWindowProxy::DetachFromWidget(views::Widget* widget) { 147 void CaptivePortalWindowProxy::DetachFromWidget(views::Widget* widget) {
136 if (!widget_ || widget_ != widget) 148 if (!widget_ || widget_ != widget)
137 return; 149 return;
138 widget_->RemoveObserver(this); 150 widget_->RemoveObserver(this);
139 widget_ = NULL; 151 widget_ = NULL;
140 } 152 }
141 153
142 } // namespace chromeos 154 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698