Extract appid from AtomCommandLine and remove redundant code 98/191498/6
authork2.nagaraju <k2.nagaraju@samsung.com>
Wed, 17 Oct 2018 11:41:25 +0000 (17:11 +0530)
committerk2.nagaraju <k2.nagaraju@samsung.com>
Tue, 23 Oct 2018 06:13:20 +0000 (11:43 +0530)
In prelaunch atom commandLine initialized with |/usr/bin/wrt-loader|.
When actual application is loaded, its command line arguments are
appending to already existing command line parameters. That is the reason
argv[1] is returning appid. Clearing the commandline |argv_| vector in
|atom::AtomCommandLine::Init| before pushing the new command line arguments.

Removed the unused files.
Extract app id from atom command line and parse for base name.

Change-Id: Ia4945208186ffbbe82fb15ab67d4881f7ef5305c
Signed-off-by: k2.nagaraju <k2.nagaraju@samsung.com>
atom/app/atom_main.cc [deleted file]
atom/app/atom_main.h [deleted file]
atom/app/atom_main_delegate.cc
atom/browser/browser.cc
atom/common/atom_command_line.cc
atom/renderer/atom_renderer_client.cc
electron.gyp
filenames.gypi
tizen/common/command_line.cc [deleted file]
tizen/common/command_line.h [deleted file]
tizen/src/wrt_main.cc

