Skip to content

Commit

Permalink
Port Ash tablet-mode rendering to Lacros
Browse files Browse the repository at this point in the history
Moves the code that sets mobile-like Blink preferences under tablet-mode
to a common filepath and configures it to be compiled into Lacros.

Bug: 1289495
Change-Id: Ib851333f94b49207e943817c8563c5e08e3d5411
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3614412
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Alex Yang <aycyang@chromium.org>
Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1001533}
  • Loading branch information
Alex Yang authored and Chromium LUCI CQ committed May 10, 2022
1 parent 61bb0e4 commit 603c721
Show file tree
Hide file tree
Showing 21 changed files with 178 additions and 116 deletions.
9 changes: 9 additions & 0 deletions chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -7469,6 +7469,15 @@ static_library("browser") {
]
deps += [ "//components/segmentation_platform/internal:optimization_guide_segmentation_handler" ]
}

if (is_chromeos) {
sources += [
"chromeos/tablet_mode/chrome_content_browser_client_tablet_mode_part.cc",
"chromeos/tablet_mode/chrome_content_browser_client_tablet_mode_part.h",
"chromeos/tablet_mode/tablet_mode_page_behavior.cc",
"chromeos/tablet_mode/tablet_mode_page_behavior.h",
]
}
}

if (is_android) {
Expand Down
35 changes: 0 additions & 35 deletions chrome/browser/ash/chrome_content_browser_client_ash_part.h

This file was deleted.

2 changes: 2 additions & 0 deletions chrome/browser/browser_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ const base::Feature kEnableUniveralLinks{"EnableUniveralLinks",
// menu.
const base::Feature kQuickSettingsPWANotifications{
"QuickSettingsPWA", base::FEATURE_DISABLED_BY_DEFAULT};
#endif

#if BUILDFLAG(IS_CHROMEOS)
// Enables being able to zoom a web page by double tapping in Chrome OS tablet
// mode.
const base::Feature kDoubleTapToZoomInTabletMode{
Expand Down
5 changes: 4 additions & 1 deletion chrome/browser/browser_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ extern const char kBrowserCommandIdParam[];
extern const base::Feature kUseManagementService;

#if BUILDFLAG(IS_CHROMEOS_ASH)
extern const base::Feature kDoubleTapToZoomInTabletMode;
extern const base::Feature kQuickSettingsPWANotifications;
#endif

#if BUILDFLAG(IS_CHROMEOS)
extern const base::Feature kDoubleTapToZoomInTabletMode;
#endif

#if BUILDFLAG(IS_MAC)
extern const base::Feature kEnableUniveralLinks;
#endif
Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/chrome_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@
#include "chrome/browser/ash/arc/fileapi/arc_content_file_system_backend_delegate.h"
#include "chrome/browser/ash/arc/fileapi/arc_documents_provider_backend_delegate.h"
#include "chrome/browser/ash/chrome_browser_main_parts_ash.h"
#include "chrome/browser/ash/chrome_content_browser_client_ash_part.h"
#include "chrome/browser/ash/drive/fileapi/drivefs_file_system_backend_delegate.h"
#include "chrome/browser/ash/file_manager/app_id.h"
#include "chrome/browser/ash/file_system_provider/fileapi/backend_delegate.h"
Expand Down Expand Up @@ -427,6 +426,7 @@
#endif // !BUILDFLAG(IS_CHROMEOS_ASH)

#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/chromeos/tablet_mode/chrome_content_browser_client_tablet_mode_part.h"
#include "chrome/browser/policy/networking/policy_cert_service.h"
#include "chrome/browser/policy/networking/policy_cert_service_factory.h"
#include "third_party/cros_system_api/switches/chrome_switches.h"
Expand Down Expand Up @@ -1286,9 +1286,9 @@ ChromeContentBrowserClient::ChromeContentBrowserClient() {
extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart);
#endif

#if BUILDFLAG(IS_CHROMEOS_ASH)
extra_parts_.push_back(new ash::ChromeContentBrowserClientAshPart);
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
#if BUILDFLAG(IS_CHROMEOS)
extra_parts_.push_back(new ChromeContentBrowserClientTabletModePart);
#endif // BUILDFLAG(IS_CHROMEOS)

#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
extra_parts_.push_back(new ChromeContentBrowserClientTabStripPart);
Expand Down
4 changes: 1 addition & 3 deletions chrome/browser/chromeos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1273,8 +1273,6 @@ source_set("chromeos") {
"../ash/child_accounts/website_approval_notifier.h",
"../ash/chrome_browser_main_parts_ash.cc",
"../ash/chrome_browser_main_parts_ash.h",
"../ash/chrome_content_browser_client_ash_part.cc",
"../ash/chrome_content_browser_client_ash_part.h",
"../ash/concierge_helper_service.cc",
"../ash/concierge_helper_service.h",
"../ash/crostini/ansible/ansible_management_service.cc",
Expand Down Expand Up @@ -4223,7 +4221,6 @@ source_set("unit_tests") {
"../ash/child_accounts/usage_time_limit_processor_unittest.cc",
"../ash/child_accounts/usage_time_state_notifier_unittest.cc",
"../ash/child_accounts/website_approval_notifier_unittest.cc",
"../ash/chrome_content_browser_client_ash_part_unittest.cc",
"../ash/concierge_helper_service_unittest.cc",
"../ash/crostini/ansible/ansible_management_service_unittest.cc",
"../ash/crostini/crostini_disk_unittest.cc",
Expand Down Expand Up @@ -4844,6 +4841,7 @@ source_set("unit_tests") {
"policy/dlp/mock_dlp_rules_manager.h",
"policy/dlp/mock_dlp_warn_notifier.cc",
"policy/dlp/mock_dlp_warn_notifier.h",
"tablet_mode/chrome_content_browser_client_tablet_mode_part_unittest.cc",

# TODO(zturner): Enable this on Windows. See
# BrowserWithTestWindowTest::SetUp() for a comment explaining why this is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ash/chrome_content_browser_client_ash_part.h"
#include "chrome/browser/chromeos/tablet_mode/chrome_content_browser_client_tablet_mode_part.h"

#include "base/feature_list.h"
#include "chrome/browser/browser_features.h"
Expand All @@ -12,8 +12,6 @@
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h"
#include "chrome/common/webui_url_constants.h"
#include "chromeos/ui/base/tablet_state.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
Expand All @@ -22,10 +20,13 @@
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "extensions/common/constants.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"

namespace ash {
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h"
#include "chrome/common/webui_url_constants.h"
#include "extensions/common/constants.h"
#endif

namespace {

Expand Down Expand Up @@ -53,24 +54,6 @@ bool IsInternalPage(content::WebContents* contents) {
return url.SchemeIs(content::kChromeUIScheme);
}

// Returns true if the WebUI at |url| is considered "system UI" and should use
// the system font size (the default) instead of the browser font size.
// Takes a URL because the WebContents may not yet be associated with a window,
// SettingsWindowManager, etc.
bool UseDefaultFontSize(const GURL& url) {
if (chromeos::SystemWebDialogDelegate::HasInstance(url))
return true;

if (url.SchemeIs(content::kChromeUIScheme))
return chrome::IsSystemWebUIHost(url.host_piece());

if (url.SchemeIs(extensions::kExtensionScheme)) {
base::StringPiece extension_id = url.host_piece();
return extension_misc::IsSystemUIApp(extension_id);
}
return false;
}

void OverrideWebkitPrefsForTabletMode(
content::WebContents* contents,
blink::web_pref::WebPreferences* web_prefs) {
Expand Down Expand Up @@ -98,6 +81,25 @@ void OverrideWebkitPrefsForTabletMode(
web_prefs->default_maximum_page_scale_factor = 5.0;
}

#if BUILDFLAG(IS_CHROMEOS_ASH)
// Returns true if the WebUI at |url| is considered "system UI" and should use
// the system font size (the default) instead of the browser font size.
// Takes a URL because the WebContents may not yet be associated with a window,
// SettingsWindowManager, etc.
bool UseDefaultFontSize(const GURL& url) {
if (chromeos::SystemWebDialogDelegate::HasInstance(url))
return true;

if (url.SchemeIs(content::kChromeUIScheme))
return chrome::IsSystemWebUIHost(url.host_piece());

if (url.SchemeIs(extensions::kExtensionScheme)) {
base::StringPiece extension_id = url.host_piece();
return extension_misc::IsSystemUIApp(extension_id);
}
return false;
}

void OverrideFontSize(content::WebContents* contents,
blink::web_pref::WebPreferences* web_prefs) {
DCHECK(contents);
Expand All @@ -112,16 +114,17 @@ void OverrideFontSize(content::WebContents* contents,
web_prefs->default_fixed_font_size = base_prefs.default_fixed_font_size;
}
}
#endif // BUILDFLAG(IS_CHROMEOS_ASH)

} // namespace

ChromeContentBrowserClientAshPart::ChromeContentBrowserClientAshPart() =
default;
ChromeContentBrowserClientTabletModePart::
ChromeContentBrowserClientTabletModePart() = default;

ChromeContentBrowserClientAshPart::~ChromeContentBrowserClientAshPart() =
default;
ChromeContentBrowserClientTabletModePart::
~ChromeContentBrowserClientTabletModePart() = default;

void ChromeContentBrowserClientAshPart::OverrideWebkitPrefs(
void ChromeContentBrowserClientTabletModePart::OverrideWebkitPrefs(
content::WebContents* web_contents,
blink::web_pref::WebPreferences* web_prefs) {
// A webcontents may not be the delegate of the render view host such as in
Expand All @@ -130,13 +133,15 @@ void ChromeContentBrowserClientAshPart::OverrideWebkitPrefs(
return;

OverrideWebkitPrefsForTabletMode(web_contents, web_prefs);
#if BUILDFLAG(IS_CHROMEOS_ASH)
OverrideFontSize(web_contents, web_prefs);
#endif
}

#if BUILDFLAG(IS_CHROMEOS_ASH)
// static
bool ChromeContentBrowserClientAshPart::UseDefaultFontSizeForTest(
bool ChromeContentBrowserClientTabletModePart::UseDefaultFontSizeForTest(
const GURL& url) {
return UseDefaultFontSize(url);
}

} // namespace ash
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2018 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_CHROMEOS_TABLET_MODE_CHROME_CONTENT_BROWSER_CLIENT_TABLET_MODE_PART_H_
#define CHROME_BROWSER_CHROMEOS_TABLET_MODE_CHROME_CONTENT_BROWSER_CLIENT_TABLET_MODE_PART_H_

#include "chrome/browser/chrome_content_browser_client_parts.h"

class GURL;

class ChromeContentBrowserClientTabletModePart
: public ChromeContentBrowserClientParts {
public:
ChromeContentBrowserClientTabletModePart();

ChromeContentBrowserClientTabletModePart(
const ChromeContentBrowserClientTabletModePart&) = delete;
ChromeContentBrowserClientTabletModePart& operator=(
const ChromeContentBrowserClientTabletModePart&) = delete;

~ChromeContentBrowserClientTabletModePart() override;

// ChromeContentBrowserClientParts:
void OverrideWebkitPrefs(content::WebContents* web_contents,
blink::web_pref::WebPreferences* web_prefs) override;

#if BUILDFLAG(IS_CHROMEOS_ASH)
static bool UseDefaultFontSizeForTest(const GURL& url);
#endif
};

#endif // CHROME_BROWSER_CHROMEOS_TABLET_MODE_CHROME_CONTENT_BROWSER_CLIENT_TABLET_MODE_PART_H_
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
#include "content/public/test/browser_test.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"

namespace ash {
using ChromeContentBrowserClientTabletModePartTest = ::InProcessBrowserTest;

using ChromeContentBrowserClientAshPartTest = ::InProcessBrowserTest;

IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientAshPartTest,
IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientTabletModePartTest,
SettingsWindowFontSize) {
// Install the Settings App.
web_app::WebAppProvider::GetForTest(browser()->profile())
Expand Down Expand Up @@ -54,5 +52,3 @@ IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientAshPartTest,
EXPECT_EQ(kDefaultFontSize, window_prefs.default_font_size);
EXPECT_EQ(kDefaultFixedFontSize, window_prefs.default_fixed_font_size);
}

} // namespace ash
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ash/chrome_content_browser_client_ash_part.h"
#include "chrome/browser/chromeos/tablet_mode/chrome_content_browser_client_tablet_mode_part.h"

#include <string>

#include "extensions/common/constants.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace ash {
namespace {

bool UseDefaultFontSize(const std::string& url) {
return ChromeContentBrowserClientAshPart::UseDefaultFontSizeForTest(
return ChromeContentBrowserClientTabletModePart::UseDefaultFontSizeForTest(
GURL(url));
}

Expand All @@ -25,7 +24,7 @@ std::string GetExtensionURL(const std::string& extension_id) {
return url;
}

TEST(ChromeContentBrowserClientAshPartTest, FontSizeForChromeUI) {
TEST(ChromeContentBrowserClientTabletModePartTest, FontSizeForChromeUI) {
struct TestCase {
std::string url;
bool is_system_ui;
Expand All @@ -42,7 +41,7 @@ TEST(ChromeContentBrowserClientAshPartTest, FontSizeForChromeUI) {
}
}

TEST(ChromeContentBrowserClientAshPartTest, FontSizeForApps) {
TEST(ChromeContentBrowserClientTabletModePartTest, FontSizeForApps) {
struct TestCase {
std::string extension_id;
bool is_system_ui;
Expand All @@ -61,4 +60,3 @@ TEST(ChromeContentBrowserClientAshPartTest, FontSizeForApps) {
}

} // namespace
} // namespace ash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/ash/tablet_mode_page_behavior.h"
#include "chrome/browser/chromeos/tablet_mode/tablet_mode_page_behavior.h"

#include <utility>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_ASH_TABLET_MODE_PAGE_BEHAVIOR_H_
#define CHROME_BROWSER_UI_ASH_TABLET_MODE_PAGE_BEHAVIOR_H_
#ifndef CHROME_BROWSER_CHROMEOS_TABLET_MODE_TABLET_MODE_PAGE_BEHAVIOR_H_
#define CHROME_BROWSER_CHROMEOS_TABLET_MODE_TABLET_MODE_PAGE_BEHAVIOR_H_

#include <memory>

Expand Down Expand Up @@ -55,4 +55,4 @@ class TabletModePageBehavior : public display::DisplayObserver,
std::unique_ptr<BrowserTabStripTracker> tab_strip_tracker_;
};

#endif // CHROME_BROWSER_UI_ASH_TABLET_MODE_PAGE_BEHAVIOR_H_
#endif // CHROME_BROWSER_CHROMEOS_TABLET_MODE_TABLET_MODE_PAGE_BEHAVIOR_H_

0 comments on commit 603c721

Please sign in to comment.