Return backed up TemplateURL on default search change
[chromium-blink-merge.git] / chrome / browser / chromeos / sim_dialog_delegate.cc
blobd20e8cbd8dfa805756edf27a235c8776f618874d
1 // Copyright (c) 2011 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/stringprintf.h"
8 #include "chrome/browser/chromeos/frame/bubble_window.h"
9 #include "chrome/browser/chromeos/login/user_manager.h"
10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/views/html_dialog_view.h"
14 #include "chrome/common/url_constants.h"
15 #include "ui/views/view.h"
16 #include "ui/views/widget/widget.h"
18 namespace {
20 // Default width/height of the dialog.
21 const int kDefaultWidth = 350;
22 const int kDefaultHeight = 225;
24 // Width/height for the change PIN dialog mode.
25 const int kChangePinWidth = 350;
26 const int kChangePinHeight = 245;
28 // URL that includes additional mode (other than Unlock flow) that we're using
29 // dialog for. Possible values:
30 // change-pin - use dialog to change PIN, ask for old & new PIN.
31 // set-lock-on - enable RequirePin restriction.
32 // set-lock-off - disable RequirePin restriction.
33 // In general SIM unlock case sim-unlock URL is loaded w/o parameters.
34 const char kSimDialogSpecialModeURL[] = "chrome://sim-unlock/?mode=%s";
36 // Dialog mode constants.
37 const char kSimDialogChangePinMode[] = "change-pin";
38 const char kSimDialogSetLockOnMode[] = "set-lock-on";
39 const char kSimDialogSetLockOffMode[] = "set-lock-off";
41 } // namespace
43 namespace chromeos {
45 // static
46 void SimDialogDelegate::ShowDialog(gfx::NativeWindow owning_window,
47 SimDialogMode mode) {
48 Profile* profile;
49 if (UserManager::Get()->user_is_logged_in()) {
50 Browser* browser = BrowserList::GetLastActive();
51 DCHECK(browser);
52 profile = browser->profile();
53 } else {
54 profile = ProfileManager::GetDefaultProfile();
56 HtmlDialogView* html_view =
57 new HtmlDialogView(profile, new SimDialogDelegate(mode));
58 html_view->InitDialog();
59 BubbleWindow::Create(owning_window,
60 STYLE_FLUSH,
61 html_view);
62 html_view->GetWidget()->Show();
65 SimDialogDelegate::SimDialogDelegate(SimDialogMode dialog_mode)
66 : dialog_mode_(dialog_mode) {
69 SimDialogDelegate::~SimDialogDelegate() {
72 bool SimDialogDelegate::IsDialogModal() const {
73 return true;
76 string16 SimDialogDelegate::GetDialogTitle() const {
77 return string16();
80 GURL SimDialogDelegate::GetDialogContentURL() const {
81 if (dialog_mode_ == SIM_DIALOG_UNLOCK) {
82 std::string url_string(chrome::kChromeUISimUnlockURL);
83 return GURL(url_string);
84 } else {
85 std::string mode_value;
86 if (dialog_mode_ == SIM_DIALOG_CHANGE_PIN)
87 mode_value = kSimDialogChangePinMode;
88 else if (dialog_mode_ == SIM_DIALOG_SET_LOCK_ON)
89 mode_value = kSimDialogSetLockOnMode;
90 else
91 mode_value = kSimDialogSetLockOffMode;
92 return GURL(StringPrintf(kSimDialogSpecialModeURL, mode_value.c_str()));
96 void SimDialogDelegate::GetWebUIMessageHandlers(
97 std::vector<WebUIMessageHandler*>* handlers) const {
100 void SimDialogDelegate::GetDialogSize(gfx::Size* size) const {
101 // TODO(nkostylev): Set custom size based on locale settings.
102 if (dialog_mode_ == SIM_DIALOG_CHANGE_PIN)
103 size->SetSize(kChangePinWidth , kChangePinHeight);
104 else
105 size->SetSize(kDefaultWidth, kDefaultHeight);
108 std::string SimDialogDelegate::GetDialogArgs() const {
109 return "[]";
112 void SimDialogDelegate::OnDialogClosed(const std::string& json_retval) {
113 delete this;
116 void SimDialogDelegate::OnCloseContents(TabContents* source,
117 bool* out_close_dialog) {
118 if (out_close_dialog)
119 *out_close_dialog = true;
122 bool SimDialogDelegate::ShouldShowDialogTitle() const {
123 return false;
126 bool SimDialogDelegate::HandleContextMenu(const ContextMenuParams& params) {
127 // Disable context menu.
128 return true;
131 } // namespace chromeos