diff options
author | jam <jam@chromium.org> | 2015-04-09 19:30:17 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-10 02:30:55 +0000 |
commit | 143eb32f63bd929f7d730970e2477804f318a7eb (patch) | |
tree | 9cf532f852ff21fa7ca246af71f7964f3fd2dbba | |
parent | 8a040a4f5f595d7dd1942bf206564587781575b6 (diff) | |
download | chromium_src-143eb32f63bd929f7d730970e2477804f318a7eb.zip chromium_src-143eb32f63bd929f7d730970e2477804f318a7eb.tar.gz chromium_src-143eb32f63bd929f7d730970e2477804f318a7eb.tar.bz2 |
Simplify mojo_shell since it's now only used for Mandoline.
-no need to map kiosk_wm to window_manager, instead, make kiosk_wm's binary output be window_manager.mojom
-no need for app-specific args, instead use base::CommandLine. This is important for Mandoline since we'll be sharing code with Chrome which does use these flags.
-mojo_shell url is enough to start a browser now
Review URL: https://codereview.chromium.org/1057603003
Cr-Commit-Position: refs/heads/master@{#324579}
23 files changed, 98 insertions, 645 deletions
diff --git a/mojo/application/application_runner_chromium.cc b/mojo/application/application_runner_chromium.cc index 069ff90..ce104f0 100644 --- a/mojo/application/application_runner_chromium.cc +++ b/mojo/application/application_runner_chromium.cc @@ -13,6 +13,18 @@ #include "mojo/public/cpp/application/application_delegate.h" #include "mojo/public/cpp/application/application_impl.h" +int g_argc; +const char* const* g_argv; +#if !defined(OS_WIN) +extern "C" { +__attribute__((visibility("default"))) void InitCommandLineArgs( + int argc, const char* const* argv) { + g_argc = argc; + g_argv = argv; +} +} +#endif + namespace mojo { // static @@ -42,7 +54,7 @@ MojoResult ApplicationRunnerChromium::Run( DCHECK(!has_run_); has_run_ = true; - base::CommandLine::Init(0, NULL); + base::CommandLine::Init(g_argc, g_argv); base::AtExitManager at_exit; #ifndef NDEBUG diff --git a/mojo/services/BUILD.gn b/mojo/services/BUILD.gn index bc6256d..945e6f0 100644 --- a/mojo/services/BUILD.gn +++ b/mojo/services/BUILD.gn @@ -21,7 +21,7 @@ group("services") { deps += [ "//mojo/services/clipboard", "//mojo/services/html_viewer", - "//mojo/services/kiosk_wm", + "//mojo/services/kiosk_wm:window_manager", "//mojo/services/native_viewport", "//mojo/services/network", "//mojo/services/surfaces", @@ -33,7 +33,7 @@ group("services") { if (is_mac) { deps -= [ "//mojo/services/html_viewer", - "//mojo/services/kiosk_wm", + "//mojo/services/kiosk_wm:window_manager", "//mojo/services/native_viewport", "//mojo/services/view_manager", ] diff --git a/mojo/services/html_viewer/html_viewer.cc b/mojo/services/html_viewer/html_viewer.cc index 1391c1c..a5aa774 100644 --- a/mojo/services/html_viewer/html_viewer.cc +++ b/mojo/services/html_viewer/html_viewer.cc @@ -47,8 +47,7 @@ using mojo::URLResponsePtr; namespace html_viewer { -// Switches for html_viewer to be used with "--args-for". For example: -// --args-for='mojo:html_viewer --enable-mojo-media-renderer' +// Switches for html_viewer. // Enable MediaRenderer in media pipeline instead of using the internal // media::Renderer implementation. @@ -186,16 +185,7 @@ class HTMLViewer : public mojo::ApplicationDelegate, ui::RegisterPathProvider(); - base::CommandLine::StringVector command_line_args; -#if defined(OS_WIN) - for (const auto& arg : app->args()) - command_line_args.push_back(base::UTF8ToUTF16(arg)); -#elif defined(OS_POSIX) - command_line_args = app->args(); -#endif - base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); - command_line->InitFromArgv(command_line_args); logging::LoggingSettings settings; settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; diff --git a/mojo/services/html_viewer/view_url.py b/mojo/services/html_viewer/view_url.py deleted file mode 100755 index a543385..0000000 --- a/mojo/services/html_viewer/view_url.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python -# 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. - -import argparse -import os -import subprocess -import sys - -root_path = os.path.realpath( - os.path.join( - os.path.dirname( - os.path.realpath(__file__)), - os.pardir, - os.pardir, - os.pardir)) - -def _BuildShellCommand(args): - sdk_version = subprocess.check_output(["cat", - "third_party/mojo/src/mojo/public/VERSION"], cwd=root_path) - build_dir = os.path.join(root_path, args.build_dir) - - shell_command = [os.path.join(build_dir, "mojo_shell")] - - options = [] - options.append( - "--origin=https://storage.googleapis.com/mojo/services/linux-x64/%s" % - sdk_version) - options.append("--url-mappings=mojo:html_viewer=file://%s/html_viewer.mojo" % - build_dir) - options.append('--args-for=mojo:kiosk_wm %s' % args.url) - - app_to_run = "mojo:kiosk_wm" - - return shell_command + options + [app_to_run] - -def main(): - parser = argparse.ArgumentParser( - description="View a URL with HTMLViewer in the Kiosk window manager. " - "You must have built //mojo/services/html_viewer and " - "//mojo/services/network first. Note that this will " - "currently often fail spectacularly due to lack of binary " - "stability in Mojo.") - parser.add_argument( - "--build-dir", - help="Path to the dir containing the linux-x64 binaries relative to the " - "repo root (default: %(default)s)", - default="out/Release") - parser.add_argument("url", - help="The URL to be viewed") - - args = parser.parse_args() - return subprocess.call(_BuildShellCommand(args)) - -if __name__ == '__main__': - sys.exit(main()) diff --git a/mojo/services/kiosk_wm/BUILD.gn b/mojo/services/kiosk_wm/BUILD.gn index 99c25f0..988c6c9 100644 --- a/mojo/services/kiosk_wm/BUILD.gn +++ b/mojo/services/kiosk_wm/BUILD.gn @@ -5,7 +5,10 @@ import("//third_party/mojo/src/mojo/public/mojo_application.gni") import("$mojo_sdk_root/mojo/public/tools/bindings/mojom.gni") -mojo_native_application("kiosk_wm") { +# Mojo shell in chromium is only used for Mandoline, and Mandoline only uses +# kiosk_wm, so we name the target window_manager to avoid having to remap on the +# command line. +mojo_native_application("window_manager") { sources = [ "kiosk_wm.cc", "kiosk_wm.h", diff --git a/mojo/services/kiosk_wm/kiosk_wm.cc b/mojo/services/kiosk_wm/kiosk_wm.cc index 28b5b5e..64ec213 100644 --- a/mojo/services/kiosk_wm/kiosk_wm.cc +++ b/mojo/services/kiosk_wm/kiosk_wm.cc @@ -4,6 +4,8 @@ #include "mojo/services/kiosk_wm/kiosk_wm.h" +#include "base/command_line.h" +#include "base/strings/utf_string_conversions.h" #include "mojo/services/kiosk_wm/merged_service_provider.h" #include "mojo/services/window_manager/basic_focus_rules.h" @@ -28,9 +30,17 @@ base::WeakPtr<KioskWM> KioskWM::GetWeakPtr() { void KioskWM::Initialize(mojo::ApplicationImpl* app) { window_manager_app_->Initialize(app); - // Format: --args-for="app_url default_url" - if (app->args().size() > 1) - default_url_ = app->args()[1]; + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + base::CommandLine::StringVector args = command_line->GetArgs(); + if (args.empty()) { + default_url_ = "http://www.google.com/"; + } else { +#if defined(OS_WIN) + default_url_ = base::WideToUTF8(args[0]); +#else + default_url_ = args[0]; +#endif + } } bool KioskWM::ConfigureIncomingConnection( diff --git a/mojo/services/window_manager/BUILD.gn b/mojo/services/window_manager/BUILD.gn index c34ebe1..bb6df15 100644 --- a/mojo/services/window_manager/BUILD.gn +++ b/mojo/services/window_manager/BUILD.gn @@ -6,23 +6,6 @@ import("//build/config/ui.gni") import("//third_party/mojo/src/mojo/public/mojo_application.gni") import("//testing/test.gni") -mojo_native_application("window_manager") { - sources = [ - "main.cc", - ] - - public_deps = [ - ":lib", - ] - - deps = [ - "//base", - "//mojo/application", - "//mojo/common:tracing_impl", - "//third_party/mojo_services/src/view_manager/public/cpp", - ] -} - source_set("lib") { sources = [ "basic_focus_rules.cc", @@ -108,6 +91,24 @@ test("window_manager_unittests") { } } +# A basic window manager with a default delegate used for testing. +mojo_native_application("test_window_manager") { + sources = [ + "main.cc", + ] + + public_deps = [ + ":lib", + ] + + deps = [ + "//base", + "//mojo/application", + "//mojo/common:tracing_impl", + "//third_party/mojo_services/src/view_manager/public/cpp", + ] +} + mojo_native_application("window_manager_apptests") { testonly = true @@ -125,5 +126,5 @@ mojo_native_application("window_manager_apptests") { "//third_party/mojo_services/src/window_manager/public/interfaces", ] - data_deps = [ ":window_manager($default_toolchain)" ] + data_deps = [ ":test_window_manager($default_toolchain)" ] } diff --git a/mojo/services/window_manager/window_manager_apptest.cc b/mojo/services/window_manager/window_manager_apptest.cc index 7f82211..f46942b 100644 --- a/mojo/services/window_manager/window_manager_apptest.cc +++ b/mojo/services/window_manager/window_manager_apptest.cc @@ -84,7 +84,7 @@ class WindowManagerApplicationTest : public test::ApplicationTestBase { // ApplicationTestBase: void SetUp() override { ApplicationTestBase::SetUp(); - application_impl()->ConnectToService("mojo:window_manager", + application_impl()->ConnectToService("mojo:test_window_manager", &window_manager_); } ApplicationDelegate* GetApplicationDelegate() override { diff --git a/mojo/shell/BUILD.gn b/mojo/shell/BUILD.gn index 1dbe6ad..e83912c 100644 --- a/mojo/shell/BUILD.gn +++ b/mojo/shell/BUILD.gn @@ -114,8 +114,6 @@ source_set("lib") { "child_process.h", "child_process_host.cc", "child_process_host.h", - "command_line_util.cc", - "command_line_util.h", "context.cc", "context.h", "filename_util.cc", @@ -363,7 +361,6 @@ mojom("app_child_process_bindings") { test("mojo_shell_tests") { sources = [ "app_child_process_host_unittest.cc", - "command_line_util_unittest.cc", "data_pipe_peek_unittest.cc", "in_process_native_runner_unittest.cc", "native_runner_unittest.cc", diff --git a/mojo/shell/android/main.cc b/mojo/shell/android/main.cc index 41c507a..9caf840 100644 --- a/mojo/shell/android/main.cc +++ b/mojo/shell/android/main.cc @@ -26,7 +26,6 @@ #include "mojo/shell/android/native_viewport_application_loader.h" #include "mojo/shell/android/ui_application_loader_android.h" #include "mojo/shell/application_manager/application_loader.h" -#include "mojo/shell/command_line_util.h" #include "mojo/shell/context.h" #include "mojo/shell/init.h" #include "ui/gl/gl_surface_egl.h" @@ -46,15 +45,12 @@ const char kFifoPath[] = "fifo-path"; class MojoShellRunner : public base::DelegateSimpleThread::Delegate { public: - MojoShellRunner(const std::vector<std::string>& parameters) - : parameters_(parameters) {} + MojoShellRunner(const std::vector<std::string>& parameters) {} ~MojoShellRunner() override {} private: void Run() override; - std::vector<std::string> parameters_; - DISALLOW_COPY_AND_ASSIGN(MojoShellRunner); }; @@ -107,10 +103,7 @@ void MojoShellRunner::Run() { ConfigureAndroidServices(context); context->Init(); - for (auto& args : parameters_) - ApplyApplicationArgs(context, args); - - RunCommandLineApps(context); + context->Run(GURL("mojo:window_manager")); loop.Run(); g_java_message_loop.Pointer()->get()->PostTask(FROM_HERE, diff --git a/mojo/shell/application_manager/application_manager.cc b/mojo/shell/application_manager/application_manager.cc index d137fb8..8c908a7 100644 --- a/mojo/shell/application_manager/application_manager.cc +++ b/mojo/shell/application_manager/application_manager.cc @@ -29,17 +29,6 @@ namespace { // Used by TestAPI. bool has_created_instance = false; -std::vector<std::string> Concatenate(const std::vector<std::string>& v1, - const std::vector<std::string>& v2) { - if (!v1.size()) - return v2; - if (!v2.size()) - return v1; - std::vector<std::string> result(v1); - result.insert(result.end(), v1.begin(), v1.end()); - return result; -} - } // namespace ApplicationManager::Delegate::~Delegate() { @@ -154,32 +143,31 @@ void ApplicationManager::ConnectToApplicationWithParameters( } // The application is not running, let's compute the parameters. - std::vector<std::string> parameters = - Concatenate(pre_redirect_parameters, GetArgsForURL(resolved_url)); - if (ConnectToApplicationWithLoader(mapped_url, requestor_url, &services, &exposed_services, on_application_end, - parameters, GetLoaderForURL(mapped_url))) { + pre_redirect_parameters, + GetLoaderForURL(mapped_url))) { return; } - if (ConnectToApplicationWithLoader( - resolved_url, requestor_url, &services, &exposed_services, - on_application_end, parameters, GetLoaderForURL(resolved_url))) { + if (ConnectToApplicationWithLoader(resolved_url, requestor_url, &services, + &exposed_services, on_application_end, + pre_redirect_parameters, + GetLoaderForURL(resolved_url))) { return; } - if (ConnectToApplicationWithLoader(resolved_url, requestor_url, &services, - &exposed_services, on_application_end, - parameters, default_loader_.get())) { + if (ConnectToApplicationWithLoader( + resolved_url, requestor_url, &services, &exposed_services, + on_application_end, pre_redirect_parameters, default_loader_.get())) { return; } - auto callback = base::Bind( - &ApplicationManager::HandleFetchCallback, weak_ptr_factory_.GetWeakPtr(), - requestor_url, base::Passed(services.Pass()), - base::Passed(exposed_services.Pass()), on_application_end, - parameters); + auto callback = base::Bind(&ApplicationManager::HandleFetchCallback, + weak_ptr_factory_.GetWeakPtr(), requestor_url, + base::Passed(services.Pass()), + base::Passed(exposed_services.Pass()), + on_application_end, pre_redirect_parameters); if (resolved_url.SchemeIsFile()) { new LocalFetcher( @@ -375,22 +363,6 @@ void ApplicationManager::RunNativeApplication( weak_ptr_factory_.GetWeakPtr(), runner)); } -void ApplicationManager::RegisterExternalApplication( - const GURL& url, - const std::vector<std::string>& args, - ApplicationPtr application) { - const auto& args_it = url_to_args_.find(url); - if (args_it != url_to_args_.end()) { - LOG(WARNING) << "--args-for provided for external application " << url - << " <ignored>"; - } - Identity identity(url); - ShellImpl* shell_impl = - new ShellImpl(application.Pass(), this, identity, base::Closure()); - identity_to_shell_impl_[identity] = shell_impl; - shell_impl->InitializeApplication(Array<String>::From(args)); -} - void ApplicationManager::RegisterContentHandler( const std::string& mime_type, const GURL& content_handler_url) { @@ -434,21 +406,6 @@ void ApplicationManager::SetLoaderForScheme( scheme_to_loader_[scheme] = loader.release(); } -void ApplicationManager::SetArgsForURL(const std::vector<std::string>& args, - const GURL& url) { - url_to_args_[url].insert(url_to_args_[url].end(), args.begin(), args.end()); - GURL mapped_url = delegate_->ResolveMappings(url); - if (mapped_url != url) { - url_to_args_[mapped_url].insert(url_to_args_[mapped_url].end(), - args.begin(), args.end()); - } - GURL resolved_url = delegate_->ResolveURL(mapped_url); - if (resolved_url != mapped_url) { - url_to_args_[resolved_url].insert(url_to_args_[resolved_url].end(), - args.begin(), args.end()); - } -} - void ApplicationManager::SetNativeOptionsForURL( const NativeRunnerFactory::Options& options, const GURL& url) { @@ -507,13 +464,6 @@ ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName( return pipe.handle0.Pass(); } -std::vector<std::string> ApplicationManager::GetArgsForURL(const GURL& url) { - const auto& args_it = url_to_args_.find(url); - if (args_it != url_to_args_.end()) - return args_it->second; - return std::vector<std::string>(); -} - void ApplicationManager::CleanupRunner(NativeRunner* runner) { native_runners_.erase( std::find(native_runners_.begin(), native_runners_.end(), runner)); diff --git a/mojo/shell/application_manager/application_manager.h b/mojo/shell/application_manager/application_manager.h index d0d3a40..44e581d 100644 --- a/mojo/shell/application_manager/application_manager.h +++ b/mojo/shell/application_manager/application_manager.h @@ -83,10 +83,6 @@ class ApplicationManager { void RegisterContentHandler(const std::string& mime_type, const GURL& content_handler_url); - void RegisterExternalApplication(const GURL& application_url, - const std::vector<std::string>& args, - ApplicationPtr application); - // Sets the default Loader to be used if not overridden by SetLoaderForURL() // or SetLoaderForScheme(). void set_default_loader(scoped_ptr<ApplicationLoader> loader) { @@ -105,11 +101,6 @@ class ApplicationManager { // Sets a Loader to be used for a specific url scheme. void SetLoaderForScheme(scoped_ptr<ApplicationLoader> loader, const std::string& scheme); - // These strings will be passed to the Initialize() method when an Application - // is instantiated. - // TODO(vtl): Maybe we should store/compare resolved URLs, like - // SetNativeOptionsForURL() below? - void SetArgsForURL(const std::vector<std::string>& args, const GURL& url); // These options will be used in running any native application at |url| // (which shouldn't contain a query string). (|url| will be mapped and // resolved, and any application whose base resolved URL matches it will have @@ -135,7 +126,6 @@ class ApplicationManager { typedef std::map<GURL, ApplicationLoader*> URLToLoaderMap; typedef std::map<Identity, ShellImpl*> IdentityToShellImplMap; typedef std::map<GURL, ContentHandlerConnection*> URLToContentHandlerMap; - typedef std::map<GURL, std::vector<std::string>> URLToArgsMap; typedef std::map<std::string, GURL> MimeTypeToURLMap; typedef std::map<GURL, NativeRunnerFactory::Options> URLToNativeOptionsMap; @@ -204,9 +194,6 @@ class ApplicationManager { // Removes a ContentHandler when it encounters an error. void OnContentHandlerError(ContentHandlerConnection* content_handler); - // Returns the arguments for the given url. - std::vector<std::string> GetArgsForURL(const GURL& url); - void CleanupRunner(NativeRunner* runner); Delegate* const delegate_; @@ -219,7 +206,6 @@ class ApplicationManager { IdentityToShellImplMap identity_to_shell_impl_; URLToContentHandlerMap url_to_content_handler_; - URLToArgsMap url_to_args_; // Note: The keys are URLs after mapping and resolving. URLToNativeOptionsMap url_to_native_options_; diff --git a/mojo/shell/application_manager/application_manager_unittest.cc b/mojo/shell/application_manager/application_manager_unittest.cc index ed16d15..cc420a7 100644 --- a/mojo/shell/application_manager/application_manager_unittest.cc +++ b/mojo/shell/application_manager/application_manager_unittest.cc @@ -419,34 +419,6 @@ class TestDelegate : public ApplicationManager::Delegate { std::map<GURL, GURL> mappings_; }; -class TestExternal : public ApplicationDelegate { - public: - TestExternal() : configure_incoming_connection_called_(false) {} - - void Initialize(ApplicationImpl* app) override { - initialize_args_ = app->args(); - base::MessageLoop::current()->Quit(); - } - - bool ConfigureIncomingConnection(ApplicationConnection* connection) override { - configure_incoming_connection_called_ = true; - base::MessageLoop::current()->Quit(); - return true; - } - - const std::vector<std::string>& initialize_args() const { - return initialize_args_; - } - - bool configure_incoming_connection_called() const { - return configure_incoming_connection_called_; - } - - private: - std::vector<std::string> initialize_args_; - bool configure_incoming_connection_called_; -}; - class ApplicationManagerTest : public testing::Test { public: ApplicationManagerTest() : tester_context_(&loop_) {} @@ -515,75 +487,6 @@ TEST_F(ApplicationManagerTest, NoArgs) { EXPECT_EQ(0U, app_args.size()); } -// Confirm that arguments are sent to an application. -TEST_F(ApplicationManagerTest, Args) { - ApplicationManager am(&test_delegate_); - GURL test_url("test:test"); - std::vector<std::string> args; - args.push_back("test_arg1"); - args.push_back("test_arg2"); - am.SetArgsForURL(args, test_url); - TestApplicationLoader* loader = new TestApplicationLoader; - loader->set_context(&context_); - am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url); - TestServicePtr test_service; - am.ConnectToService(test_url, &test_service); - TestClient test_client(test_service.Pass()); - test_client.Test("test"); - loop_.Run(); - std::vector<std::string> app_args = loader->GetArgs(); - ASSERT_EQ(args.size(), app_args.size()); - EXPECT_EQ(args[0], app_args[0]); - EXPECT_EQ(args[1], app_args[1]); -} - -// Confirm that arguments are aggregated through mappings. -TEST_F(ApplicationManagerTest, ArgsAndMapping) { - ApplicationManager am(&test_delegate_); - GURL test_url("test:test"); - GURL test_url2("test:test2"); - test_delegate_.AddMapping(test_url, test_url2); - std::vector<std::string> args; - args.push_back("test_arg1"); - args.push_back("test_arg2"); - am.SetArgsForURL(args, test_url); - std::vector<std::string> args2; - args2.push_back("test_arg3"); - args2.push_back("test_arg4"); - am.SetArgsForURL(args2, test_url2); - TestApplicationLoader* loader = new TestApplicationLoader; - loader->set_context(&context_); - am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url2); - { - // Connext to the mapped url - TestServicePtr test_service; - am.ConnectToService(test_url, &test_service); - TestClient test_client(test_service.Pass()); - test_client.Test("test"); - loop_.Run(); - std::vector<std::string> app_args = loader->GetArgs(); - ASSERT_EQ(args.size() + args2.size(), app_args.size()); - EXPECT_EQ(args[0], app_args[0]); - EXPECT_EQ(args[1], app_args[1]); - EXPECT_EQ(args2[0], app_args[2]); - EXPECT_EQ(args2[1], app_args[3]); - } - { - // Connext to the target url - TestServicePtr test_service; - am.ConnectToService(test_url2, &test_service); - TestClient test_client(test_service.Pass()); - test_client.Test("test"); - loop_.Run(); - std::vector<std::string> app_args = loader->GetArgs(); - ASSERT_EQ(args.size() + args2.size(), app_args.size()); - EXPECT_EQ(args[0], app_args[0]); - EXPECT_EQ(args[1], app_args[1]); - EXPECT_EQ(args2[0], app_args[2]); - EXPECT_EQ(args2[1], app_args[3]); - } -} - TEST_F(ApplicationManagerTest, ClientError) { test_client_->Test("test"); EXPECT_TRUE(HasFactoryForTestURL()); @@ -773,22 +676,6 @@ TEST_F(ApplicationManagerTest, MappedURLsShouldWorkWithLoaders) { custom_loader->set_context(nullptr); } -TEST_F(ApplicationManagerTest, ExternalApp) { - ApplicationPtr application; - TestExternal external; - std::vector<std::string> args; - args.push_back("test"); - ApplicationImpl app(&external, GetProxy(&application)); - application_manager_->RegisterExternalApplication(GURL("mojo:test"), args, - application.Pass()); - loop_.Run(); - EXPECT_EQ(args, external.initialize_args()); - application_manager_->ConnectToServiceByName(GURL("mojo:test"), - std::string()); - loop_.Run(); - EXPECT_TRUE(external.configure_incoming_connection_called()); -}; - TEST_F(ApplicationManagerTest, TestQueryWithLoaders) { TestApplicationLoader* url_loader = new TestApplicationLoader; TestApplicationLoader* scheme_loader = new TestApplicationLoader; diff --git a/mojo/shell/command_line_util.cc b/mojo/shell/command_line_util.cc deleted file mode 100644 index 68bdfa4..0000000 --- a/mojo/shell/command_line_util.cc +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2014 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 "mojo/shell/command_line_util.h" - -#include <functional> - -#include "base/command_line.h" -#include "base/logging.h" -#include "base/strings/string_split.h" -#include "base/strings/utf_string_conversions.h" -#include "mojo/shell/context.h" -#include "mojo/shell/switches.h" - -namespace mojo { -namespace shell { - -namespace { -GURL GetAppURLAndSetArgs(const std::string& app_url_and_args, - Context* context) { - std::vector<std::string> args; - GURL app_url = GetAppURLAndArgs(context, app_url_and_args, &args); - - if (args.size() > 1) - context->application_manager()->SetArgsForURL(args, app_url); - return app_url; -} -} // namespace - -bool ParseArgsFor(const std::string& arg, std::string* value) { - const std::string kArgsForSwitches[] = { - "-" + std::string(switches::kArgsFor) + "=", - "--" + std::string(switches::kArgsFor) + "=", - }; - for (size_t i = 0; i < arraysize(kArgsForSwitches); i++) { - const std::string& argsfor_switch = kArgsForSwitches[i]; - if (arg.compare(0, argsfor_switch.size(), argsfor_switch) == 0) { - *value = arg.substr(argsfor_switch.size(), std::string::npos); - return true; - } - } - return false; -} - -GURL GetAppURLAndArgs(Context* context, - const std::string& app_url_and_args, - std::vector<std::string>* args) { - // SplitString() returns empty strings for extra delimeter characters (' '). - base::SplitString(app_url_and_args, ' ', args); - args->erase(std::remove_if(args->begin(), args->end(), - std::mem_fun_ref(&std::string::empty)), - args->end()); - - if (args->empty()) - return GURL(); - GURL app_url = context->ResolveCommandLineURL((*args)[0]); - if (!app_url.is_valid()) { - LOG(ERROR) << "Error: invalid URL: " << (*args)[0]; - return app_url; - } - if (args->size() == 1) - args->clear(); - return app_url; -} - -void ApplyApplicationArgs(Context* context, const std::string& args) { - std::string args_for_value; - if (ParseArgsFor(args, &args_for_value)) - GetAppURLAndSetArgs(args_for_value, context); -} - -void RunCommandLineApps(Context* context) { - const auto& command_line = *base::CommandLine::ForCurrentProcess(); - for (const auto& arg : command_line.GetArgs()) { - std::string arg2; -#if defined(OS_WIN) - arg2 = base::UTF16ToUTF8(arg); -#else - arg2 = arg; -#endif - GURL url = GetAppURLAndSetArgs(arg2, context); - if (!url.is_valid()) - return; - context->Run(url); - } -} - -} // namespace shell -} // namespace mojo diff --git a/mojo/shell/command_line_util.h b/mojo/shell/command_line_util.h deleted file mode 100644 index aa80002..0000000 --- a/mojo/shell/command_line_util.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2014 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 SHELL_COMMAND_LINE_UTIL_H_ -#define SHELL_COMMAND_LINE_UTIL_H_ - -#include "mojo/shell/context.h" - -namespace mojo { -namespace shell { - -// Parse the given arg, looking for an --args-for switch. If this is not the -// case, returns |false|. Otherwise, returns |true| and set |*value| to the -// value of the switch. -bool ParseArgsFor(const std::string& arg, std::string* value); - -// The value of app_url_and_args is "<mojo_app_url> [<args>...]", where args -// is a list of "configuration" arguments separated by spaces. If one or more -// arguments are specified they will be available when the Mojo application -// is initialized. This returns the mojo_app_url, and set args to the list of -// arguments. -GURL GetAppURLAndArgs(Context* context, - const std::string& app_url_and_args, - std::vector<std::string>* args); - -// Apply arguments for an application from a line with the following format: -// '--args-for=application_url arg1 arg2 arg3' -// This does nothing if the line has not the right format. -void ApplyApplicationArgs(Context* context, const std::string& args); - -// Run all application defined on the command line, using the given context. -void RunCommandLineApps(Context* context); - -} // namespace shell -} // namespace mojo - -#endif // SHELL_COMMAND_LINE_UTIL_H_ diff --git a/mojo/shell/command_line_util_unittest.cc b/mojo/shell/command_line_util_unittest.cc deleted file mode 100644 index 547aa86..0000000 --- a/mojo/shell/command_line_util_unittest.cc +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2014 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 "mojo/shell/command_line_util.h" - -#include "base/logging.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace mojo { -namespace shell { -namespace { - -TEST(CommandLineUtil, ParseArgsFor) { - static const struct Expectation { - const char* args; - const char* value; - } EXPECTATIONS[] = { - {"", nullptr}, - {"hello", nullptr}, - {"args-for=mojo:app1", nullptr}, - {"--args-for", nullptr}, - {"--args-for=", ""}, - {"--args-for=mojo:app1", "mojo:app1"}, - {"--args-for=mojo:app1 hello world", "mojo:app1 hello world"}, - {"-args-for", nullptr}, - {"-args-for=", ""}, - {"-args-for=mojo:app1", "mojo:app1"}, - {"-args-for=mojo:app1 hello world", "mojo:app1 hello world"}}; - for (auto& expectation : EXPECTATIONS) { - std::string value; - bool result = ParseArgsFor(expectation.args, &value); - EXPECT_EQ(bool(expectation.value), result); - if (expectation.value && result) - EXPECT_EQ(value, expectation.value); - } -} - -TEST(CommandLineUtil, GetAppURLAndArgs) { - const char* NO_ARGUMENTS[] = {nullptr}; - const char* ONE_ARGUMENTS[] = {"1", nullptr}; - const char* TWO_ARGUMENTS[] = {"1", "two", nullptr}; - static const struct Expectation { - const char* args; - const char* url; - const char** values; - } EXPECTATIONS[] = { - {"", nullptr, nullptr}, - {"foo", "file:///root/foo", NO_ARGUMENTS}, - {"/foo", "file:///foo", NO_ARGUMENTS}, - {"file:foo", "file:///root/foo", NO_ARGUMENTS}, - {"file:///foo", "file:///foo", NO_ARGUMENTS}, - {"http://example.com", "http://example.com", NO_ARGUMENTS}, - {"http://example.com 1", "http://example.com", ONE_ARGUMENTS}, - {"http://example.com 1 ", "http://example.com", ONE_ARGUMENTS}, - {"http://example.com 1 ", "http://example.com", ONE_ARGUMENTS}, - {"http://example.com 1 two", "http://example.com", TWO_ARGUMENTS}, - {" http://example.com 1 two ", - "http://example.com", - TWO_ARGUMENTS}}; - Context context; - context.SetCommandLineCWD(base::FilePath(FILE_PATH_LITERAL("/root"))); - for (auto& expectation : EXPECTATIONS) { - std::vector<std::string> args; - GURL result(GetAppURLAndArgs(&context, expectation.args, &args)); - EXPECT_EQ(bool(expectation.url), result.is_valid()); - if (expectation.url && result.is_valid()) { - EXPECT_EQ(GURL(expectation.url), result); - std::vector<std::string> expected_args; - if (expectation.values) { - if (*expectation.values) - expected_args.push_back(expectation.url); - for (const char** value = expectation.values; *value; ++value) - expected_args.push_back(*value); - } - EXPECT_EQ(expected_args, args); - } - } -} - -} // namespace -} // namespace shell -} // namespace mojo diff --git a/mojo/shell/context.cc b/mojo/shell/context.cc index fbde07d..fc56476 100644 --- a/mojo/shell/context.cc +++ b/mojo/shell/context.cc @@ -30,7 +30,6 @@ #include "mojo/services/tracing/tracing.mojom.h" #include "mojo/shell/application_manager/application_loader.h" #include "mojo/shell/application_manager/application_manager.h" -#include "mojo/shell/command_line_util.h" #include "mojo/shell/filename_util.h" #include "mojo/shell/in_process_native_runner.h" #include "mojo/shell/out_of_process_native_runner.h" @@ -85,22 +84,6 @@ bool ConfigureURLMappings(const base::CommandLine& command_line, resolver->AddOriginMapping(GURL(origin_mapping.origin), GURL(origin_mapping.base_url)); - if (command_line.HasSwitch(switches::kURLMappings)) { - const std::string mappings = - command_line.GetSwitchValueASCII(switches::kURLMappings); - - base::StringPairs pairs; - if (!base::SplitStringIntoKeyValuePairs(mappings, '=', ',', &pairs)) - return false; - using StringPair = std::pair<std::string, std::string>; - for (const StringPair& pair : pairs) { - const GURL from(pair.first); - const GURL to = context->ResolveCommandLineURL(pair.second); - if (!from.is_valid() || !to.is_valid()) - return false; - resolver->AddURLMapping(from, to); - } - } return true; } diff --git a/mojo/shell/desktop/launcher_process.cc b/mojo/shell/desktop/launcher_process.cc index f6bb6de..09f7fc5 100644 --- a/mojo/shell/desktop/launcher_process.cc +++ b/mojo/shell/desktop/launcher_process.cc @@ -15,7 +15,6 @@ #include "base/message_loop/message_loop.h" #include "base/synchronization/waitable_event.h" #include "base/trace_event/trace_event.h" -#include "mojo/shell/command_line_util.h" #include "mojo/shell/context.h" #include "mojo/shell/switches.h" @@ -23,29 +22,6 @@ namespace mojo { namespace shell { namespace { -void Usage() { - std::cerr << "Launch Mojo applications.\n"; - std::cerr - << "Usage: mojo_shell" - << " [--" << switches::kArgsFor << "=<mojo-app>]" - << " [--" << switches::kContentHandlers << "=<handlers>]" - << " [--" << switches::kDisableCache << "]" - << " [--" << switches::kEnableMultiprocess << "]" - << " [--" << switches::kOrigin << "=<url-lib-path>]" - << " [--" << switches::kTraceStartup << "]" - << " [--" << switches::kURLMappings << "=from1=to1,from2=to2]" - << " [--" << switches::kPredictableAppFilenames << "]" - << " [--" << switches::kWaitForDebugger << "]" - << " <mojo-app> ...\n\n" - << "A <mojo-app> is a Mojo URL or a Mojo URL and arguments within " - << "quotes.\n" - << "Example: mojo_shell \"mojo:js_standalone test.js\".\n" - << "<url-lib-path> is searched for shared libraries named by mojo URLs.\n" - << "The value of <handlers> is a comma separated list like:\n" - << "text/html,mojo:html_viewer," - << "application/javascript,mojo:js_content_handler\n"; -} - // Whether we're currently tracing. bool g_tracing = false; @@ -99,28 +75,15 @@ void StopTracingAndFlushToDisk() { flush_complete_event.Wait(); } +void StartWindowManager(mojo::shell::Context* context) { + context->Run(GURL("mojo:window_manager")); +} + } // namespace int LauncherProcessMain(int argc, char** argv) { const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); - - const std::set<std::string> all_switches = switches::GetAllSwitches(); - const base::CommandLine::SwitchMap switches = command_line.GetSwitches(); - bool found_unknown_switch = false; - for (const auto& s : switches) { - if (all_switches.find(s.first) == all_switches.end()) { - std::cerr << "unknown switch: " << s.first << std::endl; - found_unknown_switch = true; - } - } - - if (found_unknown_switch || command_line.HasSwitch(switches::kHelp) || - command_line.GetArgs().empty()) { - Usage(); - return 0; - } - if (command_line.HasSwitch(switches::kTraceStartup)) { g_tracing = true; base::trace_event::CategoryFilter category_filter( @@ -136,7 +99,6 @@ int LauncherProcessMain(int argc, char** argv) { { base::MessageLoop message_loop; if (!shell_context.Init()) { - Usage(); return 0; } if (g_tracing) { @@ -145,16 +107,8 @@ int LauncherProcessMain(int argc, char** argv) { base::TimeDelta::FromSeconds(5)); } - // The mojo_shell --args-for command-line switch is handled specially - // because it can appear more than once. The base::CommandLine class - // collapses multiple occurrences of the same switch. - for (int i = 1; i < argc; i++) { - ApplyApplicationArgs(&shell_context, argv[i]); - } - - message_loop.PostTask( - FROM_HERE, - base::Bind(&mojo::shell::RunCommandLineApps, &shell_context)); + message_loop.PostTask(FROM_HERE, + base::Bind(&StartWindowManager, &shell_context)); message_loop.Run(); // Must be called before |message_loop| is destroyed. diff --git a/mojo/shell/native_application_support.cc b/mojo/shell/native_application_support.cc index 55ae2cf..9df3ed88 100644 --- a/mojo/shell/native_application_support.cc +++ b/mojo/shell/native_application_support.cc @@ -4,6 +4,7 @@ #include "mojo/shell/native_application_support.h" +#include "base/command_line.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/logging.h" @@ -104,6 +105,26 @@ bool RunNativeApplication(base::NativeLibrary app_library, init_go_runtime(); } +#if !defined(OS_WIN) + // On Windows, initializing base::CommandLine with null parameters gets the + // process's command line from the OS. Other platforms need it to be passed + // in. This needs to be passed in before the app initializes the command line, + // which is done as soon as it loads. + typedef void (*InitCommandLineArgs)(int, const char* const*); + InitCommandLineArgs init_command_line_args = + reinterpret_cast<InitCommandLineArgs>( + base::GetFunctionPointerFromNativeLibrary(app_library, + "InitCommandLineArgs")); + if (init_command_line_args) { + int argc = 0; + base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); + const char** argv = new const char* [cmd_line->argv().size()]; + for (auto& arg : cmd_line->argv()) + argv[argc++] = arg.c_str(); + init_command_line_args(argc, argv); + } +#endif + typedef MojoResult (*MojoMainFunction)(MojoHandle); MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( base::GetFunctionPointerFromNativeLibrary(app_library, "MojoMain")); diff --git a/mojo/shell/switches.cc b/mojo/shell/switches.cc index 2150b19..28e7d05 100644 --- a/mojo/shell/switches.cc +++ b/mojo/shell/switches.cc @@ -8,18 +8,6 @@ namespace switches { -namespace { -// This controls logging verbosity. It's not strictly a switch for mojo_shell, -// and isn't included in the public switches, but is included here so that it -// doesn't trigger an error at startup. -const char kV[] = "v"; - -} // namespace - -// Specify configuration arguments for a Mojo application URL. For example: -// --args-for='mojo:wget http://www.google.com' -const char kArgsFor[] = "args-for"; - // Used internally by the main process to indicate that a new process should be // a child process. Not for user use. const char kChildProcess[] = "child-process"; @@ -67,34 +55,4 @@ const char kPredictableAppFilenames[] = "predictable-app-filenames"; // seconds or when the shell exits. const char kTraceStartup[] = "trace-startup"; -// Specifies a set of mappings to apply when resolving urls. The value is a set -// of ',' separated mappings, where each mapping consists of a pair of urls -// giving the to/from url to map. For example, 'a=b,c=d' contains two mappings, -// the first maps 'a' to 'b' and the second 'c' to 'd'. -const char kURLMappings[] = "url-mappings"; - -// Switches valid for the main process (i.e., that the user may pass in). -const char* kSwitchArray[] = {kV, - kArgsFor, - // |kChildProcess| not for user use. - kContentHandlers, - kDisableCache, - kDontDeleteOnDownload, - kEnableMultiprocess, - kForceInProcess, - kHelp, - kMapOrigin, - kOrigin, - kPredictableAppFilenames, - kTraceStartup, - kURLMappings}; - -const std::set<std::string> GetAllSwitches() { - std::set<std::string> switch_set; - - for (size_t i = 0; i < arraysize(kSwitchArray); ++i) - switch_set.insert(kSwitchArray[i]); - return switch_set; -} - } // namespace switches diff --git a/mojo/shell/switches.h b/mojo/shell/switches.h index 52267fe..ff2eb6c 100644 --- a/mojo/shell/switches.h +++ b/mojo/shell/switches.h @@ -11,9 +11,7 @@ namespace switches { // All switches in alphabetical order. The switches should be documented -// alongside the definition of their values in the .cc file and, as needed, -// in mojo_main's Usage() function. -extern const char kArgsFor[]; +// alongside the definition of their values in the .cc file. extern const char kChildProcess[]; extern const char kContentHandlers[]; extern const char kDisableCache[]; @@ -25,9 +23,6 @@ extern const char kMapOrigin[]; extern const char kOrigin[]; extern const char kPredictableAppFilenames[]; extern const char kTraceStartup[]; -extern const char kURLMappings[]; - -extern const std::set<std::string> GetAllSwitches(); } // namespace switches diff --git a/mojo/shell/url_resolver_unittest.cc b/mojo/shell/url_resolver_unittest.cc index f959321..dd8da75 100644 --- a/mojo/shell/url_resolver_unittest.cc +++ b/mojo/shell/url_resolver_unittest.cc @@ -115,7 +115,6 @@ TEST_F(URLResolverTest, GetOriginMappings) { args.clear(); args.push_back(ARG_LITERAL("mojo_shell")); - args.push_back(ARG_LITERAL("--args-for=https://a.org/foo --test")); args.push_back(ARG_LITERAL("--map-origin=https://a.org=https://b.org/a")); args.push_back(ARG_LITERAL("--map-origin=https://b.org=https://c.org/b")); args.push_back(ARG_LITERAL("https://a.org/foo")); diff --git a/mojo/tools/android_mojo_shell.py b/mojo/tools/android_mojo_shell.py index d731afe..e269228 100755 --- a/mojo/tools/android_mojo_shell.py +++ b/mojo/tools/android_mojo_shell.py @@ -10,28 +10,10 @@ import sys from mopy.config import Config from mopy import android -USAGE = ("android_mojo_shell.py " - "[--args-for=<mojo-app>] " - "[--content-handlers=<handlers>] " - "[--enable-external-applications] " - "[--disable-cache] " - "[--enable-multiprocess] " - "[--url-mappings=from1=to1,from2=to2] " - "[<mojo-app>] " - """ - -A <mojo-app> is a Mojo URL or a Mojo URL and arguments within quotes. -Example: mojo_shell "mojo:js_standalone test.js". -<url-lib-path> is searched for shared libraries named by mojo URLs. -The value of <handlers> is a comma separated list like: -text/html,mojo:html_viewer,application/javascript,mojo:js_content_handler -""") - - def main(): logging.basicConfig() - parser = argparse.ArgumentParser(usage=USAGE) + parser = argparse.ArgumentParser("Helper for running mojo_shell") debug_group = parser.add_mutually_exclusive_group() debug_group.add_argument('--debug', help='Debug build (default)', |