| Index: components/data_reduction_proxy/content/browser/data_reduction_proxy_blocking_page.h
|
| diff --git a/components/data_reduction_proxy/content/browser/data_reduction_proxy_blocking_page.h b/components/data_reduction_proxy/content/browser/data_reduction_proxy_blocking_page.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..89c130984fc5d0f377f1391c246e6bb530e66e0b
|
| --- /dev/null
|
| +++ b/components/data_reduction_proxy/content/browser/data_reduction_proxy_blocking_page.h
|
| @@ -0,0 +1,176 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_DATA_REDUCTION_PROXY_BLOCKING_PAGE_H_
|
| +#define COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_DATA_REDUCTION_PROXY_BLOCKING_PAGE_H_
|
| +
|
| +#include <map>
|
| +#include <string>
|
| +#include <vector>
|
| +
|
| +#include "components/data_reduction_proxy/content/browser/data_reduction_proxy_ui_manager.h"
|
| +#include "content/public/browser/interstitial_page_delegate.h"
|
| +#include "url/gurl.h"
|
| +
|
| +namespace base {
|
| +class SingleThreadTaskRunner;
|
| +}
|
| +
|
| +namespace content {
|
| +class InterstitialPage;
|
| +class WebContents;
|
| +}
|
| +
|
| +namespace data_reduction_proxy {
|
| +
|
| +class DataReductionProxyBlockingPageFactory;
|
| +class DataReductionProxyUIManager;
|
| +
|
| +// When a user is about to visit a page and the the Data Reduction Proxy
|
| +// bypasses this class show an interstitial page with some options (go back,
|
| +// continue) to alert the user of the bypass.
|
| +//
|
| +// The DataReductionProxyBlockingPage is created by the
|
| +// DataReductionProxyUIManager on the UI thread when it has been determined that
|
| +// a page will be bypassed. The operation of the blocking page occurs on the UI
|
| +// thread, where it waits for the user to make a decision about what to do:
|
| +// either go back or continue on.
|
| +//
|
| +// The blocking page forwards the result of the user's choice back to the
|
| +// DataReductionProxyUIManager so that the request can be canceled for the new
|
| +// page, or allowed to continue.
|
| +//
|
| +// A web page may contain several resources flagged as blacklisted. This
|
| +// only results in one interstitial being shown. If the user decides to proceed
|
| +// in the first interstitial, we will not display another intersitial for a
|
| +// predetermined amount of time.
|
| +class DataReductionProxyBlockingPage
|
| + : public content::InterstitialPageDelegate {
|
| + public:
|
| + typedef DataReductionProxyUIManager::BypassResource BypassResource;
|
| + typedef std::vector<BypassResource> BypassResourceList;
|
| + typedef std::map<content::WebContents*, BypassResourceList> BypassResourceMap;
|
| +
|
| + virtual ~DataReductionProxyBlockingPage();
|
| +
|
| + // Creates a blocking page. Use ShowBlockingPage when access to the blocking
|
| + // page directly isn't needed.
|
| + static DataReductionProxyBlockingPage* CreateBlockingPage(
|
| + DataReductionProxyUIManager* ui_manager,
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
|
| + content::WebContents* web_contents,
|
| + const BypassResource& bypass_resource);
|
| +
|
| + // Shows a blocking page warning about a Data Reduction Proxy bypass for a
|
| + // specific resource. You can call this method several times, if an
|
| + // interstitial is already showing, the new one will be queued and displayed
|
| + // if the user decides to proceed on the currently showing interstitial.
|
| + static void ShowBlockingPage(
|
| + DataReductionProxyUIManager* ui_manager,
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
|
| + const BypassResource& bypass_resource);
|
| +
|
| + content::InterstitialPage* interstitial_page() const;
|
| +
|
| + // Makes the passed |factory| the factory used to instantiate
|
| + // DataReductionProxyBlockingPage objects. Useful for tests.
|
| + static void RegisterFactory(DataReductionProxyBlockingPageFactory* factory) {
|
| + factory_ = factory;
|
| + }
|
| +
|
| + // InterstitialPageDelegate methods:
|
| + virtual std::string GetHTMLContents() override;
|
| + virtual void OnProceed() override;
|
| + virtual void OnDontProceed() override;
|
| + virtual void CommandReceived(const std::string& command) override;
|
| +
|
| + protected:
|
| + friend class DataReductionProxyBlockingPageFactoryImpl;
|
| +
|
| + enum BlockingPageEvent {
|
| + SHOW,
|
| + PROCEED,
|
| + DONT_PROCEED,
|
| + };
|
| +
|
| + // Don't instantiate this class directly, use ShowBlockingPage instead.
|
| + DataReductionProxyBlockingPage(
|
| + DataReductionProxyUIManager* ui_manager,
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
|
| + content::WebContents* web_contents,
|
| + const BypassResourceList& resource_list);
|
| +
|
| + // Creates the InterstitialPage and shows it.
|
| + void Show();
|
| +
|
| + // A list of DataReductionProxyUIManager::BypassResource for a tab that the
|
| + // user should be warned about. They are queued when displaying more than one
|
| + // interstitial at a time.
|
| + static BypassResourceMap* GetBypassResourcesMap();
|
| +
|
| + // Prevents creating the actual interstitial view for testing.
|
| + void DontCreateViewForTesting();
|
| +
|
| + // Notifies the DataReductionProxyUIManager on the IO thread whether to
|
| + // proceed or not for the |resources|.
|
| + static void NotifyDataReductionProxyUIManager(
|
| + DataReductionProxyUIManager* ui_manager,
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
|
| + const BypassResourceList& resource_list, bool proceed);
|
| +
|
| + // Returns true if the passed |bypass_resources| is blocking the load of
|
| + // the main page.
|
| + static bool IsMainPageLoadBlocked(const BypassResourceList& resource_list);
|
| +
|
| + // For reporting back user actions.
|
| + DataReductionProxyUIManager* ui_manager_;
|
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
|
| +
|
| + // True if the interstitial is blocking the main page because it is on one
|
| + // of our lists. False if a subresource is being blocked, or in the case of
|
| + // client-side detection where the interstitial is shown after page load
|
| + // finishes.
|
| + bool is_main_frame_load_blocked_;
|
| +
|
| + // The index of a navigation entry that should be removed when DontProceed()
|
| + // is invoked, -1 if not entry should be removed.
|
| + int navigation_entry_index_to_remove_;
|
| +
|
| + // The list of bypassed resources this page is warning about.
|
| + BypassResourceList resource_list_;
|
| +
|
| + bool proceeded_;
|
| +
|
| + content::WebContents* web_contents_;
|
| + GURL url_;
|
| + content::InterstitialPage* interstitial_page_; // Owns us
|
| +
|
| + // The factory used to instantiate DataReductionProxyBlockingPage objects.
|
| + // Useful for tests, so they can provide their own implementation of
|
| + // DataReductionProxyBlockingPage.
|
| + static DataReductionProxyBlockingPageFactory* factory_;
|
| +
|
| + private:
|
| + // Whether the interstitial should create a view.
|
| + bool create_view_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(DataReductionProxyBlockingPage);
|
| +};
|
| +
|
| +// Factory for creating DataReductionProxyBlockingPage. Useful for tests.
|
| +class DataReductionProxyBlockingPageFactory {
|
| + public:
|
| + virtual ~DataReductionProxyBlockingPageFactory() { }
|
| +
|
| + virtual DataReductionProxyBlockingPage* CreateDataReductionProxyPage(
|
| + DataReductionProxyUIManager* ui_manager,
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
|
| + content::WebContents* web_contents,
|
| + const DataReductionProxyBlockingPage::BypassResourceList&
|
| + resource_list) = 0;
|
| +};
|
| +
|
| +} // namespace data_reduction_proxy
|
| +
|
| +#endif // COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_DATA_REDUCTION_PROXY_BLOCKING_PAGE_H_
|
|
|