mojo_js_standalone will quit after the last JSApp quits

I've also changed mojo_shell so that extra spaces in between app configuration arguments aren't turned into empty strings.

BUG=420243

Review URL: https://codereview.chromium.org/627093002

Cr-Commit-Position: refs/heads/master@{#298917}


CrOS-Libchrome-Original-Commit: b5334e7a527563ab6e96704325f8b5d53d8d791c
diff --git a/mojo/apps/js/application_delegate_impl.cc b/mojo/apps/js/application_delegate_impl.cc
index eb784a9..90495a3 100644
--- a/mojo/apps/js/application_delegate_impl.cc
+++ b/mojo/apps/js/application_delegate_impl.cc
@@ -37,6 +37,8 @@
       std::find(app_vector_.begin(), app_vector_.end(), app);
   if (itr != app_vector_.end())
     app_vector_.erase(itr);
+  if (app_vector_.empty())
+    base::MessageLoop::current()->QuitWhenIdle();
 }
 
 void ApplicationDelegateImpl::ConnectToService(
diff --git a/mojo/apps/js/js_app.h b/mojo/apps/js/js_app.h
index 6bbaed4..9eaedc6 100644
--- a/mojo/apps/js/js_app.h
+++ b/mojo/apps/js/js_app.h
@@ -30,7 +30,6 @@
   // This method causes Load() and then Run() to run on a new thread.
   bool Start();
 
-
   // Subclasses must return the JS source code for this app's main script and
   // the filename or URL that identifies the script's origin. This method will
   // be called from this app's thread.
diff --git a/mojo/shell/desktop/mojo_main.cc b/mojo/shell/desktop/mojo_main.cc
index 0331d3e..69b6e1d 100644
--- a/mojo/shell/desktop/mojo_main.cc
+++ b/mojo/shell/desktop/mojo_main.cc
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+#include <algorithm>
+
 #include "base/at_exit.h"
 #include "base/bind.h"
 #include "base/command_line.h"
@@ -35,14 +37,21 @@
 }
 #endif
 
+bool is_empty(const std::string& s) {
+  return s.empty();
+}
+
 // 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. See ApplicationImpl::args().
 GURL GetAppURLAndSetArgs(const base::CommandLine::StringType& app_url_and_args,
                          mojo::shell::Context* context) {
+  // SplitString() returns empty strings for extra delimeter characters (' ').
   std::vector<std::string> argv;
   SplitString(app_url_and_args, &argv);
+  argv.erase(std::remove_if(argv.begin(), argv.end(), is_empty), argv.end());
+
   if (argv.empty())
     return GURL::EmptyGURL();
   GURL app_url(argv[0]);