Commit 598b6bee authored by Ryan Sturm's avatar Ryan Sturm Committed by Commit Bot

Adding a previews state check to offline s13n

This allows Offline previews to work after network s13n is turned on.

Bug: 842233
Change-Id: I9cc97a29308b25490a5ea1b97b353aada82cccf0
Reviewed-on: https://chromium-review.googlesource.com/c/1297472Reviewed-by: default avatarJian Li <jianli@chromium.org>
Commit-Queue: Ryan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602515}
parent fa8fe00b
......@@ -1309,6 +1309,10 @@ void OfflinePageURLLoaderBuilder::InterceptRequestOnIO(
network::ResourceRequest request =
CreateResourceRequest(url, method, extra_headers, is_main_frame);
request.previews_state = test_base_->allow_preview()
? content::OFFLINE_PAGE_ON
: content::PREVIEWS_OFF;
url_loader_ = OfflinePageURLLoader::Create(
navigation_ui_data_.get(),
test_base_->web_contents()->GetMainFrame()->GetFrameTreeNodeId(), request,
......@@ -1320,9 +1324,6 @@ void OfflinePageURLLoaderBuilder::InterceptRequestOnIO(
return;
url_loader_->SetTabIdGetterForTesting(base::BindRepeating(&GetTabId, kTabId));
url_loader_->SetShouldAllowPreviewCallbackForTesting(
base::BindRepeating(&OfflinePageRequestHandlerTestBase::allow_preview,
base::Unretained(test_base_)));
}
void OfflinePageURLLoaderBuilder::InterceptRequest(
......
......@@ -4,6 +4,7 @@
#include "chrome/browser/offline_pages/offline_page_url_loader.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/threading/sequenced_task_runner_handle.h"
......@@ -12,6 +13,7 @@
#include "components/offline_pages/core/offline_page_item.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/previews_state.h"
#include "mojo/public/cpp/system/simple_watcher.h"
#include "net/base/io_buffer.h"
#include "net/url_request/url_request.h"
......@@ -86,6 +88,8 @@ OfflinePageURLLoader::OfflinePageURLLoader(
transition_type_(tentative_resource_request.transition_type),
loader_callback_(std::move(callback)),
binding_(this),
is_offline_preview_allowed_(tentative_resource_request.previews_state &
content::OFFLINE_PAGE_ON),
weak_ptr_factory_(this) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
......@@ -106,11 +110,6 @@ void OfflinePageURLLoader::SetTabIdGetterForTesting(
tab_id_getter_ = tab_id_getter;
}
void OfflinePageURLLoader::SetShouldAllowPreviewCallbackForTesting(
ShouldAllowPreviewCallback should_allow_preview_callback) {
should_allow_preview_callback_ = should_allow_preview_callback;
}
void OfflinePageURLLoader::FollowRedirect(
const base::Optional<std::vector<std::string>>&
to_be_removed_request_headers,
......@@ -210,11 +209,7 @@ void OfflinePageURLLoader::SetOfflinePageNavigationUIData(
}
bool OfflinePageURLLoader::ShouldAllowPreview() const {
// TODO(jianli): This is a temporary hack to make the tests pass. The real
// logic needs to be implemented.
if (!should_allow_preview_callback_.is_null())
return should_allow_preview_callback_.Run();
return false;
return is_offline_preview_allowed_;
}
int OfflinePageURLLoader::GetPageTransition() const {
......
......@@ -48,10 +48,6 @@ class OfflinePageURLLoader : public network::mojom::URLLoader,
void SetTabIdGetterForTesting(
OfflinePageRequestHandler::Delegate::TabIdGetter tab_id_getter);
using ShouldAllowPreviewCallback = base::RepeatingCallback<bool(void)>;
void SetShouldAllowPreviewCallbackForTesting(
ShouldAllowPreviewCallback should_allow_preview_callback);
private:
OfflinePageURLLoader(
content::NavigationUIData* navigation_ui_data,
......@@ -116,7 +112,7 @@ class OfflinePageURLLoader : public network::mojom::URLLoader,
std::unique_ptr<mojo::SimpleWatcher> handle_watcher_;
OfflinePageRequestHandler::Delegate::TabIdGetter tab_id_getter_;
ShouldAllowPreviewCallback should_allow_preview_callback_;
bool is_offline_preview_allowed_;
base::WeakPtrFactory<OfflinePageURLLoader> weak_ptr_factory_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment