From fe35a92de51776a6b2bd5ad6c6ec3292c72a6a53 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 14 Mar 2013 13:05:01 -0400 Subject: [PATCH] Get the linen background painting during elastic scrolling We weren't setting the location of the resource bundle correctly in the renderer process. It turns out base::mac::OuterBundle() returns the helper app's bundle in the renderer process. So now we have MainApplicationBundle() to give us the bundle of the main app. --- brightray/brightray.gyp | 2 + brightray/common/application_name_mac.mm | 5 ++- .../common/mac/main_application_bundle.h | 20 +++++++++ .../common/mac/main_application_bundle.mm | 42 +++++++++++++++++++ brightray/common/main_delegate_mac.mm | 20 +-------- 5 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 brightray/common/mac/main_application_bundle.h create mode 100644 brightray/common/mac/main_application_bundle.mm diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index f233b9e7bb..2a776b24fa 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -47,6 +47,8 @@ 'common/application_name_mac.mm', 'common/content_client.cc', 'common/content_client.h', + 'common/mac/main_application_bundle.h', + 'common/mac/main_application_bundle.mm', 'common/main_delegate.cc', 'common/main_delegate.h', 'common/main_delegate_mac.mm', diff --git a/brightray/common/application_name_mac.mm b/brightray/common/application_name_mac.mm index 48bac02b6f..eecccefd3f 100644 --- a/brightray/common/application_name_mac.mm +++ b/brightray/common/application_name_mac.mm @@ -1,12 +1,13 @@ #import "common/application_name.h" -#import "base/mac/bundle_locations.h" +#import "common/mac/main_application_bundle.h" + #import "base/mac/foundation_util.h" namespace brightray { std::string GetApplicationName() { - return [[base::mac::OuterBundle().infoDictionary objectForKey:base::mac::CFToNSCast(kCFBundleNameKey)] UTF8String]; + return [[MainApplicationBundle().infoDictionary objectForKey:base::mac::CFToNSCast(kCFBundleNameKey)] UTF8String]; } } diff --git a/brightray/common/mac/main_application_bundle.h b/brightray/common/mac/main_application_bundle.h new file mode 100644 index 0000000000..61f19adadd --- /dev/null +++ b/brightray/common/mac/main_application_bundle.h @@ -0,0 +1,20 @@ +#ifndef BRIGHTRAY_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_ +#define BRIGHTRAY_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_ + +@class NSBundle; + +namespace base { +class FilePath; +} + +namespace brightray { + +// The "main" application bundle is the outermost bundle for this logical application. E.g., if you +// have MyApp.app and MyApp.app/Contents/Frameworks/MyApp Helper.app, the main application bundle is +// MyApp.app, no matter which executable is currently running. +NSBundle* MainApplicationBundle(); +base::FilePath MainApplicationBundlePath(); + +} + +#endif diff --git a/brightray/common/mac/main_application_bundle.mm b/brightray/common/mac/main_application_bundle.mm new file mode 100644 index 0000000000..14173241e8 --- /dev/null +++ b/brightray/common/mac/main_application_bundle.mm @@ -0,0 +1,42 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2013 Adam Roben . All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#import "common/mac/main_application_bundle.h" + +#import "base/files/file_path.h" +#import "base/mac/foundation_util.h" +#import "base/path_service.h" + +namespace brightray { + +base::FilePath MainApplicationBundlePath() { + // Start out with the path to the running executable. + base::FilePath path; + PathService::Get(base::FILE_EXE, &path); + + // Up to Contents. + if (base::mac::IsBackgroundOnlyProcess()) { + // The running executable is the helper. Go up five steps: + // Contents/Frameworks/Helper.app/Contents/MacOS/Helper + // ^ to here ^ from here + path = path.DirName().DirName().DirName().DirName().DirName(); + } else { + // One step up to MacOS, another to Contents. + path = path.DirName().DirName(); + } + DCHECK_EQ(path.BaseName().value(), "Contents"); + + // Up one more level to the .app. + path = path.DirName(); + DCHECK_EQ(path.BaseName().Extension(), ".app"); + + return path; +} + +NSBundle* MainApplicationBundle() { + return [NSBundle bundleWithPath:base::mac::FilePathToNSString(MainApplicationBundlePath())]; +} + +} diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm index e8dd7f1d97..ec04e0f170 100644 --- a/brightray/common/main_delegate_mac.mm +++ b/brightray/common/main_delegate_mac.mm @@ -6,6 +6,7 @@ #import "main_delegate.h" #include "common/application_name.h" +#include "common/mac/main_application_bundle.h" #include "base/mac/bundle_locations.h" #include "base/mac/foundation_util.h" @@ -18,24 +19,7 @@ namespace brightray { namespace { base::FilePath GetFrameworksPath() { - // Start out with the path to the running executable. - base::FilePath path; - PathService::Get(base::FILE_EXE, &path); - - // Up to Contents. - if (base::mac::IsBackgroundOnlyProcess()) { - // The running executable is the helper. Go up five steps: - // Contents/Frameworks/Helper.app/Contents/MacOS/Helper - // ^ to here ^ from here - path = path.DirName().DirName().DirName().DirName().DirName(); - } else { - // One step up to MacOS, another to Contents. - path = path.DirName().DirName(); - } - DCHECK_EQ(path.BaseName().value(), "Contents"); - - // Go into the frameworks directory. - return path.Append("Frameworks"); + return MainApplicationBundlePath().Append("Contents").Append("Frameworks"); } }