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