diff options
author | jeremya@chromium.org <jeremya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-15 06:24:32 +0000 |
---|---|---|
committer | jeremya@chromium.org <jeremya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-15 06:24:32 +0000 |
commit | ccfab591456e8c231a784823edcd560267bcb382 (patch) | |
tree | 7f083d4ba68a22f7b946d918c3cd2a97c4c5846e /chrome/browser/web_applications | |
parent | 289f05cc53e22a3073ffe1abc14d50f5bc258014 (diff) | |
download | chromium_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 'chrome/browser/web_applications')
-rw-r--r-- | chrome/browser/web_applications/web_app_mac.mm | 6 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_mac_unittest.mm | 39 |
2 files changed, 37 insertions, 8 deletions
diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm index cdd342c..be02bc5 100644 --- a/chrome/browser/web_applications/web_app_mac.mm +++ b/chrome/browser/web_applications/web_app_mac.mm @@ -123,6 +123,8 @@ bool WebAppShortcutCreator::CreateShortcut() { return false; } + dst_path = dst_path.Append(app_file_name); + base::mac::RemoveQuarantineAttribute(dst_path); RevealGeneratedBundleInFinder(dst_path); return true; @@ -187,8 +189,8 @@ bool WebAppShortcutCreator::UpdatePlist(const FilePath& app_path) const { forKey:base::mac::CFToNSCast(kCFBundleIdentifierKey)]; [plist setObject:base::mac::FilePathToNSString(user_data_dir_) forKey:app_mode::kCrAppModeUserDataDirKey]; - [plist setObject:base::mac::FilePathToNSString(info_.extension_path) - forKey:app_mode::kCrAppModeExtensionPathKey]; + [plist setObject:base::mac::FilePathToNSString(info_.profile_path.BaseName()) + forKey:app_mode::kCrAppModeProfileDirKey]; return [plist writeToFile:plist_path atomically:YES]; } diff --git a/chrome/browser/web_applications/web_app_mac_unittest.mm b/chrome/browser/web_applications/web_app_mac_unittest.mm index 6a7efd6..575eafc 100644 --- a/chrome/browser/web_applications/web_app_mac_unittest.mm +++ b/chrome/browser/web_applications/web_app_mac_unittest.mm @@ -6,6 +6,9 @@ #import <Cocoa/Cocoa.h> +#include <sys/xattr.h> +#include <errno.h> + #include "base/file_util.h" #include "base/files/scoped_temp_dir.h" #include "base/mac/foundation_util.h" @@ -45,6 +48,7 @@ ShellIntegration::ShortcutInfo GetShortcutInfo() { info.extension_path = FilePath("/fake/extension/path"); info.title = ASCIIToUTF16("Shortcut Title"); info.url = GURL("http://example.com/"); + info.profile_path = FilePath("Default"); return info; } @@ -52,19 +56,18 @@ ShellIntegration::ShortcutInfo GetShortcutInfo() { namespace web_app { -// This test is disabled for the following reasons: -// * The plist still isn't filled in correctly. -// * WebAppShortcutCreator::CreateShortcut() opens a Finder window which it -// shouldn't be doing when run from a unit test. TEST(WebAppShortcutCreatorTest, CreateShortcut) { base::ScopedTempDir scoped_temp_dir; EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); - FilePath dst_path = scoped_temp_dir.path().Append("a.app"); ShellIntegration::ShortcutInfo info = GetShortcutInfo(); + + FilePath dst_folder = scoped_temp_dir.path(); + FilePath dst_path = dst_folder.Append(UTF16ToUTF8(info.title) + ".app"); + NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) - .WillRepeatedly(Return(dst_path)); + .WillRepeatedly(Return(dst_folder)); EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path)); EXPECT_TRUE(shortcut_creator.CreateShortcut()); @@ -91,6 +94,30 @@ TEST(WebAppShortcutCreatorTest, CreateShortcut) { } } +TEST(WebAppShortcutCreatorTest, RunShortcut) { + base::ScopedTempDir scoped_temp_dir; + EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); + + ShellIntegration::ShortcutInfo info = GetShortcutInfo(); + + FilePath dst_folder = scoped_temp_dir.path(); + dst_folder = FilePath("/Applications"); + FilePath dst_path = dst_folder.Append(UTF16ToUTF8(info.title) + ".app"); + + NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); + EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) + .WillRepeatedly(Return(dst_folder)); + EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path)); + + EXPECT_TRUE(shortcut_creator.CreateShortcut()); + EXPECT_TRUE(file_util::PathExists(dst_path)); + + ssize_t status = getxattr( + dst_path.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0); + EXPECT_EQ(-1, status); + EXPECT_EQ(ENOATTR, errno); +} + TEST(WebAppShortcutCreatorTest, CreateFailure) { NiceMock<WebAppShortcutCreatorMock> shortcut_creator(GetShortcutInfo()); EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) |