Commit bdc683ae authored by Evan Stade's avatar Evan Stade Committed by Chromium LUCI CQ

Move GetWebPageMetadata into webapps component

Bug: 1164069
Change-Id: I5061c1c90688daf15ee2c42e233eaee37a9ea77b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2626196
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844800}
parent 897fe3be
...@@ -2276,6 +2276,8 @@ static_library("browser") { ...@@ -2276,6 +2276,8 @@ static_library("browser") {
"//components/web_cache/browser", "//components/web_cache/browser",
"//components/web_resource", "//components/web_resource",
"//components/webapps/browser", "//components/webapps/browser",
"//components/webapps/common",
"//components/webapps/common:mojo_bindings",
"//components/webdata/common", "//components/webdata/common",
"//components/webdata_services", "//components/webdata_services",
"//components/webrtc", "//components/webrtc",
......
...@@ -326,6 +326,7 @@ include_rules = [ ...@@ -326,6 +326,7 @@ include_rules = [
"+components/web_modal", "+components/web_modal",
"+components/web_resource", "+components/web_resource",
"+components/webapps/browser", "+components/webapps/browser",
"+components/webapps/common",
"+components/webdata/common", "+components/webdata/common",
"+components/webdata_services", "+components/webdata_services",
"+components/webrtc_logging/browser", "+components/webrtc_logging/browser",
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "base/task/thread_pool.h" #include "base/task/thread_pool.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "chrome/common/chrome_constants.h"
#include "components/dom_distiller/core/url_utils.h" #include "components/dom_distiller/core/url_utils.h"
#include "components/favicon/content/large_favicon_provider_getter.h" #include "components/favicon/content/large_favicon_provider_getter.h"
#include "components/favicon/core/large_favicon_provider.h" #include "components/favicon/core/large_favicon_provider.h"
...@@ -27,6 +26,7 @@ ...@@ -27,6 +26,7 @@
#include "components/webapps/browser/android/webapps_icon_utils.h" #include "components/webapps/browser/android/webapps_icon_utils.h"
#include "components/webapps/browser/android/webapps_utils.h" #include "components/webapps/browser/android/webapps_utils.h"
#include "components/webapps/browser/installable/installable_manager.h" #include "components/webapps/browser/installable/installable_manager.h"
#include "components/webapps/common/constants.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -128,31 +128,29 @@ AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( ...@@ -128,31 +128,29 @@ AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
DCHECK(shortcut_info_.url.is_valid()); DCHECK(shortcut_info_.url.is_valid());
// Send a message to the renderer to retrieve information about the page. // Send a message to the renderer to retrieve information about the page.
mojo::AssociatedRemote<chrome::mojom::ChromeRenderFrame> chrome_render_frame; mojo::AssociatedRemote<mojom::WebPageMetadataAgent> metadata_agent;
web_contents->GetMainFrame()->GetRemoteAssociatedInterfaces()->GetInterface( web_contents->GetMainFrame()->GetRemoteAssociatedInterfaces()->GetInterface(
&chrome_render_frame); &metadata_agent);
// Bind the InterfacePtr into the callback so that it's kept alive until // Bind the InterfacePtr into the callback so that it's kept alive until
// there's either a connection error or a response. // there's either a connection error or a response.
auto* web_page_metadata_proxy = chrome_render_frame.get(); auto* web_page_metadata_proxy = metadata_agent.get();
web_page_metadata_proxy->GetWebPageMetadata(base::BindOnce( web_page_metadata_proxy->GetWebPageMetadata(base::BindOnce(
&AddToHomescreenDataFetcher::OnDidGetWebPageMetadata, &AddToHomescreenDataFetcher::OnDidGetWebPageMetadata,
weak_ptr_factory_.GetWeakPtr(), base::Passed(&chrome_render_frame))); weak_ptr_factory_.GetWeakPtr(), base::Passed(&metadata_agent)));
} }
AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() = default; AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() = default;
void AddToHomescreenDataFetcher::OnDidGetWebPageMetadata( void AddToHomescreenDataFetcher::OnDidGetWebPageMetadata(
mojo::AssociatedRemote<chrome::mojom::ChromeRenderFrame> mojo::AssociatedRemote<mojom::WebPageMetadataAgent> metadata_agent,
chrome_render_frame, mojom::WebPageMetadataPtr web_page_metadata) {
chrome::mojom::WebPageMetadataPtr web_page_metadata) {
if (!web_contents()) if (!web_contents())
return; return;
// Note, the title should have already been clipped on the renderer side. // Note, the title should have already been clipped on the renderer side.
// TODO(https://crbug.com/673422): Would be nice if this constraint could be // TODO(https://crbug.com/673422): Would be nice if this constraint could be
// specified directly in the mojom file and enforced automatically. // specified directly in the mojom file and enforced automatically.
if (web_page_metadata->application_name.size() > if (web_page_metadata->application_name.size() > kMaxMetaTagAttributeLength) {
chrome::kMaxMetaTagAttributeLength) {
mojo::ReportBadMessage("application_name is too long"); mojo::ReportBadMessage("application_name is too long");
return; return;
} }
...@@ -165,9 +163,9 @@ void AddToHomescreenDataFetcher::OnDidGetWebPageMetadata( ...@@ -165,9 +163,9 @@ void AddToHomescreenDataFetcher::OnDidGetWebPageMetadata(
shortcut_info_.name = shortcut_info_.user_title; shortcut_info_.name = shortcut_info_.user_title;
if (web_page_metadata->mobile_capable == if (web_page_metadata->mobile_capable ==
chrome::mojom::WebPageMobileCapable::ENABLED || mojom::WebPageMobileCapable::ENABLED ||
web_page_metadata->mobile_capable == web_page_metadata->mobile_capable ==
chrome::mojom::WebPageMobileCapable::ENABLED_APPLE) { mojom::WebPageMobileCapable::ENABLED_APPLE) {
shortcut_info_.display = blink::mojom::DisplayMode::kStandalone; shortcut_info_.display = blink::mojom::DisplayMode::kStandalone;
shortcut_info_.UpdateSource( shortcut_info_.UpdateSource(
ShortcutInfo::SOURCE_ADD_TO_HOMESCREEN_STANDALONE); ShortcutInfo::SOURCE_ADD_TO_HOMESCREEN_STANDALONE);
...@@ -175,15 +173,15 @@ void AddToHomescreenDataFetcher::OnDidGetWebPageMetadata( ...@@ -175,15 +173,15 @@ void AddToHomescreenDataFetcher::OnDidGetWebPageMetadata(
// Record what type of shortcut was added by the user. // Record what type of shortcut was added by the user.
switch (web_page_metadata->mobile_capable) { switch (web_page_metadata->mobile_capable) {
case chrome::mojom::WebPageMobileCapable::ENABLED: case mojom::WebPageMobileCapable::ENABLED:
base::RecordAction( base::RecordAction(
base::UserMetricsAction("webapps.AddShortcut.AppShortcut")); base::UserMetricsAction("webapps.AddShortcut.AppShortcut"));
break; break;
case chrome::mojom::WebPageMobileCapable::ENABLED_APPLE: case mojom::WebPageMobileCapable::ENABLED_APPLE:
base::RecordAction( base::RecordAction(
base::UserMetricsAction("webapps.AddShortcut.AppShortcutApple")); base::UserMetricsAction("webapps.AddShortcut.AppShortcutApple"));
break; break;
case chrome::mojom::WebPageMobileCapable::UNSPECIFIED: case mojom::WebPageMobileCapable::UNSPECIFIED:
base::RecordAction( base::RecordAction(
base::UserMetricsAction("webapps.AddShortcut.Bookmark")); base::UserMetricsAction("webapps.AddShortcut.Bookmark"));
break; break;
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "base/task/cancelable_task_tracker.h" #include "base/task/cancelable_task_tracker.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chrome/common/chrome_render_frame.mojom.h"
#include "components/webapps/browser/android/shortcut_info.h" #include "components/webapps/browser/android/shortcut_info.h"
#include "components/webapps/common/web_page_metadata_agent.mojom.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/bindings/associated_remote.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
...@@ -58,9 +58,8 @@ class AddToHomescreenDataFetcher : public content::WebContentsObserver { ...@@ -58,9 +58,8 @@ class AddToHomescreenDataFetcher : public content::WebContentsObserver {
// IPC message received when the initialization is finished. // IPC message received when the initialization is finished.
void OnDidGetWebPageMetadata( void OnDidGetWebPageMetadata(
mojo::AssociatedRemote<chrome::mojom::ChromeRenderFrame> mojo::AssociatedRemote<mojom::WebPageMetadataAgent> webapps_render_frame,
chrome_render_frame, mojom::WebPageMetadataPtr web_page_metadata);
chrome::mojom::WebPageMetadataPtr web_page_metadata);
// Accessors, etc. // Accessors, etc.
const SkBitmap& primary_icon() const { return primary_icon_; } const SkBitmap& primary_icon() const { return primary_icon_; }
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "chrome/browser/favicon/favicon_service_factory.h" #include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/flags/android/chrome_feature_list.h" #include "chrome/browser/flags/android/chrome_feature_list.h"
#include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/web_applications/components/web_application_info.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/webapps/browser/installable/installable_manager.h" #include "components/webapps/browser/installable/installable_manager.h"
...@@ -241,13 +240,13 @@ class AddToHomescreenDataFetcherTest : public ChromeRenderViewHostTestHarness { ...@@ -241,13 +240,13 @@ class AddToHomescreenDataFetcherTest : public ChromeRenderViewHostTestHarness {
const char* expected_name, const char* expected_name,
blink::mojom::DisplayMode display_mode, blink::mojom::DisplayMode display_mode,
bool is_webapk_compatible) { bool is_webapk_compatible) {
chrome::mojom::WebPageMetadataPtr web_page_metadata( webapps::mojom::WebPageMetadataPtr web_page_metadata(
chrome::mojom::WebPageMetadata::New()); webapps::mojom::WebPageMetadata::New());
web_page_metadata->application_name = web_page_metadata->application_name =
base::ASCIIToUTF16(kWebApplicationInfoTitle); base::ASCIIToUTF16(kWebApplicationInfoTitle);
fetcher->OnDidGetWebPageMetadata( fetcher->OnDidGetWebPageMetadata(
mojo::AssociatedRemote<chrome::mojom::ChromeRenderFrame>(), mojo::AssociatedRemote<webapps::mojom::WebPageMetadataAgent>(),
std::move(web_page_metadata)); std::move(web_page_metadata));
waiter.WaitForDataAvailable(); waiter.WaitForDataAvailable();
......
...@@ -154,6 +154,7 @@ source_set("components") { ...@@ -154,6 +154,7 @@ source_set("components") {
"//components/site_engagement/core/mojom:mojo_bindings", "//components/site_engagement/core/mojom:mojo_bindings",
"//components/user_manager:user_manager", "//components/user_manager:user_manager",
"//components/webapps/browser", "//components/webapps/browser",
"//components/webapps/common:mojo_bindings",
"//content/public/browser", "//content/public/browser",
"//extensions/common:common_constants", "//extensions/common:common_constants",
"//net", "//net",
...@@ -224,6 +225,7 @@ source_set("unit_tests") { ...@@ -224,6 +225,7 @@ source_set("unit_tests") {
"//chrome/test:test_support", "//chrome/test:test_support",
"//components/webapps/browser", "//components/webapps/browser",
"//components/webapps/browser:test_support", "//components/webapps/browser:test_support",
"//components/webapps/common:mojo_bindings",
"//content/public/browser", "//content/public/browser",
"//services/preferences/public/cpp", "//services/preferences/public/cpp",
"//skia", "//skia",
......
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/web_applications/components/web_app_icon_generator.h" #include "chrome/browser/web_applications/components/web_app_icon_generator.h"
#include "chrome/browser/web_applications/components/web_application_info.h" #include "chrome/browser/web_applications/components/web_application_info.h"
#include "chrome/common/chrome_render_frame.mojom.h"
#include "components/webapps/browser/installable/installable_data.h" #include "components/webapps/browser/installable/installable_data.h"
#include "components/webapps/browser/installable/installable_manager.h" #include "components/webapps/browser/installable/installable_manager.h"
#include "components/webapps/common/web_page_metadata_agent.mojom.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -60,23 +60,23 @@ void WebAppDataRetriever::GetWebApplicationInfo( ...@@ -60,23 +60,23 @@ void WebAppDataRetriever::GetWebApplicationInfo(
base::UTF8ToUTF16(default_web_application_info_->start_url.spec()); base::UTF8ToUTF16(default_web_application_info_->start_url.spec());
} }
mojo::AssociatedRemote<chrome::mojom::ChromeRenderFrame> chrome_render_frame; mojo::AssociatedRemote<webapps::mojom::WebPageMetadataAgent> metadata_agent;
web_contents->GetMainFrame()->GetRemoteAssociatedInterfaces()->GetInterface( web_contents->GetMainFrame()->GetRemoteAssociatedInterfaces()->GetInterface(
&chrome_render_frame); &metadata_agent);
// Set the error handler so that we can run |get_web_app_info_callback_| if // Set the error handler so that we can run |get_web_app_info_callback_| if
// the WebContents or the RenderFrameHost are destroyed and the connection // the WebContents or the RenderFrameHost are destroyed and the connection
// to ChromeRenderFrame is lost. // to ChromeRenderFrame is lost.
chrome_render_frame.set_disconnect_handler( metadata_agent.set_disconnect_handler(
base::BindOnce(&WebAppDataRetriever::CallCallbackOnError, base::BindOnce(&WebAppDataRetriever::CallCallbackOnError,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
// Bind the InterfacePtr into the callback so that it's kept alive // Bind the InterfacePtr into the callback so that it's kept alive
// until there's either a connection error or a response. // until there's either a connection error or a response.
auto* web_page_metadata_proxy = chrome_render_frame.get(); auto* web_page_metadata_proxy = metadata_agent.get();
web_page_metadata_proxy->GetWebPageMetadata( web_page_metadata_proxy->GetWebPageMetadata(
base::BindOnce(&WebAppDataRetriever::OnGetWebPageMetadata, base::BindOnce(&WebAppDataRetriever::OnGetWebPageMetadata,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(), std::move(metadata_agent),
std::move(chrome_render_frame), entry->GetUniqueID())); entry->GetUniqueID()));
} }
void WebAppDataRetriever::CheckInstallabilityAndRetrieveManifest( void WebAppDataRetriever::CheckInstallabilityAndRetrieveManifest(
...@@ -139,10 +139,9 @@ void WebAppDataRetriever::RenderProcessGone(base::TerminationStatus status) { ...@@ -139,10 +139,9 @@ void WebAppDataRetriever::RenderProcessGone(base::TerminationStatus status) {
} }
void WebAppDataRetriever::OnGetWebPageMetadata( void WebAppDataRetriever::OnGetWebPageMetadata(
mojo::AssociatedRemote<chrome::mojom::ChromeRenderFrame> mojo::AssociatedRemote<webapps::mojom::WebPageMetadataAgent> metadata_agent,
chrome_render_frame,
int last_committed_nav_entry_unique_id, int last_committed_nav_entry_unique_id,
chrome::mojom::WebPageMetadataPtr web_page_metadata) { webapps::mojom::WebPageMetadataPtr web_page_metadata) {
if (ShouldStopRetrieval()) if (ShouldStopRetrieval())
return; return;
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include "base/optional.h" #include "base/optional.h"
#include "chrome/browser/web_applications/components/web_app_icon_downloader.h" #include "chrome/browser/web_applications/components/web_app_icon_downloader.h"
#include "chrome/browser/web_applications/components/web_app_install_utils.h" #include "chrome/browser/web_applications/components/web_app_install_utils.h"
#include "chrome/common/chrome_render_frame.mojom-forward.h" #include "components/webapps/common/web_page_metadata.mojom-forward.h"
#include "chrome/common/web_page_metadata.mojom-forward.h" #include "components/webapps/common/web_page_metadata_agent.mojom-forward.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/bindings/associated_remote.h"
...@@ -83,10 +83,10 @@ class WebAppDataRetriever : content::WebContentsObserver { ...@@ -83,10 +83,10 @@ class WebAppDataRetriever : content::WebContentsObserver {
private: private:
void OnGetWebPageMetadata( void OnGetWebPageMetadata(
mojo::AssociatedRemote<chrome::mojom::ChromeRenderFrame> mojo::AssociatedRemote<webapps::mojom::WebPageMetadataAgent>
chrome_render_frame, metadata_agent,
int last_committed_nav_entry_unique_id, int last_committed_nav_entry_unique_id,
chrome::mojom::WebPageMetadataPtr web_page_metadata); webapps::mojom::WebPageMetadataPtr web_page_metadata);
void OnDidPerformInstallableCheck(const webapps::InstallableData& data); void OnDidPerformInstallableCheck(const webapps::InstallableData& data);
void OnIconsDownloaded(bool success, IconsMap icons_map); void OnIconsDownloaded(bool success, IconsMap icons_map);
......
...@@ -14,14 +14,14 @@ ...@@ -14,14 +14,14 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h" #include "base/test/bind.h"
#include "chrome/browser/web_applications/components/web_application_info.h" #include "chrome/browser/web_applications/components/web_application_info.h"
#include "chrome/common/chrome_render_frame.mojom-test-utils.h"
#include "chrome/common/web_page_metadata.mojom.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/webapps/browser/installable/fake_installable_manager.h" #include "components/webapps/browser/installable/fake_installable_manager.h"
#include "components/webapps/browser/installable/installable_data.h" #include "components/webapps/browser/installable/installable_data.h"
#include "components/webapps/browser/installable/installable_manager.h" #include "components/webapps/browser/installable/installable_manager.h"
#include "components/webapps/browser/installable/installable_metrics.h" #include "components/webapps/browser/installable/installable_metrics.h"
#include "components/webapps/common/web_page_metadata.mojom.h"
#include "components/webapps/common/web_page_metadata_agent.mojom-test-utils.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
#include "content/public/browser/site_instance.h" #include "content/public/browser/site_instance.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
...@@ -53,20 +53,20 @@ GURL BarUrl() { ...@@ -53,20 +53,20 @@ GURL BarUrl() {
} // namespace } // namespace
class FakeChromeRenderFrame class FakeWebPageMetadataAgent
: public chrome::mojom::ChromeRenderFrameInterceptorForTesting { : public webapps::mojom::WebPageMetadataAgentInterceptorForTesting {
public: public:
FakeChromeRenderFrame() = default; FakeWebPageMetadataAgent() = default;
~FakeChromeRenderFrame() override = default; ~FakeWebPageMetadataAgent() override = default;
ChromeRenderFrame* GetForwardingInterface() override { WebPageMetadataAgent* GetForwardingInterface() override {
NOTREACHED(); NOTREACHED();
return nullptr; return nullptr;
} }
void Bind(mojo::ScopedInterfaceEndpointHandle handle) { void Bind(mojo::ScopedInterfaceEndpointHandle handle) {
receiver_.Bind( receiver_.Bind(mojo::PendingAssociatedReceiver<WebPageMetadataAgent>(
mojo::PendingAssociatedReceiver<ChromeRenderFrame>(std::move(handle))); std::move(handle)));
} }
// Set |web_app_info| to respond on |GetWebApplicationInfo|. // Set |web_app_info| to respond on |GetWebApplicationInfo|.
...@@ -75,8 +75,8 @@ class FakeChromeRenderFrame ...@@ -75,8 +75,8 @@ class FakeChromeRenderFrame
} }
void GetWebPageMetadata(GetWebPageMetadataCallback callback) override { void GetWebPageMetadata(GetWebPageMetadataCallback callback) override {
chrome::mojom::WebPageMetadataPtr web_page_metadata( webapps::mojom::WebPageMetadataPtr web_page_metadata(
chrome::mojom::WebPageMetadata::New()); webapps::mojom::WebPageMetadata::New());
web_page_metadata->application_name = web_app_info_.title; web_page_metadata->application_name = web_app_info_.title;
web_page_metadata->description = web_app_info_.description; web_page_metadata->description = web_app_info_.description;
web_page_metadata->application_url = web_app_info_.start_url; web_page_metadata->application_url = web_app_info_.start_url;
...@@ -92,7 +92,8 @@ class FakeChromeRenderFrame ...@@ -92,7 +92,8 @@ class FakeChromeRenderFrame
private: private:
WebApplicationInfo web_app_info_; WebApplicationInfo web_app_info_;
mojo::AssociatedReceiver<chrome::mojom::ChromeRenderFrame> receiver_{this}; mojo::AssociatedReceiver<webapps::mojom::WebPageMetadataAgent> receiver_{
this};
}; };
class WebAppDataRetrieverTest : public ChromeRenderViewHostTestHarness { class WebAppDataRetrieverTest : public ChromeRenderViewHostTestHarness {
...@@ -102,14 +103,14 @@ class WebAppDataRetrieverTest : public ChromeRenderViewHostTestHarness { ...@@ -102,14 +103,14 @@ class WebAppDataRetrieverTest : public ChromeRenderViewHostTestHarness {
WebAppDataRetrieverTest& operator=(const WebAppDataRetrieverTest&) = delete; WebAppDataRetrieverTest& operator=(const WebAppDataRetrieverTest&) = delete;
~WebAppDataRetrieverTest() override = default; ~WebAppDataRetrieverTest() override = default;
// Set fake ChromeRenderFrame to avoid mojo connection errors. // Set fake WebPageMetadataAgent to avoid mojo connection errors.
void SetFakeChromeRenderFrame() { void SetFakeWebPageMetadataAgent() {
web_contents() web_contents()
->GetMainFrame() ->GetMainFrame()
->GetRemoteAssociatedInterfaces() ->GetRemoteAssociatedInterfaces()
->OverrideBinderForTesting( ->OverrideBinderForTesting(
chrome::mojom::ChromeRenderFrame::Name_, webapps::mojom::WebPageMetadataAgent::Name_,
base::BindRepeating(&FakeChromeRenderFrame::Bind, base::BindRepeating(&FakeWebPageMetadataAgent::Bind,
base::Unretained(&fake_chrome_render_frame_))); base::Unretained(&fake_chrome_render_frame_)));
// When ProactivelySwapBrowsingInstance or RenderDocument is enabled on // When ProactivelySwapBrowsingInstance or RenderDocument is enabled on
...@@ -170,14 +171,13 @@ class WebAppDataRetrieverTest : public ChromeRenderViewHostTestHarness { ...@@ -170,14 +171,13 @@ class WebAppDataRetrieverTest : public ChromeRenderViewHostTestHarness {
const std::vector<WebApplicationIconInfo>& icons() { return icons_; } const std::vector<WebApplicationIconInfo>& icons() { return icons_; }
private: private:
FakeChromeRenderFrame fake_chrome_render_frame_; FakeWebPageMetadataAgent fake_chrome_render_frame_;
base::Optional<std::unique_ptr<WebApplicationInfo>> web_app_info_; base::Optional<std::unique_ptr<WebApplicationInfo>> web_app_info_;
std::vector<WebApplicationIconInfo> icons_; std::vector<WebApplicationIconInfo> icons_;
}; };
TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_NoEntry) { TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_NoEntry) {
SetFakeChromeRenderFrame(); SetFakeWebPageMetadataAgent();
base::RunLoop run_loop; base::RunLoop run_loop;
WebAppDataRetriever retriever; WebAppDataRetriever retriever;
...@@ -191,7 +191,7 @@ TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_NoEntry) { ...@@ -191,7 +191,7 @@ TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_NoEntry) {
} }
TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_AppUrlAbsent) { TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_AppUrlAbsent) {
SetFakeChromeRenderFrame(); SetFakeWebPageMetadataAgent();
web_contents_tester()->NavigateAndCommit(FooUrl()); web_contents_tester()->NavigateAndCommit(FooUrl());
...@@ -214,7 +214,7 @@ TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_AppUrlAbsent) { ...@@ -214,7 +214,7 @@ TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_AppUrlAbsent) {
} }
TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_AppUrlPresent) { TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_AppUrlPresent) {
SetFakeChromeRenderFrame(); SetFakeWebPageMetadataAgent();
web_contents_tester()->NavigateAndCommit(FooUrl()); web_contents_tester()->NavigateAndCommit(FooUrl());
...@@ -235,7 +235,7 @@ TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_AppUrlPresent) { ...@@ -235,7 +235,7 @@ TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_AppUrlPresent) {
} }
TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_TitleAbsentFromRenderer) { TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_TitleAbsentFromRenderer) {
SetFakeChromeRenderFrame(); SetFakeWebPageMetadataAgent();
web_contents_tester()->NavigateAndCommit(FooUrl()); web_contents_tester()->NavigateAndCommit(FooUrl());
...@@ -262,7 +262,7 @@ TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_TitleAbsentFromRenderer) { ...@@ -262,7 +262,7 @@ TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_TitleAbsentFromRenderer) {
TEST_F(WebAppDataRetrieverTest, TEST_F(WebAppDataRetrieverTest,
GetWebApplicationInfo_TitleAbsentFromWebContents) { GetWebApplicationInfo_TitleAbsentFromWebContents) {
SetFakeChromeRenderFrame(); SetFakeWebPageMetadataAgent();
web_contents_tester()->NavigateAndCommit(FooUrl()); web_contents_tester()->NavigateAndCommit(FooUrl());
...@@ -281,14 +281,14 @@ TEST_F(WebAppDataRetrieverTest, ...@@ -281,14 +281,14 @@ TEST_F(WebAppDataRetrieverTest,
base::Unretained(this), run_loop.QuitClosure())); base::Unretained(this), run_loop.QuitClosure()));
run_loop.Run(); run_loop.Run();
// If the WebApplicationInfo has no title and the WebContents has no title, // If the WebApplicationInfo has no title and the WebContents has no title, we
// we fallback to start_url. // fallback to start_url.
EXPECT_EQ(base::UTF8ToUTF16(web_app_info()->start_url.spec()), EXPECT_EQ(base::UTF8ToUTF16(web_app_info()->start_url.spec()),
web_app_info()->title); web_app_info()->title);
} }
TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_ConnectionError) { TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_ConnectionError) {
// Do not set fake ChromeRenderFrame to simulate connection error. // Do not set fake WebPageMetadataAgent to simulate connection error.
web_contents_tester()->NavigateAndCommit(FooUrl()); web_contents_tester()->NavigateAndCommit(FooUrl());
...@@ -304,7 +304,7 @@ TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_ConnectionError) { ...@@ -304,7 +304,7 @@ TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_ConnectionError) {
} }
TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_WebContentsDestroyed) { TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_WebContentsDestroyed) {
SetFakeChromeRenderFrame(); SetFakeWebPageMetadataAgent();
web_contents_tester()->NavigateAndCommit(FooUrl()); web_contents_tester()->NavigateAndCommit(FooUrl());
...@@ -322,7 +322,7 @@ TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_WebContentsDestroyed) { ...@@ -322,7 +322,7 @@ TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_WebContentsDestroyed) {
TEST_F(WebAppDataRetrieverTest, TEST_F(WebAppDataRetrieverTest,
CheckInstallabilityAndRetrieveManifest_WebContentsDestroyed) { CheckInstallabilityAndRetrieveManifest_WebContentsDestroyed) {
SetFakeChromeRenderFrame(); SetFakeWebPageMetadataAgent();
web_contents_tester()->NavigateAndCommit(FooUrl()); web_contents_tester()->NavigateAndCommit(FooUrl());
...@@ -349,7 +349,7 @@ TEST_F(WebAppDataRetrieverTest, ...@@ -349,7 +349,7 @@ TEST_F(WebAppDataRetrieverTest,
} }
TEST_F(WebAppDataRetrieverTest, GetIcons_WebContentsDestroyed) { TEST_F(WebAppDataRetrieverTest, GetIcons_WebContentsDestroyed) {
SetFakeChromeRenderFrame(); SetFakeWebPageMetadataAgent();
web_contents_tester()->NavigateAndCommit(FooUrl()); web_contents_tester()->NavigateAndCommit(FooUrl());
...@@ -369,7 +369,7 @@ TEST_F(WebAppDataRetrieverTest, GetIcons_WebContentsDestroyed) { ...@@ -369,7 +369,7 @@ TEST_F(WebAppDataRetrieverTest, GetIcons_WebContentsDestroyed) {
} }
TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_FrameNavigated) { TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_FrameNavigated) {
SetFakeChromeRenderFrame(); SetFakeWebPageMetadataAgent();
const auto web_contents_title = base::UTF8ToUTF16(kFooTitle); const auto web_contents_title = base::UTF8ToUTF16(kFooTitle);
web_contents_tester()->SetTitle(web_contents_title); web_contents_tester()->SetTitle(web_contents_title);
...@@ -390,7 +390,7 @@ TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_FrameNavigated) { ...@@ -390,7 +390,7 @@ TEST_F(WebAppDataRetrieverTest, GetWebApplicationInfo_FrameNavigated) {
} }
TEST_F(WebAppDataRetrieverTest, CheckInstallabilityAndRetrieveManifest) { TEST_F(WebAppDataRetrieverTest, CheckInstallabilityAndRetrieveManifest) {
SetFakeChromeRenderFrame(); SetFakeWebPageMetadataAgent();
const GURL manifest_start_url = GURL("https://example.com/start"); const GURL manifest_start_url = GURL("https://example.com/start");
const base::string16 manifest_short_name = const base::string16 manifest_short_name =
...@@ -439,7 +439,7 @@ TEST_F(WebAppDataRetrieverTest, CheckInstallabilityAndRetrieveManifest) { ...@@ -439,7 +439,7 @@ TEST_F(WebAppDataRetrieverTest, CheckInstallabilityAndRetrieveManifest) {
} }
TEST_F(WebAppDataRetrieverTest, CheckInstallabilityFails) { TEST_F(WebAppDataRetrieverTest, CheckInstallabilityFails) {
SetFakeChromeRenderFrame(); SetFakeWebPageMetadataAgent();
{ {
auto manifest = std::make_unique<blink::Manifest>(); auto manifest = std::make_unique<blink::Manifest>();
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "chrome/browser/web_applications/components/web_application_info.h" #include "chrome/browser/web_applications/components/web_application_info.h"
#include "chrome/common/web_page_metadata.mojom.h" #include "components/webapps/common/web_page_metadata.mojom.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom.h" #include "third_party/blink/public/mojom/manifest/manifest.mojom.h"
// WebApplicationIconInfo // WebApplicationIconInfo
...@@ -74,7 +74,7 @@ WebApplicationInfo::WebApplicationInfo(const WebApplicationInfo& other) = ...@@ -74,7 +74,7 @@ WebApplicationInfo::WebApplicationInfo(const WebApplicationInfo& other) =
default; default;
WebApplicationInfo::WebApplicationInfo( WebApplicationInfo::WebApplicationInfo(
const chrome::mojom::WebPageMetadata& metadata) const webapps::mojom::WebPageMetadata& metadata)
: title(metadata.application_name), : title(metadata.application_name),
description(metadata.description), description(metadata.description),
start_url(metadata.application_url) { start_url(metadata.application_url) {
...@@ -86,13 +86,13 @@ WebApplicationInfo::WebApplicationInfo( ...@@ -86,13 +86,13 @@ WebApplicationInfo::WebApplicationInfo(
icon_infos.push_back(icon_info); icon_infos.push_back(icon_info);
} }
switch (metadata.mobile_capable) { switch (metadata.mobile_capable) {
case chrome::mojom::WebPageMobileCapable::UNSPECIFIED: case webapps::mojom::WebPageMobileCapable::UNSPECIFIED:
mobile_capable = MOBILE_CAPABLE_UNSPECIFIED; mobile_capable = MOBILE_CAPABLE_UNSPECIFIED;
break; break;
case chrome::mojom::WebPageMobileCapable::ENABLED: case webapps::mojom::WebPageMobileCapable::ENABLED:
mobile_capable = MOBILE_CAPABLE; mobile_capable = MOBILE_CAPABLE;
break; break;
case chrome::mojom::WebPageMobileCapable::ENABLED_APPLE: case webapps::mojom::WebPageMobileCapable::ENABLED_APPLE:
mobile_capable = MOBILE_CAPABLE_APPLE; mobile_capable = MOBILE_CAPABLE_APPLE;
break; break;
} }
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#include "base/containers/flat_set.h" #include "base/containers/flat_set.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/common/web_page_metadata.mojom-forward.h"
#include "components/services/app_service/public/cpp/share_target.h" #include "components/services/app_service/public/cpp/share_target.h"
#include "components/webapps/common/web_page_metadata.mojom-forward.h"
#include "third_party/blink/public/common/manifest/manifest.h" #include "third_party/blink/public/common/manifest/manifest.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom.h" #include "third_party/blink/public/mojom/manifest/display_mode.mojom.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom-shared.h" #include "third_party/blink/public/mojom/manifest/manifest.mojom-shared.h"
...@@ -94,7 +94,7 @@ struct WebApplicationInfo { ...@@ -94,7 +94,7 @@ struct WebApplicationInfo {
WebApplicationInfo(); WebApplicationInfo();
WebApplicationInfo(const WebApplicationInfo& other); WebApplicationInfo(const WebApplicationInfo& other);
explicit WebApplicationInfo(const chrome::mojom::WebPageMetadata& metadata); explicit WebApplicationInfo(const webapps::mojom::WebPageMetadata& metadata);
~WebApplicationInfo(); ~WebApplicationInfo();
// Title of the application. // Title of the application.
......
...@@ -717,7 +717,6 @@ mojom("mojo_bindings") { ...@@ -717,7 +717,6 @@ mojom("mojo_bindings") {
"renderer_configuration.mojom", "renderer_configuration.mojom",
"subresource_redirect_service.mojom", "subresource_redirect_service.mojom",
"sync_encryption_keys_extension.mojom", "sync_encryption_keys_extension.mojom",
"web_page_metadata.mojom",
] ]
deps = [] deps = []
......
...@@ -217,8 +217,6 @@ const char kLockScreenProfile[] = "LockScreenProfile"; ...@@ -217,8 +217,6 @@ const char kLockScreenProfile[] = "LockScreenProfile";
const char kApplicationClientIDStringForAVScanning[] = const char kApplicationClientIDStringForAVScanning[] =
"2676A9A2-D919-4FEE-9187-152100393AB2"; "2676A9A2-D919-4FEE-9187-152100393AB2";
const size_t kMaxMetaTagAttributeLength = 2000;
} // namespace chrome } // namespace chrome
#undef FPL #undef FPL
...@@ -118,9 +118,6 @@ extern const char kLockScreenProfile[]; ...@@ -118,9 +118,6 @@ extern const char kLockScreenProfile[];
// Used to identify the application to the system AV function in Windows. // Used to identify the application to the system AV function in Windows.
extern const char kApplicationClientIDStringForAVScanning[]; extern const char kApplicationClientIDStringForAVScanning[];
// The largest reasonable length we'd assume for a meta tag attribute.
extern const size_t kMaxMetaTagAttributeLength;
} // namespace chrome } // namespace chrome
#endif // CHROME_COMMON_CHROME_CONSTANTS_H_ #endif // CHROME_COMMON_CHROME_CONSTANTS_H_
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
module chrome.mojom; module chrome.mojom;
import "chrome/common/web_page_metadata.mojom";
import "mojo/public/mojom/base/string16.mojom"; import "mojo/public/mojom/base/string16.mojom";
import "third_party/blink/public/mojom/window_features/window_features.mojom"; import "third_party/blink/public/mojom/window_features/window_features.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom"; import "ui/gfx/geometry/mojom/geometry.mojom";
...@@ -46,9 +45,6 @@ interface ChromeRenderFrame { ...@@ -46,9 +45,6 @@ interface ChromeRenderFrame {
// before onload events are fired. // before onload events are fired.
ExecuteWebUIJavaScript(mojo_base.mojom.String16 javascript); ExecuteWebUIJavaScript(mojo_base.mojom.String16 javascript);
// Requests the web page metadata from the renderer.
GetWebPageMetadata() => (WebPageMetadata web_page_metadata);
// Sets a header identifying the CCT session. // Sets a header identifying the CCT session.
[EnableIf=is_android] [EnableIf=is_android]
SetCCTClientHeader(string header); SetCCTClientHeader(string header);
......
...@@ -120,8 +120,6 @@ static_library("renderer") { ...@@ -120,8 +120,6 @@ static_library("renderer") {
"url_loader_throttle_provider_impl.h", "url_loader_throttle_provider_impl.h",
"v8_unwinder.cc", "v8_unwinder.cc",
"v8_unwinder.h", "v8_unwinder.h",
"web_page_metadata_extraction.cc",
"web_page_metadata_extraction.h",
"websocket_handshake_throttle_provider_impl.cc", "websocket_handshake_throttle_provider_impl.cc",
"websocket_handshake_throttle_provider_impl.h", "websocket_handshake_throttle_provider_impl.h",
"worker_content_settings_client.cc", "worker_content_settings_client.cc",
...@@ -192,6 +190,7 @@ static_library("renderer") { ...@@ -192,6 +190,7 @@ static_library("renderer") {
"//components/translate/core/language_detection", "//components/translate/core/language_detection",
"//components/visitedlink/renderer", "//components/visitedlink/renderer",
"//components/web_cache/renderer", "//components/web_cache/renderer",
"//components/webapps/renderer",
"//content/app/resources", "//content/app/resources",
"//content/public/child", "//content/public/child",
"//content/public/common", "//content/public/common",
......
...@@ -60,6 +60,7 @@ include_rules = [ ...@@ -60,6 +60,7 @@ include_rules = [
"+components/translate/core/language_detection", "+components/translate/core/language_detection",
"+components/version_info", "+components/version_info",
"+components/visitedlink/renderer", "+components/visitedlink/renderer",
"+components/webapps/renderer",
"+components/web_cache/renderer", "+components/web_cache/renderer",
"+content/public/child", "+content/public/child",
"+content/public/renderer", "+content/public/renderer",
......
...@@ -110,6 +110,7 @@ ...@@ -110,6 +110,7 @@
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
#include "components/visitedlink/renderer/visitedlink_reader.h" #include "components/visitedlink/renderer/visitedlink_reader.h"
#include "components/web_cache/renderer/web_cache_impl.h" #include "components/web_cache/renderer/web_cache_impl.h"
#include "components/webapps/renderer/web_page_metadata_agent.h"
#include "content/public/common/content_constants.h" #include "content/public/common/content_constants.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
...@@ -521,6 +522,9 @@ void ChromeContentRendererClient::RenderFrameCreated( ...@@ -521,6 +522,9 @@ void ChromeContentRendererClient::RenderFrameCreated(
} }
#endif #endif
if (render_frame->IsMainFrame())
new webapps::WebPageMetadataAgent(render_frame);
new NetErrorHelper(render_frame); new NetErrorHelper(render_frame);
#if BUILDFLAG(ENABLE_SUPERVISED_USERS) #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
......
...@@ -22,10 +22,8 @@ ...@@ -22,10 +22,8 @@
#include "chrome/common/chrome_isolated_world_ids.h" #include "chrome/common/chrome_isolated_world_ids.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/open_search_description_document_handler.mojom.h" #include "chrome/common/open_search_description_document_handler.mojom.h"
#include "chrome/common/web_page_metadata.mojom.h"
#include "chrome/renderer/chrome_content_settings_agent_delegate.h" #include "chrome/renderer/chrome_content_settings_agent_delegate.h"
#include "chrome/renderer/media/media_feeds.h" #include "chrome/renderer/media/media_feeds.h"
#include "chrome/renderer/web_page_metadata_extraction.h"
#include "components/crash/core/common/crash_key.h" #include "components/crash/core/common/crash_key.h"
#include "components/no_state_prefetch/renderer/no_state_prefetch_helper.h" #include "components/no_state_prefetch/renderer/no_state_prefetch_helper.h"
#include "components/offline_pages/buildflags/buildflags.h" #include "components/offline_pages/buildflags/buildflags.h"
...@@ -387,47 +385,6 @@ void ChromeRenderFrameObserver::RequestReloadImageForContextNode() { ...@@ -387,47 +385,6 @@ void ChromeRenderFrameObserver::RequestReloadImageForContextNode() {
} }
} }
void ChromeRenderFrameObserver::GetWebPageMetadata(
GetWebPageMetadataCallback callback) {
WebLocalFrame* frame = render_frame()->GetWebFrame();
chrome::mojom::WebPageMetadataPtr web_page_metadata =
chrome::ExtractWebPageMetadata(frame);
// The warning below is specific to mobile but it doesn't hurt to show it even
// if the Chromium build is running on a desktop. It will get more exposition.
if (web_page_metadata->mobile_capable ==
chrome::mojom::WebPageMobileCapable::ENABLED_APPLE) {
blink::WebConsoleMessage message(
blink::mojom::ConsoleMessageLevel::kWarning,
"<meta name=\"apple-mobile-web-app-capable\" content=\"yes\"> is "
"deprecated. Please include <meta name=\"mobile-web-app-capable\" "
"content=\"yes\">");
frame->AddMessageToConsole(message);
}
// Prune out any data URLs in the set of icons. The browser process expects
// any icon with a data URL to have originated from a favicon. We don't want
// to decode arbitrary data URLs in the browser process. See
// http://b/issue?id=1162972
for (auto it = web_page_metadata->icons.begin();
it != web_page_metadata->icons.end();) {
if ((*it)->url.SchemeIs(url::kDataScheme))
it = web_page_metadata->icons.erase(it);
else
++it;
}
// Truncate the strings we send to the browser process.
web_page_metadata->application_name =
web_page_metadata->application_name.substr(
0, chrome::kMaxMetaTagAttributeLength);
web_page_metadata->description = web_page_metadata->description.substr(
0, chrome::kMaxMetaTagAttributeLength);
std::move(callback).Run(std::move(web_page_metadata));
}
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
void ChromeRenderFrameObserver::SetCCTClientHeader(const std::string& header) { void ChromeRenderFrameObserver::SetCCTClientHeader(const std::string& header) {
base::AutoLock auto_lock(GetFrameHeaderMapLock()); base::AutoLock auto_lock(GetFrameHeaderMapLock());
......
...@@ -86,7 +86,6 @@ class ChromeRenderFrameObserver : public content::RenderFrameObserver, ...@@ -86,7 +86,6 @@ class ChromeRenderFrameObserver : public content::RenderFrameObserver,
chrome::mojom::ImageFormat image_format, chrome::mojom::ImageFormat image_format,
RequestImageForContextNodeCallback callback) override; RequestImageForContextNodeCallback callback) override;
void RequestReloadImageForContextNode() override; void RequestReloadImageForContextNode() override;
void GetWebPageMetadata(GetWebPageMetadataCallback callback) override;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
void SetCCTClientHeader(const std::string& header) override; void SetCCTClientHeader(const std::string& header) override;
#endif #endif
......
# Copyright 2021 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.
import("//mojo/public/tools/bindings/mojom.gni")
source_set("common") {
sources = [
"constants.cc",
"constants.h",
]
}
mojom("mojo_bindings") {
disable_variants = true
sources = [
"web_page_metadata.mojom",
"web_page_metadata_agent.mojom",
]
deps = []
public_deps = [
"//mojo/public/mojom/base",
"//url/mojom:url_mojom_gurl",
]
}
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
// Copyright 2021 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.
#include "components/webapps/common/constants.h"
namespace webapps {
const size_t kMaxMetaTagAttributeLength = 2000;
} // namespace webapps
// Copyright 2021 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_WEBAPPS_COMMON_CONSTANTS_H_
#define COMPONENTS_WEBAPPS_COMMON_CONSTANTS_H_
#include <stddef.h>
namespace webapps {
// The largest reasonable length we'd assume for a meta tag attribute.
extern const size_t kMaxMetaTagAttributeLength;
} // namespace webapps
#endif // COMPONENTS_WEBAPPS_COMMON_CONSTANTS_H_
...@@ -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 chrome.mojom; module webapps.mojom;
import "mojo/public/mojom/base/string16.mojom"; import "mojo/public/mojom/base/string16.mojom";
import "url/mojom/url.mojom"; import "url/mojom/url.mojom";
......
// Copyright 2021 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.
module webapps.mojom;
import "components/webapps/common/web_page_metadata.mojom";
// Messages sent from the webapps component to the render frame.
interface WebPageMetadataAgent {
// Requests the web page metadata from the renderer.
GetWebPageMetadata() => (WebPageMetadata web_page_metadata);
};
# Copyright 2021 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.
static_library("renderer") {
sources = [
"web_page_metadata_agent.cc",
"web_page_metadata_agent.h",
"web_page_metadata_extraction.cc",
"web_page_metadata_extraction.h",
]
defines = []
deps = [
"//components/webapps/common",
"//components/webapps/common:mojo_bindings",
"//content/public/renderer",
"//services/service_manager/public/cpp",
"//third_party/blink/public:blink_headers",
"//third_party/blink/public/common:headers",
"//third_party/blink/public/common:headers",
]
}
include_rules = [
"+content/public/renderer",
"+mojo/public/cpp",
"+services/service_manager",
"+third_party/blink/public/common",
"+third_party/blink/public/platform",
"+third_party/blink/public/web",
"+ui/gfx",
]
// Copyright 2021 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.
#include "components/webapps/renderer/web_page_metadata_agent.h"
#include <stddef.h>
#include <utility>
#include "base/bind.h"
#include "components/webapps/common/constants.h"
#include "components/webapps/common/web_page_metadata.mojom.h"
#include "components/webapps/renderer/web_page_metadata_extraction.h"
#include "content/public/renderer/render_frame.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#include "third_party/blink/public/web/web_console_message.h"
#include "third_party/blink/public/web/web_local_frame.h"
namespace webapps {
WebPageMetadataAgent::WebPageMetadataAgent(content::RenderFrame* render_frame)
: content::RenderFrameObserver(render_frame) {
render_frame->GetAssociatedInterfaceRegistry()->AddInterface(
base::BindRepeating(&WebPageMetadataAgent::OnRenderFrameObserverRequest,
base::Unretained(this)));
}
WebPageMetadataAgent::~WebPageMetadataAgent() = default;
void WebPageMetadataAgent::OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) {
registry_.TryBindInterface(interface_name, interface_pipe);
}
void WebPageMetadataAgent::OnDestruct() {
delete this;
}
void WebPageMetadataAgent::GetWebPageMetadata(
GetWebPageMetadataCallback callback) {
blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
mojom::WebPageMetadataPtr web_page_metadata = ExtractWebPageMetadata(frame);
// The warning below is specific to mobile but it doesn't hurt to show it even
// if the Chromium build is running on a desktop. It will get more exposition.
if (web_page_metadata->mobile_capable ==
mojom::WebPageMobileCapable::ENABLED_APPLE) {
blink::WebConsoleMessage message(
blink::mojom::ConsoleMessageLevel::kWarning,
"<meta name=\"apple-mobile-web-app-capable\" content=\"yes\"> is "
"deprecated. Please include <meta name=\"mobile-web-app-capable\" "
"content=\"yes\">");
frame->AddMessageToConsole(message);
}
// Prune out any data URLs in the set of icons. The browser process expects
// any icon with a data URL to have originated from a favicon. We don't want
// to decode arbitrary data URLs in the browser process. See
// http://b/issue?id=1162972
for (auto it = web_page_metadata->icons.begin();
it != web_page_metadata->icons.end();) {
if ((*it)->url.SchemeIs(url::kDataScheme))
it = web_page_metadata->icons.erase(it);
else
++it;
}
// Truncate the strings we send to the browser process.
web_page_metadata->application_name =
web_page_metadata->application_name.substr(0, kMaxMetaTagAttributeLength);
web_page_metadata->description =
web_page_metadata->description.substr(0, kMaxMetaTagAttributeLength);
std::move(callback).Run(std::move(web_page_metadata));
}
void WebPageMetadataAgent::OnRenderFrameObserverRequest(
mojo::PendingAssociatedReceiver<mojom::WebPageMetadataAgent> receiver) {
receivers_.Add(this, std::move(receiver));
}
} // namespace webapps
// Copyright 2021 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_WEBAPPS_RENDERER_WEB_PAGE_METADATA_AGENT_H_
#define COMPONENTS_WEBAPPS_RENDERER_WEB_PAGE_METADATA_AGENT_H_
#include "build/build_config.h"
#include "components/webapps/common/web_page_metadata_agent.mojom.h"
#include "content/public/renderer/render_frame_observer.h"
#include "mojo/public/cpp/bindings/associated_receiver_set.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "services/service_manager/public/cpp/binder_registry.h"
namespace webapps {
// This class holds the WebApps specific parts of RenderFrame, and has the same
// lifetime.
class WebPageMetadataAgent : public content::RenderFrameObserver,
public mojom::WebPageMetadataAgent {
public:
explicit WebPageMetadataAgent(content::RenderFrame* render_frame);
WebPageMetadataAgent(const WebPageMetadataAgent&) = delete;
WebPageMetadataAgent& operator=(const WebPageMetadataAgent&) = delete;
~WebPageMetadataAgent() override;
private:
// RenderFrameObserver implementation.
void OnInterfaceRequestForFrame(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) override;
void OnDestruct() override;
// webapps::mojom::WebPageMetadataAgent:
void GetWebPageMetadata(GetWebPageMetadataCallback callback) override;
void OnRenderFrameObserverRequest(
mojo::PendingAssociatedReceiver<mojom::WebPageMetadataAgent> receiver);
mojo::AssociatedReceiverSet<mojom::WebPageMetadataAgent> receivers_;
service_manager::BinderRegistry registry_;
};
} // namespace webapps
#endif // COMPONENTS_WEBAPPS_RENDERER_WEB_PAGE_METADATA_AGENT_H_
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
// 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.
#include "chrome/renderer/web_page_metadata_extraction.h" #include "components/webapps/renderer/web_page_metadata_extraction.h"
#include <stddef.h> #include <stddef.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include "chrome/common/web_page_metadata.mojom.h" #include "components/webapps/common/web_page_metadata.mojom.h"
#include "third_party/blink/public/platform/web_icon_sizes_parser.h" #include "third_party/blink/public/platform/web_icon_sizes_parser.h"
#include "third_party/blink/public/platform/web_string.h" #include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_url.h" #include "third_party/blink/public/platform/web_url.h"
...@@ -25,7 +25,7 @@ using blink::WebLocalFrame; ...@@ -25,7 +25,7 @@ using blink::WebLocalFrame;
using blink::WebNode; using blink::WebNode;
using blink::WebString; using blink::WebString;
namespace chrome { namespace webapps {
namespace { namespace {
void AddInstallIcon(const WebElement& link, void AddInstallIcon(const WebElement& link,
...@@ -115,4 +115,4 @@ mojom::WebPageMetadataPtr ExtractWebPageMetadata(WebLocalFrame* frame) { ...@@ -115,4 +115,4 @@ mojom::WebPageMetadataPtr ExtractWebPageMetadata(WebLocalFrame* frame) {
return metadata; return metadata;
} }
} // namespace chrome } // namespace webapps
...@@ -2,22 +2,22 @@ ...@@ -2,22 +2,22 @@
// 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.
#ifndef CHROME_RENDERER_WEB_PAGE_METADATA_EXTRACTION_H_ #ifndef COMPONENTS_WEBAPPS_RENDERER_WEB_PAGE_METADATA_EXTRACTION_H_
#define CHROME_RENDERER_WEB_PAGE_METADATA_EXTRACTION_H_ #define COMPONENTS_WEBAPPS_RENDERER_WEB_PAGE_METADATA_EXTRACTION_H_
#include "chrome/common/web_page_metadata.mojom-forward.h" #include "components/webapps/common/web_page_metadata.mojom-forward.h"
namespace blink { namespace blink {
class WebLocalFrame; class WebLocalFrame;
} }
namespace chrome { namespace webapps {
// Extracts any metadata information out of the document in the |frame|. Note, // Extracts any metadata information out of the document in the |frame|. Note,
// this function always returns a non-null object even if no metadata was found // this function always returns a non-null object even if no metadata was found
// in the page. // in the page.
mojom::WebPageMetadataPtr ExtractWebPageMetadata(blink::WebLocalFrame* frame); mojom::WebPageMetadataPtr ExtractWebPageMetadata(blink::WebLocalFrame* frame);
} // namespace chrome } // namespace webapps
#endif // CHROME_RENDERER_WEB_PAGE_METADATA_EXTRACTION_H_ #endif // COMPONENTS_WEBAPPS_RENDERER_WEB_PAGE_METADATA_EXTRACTION_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