offline_load_page.h revision 201ade2fbba22bfb27ae029f4d23fca6ded109a0
1// Copyright (c) 2010 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#pragma once 8 9#include <string> 10 11#include "base/task.h" 12#include "chrome/browser/chromeos/network_state_notifier.h" 13#include "chrome/browser/tab_contents/interstitial_page.h" 14#include "chrome/common/notification_observer.h" 15#include "chrome/common/notification_service.h" 16 17class DictionaryValue; 18class Extension; 19class TabContents; 20 21namespace chromeos { 22 23// OfflineLoadPage class shows the interstitial page that is shown 24// when no network is available and hides when some network (either 25// one of wifi, 3g or ethernet) becomes available. 26// It deletes itself when the interstitial page is closed. 27class OfflineLoadPage : public InterstitialPage { 28 public: 29 // A delegate class that is called when the interstitinal page 30 // is closed. 31 class Delegate { 32 public: 33 Delegate() {} 34 virtual ~Delegate() {} 35 // Called when a user selected to proceed or not to proceed 36 // with loading. 37 virtual void OnBlockingPageComplete(bool proceed) = 0; 38 39 private: 40 DISALLOW_COPY_AND_ASSIGN(Delegate); 41 }; 42 static void Show(int process_host_id, int render_view_id, 43 const GURL& url, Delegate* delegate); 44 // Import show here so that overloading works. 45 using InterstitialPage::Show; 46 47 protected: 48 // Create a offline load page for the |tab_contents|. 49 OfflineLoadPage(TabContents* tab_contents, const GURL& url, 50 Delegate* delegate); 51 virtual ~OfflineLoadPage() {} 52 53 // Only for testing. 54 void EnableTest() { 55 in_test_ = true; 56 } 57 58 private: 59 // InterstitialPage implementation. 60 virtual std::string GetHTMLContents(); 61 virtual void CommandReceived(const std::string& command); 62 virtual void Proceed(); 63 virtual void DontProceed(); 64 65 // Overrides InterstitialPage's Observe. 66 virtual void Observe(NotificationType type, 67 const NotificationSource& source, 68 const NotificationDetails& details); 69 70 // Retrieves template strings of the offline page for app and 71 // normal site. 72 void GetAppOfflineStrings(const Extension* app, 73 const string16& faield_url, 74 DictionaryValue* strings) const; 75 void GetNormalOfflineStrings(const string16& faield_url, 76 DictionaryValue* strings) const; 77 78 // Really proceed with loading. 79 void DoProceed(); 80 81 Delegate* delegate_; 82 NotificationRegistrar registrar_; 83 84 // True if the proceed is chosen. 85 bool proceeded_; 86 ScopedRunnableMethodFactory<OfflineLoadPage> method_factory_; 87 88 bool in_test_; 89 90 DISALLOW_COPY_AND_ASSIGN(OfflineLoadPage); 91}; 92 93} // namespace chromeos 94 95#endif // CHROME_BROWSER_CHROMEOS_OFFLINE_OFFLINE_LOAD_PAGE_H_ 96