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/chromeos/offline/offline_load_page.h" | 5 #include "chrome/browser/chromeos/offline/offline_load_page.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/chromeos/cros/cros_library.h" | 13 #include "chrome/browser/chromeos/cros/cros_library.h" |
14 #include "chrome/browser/chromeos/cros/network_library.h" | 14 #include "chrome/browser/chromeos/cros/network_library.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/tab_contents/tab_util.h" | 17 #include "chrome/browser/tab_contents/tab_util.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_list.h" | 19 #include "chrome/browser/ui/browser_list.h" |
| 20 #include "chrome/common/chrome_notification_types.h" |
20 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
21 #include "chrome/common/jstemplate_builder.h" | 22 #include "chrome/common/jstemplate_builder.h" |
22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
23 #include "content/browser/browser_thread.h" | 24 #include "content/browser/browser_thread.h" |
24 #include "content/browser/tab_contents/navigation_controller.h" | 25 #include "content/browser/tab_contents/navigation_controller.h" |
25 #include "content/browser/tab_contents/navigation_entry.h" | 26 #include "content/browser/tab_contents/navigation_entry.h" |
26 #include "content/browser/tab_contents/tab_contents.h" | 27 #include "content/browser/tab_contents/tab_contents.h" |
| 28 #include "content/common/content_notification_types.h" |
27 #include "content/common/notification_service.h" | 29 #include "content/common/notification_service.h" |
28 #include "content/common/notification_type.h" | |
29 #include "grit/browser_resources.h" | 30 #include "grit/browser_resources.h" |
30 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
31 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
32 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
36 // Maximum time to show a blank page. | 37 // Maximum time to show a blank page. |
37 const int kMaxBlankPeriod = 3000; | 38 const int kMaxBlankPeriod = 3000; |
38 | 39 |
(...skipping 25 matching lines...) Expand all Loading... |
64 } | 65 } |
65 | 66 |
66 OfflineLoadPage::OfflineLoadPage(TabContents* tab_contents, | 67 OfflineLoadPage::OfflineLoadPage(TabContents* tab_contents, |
67 const GURL& url, | 68 const GURL& url, |
68 Delegate* delegate) | 69 Delegate* delegate) |
69 : ChromeInterstitialPage(tab_contents, true, url), | 70 : ChromeInterstitialPage(tab_contents, true, url), |
70 delegate_(delegate), | 71 delegate_(delegate), |
71 proceeded_(false), | 72 proceeded_(false), |
72 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 73 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
73 in_test_(false) { | 74 in_test_(false) { |
74 registrar_.Add(this, NotificationType::NETWORK_STATE_CHANGED, | 75 registrar_.Add(this, chrome::NOTIFICATION_NETWORK_STATE_CHANGED, |
75 NotificationService::AllSources()); | 76 NotificationService::AllSources()); |
76 } | 77 } |
77 | 78 |
78 OfflineLoadPage::~OfflineLoadPage() {} | 79 OfflineLoadPage::~OfflineLoadPage() {} |
79 | 80 |
80 std::string OfflineLoadPage::GetHTMLContents() { | 81 std::string OfflineLoadPage::GetHTMLContents() { |
81 DictionaryValue strings; | 82 DictionaryValue strings; |
82 int64 time_to_wait = std::max( | 83 int64 time_to_wait = std::max( |
83 static_cast<int64>(0), | 84 static_cast<int64>(0), |
84 kMaxBlankPeriod - | 85 kMaxBlankPeriod - |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 192 } |
192 | 193 |
193 void OfflineLoadPage::DontProceed() { | 194 void OfflineLoadPage::DontProceed() { |
194 // Inogre if it's already proceeded. | 195 // Inogre if it's already proceeded. |
195 if (proceeded_) | 196 if (proceeded_) |
196 return; | 197 return; |
197 delegate_->OnBlockingPageComplete(false); | 198 delegate_->OnBlockingPageComplete(false); |
198 InterstitialPage::DontProceed(); | 199 InterstitialPage::DontProceed(); |
199 } | 200 } |
200 | 201 |
201 void OfflineLoadPage::Observe(NotificationType type, | 202 void OfflineLoadPage::Observe(int type, |
202 const NotificationSource& source, | 203 const NotificationSource& source, |
203 const NotificationDetails& details) { | 204 const NotificationDetails& details) { |
204 if (type.value == NotificationType::NETWORK_STATE_CHANGED) { | 205 if (type == chrome::NOTIFICATION_NETWORK_STATE_CHANGED) { |
205 chromeos::NetworkStateDetails* state_details = | 206 chromeos::NetworkStateDetails* state_details = |
206 Details<chromeos::NetworkStateDetails>(details).ptr(); | 207 Details<chromeos::NetworkStateDetails>(details).ptr(); |
207 DVLOG(1) << "NetworkStateChanaged notification received: state=" | 208 DVLOG(1) << "NetworkStateChanaged notification received: state=" |
208 << state_details->state(); | 209 << state_details->state(); |
209 if (state_details->state() == | 210 if (state_details->state() == |
210 chromeos::NetworkStateDetails::CONNECTED) { | 211 chromeos::NetworkStateDetails::CONNECTED) { |
211 registrar_.Remove(this, NotificationType::NETWORK_STATE_CHANGED, | 212 registrar_.Remove(this, chrome::NOTIFICATION_NETWORK_STATE_CHANGED, |
212 NotificationService::AllSources()); | 213 NotificationService::AllSources()); |
213 Proceed(); | 214 Proceed(); |
214 } | 215 } |
215 } else { | 216 } else { |
216 ChromeInterstitialPage::Observe(type, source, details); | 217 ChromeInterstitialPage::Observe(type, source, details); |
217 } | 218 } |
218 } | 219 } |
219 | 220 |
220 bool OfflineLoadPage::ShowActivationMessage() { | 221 bool OfflineLoadPage::ShowActivationMessage() { |
221 CrosLibrary* cros = CrosLibrary::Get(); | 222 CrosLibrary* cros = CrosLibrary::Get(); |
222 if (!cros || !cros->GetNetworkLibrary()->cellular_available()) | 223 if (!cros || !cros->GetNetworkLibrary()->cellular_available()) |
223 return false; | 224 return false; |
224 | 225 |
225 const CellularNetworkVector& cell_networks = | 226 const CellularNetworkVector& cell_networks = |
226 cros->GetNetworkLibrary()->cellular_networks(); | 227 cros->GetNetworkLibrary()->cellular_networks(); |
227 for (size_t i = 0; i < cell_networks.size(); ++i) { | 228 for (size_t i = 0; i < cell_networks.size(); ++i) { |
228 chromeos::ActivationState activation_state = | 229 chromeos::ActivationState activation_state = |
229 cell_networks[i]->activation_state(); | 230 cell_networks[i]->activation_state(); |
230 if (activation_state == ACTIVATION_STATE_ACTIVATED) | 231 if (activation_state == ACTIVATION_STATE_ACTIVATED) |
231 return false; | 232 return false; |
232 } | 233 } |
233 return true; | 234 return true; |
234 } | 235 } |
235 | 236 |
236 } // namespace chromeos | 237 } // namespace chromeos |
OLD | NEW |