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/profiles/profile_manager.h"
9 #include "chrome/browser/ui/browser_dialogs.h"
10 #include "chrome/common/url_constants.h"
11 #include "ui/gfx/geometry/size.h"
13 using content::WebContents
;
14 using content::WebUIMessageHandler
;
18 // Default width/height of the dialog.
19 const int kDefaultWidth
= 350;
20 const int kDefaultHeight
= 225;
22 // Width/height for the change PIN dialog mode.
23 const int kChangePinWidth
= 350;
24 const int kChangePinHeight
= 245;
26 // Dialog mode constants.
27 const char kSimDialogChangePinMode
[] = "change-pin";
28 const char kSimDialogSetLockOnMode
[] = "set-lock-on";
29 const char kSimDialogSetLockOffMode
[] = "set-lock-off";
36 void SimDialogDelegate::ShowDialog(gfx::NativeWindow owning_window
,
38 chrome::ShowWebDialog(owning_window
,
39 ProfileManager::GetActiveUserProfile(),
40 new SimDialogDelegate(mode
));
43 SimDialogDelegate::SimDialogDelegate(SimDialogMode dialog_mode
)
44 : dialog_mode_(dialog_mode
) {
47 SimDialogDelegate::~SimDialogDelegate() {
50 ui::ModalType
SimDialogDelegate::GetDialogModalType() const {
51 return ui::MODAL_TYPE_SYSTEM
;
54 base::string16
SimDialogDelegate::GetDialogTitle() const {
55 return base::string16();
58 GURL
SimDialogDelegate::GetDialogContentURL() const {
59 if (dialog_mode_
== SIM_DIALOG_UNLOCK
) {
60 std::string
url_string(chrome::kChromeUISimUnlockURL
);
61 return GURL(url_string
);
63 std::string mode_value
;
64 if (dialog_mode_
== SIM_DIALOG_CHANGE_PIN
)
65 mode_value
= kSimDialogChangePinMode
;
66 else if (dialog_mode_
== SIM_DIALOG_SET_LOCK_ON
)
67 mode_value
= kSimDialogSetLockOnMode
;
69 mode_value
= kSimDialogSetLockOffMode
;
71 // Create a URL that includes an additional mode (other than Unlock flow).
72 // Possible values for mode are:
73 // change-pin - use dialog to change PIN, ask for old & new PIN.
74 // set-lock-on - enable RequirePin restriction.
75 // set-lock-off - disable RequirePin restriction.
76 std::string url_string
=
77 std::string(chrome::kChromeUISimUnlockURL
) + "?mode=" + mode_value
;
78 return GURL(url_string
);
82 void SimDialogDelegate::GetWebUIMessageHandlers(
83 std::vector
<WebUIMessageHandler
*>* handlers
) const {
86 void SimDialogDelegate::GetDialogSize(gfx::Size
* size
) const {
87 // TODO(nkostylev): Set custom size based on locale settings.
88 if (dialog_mode_
== SIM_DIALOG_CHANGE_PIN
)
89 size
->SetSize(kChangePinWidth
, kChangePinHeight
);
91 size
->SetSize(kDefaultWidth
, kDefaultHeight
);
94 std::string
SimDialogDelegate::GetDialogArgs() const {
98 void SimDialogDelegate::OnDialogClosed(const std::string
& json_retval
) {
102 void SimDialogDelegate::OnCloseContents(WebContents
* source
,
103 bool* out_close_dialog
) {
104 *out_close_dialog
= true;
107 bool SimDialogDelegate::ShouldShowDialogTitle() const {
111 bool SimDialogDelegate::HandleContextMenu(
112 const content::ContextMenuParams
& params
) {
113 // Disable context menu.
117 } // namespace chromeos