diff --git a/atom/app/atom_main.cc b/atom/app/atom_main.cc
deleted file mode 100644 (file)
index c67500f..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-// Copyright (c) 2013 GitHub, Inc.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#include "atom/app/atom_main.h"
-
-#include <stdlib.h>
-
-#if defined(OS_WIN)
-#include <windows.h>  // windows.h must be included first
-
-#include <shellapi.h>
-#include <shellscalingapi.h>
-#include <tchar.h>
-
-#include "atom/app/atom_main_delegate.h"
-#include "atom/common/crash_reporter/win/crash_service_main.h"
-#include "base/environment.h"
-#include "base/process/launch.h"
-#include "base/win/windows_version.h"
-#include "content/public/app/sandbox_helper_win.h"
-#include "sandbox/win/src/sandbox_types.h"
-#elif defined(OS_LINUX)  // defined(OS_WIN)
-#include "atom/app/atom_main_delegate.h"  // NOLINT
-#include "content/public/app/content_main.h"
-#else  // defined(OS_LINUX)
-#include "atom/app/atom_library_main.h"
-#endif  // defined(OS_MACOSX)
-
-#if defined(USE_EFL)
-#include "efl/init.h"
-#endif
-
-#include "atom/app/node_main.h"
-#include "atom/common/atom_command_line.h"
-#include "base/at_exit.h"
-#include "base/i18n/icu_util.h"
-
-#if defined(OS_TIZEN)
-#include <Elementary.h>
-
-#include "atom/app/runtime.h"
-#include "base/logging.h"
-#include "tizen/common/application_data.h"
-#include "tizen/common/command_line.h"
-#include "tizen/loader/prelauncher.h"
-#endif
-
-namespace {
-
-const char* kRunAsNode = "ELECTRON_RUN_AS_NODE";
-
-// Default command line flags for all profiles and platforms
-const char* kDefaultCommandLineFlags[] = {
-  "allow-file-access-from-files",
-  "enable-tizen-app-container",
-};
-
-bool IsEnvSet(const char* name) {
-#if defined(OS_WIN)
-  size_t required_size;
-  getenv_s(&required_size, nullptr, 0, name);
-  return required_size != 0;
-#else
-  char* indicator = getenv(name);
-  return indicator && indicator[0] != '\0';
-#endif
-}
-
-}  // namespace
-
-#if defined(OS_WIN)
-int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
-  int argc = 0;
-  wchar_t** wargv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
-
-  bool run_as_node = IsEnvSet(kRunAsNode);
-
-  // Make sure the output is printed to console.
-  if (run_as_node || !IsEnvSet("ELECTRON_NO_ATTACH_CONSOLE"))
-    base::RouteStdioToConsole(false);
-
-  // Convert argv to to UTF8
-  char** argv = new char*[argc];
-  for (int i = 0; i < argc; i++) {
-    // Compute the size of the required buffer
-    DWORD size = WideCharToMultiByte(CP_UTF8,
-                                     0,
-                                     wargv[i],
-                                     -1,
-                                     NULL,
-                                     0,
-                                     NULL,
-                                     NULL);
-    if (size == 0) {
-      // This should never happen.
-      fprintf(stderr, "Could not convert arguments to utf8.");
-      exit(1);
-    }
-    // Do the actual conversion
-    argv[i] = new char[size];
-    DWORD result = WideCharToMultiByte(CP_UTF8,
-                                       0,
-                                       wargv[i],
-                                       -1,
-                                       argv[i],
-                                       size,
-                                       NULL,
-                                       NULL);
-    if (result == 0) {
-      // This should never happen.
-      fprintf(stderr, "Could not convert arguments to utf8.");
-      exit(1);
-    }
-  }
-
-  if (run_as_node) {
-    // Now that argv conversion is done, we can finally start.
-    base::AtExitManager atexit_manager;
-    base::i18n::InitializeICU();
-    return atom::NodeMain(argc, argv);
-  } else if (IsEnvSet("ELECTRON_INTERNAL_CRASH_SERVICE")) {
-    return crash_service::Main(cmd);
-  }
-
-  sandbox::SandboxInterfaceInfo sandbox_info = {0};
-  content::InitializeSandboxInfo(&sandbox_info);
-  atom::AtomMainDelegate delegate;
-
-  content::ContentMainParams params(&delegate);
-  params.instance = instance;
-  params.sandbox_info = &sandbox_info;
-  atom::AtomCommandLine::Init(argc, argv);
-  atom::AtomCommandLine::InitW(argc, wargv);
-  return content::ContentMain(params);
-}
-
-#elif defined(OS_LINUX)  // defined(OS_WIN)
-
-#if defined(OS_TIZEN)
-// For debug purpose only.
-// TODO: To be removed later
-bool hasTizenPackageID(int argc, const char* const* argv) {
-  if (argc > 3) {
-    if (0 == strncmp(argv[0], "/opt/usr/globalapps/", strlen("/opt/usr/globalapps/"))) {
-      return true;
-    }
-  }
-  return false;
-}
-
-int real_main(int argc, char* argv[]) {
-#else
-int main(int argc, char* argv[]) {
-#endif
-  if (IsEnvSet(kRunAsNode)) {
-    base::i18n::InitializeICU();
-    base::AtExitManager atexit_manager;
-    return atom::NodeMain(argc, const_cast<char**>(argv));
-  }
-
-#if defined(USE_EFL)
-  common::CommandLine::Init(argc, argv);
-  common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess();
-  std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/electron");
-
-  // load manifest
-  if (appid != "electron") { // TODO: Any better way to distinguish?
-    auto appdata_manager = common::ApplicationDataManager::GetInstance();
-    common::ApplicationData* appdata = appdata_manager->GetApplicationData(appid);
-    if (!appdata->LoadManifestData()) {
-      return false;
-    }
-  }
-
-  if (efl::Initialize(argc, const_cast<const char**>(argv)))
-    return 1;
-
-  // Add params for EFL port
-  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
-
-  static std::vector<char*> flags;
-  for (auto arg : kDefaultCommandLineFlags)
-    command_line->AppendSwitch(const_cast<char*>(arg));
-  efl::AppendPortParams(*command_line);
-#endif
-
-  atom::AtomMainDelegate delegate;
-  content::ContentMainParams params(&delegate);
-  params.argc = argc;
-  params.argv = const_cast<const char**>(argv);
-  atom::AtomCommandLine::Init(argc, argv);
-#if defined(OS_TIZEN)
-  if (hasTizenPackageID(argc,argv)) { // TODO: Check to be removed later
-    elm_init(argc, argv);
-    std::unique_ptr<runtime::Runtime> runtime = runtime::Runtime::MakeRuntime(&params);
-    return runtime->Exec();
-  }
-#endif
-  return content::ContentMain(params);
-}
-
-#if defined(OS_TIZEN)
-__attribute__((visibility("default")))
-int main(int argc, const char* argv[]) {
-  if (strcmp(argv[0], "/usr/bin/wrt-loader") == 0) {
-    LOG(INFO) << "run with wrt-loader";
-    auto preload = [argv](void) {
-    };
-    auto did_launch = [](const std::string& app_path) {
-    };
-    auto prelaunch = runtime::PreLauncher::Prelaunch;
-    return prelaunch(argc, const_cast<char**>(argv), preload, did_launch, real_main);
-  } else {
-    LOG(INFO) << "run without wrt-loader";
-    return real_main(argc, const_cast<char**>(argv));
-  }
-}
-#endif
-
-#else  // defined(OS_LINUX)
-
-int main(int argc, const char* argv[]) {
-  if (IsEnvSet(kRunAsNode)) {
-    return AtomInitializeICUandStartNode(argc, const_cast<char**>(argv));
-  }
-
-  return AtomMain(argc, argv);
-}
-
-#endif  // defined(OS_MACOSX)
diff --git a/atom/app/atom_main.h b/atom/app/atom_main.h
deleted file mode 100644 (file)
index 30663a4..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright (c) 2013 GitHub, Inc.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#ifndef ATOM_APP_ATOM_MAIN_H_
-#define ATOM_APP_ATOM_MAIN_H_
-
-#include "content/public/app/content_main.h"
-
-#endif  // ATOM_APP_ATOM_MAIN_H_
index 0358e7d..4bcafba 100644 (file)
@@ -26,7 +26,6 @@
 #include "ui/base/resource/resource_bundle.h"
 
 #if defined(OS_TIZEN)
-#include "tizen/common/command_line.h"
 #include "atom/common/atom_command_line.h"
 #endif
 
index 7313bb2..d429a0a 100644 (file)
@@ -21,7 +21,6 @@
 #include "content/public/browser/render_view_host.h"
 
 #if defined(OS_TIZEN)
-#include "tizen/common/command_line.h"
 #include "tizen/common/application_data.h"
 #include "tizen/src/browser/native_web_runtime.h"
 #include <Elementary.h>
index 4a5bfe9..4f74284 100644 (file)
@@ -5,6 +5,7 @@
 #include "atom/common/atom_command_line.h"
 
 #include "base/command_line.h"
+#include "common/file_utils.h"
 #include "node/deps/uv/include/uv.h"
 
 namespace atom {
@@ -20,6 +21,7 @@ std::vector<std::wstring> AtomCommandLine::wargv_;
 // static
 void AtomCommandLine::Init(int argc, const char* const* argv) {
   // Hack around with the argv pointer. Used for process.title = "blah"
+  argv_.clear();
   argc_ = argc;
   char** new_argv = uv_setup_args(argc, const_cast<char**>(argv));
   for (int i = 0; i < argc; ++i) {
@@ -45,7 +47,7 @@ void AtomCommandLine::InitializeFromCommandLine() {
 
 std::string AtomCommandLine::GetAppIdFromCommandLine(const std::string& program) {
   if (argc_ > 0) {
-    std::string tmp = argv_[0];
+    std::string tmp = common::utils::BaseName(argv_[0]);
     if (tmp == program) {
       if (argv_.size() > 0) {
         // Suppose that appid is at the first of arguments_
@@ -58,5 +60,4 @@ std::string AtomCommandLine::GetAppIdFromCommandLine(const std::string& program)
   return std::string();
 }
 
-
 }  // namespace atom
index 7fa37d4..889ad73 100644 (file)
@@ -84,7 +84,11 @@ void AtomRendererClient::RenderThreadStarted() {
   base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
   base::CommandLine::StringVector argv = command_line->argv();
   const char** c_argv = StringVectorToArgArray(argv);
-  atom::AtomCommandLine::Init(argv.size(), c_argv);
+
+  // In case of tizen apps AtomCommandLine already initialized in |real_main|.
+  if (!::tizen::is_single_process)
+    atom::AtomCommandLine::Init(argv.size(), c_argv);
+
   std::string tizen_app_id = command_line->GetSwitchValueASCII(
       "widget-id");
 
index ce3673a..c80b10b 100644 (file)
         'app2asar',
         '<(project_name)_lib',
       ],
-      'sources': [
-        '<@(app_sources)',
-      ],
       'include_dirs': [
         '.',
       ],
       'conditions': [
+        ['is_tizen==0', {
+          'sources': [
+            '<@(app_sources)',
+          ],
+        }],
         ['OS=="mac"', {
           'product_name': '<(product_name)',
           'mac_bundle': 1,
index b7bb9a8..7d1e999 100644 (file)
@@ -1,9 +1,5 @@
 {
   'variables': {
-    'app_sources': [
-      'atom/app/atom_main.cc',
-      'atom/app/atom_main.h',
-    ],
     'bundle_sources': [
       'atom/browser/resources/mac/electron.icns',
     ],
diff --git a/tizen/common/command_line.cc b/tizen/common/command_line.cc
deleted file mode 100644 (file)
index ecf6d3c..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-
-#include "common/command_line.h"
-
-#include <cstring>
-
-#include "common/file_utils.h"
-
-namespace common {
-
-namespace {
-
-const char* kOptionPrefix = "--";
-const char* kOptionValueSeparator = "=";
-
-static bool IsValidOptionString(const char* argument) {
-  if (NULL != argument &&
-      strncmp(argument, kOptionPrefix, strlen(kOptionPrefix)) == 0) {
-    return true;
-  } else {
-    return false;
-  }
-}
-
-}  // namespace
-
-CommandLine* CommandLine::current_process_commandline_ = NULL;
-
-CommandLine::CommandLine(int argc, char* argv[]) : argc_(argc), argv_(argv) {
-  // Append option or push each arg(not option) into arguments_
-  for (int i = 1; i < argc; ++i) {
-    if (IsValidOptionString(argv[i])) {
-      AppendOption(argv[i]);
-    } else {
-      arguments_.push_back(argv[i]);
-    }
-  }
-
-  // Parse program name and appid from argv_ or arguments_
-  program_ = std::string(argv[0]);
-}
-
-CommandLine::~CommandLine() {}
-
-void CommandLine::AppendOption(const char* value) {
-  std::string option_string(value);
-  std::string option_name;
-  std::string option_value;
-
-  int value_separator_pos =
-      option_string.find(kOptionValueSeparator, strlen(kOptionPrefix));
-  if (value_separator_pos >= 0) {
-    int substr_len = value_separator_pos - strlen(kOptionPrefix);
-    option_name = option_string.substr(strlen(kOptionPrefix), substr_len);
-    option_value = option_string.substr(value_separator_pos + 1);
-  } else {
-    option_name =
-        option_string.substr(strlen(kOptionPrefix), value_separator_pos);
-  }
-
-  options_[option_name] = option_value;
-}
-
-bool CommandLine::HasOptionName(const std::string& option_name) {
-  return (options_.find(option_name) != options_.end());
-}
-
-std::string CommandLine::GetOptionValue(const std::string& option_name) {
-  if (HasOptionName(option_name)) {
-    return options_[option_name];
-  } else {
-    return std::string();
-  }
-}
-
-std::string CommandLine::GetCommandString() {
-  std::string result;
-  result.append(program_);
-  result.append(" ");
-  for (auto& it : options_) {
-    result.append(kOptionPrefix);
-    result.append(it.first);
-    if (!it.second.empty()) {
-      result.append(kOptionValueSeparator);
-      result.append(it.second);
-    }
-    result.append(" ");
-  }
-  for (auto& it : arguments_) {
-    result.append(it);
-    result.append(" ");
-  }
-  return result;
-}
-
-std::string CommandLine::GetAppIdFromCommandLine(const std::string& program) {
-  if (argc_ > 0) {
-    std::string tmp = utils::BaseName(program_);
-    if (tmp == program) {
-      if (arguments_.size() > 0) {
-        // Suppose that appid is at the first of arguments_
-        return arguments_[0];
-      }
-    } else {
-      return tmp;
-    }
-  }
-  return std::string();
-}
-
-// static
-void CommandLine::Reset() {
-  if (!!current_process_commandline_) {
-    delete current_process_commandline_;
-    current_process_commandline_ = NULL;
-  }
-}
-
-// static
-bool CommandLine::Init(int argc, char* argv[]) {
-  if (!current_process_commandline_) {
-    current_process_commandline_ = new CommandLine(argc, argv);
-    return true;
-  }
-  return false;
-}
-
-// static
-CommandLine* CommandLine::ForCurrentProcess() {
-  return current_process_commandline_;
-}
-
-}  // namespace common
diff --git a/tizen/common/command_line.h b/tizen/common/command_line.h
deleted file mode 100644 (file)
index 1c7bae0..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-
-#ifndef XWALK_COMMON_COMMAND_LINE_H_
-#define XWALK_COMMON_COMMAND_LINE_H_
-
-#include <map>
-#include <string>
-#include <vector>
-
-namespace common {
-
-class CommandLine {
- public:
-  // CommandLine only uses long options
-  typedef std::map<std::string, std::string> OptionMap;
-  // Arguments which except for option strings
-  typedef std::vector<std::string> Arguments;
-
-  static bool Init(int argc, char* argv[]);
-  static CommandLine* ForCurrentProcess();
-  static void Reset();
-
-  // Test if options_ has 'option_name'
-  bool HasOptionName(const std::string& option_name);
-  // Get the option's value
-  std::string GetOptionValue(const std::string& option_name);
-  // Get command string include options and arguments
-  std::string GetCommandString();
-
-  std::string GetAppIdFromCommandLine(const std::string& program);
-
-  std::string program() const { return program_; }
-  const OptionMap& options() const { return options_; }
-  const Arguments& arguments() const { return arguments_; }
-  char** argv() const { return argv_; }
-  int argc() const { return argc_; }
-
- private:
-  CommandLine(int argc, char* argv[]);
-  virtual ~CommandLine();
-
-  void AppendOption(const char* value);
-
-  // The singleton CommandLine instance of current process
-  static CommandLine* current_process_commandline_;
-
-  std::string program_;
-  OptionMap options_;
-  Arguments arguments_;
-  int argc_;
-  char** argv_;
-};
-
-}  // namespace common
-
-#endif  // XWALK_COMMON_COMMAND_LINE_H_
index 87fd3e8..41141ea 100644 (file)
@@ -67,7 +67,6 @@ int real_main(int argc, char* argv[]) {
   content::ContentMainParams params(&g_delegate);
   params.argc = argc;
   params.argv = const_cast<const char**>(argv);
-  atom::AtomCommandLine::Init(argc, argv);
 
   if (is_browser_process) {
     auto app_data = common::ApplicationDataManager::GetCurrentAppData();