summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorjeremya@chromium.org <jeremya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-15 06:24:32 +0000
committerjeremya@chromium.org <jeremya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-15 06:24:32 +0000
commitccfab591456e8c231a784823edcd560267bcb382 (patch)
tree7f083d4ba68a22f7b946d918c3cd2a97c4c5846e /base
parent289f05cc53e22a3073ffe1abc14d50f5bc258014 (diff)
downloadchromium_src-ccfab591456e8c231a784823edcd560267bcb382.zip
chromium_src-ccfab591456e8c231a784823edcd560267bcb382.tar.gz
chromium_src-ccfab591456e8c231a784823edcd560267bcb382.tar.bz2
Rearchitecting the 'app mode' code on mac for v2 apps.
A lot of the old code assumed an outdated model for v2 packaged apps on mac; specifically that they used to run in their own Chrome process with their own user data directory. This is no longer the case, and as such it's not possible to have apps running in their own process, because they need access to profile information from Chrome. This patch changes the code so that the 'app mode' .app bundles function more like shortcuts to open the app in an existing Chrome browser process (launching Chrome if it's not already running). This allows the app to be launched via Spotlight and the /Applications folder, and the user can e.g. drag the app onto the dock like a regular Mac application. There is as yet no way to trigger the shortcut creation code. BUG=168080 Review URL: https://chromiumcodereview.appspot.com/11737014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176803 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/mac/mac_util.h4
-rw-r--r--base/mac/mac_util.mm9
-rw-r--r--base/mac/mac_util_unittest.mm43
3 files changed, 56 insertions, 0 deletions
diff --git a/base/mac/mac_util.h b/base/mac/mac_util.h
index ff8b2b2..1a35b33 100644
--- a/base/mac/mac_util.h
+++ b/base/mac/mac_util.h
@@ -121,6 +121,10 @@ BASE_EXPORT bool WasLaunchedAsLoginOrResumeItem();
// 'Login Item' with 'hide on startup' flag. Used to suppress opening windows.
BASE_EXPORT bool WasLaunchedAsHiddenLoginItem();
+// Remove the quarantine xattr from the given file. Returns false if there was
+// an error, or true otherwise.
+BASE_EXPORT bool RemoveQuarantineAttribute(const FilePath& file_path);
+
// Run-time OS version checks. Use these instead of
// base::SysInfo::OperatingSystemVersionNumbers. Prefer the "OrEarlier" and
// "OrLater" variants to those that check for a specific version, unless you
diff --git a/base/mac/mac_util.mm b/base/mac/mac_util.mm
index 3263db1..a0fee53 100644
--- a/base/mac/mac_util.mm
+++ b/base/mac/mac_util.mm
@@ -6,8 +6,11 @@
#import <Cocoa/Cocoa.h>
#import <IOKit/IOKitLib.h>
+
+#include <errno.h>
#include <string.h>
#include <sys/utsname.h>
+#include <sys/xattr.h>
#include "base/file_path.h"
#include "base/logging.h"
@@ -484,6 +487,12 @@ bool WasLaunchedAsHiddenLoginItem() {
return IsHiddenLoginItem(item);
}
+bool RemoveQuarantineAttribute(const FilePath& file_path) {
+ const char kQuarantineAttrName[] = "com.apple.quarantine";
+ int status = removexattr(file_path.value().c_str(), kQuarantineAttrName, 0);
+ return status == 0 || errno == ENOATTR;
+}
+
namespace {
// Returns the running system's Darwin major version. Don't call this, it's
diff --git a/base/mac/mac_util_unittest.mm b/base/mac/mac_util_unittest.mm
index d69e077..3182948 100644
--- a/base/mac/mac_util_unittest.mm
+++ b/base/mac/mac_util_unittest.mm
@@ -16,6 +16,9 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
+#include <errno.h>
+#include <sys/xattr.h>
+
namespace base {
namespace mac {
@@ -206,6 +209,46 @@ TEST_F(MacUtilTest, ParseModelIdentifier) {
EXPECT_EQ(2, minor);
}
+TEST_F(MacUtilTest, TestRemoveQuarantineAttribute) {
+ ScopedTempDir temp_dir_;
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ FilePath dummy_folder_path = temp_dir_.path().Append("DummyFolder");
+ ASSERT_TRUE(file_util::CreateDirectory(dummy_folder_path));
+ const char* quarantine_str = "0000;4b392bb2;Chromium;|org.chromium.Chromium";
+ const char* file_path_str = dummy_folder_path.value().c_str();
+ EXPECT_EQ(0, setxattr(file_path_str, "com.apple.quarantine",
+ quarantine_str, strlen(quarantine_str), 0, 0));
+ EXPECT_EQ(static_cast<long>(strlen(quarantine_str)),
+ getxattr(file_path_str, "com.apple.quarantine",
+ NULL, 0, 0, 0));
+ EXPECT_TRUE(RemoveQuarantineAttribute(dummy_folder_path));
+ EXPECT_EQ(-1, getxattr(file_path_str, "com.apple.quarantine", NULL, 0, 0, 0));
+ EXPECT_EQ(ENOATTR, errno);
+}
+
+TEST_F(MacUtilTest, TestRemoveQuarantineAttributeTwice) {
+ ScopedTempDir temp_dir_;
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ FilePath dummy_folder_path = temp_dir_.path().Append("DummyFolder");
+ const char* file_path_str = dummy_folder_path.value().c_str();
+ ASSERT_TRUE(file_util::CreateDirectory(dummy_folder_path));
+ EXPECT_EQ(-1, getxattr(file_path_str, "com.apple.quarantine", NULL, 0, 0, 0));
+ // No quarantine attribute to begin with, but RemoveQuarantineAttribute still
+ // succeeds because in the end the folder still doesn't have the quarantine
+ // attribute set.
+ EXPECT_TRUE(RemoveQuarantineAttribute(dummy_folder_path));
+ EXPECT_TRUE(RemoveQuarantineAttribute(dummy_folder_path));
+ EXPECT_EQ(ENOATTR, errno);
+}
+
+TEST_F(MacUtilTest, TestRemoveQuarantineAttributeNonExistentPath) {
+ ScopedTempDir temp_dir_;
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ FilePath non_existent_path = temp_dir_.path().Append("DummyPath");
+ ASSERT_FALSE(file_util::PathExists(non_existent_path));
+ EXPECT_FALSE(RemoveQuarantineAttribute(non_existent_path));
+}
+
} // namespace
} // namespace mac