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