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

Webapps: introduce WebappsClient

Use it to sever a Chrome dependency from InstallableManager.

ChromeWebappsClient is added to the //chrome/browser target in a
new //chrome/browser/webapps directory, as there's no directory
currently shared by Android and desktop for web apps. That is,
//chrome/android/webapps and //chrome/browser/web_applications are
platform-specific.

Unfortunately the new method is called in many unit tests, so to
avoid crashing we either have to instantiate a ChromeWebappsClient
in each unit test (or unit test base class, i.e. at least
BrowserWithTestWindowTest, ChromeRenderViewHostTestHarness, and
ExtensionServiceTestBase), or we gracefully handle a missing
client. I opted for the latter, although this decision may be
revisited if many other WebappsClient callsites wind up needing to
null check.

Bug: 1147276
Change-Id: I40eaa3e999dbe987aa4ecc2bbfaafb57cbcdc0cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566743
Auto-Submit: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarGlenn Hartmann <hartmanng@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833540}
parent 3648578d
...@@ -1884,6 +1884,8 @@ static_library("browser") { ...@@ -1884,6 +1884,8 @@ static_library("browser") {
"wake_lock/wake_lock_permission_context.h", "wake_lock/wake_lock_permission_context.h",
"web_data_service_factory.cc", "web_data_service_factory.cc",
"web_data_service_factory.h", "web_data_service_factory.h",
"webapps/chrome_webapps_client.cc",
"webapps/chrome_webapps_client.h",
"window_placement/window_placement_permission_context.cc", "window_placement/window_placement_permission_context.cc",
"window_placement/window_placement_permission_context.h", "window_placement/window_placement_permission_context.h",
] ]
...@@ -2244,6 +2246,7 @@ static_library("browser") { ...@@ -2244,6 +2246,7 @@ static_library("browser") {
"//components/visitedlink/common", "//components/visitedlink/common",
"//components/web_cache/browser", "//components/web_cache/browser",
"//components/web_resource", "//components/web_resource",
"//components/webapps",
"//components/webdata/common", "//components/webdata/common",
"//components/webdata_services", "//components/webdata_services",
"//components/webrtc", "//components/webrtc",
......
...@@ -75,6 +75,7 @@ ...@@ -75,6 +75,7 @@
#include "chrome/browser/status_icons/status_tray.h" #include "chrome/browser/status_icons/status_tray.h"
#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/update_client/chrome_update_query_params_delegate.h" #include "chrome/browser/update_client/chrome_update_query_params_delegate.h"
#include "chrome/browser/webapps/chrome_webapps_client.h"
#include "chrome/common/buildflags.h" #include "chrome/common/buildflags.h"
#include "chrome/common/channel_info.h" #include "chrome/common/channel_info.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
...@@ -307,6 +308,9 @@ void BrowserProcessImpl::Init() { ...@@ -307,6 +308,9 @@ void BrowserProcessImpl::Init() {
// Make sure permissions client has been set. // Make sure permissions client has been set.
ChromePermissionsClient::GetInstance(); ChromePermissionsClient::GetInstance();
// Make sure webapps client has been set.
webapps::ChromeWebappsClient::GetInstance();
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
KeepAliveRegistry::GetInstance()->SetIsShuttingDown(false); KeepAliveRegistry::GetInstance()->SetIsShuttingDown(false);
KeepAliveRegistry::GetInstance()->AddObserver(this); KeepAliveRegistry::GetInstance()->AddObserver(this);
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/installable/installable_metrics.h" #include "chrome/browser/installable/installable_metrics.h"
#include "chrome/browser/ssl/security_state_tab_helper.h"
#include "components/security_state/core/security_state.h" #include "components/security_state/core/security_state.h"
#include "components/webapps/webapps_client.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/manifest_icon_downloader.h" #include "content/public/browser/manifest_icon_downloader.h"
...@@ -280,9 +280,13 @@ bool InstallableManager::IsContentSecure(content::WebContents* web_contents) { ...@@ -280,9 +280,13 @@ bool InstallableManager::IsContentSecure(content::WebContents* web_contents) {
if (IsOriginConsideredSecure(url)) if (IsOriginConsideredSecure(url))
return true; return true;
// This can be null in unit tests but should be non-null in production.
if (!webapps::WebappsClient::Get())
return false;
return security_state::IsSslCertificateValid( return security_state::IsSslCertificateValid(
SecurityStateTabHelper::FromWebContents(web_contents) webapps::WebappsClient::Get()->GetSecurityLevelForWebContents(
->GetSecurityLevel()); web_contents));
} }
// static // static
......
monorail {
component: "UI>Browser>WebAppInstalls"
}
team_email: "pwa-dev@chromium.org"
file://components/webapps/OWNERS
// Copyright 2020 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 "chrome/browser/webapps/chrome_webapps_client.h"
#include "chrome/browser/ssl/security_state_tab_helper.h"
namespace webapps {
// static
ChromeWebappsClient* ChromeWebappsClient::GetInstance() {
static base::NoDestructor<ChromeWebappsClient> instance;
return instance.get();
}
security_state::SecurityLevel
ChromeWebappsClient::GetSecurityLevelForWebContents(
content::WebContents* web_contents) {
return SecurityStateTabHelper::FromWebContents(web_contents)
->GetSecurityLevel();
}
} // namespace webapps
// Copyright 2020 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 CHROME_BROWSER_WEBAPPS_CHROME_WEBAPPS_CLIENT_H_
#define CHROME_BROWSER_WEBAPPS_CHROME_WEBAPPS_CLIENT_H_
#include "base/no_destructor.h"
#include "components/webapps/webapps_client.h"
namespace webapps {
class ChromeWebappsClient : public webapps::WebappsClient {
public:
ChromeWebappsClient(const ChromeWebappsClient&) = delete;
ChromeWebappsClient& operator=(const ChromeWebappsClient&) = delete;
static ChromeWebappsClient* GetInstance();
// webapps::WebappsClient:
security_state::SecurityLevel GetSecurityLevelForWebContents(
content::WebContents* web_contents) override;
private:
friend base::NoDestructor<ChromeWebappsClient>;
ChromeWebappsClient() = default;
};
} // namespace webapps
#endif // CHROME_BROWSER_WEBAPPS_CHROME_WEBAPPS_CLIENT_H_
# Copyright 2020 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.
source_set("webapps") {
sources = [
"webapps_client.cc",
"webapps_client.h",
]
deps = [ "//components/security_state/core" ]
}
include_rules = [
"+components/security_state/core",
]
monorail {
component: "UI>Browser>WebAppInstalls"
}
team_email: "pwa-dev@chromium.org"
dominickn@chromium.org dominickn@chromium.org
hartmanng@chromium.org hartmanng@chromium.org
# COMPONENT: UI>Browser>WebAppInstalls
# TEAM: web-apps-platform-team@chromium.org
// Copyright 2020 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/webapps_client.h"
namespace webapps {
namespace {
WebappsClient* g_instance = nullptr;
}
WebappsClient::WebappsClient() {
DCHECK(!g_instance);
g_instance = this;
}
WebappsClient::~WebappsClient() {
DCHECK(g_instance);
g_instance = nullptr;
}
// static
WebappsClient* WebappsClient::Get() {
return g_instance;
}
} // namespace webapps
// Copyright 2020 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_WEBAPPS_CLIENT_H_
#define COMPONENTS_WEBAPPS_WEBAPPS_CLIENT_H_
#include "components/security_state/core/security_state.h"
namespace content {
class WebContents;
} // namespace content
namespace webapps {
// Interface to be implemented by the embedder (such as Chrome or WebLayer) to
// expose embedder specific logic.
class WebappsClient {
public:
WebappsClient();
WebappsClient(const WebappsClient&) = delete;
WebappsClient& operator=(const WebappsClient&) = delete;
virtual ~WebappsClient();
// Return the webapps client.
static WebappsClient* Get();
virtual security_state::SecurityLevel GetSecurityLevelForWebContents(
content::WebContents* web_contents) = 0;
};
} // namespace webapps
#endif // COMPONENTS_WEBAPPS_WEBAPPS_CLIENT_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