sim_dialog_delegate.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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.
4
5#include "chrome/browser/chromeos/sim_dialog_delegate.h"
6
7#include "base/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"
13
14using content::WebContents;
15using content::WebUIMessageHandler;
16
17namespace {
18
19// Default width/height of the dialog.
20const int kDefaultWidth = 350;
21const int kDefaultHeight = 225;
22
23// Width/height for the change PIN dialog mode.
24const int kChangePinWidth = 350;
25const int kChangePinHeight = 245;
26
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.
33const char kSimDialogSpecialModeURL[] = "chrome://sim-unlock/?mode=%s";
34
35// Dialog mode constants.
36const char kSimDialogChangePinMode[]  = "change-pin";
37const char kSimDialogSetLockOnMode[]  = "set-lock-on";
38const char kSimDialogSetLockOffMode[] = "set-lock-off";
39
40}  // namespace
41
42namespace chromeos {
43
44// static
45void SimDialogDelegate::ShowDialog(gfx::NativeWindow owning_window,
46                                   SimDialogMode mode) {
47  chrome::ShowWebDialog(owning_window,
48                        ProfileManager::GetDefaultProfileOrOffTheRecord(),
49                        new SimDialogDelegate(mode));
50}
51
52SimDialogDelegate::SimDialogDelegate(SimDialogMode dialog_mode)
53    : dialog_mode_(dialog_mode) {
54}
55
56SimDialogDelegate::~SimDialogDelegate() {
57}
58
59ui::ModalType SimDialogDelegate::GetDialogModalType() const {
60  return ui::MODAL_TYPE_SYSTEM;
61}
62
63string16 SimDialogDelegate::GetDialogTitle() const {
64  return string16();
65}
66
67GURL SimDialogDelegate::GetDialogContentURL() const {
68  if (dialog_mode_ == SIM_DIALOG_UNLOCK) {
69    std::string url_string(chrome::kChromeUISimUnlockURL);
70    return GURL(url_string);
71  } else {
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;
77    else
78      mode_value = kSimDialogSetLockOffMode;
79    return GURL(
80        base::StringPrintf(kSimDialogSpecialModeURL, mode_value.c_str()));
81  }
82}
83
84void SimDialogDelegate::GetWebUIMessageHandlers(
85    std::vector<WebUIMessageHandler*>* handlers) const {
86}
87
88void 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);
92  else
93    size->SetSize(kDefaultWidth, kDefaultHeight);
94}
95
96std::string SimDialogDelegate::GetDialogArgs() const {
97  return "[]";
98}
99
100void SimDialogDelegate::OnDialogClosed(const std::string& json_retval) {
101  delete this;
102}
103
104void SimDialogDelegate::OnCloseContents(WebContents* source,
105                                        bool* out_close_dialog) {
106  if (out_close_dialog)
107    *out_close_dialog = true;
108}
109
110bool SimDialogDelegate::ShouldShowDialogTitle() const {
111  return false;
112}
113
114bool SimDialogDelegate::HandleContextMenu(
115    const content::ContextMenuParams& params) {
116  // Disable context menu.
117  return true;
118}
119
120}  // namespace chromeos
121