mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
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:
@@ -103,7 +103,6 @@ MainContextImpl::MainContextImpl(CefRefPtr<CefCommandLine> command_line,
|
||||
use_chrome_runtime_ = false;
|
||||
}
|
||||
|
||||
#if defined(OS_WIN) || defined(OS_LINUX)
|
||||
// Whether the Views framework will be used.
|
||||
use_views_ = command_line_->HasSwitch(switches::kUseViews);
|
||||
|
||||
@@ -126,7 +125,6 @@ MainContextImpl::MainContextImpl(CefRefPtr<CefCommandLine> command_line,
|
||||
// Use the draggable regions test as the default URL for frameless windows.
|
||||
main_url_ = "http://tests/draggable";
|
||||
}
|
||||
#endif // defined(OS_WIN) || defined(OS_LINUX)
|
||||
|
||||
if (command_line_->HasSwitch(switches::kBackgroundColor)) {
|
||||
// Parse the background color value.
|
||||
|
@@ -4,9 +4,7 @@
|
||||
|
||||
#include "tests/cefclient/browser/root_window.h"
|
||||
|
||||
#if defined(OS_WIN) || defined(OS_LINUX)
|
||||
#include "tests/cefclient/browser/root_window_views.h"
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "tests/cefclient/browser/root_window_win.h"
|
||||
@@ -21,11 +19,7 @@ namespace client {
|
||||
// static
|
||||
scoped_refptr<RootWindow> RootWindow::Create(bool use_views) {
|
||||
if (use_views) {
|
||||
#if defined(OS_WIN) || defined(OS_LINUX)
|
||||
return new RootWindowViews();
|
||||
#else
|
||||
LOG(FATAL) << "Views framework is not supported on this platform.";
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
|
@@ -686,9 +686,13 @@ ViewsWindow::ViewsWindow(Delegate* delegate,
|
||||
frameless_ = command_line->HasSwitch(switches::kHideFrame) ||
|
||||
delegate_->WithExtension();
|
||||
|
||||
#if !defined(OS_MAC)
|
||||
// On Mac we don't show a top menu on the window. The options are available in
|
||||
// the app menu instead.
|
||||
if (!command_line->HasSwitch(switches::kHideTopMenu)) {
|
||||
top_menu_bar_ = new ViewsMenuBar(this, ID_TOP_MENU_FIRST);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ViewsWindow::SetBrowserView(CefRefPtr<CefBrowserView> browser_view) {
|
||||
|
@@ -13,12 +13,8 @@
|
||||
#include "tests/cefsimple/simple_handler.h"
|
||||
|
||||
// Receives notifications from the application.
|
||||
@interface SimpleAppDelegate : NSObject <NSApplicationDelegate> {
|
||||
@private
|
||||
bool with_chrome_runtime_;
|
||||
}
|
||||
@interface SimpleAppDelegate : NSObject <NSApplicationDelegate>
|
||||
|
||||
- (id)initWithChromeRuntime:(bool)with_chrome_runtime;
|
||||
- (void)createApplication:(id)object;
|
||||
- (void)tryToTerminateApplication:(NSApplication*)app;
|
||||
@end
|
||||
@@ -91,23 +87,11 @@
|
||||
|
||||
@implementation SimpleAppDelegate
|
||||
|
||||
- (id)initWithChromeRuntime:(bool)with_chrome_runtime {
|
||||
if (self = [super init]) {
|
||||
with_chrome_runtime_ = with_chrome_runtime;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
// Create the application on the UI thread.
|
||||
- (void)createApplication:(id)object {
|
||||
if (!with_chrome_runtime_) {
|
||||
// Chrome will create the top-level menu programmatically in
|
||||
// chrome/browser/ui/cocoa/main_menu_builder.h
|
||||
// TODO(chrome-runtime): Expose a way to customize this menu.
|
||||
[[NSBundle mainBundle] loadNibNamed:@"MainMenu"
|
||||
owner:NSApp
|
||||
topLevelObjects:nil];
|
||||
}
|
||||
[[NSBundle mainBundle] loadNibNamed:@"MainMenu"
|
||||
owner:NSApp
|
||||
topLevelObjects:nil];
|
||||
|
||||
// Set the delegate for application events.
|
||||
[[NSApplication sharedApplication] setDelegate:self];
|
||||
@@ -177,8 +161,7 @@ int main(int argc, char* argv[]) {
|
||||
CefInitialize(main_args, settings, app.get(), NULL);
|
||||
|
||||
// Create the application delegate.
|
||||
NSObject* delegate =
|
||||
[[SimpleAppDelegate alloc] initWithChromeRuntime:with_chrome_runtime];
|
||||
NSObject* delegate = [[SimpleAppDelegate alloc] init];
|
||||
[delegate performSelectorOnMainThread:@selector(createApplication:)
|
||||
withObject:nil
|
||||
waitUntilDone:NO];
|
||||
|
@@ -85,15 +85,10 @@ void SimpleApp::OnContextInitialized() {
|
||||
CefRefPtr<CefCommandLine> command_line =
|
||||
CefCommandLine::GetGlobalCommandLine();
|
||||
|
||||
#if defined(OS_WIN) || defined(OS_LINUX)
|
||||
// Create the browser using the Views framework if "--use-views" is specified
|
||||
// via the command-line. Otherwise, create the browser using the native
|
||||
// platform framework. The Views framework is currently only supported on
|
||||
// Windows and Linux.
|
||||
// platform framework.
|
||||
const bool use_views = command_line->HasSwitch("use-views");
|
||||
#else
|
||||
const bool use_views = false;
|
||||
#endif
|
||||
|
||||
// SimpleHandler implements browser-level callbacks.
|
||||
CefRefPtr<SimpleHandler> handler(new SimpleHandler(use_views));
|
||||
|
@@ -21,8 +21,6 @@
|
||||
'ceftests_sources_common',
|
||||
'ceftests_sources_linux:LINUX',
|
||||
'ceftests_sources_mac:MAC',
|
||||
'ceftests_sources_views:WINDOWS',
|
||||
'ceftests_sources_views:LINUX',
|
||||
'ceftests_sources_win:WINDOWS',
|
||||
],
|
||||
}}
|
||||
|
@@ -8,20 +8,15 @@
|
||||
#include "include/base/cef_logging.h"
|
||||
#include "include/cef_command_line.h"
|
||||
#include "include/cef_stream.h"
|
||||
#include "include/views/cef_browser_view.h"
|
||||
#include "include/views/cef_window.h"
|
||||
#include "include/wrapper/cef_closure_task.h"
|
||||
#include "include/wrapper/cef_stream_resource_handler.h"
|
||||
#include "tests/ceftests/test_request.h"
|
||||
#include "tests/shared/common/client_switches.h"
|
||||
|
||||
#if defined(USE_AURA)
|
||||
#include "include/views/cef_browser_view.h"
|
||||
#include "include/views/cef_window.h"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
#if defined(USE_AURA)
|
||||
|
||||
// Delegate implementation for the CefWindow that will host the Views-based
|
||||
// browser.
|
||||
class TestWindowDelegate : public CefWindowDelegate {
|
||||
@@ -88,8 +83,6 @@ class TestBrowserViewDelegate : public CefBrowserViewDelegate {
|
||||
DISALLOW_COPY_AND_ASSIGN(TestBrowserViewDelegate);
|
||||
};
|
||||
|
||||
#endif // defined(USE_AURA)
|
||||
|
||||
} // namespace
|
||||
|
||||
// TestHandler::CompletionState
|
||||
@@ -353,7 +346,6 @@ void TestHandler::OnTestTimeout(int timeout_ms, bool treat_as_error) {
|
||||
void TestHandler::CreateBrowser(const CefString& url,
|
||||
CefRefPtr<CefRequestContext> request_context,
|
||||
CefRefPtr<CefDictionaryValue> extra_info) {
|
||||
#if defined(USE_AURA)
|
||||
const bool use_views = CefCommandLine::GetGlobalCommandLine()->HasSwitch(
|
||||
client::switches::kUseViews);
|
||||
if (use_views && !CefCurrentlyOn(TID_UI)) {
|
||||
@@ -362,13 +354,11 @@ void TestHandler::CreateBrowser(const CefString& url,
|
||||
request_context, extra_info));
|
||||
return;
|
||||
}
|
||||
#endif // defined(USE_AURA)
|
||||
|
||||
CefWindowInfo windowInfo;
|
||||
CefBrowserSettings settings;
|
||||
PopulateBrowserSettings(&settings);
|
||||
|
||||
#if defined(USE_AURA)
|
||||
if (use_views) {
|
||||
// Create the BrowserView.
|
||||
CefRefPtr<CefBrowserView> browser_view = CefBrowserView::CreateBrowserView(
|
||||
@@ -377,9 +367,7 @@ void TestHandler::CreateBrowser(const CefString& url,
|
||||
|
||||
// Create the Window. It will show itself after creation.
|
||||
TestWindowDelegate::CreateBrowserWindow(browser_view, std::string());
|
||||
} else
|
||||
#endif // defined(USE_AURA)
|
||||
{
|
||||
} else {
|
||||
#if defined(OS_WIN)
|
||||
windowInfo.SetAsPopup(nullptr, "CefUnitTest");
|
||||
windowInfo.style |= WS_VISIBLE;
|
||||
|
@@ -189,12 +189,12 @@ void CefTestSuite::PreInitialize() {
|
||||
HeapSetInformation(nullptr, HeapEnableTerminationOnCorruption, nullptr, 0);
|
||||
#endif
|
||||
|
||||
#if defined(OS_LINUX) && defined(USE_AURA)
|
||||
#if defined(OS_LINUX)
|
||||
// When calling native char conversion functions (e.g wrctomb) we need to
|
||||
// have the locale set. In the absence of such a call the "C" locale is the
|
||||
// default. In the gtk code (below) gtk_init() implicitly sets a locale.
|
||||
setlocale(LC_ALL, "");
|
||||
#endif // defined(OS_LINUX) && defined(USE_AURA)
|
||||
#endif // defined(OS_LINUX)
|
||||
|
||||
// Don't add additional code to this function. Instead add it to Initialize().
|
||||
}
|
||||
|
Reference in New Issue
Block a user