| 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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/chromeos/mobile/mobile_activator.h" |
| 10 #include "chrome/browser/platform_util.h" | 11 #include "chrome/browser/platform_util.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/browser/ui/browser_dialogs.h" | 13 #include "chrome/browser/ui/browser_dialogs.h" |
| 13 #include "chrome/browser/ui/simple_message_box.h" | 14 #include "chrome/browser/ui/simple_message_box.h" |
| 14 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/gfx/size.h" | 19 #include "ui/gfx/size.h" |
| 19 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 20 #include "ui/web_dialogs/web_dialog_delegate.h" | 21 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 21 | 22 |
| 23 using chromeos::CellularNetwork; |
| 24 using chromeos::MobileActivator; |
| 22 using content::BrowserThread; | 25 using content::BrowserThread; |
| 23 using content::WebContents; | 26 using content::WebContents; |
| 24 using content::WebUIMessageHandler; | 27 using content::WebUIMessageHandler; |
| 25 using ui::WebDialogDelegate; | 28 using ui::WebDialogDelegate; |
| 26 | 29 |
| 27 class MobileSetupDialogDelegate : public WebDialogDelegate { | 30 class MobileSetupDialogDelegate : public WebDialogDelegate, |
| 31 public MobileActivator::Observer { |
| 28 public: | 32 public: |
| 29 static MobileSetupDialogDelegate* GetInstance(); | 33 static MobileSetupDialogDelegate* GetInstance(); |
| 30 void ShowDialog(); | 34 void ShowDialog(const std::string& service_path); |
| 31 | 35 |
| 32 protected: | 36 protected: |
| 33 friend struct DefaultSingletonTraits<MobileSetupDialogDelegate>; | 37 friend struct DefaultSingletonTraits<MobileSetupDialogDelegate>; |
| 34 | 38 |
| 35 MobileSetupDialogDelegate(); | 39 MobileSetupDialogDelegate(); |
| 36 virtual ~MobileSetupDialogDelegate(); | 40 virtual ~MobileSetupDialogDelegate(); |
| 37 | 41 |
| 38 void OnCloseDialog(); | 42 void OnCloseDialog(); |
| 39 | 43 |
| 40 // WebDialogDelegate overrides. | 44 // WebDialogDelegate overrides. |
| 41 virtual ui::ModalType GetDialogModalType() const OVERRIDE; | 45 virtual ui::ModalType GetDialogModalType() const OVERRIDE; |
| 42 virtual string16 GetDialogTitle() const OVERRIDE; | 46 virtual string16 GetDialogTitle() const OVERRIDE; |
| 43 virtual GURL GetDialogContentURL() const OVERRIDE; | 47 virtual GURL GetDialogContentURL() const OVERRIDE; |
| 44 virtual void GetWebUIMessageHandlers( | 48 virtual void GetWebUIMessageHandlers( |
| 45 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; | 49 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; |
| 46 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; | 50 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; |
| 47 virtual std::string GetDialogArgs() const OVERRIDE; | 51 virtual std::string GetDialogArgs() const OVERRIDE; |
| 52 virtual void OnDialogShown( |
| 53 content::WebUI* webui, |
| 54 content::RenderViewHost* render_view_host) OVERRIDE; |
| 48 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; | 55 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; |
| 49 virtual void OnCloseContents(WebContents* source, | 56 virtual void OnCloseContents(WebContents* source, |
| 50 bool* out_close_dialog) OVERRIDE; | 57 bool* out_close_dialog) OVERRIDE; |
| 51 virtual bool ShouldShowDialogTitle() const OVERRIDE; | 58 virtual bool ShouldShowDialogTitle() const OVERRIDE; |
| 52 virtual bool HandleContextMenu( | 59 virtual bool HandleContextMenu( |
| 53 const content::ContextMenuParams& params) OVERRIDE; | 60 const content::ContextMenuParams& params) OVERRIDE; |
| 54 | 61 |
| 62 // MobileActivator::Observer overrides. |
| 63 virtual void OnActivationStateChanged( |
| 64 CellularNetwork* network, |
| 65 MobileActivator::PlanActivationState state, |
| 66 const std::string& error_description) OVERRIDE; |
| 67 |
| 55 private: | 68 private: |
| 56 gfx::NativeWindow dialog_window_; | 69 gfx::NativeWindow dialog_window_; |
| 57 | 70 // Cellular network service path. |
| 71 std::string service_path_; |
| 58 DISALLOW_COPY_AND_ASSIGN(MobileSetupDialogDelegate); | 72 DISALLOW_COPY_AND_ASSIGN(MobileSetupDialogDelegate); |
| 59 }; | 73 }; |
| 60 | 74 |
| 61 // static | 75 // static |
| 62 void MobileSetupDialog::Show() { | 76 void MobileSetupDialog::Show(const std::string& service_path) { |
| 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 64 MobileSetupDialogDelegate::GetInstance()->ShowDialog(); | 78 MobileSetupDialogDelegate::GetInstance()->ShowDialog(service_path); |
| 65 } | 79 } |
| 66 | 80 |
| 67 // static | 81 // static |
| 68 MobileSetupDialogDelegate* MobileSetupDialogDelegate::GetInstance() { | 82 MobileSetupDialogDelegate* MobileSetupDialogDelegate::GetInstance() { |
| 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 70 return Singleton<MobileSetupDialogDelegate>::get(); | 84 return Singleton<MobileSetupDialogDelegate>::get(); |
| 71 } | 85 } |
| 72 | 86 |
| 73 MobileSetupDialogDelegate::MobileSetupDialogDelegate() : dialog_window_(NULL) { | 87 MobileSetupDialogDelegate::MobileSetupDialogDelegate() : dialog_window_(NULL) { |
| 74 } | 88 } |
| 75 | 89 |
| 76 MobileSetupDialogDelegate::~MobileSetupDialogDelegate() { | 90 MobileSetupDialogDelegate::~MobileSetupDialogDelegate() { |
| 91 MobileActivator::GetInstance()->RemoveObserver(this); |
| 77 } | 92 } |
| 78 | 93 |
| 79 void MobileSetupDialogDelegate::ShowDialog() { | 94 void MobileSetupDialogDelegate::ShowDialog(const std::string& service_path) { |
| 95 service_path_ = service_path; |
| 80 dialog_window_ = browser::ShowWebDialog( | 96 dialog_window_ = browser::ShowWebDialog( |
| 81 NULL, | 97 NULL, |
| 82 ProfileManager::GetDefaultProfileOrOffTheRecord(), | 98 ProfileManager::GetDefaultProfileOrOffTheRecord(), |
| 83 NULL, | 99 NULL, |
| 84 this); | 100 this); |
| 85 } | 101 } |
| 86 | 102 |
| 87 ui::ModalType MobileSetupDialogDelegate::GetDialogModalType() const { | 103 ui::ModalType MobileSetupDialogDelegate::GetDialogModalType() const { |
| 88 return ui::MODAL_TYPE_SYSTEM; | 104 return ui::MODAL_TYPE_SYSTEM; |
| 89 } | 105 } |
| 90 | 106 |
| 91 string16 MobileSetupDialogDelegate::GetDialogTitle() const { | 107 string16 MobileSetupDialogDelegate::GetDialogTitle() const { |
| 92 return l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE); | 108 return l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE); |
| 93 } | 109 } |
| 94 | 110 |
| 95 GURL MobileSetupDialogDelegate::GetDialogContentURL() const { | 111 GURL MobileSetupDialogDelegate::GetDialogContentURL() const { |
| 96 return GURL(chrome::kChromeUIMobileSetupURL); | 112 std::string url(chrome::kChromeUIMobileSetupURL); |
| 113 url.append(service_path_); |
| 114 return GURL(url); |
| 97 } | 115 } |
| 98 | 116 |
| 99 void MobileSetupDialogDelegate::GetWebUIMessageHandlers( | 117 void MobileSetupDialogDelegate::GetWebUIMessageHandlers( |
| 100 std::vector<WebUIMessageHandler*>* handlers) const{ | 118 std::vector<WebUIMessageHandler*>* handlers) const { |
| 101 } | 119 } |
| 102 | 120 |
| 103 void MobileSetupDialogDelegate::GetDialogSize(gfx::Size* size) const { | 121 void MobileSetupDialogDelegate::GetDialogSize(gfx::Size* size) const { |
| 104 size->SetSize(850, 650); | 122 size->SetSize(850, 650); |
| 105 } | 123 } |
| 106 | 124 |
| 107 std::string MobileSetupDialogDelegate::GetDialogArgs() const { | 125 std::string MobileSetupDialogDelegate::GetDialogArgs() const { |
| 108 return std::string(); | 126 return std::string(); |
| 109 } | 127 } |
| 110 | 128 |
| 129 void MobileSetupDialogDelegate::OnDialogShown( |
| 130 content::WebUI* webui, content::RenderViewHost* render_view_host) { |
| 131 MobileActivator::GetInstance()->AddObserver(this); |
| 132 } |
| 133 |
| 134 |
| 111 void MobileSetupDialogDelegate::OnDialogClosed(const std::string& json_retval) { | 135 void MobileSetupDialogDelegate::OnDialogClosed(const std::string& json_retval) { |
| 136 MobileActivator::GetInstance()->RemoveObserver(this); |
| 112 dialog_window_ = NULL; | 137 dialog_window_ = NULL; |
| 113 } | 138 } |
| 114 | 139 |
| 115 void MobileSetupDialogDelegate::OnCloseContents(WebContents* source, | 140 void MobileSetupDialogDelegate::OnCloseContents(WebContents* source, |
| 116 bool* out_close_dialog) { | 141 bool* out_close_dialog) { |
| 117 if (!dialog_window_) { | 142 if (!dialog_window_ || !MobileActivator::GetInstance()->RunningActivation()) { |
| 118 *out_close_dialog = true; | 143 *out_close_dialog = true; |
| 119 return; | 144 return; |
| 120 } | 145 } |
| 121 | 146 |
| 122 *out_close_dialog = browser::ShowMessageBox(dialog_window_, | 147 *out_close_dialog = browser::ShowMessageBox(dialog_window_, |
| 123 l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE), | 148 l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE), |
| 124 l10n_util::GetStringUTF16(IDS_MOBILE_CANCEL_ACTIVATION), | 149 l10n_util::GetStringUTF16(IDS_MOBILE_CANCEL_ACTIVATION), |
| 125 browser::MESSAGE_BOX_TYPE_QUESTION); | 150 browser::MESSAGE_BOX_TYPE_QUESTION); |
| 126 } | 151 } |
| 127 | 152 |
| 128 bool MobileSetupDialogDelegate::ShouldShowDialogTitle() const { | 153 bool MobileSetupDialogDelegate::ShouldShowDialogTitle() const { |
| 129 return true; | 154 return true; |
| 130 } | 155 } |
| 131 | 156 |
| 132 bool MobileSetupDialogDelegate::HandleContextMenu( | 157 bool MobileSetupDialogDelegate::HandleContextMenu( |
| 133 const content::ContextMenuParams& params) { | 158 const content::ContextMenuParams& params) { |
| 134 return true; | 159 return true; |
| 135 } | 160 } |
| 161 |
| 162 void MobileSetupDialogDelegate::OnActivationStateChanged( |
| 163 CellularNetwork* network, |
| 164 MobileActivator::PlanActivationState state, |
| 165 const std::string& error_description) { |
| 166 } |
| OLD | NEW |