supervised_user_interstitial.h revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
1// Copyright 2014 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_SUPERVISED_USER_SUPERVISED_USER_INTERSTITIAL_H_
6#define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_INTERSTITIAL_H_
7
8#include <string>
9
10#include "base/callback.h"
11#include "base/prefs/pref_change_registrar.h"
12#include "content/public/browser/interstitial_page_delegate.h"
13#include "url/gurl.h"
14
15namespace content {
16class InterstitialPage;
17class WebContents;
18}
19
20// Delegate for an interstitial page when a page is blocked for a supervised
21// user because it is on a blacklist (in "allow everything" mode) or not on any
22// whitelist (in "allow only specified sites" mode).
23class SupervisedUserInterstitial : public content::InterstitialPageDelegate {
24 public:
25  static void Show(content::WebContents* web_contents,
26                   const GURL& url,
27                   const base::Callback<void(bool)>& callback);
28
29 private:
30  SupervisedUserInterstitial(content::WebContents* web_contents,
31                             const GURL& url,
32                             const base::Callback<void(bool)>& callback);
33  virtual ~SupervisedUserInterstitial();
34
35  bool Init();
36
37  // InterstitialPageDelegate implementation.
38  virtual std::string GetHTMLContents() OVERRIDE;
39  virtual void CommandReceived(const std::string& command) OVERRIDE;
40  virtual void OnProceed() OVERRIDE;
41  virtual void OnDontProceed() OVERRIDE;
42
43  // Returns whether the blocked URL is now allowed. Called initially before the
44  // interstitial is shown (to catch race conditions), or when the URL filtering
45  // prefs change.
46  bool ShouldProceed();
47
48  void OnFilteringPrefsChanged();
49  void DispatchContinueRequest(bool continue_request);
50
51  // Owns the interstitial, which owns us.
52  content::WebContents* web_contents_;
53
54  content::InterstitialPage* interstitial_page_;  // Owns us.
55
56  PrefChangeRegistrar pref_change_registrar_;
57
58  GURL url_;
59
60  base::Callback<void(bool)> callback_;
61
62  DISALLOW_COPY_AND_ASSIGN(SupervisedUserInterstitial);
63};
64
65#endif  // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_INTERSTITIAL_H_
66