Skip to content

Commit

Permalink
[WebLayer] Implement GetContentSettings, GetPermisisonResult.
Browse files Browse the repository at this point in the history
Implement two more methods in PageInfoDelegateImpl and add browsertests
to verify expected behavior.

Bug: 1052375
Change-Id: I474bbd06ad2736894881461cb8381b0adf0dcfa4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2170348
Reviewed-by: Clark DuVall <cduvall@chromium.org>
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Cr-Commit-Position: refs/heads/master@{#763428}
  • Loading branch information
Mugdha Lakhani authored and Commit Bot committed Apr 28, 2020
1 parent c0e1f71 commit ef94b43
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
26 changes: 26 additions & 0 deletions weblayer/browser/url_bar/page_info_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/content_settings/core/common/content_settings.h"
#include "components/page_info/android/page_info_client.h"
#include "components/page_info/page_info_delegate.h"
#include "weblayer/browser/tab_impl.h"
Expand Down Expand Up @@ -46,4 +47,29 @@ IN_PROC_BROWSER_TEST_F(PageInfoBrowserTest, PermissionDecisionAutoblocker) {
EXPECT_TRUE(page_info_delegate->GetPermissionDecisionAutoblocker());
}

IN_PROC_BROWSER_TEST_F(PageInfoBrowserTest, ContentSettings) {
std::unique_ptr<PageInfoDelegate> page_info_delegate =
page_info::GetPageInfoClient()->CreatePageInfoDelegate(GetWebContents());
ASSERT_TRUE(page_info_delegate);
EXPECT_TRUE(page_info_delegate->GetContentSettings());
}

IN_PROC_BROWSER_TEST_F(PageInfoBrowserTest, PermissionStatus) {
std::unique_ptr<PageInfoDelegate> page_info_delegate =
page_info::GetPageInfoClient()->CreatePageInfoDelegate(GetWebContents());
ASSERT_TRUE(page_info_delegate);
GURL url("https://example.com");

auto* content_settings_map = page_info_delegate->GetContentSettings();
ASSERT_TRUE(content_settings_map);
content_settings_map->SetContentSettingDefaultScope(
url, url, ContentSettingsType::BACKGROUND_SYNC, std::string(),
CONTENT_SETTING_BLOCK);

// Check that |page_info_delegate| returns expected ContentSettingsType.
EXPECT_EQ(page_info_delegate
->GetPermissionStatus(ContentSettingsType::NOTIFICATIONS, url)
.content_setting,
CONTENT_SETTING_BLOCK);
}
} // namespace weblayer
16 changes: 8 additions & 8 deletions weblayer/browser/url_bar/page_info_delegate_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

#include "weblayer/browser/url_bar/page_info_delegate_impl.h"

#include "components/permissions/permission_manager.h"
#include "components/security_interstitials/content/stateful_ssl_host_state_delegate.h"
#include "components/security_state/content/content_utils.h"
#include "content/public/browser/browser_context.h"
#include "weblayer/browser/host_content_settings_map_factory.h"
#include "weblayer/browser/permissions/permission_decision_auto_blocker_factory.h"
#include "weblayer/browser/permissions/permission_manager_factory.h"
#include "weblayer/browser/stateful_ssl_host_state_delegate_factory.h"

PageInfoDelegateImpl::PageInfoDelegateImpl(content::WebContents* web_contents)
Expand Down Expand Up @@ -45,10 +48,9 @@ base::string16 PageInfoDelegateImpl::GetWarningDetailText() {
permissions::PermissionResult PageInfoDelegateImpl::GetPermissionStatus(
ContentSettingsType type,
const GURL& site_url) {
// TODO(crbug.com/1052375): Implement.
NOTREACHED();
return permissions::PermissionResult(
CONTENT_SETTING_BLOCK, permissions::PermissionStatusSource::UNSPECIFIED);
return weblayer::PermissionManagerFactory::GetForBrowserContext(
GetBrowserContext())
->GetPermissionStatus(type, site_url, site_url);
}

#if !defined(OS_ANDROID)
Expand Down Expand Up @@ -77,10 +79,8 @@ PageInfoDelegateImpl::GetStatefulSSLHostStateDelegate() {
}

HostContentSettingsMap* PageInfoDelegateImpl::GetContentSettings() {
// TODO(crbug.com/1052375): Implement once site settings code has been
// componentized.
NOTREACHED();
return nullptr;
return weblayer::HostContentSettingsMapFactory::GetForBrowserContext(
GetBrowserContext());
}

bool PageInfoDelegateImpl::IsContentDisplayedInVrHeadset() {
Expand Down

0 comments on commit ef94b43

Please sign in to comment.