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