chrome_main_mac.mm 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "chrome/app/chrome_main_mac.h"
  5. #import <Cocoa/Cocoa.h>
  6. #include <string>
  7. #include "base/command_line.h"
  8. #include "base/files/file_path.h"
  9. #import "base/mac/bundle_locations.h"
  10. #import "base/mac/foundation_util.h"
  11. #include "base/path_service.h"
  12. #include "base/strings/string_util.h"
  13. #include "base/strings/sys_string_conversions.h"
  14. #include "chrome/common/chrome_constants.h"
  15. #include "chrome/common/chrome_paths_internal.h"
  16. #include "content/public/common/content_paths.h"
  17. #include "content/public/common/content_switches.h"
  18. void SetUpBundleOverrides() {
  19. @autoreleasepool {
  20. base::mac::SetOverrideFrameworkBundlePath(chrome::GetFrameworkBundlePath());
  21. NSBundle* base_bundle = chrome::OuterAppBundle();
  22. base::mac::SetBaseBundleID([[base_bundle bundleIdentifier] UTF8String]);
  23. base::FilePath child_exe_path =
  24. chrome::GetFrameworkBundlePath().Append("Helpers").Append(
  25. chrome::kHelperProcessExecutablePath);
  26. // On the Mac, the child executable lives at a predefined location within
  27. // the app bundle's versioned directory.
  28. base::PathService::Override(content::CHILD_PROCESS_EXE, child_exe_path);
  29. }
  30. }
  31. bool IsAlertsHelperLaunchedViaNotificationAction() {
  32. // We allow the main Chrome app to be launched via a notification action. We
  33. // detect and log that to UMA by checking the passed in NSNotification in
  34. // -applicationDidFinishLaunching: (//chrome/browser/app_controller_mac.mm).
  35. if (!base::mac::IsBackgroundOnlyProcess())
  36. return false;
  37. // If we have a process type then we were not launched by the system.
  38. if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType))
  39. return false;
  40. base::FilePath path;
  41. if (!base::PathService::Get(base::FILE_EXE, &path))
  42. return false;
  43. // Check if our executable name matches the helper app for notifications.
  44. std::string helper_name = path.BaseName().value();
  45. return base::EndsWith(helper_name, chrome::kMacHelperSuffixAlerts);
  46. }