Mac: Add Views API support (see issue #1749)

The Chrome browser can now be hosted in a Views-based application on Mac
(see issue #2969).

To launch a fully-featured Chrome window using cefsimple:
$ open cefsimple.app --args --enable-chrome-runtime

To launch a minimally-styled Views-hosted window using cefsimple:
$ open cefsimple.app --args --use-views [--enable-chrome-runtime]

To launch a fully-styled Views-hosted window using cefclient:
$ open cefclient.app --args --use-views [--enable-chrome-runtime]

Known issues:
- Some Views unit tests are currently failing on Mac.
This commit is contained in:
Marshall Greenblatt
2021-02-23 15:08:33 -05:00
parent f93c9c0c5c
commit 1d39ff720e
22 changed files with 264 additions and 190 deletions

View File

@@ -1,8 +1,16 @@
diff --git chrome/browser/app_controller_mac.mm chrome/browser/app_controller_mac.mm
index e2eb5c2c73d0..601b582c6675 100644
index e2eb5c2c73d0..d08b0a9a2a54 100644
--- chrome/browser/app_controller_mac.mm
+++ chrome/browser/app_controller_mac.mm
@@ -1194,6 +1194,7 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session;
@@ -29,6 +29,7 @@
#include "base/task/thread_pool.h"
#include "base/threading/scoped_blocking_call.h"
#include "build/branding_buildflags.h"
+#include "cef/libcef/features/features.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/apps/app_shim/app_shim_manager_mac.h"
#include "chrome/browser/apps/app_shim/app_shim_termination_manager.h"
@@ -1194,6 +1195,7 @@ - (void)commandDispatch:(id)sender {
// Run a (background) application in a new tab.
- (void)executeApplication:(id)sender {
@@ -10,7 +18,7 @@ index e2eb5c2c73d0..601b582c6675 100644
NSInteger tag = [sender tag];
Profile* profile = [self lastProfile];
DCHECK(profile);
@@ -1202,6 +1203,7 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session;
@@ -1202,6 +1204,7 @@ - (void)executeApplication:(id)sender {
tag < static_cast<int>(applications.size()));
const extensions::Extension* extension = applications.GetExtension(tag);
BackgroundModeManager::LaunchBackgroundApplication(profile, extension);
@@ -18,7 +26,7 @@ index e2eb5c2c73d0..601b582c6675 100644
}
// Same as |-commandDispatch:|, but executes commands using a disposition
@@ -1599,6 +1601,7 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session;
@@ -1599,6 +1602,7 @@ - (NSMenu*)applicationDockMenu:(NSApplication*)sender {
// TODO(rickcam): Mock out BackgroundApplicationListModel, then add unit
// tests which use the mock in place of the profile-initialized model.
@@ -26,7 +34,7 @@ index e2eb5c2c73d0..601b582c6675 100644
// Avoid breaking unit tests which have no profile.
if (profile) {
BackgroundApplicationListModel applications(profile);
@@ -1625,6 +1628,7 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session;
@@ -1625,6 +1629,7 @@ - (NSMenu*)applicationDockMenu:(NSApplication*)sender {
}
}
}
@@ -34,6 +42,20 @@ index e2eb5c2c73d0..601b582c6675 100644
return dockMenu;
}
@@ -1835,11 +1840,13 @@ - (void)handoffActiveURLChanged:(content::WebContents*)webContents {
namespace {
void UpdateProfileInUse(Profile* profile, Profile::CreateStatus status) {
+#if !BUILDFLAG(ENABLE_CEF)
if (status == Profile::CREATE_STATUS_INITIALIZED) {
AppController* controller =
base::mac::ObjCCastStrict<AppController>([NSApp delegate]);
[controller windowChangedToProfile:profile];
}
+#endif // !BUILDFLAG(ENABLE_CEF)
}
} // namespace
diff --git chrome/browser/browser_process.h chrome/browser/browser_process.h
index 1ea08a7ad6ae..473ebde08451 100644
--- chrome/browser/browser_process.h

View File

@@ -128,6 +128,44 @@ index fee4d5f1a8ca..2e4fb506d851 100644
// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
// of lacros-chrome is complete.
#if defined(OS_WIN) || (defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
diff --git chrome/browser/chrome_browser_main_mac.mm chrome/browser/chrome_browser_main_mac.mm
index c30b73c2575f..5da45a243f9b 100644
--- chrome/browser/chrome_browser_main_mac.mm
+++ chrome/browser/chrome_browser_main_mac.mm
@@ -16,6 +16,7 @@
#include "base/path_service.h"
#include "base/strings/sys_string_conversions.h"
#include "build/branding_buildflags.h"
+#include "cef/libcef/features/features.h"
#import "chrome/browser/app_controller_mac.h"
#include "chrome/browser/apps/app_shim/app_shim_listener.h"
#include "chrome/browser/browser_process.h"
@@ -111,6 +112,7 @@
}
}
+#if !BUILDFLAG(ENABLE_CEF)
// Create the app delegate. This object is intentionally leaked as a global
// singleton. It is accessed through -[NSApp delegate].
AppController* app_controller = [[AppController alloc] init];
@@ -119,6 +121,7 @@
chrome::BuildMainMenu(NSApp, app_controller,
l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), false);
[app_controller mainMenuCreated];
+#endif // BUILDFLAG(ENABLE_CEF)
PrefService* local_state = g_browser_process->local_state();
DCHECK(local_state);
@@ -175,7 +178,9 @@
}
void ChromeBrowserMainPartsMac::DidEndMainMessageLoop() {
+#if !BUILDFLAG(ENABLE_CEF)
AppController* appController =
base::mac::ObjCCastStrict<AppController>([NSApp delegate]);
[appController didEndMainMessageLoop];
+#endif
}
diff --git chrome/browser/notifications/notification_platform_bridge_mac.mm chrome/browser/notifications/notification_platform_bridge_mac.mm
index 9e8fcb9f9f91..2a9eaca0fb0d 100644
--- chrome/browser/notifications/notification_platform_bridge_mac.mm
@@ -140,7 +178,7 @@ index 9e8fcb9f9f91..2a9eaca0fb0d 100644
#include "chrome/browser/browser_features.h"
#include "chrome/browser/notifications/notification_common.h"
#include "chrome/browser/notifications/notification_display_service_impl.h"
@@ -451,6 +452,12 @@ getDisplayedAlertsForProfileId:(NSString*)profileId
@@ -451,6 +452,12 @@ - (void)notificationClick:(NSDictionary*)notificationResponseData {
- (id<NotificationDelivery>)serviceProxy {
id<NotificationDelivery> proxy = [_xpcConnection remoteObjectProxy];