Chromium Code Reviews| Index: components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_blocking_page.h |
| diff --git a/components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_blocking_page.h b/components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_blocking_page.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..68bf928015a9061a480af8a9110eef3548aa17cf |
| --- /dev/null |
| +++ b/components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_blocking_page.h |
| @@ -0,0 +1,183 @@ |
| +// 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_debug_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 DataReductionProxyDebugBlockingPageFactory; |
| +class DataReductionProxyDebugUIManager; |
| + |
| +// When a user is about to visit a page and the the Data Reduction Proxy |
|
bengr
2015/02/05 01:30:08
the the -> the
megjablon
2015/02/13 01:48:08
Done.
|
| +// bypasses this class show an interstitial page with some options (go back, |
|
bengr
2015/02/05 01:30:09
class -> class,
megjablon
2015/02/13 01:48:08
Done.
|
| +// continue) to alert the user of the bypass. |
| +// |
| +// The DataReductionProxyDebugBlockingPage is created by the |
| +// DataReductionProxyDebugUIManager 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 |
| +// DataReductionProxyDebugUIManager 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 |
|
bengr
2015/02/05 01:30:09
Remove "we" from comments.
megjablon
2015/02/13 01:48:08
Done.
|
| +// predetermined amount of time. |
| +class DataReductionProxyDebugBlockingPage |
| + : public content::InterstitialPageDelegate { |
| + public: |
| + typedef DataReductionProxyDebugUIManager::BypassResource BypassResource; |
| + typedef std::vector<BypassResource> BypassResourceList; |
| + typedef std::map<content::WebContents*, BypassResourceList> BypassResourceMap; |
| + |
| + virtual ~DataReductionProxyDebugBlockingPage(); |
| + |
| + // Creates a blocking page. Use ShowBlockingPage when access to the blocking |
| + // page directly isn't needed. |
| + static DataReductionProxyDebugBlockingPage* CreateBlockingPage( |
| + DataReductionProxyDebugUIManager* ui_manager, |
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| + content::WebContents* web_contents, |
| + const BypassResource& bypass_resource, |
| + const std::string& app_locale); |
| + |
| + // Shows a blocking page warning about a Data Reduction Proxy bypass for a |
| + // specific resource. You can call this method several times, if an |
|
bengr
2015/02/05 01:30:09
This method can be called several times...
megjablon
2015/02/13 01:48:08
Done.
|
| + // 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( |
| + DataReductionProxyDebugUIManager* ui_manager, |
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| + const BypassResource& bypass_resource, |
| + const std::string& app_locale); |
| + |
| + content::InterstitialPage* interstitial_page() const; |
| + |
| + // Makes the passed |factory| the factory used to instantiate |
|
bengr
2015/02/05 01:30:08
Makes |factory| the...
megjablon
2015/02/13 01:48:08
Done.
|
| + // DataReductionProxyDebugBlockingPage objects. Useful for tests. |
| + static void RegisterFactory( |
| + DataReductionProxyDebugBlockingPageFactory* factory) { |
| + factory_ = factory; |
| + } |
| + |
| + // InterstitialPageDelegate methods: |
|
bengr
2015/02/05 01:30:09
methods -> overrides
megjablon
2015/02/13 01:48:08
Done.
|
| + virtual std::string GetHTMLContents() override; |
| + virtual void OnProceed() override; |
| + virtual void OnDontProceed() override; |
| + virtual void CommandReceived(const std::string& command) override; |
| + |
| + protected: |
| + friend class DataReductionProxyDebugBlockingPageFactoryImpl; |
| + |
| + enum BlockingPageEvent { |
| + SHOW, |
| + PROCEED, |
| + DONT_PROCEED, |
| + }; |
| + |
| + // Don't instantiate this class directly, use ShowBlockingPage instead. |
| + DataReductionProxyDebugBlockingPage( |
|
bengr
2015/02/05 01:30:09
Can this be private?
Also say "This constructor s
megjablon
2015/02/13 01:48:07
Can't be private because the factory uses it.
|
| + DataReductionProxyDebugUIManager* ui_manager, |
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| + content::WebContents* web_contents, |
| + const BypassResourceList& resource_list, |
| + const std::string& app_locale); |
| + |
| + // Creates the InterstitialPage and shows it. |
| + void Show(); |
| + |
| + // A list of DataReductionProxyDebugUIManager::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 DataReductionProxyDebugUIManager on the IO thread whether to |
| + // proceed or not for the |resources|. |
| + static void NotifyDataReductionProxyDebugUIManager( |
| + DataReductionProxyDebugUIManager* 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. |
| + DataReductionProxyDebugUIManager* 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 |
|
bengr
2015/02/05 01:30:08
Who is us? Don't personify code.
megjablon
2015/02/13 01:48:08
Done.
|
| + |
| + // The factory used to instantiate DataReductionProxyDebugBlockingPage |
| + // objects. Useful for tests, so they can provide their own implementation of |
| + // DataReductionProxyDebugBlockingPage. |
| + static DataReductionProxyDebugBlockingPageFactory* factory_; |
| + |
| + private: |
| + // Whether the interstitial should create a view. |
|
bengr
2015/02/05 01:30:09
Comments should be complete sentences.
megjablon
2015/02/13 01:48:08
Done.
|
| + bool create_view_; |
| + |
| + const std::string& app_locale_; |
|
bengr
2015/02/05 01:30:09
Add comments for all member variables.
megjablon
2015/02/13 01:48:08
Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(DataReductionProxyDebugBlockingPage); |
|
bengr
2015/02/05 01:30:09
#include base/macros.h
megjablon
2015/02/13 01:48:08
Done.
|
| +}; |
| + |
| +// Factory for creating DataReductionProxyDebugBlockingPage. Useful for tests. |
|
bengr
2015/02/05 01:30:09
Why not move this to the tests?
megjablon
2015/02/13 01:48:08
As commented, this is how the other interstitials
|
| +class DataReductionProxyDebugBlockingPageFactory { |
| + public: |
| + virtual ~DataReductionProxyDebugBlockingPageFactory() { } |
| + |
| + virtual DataReductionProxyDebugBlockingPage* CreateDataReductionProxyPage( |
| + DataReductionProxyDebugUIManager* ui_manager, |
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| + content::WebContents* web_contents, |
| + const DataReductionProxyDebugBlockingPage::BypassResourceList& |
| + resource_list, |
| + const std::string& app_locale) = 0; |
| +}; |
| + |
| +} // namespace data_reduction_proxy |
| + |
| +#endif // COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_DATA_REDUCTION_PROXY_BLOCKING_PAGE_H_ |