offline_load_page.h revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_CHROMEOS_OFFLINE_OFFLINE_LOAD_PAGE_H_ 6#define CHROME_BROWSER_CHROMEOS_OFFLINE_OFFLINE_LOAD_PAGE_H_ 7 8#include <string> 9 10#include "base/callback.h" 11#include "base/compiler_specific.h" 12#include "content/public/browser/interstitial_page_delegate.h" 13#include "net/base/network_change_notifier.h" 14#include "url/gurl.h" 15 16namespace base { 17class DictionaryValue; 18} 19 20namespace content { 21class InterstitialPage; 22class WebContents; 23} 24 25namespace extensions { 26class Extension; 27} 28 29namespace chromeos { 30 31// OfflineLoadPage class shows the interstitial page that is shown 32// when no network is available and hides when some network (either 33// one of wifi, 3g or ethernet) becomes available. 34// It deletes itself when the interstitial page is closed. 35class OfflineLoadPage 36 : public content::InterstitialPageDelegate, 37 public net::NetworkChangeNotifier::ConnectionTypeObserver { 38 public: 39 // Passed a boolean indicating whether or not it is OK to proceed with the 40 // page load. 41 typedef base::Callback<void(bool /*proceed*/)> CompletionCallback; 42 43 // Create a offline load page for the |web_contents|. The callback will be 44 // run on the IO thread. 45 OfflineLoadPage(content::WebContents* web_contents, const GURL& url, 46 const CompletionCallback& callback); 47 48 void Show(); 49 50 protected: 51 virtual ~OfflineLoadPage(); 52 53 // Overridden by tests. 54 virtual void NotifyBlockingPageComplete(bool proceed); 55 56 private: 57 friend class TestOfflineLoadPage; 58 59 // InterstitialPageDelegate implementation. 60 virtual std::string GetHTMLContents() OVERRIDE; 61 virtual void CommandReceived(const std::string& command) OVERRIDE; 62 virtual void OverrideRendererPrefs( 63 content::RendererPreferences* prefs) OVERRIDE; 64 virtual void OnProceed() OVERRIDE; 65 virtual void OnDontProceed() OVERRIDE; 66 67 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. 68 virtual void OnConnectionTypeChanged( 69 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; 70 71 // Retrieves template strings of the offline page for app and 72 // normal site. 73 void GetAppOfflineStrings(const extensions::Extension* app, 74 base::DictionaryValue* strings) const; 75 void GetNormalOfflineStrings(base::DictionaryValue* strings) const; 76 77 // True if there is a mobile network is available but 78 // has not been activated. 79 bool ShowActivationMessage(); 80 81 CompletionCallback callback_; 82 83 // True if the proceed is chosen. 84 bool proceeded_; 85 86 content::WebContents* web_contents_; 87 GURL url_; 88 content::InterstitialPage* interstitial_page_; // Owns us. 89 90 DISALLOW_COPY_AND_ASSIGN(OfflineLoadPage); 91}; 92 93} // namespace chromeos 94 95#endif // CHROME_BROWSER_CHROMEOS_OFFLINE_OFFLINE_LOAD_PAGE_H_ 96