Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: mojo/shell/desktop/mojo_main.cc

Issue 617943002: Enable setting configuration arguments for Mojo applications with mojo_shell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use base::string16 instead std::wstring Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/examples/wget/wget.cc ('k') | mojo/shell/switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_split.h"
11 #include "base/strings/utf_string_conversions.h"
10 #include "mojo/shell/child_process.h" 12 #include "mojo/shell/child_process.h"
11 #include "mojo/shell/context.h" 13 #include "mojo/shell/context.h"
12 #include "mojo/shell/init.h" 14 #include "mojo/shell/init.h"
13 #include "mojo/shell/switches.h" 15 #include "mojo/shell/switches.h"
14 16
15 #if defined(COMPONENT_BUILD) 17 #if defined(COMPONENT_BUILD)
16 #include "ui/gl/gl_surface.h" 18 #include "ui/gl/gl_surface.h"
17 #endif 19 #endif
18 20
19 namespace { 21 namespace {
20 22
21 #if defined(OS_LINUX) 23 #if defined(OS_LINUX)
22 // Copied from ui/gfx/switches.cc to avoid a dependency on //ui/gfx 24 // Copied from ui/gfx/switches.cc to avoid a dependency on //ui/gfx
23 const char kEnableHarfBuzzRenderText[] = "enable-harfbuzz-rendertext"; 25 const char kEnableHarfBuzzRenderText[] = "enable-harfbuzz-rendertext";
24 #endif 26 #endif
25 27
28 #if defined(OS_WIN)
29 void SplitString(const base::string16& str, std::vector<std::string>* argv) {
30 base::SplitString(base::UTF16ToUTF8(str), ' ', argv);
31 }
32 #elif defined(OS_POSIX)
33 void SplitString(const std::string& str, std::vector<std::string>* argv) {
34 base::SplitString(str, ' ', argv);
35 }
36 #endif
37
38 // The value of app_url_and_args is "<mojo_app_url> [<args>...]", where args
39 // is a list of "configuration" arguments separated by spaces. If one or more
40 // arguments are specified they will be available when the Mojo application
41 // is initialized. See ApplicationImpl::args().
42 GURL GetAppURLAndSetArgs(const base::CommandLine::StringType& app_url_and_args,
43 mojo::shell::Context* context) {
44 std::vector<std::string> argv;
45 SplitString(app_url_and_args, &argv);
46 if (argv.empty())
47 return GURL::EmptyGURL();
48 GURL app_url(argv[0]);
49 if (argv.size() > 1)
50 context->application_manager()->SetArgsForURL(argv, app_url);
51 return app_url;
52 }
53
26 void RunApps(mojo::shell::Context* context) { 54 void RunApps(mojo::shell::Context* context) {
27 const base::CommandLine& command_line = 55 const auto& command_line = *base::CommandLine::ForCurrentProcess();
28 *base::CommandLine::ForCurrentProcess(); 56 for (const auto& arg : command_line.GetArgs())
29 base::CommandLine::StringVector args = command_line.GetArgs(); 57 context->Run(GetAppURLAndSetArgs(arg, context));
30 for (base::CommandLine::StringVector::const_iterator it = args.begin();
31 it != args.end();
32 ++it) {
33 context->Run(GURL(*it));
34 }
35 } 58 }
36 59
37 } // namespace 60 } // namespace
38 61
39 int main(int argc, char** argv) { 62 int main(int argc, char** argv) {
40 base::AtExitManager at_exit; 63 base::AtExitManager at_exit;
41 base::CommandLine::Init(argc, argv); 64 base::CommandLine::Init(argc, argv);
42 #if defined(OS_LINUX) 65 #if defined(OS_LINUX)
43 // We use gfx::RenderText from multiple threads concurrently and the pango 66 // We use gfx::RenderText from multiple threads concurrently and the pango
44 // backend (currently the default on linux) is not close to threadsafe. Force 67 // backend (currently the default on linux) is not close to threadsafe. Force
(...skipping 19 matching lines...) Expand all
64 base::MessageLoop message_loop; 87 base::MessageLoop message_loop;
65 shell_context.Init(); 88 shell_context.Init();
66 89
67 const base::CommandLine& command_line = 90 const base::CommandLine& command_line =
68 *base::CommandLine::ForCurrentProcess(); 91 *base::CommandLine::ForCurrentProcess();
69 if (command_line.HasSwitch(switches::kOrigin)) { 92 if (command_line.HasSwitch(switches::kOrigin)) {
70 shell_context.mojo_url_resolver()->SetBaseURL( 93 shell_context.mojo_url_resolver()->SetBaseURL(
71 GURL(command_line.GetSwitchValueASCII(switches::kOrigin))); 94 GURL(command_line.GetSwitchValueASCII(switches::kOrigin)));
72 } 95 }
73 96
97 for (const auto& kv : command_line.GetSwitches()) {
98 if (kv.first == switches::kArgsFor)
99 GetAppURLAndSetArgs(kv.second, &shell_context);
100 }
101
74 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context)); 102 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context));
75 message_loop.Run(); 103 message_loop.Run();
76 } 104 }
77 } 105 }
78 return 0; 106 return 0;
79 } 107 }
OLDNEW
« no previous file with comments | « mojo/examples/wget/wget.cc ('k') | mojo/shell/switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698