OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/browser_shutdown.h" | 10 #include "chrome/browser/browser_shutdown.h" |
11 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | 11 #include "chrome/browser/chromeos/login/login_display_host_impl.h" |
12 #include "chrome/browser/chromeos/login/webui_login_view.h" | 12 #include "chrome/browser/chromeos/login/webui_login_view.h" |
13 #include "chrome/browser/chromeos/mobile/mobile_activator.h" | 13 #include "chrome/browser/chromeos/mobile/mobile_activator.h" |
14 #include "chrome/browser/platform_util.h" | 14 #include "chrome/browser/platform_util.h" |
15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
16 #include "chrome/browser/ui/browser_dialogs.h" | 16 #include "chrome/browser/ui/browser_dialogs.h" |
17 #include "chrome/browser/ui/simple_message_box.h" | 17 #include "chrome/browser/ui/simple_message_box.h" |
18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/gfx/size.h" | 22 #include "ui/gfx/size.h" |
23 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
24 #include "ui/web_dialogs/web_dialog_delegate.h" | 24 #include "ui/web_dialogs/web_dialog_delegate.h" |
25 | 25 |
26 using chromeos::CellularNetwork; | |
27 using chromeos::MobileActivator; | 26 using chromeos::MobileActivator; |
28 using content::BrowserThread; | 27 using content::BrowserThread; |
29 using content::WebContents; | 28 using content::WebContents; |
30 using content::WebUIMessageHandler; | 29 using content::WebUIMessageHandler; |
31 using ui::WebDialogDelegate; | 30 using ui::WebDialogDelegate; |
32 | 31 |
33 class MobileSetupDialogDelegate : public WebDialogDelegate, | 32 class MobileSetupDialogDelegate : public WebDialogDelegate { |
34 public MobileActivator::Observer { | |
35 public: | 33 public: |
36 static MobileSetupDialogDelegate* GetInstance(); | 34 static MobileSetupDialogDelegate* GetInstance(); |
37 void ShowDialog(const std::string& service_path); | 35 void ShowDialog(const std::string& service_path); |
38 | 36 |
39 protected: | 37 protected: |
40 friend struct DefaultSingletonTraits<MobileSetupDialogDelegate>; | 38 friend struct DefaultSingletonTraits<MobileSetupDialogDelegate>; |
41 | 39 |
42 MobileSetupDialogDelegate(); | 40 MobileSetupDialogDelegate(); |
43 virtual ~MobileSetupDialogDelegate(); | 41 virtual ~MobileSetupDialogDelegate(); |
44 | 42 |
(...skipping 10 matching lines...) Expand all Loading... |
55 virtual void OnDialogShown( | 53 virtual void OnDialogShown( |
56 content::WebUI* webui, | 54 content::WebUI* webui, |
57 content::RenderViewHost* render_view_host) OVERRIDE; | 55 content::RenderViewHost* render_view_host) OVERRIDE; |
58 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; | 56 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; |
59 virtual void OnCloseContents(WebContents* source, | 57 virtual void OnCloseContents(WebContents* source, |
60 bool* out_close_dialog) OVERRIDE; | 58 bool* out_close_dialog) OVERRIDE; |
61 virtual bool ShouldShowDialogTitle() const OVERRIDE; | 59 virtual bool ShouldShowDialogTitle() const OVERRIDE; |
62 virtual bool HandleContextMenu( | 60 virtual bool HandleContextMenu( |
63 const content::ContextMenuParams& params) OVERRIDE; | 61 const content::ContextMenuParams& params) OVERRIDE; |
64 | 62 |
65 // MobileActivator::Observer overrides. | |
66 virtual void OnActivationStateChanged( | |
67 CellularNetwork* network, | |
68 MobileActivator::PlanActivationState state, | |
69 const std::string& error_description) OVERRIDE; | |
70 | |
71 private: | 63 private: |
72 gfx::NativeWindow dialog_window_; | 64 gfx::NativeWindow dialog_window_; |
73 // Cellular network service path. | 65 // Cellular network service path. |
74 std::string service_path_; | 66 std::string service_path_; |
75 DISALLOW_COPY_AND_ASSIGN(MobileSetupDialogDelegate); | 67 DISALLOW_COPY_AND_ASSIGN(MobileSetupDialogDelegate); |
76 }; | 68 }; |
77 | 69 |
78 // static | 70 // static |
79 void MobileSetupDialog::Show(const std::string& service_path) { | 71 void MobileSetupDialog::Show(const std::string& service_path) { |
80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
81 MobileSetupDialogDelegate::GetInstance()->ShowDialog(service_path); | 73 MobileSetupDialogDelegate::GetInstance()->ShowDialog(service_path); |
82 } | 74 } |
83 | 75 |
84 // static | 76 // static |
85 MobileSetupDialogDelegate* MobileSetupDialogDelegate::GetInstance() { | 77 MobileSetupDialogDelegate* MobileSetupDialogDelegate::GetInstance() { |
86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
87 return Singleton<MobileSetupDialogDelegate>::get(); | 79 return Singleton<MobileSetupDialogDelegate>::get(); |
88 } | 80 } |
89 | 81 |
90 MobileSetupDialogDelegate::MobileSetupDialogDelegate() : dialog_window_(NULL) { | 82 MobileSetupDialogDelegate::MobileSetupDialogDelegate() : dialog_window_(NULL) { |
91 } | 83 } |
92 | 84 |
93 MobileSetupDialogDelegate::~MobileSetupDialogDelegate() { | 85 MobileSetupDialogDelegate::~MobileSetupDialogDelegate() { |
94 MobileActivator::GetInstance()->RemoveObserver(this); | |
95 } | 86 } |
96 | 87 |
97 void MobileSetupDialogDelegate::ShowDialog(const std::string& service_path) { | 88 void MobileSetupDialogDelegate::ShowDialog(const std::string& service_path) { |
98 service_path_ = service_path; | 89 service_path_ = service_path; |
99 | 90 |
100 gfx::NativeWindow parent = NULL; | 91 gfx::NativeWindow parent = NULL; |
101 // If we're on the login screen. | 92 // If we're on the login screen. |
102 if (chromeos::LoginDisplayHostImpl::default_host()) { | 93 if (chromeos::LoginDisplayHostImpl::default_host()) { |
103 chromeos::LoginDisplayHostImpl* webui_host = | 94 chromeos::LoginDisplayHostImpl* webui_host = |
104 static_cast<chromeos::LoginDisplayHostImpl*>( | 95 static_cast<chromeos::LoginDisplayHostImpl*>( |
(...skipping 30 matching lines...) Expand all Loading... |
135 void MobileSetupDialogDelegate::GetDialogSize(gfx::Size* size) const { | 126 void MobileSetupDialogDelegate::GetDialogSize(gfx::Size* size) const { |
136 size->SetSize(850, 650); | 127 size->SetSize(850, 650); |
137 } | 128 } |
138 | 129 |
139 std::string MobileSetupDialogDelegate::GetDialogArgs() const { | 130 std::string MobileSetupDialogDelegate::GetDialogArgs() const { |
140 return std::string(); | 131 return std::string(); |
141 } | 132 } |
142 | 133 |
143 void MobileSetupDialogDelegate::OnDialogShown( | 134 void MobileSetupDialogDelegate::OnDialogShown( |
144 content::WebUI* webui, content::RenderViewHost* render_view_host) { | 135 content::WebUI* webui, content::RenderViewHost* render_view_host) { |
145 MobileActivator::GetInstance()->AddObserver(this); | |
146 } | 136 } |
147 | 137 |
148 | 138 |
149 void MobileSetupDialogDelegate::OnDialogClosed(const std::string& json_retval) { | 139 void MobileSetupDialogDelegate::OnDialogClosed(const std::string& json_retval) { |
150 MobileActivator::GetInstance()->RemoveObserver(this); | |
151 dialog_window_ = NULL; | 140 dialog_window_ = NULL; |
152 } | 141 } |
153 | 142 |
154 void MobileSetupDialogDelegate::OnCloseContents(WebContents* source, | 143 void MobileSetupDialogDelegate::OnCloseContents(WebContents* source, |
155 bool* out_close_dialog) { | 144 bool* out_close_dialog) { |
156 // If we're exiting, popping up the confirmation dialog can cause a | 145 // If we're exiting, popping up the confirmation dialog can cause a |
157 // crash. Note: IsTryingToQuit can be cancelled on other platforms by the | 146 // crash. Note: IsTryingToQuit can be cancelled on other platforms by the |
158 // onbeforeunload handler, except on ChromeOS. So IsTryingToQuit is the | 147 // onbeforeunload handler, except on ChromeOS. So IsTryingToQuit is the |
159 // appropriate check to use here. | 148 // appropriate check to use here. |
160 if (!dialog_window_ || | 149 if (!dialog_window_ || |
(...skipping 10 matching lines...) Expand all Loading... |
171 } | 160 } |
172 | 161 |
173 bool MobileSetupDialogDelegate::ShouldShowDialogTitle() const { | 162 bool MobileSetupDialogDelegate::ShouldShowDialogTitle() const { |
174 return true; | 163 return true; |
175 } | 164 } |
176 | 165 |
177 bool MobileSetupDialogDelegate::HandleContextMenu( | 166 bool MobileSetupDialogDelegate::HandleContextMenu( |
178 const content::ContextMenuParams& params) { | 167 const content::ContextMenuParams& params) { |
179 return true; | 168 return true; |
180 } | 169 } |
181 | |
182 void MobileSetupDialogDelegate::OnActivationStateChanged( | |
183 CellularNetwork* network, | |
184 MobileActivator::PlanActivationState state, | |
185 const std::string& error_description) { | |
186 } | |
OLD | NEW |