OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h" | 5 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/platform_util.h" | 10 #include "chrome/browser/platform_util.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_dialogs.h" | 12 #include "chrome/browser/ui/browser_dialogs.h" |
13 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
14 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 14 #include "chrome/browser/ui/webui/html_dialog_ui.h" |
15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
18 | 18 |
19 // static | 19 class MobileSetupDialogDelegate : public HtmlDialogUIDelegate { |
20 MobileSetupDialog* MobileSetupDialog::GetInstance() { | 20 public: |
21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 21 static MobileSetupDialogDelegate* GetInstance(); |
22 return Singleton<MobileSetupDialog>::get(); | 22 void ShowDialog(); |
23 } | |
24 | 23 |
25 MobileSetupDialog::MobileSetupDialog() { | 24 protected: |
26 } | 25 friend struct DefaultSingletonTraits<MobileSetupDialogDelegate>; |
27 | 26 |
28 MobileSetupDialog::~MobileSetupDialog() { | 27 MobileSetupDialogDelegate(); |
29 } | 28 virtual ~MobileSetupDialogDelegate(); |
| 29 |
| 30 void OnCloseDialog(); |
| 31 |
| 32 // HtmlDialogUIDelegate overrides. |
| 33 virtual bool IsDialogModal() const OVERRIDE; |
| 34 virtual string16 GetDialogTitle() const OVERRIDE; |
| 35 virtual GURL GetDialogContentURL() const OVERRIDE; |
| 36 virtual void GetWebUIMessageHandlers( |
| 37 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; |
| 38 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; |
| 39 virtual std::string GetDialogArgs() const OVERRIDE; |
| 40 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; |
| 41 virtual void OnCloseContents(TabContents* source, |
| 42 bool* out_close_dialog) OVERRIDE; |
| 43 virtual bool ShouldShowDialogTitle() const OVERRIDE; |
| 44 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE; |
| 45 |
| 46 private: |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(MobileSetupDialogDelegate); |
| 49 }; |
30 | 50 |
31 // static | 51 // static |
32 void MobileSetupDialog::Show() { | 52 void MobileSetupDialog::Show() { |
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
34 MobileSetupDialog* dialog = MobileSetupDialog::GetInstance(); | 54 MobileSetupDialogDelegate::GetInstance()->ShowDialog(); |
35 dialog->ShowDialog(); | |
36 } | 55 } |
37 | 56 |
38 void MobileSetupDialog::ShowDialog() { | 57 // static |
| 58 MobileSetupDialogDelegate* MobileSetupDialogDelegate::GetInstance() { |
| 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 60 return Singleton<MobileSetupDialogDelegate>::get(); |
| 61 } |
| 62 |
| 63 MobileSetupDialogDelegate::MobileSetupDialogDelegate() { |
| 64 } |
| 65 |
| 66 MobileSetupDialogDelegate::~MobileSetupDialogDelegate() { |
| 67 } |
| 68 |
| 69 void MobileSetupDialogDelegate::ShowDialog() { |
39 Browser* browser = BrowserList::GetLastActive(); | 70 Browser* browser = BrowserList::GetLastActive(); |
40 if (!browser) | 71 if (!browser) |
41 return; | 72 return; |
42 browser->BrowserShowHtmlDialog(this, NULL); | 73 browser->BrowserShowHtmlDialog(this, NULL); |
43 } | 74 } |
44 | 75 |
45 bool MobileSetupDialog::IsDialogModal() const { | 76 bool MobileSetupDialogDelegate::IsDialogModal() const { |
46 return true; | 77 return true; |
47 } | 78 } |
48 | 79 |
49 string16 MobileSetupDialog::GetDialogTitle() const { | 80 string16 MobileSetupDialogDelegate::GetDialogTitle() const { |
50 return l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE); | 81 return l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE); |
51 } | 82 } |
52 | 83 |
53 GURL MobileSetupDialog::GetDialogContentURL() const { | 84 GURL MobileSetupDialogDelegate::GetDialogContentURL() const { |
54 return GURL(chrome::kChromeUIMobileSetupURL); | 85 return GURL(chrome::kChromeUIMobileSetupURL); |
55 } | 86 } |
56 | 87 |
57 void MobileSetupDialog::GetWebUIMessageHandlers( | 88 void MobileSetupDialogDelegate::GetWebUIMessageHandlers( |
58 std::vector<WebUIMessageHandler*>* handlers) const{ | 89 std::vector<WebUIMessageHandler*>* handlers) const{ |
59 } | 90 } |
60 | 91 |
61 void MobileSetupDialog::GetDialogSize(gfx::Size* size) const { | 92 void MobileSetupDialogDelegate::GetDialogSize(gfx::Size* size) const { |
62 #if defined(POST_PORTAL) | 93 #if defined(POST_PORTAL) |
63 size->SetSize(850, 650); | 94 size->SetSize(850, 650); |
64 #else | 95 #else |
65 size->SetSize(1100, 700); | 96 size->SetSize(1100, 700); |
66 #endif | 97 #endif |
67 } | 98 } |
68 | 99 |
69 std::string MobileSetupDialog::GetDialogArgs() const { | 100 std::string MobileSetupDialogDelegate::GetDialogArgs() const { |
70 return std::string(); | 101 return std::string(); |
71 } | 102 } |
72 | 103 |
73 void MobileSetupDialog::OnDialogClosed(const std::string& json_retval) { | 104 void MobileSetupDialogDelegate::OnDialogClosed(const std::string& json_retval) { |
74 } | 105 } |
75 | 106 |
76 void MobileSetupDialog::OnCloseContents(TabContents* source, | 107 void MobileSetupDialogDelegate::OnCloseContents(TabContents* source, |
77 bool* out_close_dialog) { | 108 bool* out_close_dialog) { |
78 *out_close_dialog = true; | 109 *out_close_dialog = true; |
79 } | 110 } |
80 | 111 |
81 bool MobileSetupDialog::ShouldShowDialogTitle() const { | 112 bool MobileSetupDialogDelegate::ShouldShowDialogTitle() const { |
82 return true; | 113 return true; |
83 } | 114 } |
84 | 115 |
85 bool MobileSetupDialog::HandleContextMenu(const ContextMenuParams& params) { | 116 bool MobileSetupDialogDelegate::HandleContextMenu(const ContextMenuParams& param
s) { |
86 return true; | 117 return true; |
87 } | 118 } |
OLD | NEW |