Merge pull request #635 from abarth/mac_main

Make it easier to run SkyShell from the command line on Mac
This commit is contained in:
Adam Barth 2015-08-15 13:54:00 -07:00
commit 208bec2d27
6 changed files with 87 additions and 99 deletions

View File

@ -27,6 +27,13 @@ common_deps = [
"//ui/gl",
]
testing_sources = [
"testing/test_runner.cc",
"testing/test_runner.h",
"testing/testing.cc",
"testing/testing.h",
]
source_set("common") {
sources = [
"gpu/ganesh_context.cc",
@ -225,12 +232,10 @@ if (is_android) {
output_name = "sky_shell"
sources = [
"linux/main.cc",
"linux/main_linux.cc",
"linux/platform_service_provider_linux.cc",
"linux/platform_view_linux.cc",
"testing/test_runner.cc",
"testing/test_runner.h",
]
] + testing_sources
deps = common_deps + [
":common",
@ -254,9 +259,7 @@ if (is_android) {
"mac/sky_application.mm",
"mac/sky_window.h",
"mac/sky_window.mm",
"testing/test_runner.cc",
"testing/test_runner.h",
]
] + testing_sources
deps = common_deps + [
":common",

View File

@ -0,0 +1,36 @@
// Copyright 2015 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 "base/at_exit.h"
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "sky/shell/service_provider.h"
#include "sky/shell/shell.h"
#include "sky/shell/switches.h"
#include "sky/shell/testing/testing.h"
int main(int argc, const char* argv[]) {
base::AtExitManager exit_manager;
base::CommandLine::Init(argc, argv);
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(sky::shell::switches::kHelp)) {
sky::shell::switches::PrintUsage("sky_shell");
return 0;
}
base::MessageLoop message_loop;
sky::shell::Shell::Init(make_scoped_ptr(
new sky::shell::ServiceProviderContext(message_loop.task_runner())));
message_loop.PostTask(FROM_HERE, base::Bind(&sky::shell::InitForTesting));
message_loop.Run();
return 0;
}

View File

@ -5,58 +5,17 @@
#import <Cocoa/Cocoa.h>
#include <iostream>
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "sky/engine/public/web/WebRuntimeFeatures.h"
#include "sky/shell/mac/platform_mac.h"
#include "base/command_line.h"
#include "sky/shell/switches.h"
#include "sky/shell/testing/test_runner.h"
#include "base/message_loop/message_loop.h"
#include "sky/shell/mac/platform_mac.h"
#include "sky/shell/mac/sky_application.h"
#include "sky/shell/switches.h"
#include "sky/shell/testing/testing.h"
namespace sky {
namespace shell {
namespace {
bool FlagsValid() {
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(sky::shell::switches::kHelp) ||
(!command_line.HasSwitch(sky::shell::switches::kPackageRoot) &&
!command_line.HasSwitch(sky::shell::switches::kSnapshot))) {
return false;
}
return true;
}
void Init() {
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
blink::WebRuntimeFeatures::enableObservatory(
!command_line.HasSwitch(switches::kNonInteractive));
// Explicitly boot the shared test runner.
TestRunner& runner = TestRunner::Shared();
std::string package_root =
command_line.GetSwitchValueASCII(switches::kPackageRoot);
runner.set_package_root(package_root);
scoped_ptr<TestRunner::SingleTest> single_test;
if (command_line.HasSwitch(switches::kSnapshot)) {
single_test.reset(new TestRunner::SingleTest);
single_test->path = command_line.GetSwitchValueASCII(switches::kSnapshot);
single_test->is_snapshot = true;
} else {
auto args = command_line.GetArgs();
if (!args.empty()) {
single_test.reset(new TestRunner::SingleTest);
single_test->path = args[0];
}
}
runner.Start(single_test.Pass());
}
void AttachMessageLoopToMainRunLoop(void) {
// We want to call Run() on the MessageLoopForUI but after NSApplicationMain.
// If called before this point, the call is blocking and will prevent the
@ -74,15 +33,20 @@ int main(int argc, const char* argv[]) {
[SkyApplication sharedApplication];
return PlatformMacMain(argc, argv, ^() {
if (!sky::shell::FlagsValid()) {
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(sky::shell::switches::kHelp)) {
sky::shell::switches::PrintUsage("SkyShell");
sky::shell::AttachMessageLoopToMainRunLoop();
return NSApplicationMain(argc, argv);
} else {
return EXIT_SUCCESS;
}
if (command_line.HasSwitch(sky::shell::switches::kNonInteractive)) {
auto loop = base::MessageLoop::current();
loop->PostTask(FROM_HERE, base::Bind(&sky::shell::Init));
loop->PostTask(FROM_HERE, base::Bind(&sky::shell::InitForTesting));
loop->Run();
return EXIT_SUCCESS;
}
sky::shell::AttachMessageLoopToMainRunLoop();
return NSApplicationMain(argc, argv);
});
}

View File

@ -8,11 +8,11 @@
#include "mojo/public/cpp/bindings/interface_request.h"
#include "sky/services/engine/input_event.mojom.h"
#include "sky/shell/mac/platform_view_mac.h"
#include "sky/shell/shell.h"
#include "sky/shell/shell_view.h"
#include "sky/shell/shell.h"
#include "sky/shell/switches.h"
#include "sky/shell/ui_delegate.h"
@interface SkyWindow ()<NSWindowDelegate>
@property(assign) IBOutlet NSOpenGLView* renderSurface;
@ -87,12 +87,17 @@ static inline sky::EventType EventTypeFromNSEventPhase(NSEventPhase phase) {
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
base::CommandLine::StringVector args = command_line.GetArgs();
if (args.size() > 0) {
LOG(INFO) << "Loading " << args[0];
mojo::String string(args[0]);
_sky_engine->RunFromNetwork(string);
return;
}
if (command_line.HasSwitch(sky::shell::switches::kSnapshot)) {
auto snapshot = command_line.GetSwitchValueASCII(sky::shell::switches::kSnapshot);
_sky_engine->RunFromSnapshot(snapshot);
return;
}
NSString *endpoint = self.skyInitialBundleURL;
if (endpoint.length > 0) {
// Load from bundle

View File

@ -2,28 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <iostream>
#include "sky/shell/testing/testing.h"
#include "base/at_exit.h"
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/i18n/icu_util.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "sky/engine/public/web/WebRuntimeFeatures.h"
#include "sky/shell/platform_view.h"
#include "sky/shell/service_provider.h"
#include "sky/shell/shell.h"
#include "sky/shell/shell_view.h"
#include "base/command_line.h"
#include "sky/shell/switches.h"
#include "sky/shell/testing/test_runner.h"
namespace sky {
namespace shell {
namespace {
void Init() {
void InitForTesting() {
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
blink::WebRuntimeFeatures::enableObservatory(
!command_line.HasSwitch(switches::kNonInteractive));
@ -51,30 +40,5 @@ void Init() {
runner.Start(single_test.Pass());
}
} // namespace
} // namespace shell
} // namespace sky
int main(int argc, const char* argv[]) {
base::AtExitManager exit_manager;
base::CommandLine::Init(argc, argv);
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(sky::shell::switches::kHelp) ||
(!command_line.HasSwitch(sky::shell::switches::kPackageRoot) &&
!command_line.HasSwitch(sky::shell::switches::kSnapshot))) {
sky::shell::switches::PrintUsage("sky_shell");
return 0;
}
base::MessageLoop message_loop;
sky::shell::Shell::Init(make_scoped_ptr(
new sky::shell::ServiceProviderContext(message_loop.task_runner())));
message_loop.PostTask(FROM_HERE, base::Bind(&sky::shell::Init));
message_loop.Run();
return 0;
}

View File

@ -0,0 +1,16 @@
// Copyright 2015 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 SKY_SHELL_TESTING_TESTING_H_
#define SKY_SHELL_TESTING_TESTING_H_
namespace sky {
namespace shell {
void InitForTesting();
} // namespace shell
} // namespace sky
#endif // SKY_SHELL_TESTING_TESTING_H_