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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/sim_dialog_delegate.h"
7 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/chromeos/login/user_manager.h"
9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/ui/browser_dialogs.h"
11 #include "chrome/common/url_constants.h"
12 #include "ui/gfx/size.h"
14 using content::WebContents
;
15 using content::WebUIMessageHandler
;
19 // Default width/height of the dialog.
20 const int kDefaultWidth
= 350;
21 const int kDefaultHeight
= 225;
23 // Width/height for the change PIN dialog mode.
24 const int kChangePinWidth
= 350;
25 const int kChangePinHeight
= 245;
27 // URL that includes additional mode (other than Unlock flow) that we're using
28 // dialog for. Possible values:
29 // change-pin - use dialog to change PIN, ask for old & new PIN.
30 // set-lock-on - enable RequirePin restriction.
31 // set-lock-off - disable RequirePin restriction.
32 // In general SIM unlock case sim-unlock URL is loaded w/o parameters.
33 const char kSimDialogSpecialModeURL
[] = "chrome://sim-unlock/?mode=%s";
35 // Dialog mode constants.
36 const char kSimDialogChangePinMode
[] = "change-pin";
37 const char kSimDialogSetLockOnMode
[] = "set-lock-on";
38 const char kSimDialogSetLockOffMode
[] = "set-lock-off";
45 void SimDialogDelegate::ShowDialog(gfx::NativeWindow owning_window
,
47 chrome::ShowWebDialog(owning_window
,
48 ProfileManager::GetActiveUserProfile(),
49 new SimDialogDelegate(mode
));
52 SimDialogDelegate::SimDialogDelegate(SimDialogMode dialog_mode
)
53 : dialog_mode_(dialog_mode
) {
56 SimDialogDelegate::~SimDialogDelegate() {
59 ui::ModalType
SimDialogDelegate::GetDialogModalType() const {
60 return ui::MODAL_TYPE_SYSTEM
;
63 base::string16
SimDialogDelegate::GetDialogTitle() const {
64 return base::string16();
67 GURL
SimDialogDelegate::GetDialogContentURL() const {
68 if (dialog_mode_
== SIM_DIALOG_UNLOCK
) {
69 std::string
url_string(chrome::kChromeUISimUnlockURL
);
70 return GURL(url_string
);
72 std::string mode_value
;
73 if (dialog_mode_
== SIM_DIALOG_CHANGE_PIN
)
74 mode_value
= kSimDialogChangePinMode
;
75 else if (dialog_mode_
== SIM_DIALOG_SET_LOCK_ON
)
76 mode_value
= kSimDialogSetLockOnMode
;
78 mode_value
= kSimDialogSetLockOffMode
;
80 base::StringPrintf(kSimDialogSpecialModeURL
, mode_value
.c_str()));
84 void SimDialogDelegate::GetWebUIMessageHandlers(
85 std::vector
<WebUIMessageHandler
*>* handlers
) const {
88 void SimDialogDelegate::GetDialogSize(gfx::Size
* size
) const {
89 // TODO(nkostylev): Set custom size based on locale settings.
90 if (dialog_mode_
== SIM_DIALOG_CHANGE_PIN
)
91 size
->SetSize(kChangePinWidth
, kChangePinHeight
);
93 size
->SetSize(kDefaultWidth
, kDefaultHeight
);
96 std::string
SimDialogDelegate::GetDialogArgs() const {
100 void SimDialogDelegate::OnDialogClosed(const std::string
& json_retval
) {
104 void SimDialogDelegate::OnCloseContents(WebContents
* source
,
105 bool* out_close_dialog
) {
106 if (out_close_dialog
)
107 *out_close_dialog
= true;
110 bool SimDialogDelegate::ShouldShowDialogTitle() const {
114 bool SimDialogDelegate::HandleContextMenu(
115 const content::ContextMenuParams
& params
) {
116 // Disable context menu.
120 } // namespace chromeos