]> khamidou — GitHub mirrors - electron.git/commitdiff
mac: Force using "Atom" as application name in framework bundle path.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 12 Sep 2013 09:51:45 +0000 (17:51 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 12 Sep 2013 09:51:45 +0000 (17:51 +0800)
app/atom_main_delegate.cc
app/atom_main_delegate.h
app/atom_main_delegate_mac.mm [new file with mode: 0644]
atom.gyp

index f868e270c2b805c273c6a82a27c37a7cded3192e..fbb85f94d21e71c0c1e2d257dc8ba56a09d0e971 100644 (file)
@@ -9,27 +9,7 @@
 #include "browser/atom_browser_client.h"
 #include "content/public/common/content_switches.h"
 #include "renderer/atom_renderer_client.h"
-
-#if defined(OS_MACOSX)
-
-#include "base/mac/bundle_locations.h"
-#include "base/path_service.h"
-#include "content/public/common/content_paths.h"
-
-namespace brightray {
-base::FilePath MainApplicationBundlePath();
-}
-
-namespace {
-
-base::FilePath GetFrameworksPath() {
-  return brightray::MainApplicationBundlePath().Append("Contents")
-                                               .Append("Frameworks");
-}
-
-}  // namespace
-
-#endif  // defined(OS_MACOSX)
+#include "ui/base/resource/resource_bundle.h"
 
 namespace atom {
 
@@ -59,23 +39,31 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
 }
 
 void AtomMainDelegate::PreSandboxStartup() {
-  brightray::MainDelegate::PreSandboxStartup();
-
 #if defined(OS_MACOSX)
-  // Override the path to helper process, since third party users may want to
-  // change the application name.
-  base::FilePath helper_path = GetFrameworksPath().Append("Atom Helper.app")
-                                                  .Append("Contents")
-                                                  .Append("MacOS")
-                                                  .Append("Atom Helper");
-  PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
-#endif  // defined(OS_MACOSX)
+  OverrideChildProcessPath();
+  OverrideFrameworkBundlePath();
+  SetProcessName();
+#endif
+  InitializeResourceBundle();
 
   // Disable renderer sandbox for most of node's functions.
   CommandLine* command_line = CommandLine::ForCurrentProcess();
   command_line->AppendSwitch(switches::kNoSandbox);
 }
 
+void AtomMainDelegate::InitializeResourceBundle() {
+  base::FilePath path;
+#if defined(OS_MACOSX)
+  path = GetResourcesPakFilePath();
+#else
+  base::FilePath pak_dir;
+  PathService::Get(base::DIR_MODULE, &pak_dir);
+  path = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak"));
+#endif
+
+  ui::ResourceBundle::InitSharedInstanceWithPakPath(path);
+}
+
 content::ContentBrowserClient* AtomMainDelegate::CreateContentBrowserClient() {
   browser_client_.reset(new AtomBrowserClient);
   return browser_client_.get();
index 4a1f7921da6832264f7aec27da8ec1e29989ac00..1b2a85304309d4e5e7ccd4748bd4314a7188a2ea 100644 (file)
@@ -17,6 +17,14 @@ class AtomMainDelegate : public brightray::MainDelegate {
  protected:
   virtual bool BasicStartupComplete(int* exit_code) OVERRIDE;
   virtual void PreSandboxStartup() OVERRIDE;
+  virtual void InitializeResourceBundle();
+
+#if defined(OS_MACOSX)
+  virtual base::FilePath GetResourcesPakFilePath();
+  virtual void OverrideChildProcessPath();
+  virtual void OverrideFrameworkBundlePath();
+  virtual void SetProcessName();
+#endif
 
  private:
   virtual content::ContentBrowserClient* CreateContentBrowserClient() OVERRIDE;
diff --git a/app/atom_main_delegate_mac.mm b/app/atom_main_delegate_mac.mm
new file mode 100644 (file)
index 0000000..e2073df
--- /dev/null
@@ -0,0 +1,66 @@
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "app/atom_main_delegate.h"
+
+#import "base/mac/bundle_locations.h"
+#import "base/mac/foundation_util.h"
+#import "base/mac/mac_util.h"
+#include "base/command_line.h"
+#include "base/path_service.h"
+#include "base/strings/sys_string_conversions.h"
+#include "content/public/common/content_paths.h"
+#include "content/public/common/content_switches.h"
+#include "vendor/brightray/common/application_info.h"
+#include "vendor/brightray/common/mac/main_application_bundle.h"
+
+namespace atom {
+
+namespace {
+
+base::FilePath GetFrameworksPath() {
+  return brightray::MainApplicationBundlePath().Append("Contents")
+                                               .Append("Frameworks");
+}
+
+}  // namespace
+
+base::FilePath AtomMainDelegate::GetResourcesPakFilePath() {
+  NSString* path = [base::mac::FrameworkBundle()
+      pathForResource:@"content_shell" ofType:@"pak"];
+  return base::mac::NSStringToFilePath(path);
+}
+
+void AtomMainDelegate::OverrideFrameworkBundlePath() {
+  base::mac::SetOverrideFrameworkBundlePath(
+      GetFrameworksPath().Append("Atom.framework"));
+}
+
+void AtomMainDelegate::OverrideChildProcessPath() {
+  base::FilePath helper_path = GetFrameworksPath().Append("Atom Helper.app")
+                                                  .Append("Contents")
+                                                  .Append("MacOS")
+                                                  .Append("Atom Helper");
+  PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
+}
+
+void AtomMainDelegate::SetProcessName() {
+  const auto& command_line = *CommandLine::ForCurrentProcess();
+  auto process_type = command_line.GetSwitchValueASCII(switches::kProcessType);
+  std::string suffix;
+  if (process_type == switches::kRendererProcess)
+    suffix = "Renderer";
+  else if (process_type == switches::kPluginProcess ||
+           process_type == switches::kPpapiPluginProcess)
+    suffix = "Plug-In Host";
+  else if (process_type == switches::kUtilityProcess)
+    suffix = "Utility";
+  else
+    return;
+
+  base::mac::SetProcessName(base::mac::NSToCFCast(base::SysUTF8ToNSString(
+      brightray::GetApplicationName() + " " + suffix)));
+}
+
+}  // namespace atom
index 9d0d20b7cc074d722130a1476b3f3b67391e39c1..4d0bab4a5aa00927253d9178361152b080c44ebf 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
@@ -33,6 +33,7 @@
     'lib_sources': [
       'app/atom_main_delegate.cc',
       'app/atom_main_delegate.h',
+      'app/atom_main_delegate_mac.mm',
       'browser/api/atom_api_app.cc',
       'browser/api/atom_api_app.h',
       'browser/api/atom_api_auto_updater.cc',