summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormegjablon <megjablon@chromium.org>2015-10-22 16:56:12 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-22 23:56:54 +0000
commitd5ac7d52b323d04178bba9cc746c623438d48751 (patch)
tree7097e23007daea9b2678df9f389acb1e95ac3600
parent20f6367b6cd95ead067a0716709bdb2afa776be9 (diff)
downloadchromium_src-d5ac7d52b323d04178bba9cc746c623438d48751.zip
chromium_src-d5ac7d52b323d04178bba9cc746c623438d48751.tar.gz
chromium_src-d5ac7d52b323d04178bba9cc746c623438d48751.tar.bz2
Consistently use LoFi for an entire page
Store the LoFi state in the renderer and use that state to add LoFi request headers when appropriate. Introduce a state variable that has three values: LOFI_DEFAULT, LOFI_ON, and LOFI_OFF. The snackbar triggering does not use this state yet, but still looks at the last mainframe LoFi value. Single image loads also use the bypass cache flag up to willSendRequest. These will be fixed in follow up cls. The LoFi state is not preserved from navigation to navigation, and iframes inherit the status. Renderer initiated navigations always start with state LOFI_DEFAULT whereas browser initiated navigations can force LOFI_ON or LOFI_OFF. BUG=524652 Review URL: https://codereview.chromium.org/1310743003 Cr-Commit-Position: refs/heads/master@{#355679}
-rw-r--r--chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc13
-rw-r--r--chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h3
-rw-r--r--chrome/renderer/page_load_histograms.cc5
-rw-r--r--components/data_reduction_proxy/content/browser/content_lofi_decider.cc7
-rw-r--r--content/browser/frame_host/navigation_controller_impl.cc3
-rw-r--r--content/browser/frame_host/navigation_controller_impl.h1
-rw-r--r--content/browser/frame_host/navigation_entry_impl.cc5
-rw-r--r--content/browser/frame_host/navigation_entry_impl.h3
-rw-r--r--content/browser/frame_host/navigation_request.cc3
-rw-r--r--content/browser/frame_host/navigator_impl.cc10
-rw-r--r--content/browser/frame_host/render_frame_host_impl.cc3
-rw-r--r--content/browser/loader/resource_dispatcher_host_browsertest.cc217
-rw-r--r--content/browser/loader/resource_dispatcher_host_impl.cc32
-rw-r--r--content/browser/loader/resource_loader.cc4
-rw-r--r--content/browser/loader/resource_request_info_impl.cc13
-rw-r--r--content/browser/loader/resource_request_info_impl.h5
-rw-r--r--content/child/request_extra_data.cc3
-rw-r--r--content/child/request_extra_data.h8
-rw-r--r--content/child/resource_dispatcher.cc2
-rw-r--r--content/child/web_url_loader_impl.cc1
-rw-r--r--content/child/weburlresponse_extradata_impl.h4
-rw-r--r--content/common/frame_messages.h4
-rw-r--r--content/common/navigation_params.cc9
-rw-r--r--content/common/navigation_params.h19
-rw-r--r--content/common/resource_messages.h6
-rw-r--r--content/public/browser/navigation_controller.h6
-rw-r--r--content/public/browser/resource_dispatcher_host_delegate.cc6
-rw-r--r--content/public/browser/resource_dispatcher_host_delegate.h5
-rw-r--r--content/public/browser/resource_request_info.h3
-rw-r--r--content/public/common/resource_response_info.cc3
-rw-r--r--content/public/common/resource_response_info.h3
-rw-r--r--content/public/renderer/render_frame.h3
-rw-r--r--content/public/test/render_view_test.cc6
-rw-r--r--content/renderer/render_frame_impl.cc23
-rw-r--r--content/renderer/render_frame_impl.h4
-rw-r--r--content/test/data/image.jpg1
-rw-r--r--content/test/data/page_with_iframe.html8
37 files changed, 420 insertions, 34 deletions
diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
index a08f0c0..07850a8 100644
--- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
+++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
@@ -34,6 +34,7 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
#include "components/google/core/browser/google_util.h"
#include "components/variations/net/variations_http_header_provider.h"
#include "content/public/browser/browser_thread.h"
@@ -721,6 +722,18 @@ void ChromeResourceDispatcherHostDelegate::RequestComplete(
}
}
+bool ChromeResourceDispatcherHostDelegate::ShouldEnableLoFiMode(
+ const net::URLRequest& url_request,
+ content::ResourceContext* resource_context) {
+ ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
+ data_reduction_proxy::DataReductionProxyIOData* data_reduction_proxy_io_data =
+ io_data->data_reduction_proxy_io_data();
+
+ if (data_reduction_proxy_io_data)
+ return data_reduction_proxy_io_data->ShouldEnableLoFiMode(url_request);
+ return false;
+}
+
// static
void ChromeResourceDispatcherHostDelegate::
SetExternalProtocolHandlerDelegateForTesting(
diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h
index 5101ce2..59abdb93 100644
--- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h
+++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h
@@ -76,6 +76,9 @@ class ChromeResourceDispatcherHostDelegate
content::ResourceContext* resource_context,
content::ResourceResponse* response) override;
void RequestComplete(net::URLRequest* url_request) override;
+ bool ShouldEnableLoFiMode(
+ const net::URLRequest& url_request,
+ content::ResourceContext* resource_context) override;
// Called on the UI thread. Allows switching out the
// ExternalProtocolHandler::Delegate for testing code.
diff --git a/chrome/renderer/page_load_histograms.cc b/chrome/renderer/page_load_histograms.cc
index 768798b..57bc17a 100644
--- a/chrome/renderer/page_load_histograms.cc
+++ b/chrome/renderer/page_load_histograms.cc
@@ -921,11 +921,14 @@ void PageLoadHistograms::Dump(WebFrame* frame) {
MaybeDumpFirstLayoutHistograms();
+ content::RenderFrame* render_frame =
+ content::RenderFrame::FromWebFrame(frame);
+
// Metrics based on the timing information recorded for the Navigation Timing
// API - http://www.w3.org/TR/navigation-timing/.
DumpHistograms(
frame->performance(), document_state, data_reduction_proxy_was_used,
- false /* TODO: render_frame->IsUsingLoFi() */, came_from_websearch,
+ render_frame && render_frame->IsUsingLoFi(), came_from_websearch,
websearch_chrome_joint_experiment_id, is_preview, scheme_type);
// Old metrics based on the timing information stored in DocumentState. These
diff --git a/components/data_reduction_proxy/content/browser/content_lofi_decider.cc b/components/data_reduction_proxy/content/browser/content_lofi_decider.cc
index 6a83c75..0132add 100644
--- a/components/data_reduction_proxy/content/browser/content_lofi_decider.cc
+++ b/components/data_reduction_proxy/content/browser/content_lofi_decider.cc
@@ -4,6 +4,8 @@
#include "components/data_reduction_proxy/content/browser/content_lofi_decider.h"
+#include "content/public/browser/resource_request_info.h"
+
namespace data_reduction_proxy {
ContentLoFiDecider::ContentLoFiDecider() {}
@@ -11,7 +13,10 @@ ContentLoFiDecider::ContentLoFiDecider() {}
ContentLoFiDecider::~ContentLoFiDecider() {}
bool ContentLoFiDecider::IsUsingLoFiMode(const net::URLRequest& request) const {
- // TODO: will be check of ResourceRequestInfo::IsUsingLoFi
+ const content::ResourceRequestInfo* request_info =
+ content::ResourceRequestInfo::ForRequest(&request);
+ if (request_info)
+ return request_info->IsUsingLoFi();
return false;
}
diff --git a/content/browser/frame_host/navigation_controller_impl.cc b/content/browser/frame_host/navigation_controller_impl.cc
index b0871f7..a6a7a9d 100644
--- a/content/browser/frame_host/navigation_controller_impl.cc
+++ b/content/browser/frame_host/navigation_controller_impl.cc
@@ -288,6 +288,9 @@ void NavigationControllerImpl::ReloadIgnoringCache(bool check_for_repost) {
void NavigationControllerImpl::ReloadOriginalRequestURL(bool check_for_repost) {
ReloadInternal(check_for_repost, RELOAD_ORIGINAL_REQUEST_URL);
}
+void NavigationControllerImpl::ReloadDisableLoFi(bool check_for_repost) {
+ ReloadInternal(check_for_repost, RELOAD_DISABLE_LOFI_MODE);
+}
void NavigationControllerImpl::ReloadInternal(bool check_for_repost,
ReloadType reload_type) {
diff --git a/content/browser/frame_host/navigation_controller_impl.h b/content/browser/frame_host/navigation_controller_impl.h
index 736f637..fe387b1 100644
--- a/content/browser/frame_host/navigation_controller_impl.h
+++ b/content/browser/frame_host/navigation_controller_impl.h
@@ -83,6 +83,7 @@ class CONTENT_EXPORT NavigationControllerImpl
void Reload(bool check_for_repost) override;
void ReloadIgnoringCache(bool check_for_repost) override;
void ReloadOriginalRequestURL(bool check_for_repost) override;
+ void ReloadDisableLoFi(bool check_for_repost) override;
void NotifyEntryChanged(const NavigationEntry* entry) override;
void CopyStateFrom(const NavigationController& source) override;
void CopyStateFromAndPrune(NavigationController* source,
diff --git a/content/browser/frame_host/navigation_entry_impl.cc b/content/browser/frame_host/navigation_entry_impl.cc
index 1adb2be..3b1f6d8 100644
--- a/content/browser/frame_host/navigation_entry_impl.cc
+++ b/content/browser/frame_host/navigation_entry_impl.cc
@@ -441,7 +441,8 @@ CommonNavigationParams NavigationEntryImpl::ConstructCommonNavigationParams(
const GURL& dest_url,
const Referrer& dest_referrer,
const FrameNavigationEntry& frame_entry,
- FrameMsg_Navigate_Type::Value navigation_type) const {
+ FrameMsg_Navigate_Type::Value navigation_type,
+ LoFiState lofi_state) const {
FrameMsg_UILoadMetricsReportType::Value report_type =
FrameMsg_UILoadMetricsReportType::NO_REPORT;
base::TimeTicks ui_timestamp = base::TimeTicks();
@@ -454,7 +455,7 @@ CommonNavigationParams NavigationEntryImpl::ConstructCommonNavigationParams(
return CommonNavigationParams(
dest_url, dest_referrer, GetTransitionType(), navigation_type,
!IsViewSourceMode(), should_replace_entry(), ui_timestamp, report_type,
- GetBaseURLForDataURL(), GetHistoryURLForDataURL());
+ GetBaseURLForDataURL(), GetHistoryURLForDataURL(), lofi_state);
}
StartNavigationParams NavigationEntryImpl::ConstructStartNavigationParams()
diff --git a/content/browser/frame_host/navigation_entry_impl.h b/content/browser/frame_host/navigation_entry_impl.h
index 8aec815..71dc8a3 100644
--- a/content/browser/frame_host/navigation_entry_impl.h
+++ b/content/browser/frame_host/navigation_entry_impl.h
@@ -147,7 +147,8 @@ class CONTENT_EXPORT NavigationEntryImpl
const GURL& dest_url,
const Referrer& dest_referrer,
const FrameNavigationEntry& frame_entry,
- FrameMsg_Navigate_Type::Value navigation_type) const;
+ FrameMsg_Navigate_Type::Value navigation_type,
+ LoFiState lofi_state) const;
StartNavigationParams ConstructStartNavigationParams() const;
RequestNavigationParams ConstructRequestNavigationParams(
const FrameNavigationEntry& frame_entry,
diff --git a/content/browser/frame_host/navigation_request.cc b/content/browser/frame_host/navigation_request.cc
index eb7cd85..171b1b5 100644
--- a/content/browser/frame_host/navigation_request.cc
+++ b/content/browser/frame_host/navigation_request.cc
@@ -86,7 +86,8 @@ scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated(
scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest(
frame_tree_node,
entry.ConstructCommonNavigationParams(dest_url, dest_referrer,
- frame_entry, navigation_type),
+ frame_entry, navigation_type,
+ LOFI_UNSPECIFIED),
BeginNavigationParams(method, headers.ToString(),
LoadFlagFromNavigationType(navigation_type),
false, // has_user_gestures
diff --git a/content/browser/frame_host/navigator_impl.cc b/content/browser/frame_host/navigator_impl.cc
index 2e9a114e..5d9f225 100644
--- a/content/browser/frame_host/navigator_impl.cc
+++ b/content/browser/frame_host/navigator_impl.cc
@@ -53,6 +53,7 @@ FrameMsg_Navigate_Type::Value GetNavigationType(
case NavigationControllerImpl::RELOAD:
return FrameMsg_Navigate_Type::RELOAD;
case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
+ case NavigationControllerImpl::RELOAD_DISABLE_LOFI_MODE:
return FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
return FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
@@ -334,9 +335,14 @@ bool NavigatorImpl::NavigateToEntry(
// Create the navigation parameters.
FrameMsg_Navigate_Type::Value navigation_type =
GetNavigationType(controller_->GetBrowserContext(), entry, reload_type);
+ LoFiState lofi_state =
+ (reload_type ==
+ NavigationController::ReloadType::RELOAD_DISABLE_LOFI_MODE
+ ? LOFI_OFF
+ : LOFI_UNSPECIFIED);
dest_render_frame_host->Navigate(
- entry.ConstructCommonNavigationParams(dest_url, dest_referrer,
- frame_entry, navigation_type),
+ entry.ConstructCommonNavigationParams(
+ dest_url, dest_referrer, frame_entry, navigation_type, lofi_state),
entry.ConstructStartNavigationParams(),
entry.ConstructRequestNavigationParams(
frame_entry, navigation_start, is_same_document_history_load,
diff --git a/content/browser/frame_host/render_frame_host_impl.cc b/content/browser/frame_host/render_frame_host_impl.cc
index 70618ac..7868121 100644
--- a/content/browser/frame_host/render_frame_host_impl.cc
+++ b/content/browser/frame_host/render_frame_host_impl.cc
@@ -1748,7 +1748,8 @@ void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) {
CommonNavigationParams common_params(
data_url, Referrer(), ui::PAGE_TRANSITION_LINK,
FrameMsg_Navigate_Type::NORMAL, false, false, base::TimeTicks::Now(),
- FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL());
+ FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL(),
+ LOFI_OFF);
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableBrowserSideNavigation)) {
CommitNavigation(nullptr, nullptr, common_params,
diff --git a/content/browser/loader/resource_dispatcher_host_browsertest.cc b/content/browser/loader/resource_dispatcher_host_browsertest.cc
index 9b87167..f82fe7c 100644
--- a/content/browser/loader/resource_dispatcher_host_browsertest.cc
+++ b/content/browser/loader/resource_dispatcher_host_browsertest.cc
@@ -2,7 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/memory/ref_counted.h"
+#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
@@ -18,6 +21,7 @@
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
+#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_content_browser_client.h"
@@ -28,6 +32,8 @@
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/url_request/url_request_failed_job.h"
#include "net/test/url_request/url_request_mock_http_job.h"
+#include "net/url_request/url_request.h"
+#include "url/gurl.h"
using base::ASCIIToUTF16;
@@ -533,4 +539,215 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
delegate.page_transition() & ui::PAGE_TRANSITION_CLIENT_REDIRECT);
}
+namespace {
+
+// Checks whether the given urls are requested, and that IsUsingLofi() returns
+// the appropriate value when the Lo-Fi state is set.
+class LoFiModeResourceDispatcherHostDelegate
+ : public ResourceDispatcherHostDelegate {
+ public:
+ LoFiModeResourceDispatcherHostDelegate(const GURL& main_frame_url,
+ const GURL& subresource_url,
+ const GURL& iframe_url)
+ : main_frame_url_(main_frame_url),
+ subresource_url_(subresource_url),
+ iframe_url_(iframe_url),
+ main_frame_url_seen_(false),
+ subresource_url_seen_(false),
+ iframe_url_seen_(false),
+ use_lofi_(false),
+ should_enable_lofi_mode_called_(false) {}
+
+ ~LoFiModeResourceDispatcherHostDelegate() override {}
+
+ // ResourceDispatcherHostDelegate implementation:
+ void RequestBeginning(net::URLRequest* request,
+ ResourceContext* resource_context,
+ AppCacheService* appcache_service,
+ ResourceType resource_type,
+ ScopedVector<ResourceThrottle>* throttles) override {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
+ if (request->url() != main_frame_url_ && request->url() != subresource_url_
+ && request->url() != iframe_url_)
+ return;
+ if (request->url() == main_frame_url_) {
+ EXPECT_FALSE(main_frame_url_seen_);
+ main_frame_url_seen_ = true;
+ } else if (request->url() == subresource_url_) {
+ EXPECT_TRUE(main_frame_url_seen_);
+ EXPECT_FALSE(subresource_url_seen_);
+ subresource_url_seen_ = true;
+ } else if (request->url() == iframe_url_) {
+ EXPECT_TRUE(main_frame_url_seen_);
+ EXPECT_FALSE(iframe_url_seen_);
+ iframe_url_seen_ = true;
+ }
+ EXPECT_EQ(use_lofi_, info->IsUsingLoFi());
+ }
+
+ void SetDelegate() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ ResourceDispatcherHost::Get()->SetDelegate(this);
+ }
+
+ bool ShouldEnableLoFiMode(
+ const net::URLRequest& request,
+ content::ResourceContext* resource_context) override {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ EXPECT_FALSE(should_enable_lofi_mode_called_);
+ should_enable_lofi_mode_called_ = true;
+ EXPECT_EQ(main_frame_url_, request.url());
+ return use_lofi_;
+ }
+
+ void Reset(bool use_lofi) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ main_frame_url_seen_ = false;
+ subresource_url_seen_ = false;
+ iframe_url_seen_ = false;
+ use_lofi_ = use_lofi;
+ should_enable_lofi_mode_called_ = false;
+ }
+
+ void CheckResourcesRequested(bool should_enable_lofi_mode_called) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ EXPECT_EQ(should_enable_lofi_mode_called, should_enable_lofi_mode_called_);
+ EXPECT_TRUE(main_frame_url_seen_);
+ EXPECT_TRUE(subresource_url_seen_);
+ EXPECT_TRUE(iframe_url_seen_);
+ }
+
+ private:
+ const GURL main_frame_url_;
+ const GURL subresource_url_;
+ const GURL iframe_url_;
+
+ bool main_frame_url_seen_;
+ bool subresource_url_seen_;
+ bool iframe_url_seen_;
+ bool use_lofi_;
+ bool should_enable_lofi_mode_called_;
+
+ DISALLOW_COPY_AND_ASSIGN(LoFiModeResourceDispatcherHostDelegate);
+};
+
+} // namespace
+
+class LoFiResourceDispatcherHostBrowserTest : public ContentBrowserTest {
+ public:
+ ~LoFiResourceDispatcherHostBrowserTest() override {}
+
+ protected:
+ void SetUpOnMainThread() override {
+ ContentBrowserTest::SetUpOnMainThread();
+
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
+
+ delegate_.reset(new LoFiModeResourceDispatcherHostDelegate(
+ embedded_test_server()->GetURL("/page_with_iframe.html"),
+ embedded_test_server()->GetURL("/image.jpg"),
+ embedded_test_server()->GetURL("/title1.html")));
+
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&LoFiModeResourceDispatcherHostDelegate::SetDelegate,
+ base::Unretained(delegate_.get())));
+ }
+
+ void Reset(bool use_lofi) {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&LoFiModeResourceDispatcherHostDelegate::Reset,
+ base::Unretained(delegate_.get()), use_lofi));
+ }
+
+ void CheckResourcesRequested(
+ bool should_enable_lofi_mode_called) {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(
+ &LoFiModeResourceDispatcherHostDelegate::CheckResourcesRequested,
+ base::Unretained(delegate_.get()), should_enable_lofi_mode_called));
+ }
+
+ private:
+ scoped_ptr<LoFiModeResourceDispatcherHostDelegate> delegate_;
+};
+
+// Test that navigating with ShouldEnableLoFiMode returning true fetches the
+// resources with LOFI_ON.
+IN_PROC_BROWSER_TEST_F(LoFiResourceDispatcherHostBrowserTest,
+ ShouldEnableLoFiModeOn) {
+ // Navigate with ShouldEnableLoFiMode returning true.
+ Reset(true);
+ NavigateToURLBlockUntilNavigationsComplete(
+ shell(), embedded_test_server()->GetURL("/page_with_iframe.html"), 1);
+ CheckResourcesRequested(true);
+}
+
+// Test that navigating with ShouldEnableLoFiMode returning false fetches the
+// resources with LOFI_OFF.
+IN_PROC_BROWSER_TEST_F(LoFiResourceDispatcherHostBrowserTest,
+ ShouldEnableLoFiModeOff) {
+ // Navigate with ShouldEnableLoFiMode returning false.
+ NavigateToURLBlockUntilNavigationsComplete(
+ shell(), embedded_test_server()->GetURL("/page_with_iframe.html"), 1);
+ CheckResourcesRequested(true);
+}
+
+// Test that reloading calls ShouldEnableLoFiMode again and changes the Lo-Fi
+// state.
+IN_PROC_BROWSER_TEST_F(LoFiResourceDispatcherHostBrowserTest,
+ ShouldEnableLoFiModeReload) {
+ // Navigate with ShouldEnableLoFiMode returning false.
+ NavigateToURLBlockUntilNavigationsComplete(
+ shell(), embedded_test_server()->GetURL("/page_with_iframe.html"), 1);
+ CheckResourcesRequested(true);
+
+ // Reload. ShouldEnableLoFiMode should be called.
+ Reset(true);
+ ReloadBlockUntilNavigationsComplete(shell(), 1);
+ CheckResourcesRequested(true);
+}
+
+// Test that navigating backwards calls ShouldEnableLoFiMode again and changes
+// the Lo-Fi state.
+IN_PROC_BROWSER_TEST_F(LoFiResourceDispatcherHostBrowserTest,
+ ShouldEnableLoFiModeNavigateBackThenForward) {
+ // Navigate with ShouldEnableLoFiMode returning false.
+ NavigateToURLBlockUntilNavigationsComplete(
+ shell(), embedded_test_server()->GetURL("/page_with_iframe.html"), 1);
+ CheckResourcesRequested(true);
+
+ // Go to a different page.
+ NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
+
+ // Go back with ShouldEnableLoFiMode returning true.
+ Reset(true);
+ TestNavigationObserver tab_observer(shell()->web_contents(), 1);
+ shell()->GoBackOrForward(-1);
+ tab_observer.Wait();
+ CheckResourcesRequested(true);
+}
+
+// Test that reloading with Lo-Fi disabled doesn't call ShouldEnableLoFiMode and
+// already has LOFI_OFF.
+IN_PROC_BROWSER_TEST_F(LoFiResourceDispatcherHostBrowserTest,
+ ShouldEnableLoFiModeReloadDisableLoFi) {
+ // Navigate with ShouldEnableLoFiMode returning true.
+ Reset(true);
+ NavigateToURLBlockUntilNavigationsComplete(
+ shell(), embedded_test_server()->GetURL("/page_with_iframe.html"), 1);
+ CheckResourcesRequested(true);
+
+ // Reload with Lo-Fi disabled.
+ Reset(false);
+ TestNavigationObserver tab_observer(shell()->web_contents(), 1);
+ shell()->web_contents()->GetController().ReloadDisableLoFi(true);
+ tab_observer.Wait();
+ CheckResourcesRequested(false);
+}
+
} // namespace content
diff --git a/content/browser/loader/resource_dispatcher_host_impl.cc b/content/browser/loader/resource_dispatcher_host_impl.cc
index 2d7512b..efae657 100644
--- a/content/browser/loader/resource_dispatcher_host_impl.cc
+++ b/content/browser/loader/resource_dispatcher_host_impl.cc
@@ -436,6 +436,15 @@ void LogResourceRequestTimeOnUI(
}
}
+bool IsUsingLoFi(LoFiState lofi_state,
+ ResourceDispatcherHostDelegate* delegate,
+ const net::URLRequest& request,
+ ResourceContext* resource_context) {
+ if (lofi_state == LOFI_UNSPECIFIED && delegate)
+ return delegate->ShouldEnableLoFiMode(request, resource_context);
+ return lofi_state == LOFI_ON;
+}
+
} // namespace
// static
@@ -1346,7 +1355,9 @@ void ResourceDispatcherHostImpl::BeginRequest(
request_data.visiblity_state,
resource_context, filter_->GetWeakPtr(),
report_raw_headers,
- !is_sync_load);
+ !is_sync_load,
+ IsUsingLoFi(request_data.lofi_state, delegate_,
+ *new_request, resource_context));
// Request takes ownership.
extra_info->AssociateWithRequest(new_request.get());
@@ -1632,7 +1643,8 @@ ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo(
context,
base::WeakPtr<ResourceMessageFilter>(), // filter
false, // report_raw_headers
- true); // is_async
+ true, // is_async
+ false); // is_using_lofi
}
void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id,
@@ -2054,18 +2066,15 @@ void ResourceDispatcherHostImpl::BeginNavigationRequest(
-1, // request_data.origin_pid,
request_id_,
-1, // request_data.render_frame_id,
- info.is_main_frame,
- info.parent_is_main_frame,
+ info.is_main_frame, info.parent_is_main_frame,
-1, // request_data.parent_render_frame_id,
- resource_type,
- info.common_params.transition,
+ resource_type, info.common_params.transition,
// should_replace_current_entry. This was only maintained at layer for
// request transfers and isn't needed for browser-side navigations.
false,
false, // is download
false, // is stream
- info.common_params.allow_download,
- info.begin_params.has_user_gesture,
+ info.common_params.allow_download, info.begin_params.has_user_gesture,
true, // enable_load_timing
false, // enable_upload_progress
false, // do_not_prompt_for_login
@@ -2073,11 +2082,12 @@ void ResourceDispatcherHostImpl::BeginNavigationRequest(
// TODO(davidben): This is only used for prerenders. Replace
// is_showing with something for that. Or maybe it just comes from the
// same mechanism as the cookie one.
- blink::WebPageVisibilityStateVisible,
- resource_context,
+ blink::WebPageVisibilityStateVisible, resource_context,
base::WeakPtr<ResourceMessageFilter>(), // filter
false, // request_data.report_raw_headers
- true);
+ true,
+ IsUsingLoFi(info.common_params.lofi_state, delegate_,
+ *new_request, resource_context));
// Request takes ownership.
extra_info->AssociateWithRequest(new_request.get());
diff --git a/content/browser/loader/resource_loader.cc b/content/browser/loader/resource_loader.cc
index 64f5e7b..609aa87 100644
--- a/content/browser/loader/resource_loader.cc
+++ b/content/browser/loader/resource_loader.cc
@@ -94,6 +94,10 @@ void PopulateResourceResponse(ResourceRequestInfoImpl* info,
response->head.was_fetched_via_proxy = request->was_fetched_via_proxy();
response->head.proxy_server = response_info.proxy_server;
response->head.socket_address = request->GetSocketAddress();
+ const content::ResourceRequestInfo* request_info =
+ content::ResourceRequestInfo::ForRequest(request);
+ if (request_info)
+ response->head.is_using_lofi = request_info->IsUsingLoFi();
if (ServiceWorkerRequestHandler* handler =
ServiceWorkerRequestHandler::GetHandler(request)) {
handler->GetExtraResponseInfo(&response->head);
diff --git a/content/browser/loader/resource_request_info_impl.cc b/content/browser/loader/resource_request_info_impl.cc
index eb400bc..bb59b0a 100644
--- a/content/browser/loader/resource_request_info_impl.cc
+++ b/content/browser/loader/resource_request_info_impl.cc
@@ -68,7 +68,8 @@ void ResourceRequestInfo::AllocateForTesting(net::URLRequest* request,
context, // context
base::WeakPtr<ResourceMessageFilter>(), // filter
false, // report_raw_headers
- is_async); // is_async
+ is_async, // is_async
+ false); // is_using_lofi
info->AssociateWithRequest(request);
}
@@ -127,7 +128,8 @@ ResourceRequestInfoImpl::ResourceRequestInfoImpl(
ResourceContext* context,
base::WeakPtr<ResourceMessageFilter> filter,
bool report_raw_headers,
- bool is_async)
+ bool is_async,
+ bool is_using_lofi)
: cross_site_handler_(NULL),
detachable_handler_(NULL),
process_type_(process_type),
@@ -158,7 +160,8 @@ ResourceRequestInfoImpl::ResourceRequestInfoImpl(
context_(context),
filter_(filter),
report_raw_headers_(report_raw_headers),
- is_async_(is_async) {
+ is_async_(is_async),
+ is_using_lofi_(is_using_lofi) {
}
ResourceRequestInfoImpl::~ResourceRequestInfoImpl() {
@@ -250,6 +253,10 @@ bool ResourceRequestInfoImpl::IsDownload() const {
return is_download_;
}
+bool ResourceRequestInfoImpl::IsUsingLoFi() const {
+ return is_using_lofi_;
+}
+
bool ResourceRequestInfoImpl::ShouldReportRawHeaders() const {
return report_raw_headers_;
}
diff --git a/content/browser/loader/resource_request_info_impl.h b/content/browser/loader/resource_request_info_impl.h
index f0251e5..40a597a 100644
--- a/content/browser/loader/resource_request_info_impl.h
+++ b/content/browser/loader/resource_request_info_impl.h
@@ -65,7 +65,8 @@ class ResourceRequestInfoImpl : public ResourceRequestInfo,
ResourceContext* context,
base::WeakPtr<ResourceMessageFilter> filter,
bool report_raw_headers,
- bool is_async);
+ bool is_async,
+ bool is_using_lofi);
~ResourceRequestInfoImpl() override;
// ResourceRequestInfo implementation:
@@ -89,6 +90,7 @@ class ResourceRequestInfoImpl : public ResourceRequestInfo,
int* render_frame_id) const override;
bool IsAsync() const override;
bool IsDownload() const override;
+ bool IsUsingLoFi() const override;
bool ShouldReportRawHeaders() const;
CONTENT_EXPORT void AssociateWithRequest(net::URLRequest* request);
@@ -221,6 +223,7 @@ class ResourceRequestInfoImpl : public ResourceRequestInfo,
base::WeakPtr<ResourceMessageFilter> filter_;
bool report_raw_headers_;
bool is_async_;
+ bool is_using_lofi_;
DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl);
};
diff --git a/content/child/request_extra_data.cc b/content/child/request_extra_data.cc
index 5a1c689fc..5105c33 100644
--- a/content/child/request_extra_data.cc
+++ b/content/child/request_extra_data.cc
@@ -22,7 +22,8 @@ RequestExtraData::RequestExtraData()
should_replace_current_entry_(false),
transferred_request_child_id_(-1),
transferred_request_request_id_(-1),
- service_worker_provider_id_(kInvalidServiceWorkerProviderId) {
+ service_worker_provider_id_(kInvalidServiceWorkerProviderId),
+ lofi_state_(LOFI_UNSPECIFIED) {
}
RequestExtraData::~RequestExtraData() {
diff --git a/content/child/request_extra_data.h b/content/child/request_extra_data.h
index b73e196..37988d54 100644
--- a/content/child/request_extra_data.h
+++ b/content/child/request_extra_data.h
@@ -8,6 +8,7 @@
#include "base/compiler_specific.h"
#include "content/child/web_url_loader_impl.h"
#include "content/common/content_export.h"
+#include "content/common/navigation_params.h"
#include "third_party/WebKit/public/platform/WebPageVisibilityState.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
@@ -86,6 +87,12 @@ class CONTENT_EXPORT RequestExtraData
int service_worker_provider_id) {
service_worker_provider_id_ = service_worker_provider_id;
}
+ LoFiState lofi_state() const {
+ return lofi_state_;
+ }
+ void set_lofi_state(LoFiState lofi_state) {
+ lofi_state_ = lofi_state;
+ }
// |custom_user_agent| is used to communicate an overriding custom user agent
// to |RenderViewImpl::willSendRequest()|; set to a null string to indicate no
// override and an empty string to indicate that there should be no user
@@ -130,6 +137,7 @@ class CONTENT_EXPORT RequestExtraData
blink::WebString custom_user_agent_;
blink::WebString requested_with_;
scoped_ptr<StreamOverrideParameters> stream_override_;
+ LoFiState lofi_state_;
DISALLOW_COPY_AND_ASSIGN(RequestExtraData);
};
diff --git a/content/child/resource_dispatcher.cc b/content/child/resource_dispatcher.cc
index 1d6854f..c29adba 100644
--- a/content/child/resource_dispatcher.cc
+++ b/content/child/resource_dispatcher.cc
@@ -24,6 +24,7 @@
#include "content/child/sync_load_response.h"
#include "content/child/threaded_data_provider.h"
#include "content/common/inter_process_time_ticks_converter.h"
+#include "content/common/navigation_params.h"
#include "content/common/resource_messages.h"
#include "content/public/child/fixed_received_data.h"
#include "content/public/child/request_peer.h"
@@ -808,6 +809,7 @@ scoped_ptr<ResourceHostMsg_Request> ResourceDispatcher::CreateRequest(
extra_data->transferred_request_request_id();
request->service_worker_provider_id =
extra_data->service_worker_provider_id();
+ request->lofi_state = extra_data->lofi_state();
request->request_body = request_body;
if (frame_origin)
*frame_origin = extra_data->frame_origin();
diff --git a/content/child/web_url_loader_impl.cc b/content/child/web_url_loader_impl.cc
index 5818965..193797b 100644
--- a/content/child/web_url_loader_impl.cc
+++ b/content/child/web_url_loader_impl.cc
@@ -918,6 +918,7 @@ void WebURLLoaderImpl::PopulateURLResponse(const GURL& url,
extra_data->set_connection_info(info.connection_info);
extra_data->set_was_fetched_via_proxy(info.was_fetched_via_proxy);
extra_data->set_proxy_server(info.proxy_server);
+ extra_data->set_is_using_lofi(info.is_using_lofi);
// If there's no received headers end time, don't set load timing. This is
// the case for non-HTTP requests, requests that don't go over the wire, and
diff --git a/content/child/weburlresponse_extradata_impl.h b/content/child/weburlresponse_extradata_impl.h
index 49cbf39..dd7765a 100644
--- a/content/child/weburlresponse_extradata_impl.h
+++ b/content/child/weburlresponse_extradata_impl.h
@@ -87,6 +87,9 @@ class CONTENT_EXPORT WebURLResponseExtraDataImpl :
is_ftp_directory_listing_ = is_ftp_directory_listing;
}
+ bool is_using_lofi() const { return is_using_lofi_; }
+ void set_is_using_lofi(bool is_using_lofi) { is_using_lofi_ = is_using_lofi; }
+
private:
std::string npn_negotiated_protocol_;
bool is_ftp_directory_listing_;
@@ -96,6 +99,7 @@ class CONTENT_EXPORT WebURLResponseExtraDataImpl :
bool was_npn_negotiated_;
net::HttpResponseInfo::ConnectionInfo connection_info_;
bool was_alternate_protocol_available_;
+ bool is_using_lofi_;
DISALLOW_COPY_AND_ASSIGN(WebURLResponseExtraDataImpl);
};
diff --git a/content/common/frame_messages.h b/content/common/frame_messages.h
index b67af2a..424a0e2 100644
--- a/content/common/frame_messages.h
+++ b/content/common/frame_messages.h
@@ -60,6 +60,9 @@ IPC_ENUM_TRAITS(blink::WebSandboxFlags) // Bitmask.
IPC_ENUM_TRAITS_MAX_VALUE(blink::WebTreeScopeType,
blink::WebTreeScopeType::Last)
IPC_ENUM_TRAITS_MAX_VALUE(ui::MenuSourceType, ui::MENU_SOURCE_TYPE_LAST)
+IPC_ENUM_TRAITS_MIN_MAX_VALUE(content::LoFiState,
+ content::LOFI_UNSPECIFIED,
+ content::LOFI_ON)
IPC_STRUCT_TRAITS_BEGIN(content::ColorSuggestion)
IPC_STRUCT_TRAITS_MEMBER(color)
@@ -270,6 +273,7 @@ IPC_STRUCT_TRAITS_BEGIN(content::CommonNavigationParams)
IPC_STRUCT_TRAITS_MEMBER(report_type)
IPC_STRUCT_TRAITS_MEMBER(base_url_for_data_url)
IPC_STRUCT_TRAITS_MEMBER(history_url_for_data_url)
+ IPC_STRUCT_TRAITS_MEMBER(lofi_state)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(content::BeginNavigationParams)
diff --git a/content/common/navigation_params.cc b/content/common/navigation_params.cc
index 9c0f445..dfaefb1 100644
--- a/content/common/navigation_params.cc
+++ b/content/common/navigation_params.cc
@@ -29,7 +29,8 @@ CommonNavigationParams::CommonNavigationParams()
navigation_type(FrameMsg_Navigate_Type::NORMAL),
allow_download(true),
should_replace_current_entry(false),
- report_type(FrameMsg_UILoadMetricsReportType::NO_REPORT) {
+ report_type(FrameMsg_UILoadMetricsReportType::NO_REPORT),
+ lofi_state(LOFI_UNSPECIFIED) {
}
CommonNavigationParams::CommonNavigationParams(
@@ -42,7 +43,8 @@ CommonNavigationParams::CommonNavigationParams(
base::TimeTicks ui_timestamp,
FrameMsg_UILoadMetricsReportType::Value report_type,
const GURL& base_url_for_data_url,
- const GURL& history_url_for_data_url)
+ const GURL& history_url_for_data_url,
+ LoFiState lofi_state)
: url(url),
referrer(referrer),
transition(transition),
@@ -52,7 +54,8 @@ CommonNavigationParams::CommonNavigationParams(
ui_timestamp(ui_timestamp),
report_type(report_type),
base_url_for_data_url(base_url_for_data_url),
- history_url_for_data_url(history_url_for_data_url) {
+ history_url_for_data_url(history_url_for_data_url),
+ lofi_state(lofi_state) {
}
CommonNavigationParams::~CommonNavigationParams() {
diff --git a/content/common/navigation_params.h b/content/common/navigation_params.h
index 3ed8377..8093623 100644
--- a/content/common/navigation_params.h
+++ b/content/common/navigation_params.h
@@ -23,6 +23,18 @@ class RefCountedMemory;
namespace content {
+// The LoFi state which determines whether to add the Lo-Fi header.
+enum LoFiState {
+ // Let the browser process decide whether or not to request the Lo-Fi version.
+ LOFI_UNSPECIFIED = 0,
+
+ // Request a normal (non-Lo-Fi) version of the resource.
+ LOFI_OFF,
+
+ // Request a Lo-Fi version of the resource.
+ LOFI_ON,
+};
+
// PlzNavigate
// Helper function to determine if the navigation to |url| should make a request
// to the network stack. A request should not be sent for data URLs, JavaScript
@@ -47,7 +59,8 @@ struct CONTENT_EXPORT CommonNavigationParams {
base::TimeTicks ui_timestamp,
FrameMsg_UILoadMetricsReportType::Value report_type,
const GURL& base_url_for_data_url,
- const GURL& history_url_for_data_url);
+ const GURL& history_url_for_data_url,
+ LoFiState lofi_state);
~CommonNavigationParams();
// The URL to navigate to.
@@ -90,6 +103,10 @@ struct CONTENT_EXPORT CommonNavigationParams {
// History URL for use in Blink's SubstituteData.
// Is only used with data: URLs.
GURL history_url_for_data_url;
+
+ // Whether or not to request a LoFi version of the document or let the browser
+ // decide.
+ LoFiState lofi_state;
};
// Provided by the renderer ----------------------------------------------------
diff --git a/content/common/resource_messages.h b/content/common/resource_messages.h
index 744a923..dc4bac4 100644
--- a/content/common/resource_messages.h
+++ b/content/common/resource_messages.h
@@ -10,6 +10,7 @@
#include "base/memory/shared_memory.h"
#include "base/process/process.h"
#include "content/common/content_param_traits_macros.h"
+#include "content/common/navigation_params.h"
#include "content/common/resource_request_body.h"
#include "content/common/service_worker/service_worker_types.h"
#include "content/public/common/common_param_traits.h"
@@ -135,6 +136,7 @@ IPC_STRUCT_TRAITS_BEGIN(content::ResourceResponseInfo)
IPC_STRUCT_TRAITS_MEMBER(service_worker_start_time)
IPC_STRUCT_TRAITS_MEMBER(service_worker_ready_time)
IPC_STRUCT_TRAITS_MEMBER(proxy_server)
+ IPC_STRUCT_TRAITS_MEMBER(is_using_lofi)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(net::RedirectInfo)
@@ -270,6 +272,10 @@ IPC_STRUCT_BEGIN(ResourceHostMsg_Request)
// Whether to intercept headers to pass back to the renderer.
IPC_STRUCT_MEMBER(bool, report_raw_headers)
+
+ // Whether or not to request a LoFi version of the resource or let the browser
+ // decide.
+ IPC_STRUCT_MEMBER(content::LoFiState, lofi_state)
IPC_STRUCT_END()
// Parameters for a ResourceMsg_RequestComplete
diff --git a/content/public/browser/navigation_controller.h b/content/public/browser/navigation_controller.h
index 3ad7e03..af1b3b9 100644
--- a/content/public/browser/navigation_controller.h
+++ b/content/public/browser/navigation_controller.h
@@ -43,7 +43,8 @@ class NavigationController {
NO_RELOAD, // Normal load.
RELOAD, // Normal (cache-validating) reload.
RELOAD_IGNORING_CACHE, // Reload bypassing the cache (shift-reload).
- RELOAD_ORIGINAL_REQUEST_URL // Reload using the original request URL.
+ RELOAD_ORIGINAL_REQUEST_URL, // Reload using the original request URL.
+ RELOAD_DISABLE_LOFI_MODE // Reload with Lo-Fi mode disabled.
};
// Load type used in LoadURLParams.
@@ -365,6 +366,9 @@ class NavigationController {
// user agent after following a redirect.
virtual void ReloadOriginalRequestURL(bool check_for_repost) = 0;
+ // Like Reload(), but disables Lo-Fi.
+ virtual void ReloadDisableLoFi(bool check_for_repost) = 0;
+
// Removing of entries -------------------------------------------------------
// Removes the entry at the specified |index|. If the index is the last
diff --git a/content/public/browser/resource_dispatcher_host_delegate.cc b/content/public/browser/resource_dispatcher_host_delegate.cc
index e418875..ce903af 100644
--- a/content/public/browser/resource_dispatcher_host_delegate.cc
+++ b/content/public/browser/resource_dispatcher_host_delegate.cc
@@ -90,6 +90,12 @@ void ResourceDispatcherHostDelegate::RequestComplete(
net::URLRequest* url_request) {
}
+bool ResourceDispatcherHostDelegate::ShouldEnableLoFiMode(
+ const net::URLRequest& url_request,
+ content::ResourceContext* resource_context) {
+ return false;
+}
+
ResourceDispatcherHostDelegate::ResourceDispatcherHostDelegate() {
}
diff --git a/content/public/browser/resource_dispatcher_host_delegate.h b/content/public/browser/resource_dispatcher_host_delegate.h
index 181962ee..05c55c4 100644
--- a/content/public/browser/resource_dispatcher_host_delegate.h
+++ b/content/public/browser/resource_dispatcher_host_delegate.h
@@ -124,6 +124,11 @@ class CONTENT_EXPORT ResourceDispatcherHostDelegate {
// Notification that a request has completed.
virtual void RequestComplete(net::URLRequest* url_request);
+ // Asks the embedder if Lo-Fi mode should be enabled for the given request. It
+ // is only called for requests with an unspecified Lo-Fi value.
+ virtual bool ShouldEnableLoFiMode(const net::URLRequest& url_request,
+ content::ResourceContext* resource_context);
+
protected:
ResourceDispatcherHostDelegate();
virtual ~ResourceDispatcherHostDelegate();
diff --git a/content/public/browser/resource_request_info.h b/content/public/browser/resource_request_info.h
index e9ba86eb..f6cdfce 100644
--- a/content/public/browser/resource_request_info.h
+++ b/content/public/browser/resource_request_info.h
@@ -124,6 +124,9 @@ class ResourceRequestInfo {
// Whether this is a download.
virtual bool IsDownload() const = 0;
+ // Whether this request if using Lo-Fi mode.
+ virtual bool IsUsingLoFi() const = 0;
+
protected:
virtual ~ResourceRequestInfo() {}
};
diff --git a/content/public/common/resource_response_info.cc b/content/public/common/resource_response_info.cc
index d5e81e91..1d4e304 100644
--- a/content/public/common/resource_response_info.cc
+++ b/content/public/common/resource_response_info.cc
@@ -21,7 +21,8 @@ ResourceResponseInfo::ResourceResponseInfo()
was_fetched_via_service_worker(false),
was_fallback_required_by_service_worker(false),
response_type_via_service_worker(
- blink::WebServiceWorkerResponseTypeDefault) {
+ blink::WebServiceWorkerResponseTypeDefault),
+ is_using_lofi(false) {
}
ResourceResponseInfo::~ResourceResponseInfo() {
diff --git a/content/public/common/resource_response_info.h b/content/public/common/resource_response_info.h
index d7d1698..1a0f126 100644
--- a/content/public/common/resource_response_info.h
+++ b/content/public/common/resource_response_info.h
@@ -129,6 +129,9 @@ struct ResourceResponseInfo {
// If the response is not provided by the ServiceWorker, kept empty.
// TODO(ksakamoto): Move this to net::LoadTimingInfo.
base::TimeTicks service_worker_ready_time;
+
+ // Whether or not the request was for a LoFi version of the resource.
+ bool is_using_lofi;
};
} // namespace content
diff --git a/content/public/renderer/render_frame.h b/content/public/renderer/render_frame.h
index 8148225..e836670 100644
--- a/content/public/renderer/render_frame.h
+++ b/content/public/renderer/render_frame.h
@@ -157,6 +157,9 @@ class CONTENT_EXPORT RenderFrame : public IPC::Listener,
virtual void AddMessageToConsole(ConsoleMessageLevel level,
const std::string& message) = 0;
+ // Whether or not this frame is using Lo-Fi.
+ virtual bool IsUsingLoFi() const = 0;
+
protected:
~RenderFrame() override {}
diff --git a/content/public/test/render_view_test.cc b/content/public/test/render_view_test.cc
index 57244d6..39ccf86 100644
--- a/content/public/test/render_view_test.cc
+++ b/content/public/test/render_view_test.cc
@@ -446,7 +446,8 @@ void RenderViewTest::Reload(const GURL& url) {
CommonNavigationParams common_params(
url, Referrer(), ui::PAGE_TRANSITION_LINK, FrameMsg_Navigate_Type::RELOAD,
true, false, base::TimeTicks(),
- FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL());
+ FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL(),
+ LOFI_UNSPECIFIED);
RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_);
TestRenderFrame* frame =
static_cast<TestRenderFrame*>(impl->GetMainRenderFrame());
@@ -578,7 +579,8 @@ void RenderViewTest::GoToOffset(int offset, const PageState& state) {
CommonNavigationParams common_params(
GURL(), Referrer(), ui::PAGE_TRANSITION_FORWARD_BACK,
FrameMsg_Navigate_Type::NORMAL, true, false, base::TimeTicks(),
- FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL());
+ FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL(),
+ LOFI_UNSPECIFIED);
RequestNavigationParams request_params;
request_params.page_state = state;
request_params.page_id = impl->page_id_ + offset;
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
index 74200a8..5efa143 100644
--- a/content/renderer/render_frame_impl.cc
+++ b/content/renderer/render_frame_impl.cc
@@ -502,7 +502,7 @@ CommonNavigationParams MakeCommonNavigationParams(
return CommonNavigationParams(
request->url(), referrer, extra_data->transition_type(),
FrameMsg_Navigate_Type::NORMAL, true, should_replace_current_entry,
- ui_timestamp, report_type, GURL(), GURL());
+ ui_timestamp, report_type, GURL(), GURL(), LOFI_UNSPECIFIED);
}
#if !defined(OS_ANDROID) || defined(ENABLE_MEDIA_PIPELINE_ON_ANDROID)
@@ -739,6 +739,7 @@ RenderFrameImpl::RenderFrameImpl(const CreateParams& params)
manifest_manager_(NULL),
accessibility_mode_(AccessibilityModeOff),
renderer_accessibility_(NULL),
+ is_using_lofi_(false),
weak_factory_(this) {
std::pair<RoutingIDFrameMap::iterator, bool> result =
g_routing_id_frame_map.Get().insert(std::make_pair(routing_id_, this));
@@ -813,6 +814,11 @@ void RenderFrameImpl::Initialize() {
is_main_frame_ = !frame_->parent();
is_local_root_ = is_main_frame_ || frame_->parent()->isWebRemoteFrame();
+ RenderFrameImpl* parent_frame = RenderFrameImpl::FromWebFrame(
+ frame_->parent());
+ if (parent_frame)
+ is_using_lofi_ = parent_frame->IsUsingLoFi();
+
bool is_tracing = false;
TRACE_EVENT_CATEGORY_GROUP_ENABLED("navigation", &is_tracing);
if (is_tracing) {
@@ -2031,6 +2037,10 @@ void RenderFrameImpl::AddMessageToConsole(ConsoleMessageLevel level,
devtools_agent_->AddMessageToConsole(level, message);
}
+bool RenderFrameImpl::IsUsingLoFi() const {
+ return is_using_lofi_;
+}
+
// blink::WebFrameClient implementation ----------------------------------------
blink::WebPlugin* RenderFrameImpl::createPlugin(
@@ -2718,6 +2728,9 @@ void RenderFrameImpl::didCommitProvisionalLoad(
DocumentState::FromDataSource(frame->dataSource());
NavigationStateImpl* navigation_state =
static_cast<NavigationStateImpl*>(document_state->navigation_state());
+ WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(
+ frame->dataSource()->response());
+ is_using_lofi_ = extra_data && extra_data->is_using_lofi();
if (proxy_routing_id_ != MSG_ROUTING_NONE) {
RenderFrameProxy* proxy =
@@ -3378,6 +3391,14 @@ void RenderFrameImpl::willSendRequest(
navigation_state->start_params().transferred_request_request_id);
extra_data->set_service_worker_provider_id(provider_id);
extra_data->set_stream_override(stream_override.Pass());
+ // TODO(megjablon): Set the navigation params for single image loads to
+ // LOFI_OFF and remove the dependency on ReloadBypassingCache.
+ if (request.cachePolicy() == WebURLRequest::ReloadBypassingCache)
+ extra_data->set_lofi_state(LOFI_OFF);
+ else if (is_main_frame_ && !navigation_state->request_committed())
+ extra_data->set_lofi_state(navigation_state->common_params().lofi_state);
+ else
+ extra_data->set_lofi_state(is_using_lofi_ ? LOFI_ON : LOFI_OFF);
request.setExtraData(extra_data);
// TODO(creis): Update prefetching to work with out-of-process iframes.
diff --git a/content/renderer/render_frame_impl.h b/content/renderer/render_frame_impl.h
index 9237513..56e9b5f 100644
--- a/content/renderer/render_frame_impl.h
+++ b/content/renderer/render_frame_impl.h
@@ -374,6 +374,7 @@ class CONTENT_EXPORT RenderFrameImpl
v8::Local<v8::Context> context) override;
void AddMessageToConsole(ConsoleMessageLevel level,
const std::string& message) override;
+ bool IsUsingLoFi() const override;
// blink::WebFrameClient implementation:
blink::WebPlugin* createPlugin(blink::WebLocalFrame* frame,
@@ -1050,6 +1051,9 @@ class CONTENT_EXPORT RenderFrameImpl
scoped_ptr<blink::WebUSBClient> usb_client_;
+ // Whether or not this RenderFrame is using Lo-Fi mode.
+ bool is_using_lofi_;
+
#if defined(ENABLE_WEBVR)
// The VR dispatcher attached to the frame, lazily initialized.
scoped_ptr<VRDispatcher> vr_dispatcher_;
diff --git a/content/test/data/image.jpg b/content/test/data/image.jpg
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/content/test/data/image.jpg
@@ -0,0 +1 @@
+
diff --git a/content/test/data/page_with_iframe.html b/content/test/data/page_with_iframe.html
new file mode 100644
index 0000000..1415f19
--- /dev/null
+++ b/content/test/data/page_with_iframe.html
@@ -0,0 +1,8 @@
+<html>
+<head></head>
+<body>
+ <img src="image.jpg"/>
+ <p>This page has an iframe. Yay for iframes!
+ <p><iframe src="title1.html"></iframe>
+</body>
+</html> \ No newline at end of file