Commit 23e7d383 authored by rajendrant's avatar rajendrant Committed by Commit Bot

Move PreviewsResourceLoadingHints mojo out of blink

Moves the PreviewsResourceLoadingHints interface away from blink, since
its not used in blink. This also refactors the subresource redirect
interface out of PreviewsResourceLoadingHints.

Bug: 1152527
TBR: dom@chromium.org
Change-Id: Id3036c3ef91240cb9fb986f06cf478780e18492c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2556566
Commit-Queue: rajendrant <rajendrant@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarRobert Ogden <robertogden@chromium.org>
Cr-Commit-Position: refs/heads/master@{#831162}
parent fba47e51
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h" #include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h" #include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/previews_resource_loading_hints.mojom.h"
#include "components/optimization_guide/optimization_guide_decider.h" #include "components/optimization_guide/optimization_guide_decider.h"
#include "components/optimization_guide/proto/lite_video_metadata.pb.h" #include "components/optimization_guide/proto/lite_video_metadata.pb.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
...@@ -33,7 +34,6 @@ ...@@ -33,7 +34,6 @@
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/loader/previews_resource_loading_hints.mojom.h"
namespace { namespace {
...@@ -183,10 +183,10 @@ void LiteVideoObserver::SendHintToRenderFrameAgentForID( ...@@ -183,10 +183,10 @@ void LiteVideoObserver::SendHintToRenderFrameAgentForID(
if (!render_frame_host) if (!render_frame_host)
return; return;
mojo::AssociatedRemote<blink::mojom::PreviewsResourceLoadingHintsReceiver> mojo::AssociatedRemote<previews::mojom::PreviewsResourceLoadingHintsReceiver>
loading_hints_agent; loading_hints_agent;
auto hint_ptr = blink::mojom::LiteVideoHint::New(); auto hint_ptr = previews::mojom::LiteVideoHint::New();
hint_ptr->target_downlink_bandwidth_kbps = hint_ptr->target_downlink_bandwidth_kbps =
hint.target_downlink_bandwidth_kbps(); hint.target_downlink_bandwidth_kbps();
hint_ptr->kilobytes_to_buffer_before_throttle = hint_ptr->kilobytes_to_buffer_before_throttle =
...@@ -249,7 +249,7 @@ void LiteVideoObserver::MediaBufferUnderflow(const content::MediaPlayerId& id) { ...@@ -249,7 +249,7 @@ void LiteVideoObserver::MediaBufferUnderflow(const content::MediaPlayerId& id) {
return; return;
} }
mojo::AssociatedRemote<blink::mojom::PreviewsResourceLoadingHintsReceiver> mojo::AssociatedRemote<previews::mojom::PreviewsResourceLoadingHintsReceiver>
loading_hints_agent; loading_hints_agent;
if (!render_frame_host->GetRemoteAssociatedInterfaces()) if (!render_frame_host->GetRemoteAssociatedInterfaces())
...@@ -291,7 +291,7 @@ void LiteVideoObserver::MediaPlayerSeek(const content::MediaPlayerId& id) { ...@@ -291,7 +291,7 @@ void LiteVideoObserver::MediaPlayerSeek(const content::MediaPlayerId& id) {
return; return;
} }
mojo::AssociatedRemote<blink::mojom::PreviewsResourceLoadingHintsReceiver> mojo::AssociatedRemote<previews::mojom::PreviewsResourceLoadingHintsReceiver>
loading_hints_agent; loading_hints_agent;
if (!render_frame_host->GetRemoteAssociatedInterfaces()) if (!render_frame_host->GetRemoteAssociatedInterfaces())
......
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h" #include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h" #include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/previews_resource_loading_hints.mojom.h"
#include "components/optimization_guide/proto/hints.pb.h" #include "components/optimization_guide/proto/hints.pb.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/mojom/loader/previews_resource_loading_hints.mojom.h"
namespace optimization_guide { namespace optimization_guide {
...@@ -60,7 +60,7 @@ void BlinkOptimizationGuideWebContentsObserver::ReadyToCommitNavigation( ...@@ -60,7 +60,7 @@ void BlinkOptimizationGuideWebContentsObserver::ReadyToCommitNavigation(
// Tentatively use the Previews interface to talk with the renderer. // Tentatively use the Previews interface to talk with the renderer.
// TODO(https://crbug.com/1113980): Implement our own interface. // TODO(https://crbug.com/1113980): Implement our own interface.
mojo::AssociatedRemote<blink::mojom::PreviewsResourceLoadingHintsReceiver> mojo::AssociatedRemote<previews::mojom::PreviewsResourceLoadingHintsReceiver>
hints_receiver_associated; hints_receiver_associated;
if (navigation_handle->GetRenderFrameHost() if (navigation_handle->GetRenderFrameHost()
->GetRemoteAssociatedInterfaces()) { ->GetRemoteAssociatedInterfaces()) {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/previews/previews_service_factory.h" #include "chrome/browser/previews/previews_service_factory.h"
#include "chrome/browser/previews/previews_ui_tab_helper.h" #include "chrome/browser/previews/previews_ui_tab_helper.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/previews_resource_loading_hints.mojom.h"
#include "components/previews/content/previews_ui_service.h" #include "components/previews/content/previews_ui_service.h"
#include "components/previews/content/previews_user_data.h" #include "components/previews/content/previews_user_data.h"
#include "components/previews/core/previews_experiments.h" #include "components/previews/core/previews_experiments.h"
...@@ -26,7 +27,6 @@ ...@@ -26,7 +27,6 @@
#include "services/metrics/public/cpp/ukm_source_id.h" #include "services/metrics/public/cpp/ukm_source_id.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/loader/previews_resource_loading_hints.mojom.h"
#include "url/gurl.h" #include "url/gurl.h"
ResourceLoadingHintsWebContentsObserver:: ResourceLoadingHintsWebContentsObserver::
...@@ -95,11 +95,11 @@ void ResourceLoadingHintsWebContentsObserver::SendResourceLoadingHints( ...@@ -95,11 +95,11 @@ void ResourceLoadingHintsWebContentsObserver::SendResourceLoadingHints(
bool is_redirect = previews_user_data->is_redirect(); bool is_redirect = previews_user_data->is_redirect();
mojo::Remote<blink::mojom::PreviewsResourceLoadingHintsReceiver> mojo::Remote<previews::mojom::PreviewsResourceLoadingHintsReceiver>
hints_receiver; hints_receiver;
blink::mojom::PreviewsResourceLoadingHintsPtr hints_ptr = previews::mojom::PreviewsResourceLoadingHintsPtr hints_ptr =
blink::mojom::PreviewsResourceLoadingHints::New(); previews::mojom::PreviewsResourceLoadingHints::New();
const std::vector<std::string>& hints = const std::vector<std::string>& hints =
GetResourceLoadingHintsResourcePatternsToBlock( GetResourceLoadingHintsResourcePatternsToBlock(
...@@ -144,10 +144,10 @@ const std::vector<std::string> ResourceLoadingHintsWebContentsObserver:: ...@@ -144,10 +144,10 @@ const std::vector<std::string> ResourceLoadingHintsWebContentsObserver::
return resource_patterns_to_block; return resource_patterns_to_block;
} }
mojo::AssociatedRemote<blink::mojom::PreviewsResourceLoadingHintsReceiver> mojo::AssociatedRemote<previews::mojom::PreviewsResourceLoadingHintsReceiver>
ResourceLoadingHintsWebContentsObserver::GetResourceLoadingHintsReceiver( ResourceLoadingHintsWebContentsObserver::GetResourceLoadingHintsReceiver(
content::NavigationHandle* navigation_handle) { content::NavigationHandle* navigation_handle) {
mojo::AssociatedRemote<blink::mojom::PreviewsResourceLoadingHintsReceiver> mojo::AssociatedRemote<previews::mojom::PreviewsResourceLoadingHintsReceiver>
loading_hints_agent; loading_hints_agent;
if (navigation_handle->GetRenderFrameHost() if (navigation_handle->GetRenderFrameHost()
......
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "chrome/common/previews_resource_loading_hints.mojom-forward.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h" #include "content/public/browser/web_contents_user_data.h"
#include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/bindings/associated_remote.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/mojom/loader/previews_resource_loading_hints.mojom-forward.h"
class Profile; class Profile;
...@@ -71,7 +71,7 @@ class ResourceLoadingHintsWebContentsObserver ...@@ -71,7 +71,7 @@ class ResourceLoadingHintsWebContentsObserver
// Set in constructor. // Set in constructor.
Profile* profile_ = nullptr; Profile* profile_ = nullptr;
mojo::AssociatedRemote<blink::mojom::PreviewsResourceLoadingHintsReceiver> mojo::AssociatedRemote<previews::mojom::PreviewsResourceLoadingHintsReceiver>
GetResourceLoadingHintsReceiver(content::NavigationHandle* navigation_handle); GetResourceLoadingHintsReceiver(content::NavigationHandle* navigation_handle);
WEB_CONTENTS_USER_DATA_KEY_DECL(); WEB_CONTENTS_USER_DATA_KEY_DECL();
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/mojom/loader/previews_resource_loading_hints.mojom.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace subresource_redirect { namespace subresource_redirect {
...@@ -45,14 +44,14 @@ GetOptimizationGuideDeciderFromWebContents(content::WebContents* web_contents) { ...@@ -45,14 +44,14 @@ GetOptimizationGuideDeciderFromWebContents(content::WebContents* web_contents) {
// Pass down the |images_hints| to |render_frame_host|. // Pass down the |images_hints| to |render_frame_host|.
void SetResourceLoadingImageHints( void SetResourceLoadingImageHints(
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
blink::mojom::CompressPublicImagesHintsPtr images_hints) { mojom::CompressPublicImagesHintsPtr images_hints) {
mojo::AssociatedRemote<blink::mojom::PreviewsResourceLoadingHintsReceiver> mojo::AssociatedRemote<mojom::SubresourceRedirectHintsReceiver>
loading_hints_agent; hints_receiver;
if (render_frame_host->GetRemoteAssociatedInterfaces()) { if (render_frame_host->GetRemoteAssociatedInterfaces()) {
render_frame_host->GetRemoteAssociatedInterfaces()->GetInterface( render_frame_host->GetRemoteAssociatedInterfaces()->GetInterface(
&loading_hints_agent); &hints_receiver);
loading_hints_agent->SetCompressPublicImagesHints(std::move(images_hints)); hints_receiver->SetCompressPublicImagesHints(std::move(images_hints));
} }
} }
...@@ -166,7 +165,7 @@ void SubresourceRedirectObserver::OnResourceLoadingImageHintsReceived( ...@@ -166,7 +165,7 @@ void SubresourceRedirectObserver::OnResourceLoadingImageHintsReceived(
// purposes. // purposes.
SetResourceLoadingImageHints( SetResourceLoadingImageHints(
current_render_frame_host, current_render_frame_host,
blink::mojom::CompressPublicImagesHints::New(public_image_urls)); mojom::CompressPublicImagesHints::New(public_image_urls));
if (!public_image_urls.empty()) if (!public_image_urls.empty())
is_https_image_compression_applied_ = true; is_https_image_compression_applied_ = true;
} }
......
...@@ -714,6 +714,7 @@ mojom("mojo_bindings") { ...@@ -714,6 +714,7 @@ mojom("mojo_bindings") {
"network_easter_egg.mojom", "network_easter_egg.mojom",
"open_search_description_document_handler.mojom", "open_search_description_document_handler.mojom",
"plugin.mojom", "plugin.mojom",
"previews_resource_loading_hints.mojom",
"renderer_configuration.mojom", "renderer_configuration.mojom",
"subresource_redirect_service.mojom", "subresource_redirect_service.mojom",
"sync_encryption_keys_extension.mojom", "sync_encryption_keys_extension.mojom",
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
module blink.mojom; module previews.mojom;
import "mojo/public/mojom/base/time.mojom"; import "mojo/public/mojom/base/time.mojom";
import "third_party/blink/public/mojom/optimization_guide/optimization_guide.mojom"; import "third_party/blink/public/mojom/optimization_guide/optimization_guide.mojom";
...@@ -22,13 +22,6 @@ struct PreviewsResourceLoadingHints { ...@@ -22,13 +22,6 @@ struct PreviewsResourceLoadingHints {
array<string> subresources_to_block; array<string> subresources_to_block;
}; };
// Image loading hints passed by the browser to renderers. Send at most once
// per page load from browser to renderer. The hints are provided to the
// renderer and aid in redirecting these public images to compressed versions.
struct CompressPublicImagesHints {
array<string> image_urls;
};
// LiteVideo hints passed by the browser to renderers. Send at most once // LiteVideo hints passed by the browser to renderers. Send at most once
// per render frame from browser to renderer. The hints are provided to the // per render frame from browser to renderer. The hints are provided to the
// renderer and aid in optimizing media data use. // renderer and aid in optimizing media data use.
...@@ -52,16 +45,13 @@ interface PreviewsResourceLoadingHintsReceiver { ...@@ -52,16 +45,13 @@ interface PreviewsResourceLoadingHintsReceiver {
// Sends the resource loading hints from the browser to renderers. // Sends the resource loading hints from the browser to renderers.
SetResourceLoadingHints(PreviewsResourceLoadingHints previews_resource_loading_hints); SetResourceLoadingHints(PreviewsResourceLoadingHints previews_resource_loading_hints);
// Sends the public image URL hints from the browser to renderers.
SetCompressPublicImagesHints(CompressPublicImagesHints images_hints);
// Sends the hints for reducing the data-costs of streaming // Sends the hints for reducing the data-costs of streaming
// media/videos from the browser to renderers. // media/videos from the browser to renderers.
SetLiteVideoHint(LiteVideoHint lite_video_hint); SetLiteVideoHint(LiteVideoHint lite_video_hint);
// Sends the hints for Blink. // Sends the hints for Blink.
// TODO(https://crbug.com/1113980): Move this to its own mojo plumbing. // TODO(https://crbug.com/1113980): Move this to its own mojo plumbing.
SetBlinkOptimizationGuideHints(BlinkOptimizationGuideHints hints); SetBlinkOptimizationGuideHints(blink.mojom.BlinkOptimizationGuideHints hints);
// Notifies the renderers that active media request throttles should be stopped // Notifies the renderers that active media request throttles should be stopped
// and not allow any new throttles. // and not allow any new throttles.
......
...@@ -6,6 +6,13 @@ module subresource_redirect.mojom; ...@@ -6,6 +6,13 @@ module subresource_redirect.mojom;
import "mojo/public/mojom/base/time.mojom"; import "mojo/public/mojom/base/time.mojom";
// Image loading hints passed by the browser to renderers. Send at most once
// per page load from browser to renderer. The hints are provided to the
// renderer and aid in redirecting these public images to compressed versions.
struct CompressPublicImagesHints {
array<string> image_urls;
};
// This service is implemented in the browser process and is used by the // This service is implemented in the browser process and is used by the
// renderer to notify the state of https image compression. This interface is // renderer to notify the state of https image compression. This interface is
// associated with a frame. // associated with a frame.
...@@ -16,3 +23,10 @@ interface SubresourceRedirectService { ...@@ -16,3 +23,10 @@ interface SubresourceRedirectService {
// |retry_after| is zero. // |retry_after| is zero.
NotifyCompressedImageFetchFailed(mojo_base.mojom.TimeDelta retry_after); NotifyCompressedImageFetchFailed(mojo_base.mojom.TimeDelta retry_after);
}; };
// Render process implemented interface that receives hints from the browser
// about https image compression.
interface SubresourceRedirectHintsReceiver {
// Sends the public image URL hints from the browser to renderers.
SetCompressPublicImagesHints(CompressPublicImagesHints images_hints);
};
...@@ -607,7 +607,8 @@ void ChromeContentRendererClient::RenderFrameCreated( ...@@ -607,7 +607,8 @@ void ChromeContentRendererClient::RenderFrameCreated(
new previews::ResourceLoadingHintsAgent(associated_interfaces, render_frame); new previews::ResourceLoadingHintsAgent(associated_interfaces, render_frame);
if (subresource_redirect::IsPublicImageHintsBasedCompressionEnabled()) if (subresource_redirect::IsPublicImageHintsBasedCompressionEnabled())
new subresource_redirect::SubresourceRedirectHintsAgent(render_frame); new subresource_redirect::SubresourceRedirectHintsAgent(
associated_interfaces, render_frame);
if (translate::IsSubFrameTranslationEnabled()) { if (translate::IsSubFrameTranslationEnabled()) {
new translate::PerFrameTranslateAgent( new translate::PerFrameTranslateAgent(
......
...@@ -86,7 +86,7 @@ bool LiteVideoHintAgent::HasLiteVideoHint() const { ...@@ -86,7 +86,7 @@ bool LiteVideoHintAgent::HasLiteVideoHint() const {
} }
void LiteVideoHintAgent::SetLiteVideoHint( void LiteVideoHintAgent::SetLiteVideoHint(
blink::mojom::LiteVideoHintPtr lite_video_hint) { previews::mojom::LiteVideoHintPtr lite_video_hint) {
if (!lite_video_hint) if (!lite_video_hint)
return; return;
target_downlink_bandwidth_kbps_ = target_downlink_bandwidth_kbps_ =
......
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/common/previews_resource_loading_hints.mojom.h"
#include "chrome/renderer/lite_video/lite_video_url_loader_throttle.h" #include "chrome/renderer/lite_video/lite_video_url_loader_throttle.h"
#include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_frame_observer_tracker.h" #include "content/public/renderer/render_frame_observer_tracker.h"
#include "third_party/blink/public/mojom/loader/previews_resource_loading_hints.mojom.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace lite_video { namespace lite_video {
...@@ -40,7 +40,7 @@ class LiteVideoHintAgent ...@@ -40,7 +40,7 @@ class LiteVideoHintAgent
// Updates the LiteVideo throttling parameters for calculating // Updates the LiteVideo throttling parameters for calculating
// the latency to add to media requests. // the latency to add to media requests.
void SetLiteVideoHint(blink::mojom::LiteVideoHintPtr lite_video_hint); void SetLiteVideoHint(previews::mojom::LiteVideoHintPtr lite_video_hint);
// Returns whether |this| has been provided a LiteVideoHint and // Returns whether |this| has been provided a LiteVideoHint and
// has the parameters needed for calculating the throttling latency. // has the parameters needed for calculating the throttling latency.
......
...@@ -135,7 +135,8 @@ class LiteVideoHintAgentTest : public ChromeRenderViewTest { ...@@ -135,7 +135,8 @@ class LiteVideoHintAgentTest : public ChromeRenderViewTest {
new LiteVideoHintAgent(view_->GetMainRenderFrame()); new LiteVideoHintAgent(view_->GetMainRenderFrame());
// Set some default hints. // Set some default hints.
blink::mojom::LiteVideoHintPtr hint = blink::mojom::LiteVideoHint::New(); previews::mojom::LiteVideoHintPtr hint =
previews::mojom::LiteVideoHint::New();
hint->kilobytes_to_buffer_before_throttle = 10; hint->kilobytes_to_buffer_before_throttle = 10;
hint->target_downlink_bandwidth_kbps = 60; hint->target_downlink_bandwidth_kbps = 60;
hint->target_downlink_rtt_latency = base::TimeDelta::FromMilliseconds(500); hint->target_downlink_rtt_latency = base::TimeDelta::FromMilliseconds(500);
......
...@@ -103,7 +103,7 @@ ResourceLoadingHintsAgent::~ResourceLoadingHintsAgent() = default; ...@@ -103,7 +103,7 @@ ResourceLoadingHintsAgent::~ResourceLoadingHintsAgent() = default;
void ResourceLoadingHintsAgent::SetReceiver( void ResourceLoadingHintsAgent::SetReceiver(
mojo::PendingAssociatedReceiver< mojo::PendingAssociatedReceiver<
blink::mojom::PreviewsResourceLoadingHintsReceiver> receiver) { previews::mojom::PreviewsResourceLoadingHintsReceiver> receiver) {
receiver_.Bind(std::move(receiver)); receiver_.Bind(std::move(receiver));
} }
...@@ -112,7 +112,7 @@ bool ResourceLoadingHintsAgent::IsMainFrame() const { ...@@ -112,7 +112,7 @@ bool ResourceLoadingHintsAgent::IsMainFrame() const {
} }
void ResourceLoadingHintsAgent::SetResourceLoadingHints( void ResourceLoadingHintsAgent::SetResourceLoadingHints(
blink::mojom::PreviewsResourceLoadingHintsPtr resource_loading_hints) { previews::mojom::PreviewsResourceLoadingHintsPtr resource_loading_hints) {
if (!IsMainFrame()) if (!IsMainFrame())
return; return;
...@@ -124,18 +124,8 @@ void ResourceLoadingHintsAgent::SetResourceLoadingHints( ...@@ -124,18 +124,8 @@ void ResourceLoadingHintsAgent::SetResourceLoadingHints(
} }
} }
void ResourceLoadingHintsAgent::SetCompressPublicImagesHints(
blink::mojom::CompressPublicImagesHintsPtr images_hints) {
if (auto* subresource_redirect_hints_agent =
subresource_redirect::SubresourceRedirectHintsAgent::Get(
render_frame())) {
subresource_redirect_hints_agent->SetCompressPublicImagesHints(
std::move(images_hints));
}
}
void ResourceLoadingHintsAgent::SetLiteVideoHint( void ResourceLoadingHintsAgent::SetLiteVideoHint(
blink::mojom::LiteVideoHintPtr lite_video_hint) { previews::mojom::LiteVideoHintPtr lite_video_hint) {
auto* lite_video_hint_agent = auto* lite_video_hint_agent =
lite_video::LiteVideoHintAgent::Get(render_frame()); lite_video::LiteVideoHintAgent::Get(render_frame());
if (lite_video_hint_agent) if (lite_video_hint_agent)
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h" #include "base/optional.h"
#include "chrome/common/previews_resource_loading_hints.mojom.h"
#include "chrome/renderer/lite_video/lite_video_hint_agent.h" #include "chrome/renderer/lite_video/lite_video_hint_agent.h"
#include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_observer.h"
#include "mojo/public/cpp/bindings/associated_receiver.h" #include "mojo/public/cpp/bindings/associated_receiver.h"
...@@ -17,7 +18,6 @@ ...@@ -17,7 +18,6 @@
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#include "third_party/blink/public/mojom/loader/previews_resource_loading_hints.mojom.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace previews { namespace previews {
...@@ -27,7 +27,7 @@ namespace previews { ...@@ -27,7 +27,7 @@ namespace previews {
// the document loader. // the document loader.
class ResourceLoadingHintsAgent class ResourceLoadingHintsAgent
: public content::RenderFrameObserver, : public content::RenderFrameObserver,
public blink::mojom::PreviewsResourceLoadingHintsReceiver, public previews::mojom::PreviewsResourceLoadingHintsReceiver,
public base::SupportsWeakPtr<ResourceLoadingHintsAgent> { public base::SupportsWeakPtr<ResourceLoadingHintsAgent> {
public: public:
ResourceLoadingHintsAgent( ResourceLoadingHintsAgent(
...@@ -42,27 +42,26 @@ class ResourceLoadingHintsAgent ...@@ -42,27 +42,26 @@ class ResourceLoadingHintsAgent
GURL GetDocumentURL() const; GURL GetDocumentURL() const;
// blink::mojom::PreviewsResourceLoadingHintsReceiver: // previews::mojom::PreviewsResourceLoadingHintsReceiver:
void SetResourceLoadingHints(blink::mojom::PreviewsResourceLoadingHintsPtr void SetResourceLoadingHints(previews::mojom::PreviewsResourceLoadingHintsPtr
resource_loading_hints) override; resource_loading_hints) override;
void SetCompressPublicImagesHints(
blink::mojom::CompressPublicImagesHintsPtr images_hints) override;
void SetLiteVideoHint( void SetLiteVideoHint(
blink::mojom::LiteVideoHintPtr lite_video_hint) override; previews::mojom::LiteVideoHintPtr lite_video_hint) override;
void SetBlinkOptimizationGuideHints( void SetBlinkOptimizationGuideHints(
blink::mojom::BlinkOptimizationGuideHintsPtr hints) override; blink::mojom::BlinkOptimizationGuideHintsPtr hints) override;
void StopThrottlingMediaRequests() override; void StopThrottlingMediaRequests() override;
void SetReceiver( void SetReceiver(
mojo::PendingAssociatedReceiver< mojo::PendingAssociatedReceiver<
blink::mojom::PreviewsResourceLoadingHintsReceiver> receiver); previews::mojom::PreviewsResourceLoadingHintsReceiver> receiver);
bool IsMainFrame() const; bool IsMainFrame() const;
std::vector<std::string> subresource_patterns_to_block_; std::vector<std::string> subresource_patterns_to_block_;
base::Optional<int64_t> ukm_source_id_; base::Optional<int64_t> ukm_source_id_;
mojo::AssociatedReceiver<blink::mojom::PreviewsResourceLoadingHintsReceiver> mojo::AssociatedReceiver<
previews::mojom::PreviewsResourceLoadingHintsReceiver>
receiver_{this}; receiver_{this};
blink::mojom::BlinkOptimizationGuideHintsPtr blink_optimization_guide_hints_; blink::mojom::BlinkOptimizationGuideHintsPtr blink_optimization_guide_hints_;
......
...@@ -39,7 +39,7 @@ class SubresourceRedirectPublicImageHintsURLLoaderThrottleTest ...@@ -39,7 +39,7 @@ class SubresourceRedirectPublicImageHintsURLLoaderThrottleTest
void SetCompressPublicImagesHints( void SetCompressPublicImagesHints(
const std::vector<std::string>& public_image_urls) { const std::vector<std::string>& public_image_urls) {
subresource_redirect_hints_agent_->SetCompressPublicImagesHints( subresource_redirect_hints_agent_->SetCompressPublicImagesHints(
blink::mojom::CompressPublicImagesHints::New(public_image_urls)); mojom::CompressPublicImagesHints::New(public_image_urls));
} }
std::unique_ptr<PublicImageHintsURLLoaderThrottle> std::unique_ptr<PublicImageHintsURLLoaderThrottle>
...@@ -67,8 +67,8 @@ class SubresourceRedirectPublicImageHintsURLLoaderThrottleTest ...@@ -67,8 +67,8 @@ class SubresourceRedirectPublicImageHintsURLLoaderThrottleTest
{{blink::features::kSubresourceRedirect, {{blink::features::kSubresourceRedirect,
{{"enable_subresource_server_redirect", "true"}}}}, {{"enable_subresource_server_redirect", "true"}}}},
{}); {});
subresource_redirect_hints_agent_ = subresource_redirect_hints_agent_ = new SubresourceRedirectHintsAgent(
new SubresourceRedirectHintsAgent(view_->GetMainRenderFrame()); &associated_interfaces_, view_->GetMainRenderFrame());
} }
private: private:
......
...@@ -17,12 +17,18 @@ ...@@ -17,12 +17,18 @@
namespace subresource_redirect { namespace subresource_redirect {
SubresourceRedirectHintsAgent::SubresourceRedirectHintsAgent( SubresourceRedirectHintsAgent::SubresourceRedirectHintsAgent(
blink::AssociatedInterfaceRegistry* associated_interfaces,
content::RenderFrame* render_frame) content::RenderFrame* render_frame)
: content::RenderFrameObserver(render_frame), : content::RenderFrameObserver(render_frame),
content::RenderFrameObserverTracker<SubresourceRedirectHintsAgent>( content::RenderFrameObserverTracker<SubresourceRedirectHintsAgent>(
render_frame) { render_frame) {
DCHECK(render_frame); DCHECK(render_frame);
DCHECK(IsPublicImageHintsBasedCompressionEnabled()); DCHECK(IsPublicImageHintsBasedCompressionEnabled());
// base::Unretained is safe here because |this| is created for the RenderFrame
// never destroyed.
associated_interfaces->AddInterface(
base::BindRepeating(&SubresourceRedirectHintsAgent::BindHintsReceiver,
base::Unretained(this)));
} }
SubresourceRedirectHintsAgent::~SubresourceRedirectHintsAgent() = default; SubresourceRedirectHintsAgent::~SubresourceRedirectHintsAgent() = default;
...@@ -60,7 +66,7 @@ void SubresourceRedirectHintsAgent::OnDestruct() { ...@@ -60,7 +66,7 @@ void SubresourceRedirectHintsAgent::OnDestruct() {
} }
void SubresourceRedirectHintsAgent::SetCompressPublicImagesHints( void SubresourceRedirectHintsAgent::SetCompressPublicImagesHints(
blink::mojom::CompressPublicImagesHintsPtr images_hints) { mojom::CompressPublicImagesHintsPtr images_hints) {
if (!IsMainFrame()) if (!IsMainFrame())
return; return;
DCHECK(public_image_urls_.empty()); DCHECK(public_image_urls_.empty());
...@@ -185,4 +191,10 @@ void SubresourceRedirectHintsAgent::NotifyHttpsImageCompressionFetchFailed( ...@@ -185,4 +191,10 @@ void SubresourceRedirectHintsAgent::NotifyHttpsImageCompressionFetchFailed(
ClearImageHints(); ClearImageHints();
} }
void SubresourceRedirectHintsAgent::BindHintsReceiver(
mojo::PendingAssociatedReceiver<mojom::SubresourceRedirectHintsReceiver>
receiver) {
subresource_redirect_hints_receiver_.Bind(std::move(receiver));
}
} // namespace subresource_redirect } // namespace subresource_redirect
...@@ -9,12 +9,14 @@ ...@@ -9,12 +9,14 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chrome/common/previews_resource_loading_hints.mojom.h"
#include "chrome/common/subresource_redirect_service.mojom.h" #include "chrome/common/subresource_redirect_service.mojom.h"
#include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_frame_observer_tracker.h" #include "content/public/renderer/render_frame_observer_tracker.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#include "third_party/blink/public/mojom/loader/previews_resource_loading_hints.mojom.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace subresource_redirect { namespace subresource_redirect {
...@@ -23,6 +25,7 @@ namespace subresource_redirect { ...@@ -23,6 +25,7 @@ namespace subresource_redirect {
// redirects public images for mainframes. // redirects public images for mainframes.
class SubresourceRedirectHintsAgent class SubresourceRedirectHintsAgent
: public content::RenderFrameObserver, : public content::RenderFrameObserver,
public mojom::SubresourceRedirectHintsReceiver,
public content::RenderFrameObserverTracker< public content::RenderFrameObserverTracker<
SubresourceRedirectHintsAgent> { SubresourceRedirectHintsAgent> {
public: public:
...@@ -55,13 +58,19 @@ class SubresourceRedirectHintsAgent ...@@ -55,13 +58,19 @@ class SubresourceRedirectHintsAgent
kIneligibleOtherImage kIneligibleOtherImage
}; };
explicit SubresourceRedirectHintsAgent(content::RenderFrame* render_frame); explicit SubresourceRedirectHintsAgent(
blink::AssociatedInterfaceRegistry* associated_interfaces,
content::RenderFrame* render_frame);
~SubresourceRedirectHintsAgent() override; ~SubresourceRedirectHintsAgent() override;
SubresourceRedirectHintsAgent(const SubresourceRedirectHintsAgent&) = delete; SubresourceRedirectHintsAgent(const SubresourceRedirectHintsAgent&) = delete;
SubresourceRedirectHintsAgent& operator=( SubresourceRedirectHintsAgent& operator=(
const SubresourceRedirectHintsAgent&) = delete; const SubresourceRedirectHintsAgent&) = delete;
// mojom::SubresourceRedirectHintsReceiver:
void SetCompressPublicImagesHints(
mojom::CompressPublicImagesHintsPtr images_hints) override;
RedirectResult ShouldRedirectImage(const GURL& url) const; RedirectResult ShouldRedirectImage(const GURL& url) const;
// Record metrics when the resource load is finished. // Record metrics when the resource load is finished.
...@@ -69,9 +78,6 @@ class SubresourceRedirectHintsAgent ...@@ -69,9 +78,6 @@ class SubresourceRedirectHintsAgent
int64_t content_length, int64_t content_length,
RedirectResult redirect_result); RedirectResult redirect_result);
void SetCompressPublicImagesHints(
blink::mojom::CompressPublicImagesHintsPtr images_hints);
// Notifies the browser process that https image compression fetch had failed. // Notifies the browser process that https image compression fetch had failed.
void NotifyHttpsImageCompressionFetchFailed(base::TimeDelta retry_after); void NotifyHttpsImageCompressionFetchFailed(base::TimeDelta retry_after);
...@@ -99,6 +105,11 @@ class SubresourceRedirectHintsAgent ...@@ -99,6 +105,11 @@ class SubresourceRedirectHintsAgent
// image was in the delayed hints. // image was in the delayed hints.
void RecordImageHintsUnavailableMetrics(); void RecordImageHintsUnavailableMetrics();
// Binds the mojo hints receiver pipe.
void BindHintsReceiver(
mojo::PendingAssociatedReceiver<mojom::SubresourceRedirectHintsReceiver>
receiver);
bool public_image_urls_received_ = false; bool public_image_urls_received_ = false;
base::flat_set<std::string> public_image_urls_; base::flat_set<std::string> public_image_urls_;
...@@ -111,6 +122,9 @@ class SubresourceRedirectHintsAgent ...@@ -111,6 +122,9 @@ class SubresourceRedirectHintsAgent
// until hints are received or it times out and used to record metrics. // until hints are received or it times out and used to record metrics.
base::flat_set<std::pair<std::string, int64_t>> unavailable_image_hints_urls_; base::flat_set<std::pair<std::string, int64_t>> unavailable_image_hints_urls_;
mojo::AssociatedReceiver<mojom::SubresourceRedirectHintsReceiver>
subresource_redirect_hints_receiver_{this};
mojo::AssociatedRemote< mojo::AssociatedRemote<
subresource_redirect::mojom::SubresourceRedirectService> subresource_redirect::mojom::SubresourceRedirectService>
subresource_redirect_service_remote_; subresource_redirect_service_remote_;
......
...@@ -98,7 +98,6 @@ mojom("mojom_platform") { ...@@ -98,7 +98,6 @@ mojom("mojom_platform") {
"loader/fetch_client_settings_object.mojom", "loader/fetch_client_settings_object.mojom",
"loader/navigation_predictor.mojom", "loader/navigation_predictor.mojom",
"loader/pause_subresource_loading_handle.mojom", "loader/pause_subresource_loading_handle.mojom",
"loader/previews_resource_loading_hints.mojom",
"loader/referrer.mojom", "loader/referrer.mojom",
"loader/request_context_frame_type.mojom", "loader/request_context_frame_type.mojom",
"loader/resource_load_info.mojom", "loader/resource_load_info.mojom",
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include "mojo/public/cpp/bindings/binder_map.h" #include "mojo/public/cpp/bindings/binder_map.h"
#include "third_party/blink/public/common/experiments/memory_ablation_experiment.h" #include "third_party/blink/public/common/experiments/memory_ablation_experiment.h"
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/loader/previews_resource_loading_hints.mojom-blink.h" #include "third_party/blink/public/mojom/optimization_guide/optimization_guide.mojom-blink.h"
#include "third_party/blink/public/platform/interface_registry.h" #include "third_party/blink/public/platform/interface_registry.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/web/blink.h" #include "third_party/blink/public/web/blink.h"
......
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