blob: d81e9151886321a23112e89c09e2d25b5d0194a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
// 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 "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h"
#include "base/bind.h"
#include "base/memory/singleton.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
#include "chrome/browser/chromeos/login/ui/webui_login_view.h"
#include "chrome/browser/chromeos/mobile/mobile_activator.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/simple_message_box.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/browser_thread.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/widget/widget.h"
#include "ui/web_dialogs/web_dialog_delegate.h"
using chromeos::MobileActivator;
using content::BrowserThread;
using content::WebContents;
using content::WebUIMessageHandler;
using ui::WebDialogDelegate;
class MobileSetupDialogDelegate : public WebDialogDelegate {
public:
static MobileSetupDialogDelegate* GetInstance();
void ShowDialog(const std::string& service_path);
protected:
friend struct DefaultSingletonTraits<MobileSetupDialogDelegate>;
MobileSetupDialogDelegate();
virtual ~MobileSetupDialogDelegate();
void OnCloseDialog();
// WebDialogDelegate overrides.
virtual ui::ModalType GetDialogModalType() const override;
virtual base::string16 GetDialogTitle() const override;
virtual GURL GetDialogContentURL() const override;
virtual void GetWebUIMessageHandlers(
std::vector<WebUIMessageHandler*>* handlers) const override;
virtual void GetDialogSize(gfx::Size* size) const override;
virtual std::string GetDialogArgs() const override;
virtual void OnDialogClosed(const std::string& json_retval) override;
virtual void OnCloseContents(WebContents* source,
bool* out_close_dialog) override;
virtual bool ShouldShowDialogTitle() const override;
virtual bool HandleContextMenu(
const content::ContextMenuParams& params) override;
private:
gfx::NativeWindow dialog_window_;
// Cellular network service path.
std::string service_path_;
DISALLOW_COPY_AND_ASSIGN(MobileSetupDialogDelegate);
};
// static
void MobileSetupDialog::Show(const std::string& service_path) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
MobileSetupDialogDelegate::GetInstance()->ShowDialog(service_path);
}
// static
MobileSetupDialogDelegate* MobileSetupDialogDelegate::GetInstance() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
return Singleton<MobileSetupDialogDelegate>::get();
}
MobileSetupDialogDelegate::MobileSetupDialogDelegate() : dialog_window_(NULL) {
}
MobileSetupDialogDelegate::~MobileSetupDialogDelegate() {
}
void MobileSetupDialogDelegate::ShowDialog(const std::string& service_path) {
service_path_ = service_path;
gfx::NativeWindow parent = NULL;
// If we're on the login screen.
if (chromeos::LoginDisplayHostImpl::default_host()) {
chromeos::LoginDisplayHostImpl* webui_host =
static_cast<chromeos::LoginDisplayHostImpl*>(
chromeos::LoginDisplayHostImpl::default_host());
chromeos::WebUILoginView* login_view = webui_host->GetWebUILoginView();
if (login_view)
parent = login_view->GetNativeWindow();
}
// Only the primary user can change this.
dialog_window_ = chrome::ShowWebDialog(
parent,
ProfileManager::GetPrimaryUserProfile(),
this);
}
ui::ModalType MobileSetupDialogDelegate::GetDialogModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
base::string16 MobileSetupDialogDelegate::GetDialogTitle() const {
return l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE);
}
GURL MobileSetupDialogDelegate::GetDialogContentURL() const {
std::string url(chrome::kChromeUIMobileSetupURL);
url.append(service_path_);
return GURL(url);
}
void MobileSetupDialogDelegate::GetWebUIMessageHandlers(
std::vector<WebUIMessageHandler*>* handlers) const {
}
void MobileSetupDialogDelegate::GetDialogSize(gfx::Size* size) const {
size->SetSize(850, 650);
}
std::string MobileSetupDialogDelegate::GetDialogArgs() const {
return std::string();
}
void MobileSetupDialogDelegate::OnDialogClosed(const std::string& json_retval) {
dialog_window_ = NULL;
}
void MobileSetupDialogDelegate::OnCloseContents(WebContents* source,
bool* out_close_dialog) {
// If we're exiting, popping up the confirmation dialog can cause a
// crash. Note: IsTryingToQuit can be cancelled on other platforms by the
// onbeforeunload handler, except on ChromeOS. So IsTryingToQuit is the
// appropriate check to use here.
if (!dialog_window_ ||
!MobileActivator::GetInstance()->RunningActivation() ||
browser_shutdown::IsTryingToQuit()) {
*out_close_dialog = true;
return;
}
*out_close_dialog = chrome::ShowMessageBox(dialog_window_,
l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE),
l10n_util::GetStringUTF16(IDS_MOBILE_CANCEL_ACTIVATION),
chrome::MESSAGE_BOX_TYPE_QUESTION);
}
bool MobileSetupDialogDelegate::ShouldShowDialogTitle() const {
return true;
}
bool MobileSetupDialogDelegate::HandleContextMenu(
const content::ContextMenuParams& params) {
return true;
}
|