• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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/size.h"
12 
13 using content::WebContents;
14 using content::WebUIMessageHandler;
15 
16 namespace {
17 
18 // Default width/height of the dialog.
19 const int kDefaultWidth = 350;
20 const int kDefaultHeight = 225;
21 
22 // Width/height for the change PIN dialog mode.
23 const int kChangePinWidth = 350;
24 const int kChangePinHeight = 245;
25 
26 // Dialog mode constants.
27 const char kSimDialogChangePinMode[]  = "change-pin";
28 const char kSimDialogSetLockOnMode[]  = "set-lock-on";
29 const char kSimDialogSetLockOffMode[] = "set-lock-off";
30 
31 }  // namespace
32 
33 namespace chromeos {
34 
35 // static
ShowDialog(gfx::NativeWindow owning_window,SimDialogMode mode)36 void SimDialogDelegate::ShowDialog(gfx::NativeWindow owning_window,
37                                    SimDialogMode mode) {
38   chrome::ShowWebDialog(owning_window,
39                         ProfileManager::GetActiveUserProfile(),
40                         new SimDialogDelegate(mode));
41 }
42 
SimDialogDelegate(SimDialogMode dialog_mode)43 SimDialogDelegate::SimDialogDelegate(SimDialogMode dialog_mode)
44     : dialog_mode_(dialog_mode) {
45 }
46 
~SimDialogDelegate()47 SimDialogDelegate::~SimDialogDelegate() {
48 }
49 
GetDialogModalType() const50 ui::ModalType SimDialogDelegate::GetDialogModalType() const {
51   return ui::MODAL_TYPE_SYSTEM;
52 }
53 
GetDialogTitle() const54 base::string16 SimDialogDelegate::GetDialogTitle() const {
55   return base::string16();
56 }
57 
GetDialogContentURL() const58 GURL SimDialogDelegate::GetDialogContentURL() const {
59   if (dialog_mode_ == SIM_DIALOG_UNLOCK) {
60     std::string url_string(chrome::kChromeUISimUnlockURL);
61     return GURL(url_string);
62   } else {
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;
68     else
69       mode_value = kSimDialogSetLockOffMode;
70 
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);
79   }
80 }
81 
GetWebUIMessageHandlers(std::vector<WebUIMessageHandler * > * handlers) const82 void SimDialogDelegate::GetWebUIMessageHandlers(
83     std::vector<WebUIMessageHandler*>* handlers) const {
84 }
85 
GetDialogSize(gfx::Size * size) const86 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);
90   else
91     size->SetSize(kDefaultWidth, kDefaultHeight);
92 }
93 
GetDialogArgs() const94 std::string SimDialogDelegate::GetDialogArgs() const {
95   return "[]";
96 }
97 
OnDialogClosed(const std::string & json_retval)98 void SimDialogDelegate::OnDialogClosed(const std::string& json_retval) {
99   delete this;
100 }
101 
OnCloseContents(WebContents * source,bool * out_close_dialog)102 void SimDialogDelegate::OnCloseContents(WebContents* source,
103                                         bool* out_close_dialog) {
104   if (out_close_dialog)
105     *out_close_dialog = true;
106 }
107 
ShouldShowDialogTitle() const108 bool SimDialogDelegate::ShouldShowDialogTitle() const {
109   return false;
110 }
111 
HandleContextMenu(const content::ContextMenuParams & params)112 bool SimDialogDelegate::HandleContextMenu(
113     const content::ContextMenuParams& params) {
114   // Disable context menu.
115   return true;
116 }
117 
118 }  // namespace chromeos
119