1 // Copyright 2010-2018, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 //     * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //     * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 //     * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 #ifndef MOZC_BASE_MAC_UTIL_H_
31 #define MOZC_BASE_MAC_UTIL_H_
32 
33 #ifdef OS_MACOSX
34 #include <string>
35 #include "base/port.h"
36 
37 namespace mozc {
38 class MacUtil {
39  public:
40   // Returns the label commonly used in the project for specified suffix.
41   static string GetLabelForSuffix(const string &suffix);
42 
43   // Returns (basically) "~/Library/Application Support".
44   static string GetApplicationSupportDirectory();
45 
46   // Returns (basically) "~/Library/Caches".
47   static string GetCachesDirectory();
48 
49   // Returns (basically) ~/Library/Logs
50   static string GetLoggingDirectory();
51 
52   // Returns OS version string like, "Version 10.x (Build xXxxx)".
53   static string GetOSVersionString();
54 
55   // Returns server directory using OS-specific API.
56   static string GetServerDirectory();
57 
58   // Returns the "Resouces/" directory in the current application.
59   static string GetResourcesDirectory();
60 
61   // Returns the machine serial number.
62   static string GetSerialNumber();
63 
64   // Starts the specified service by using launchd.  "service_name" is
65   // a suffix for the service label (like "Converter" or "Renderer").
66   // If "pid" is non-null, it will store the pid of the launched
67   // process in it.  Returns true if it successfully launches the
68   // process.
69   static bool StartLaunchdService(const string &service_name,
70                                   pid_t *pid);
71 
72   // Checks if the prelauncher is set in "Login Item".
73   static bool CheckPrelauncherLoginItemStatus();
74 
75   // Removes the prelauncher from "Login Item".
76   static void RemovePrelauncherLoginItem();
77 
78   // Adds the prelauncher to "Login Item"
79   static void AddPrelauncherLoginItem();
80 
81   // Gets the name and the owner name of the frontmost window.
82   // Returns false if an error occurred.
83   static bool GetFrontmostWindowNameAndOwner(string *name, string *owner);
84 
85   // Returns true when Mozc's suggestion UI is expected to be surpressed on
86   // the window specified by |name| and |owner|.
87   static bool IsSuppressSuggestionWindow(const string &name,
88                                          const string &owner);
89 
90  private:
MacUtil()91   MacUtil() {}
~MacUtil()92   ~MacUtil() {}
93 };
94 }  // namespace mozc
95 
96 #endif  // OS_MACOSX
97 #endif  // MOZC_BASE_MAC_UTIL_H_
98