Remove some ScopedNSAutoreleasePool usage.
This touches a lot of ancient code that trips the presubmit, so skip the presubmit. BUG=772489 Change-Id: Ifea8ca3bd1ebb92eaa47421a6000ae70a25fe3e5 No-Presubmit: true Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1783211 Commit-Queue: Avi Drissman <avi@chromium.org> Reviewed-by: Nico Weber <thakis@chromium.org> Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org> Reviewed-by: Yuwei Huang <yuweih@chromium.org> Reviewed-by: Miguel Casas <mcasas@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/master@{#694364}
This commit is contained in:
base
ios
mac
bind_objc_block_unittest.mmfoundation_util_unittest.mmobjc_release_properties_unittest.mmscoped_nsautorelease_pool.hscoped_nsobject.hscoped_nsobject_unittest.mm
system
test
chrome
app
app_shim
browser
common
test
tools
build
components
content
browser
renderer_host
common
printing
remoting
rlz/mac/lib
services
ui
base
test
views
controls
test
widget
@ -5,7 +5,6 @@
|
||||
#import "base/ios/crb_protocol_observers.h"
|
||||
#include "base/ios/weak_nsobject.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "testing/gtest_mac.h"
|
||||
@ -122,11 +121,10 @@ TEST_F(CRBProtocolObserversTest, WeakReference) {
|
||||
|
||||
[observers_ addObserver:partial_observer_];
|
||||
|
||||
{
|
||||
// Need an autorelease pool here, because
|
||||
// -[CRBProtocolObservers forwardInvocation:] creates a temporary
|
||||
// autoreleased array that holds all the observers.
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
// Need an autorelease pool here, because
|
||||
// -[CRBProtocolObservers forwardInvocation:] creates a temporary
|
||||
// autoreleased array that holds all the observers.
|
||||
@autoreleasepool {
|
||||
[observers_ requiredMethod];
|
||||
EXPECT_TRUE([partial_observer_ requiredMethodInvoked]);
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include "base/ios/weak_nsobject.h"
|
||||
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
|
||||
namespace {
|
||||
@ -34,23 +33,24 @@ WeakContainer::~WeakContainer() {}
|
||||
+ (scoped_refptr<base::WeakContainer>)containerForObject:(id)object {
|
||||
if (object == nil)
|
||||
return nullptr;
|
||||
// The autoreleasePool is needed here as the call to objc_getAssociatedObject
|
||||
// The autoreleasepool is needed here as the call to objc_getAssociatedObject
|
||||
// returns an autoreleased object which is better released sooner than later.
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
CRBWeakNSProtocolSentinel* sentinel =
|
||||
objc_getAssociatedObject(object, &sentinelObserverKey_);
|
||||
if (!sentinel) {
|
||||
base::scoped_nsobject<CRBWeakNSProtocolSentinel> newSentinel(
|
||||
[[CRBWeakNSProtocolSentinel alloc]
|
||||
initWithContainer:new base::WeakContainer(object)]);
|
||||
sentinel = newSentinel;
|
||||
objc_setAssociatedObject(object, &sentinelObserverKey_, sentinel,
|
||||
OBJC_ASSOCIATION_RETAIN);
|
||||
// The retain count is 2. One retain is due to the alloc, the other to the
|
||||
// association with the weak object.
|
||||
DCHECK_EQ(2u, [sentinel retainCount]);
|
||||
@autoreleasepool {
|
||||
CRBWeakNSProtocolSentinel* sentinel =
|
||||
objc_getAssociatedObject(object, &sentinelObserverKey_);
|
||||
if (!sentinel) {
|
||||
base::scoped_nsobject<CRBWeakNSProtocolSentinel> newSentinel(
|
||||
[[CRBWeakNSProtocolSentinel alloc]
|
||||
initWithContainer:new base::WeakContainer(object)]);
|
||||
sentinel = newSentinel;
|
||||
objc_setAssociatedObject(object, &sentinelObserverKey_, sentinel,
|
||||
OBJC_ASSOCIATION_RETAIN);
|
||||
// The retain count is 2. One retain is due to the alloc, the other to the
|
||||
// association with the weak object.
|
||||
DCHECK_EQ(2u, [sentinel retainCount]);
|
||||
}
|
||||
return [sentinel container];
|
||||
}
|
||||
return [sentinel container];
|
||||
}
|
||||
|
||||
- (id)initWithContainer:(scoped_refptr<base::WeakContainer>)container {
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include "base/bind.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/callback_helpers.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "build/build_config.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "testing/gtest_mac.h"
|
||||
@ -108,8 +107,7 @@ TEST(BindObjcBlockTest, TestSixArguments) {
|
||||
TEST(BindObjcBlockTest, TestBlockMoveable) {
|
||||
base::OnceClosure c;
|
||||
__block BOOL invoked_block = NO;
|
||||
{
|
||||
base::mac::ScopedNSAutoreleasePool autorelease_pool;
|
||||
@autoreleasepool {
|
||||
c = base::BindOnce(base::RetainBlock(^(std::unique_ptr<BOOL> v) {
|
||||
invoked_block = *v;
|
||||
}),
|
||||
@ -139,8 +137,7 @@ TEST(BindObjcBlockTest, TestBlockDeallocation) {
|
||||
|
||||
TEST(BindObjcBlockTest, TestBlockReleased) {
|
||||
base::WeakNSObject<NSObject> weak_nsobject;
|
||||
{
|
||||
base::mac::ScopedNSAutoreleasePool autorelease_pool;
|
||||
@autoreleasepool {
|
||||
NSObject* nsobject = [[[NSObject alloc] init] autorelease];
|
||||
weak_nsobject.reset(nsobject);
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/format_macros.h"
|
||||
#include "base/mac/scoped_cftyperef.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "build/build_config.h"
|
||||
@ -162,112 +161,107 @@ TEST(FoundationUtilTest, CFCast) {
|
||||
}
|
||||
|
||||
TEST(FoundationUtilTest, ObjCCast) {
|
||||
ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
id test_array = @[];
|
||||
id test_array_mutable = [NSMutableArray array];
|
||||
id test_data = [NSData data];
|
||||
id test_data_mutable = [NSMutableData dataWithCapacity:10];
|
||||
id test_date = [NSDate date];
|
||||
id test_dict = @{@"meaning" : @42};
|
||||
id test_dict_mutable = [NSMutableDictionary dictionaryWithCapacity:10];
|
||||
id test_number = @42;
|
||||
id test_null = [NSNull null];
|
||||
id test_set = [NSSet setWithObject:@"string object"];
|
||||
id test_set_mutable = [NSMutableSet setWithCapacity:10];
|
||||
id test_str = [NSString string];
|
||||
id test_str_const = @"bonjour";
|
||||
id test_str_mutable = [NSMutableString stringWithCapacity:10];
|
||||
|
||||
id test_array = @[];
|
||||
id test_array_mutable = [NSMutableArray array];
|
||||
id test_data = [NSData data];
|
||||
id test_data_mutable = [NSMutableData dataWithCapacity:10];
|
||||
id test_date = [NSDate date];
|
||||
id test_dict = @{ @"meaning" : @42 };
|
||||
id test_dict_mutable = [NSMutableDictionary dictionaryWithCapacity:10];
|
||||
id test_number = @42;
|
||||
id test_null = [NSNull null];
|
||||
id test_set = [NSSet setWithObject:@"string object"];
|
||||
id test_set_mutable = [NSMutableSet setWithCapacity:10];
|
||||
id test_str = [NSString string];
|
||||
id test_str_const = @"bonjour";
|
||||
id test_str_mutable = [NSMutableString stringWithCapacity:10];
|
||||
// Make sure the allocations of NS types are good.
|
||||
EXPECT_TRUE(test_array);
|
||||
EXPECT_TRUE(test_array_mutable);
|
||||
EXPECT_TRUE(test_data);
|
||||
EXPECT_TRUE(test_data_mutable);
|
||||
EXPECT_TRUE(test_date);
|
||||
EXPECT_TRUE(test_dict);
|
||||
EXPECT_TRUE(test_dict_mutable);
|
||||
EXPECT_TRUE(test_number);
|
||||
EXPECT_TRUE(test_null);
|
||||
EXPECT_TRUE(test_set);
|
||||
EXPECT_TRUE(test_set_mutable);
|
||||
EXPECT_TRUE(test_str);
|
||||
EXPECT_TRUE(test_str_const);
|
||||
EXPECT_TRUE(test_str_mutable);
|
||||
|
||||
// Make sure the allocations of NS types are good.
|
||||
EXPECT_TRUE(test_array);
|
||||
EXPECT_TRUE(test_array_mutable);
|
||||
EXPECT_TRUE(test_data);
|
||||
EXPECT_TRUE(test_data_mutable);
|
||||
EXPECT_TRUE(test_date);
|
||||
EXPECT_TRUE(test_dict);
|
||||
EXPECT_TRUE(test_dict_mutable);
|
||||
EXPECT_TRUE(test_number);
|
||||
EXPECT_TRUE(test_null);
|
||||
EXPECT_TRUE(test_set);
|
||||
EXPECT_TRUE(test_set_mutable);
|
||||
EXPECT_TRUE(test_str);
|
||||
EXPECT_TRUE(test_str_const);
|
||||
EXPECT_TRUE(test_str_mutable);
|
||||
// Casting the id correctly provides the same pointer.
|
||||
EXPECT_EQ(test_array, ObjCCast<NSArray>(test_array));
|
||||
EXPECT_EQ(test_array_mutable, ObjCCast<NSArray>(test_array_mutable));
|
||||
EXPECT_EQ(test_data, ObjCCast<NSData>(test_data));
|
||||
EXPECT_EQ(test_data_mutable, ObjCCast<NSData>(test_data_mutable));
|
||||
EXPECT_EQ(test_date, ObjCCast<NSDate>(test_date));
|
||||
EXPECT_EQ(test_dict, ObjCCast<NSDictionary>(test_dict));
|
||||
EXPECT_EQ(test_dict_mutable, ObjCCast<NSDictionary>(test_dict_mutable));
|
||||
EXPECT_EQ(test_number, ObjCCast<NSNumber>(test_number));
|
||||
EXPECT_EQ(test_null, ObjCCast<NSNull>(test_null));
|
||||
EXPECT_EQ(test_set, ObjCCast<NSSet>(test_set));
|
||||
EXPECT_EQ(test_set_mutable, ObjCCast<NSSet>(test_set_mutable));
|
||||
EXPECT_EQ(test_str, ObjCCast<NSString>(test_str));
|
||||
EXPECT_EQ(test_str_const, ObjCCast<NSString>(test_str_const));
|
||||
EXPECT_EQ(test_str_mutable, ObjCCast<NSString>(test_str_mutable));
|
||||
|
||||
// Casting the id correctly provides the same pointer.
|
||||
EXPECT_EQ(test_array, ObjCCast<NSArray>(test_array));
|
||||
EXPECT_EQ(test_array_mutable, ObjCCast<NSArray>(test_array_mutable));
|
||||
EXPECT_EQ(test_data, ObjCCast<NSData>(test_data));
|
||||
EXPECT_EQ(test_data_mutable, ObjCCast<NSData>(test_data_mutable));
|
||||
EXPECT_EQ(test_date, ObjCCast<NSDate>(test_date));
|
||||
EXPECT_EQ(test_dict, ObjCCast<NSDictionary>(test_dict));
|
||||
EXPECT_EQ(test_dict_mutable, ObjCCast<NSDictionary>(test_dict_mutable));
|
||||
EXPECT_EQ(test_number, ObjCCast<NSNumber>(test_number));
|
||||
EXPECT_EQ(test_null, ObjCCast<NSNull>(test_null));
|
||||
EXPECT_EQ(test_set, ObjCCast<NSSet>(test_set));
|
||||
EXPECT_EQ(test_set_mutable, ObjCCast<NSSet>(test_set_mutable));
|
||||
EXPECT_EQ(test_str, ObjCCast<NSString>(test_str));
|
||||
EXPECT_EQ(test_str_const, ObjCCast<NSString>(test_str_const));
|
||||
EXPECT_EQ(test_str_mutable, ObjCCast<NSString>(test_str_mutable));
|
||||
// When given an incorrect ObjC cast, provide nil.
|
||||
EXPECT_FALSE(ObjCCast<NSString>(test_array));
|
||||
EXPECT_FALSE(ObjCCast<NSString>(test_array_mutable));
|
||||
EXPECT_FALSE(ObjCCast<NSString>(test_data));
|
||||
EXPECT_FALSE(ObjCCast<NSString>(test_data_mutable));
|
||||
EXPECT_FALSE(ObjCCast<NSSet>(test_date));
|
||||
EXPECT_FALSE(ObjCCast<NSSet>(test_dict));
|
||||
EXPECT_FALSE(ObjCCast<NSNumber>(test_dict_mutable));
|
||||
EXPECT_FALSE(ObjCCast<NSNull>(test_number));
|
||||
EXPECT_FALSE(ObjCCast<NSDictionary>(test_null));
|
||||
EXPECT_FALSE(ObjCCast<NSDictionary>(test_set));
|
||||
EXPECT_FALSE(ObjCCast<NSDate>(test_set_mutable));
|
||||
EXPECT_FALSE(ObjCCast<NSData>(test_str));
|
||||
EXPECT_FALSE(ObjCCast<NSData>(test_str_const));
|
||||
EXPECT_FALSE(ObjCCast<NSArray>(test_str_mutable));
|
||||
|
||||
// When given an incorrect ObjC cast, provide nil.
|
||||
EXPECT_FALSE(ObjCCast<NSString>(test_array));
|
||||
EXPECT_FALSE(ObjCCast<NSString>(test_array_mutable));
|
||||
EXPECT_FALSE(ObjCCast<NSString>(test_data));
|
||||
EXPECT_FALSE(ObjCCast<NSString>(test_data_mutable));
|
||||
EXPECT_FALSE(ObjCCast<NSSet>(test_date));
|
||||
EXPECT_FALSE(ObjCCast<NSSet>(test_dict));
|
||||
EXPECT_FALSE(ObjCCast<NSNumber>(test_dict_mutable));
|
||||
EXPECT_FALSE(ObjCCast<NSNull>(test_number));
|
||||
EXPECT_FALSE(ObjCCast<NSDictionary>(test_null));
|
||||
EXPECT_FALSE(ObjCCast<NSDictionary>(test_set));
|
||||
EXPECT_FALSE(ObjCCast<NSDate>(test_set_mutable));
|
||||
EXPECT_FALSE(ObjCCast<NSData>(test_str));
|
||||
EXPECT_FALSE(ObjCCast<NSData>(test_str_const));
|
||||
EXPECT_FALSE(ObjCCast<NSArray>(test_str_mutable));
|
||||
// Giving a nil provides a nil.
|
||||
EXPECT_FALSE(ObjCCast<NSArray>(nil));
|
||||
EXPECT_FALSE(ObjCCast<NSData>(nil));
|
||||
EXPECT_FALSE(ObjCCast<NSDate>(nil));
|
||||
EXPECT_FALSE(ObjCCast<NSDictionary>(nil));
|
||||
EXPECT_FALSE(ObjCCast<NSNull>(nil));
|
||||
EXPECT_FALSE(ObjCCast<NSNumber>(nil));
|
||||
EXPECT_FALSE(ObjCCast<NSSet>(nil));
|
||||
EXPECT_FALSE(ObjCCast<NSString>(nil));
|
||||
|
||||
// Giving a nil provides a nil.
|
||||
EXPECT_FALSE(ObjCCast<NSArray>(nil));
|
||||
EXPECT_FALSE(ObjCCast<NSData>(nil));
|
||||
EXPECT_FALSE(ObjCCast<NSDate>(nil));
|
||||
EXPECT_FALSE(ObjCCast<NSDictionary>(nil));
|
||||
EXPECT_FALSE(ObjCCast<NSNull>(nil));
|
||||
EXPECT_FALSE(ObjCCast<NSNumber>(nil));
|
||||
EXPECT_FALSE(ObjCCast<NSSet>(nil));
|
||||
EXPECT_FALSE(ObjCCast<NSString>(nil));
|
||||
// ObjCCastStrict: correct cast results in correct pointer being returned.
|
||||
EXPECT_EQ(test_array, ObjCCastStrict<NSArray>(test_array));
|
||||
EXPECT_EQ(test_array_mutable, ObjCCastStrict<NSArray>(test_array_mutable));
|
||||
EXPECT_EQ(test_data, ObjCCastStrict<NSData>(test_data));
|
||||
EXPECT_EQ(test_data_mutable, ObjCCastStrict<NSData>(test_data_mutable));
|
||||
EXPECT_EQ(test_date, ObjCCastStrict<NSDate>(test_date));
|
||||
EXPECT_EQ(test_dict, ObjCCastStrict<NSDictionary>(test_dict));
|
||||
EXPECT_EQ(test_dict_mutable,
|
||||
ObjCCastStrict<NSDictionary>(test_dict_mutable));
|
||||
EXPECT_EQ(test_number, ObjCCastStrict<NSNumber>(test_number));
|
||||
EXPECT_EQ(test_null, ObjCCastStrict<NSNull>(test_null));
|
||||
EXPECT_EQ(test_set, ObjCCastStrict<NSSet>(test_set));
|
||||
EXPECT_EQ(test_set_mutable, ObjCCastStrict<NSSet>(test_set_mutable));
|
||||
EXPECT_EQ(test_str, ObjCCastStrict<NSString>(test_str));
|
||||
EXPECT_EQ(test_str_const, ObjCCastStrict<NSString>(test_str_const));
|
||||
EXPECT_EQ(test_str_mutable, ObjCCastStrict<NSString>(test_str_mutable));
|
||||
|
||||
// ObjCCastStrict: correct cast results in correct pointer being returned.
|
||||
EXPECT_EQ(test_array, ObjCCastStrict<NSArray>(test_array));
|
||||
EXPECT_EQ(test_array_mutable,
|
||||
ObjCCastStrict<NSArray>(test_array_mutable));
|
||||
EXPECT_EQ(test_data, ObjCCastStrict<NSData>(test_data));
|
||||
EXPECT_EQ(test_data_mutable,
|
||||
ObjCCastStrict<NSData>(test_data_mutable));
|
||||
EXPECT_EQ(test_date, ObjCCastStrict<NSDate>(test_date));
|
||||
EXPECT_EQ(test_dict, ObjCCastStrict<NSDictionary>(test_dict));
|
||||
EXPECT_EQ(test_dict_mutable,
|
||||
ObjCCastStrict<NSDictionary>(test_dict_mutable));
|
||||
EXPECT_EQ(test_number, ObjCCastStrict<NSNumber>(test_number));
|
||||
EXPECT_EQ(test_null, ObjCCastStrict<NSNull>(test_null));
|
||||
EXPECT_EQ(test_set, ObjCCastStrict<NSSet>(test_set));
|
||||
EXPECT_EQ(test_set_mutable,
|
||||
ObjCCastStrict<NSSet>(test_set_mutable));
|
||||
EXPECT_EQ(test_str, ObjCCastStrict<NSString>(test_str));
|
||||
EXPECT_EQ(test_str_const,
|
||||
ObjCCastStrict<NSString>(test_str_const));
|
||||
EXPECT_EQ(test_str_mutable,
|
||||
ObjCCastStrict<NSString>(test_str_mutable));
|
||||
|
||||
// ObjCCastStrict: Giving a nil provides a nil.
|
||||
EXPECT_FALSE(ObjCCastStrict<NSArray>(nil));
|
||||
EXPECT_FALSE(ObjCCastStrict<NSData>(nil));
|
||||
EXPECT_FALSE(ObjCCastStrict<NSDate>(nil));
|
||||
EXPECT_FALSE(ObjCCastStrict<NSDictionary>(nil));
|
||||
EXPECT_FALSE(ObjCCastStrict<NSNull>(nil));
|
||||
EXPECT_FALSE(ObjCCastStrict<NSNumber>(nil));
|
||||
EXPECT_FALSE(ObjCCastStrict<NSSet>(nil));
|
||||
EXPECT_FALSE(ObjCCastStrict<NSString>(nil));
|
||||
// ObjCCastStrict: Giving a nil provides a nil.
|
||||
EXPECT_FALSE(ObjCCastStrict<NSArray>(nil));
|
||||
EXPECT_FALSE(ObjCCastStrict<NSData>(nil));
|
||||
EXPECT_FALSE(ObjCCastStrict<NSDate>(nil));
|
||||
EXPECT_FALSE(ObjCCastStrict<NSDictionary>(nil));
|
||||
EXPECT_FALSE(ObjCCastStrict<NSNull>(nil));
|
||||
EXPECT_FALSE(ObjCCastStrict<NSNumber>(nil));
|
||||
EXPECT_FALSE(ObjCCastStrict<NSSet>(nil));
|
||||
EXPECT_FALSE(ObjCCastStrict<NSString>(nil));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(FoundationUtilTest, GetValueFromDictionary) {
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include "base/mac/objc_release_properties.h"
|
||||
#include "base/stl_util.h"
|
||||
|
||||
#import "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
#import <objc/runtime.h>
|
||||
@ -268,9 +267,7 @@ TEST(ObjCReleasePropertiesTest, SesameStreet) {
|
||||
// Make sure that worked before things get more involved.
|
||||
EXPECT_EQ(3, ah_ah_ah);
|
||||
|
||||
{
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
|
||||
@autoreleasepool {
|
||||
test_object.baseCvcRetain = [CountVonCount countVonCount];
|
||||
test_object.baseCvcCopy = [CountVonCount countVonCount];
|
||||
test_object.baseCvcAssign = baseAssign;
|
||||
@ -324,9 +321,7 @@ TEST(ObjCReleasePropertiesTest, SesameStreet) {
|
||||
// readonly.
|
||||
EXPECT_EQ(6, ah_ah_ah);
|
||||
|
||||
{
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
|
||||
@autoreleasepool {
|
||||
// Put things back to how they were.
|
||||
test_object.baseCvcRetain = [CountVonCount countVonCount];
|
||||
test_object.baseCvcCopy = [CountVonCount countVonCount];
|
||||
|
@ -21,6 +21,8 @@ namespace mac {
|
||||
// sends it a -drain message when destroyed. This allows an autorelease pool to
|
||||
// be maintained in ordinary C++ code without bringing in any direct Objective-C
|
||||
// dependency.
|
||||
//
|
||||
// Use only in C++ code; use @autoreleasepool in Obj-C(++) code.
|
||||
|
||||
class BASE_EXPORT ScopedNSAutoreleasePool {
|
||||
public:
|
||||
|
@ -36,11 +36,10 @@ namespace base {
|
||||
// scoped_nsprotocol<> has the same behavior as scoped_nsobject, but can be used
|
||||
// with protocols.
|
||||
//
|
||||
// scoped_nsobject<> is not to be used for NSAutoreleasePools. For
|
||||
// NSAutoreleasePools use ScopedNSAutoreleasePool from
|
||||
// scoped_nsautorelease_pool.h instead.
|
||||
// We check for bad uses of scoped_nsobject and NSAutoreleasePool at compile
|
||||
// time with a template specialization (see below).
|
||||
// scoped_nsobject<> is not to be used for NSAutoreleasePools. For C++ code use
|
||||
// NSAutoreleasePool; for Objective-C(++) code use @autoreleasepool instead. We
|
||||
// check for bad uses of scoped_nsobject and NSAutoreleasePool at compile time
|
||||
// with a template specialization (see below).
|
||||
//
|
||||
// If Automatic Reference Counting (aka ARC) is enabled then the ownership
|
||||
// policy is not controllable by the user as ARC make it really difficult to
|
||||
@ -187,7 +186,7 @@ class scoped_nsobject : public scoped_nsprotocol<NST*> {
|
||||
|
||||
#if !defined(__has_feature) || !__has_feature(objc_arc)
|
||||
static_assert(std::is_same<NST, NSAutoreleasePool>::value == false,
|
||||
"Use ScopedNSAutoreleasePool instead");
|
||||
"Use @autoreleasepool instead");
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
@ -24,8 +23,7 @@ TEST(ScopedNSObjectTest, ScopedNSObject) {
|
||||
base::scoped_nsobject<NSObject> p3 = p1;
|
||||
ASSERT_EQ(p1.get(), p3.get());
|
||||
ASSERT_EQ(2u, [p1 retainCount]);
|
||||
{
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
p3 = p1;
|
||||
}
|
||||
ASSERT_EQ(p1.get(), p3.get());
|
||||
@ -46,8 +44,7 @@ TEST(ScopedNSObjectTest, ScopedNSObject) {
|
||||
|
||||
base::scoped_nsobject<NSObject> p6 = p1;
|
||||
ASSERT_EQ(3u, [p6 retainCount]);
|
||||
{
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
p6.autorelease();
|
||||
ASSERT_EQ(nil, p6.get());
|
||||
ASSERT_EQ(3u, [p1 retainCount]);
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/mac/scoped_mach_port.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/process/process_metrics.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/strings/string_util.h"
|
||||
@ -43,9 +42,10 @@ std::string SysInfo::OperatingSystemName() {
|
||||
static dispatch_once_t get_system_name_once;
|
||||
static std::string* system_name;
|
||||
dispatch_once(&get_system_name_once, ^{
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
system_name = new std::string(
|
||||
SysNSStringToUTF8([[UIDevice currentDevice] systemName]));
|
||||
@autoreleasepool {
|
||||
system_name = new std::string(
|
||||
SysNSStringToUTF8([[UIDevice currentDevice] systemName]));
|
||||
}
|
||||
});
|
||||
// Examples of returned value: 'iPhone OS' on iPad 5.1.1
|
||||
// and iPhone 5.1.1.
|
||||
@ -57,9 +57,10 @@ std::string SysInfo::OperatingSystemVersion() {
|
||||
static dispatch_once_t get_system_version_once;
|
||||
static std::string* system_version;
|
||||
dispatch_once(&get_system_version_once, ^{
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
system_version = new std::string(
|
||||
SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]));
|
||||
@autoreleasepool {
|
||||
system_version = new std::string(
|
||||
SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]));
|
||||
}
|
||||
});
|
||||
return *system_version;
|
||||
}
|
||||
@ -68,18 +69,19 @@ std::string SysInfo::OperatingSystemVersion() {
|
||||
void SysInfo::OperatingSystemVersionNumbers(int32_t* major_version,
|
||||
int32_t* minor_version,
|
||||
int32_t* bugfix_version) {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
std::string system_version = OperatingSystemVersion();
|
||||
if (!system_version.empty()) {
|
||||
// Try to parse out the version numbers from the string.
|
||||
int num_read = sscanf(system_version.c_str(), "%d.%d.%d", major_version,
|
||||
minor_version, bugfix_version);
|
||||
if (num_read < 1)
|
||||
*major_version = 0;
|
||||
if (num_read < 2)
|
||||
*minor_version = 0;
|
||||
if (num_read < 3)
|
||||
*bugfix_version = 0;
|
||||
@autoreleasepool {
|
||||
std::string system_version = OperatingSystemVersion();
|
||||
if (!system_version.empty()) {
|
||||
// Try to parse out the version numbers from the string.
|
||||
int num_read = sscanf(system_version.c_str(), "%d.%d.%d", major_version,
|
||||
minor_version, bugfix_version);
|
||||
if (num_read < 1)
|
||||
*major_version = 0;
|
||||
if (num_read < 2)
|
||||
*minor_version = 0;
|
||||
if (num_read < 3)
|
||||
*bugfix_version = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
// The iOS watchdog timer will kill an app that doesn't spin the main event
|
||||
@ -22,11 +21,11 @@ class IOSRunLoopListener : public testing::EmptyTestEventListener {
|
||||
};
|
||||
|
||||
void IOSRunLoopListener::OnTestEnd(const testing::TestInfo& test_info) {
|
||||
base::mac::ScopedNSAutoreleasePool scoped_pool;
|
||||
|
||||
// At the end of the test, spin the default loop for a moment.
|
||||
NSDate* stop_date = [NSDate dateWithTimeIntervalSinceNow:0.001];
|
||||
[[NSRunLoop currentRunLoop] runUntilDate:stop_date];
|
||||
@autoreleasepool {
|
||||
// At the end of the test, spin the default loop for a moment.
|
||||
NSDate* stop_date = [NSDate dateWithTimeIntervalSinceNow:0.001];
|
||||
[[NSRunLoop currentRunLoop] runUntilDate:stop_date];
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
#include "base/debug/debugger.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "base/message_loop/message_pump.h"
|
||||
#include "base/message_loop/message_pump_default.h"
|
||||
@ -209,10 +208,11 @@ void RunTestsFromIOSApp() {
|
||||
static bool ran_hook = false;
|
||||
if (!ran_hook) {
|
||||
ran_hook = true;
|
||||
mac::ScopedNSAutoreleasePool pool;
|
||||
int exit_status = UIApplicationMain(g_argc, g_argv, nil,
|
||||
@"ChromeUnitTestDelegate");
|
||||
exit(exit_status);
|
||||
@autoreleasepool {
|
||||
int exit_status =
|
||||
UIApplicationMain(g_argc, g_argv, nil, @"ChromeUnitTestDelegate");
|
||||
exit(exit_status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "base/logging.h"
|
||||
#import "base/mac/bundle_locations.h"
|
||||
#import "base/mac/foundation_util.h"
|
||||
#import "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "chrome/common/chrome_constants.h"
|
||||
@ -20,19 +19,18 @@
|
||||
#include "content/public/common/content_paths.h"
|
||||
|
||||
void SetUpBundleOverrides() {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
base::mac::SetOverrideFrameworkBundlePath(chrome::GetFrameworkBundlePath());
|
||||
|
||||
base::mac::SetOverrideFrameworkBundlePath(chrome::GetFrameworkBundlePath());
|
||||
NSBundle* base_bundle = chrome::OuterAppBundle();
|
||||
base::mac::SetBaseBundleID([[base_bundle bundleIdentifier] UTF8String]);
|
||||
|
||||
NSBundle* base_bundle = chrome::OuterAppBundle();
|
||||
base::mac::SetBaseBundleID([[base_bundle bundleIdentifier] UTF8String]);
|
||||
base::FilePath child_exe_path =
|
||||
chrome::GetFrameworkBundlePath().Append("Helpers").Append(
|
||||
chrome::kHelperProcessExecutablePath);
|
||||
|
||||
base::FilePath child_exe_path =
|
||||
chrome::GetFrameworkBundlePath()
|
||||
.Append("Helpers")
|
||||
.Append(chrome::kHelperProcessExecutablePath);
|
||||
|
||||
// On the Mac, the child executable lives at a predefined location within
|
||||
// the app bundle's versioned directory.
|
||||
base::PathService::Override(content::CHILD_PROCESS_EXE, child_exe_path);
|
||||
// On the Mac, the child executable lives at a predefined location within
|
||||
// the app bundle's versioned directory.
|
||||
base::PathService::Override(content::CHILD_PROCESS_EXE, child_exe_path);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "base/logging.h"
|
||||
#include "base/mac/foundation_util.h"
|
||||
#import "base/mac/launch_services_util.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/process/launch.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
@ -38,165 +37,166 @@ int LoadFrameworkAndStart(int argc, char** argv) {
|
||||
using base::mac::CFCastStrict;
|
||||
using base::mac::NSToCFCast;
|
||||
|
||||
base::mac::ScopedNSAutoreleasePool scoped_pool;
|
||||
@autoreleasepool {
|
||||
// Get the current main bundle, i.e., that of the app loader that's running.
|
||||
NSBundle* app_bundle = [NSBundle mainBundle];
|
||||
CHECK(app_bundle) << "couldn't get loader bundle";
|
||||
|
||||
// Get the current main bundle, i.e., that of the app loader that's running.
|
||||
NSBundle* app_bundle = [NSBundle mainBundle];
|
||||
CHECK(app_bundle) << "couldn't get loader bundle";
|
||||
// ** 1: Get path to outer Chrome bundle.
|
||||
// Get the bundle ID of the browser that created this app bundle.
|
||||
NSString* cr_bundle_id = base::mac::ObjCCast<NSString>(
|
||||
[app_bundle objectForInfoDictionaryKey:app_mode::kBrowserBundleIDKey]);
|
||||
CHECK(cr_bundle_id) << "couldn't get browser bundle ID";
|
||||
|
||||
// ** 1: Get path to outer Chrome bundle.
|
||||
// Get the bundle ID of the browser that created this app bundle.
|
||||
NSString* cr_bundle_id = base::mac::ObjCCast<NSString>(
|
||||
[app_bundle objectForInfoDictionaryKey:app_mode::kBrowserBundleIDKey]);
|
||||
CHECK(cr_bundle_id) << "couldn't get browser bundle ID";
|
||||
// First check if Chrome exists at the last known location.
|
||||
base::FilePath cr_bundle_path;
|
||||
NSString* cr_bundle_path_ns =
|
||||
[CFToNSCast(CFCastStrict<CFStringRef>(CFPreferencesCopyAppValue(
|
||||
NSToCFCast(app_mode::kLastRunAppBundlePathPrefsKey),
|
||||
NSToCFCast(cr_bundle_id)))) autorelease];
|
||||
cr_bundle_path = base::mac::NSStringToFilePath(cr_bundle_path_ns);
|
||||
bool found_bundle =
|
||||
!cr_bundle_path.empty() && base::DirectoryExists(cr_bundle_path);
|
||||
|
||||
// First check if Chrome exists at the last known location.
|
||||
base::FilePath cr_bundle_path;
|
||||
NSString* cr_bundle_path_ns =
|
||||
[CFToNSCast(CFCastStrict<CFStringRef>(CFPreferencesCopyAppValue(
|
||||
NSToCFCast(app_mode::kLastRunAppBundlePathPrefsKey),
|
||||
NSToCFCast(cr_bundle_id)))) autorelease];
|
||||
cr_bundle_path = base::mac::NSStringToFilePath(cr_bundle_path_ns);
|
||||
bool found_bundle =
|
||||
!cr_bundle_path.empty() && base::DirectoryExists(cr_bundle_path);
|
||||
|
||||
if (!found_bundle) {
|
||||
// If no such bundle path exists, try to search by bundle ID.
|
||||
if (!app_mode::FindBundleById(cr_bundle_id, &cr_bundle_path)) {
|
||||
// TODO(jeremy): Display UI to allow user to manually locate the Chrome
|
||||
// bundle.
|
||||
LOG(FATAL) << "Failed to locate bundle by identifier";
|
||||
if (!found_bundle) {
|
||||
// If no such bundle path exists, try to search by bundle ID.
|
||||
if (!app_mode::FindBundleById(cr_bundle_id, &cr_bundle_path)) {
|
||||
// TODO(jeremy): Display UI to allow user to manually locate the Chrome
|
||||
// bundle.
|
||||
LOG(FATAL) << "Failed to locate bundle by identifier";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ** 2: Read the running Chrome version.
|
||||
// The user_data_dir for shims actually contains the app_data_path.
|
||||
// I.e. <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/
|
||||
base::FilePath app_data_dir = base::mac::NSStringToFilePath([app_bundle
|
||||
objectForInfoDictionaryKey:app_mode::kCrAppModeUserDataDirKey]);
|
||||
base::FilePath user_data_dir = app_data_dir.DirName().DirName().DirName();
|
||||
CHECK(!user_data_dir.empty());
|
||||
// ** 2: Read the running Chrome version.
|
||||
// The user_data_dir for shims actually contains the app_data_path.
|
||||
// I.e. <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/
|
||||
base::FilePath app_data_dir = base::mac::NSStringToFilePath([app_bundle
|
||||
objectForInfoDictionaryKey:app_mode::kCrAppModeUserDataDirKey]);
|
||||
base::FilePath user_data_dir = app_data_dir.DirName().DirName().DirName();
|
||||
CHECK(!user_data_dir.empty());
|
||||
|
||||
// If the version file does not exist, |cr_version_str| will be empty and
|
||||
// app_mode::GetChromeBundleInfo will default to the latest version.
|
||||
base::FilePath cr_version_str;
|
||||
base::ReadSymbolicLink(
|
||||
user_data_dir.Append(app_mode::kRunningChromeVersionSymlinkName),
|
||||
&cr_version_str);
|
||||
// If the version file does not exist, |cr_version_str| will be empty and
|
||||
// app_mode::GetChromeBundleInfo will default to the latest version.
|
||||
base::FilePath cr_version_str;
|
||||
base::ReadSymbolicLink(
|
||||
user_data_dir.Append(app_mode::kRunningChromeVersionSymlinkName),
|
||||
&cr_version_str);
|
||||
|
||||
// If the version file does exist, it may have been left by a crashed Chrome
|
||||
// process. Ensure the process is still running.
|
||||
if (!cr_version_str.empty()) {
|
||||
NSArray* existing_chrome = [NSRunningApplication
|
||||
runningApplicationsWithBundleIdentifier:cr_bundle_id];
|
||||
if ([existing_chrome count] == 0)
|
||||
cr_version_str.clear();
|
||||
}
|
||||
|
||||
// ** 3: Read information from the Chrome bundle.
|
||||
base::FilePath executable_path;
|
||||
base::FilePath framework_path;
|
||||
base::FilePath framework_dylib_path;
|
||||
if (!app_mode::GetChromeBundleInfo(cr_bundle_path, cr_version_str.value(),
|
||||
&executable_path, &framework_path,
|
||||
&framework_dylib_path)) {
|
||||
LOG(FATAL) << "Couldn't ready Chrome bundle info";
|
||||
}
|
||||
base::FilePath app_mode_bundle_path =
|
||||
base::mac::NSStringToFilePath([app_bundle bundlePath]);
|
||||
|
||||
// ** 4: Read information from the Info.plist.
|
||||
// Read information about the this app shortcut from the Info.plist.
|
||||
// Don't check for null-ness on optional items.
|
||||
NSDictionary* info_plist = [app_bundle infoDictionary];
|
||||
CHECK(info_plist) << "couldn't get loader Info.plist";
|
||||
|
||||
const std::string app_mode_id = SysNSStringToUTF8(
|
||||
[info_plist objectForKey:app_mode::kCrAppModeShortcutIDKey]);
|
||||
CHECK(app_mode_id.size()) << "couldn't get app shortcut ID";
|
||||
|
||||
const std::string app_mode_name = SysNSStringToUTF8(
|
||||
[info_plist objectForKey:app_mode::kCrAppModeShortcutNameKey]);
|
||||
const std::string app_mode_url = SysNSStringToUTF8(
|
||||
[info_plist objectForKey:app_mode::kCrAppModeShortcutURLKey]);
|
||||
|
||||
base::FilePath plist_user_data_dir = base::mac::NSStringToFilePath(
|
||||
[info_plist objectForKey:app_mode::kCrAppModeUserDataDirKey]);
|
||||
|
||||
base::FilePath profile_dir = base::mac::NSStringToFilePath(
|
||||
[info_plist objectForKey:app_mode::kCrAppModeProfileDirKey]);
|
||||
|
||||
// ** 5: Open the framework.
|
||||
StartFun ChromeAppModeStart = NULL;
|
||||
void* cr_dylib = dlopen(framework_dylib_path.value().c_str(), RTLD_LAZY);
|
||||
if (cr_dylib) {
|
||||
// Find the entry point.
|
||||
ChromeAppModeStart =
|
||||
(StartFun)dlsym(cr_dylib, APP_SHIM_ENTRY_POINT_NAME_STRING);
|
||||
if (!ChromeAppModeStart)
|
||||
LOG(ERROR) << "Couldn't get entry point: " << dlerror();
|
||||
} else {
|
||||
LOG(ERROR) << "Couldn't load framework: " << dlerror();
|
||||
}
|
||||
|
||||
// ** 6: Fill in ChromeAppModeInfo and call into Chrome's framework.
|
||||
if (ChromeAppModeStart) {
|
||||
// Ensure that the strings pointed to by |info| outlive |info|.
|
||||
const std::string framework_path_utf8 = framework_path.AsUTF8Unsafe();
|
||||
const std::string cr_bundle_path_utf8 = cr_bundle_path.AsUTF8Unsafe();
|
||||
const std::string app_mode_bundle_path_utf8 =
|
||||
app_mode_bundle_path.AsUTF8Unsafe();
|
||||
const std::string plist_user_data_dir_utf8 =
|
||||
plist_user_data_dir.AsUTF8Unsafe();
|
||||
const std::string profile_dir_utf8 = profile_dir.AsUTF8Unsafe();
|
||||
app_mode::ChromeAppModeInfo info;
|
||||
info.argc = argc;
|
||||
info.argv = argv;
|
||||
info.chrome_framework_path = framework_path_utf8.c_str();
|
||||
info.chrome_outer_bundle_path = cr_bundle_path_utf8.c_str();
|
||||
info.app_mode_bundle_path = app_mode_bundle_path_utf8.c_str();
|
||||
info.app_mode_id = app_mode_id.c_str();
|
||||
info.app_mode_name = app_mode_name.c_str();
|
||||
info.app_mode_url = app_mode_url.c_str();
|
||||
info.user_data_dir = plist_user_data_dir_utf8.c_str();
|
||||
info.profile_dir = profile_dir_utf8.c_str();
|
||||
return ChromeAppModeStart(&info);
|
||||
}
|
||||
|
||||
LOG(ERROR) << "Loading Chrome failed, launching Chrome with command line";
|
||||
base::CommandLine command_line(executable_path);
|
||||
// The user_data_dir from the plist is actually the app data dir.
|
||||
command_line.AppendSwitchPath(
|
||||
switches::kUserDataDir,
|
||||
plist_user_data_dir.DirName().DirName().DirName());
|
||||
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
||||
app_mode::kLaunchedByChromeProcessId)) {
|
||||
// Pass --app-shim-error to have Chrome rebuild this shim.
|
||||
// If Chrome has rebuilt this shim once already, then rebuilding doesn't fix
|
||||
// the problem, so don't try again.
|
||||
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
|
||||
app_mode::kLaunchedAfterRebuild)) {
|
||||
command_line.AppendSwitchPath(app_mode::kAppShimError,
|
||||
app_mode_bundle_path);
|
||||
// If the version file does exist, it may have been left by a crashed Chrome
|
||||
// process. Ensure the process is still running.
|
||||
if (!cr_version_str.empty()) {
|
||||
NSArray* existing_chrome = [NSRunningApplication
|
||||
runningApplicationsWithBundleIdentifier:cr_bundle_id];
|
||||
if ([existing_chrome count] == 0)
|
||||
cr_version_str.clear();
|
||||
}
|
||||
} else {
|
||||
// If the shim was launched directly (instead of by Chrome), first ask
|
||||
// Chrome to launch the app. Chrome will launch the shim again, the same
|
||||
// error will occur and be handled above. This approach allows the app to be
|
||||
// started without blocking on fixing the shim and guarantees that the
|
||||
// profile is loaded when Chrome receives --app-shim-error.
|
||||
command_line.AppendSwitchPath(switches::kProfileDirectory, profile_dir);
|
||||
command_line.AppendSwitchASCII(switches::kAppId, app_mode_id);
|
||||
}
|
||||
// Launch the executable directly since base::mac::OpenApplicationWithPath
|
||||
// doesn't pass command line arguments if the application is already running.
|
||||
if (!base::LaunchProcess(command_line, base::LaunchOptions()).IsValid()) {
|
||||
LOG(ERROR) << "Could not launch Chrome: "
|
||||
<< command_line.GetCommandLineString();
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
// ** 3: Read information from the Chrome bundle.
|
||||
base::FilePath executable_path;
|
||||
base::FilePath framework_path;
|
||||
base::FilePath framework_dylib_path;
|
||||
if (!app_mode::GetChromeBundleInfo(cr_bundle_path, cr_version_str.value(),
|
||||
&executable_path, &framework_path,
|
||||
&framework_dylib_path)) {
|
||||
LOG(FATAL) << "Couldn't ready Chrome bundle info";
|
||||
}
|
||||
base::FilePath app_mode_bundle_path =
|
||||
base::mac::NSStringToFilePath([app_bundle bundlePath]);
|
||||
|
||||
// ** 4: Read information from the Info.plist.
|
||||
// Read information about the this app shortcut from the Info.plist.
|
||||
// Don't check for null-ness on optional items.
|
||||
NSDictionary* info_plist = [app_bundle infoDictionary];
|
||||
CHECK(info_plist) << "couldn't get loader Info.plist";
|
||||
|
||||
const std::string app_mode_id = SysNSStringToUTF8(
|
||||
[info_plist objectForKey:app_mode::kCrAppModeShortcutIDKey]);
|
||||
CHECK(app_mode_id.size()) << "couldn't get app shortcut ID";
|
||||
|
||||
const std::string app_mode_name = SysNSStringToUTF8(
|
||||
[info_plist objectForKey:app_mode::kCrAppModeShortcutNameKey]);
|
||||
const std::string app_mode_url = SysNSStringToUTF8(
|
||||
[info_plist objectForKey:app_mode::kCrAppModeShortcutURLKey]);
|
||||
|
||||
base::FilePath plist_user_data_dir = base::mac::NSStringToFilePath(
|
||||
[info_plist objectForKey:app_mode::kCrAppModeUserDataDirKey]);
|
||||
|
||||
base::FilePath profile_dir = base::mac::NSStringToFilePath(
|
||||
[info_plist objectForKey:app_mode::kCrAppModeProfileDirKey]);
|
||||
|
||||
// ** 5: Open the framework.
|
||||
StartFun ChromeAppModeStart = NULL;
|
||||
void* cr_dylib = dlopen(framework_dylib_path.value().c_str(), RTLD_LAZY);
|
||||
if (cr_dylib) {
|
||||
// Find the entry point.
|
||||
ChromeAppModeStart =
|
||||
(StartFun)dlsym(cr_dylib, APP_SHIM_ENTRY_POINT_NAME_STRING);
|
||||
if (!ChromeAppModeStart)
|
||||
LOG(ERROR) << "Couldn't get entry point: " << dlerror();
|
||||
} else {
|
||||
LOG(ERROR) << "Couldn't load framework: " << dlerror();
|
||||
}
|
||||
|
||||
// ** 6: Fill in ChromeAppModeInfo and call into Chrome's framework.
|
||||
if (ChromeAppModeStart) {
|
||||
// Ensure that the strings pointed to by |info| outlive |info|.
|
||||
const std::string framework_path_utf8 = framework_path.AsUTF8Unsafe();
|
||||
const std::string cr_bundle_path_utf8 = cr_bundle_path.AsUTF8Unsafe();
|
||||
const std::string app_mode_bundle_path_utf8 =
|
||||
app_mode_bundle_path.AsUTF8Unsafe();
|
||||
const std::string plist_user_data_dir_utf8 =
|
||||
plist_user_data_dir.AsUTF8Unsafe();
|
||||
const std::string profile_dir_utf8 = profile_dir.AsUTF8Unsafe();
|
||||
app_mode::ChromeAppModeInfo info;
|
||||
info.argc = argc;
|
||||
info.argv = argv;
|
||||
info.chrome_framework_path = framework_path_utf8.c_str();
|
||||
info.chrome_outer_bundle_path = cr_bundle_path_utf8.c_str();
|
||||
info.app_mode_bundle_path = app_mode_bundle_path_utf8.c_str();
|
||||
info.app_mode_id = app_mode_id.c_str();
|
||||
info.app_mode_name = app_mode_name.c_str();
|
||||
info.app_mode_url = app_mode_url.c_str();
|
||||
info.user_data_dir = plist_user_data_dir_utf8.c_str();
|
||||
info.profile_dir = profile_dir_utf8.c_str();
|
||||
return ChromeAppModeStart(&info);
|
||||
}
|
||||
|
||||
LOG(ERROR) << "Loading Chrome failed, launching Chrome with command line";
|
||||
base::CommandLine command_line(executable_path);
|
||||
// The user_data_dir from the plist is actually the app data dir.
|
||||
command_line.AppendSwitchPath(
|
||||
switches::kUserDataDir,
|
||||
plist_user_data_dir.DirName().DirName().DirName());
|
||||
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
||||
app_mode::kLaunchedByChromeProcessId)) {
|
||||
// Pass --app-shim-error to have Chrome rebuild this shim.
|
||||
// If Chrome has rebuilt this shim once already, then rebuilding doesn't
|
||||
// fix the problem, so don't try again.
|
||||
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
|
||||
app_mode::kLaunchedAfterRebuild)) {
|
||||
command_line.AppendSwitchPath(app_mode::kAppShimError,
|
||||
app_mode_bundle_path);
|
||||
}
|
||||
} else {
|
||||
// If the shim was launched directly (instead of by Chrome), first ask
|
||||
// Chrome to launch the app. Chrome will launch the shim again, the same
|
||||
// error will occur and be handled above. This approach allows the app to
|
||||
// be started without blocking on fixing the shim and guarantees that the
|
||||
// profile is loaded when Chrome receives --app-shim-error.
|
||||
command_line.AppendSwitchPath(switches::kProfileDirectory, profile_dir);
|
||||
command_line.AppendSwitchASCII(switches::kAppId, app_mode_id);
|
||||
}
|
||||
// Launch the executable directly since base::mac::OpenApplicationWithPath
|
||||
// doesn't pass command line arguments if the application is already
|
||||
// running.
|
||||
if (!base::LaunchProcess(command_line, base::LaunchOptions()).IsValid()) {
|
||||
LOG(ERROR) << "Could not launch Chrome: "
|
||||
<< command_line.GetCommandLineString();
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "base/logging.h"
|
||||
#include "base/mac/bundle_locations.h"
|
||||
#include "base/mac/mac_logging.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/message_loop/message_pump_type.h"
|
||||
#include "base/run_loop.h"
|
||||
@ -73,94 +72,96 @@ void PostRepeatingDelayedTask() {
|
||||
int APP_SHIM_ENTRY_POINT_NAME(const app_mode::ChromeAppModeInfo* info) {
|
||||
base::CommandLine::Init(info->argc, info->argv);
|
||||
|
||||
base::mac::ScopedNSAutoreleasePool scoped_pool;
|
||||
base::AtExitManager exit_manager;
|
||||
chrome::RegisterPathProvider();
|
||||
@autoreleasepool {
|
||||
base::AtExitManager exit_manager;
|
||||
chrome::RegisterPathProvider();
|
||||
|
||||
// Set bundle paths. This loads the bundles.
|
||||
base::mac::SetOverrideOuterBundlePath(
|
||||
base::FilePath(info->chrome_outer_bundle_path));
|
||||
base::mac::SetOverrideFrameworkBundlePath(
|
||||
base::FilePath(info->chrome_framework_path));
|
||||
// Set bundle paths. This loads the bundles.
|
||||
base::mac::SetOverrideOuterBundlePath(
|
||||
base::FilePath(info->chrome_outer_bundle_path));
|
||||
base::mac::SetOverrideFrameworkBundlePath(
|
||||
base::FilePath(info->chrome_framework_path));
|
||||
|
||||
ChromeCrashReporterClient::Create();
|
||||
crash_reporter::InitializeCrashpad(true, "app_shim");
|
||||
ChromeCrashReporterClient::Create();
|
||||
crash_reporter::InitializeCrashpad(true, "app_shim");
|
||||
|
||||
// Calculate the preferred locale used by Chrome.
|
||||
// We can't use l10n_util::OverrideLocaleWithCocoaLocale() because it calls
|
||||
// [base::mac::OuterBundle() preferredLocalizations] which gets localizations
|
||||
// from the bundle of the running app (i.e. it is equivalent to
|
||||
// [[NSBundle mainBundle] preferredLocalizations]) instead of the target
|
||||
// bundle.
|
||||
NSArray* preferred_languages = [NSLocale preferredLanguages];
|
||||
NSArray* supported_languages = [base::mac::OuterBundle() localizations];
|
||||
std::string preferred_localization;
|
||||
for (NSString* language in preferred_languages) {
|
||||
// We must convert the "-" separator to "_" to be compatible with
|
||||
// NSBundle::localizations() e.g. "en-GB" becomes "en_GB".
|
||||
// See https://crbug.com/913345.
|
||||
language = [language stringByReplacingOccurrencesOfString:@"-"
|
||||
withString:@"_"];
|
||||
if ([supported_languages containsObject:language]) {
|
||||
preferred_localization = base::SysNSStringToUTF8(language);
|
||||
break;
|
||||
}
|
||||
// Check for language support without the region component.
|
||||
language = [language componentsSeparatedByString:@"_"][0];
|
||||
if ([supported_languages containsObject:language]) {
|
||||
preferred_localization = base::SysNSStringToUTF8(language);
|
||||
break;
|
||||
// Calculate the preferred locale used by Chrome. We can't use
|
||||
// l10n_util::OverrideLocaleWithCocoaLocale() because it calls
|
||||
// [base::mac::OuterBundle() preferredLocalizations] which gets
|
||||
// localizations from the bundle of the running app (i.e. it is equivalent
|
||||
// to [[NSBundle mainBundle] preferredLocalizations]) instead of the target
|
||||
// bundle.
|
||||
NSArray* preferred_languages = [NSLocale preferredLanguages];
|
||||
NSArray* supported_languages = [base::mac::OuterBundle() localizations];
|
||||
std::string preferred_localization;
|
||||
for (NSString* language in preferred_languages) {
|
||||
// We must convert the "-" separator to "_" to be compatible with
|
||||
// NSBundle::localizations() e.g. "en-GB" becomes "en_GB".
|
||||
// See https://crbug.com/913345.
|
||||
language = [language stringByReplacingOccurrencesOfString:@"-"
|
||||
withString:@"_"];
|
||||
if ([supported_languages containsObject:language]) {
|
||||
preferred_localization = base::SysNSStringToUTF8(language);
|
||||
break;
|
||||
}
|
||||
// Check for language support without the region component.
|
||||
language = [language componentsSeparatedByString:@"_"][0];
|
||||
if ([supported_languages containsObject:language]) {
|
||||
preferred_localization = base::SysNSStringToUTF8(language);
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::string locale = l10n_util::NormalizeLocale(
|
||||
l10n_util::GetApplicationLocale(preferred_localization));
|
||||
|
||||
// Load localized strings and mouse cursor images.
|
||||
ui::ResourceBundle::InitSharedInstanceWithLocale(
|
||||
locale, NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
|
||||
|
||||
ChromeContentClient chrome_content_client;
|
||||
content::SetContentClient(&chrome_content_client);
|
||||
|
||||
// Launch the IO thread.
|
||||
base::Thread::Options io_thread_options;
|
||||
io_thread_options.message_pump_type = base::MessagePumpType::IO;
|
||||
base::Thread* io_thread = new base::Thread("CrAppShimIO");
|
||||
io_thread->StartWithOptions(io_thread_options);
|
||||
|
||||
mojo::core::Init();
|
||||
mojo::core::ScopedIPCSupport ipc_support(
|
||||
io_thread->task_runner(),
|
||||
mojo::core::ScopedIPCSupport::ShutdownPolicy::FAST);
|
||||
|
||||
// Initialize the NSApplication (and ensure that it was not previously
|
||||
// initialized).
|
||||
[AppShimApplication sharedApplication];
|
||||
CHECK([NSApp isKindOfClass:[AppShimApplication class]]);
|
||||
|
||||
base::SingleThreadTaskExecutor main_task_executor(
|
||||
base::MessagePumpType::UI);
|
||||
ui::WindowResizeHelperMac::Get()->Init(main_task_executor.task_runner());
|
||||
base::PlatformThread::SetName("CrAppShimMain");
|
||||
|
||||
// TODO(https://crbug.com/925998): This workaround ensures that there is
|
||||
// always delayed work enqueued. If there is ever not enqueued delayed work,
|
||||
// then NSMenus and NSAlerts can start misbehaving (see
|
||||
// https://crbug.com/920795 for examples). This workaround is not an
|
||||
// appropriate solution to the problem, and should be replaced by a fix in
|
||||
// the relevant message pump code.
|
||||
PostRepeatingDelayedTask();
|
||||
|
||||
AppShimController::Params controller_params;
|
||||
// Note that |info->user_data_dir| for shims contains the app data path,
|
||||
// <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/.
|
||||
controller_params.user_data_dir =
|
||||
base::FilePath(info->user_data_dir).DirName().DirName().DirName();
|
||||
controller_params.profile_dir = base::FilePath(info->profile_dir);
|
||||
controller_params.app_id = info->app_mode_id;
|
||||
controller_params.app_name = base::UTF8ToUTF16(info->app_mode_name);
|
||||
controller_params.app_url = GURL(info->app_mode_url);
|
||||
|
||||
AppShimController controller(controller_params);
|
||||
base::RunLoop().Run();
|
||||
return 0;
|
||||
}
|
||||
std::string locale = l10n_util::NormalizeLocale(
|
||||
l10n_util::GetApplicationLocale(preferred_localization));
|
||||
|
||||
// Load localized strings and mouse cursor images.
|
||||
ui::ResourceBundle::InitSharedInstanceWithLocale(
|
||||
locale, NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
|
||||
|
||||
ChromeContentClient chrome_content_client;
|
||||
content::SetContentClient(&chrome_content_client);
|
||||
|
||||
// Launch the IO thread.
|
||||
base::Thread::Options io_thread_options;
|
||||
io_thread_options.message_pump_type = base::MessagePumpType::IO;
|
||||
base::Thread *io_thread = new base::Thread("CrAppShimIO");
|
||||
io_thread->StartWithOptions(io_thread_options);
|
||||
|
||||
mojo::core::Init();
|
||||
mojo::core::ScopedIPCSupport ipc_support(
|
||||
io_thread->task_runner(),
|
||||
mojo::core::ScopedIPCSupport::ShutdownPolicy::FAST);
|
||||
|
||||
// Initialize the NSApplication (and ensure that it was not previously
|
||||
// initialized).
|
||||
[AppShimApplication sharedApplication];
|
||||
CHECK([NSApp isKindOfClass:[AppShimApplication class]]);
|
||||
|
||||
base::SingleThreadTaskExecutor main_task_executor(base::MessagePumpType::UI);
|
||||
ui::WindowResizeHelperMac::Get()->Init(main_task_executor.task_runner());
|
||||
base::PlatformThread::SetName("CrAppShimMain");
|
||||
|
||||
// TODO(https://crbug.com/925998): This workaround ensures that there is
|
||||
// always delayed work enqueued. If there is ever not enqueued delayed work,
|
||||
// then NSMenus and NSAlerts can start misbehaving (see
|
||||
// https://crbug.com/920795 for examples). This workaround is not an
|
||||
// appropriate solution to the problem, and should be replaced by a fix in
|
||||
// the relevant message pump code.
|
||||
PostRepeatingDelayedTask();
|
||||
|
||||
AppShimController::Params controller_params;
|
||||
// Note that |info->user_data_dir| for shims contains the app data path,
|
||||
// <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/.
|
||||
controller_params.user_data_dir =
|
||||
base::FilePath(info->user_data_dir).DirName().DirName().DirName();
|
||||
controller_params.profile_dir = base::FilePath(info->profile_dir);
|
||||
controller_params.app_id = info->app_mode_id;
|
||||
controller_params.app_name = base::UTF8ToUTF16(info->app_mode_name);
|
||||
controller_params.app_url = GURL(info->app_mode_url);
|
||||
|
||||
AppShimController controller(controller_params);
|
||||
base::RunLoop().Run();
|
||||
return 0;
|
||||
}
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "base/mac/scoped_authorizationref.h"
|
||||
#include "base/mac/scoped_cftyperef.h"
|
||||
#include "base/mac/scoped_ioobject.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/mac/sdk_forward_declarations.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/stl_util.h"
|
||||
@ -407,84 +406,80 @@ DiskImageStatus IsAppRunningFromReadOnlyDiskImage(
|
||||
}
|
||||
|
||||
bool MaybeInstallFromDiskImage() {
|
||||
base::mac::ScopedNSAutoreleasePool autorelease_pool;
|
||||
@autoreleasepool {
|
||||
std::string dmg_bsd_device_name;
|
||||
if (IsAppRunningFromReadOnlyDiskImage(&dmg_bsd_device_name) !=
|
||||
DiskImageStatusTrue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string dmg_bsd_device_name;
|
||||
if (IsAppRunningFromReadOnlyDiskImage(&dmg_bsd_device_name) !=
|
||||
DiskImageStatusTrue) {
|
||||
return false;
|
||||
NSArray* application_directories = NSSearchPathForDirectoriesInDomains(
|
||||
NSApplicationDirectory, NSLocalDomainMask, YES);
|
||||
if ([application_directories count] == 0) {
|
||||
LOG(ERROR) << "NSSearchPathForDirectoriesInDomains: "
|
||||
<< "no local application directories";
|
||||
return false;
|
||||
}
|
||||
NSString* application_directory = [application_directories objectAtIndex:0];
|
||||
|
||||
NSFileManager* file_manager = [NSFileManager defaultManager];
|
||||
|
||||
BOOL is_directory;
|
||||
if (![file_manager fileExistsAtPath:application_directory
|
||||
isDirectory:&is_directory] ||
|
||||
!is_directory) {
|
||||
VLOG(1) << "No application directory at "
|
||||
<< [application_directory UTF8String];
|
||||
return false;
|
||||
}
|
||||
|
||||
NSString* source_path = [base::mac::OuterBundle() bundlePath];
|
||||
NSString* application_name = [source_path lastPathComponent];
|
||||
NSString* target_path =
|
||||
[application_directory stringByAppendingPathComponent:application_name];
|
||||
|
||||
if ([file_manager fileExistsAtPath:target_path]) {
|
||||
VLOG(1) << "Something already exists at " << [target_path UTF8String];
|
||||
return false;
|
||||
}
|
||||
|
||||
NSString* installer_path =
|
||||
[base::mac::FrameworkBundle() pathForResource:@"install" ofType:@"sh"];
|
||||
if (!installer_path) {
|
||||
VLOG(1) << "Could not locate install.sh";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ShouldInstallDialog()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
base::mac::ScopedAuthorizationRef authorization(
|
||||
MaybeShowAuthorizationDialog(application_directory));
|
||||
// authorization will be NULL if it's deemed unnecessary or if
|
||||
// authentication fails. In either case, try to install without privilege
|
||||
// escalation.
|
||||
|
||||
if (!InstallFromDiskImage(authorization.release(), installer_path,
|
||||
source_path, target_path)) {
|
||||
ShowErrorDialog();
|
||||
return false;
|
||||
}
|
||||
|
||||
dock::AddIcon(target_path, source_path);
|
||||
|
||||
if (dmg_bsd_device_name.empty()) {
|
||||
// Not fatal, just diagnostic.
|
||||
LOG(ERROR) << "Could not determine disk image BSD device name";
|
||||
}
|
||||
|
||||
if (!LaunchInstalledApp(target_path, dmg_bsd_device_name)) {
|
||||
ShowErrorDialog();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NSArray* application_directories =
|
||||
NSSearchPathForDirectoriesInDomains(NSApplicationDirectory,
|
||||
NSLocalDomainMask,
|
||||
YES);
|
||||
if ([application_directories count] == 0) {
|
||||
LOG(ERROR) << "NSSearchPathForDirectoriesInDomains: "
|
||||
<< "no local application directories";
|
||||
return false;
|
||||
}
|
||||
NSString* application_directory = [application_directories objectAtIndex:0];
|
||||
|
||||
NSFileManager* file_manager = [NSFileManager defaultManager];
|
||||
|
||||
BOOL is_directory;
|
||||
if (![file_manager fileExistsAtPath:application_directory
|
||||
isDirectory:&is_directory] ||
|
||||
!is_directory) {
|
||||
VLOG(1) << "No application directory at "
|
||||
<< [application_directory UTF8String];
|
||||
return false;
|
||||
}
|
||||
|
||||
NSString* source_path = [base::mac::OuterBundle() bundlePath];
|
||||
NSString* application_name = [source_path lastPathComponent];
|
||||
NSString* target_path =
|
||||
[application_directory stringByAppendingPathComponent:application_name];
|
||||
|
||||
if ([file_manager fileExistsAtPath:target_path]) {
|
||||
VLOG(1) << "Something already exists at " << [target_path UTF8String];
|
||||
return false;
|
||||
}
|
||||
|
||||
NSString* installer_path =
|
||||
[base::mac::FrameworkBundle() pathForResource:@"install" ofType:@"sh"];
|
||||
if (!installer_path) {
|
||||
VLOG(1) << "Could not locate install.sh";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ShouldInstallDialog()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
base::mac::ScopedAuthorizationRef authorization(
|
||||
MaybeShowAuthorizationDialog(application_directory));
|
||||
// authorization will be NULL if it's deemed unnecessary or if
|
||||
// authentication fails. In either case, try to install without privilege
|
||||
// escalation.
|
||||
|
||||
if (!InstallFromDiskImage(authorization.release(),
|
||||
installer_path,
|
||||
source_path,
|
||||
target_path)) {
|
||||
ShowErrorDialog();
|
||||
return false;
|
||||
}
|
||||
|
||||
dock::AddIcon(target_path, source_path);
|
||||
|
||||
if (dmg_bsd_device_name.empty()) {
|
||||
// Not fatal, just diagnostic.
|
||||
LOG(ERROR) << "Could not determine disk image BSD device name";
|
||||
}
|
||||
|
||||
if (!LaunchInstalledApp(target_path, dmg_bsd_device_name)) {
|
||||
ShowErrorDialog();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "base/mac/bundle_locations.h"
|
||||
#include "base/mac/foundation_util.h"
|
||||
#include "base/mac/mac_logging.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
@ -111,8 +110,9 @@ class PerformBridge : public base::RefCountedThreadSafe<PerformBridge> {
|
||||
|
||||
// Happens on a WorkerPool thread.
|
||||
void Run() {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
[target_ performSelector:sel_ withObject:arg_];
|
||||
@autoreleasepool {
|
||||
[target_ performSelector:sel_ withObject:arg_];
|
||||
}
|
||||
}
|
||||
|
||||
base::scoped_nsobject<id> target_;
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "base/files/scoped_file.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/mac/mac_logging.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/posix/eintr_wrapper.h"
|
||||
@ -266,137 +265,137 @@ void RelauncherSynchronizeWithParent() {
|
||||
namespace internal {
|
||||
|
||||
int RelauncherMain(const content::MainFunctionParams& main_parameters) {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
// CommandLine rearranges the order of the arguments returned by
|
||||
// main_parameters.argv(), rendering it impossible to determine which
|
||||
// arguments originally came before kRelauncherArgSeparator and which came
|
||||
// after. It's crucial to distinguish between these because only those
|
||||
// after the separator should be given to the relaunched process; it's also
|
||||
// important to not treat the path to the relaunched process as a "loose"
|
||||
// argument. NXArgc and NXArgv are pointers to the original argc and argv as
|
||||
// passed to main(), so use those. Access them through _NSGetArgc and
|
||||
// _NSGetArgv because NXArgc and NXArgv are normally only available to a
|
||||
// main executable via crt1.o and this code will run from a dylib, and
|
||||
// because of http://crbug.com/139902.
|
||||
const int* argcp = _NSGetArgc();
|
||||
if (!argcp) {
|
||||
NOTREACHED();
|
||||
return 1;
|
||||
}
|
||||
int argc = *argcp;
|
||||
|
||||
// CommandLine rearranges the order of the arguments returned by
|
||||
// main_parameters.argv(), rendering it impossible to determine which
|
||||
// arguments originally came before kRelauncherArgSeparator and which came
|
||||
// after. It's crucial to distinguish between these because only those
|
||||
// after the separator should be given to the relaunched process; it's also
|
||||
// important to not treat the path to the relaunched process as a "loose"
|
||||
// argument. NXArgc and NXArgv are pointers to the original argc and argv as
|
||||
// passed to main(), so use those. Access them through _NSGetArgc and
|
||||
// _NSGetArgv because NXArgc and NXArgv are normally only available to a
|
||||
// main executable via crt1.o and this code will run from a dylib, and
|
||||
// because of http://crbug.com/139902.
|
||||
const int* argcp = _NSGetArgc();
|
||||
if (!argcp) {
|
||||
NOTREACHED();
|
||||
return 1;
|
||||
}
|
||||
int argc = *argcp;
|
||||
const char* const* const* argvp = _NSGetArgv();
|
||||
if (!argvp) {
|
||||
NOTREACHED();
|
||||
return 1;
|
||||
}
|
||||
const char* const* argv = *argvp;
|
||||
|
||||
const char* const* const* argvp = _NSGetArgv();
|
||||
if (!argvp) {
|
||||
NOTREACHED();
|
||||
return 1;
|
||||
}
|
||||
const char* const* argv = *argvp;
|
||||
|
||||
if (argc < 4 || RelauncherTypeArg() != argv[1]) {
|
||||
LOG(ERROR) << "relauncher process invoked with unexpected arguments";
|
||||
return 1;
|
||||
}
|
||||
|
||||
RelauncherSynchronizeWithParent();
|
||||
|
||||
// The capacity for relaunch_args is 4 less than argc, because it
|
||||
// won't contain the argv[0] of the relauncher process, the
|
||||
// RelauncherTypeArg() at argv[1], kRelauncherArgSeparator, or the
|
||||
// executable path of the process to be launched.
|
||||
base::scoped_nsobject<NSMutableArray> relaunch_args(
|
||||
[[NSMutableArray alloc] initWithCapacity:argc - 4]);
|
||||
|
||||
// Figure out what to execute, what arguments to pass it, and whether to
|
||||
// start it in the background.
|
||||
bool background = false;
|
||||
bool wait_for_staged_update = false;
|
||||
bool in_relaunch_args = false;
|
||||
std::string dmg_bsd_device_name;
|
||||
bool seen_relaunch_executable = false;
|
||||
std::string relaunch_executable;
|
||||
const std::string relauncher_dmg_device_arg =
|
||||
base::StringPrintf("--%s=", switches::kRelauncherProcessDMGDevice);
|
||||
for (int argv_index = 2; argv_index < argc; ++argv_index) {
|
||||
const std::string arg(argv[argv_index]);
|
||||
|
||||
// Strip any -psn_ arguments, as they apply to a specific process.
|
||||
if (arg.compare(0, strlen(kPSNArg), kPSNArg) == 0) {
|
||||
continue;
|
||||
if (argc < 4 || RelauncherTypeArg() != argv[1]) {
|
||||
LOG(ERROR) << "relauncher process invoked with unexpected arguments";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!in_relaunch_args) {
|
||||
if (arg == kRelauncherArgSeparator) {
|
||||
in_relaunch_args = true;
|
||||
} else if (arg == kRelauncherBackgroundArg) {
|
||||
background = true;
|
||||
} else if (arg == kRelauncherWaitForUpdateArg) {
|
||||
wait_for_staged_update = true;
|
||||
} else if (arg.compare(0, relauncher_dmg_device_arg.size(),
|
||||
relauncher_dmg_device_arg) == 0) {
|
||||
dmg_bsd_device_name.assign(
|
||||
arg.substr(relauncher_dmg_device_arg.size()));
|
||||
}
|
||||
} else {
|
||||
if (!seen_relaunch_executable) {
|
||||
// The first argument after kRelauncherBackgroundArg is the path to
|
||||
// the executable file or .app bundle directory. The Launch Services
|
||||
// interface wants this separate from the rest of the arguments. In
|
||||
// the relaunched process, this path will still be visible at argv[0].
|
||||
relaunch_executable.assign(arg);
|
||||
seen_relaunch_executable = true;
|
||||
} else {
|
||||
RelauncherSynchronizeWithParent();
|
||||
|
||||
NSString* arg_string = base::SysUTF8ToNSString(arg);
|
||||
if (!arg_string) {
|
||||
LOG(ERROR) << "base::SysUTF8ToNSString failed for " << arg;
|
||||
return 1;
|
||||
// The capacity for relaunch_args is 4 less than argc, because it
|
||||
// won't contain the argv[0] of the relauncher process, the
|
||||
// RelauncherTypeArg() at argv[1], kRelauncherArgSeparator, or the
|
||||
// executable path of the process to be launched.
|
||||
base::scoped_nsobject<NSMutableArray> relaunch_args(
|
||||
[[NSMutableArray alloc] initWithCapacity:argc - 4]);
|
||||
|
||||
// Figure out what to execute, what arguments to pass it, and whether to
|
||||
// start it in the background.
|
||||
bool background = false;
|
||||
bool wait_for_staged_update = false;
|
||||
bool in_relaunch_args = false;
|
||||
std::string dmg_bsd_device_name;
|
||||
bool seen_relaunch_executable = false;
|
||||
std::string relaunch_executable;
|
||||
const std::string relauncher_dmg_device_arg =
|
||||
base::StringPrintf("--%s=", switches::kRelauncherProcessDMGDevice);
|
||||
for (int argv_index = 2; argv_index < argc; ++argv_index) {
|
||||
const std::string arg(argv[argv_index]);
|
||||
|
||||
// Strip any -psn_ arguments, as they apply to a specific process.
|
||||
if (arg.compare(0, strlen(kPSNArg), kPSNArg) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!in_relaunch_args) {
|
||||
if (arg == kRelauncherArgSeparator) {
|
||||
in_relaunch_args = true;
|
||||
} else if (arg == kRelauncherBackgroundArg) {
|
||||
background = true;
|
||||
} else if (arg == kRelauncherWaitForUpdateArg) {
|
||||
wait_for_staged_update = true;
|
||||
} else if (arg.compare(0, relauncher_dmg_device_arg.size(),
|
||||
relauncher_dmg_device_arg) == 0) {
|
||||
dmg_bsd_device_name.assign(
|
||||
arg.substr(relauncher_dmg_device_arg.size()));
|
||||
}
|
||||
} else {
|
||||
if (!seen_relaunch_executable) {
|
||||
// The first argument after kRelauncherBackgroundArg is the path to
|
||||
// the executable file or .app bundle directory. The Launch Services
|
||||
// interface wants this separate from the rest of the arguments. In
|
||||
// the relaunched process, this path will still be visible at argv[0].
|
||||
relaunch_executable.assign(arg);
|
||||
seen_relaunch_executable = true;
|
||||
} else {
|
||||
NSString* arg_string = base::SysUTF8ToNSString(arg);
|
||||
if (!arg_string) {
|
||||
LOG(ERROR) << "base::SysUTF8ToNSString failed for " << arg;
|
||||
return 1;
|
||||
}
|
||||
[relaunch_args addObject:arg_string];
|
||||
}
|
||||
[relaunch_args addObject:arg_string];
|
||||
}
|
||||
}
|
||||
|
||||
if (!seen_relaunch_executable) {
|
||||
LOG(ERROR) << "nothing to relaunch";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// If an update is staged but not yet installed, wait for it to be
|
||||
// installed.
|
||||
if (wait_for_staged_update) {
|
||||
base::scoped_nsobject<CrStagingKeyWatcher> watcher(
|
||||
[[CrStagingKeyWatcher alloc] initWithPollingTime:0.5]);
|
||||
[watcher waitForStagingKeyToClear];
|
||||
}
|
||||
|
||||
NSString* path = base::SysUTF8ToNSString(relaunch_executable);
|
||||
base::scoped_nsobject<NSURL> url([[NSURL alloc] initFileURLWithPath:path]);
|
||||
NSDictionary* configuration =
|
||||
@{NSWorkspaceLaunchConfigurationArguments : (relaunch_args.get())};
|
||||
|
||||
NSRunningApplication* application = [[NSWorkspace sharedWorkspace]
|
||||
launchApplicationAtURL:url
|
||||
options:NSWorkspaceLaunchDefault |
|
||||
NSWorkspaceLaunchWithErrorPresentation |
|
||||
(background ? NSWorkspaceLaunchWithoutActivation
|
||||
: 0) |
|
||||
NSWorkspaceLaunchNewInstance
|
||||
configuration:configuration
|
||||
error:nil];
|
||||
if (!application) {
|
||||
LOG(ERROR) << "Failed to relaunch " << relaunch_executable;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// The application should have relaunched (or is in the process of
|
||||
// relaunching). From this point on, only clean-up tasks should occur, and
|
||||
// failures are tolerable.
|
||||
|
||||
if (!dmg_bsd_device_name.empty()) {
|
||||
EjectAndTrashDiskImage(dmg_bsd_device_name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!seen_relaunch_executable) {
|
||||
LOG(ERROR) << "nothing to relaunch";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// If an update is staged but not yet installed, wait for it to be installed.
|
||||
if (wait_for_staged_update) {
|
||||
base::scoped_nsobject<CrStagingKeyWatcher> watcher(
|
||||
[[CrStagingKeyWatcher alloc] initWithPollingTime:0.5]);
|
||||
[watcher waitForStagingKeyToClear];
|
||||
}
|
||||
|
||||
NSString* path = base::SysUTF8ToNSString(relaunch_executable);
|
||||
base::scoped_nsobject<NSURL> url([[NSURL alloc] initFileURLWithPath:path]);
|
||||
NSDictionary* configuration =
|
||||
@{NSWorkspaceLaunchConfigurationArguments : (relaunch_args.get())};
|
||||
|
||||
NSRunningApplication *application = [[NSWorkspace sharedWorkspace]
|
||||
launchApplicationAtURL:url
|
||||
options:NSWorkspaceLaunchDefault |
|
||||
NSWorkspaceLaunchWithErrorPresentation |
|
||||
(background ? NSWorkspaceLaunchWithoutActivation
|
||||
: 0) |
|
||||
NSWorkspaceLaunchNewInstance
|
||||
configuration:configuration
|
||||
error:nil];
|
||||
if (!application) {
|
||||
LOG(ERROR) << "Failed to relaunch " << relaunch_executable;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// The application should have relaunched (or is in the process of
|
||||
// relaunching). From this point on, only clean-up tasks should occur, and
|
||||
// failures are tolerable.
|
||||
|
||||
if (!dmg_bsd_device_name.empty()) {
|
||||
EjectAndTrashDiskImage(dmg_bsd_device_name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "base/base_paths.h"
|
||||
#include "base/logging.h"
|
||||
#import "base/mac/foundation_util.h"
|
||||
#import "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/memory/free_deleter.h"
|
||||
#include "base/path_service.h"
|
||||
#include "build/build_config.h"
|
||||
@ -24,48 +23,50 @@ namespace {
|
||||
// implementation of chrome::OuterAppBundle(), which should be the only
|
||||
// caller.
|
||||
NSBundle* OuterAppBundleInternal() {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
if (!base::mac::AmIBundled()) {
|
||||
// If unbundled (as in a test), there's no app bundle.
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (!base::mac::AmIBundled()) {
|
||||
// If unbundled (as in a test), there's no app bundle.
|
||||
return nil;
|
||||
if (!base::mac::IsBackgroundOnlyProcess()) {
|
||||
// Shortcut: in the browser process, just return the main app bundle.
|
||||
return [[NSBundle mainBundle] retain];
|
||||
}
|
||||
|
||||
// From C.app/Contents/Frameworks/C.framework/Versions/1.2.3.4, go up five
|
||||
// steps to C.app.
|
||||
base::FilePath framework_path = chrome::GetFrameworkBundlePath();
|
||||
base::FilePath outer_app_dir =
|
||||
framework_path.DirName().DirName().DirName().DirName().DirName();
|
||||
const char* outer_app_dir_c = outer_app_dir.value().c_str();
|
||||
NSString* outer_app_dir_ns =
|
||||
[NSString stringWithUTF8String:outer_app_dir_c];
|
||||
|
||||
return [[NSBundle bundleWithPath:outer_app_dir_ns] retain];
|
||||
}
|
||||
|
||||
if (!base::mac::IsBackgroundOnlyProcess()) {
|
||||
// Shortcut: in the browser process, just return the main app bundle.
|
||||
return [[NSBundle mainBundle] retain];
|
||||
}
|
||||
|
||||
// From C.app/Contents/Frameworks/C.framework/Versions/1.2.3.4, go up five
|
||||
// steps to C.app.
|
||||
base::FilePath framework_path = chrome::GetFrameworkBundlePath();
|
||||
base::FilePath outer_app_dir =
|
||||
framework_path.DirName().DirName().DirName().DirName().DirName();
|
||||
const char* outer_app_dir_c = outer_app_dir.value().c_str();
|
||||
NSString* outer_app_dir_ns = [NSString stringWithUTF8String:outer_app_dir_c];
|
||||
|
||||
return [[NSBundle bundleWithPath:outer_app_dir_ns] retain];
|
||||
}
|
||||
|
||||
char* ProductDirNameForBundle(NSBundle* chrome_bundle) {
|
||||
const char* product_dir_name = NULL;
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
const char* product_dir_name = NULL;
|
||||
|
||||
NSString* product_dir_name_ns =
|
||||
[chrome_bundle objectForInfoDictionaryKey:@"CrProductDirName"];
|
||||
product_dir_name = [product_dir_name_ns fileSystemRepresentation];
|
||||
NSString* product_dir_name_ns =
|
||||
[chrome_bundle objectForInfoDictionaryKey:@"CrProductDirName"];
|
||||
product_dir_name = [product_dir_name_ns fileSystemRepresentation];
|
||||
|
||||
if (!product_dir_name) {
|
||||
if (!product_dir_name) {
|
||||
#if defined(GOOGLE_CHROME_BUILD)
|
||||
product_dir_name = "Google/Chrome";
|
||||
product_dir_name = "Google/Chrome";
|
||||
#else
|
||||
product_dir_name = "Chromium";
|
||||
product_dir_name = "Chromium";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Leaked, but the only caller initializes a static with this result, so it
|
||||
// only happens once, and that's OK.
|
||||
return strdup(product_dir_name);
|
||||
// Leaked, but the only caller initializes a static with this result, so it
|
||||
// only happens once, and that's OK.
|
||||
return strdup(product_dir_name);
|
||||
}
|
||||
}
|
||||
|
||||
// ProductDirName returns the name of the directory inside
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
#include "base/mac/foundation_util.h"
|
||||
#include "base/mac/scoped_cftyperef.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/process/launch.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
@ -100,63 +99,67 @@ bool Launchd::RestartJob(Domain domain,
|
||||
Type type,
|
||||
CFStringRef name,
|
||||
CFStringRef cf_session_type) {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
NSURL* url = GetPlistURL(domain, type, name);
|
||||
NSString* ns_path = [url path];
|
||||
ns_path = SanitizeShellArgument(ns_path);
|
||||
const char* file_path = [ns_path fileSystemRepresentation];
|
||||
@autoreleasepool {
|
||||
NSURL* url = GetPlistURL(domain, type, name);
|
||||
NSString* ns_path = [url path];
|
||||
ns_path = SanitizeShellArgument(ns_path);
|
||||
const char* file_path = [ns_path fileSystemRepresentation];
|
||||
|
||||
NSString* ns_session_type =
|
||||
SanitizeShellArgument(base::mac::CFToNSCast(cf_session_type));
|
||||
if (!file_path || !ns_session_type) {
|
||||
return false;
|
||||
NSString* ns_session_type =
|
||||
SanitizeShellArgument(base::mac::CFToNSCast(cf_session_type));
|
||||
if (!file_path || !ns_session_type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string> argv;
|
||||
argv.push_back("/bin/bash");
|
||||
argv.push_back("--noprofile");
|
||||
argv.push_back("-c");
|
||||
std::string command =
|
||||
base::StringPrintf("/bin/launchctl unload -S %s %s;"
|
||||
"/bin/launchctl load -S %s %s;",
|
||||
[ns_session_type UTF8String], file_path,
|
||||
[ns_session_type UTF8String], file_path);
|
||||
argv.push_back(command);
|
||||
|
||||
base::LaunchOptions options;
|
||||
options.new_process_group = true;
|
||||
return base::LaunchProcess(argv, options).IsValid();
|
||||
}
|
||||
|
||||
std::vector<std::string> argv;
|
||||
argv.push_back("/bin/bash");
|
||||
argv.push_back("--noprofile");
|
||||
argv.push_back("-c");
|
||||
std::string command = base::StringPrintf(
|
||||
"/bin/launchctl unload -S %s %s;"
|
||||
"/bin/launchctl load -S %s %s;",
|
||||
[ns_session_type UTF8String], file_path,
|
||||
[ns_session_type UTF8String], file_path);
|
||||
argv.push_back(command);
|
||||
|
||||
base::LaunchOptions options;
|
||||
options.new_process_group = true;
|
||||
return base::LaunchProcess(argv, options).IsValid();
|
||||
}
|
||||
|
||||
CFMutableDictionaryRef Launchd::CreatePlistFromFile(Domain domain,
|
||||
Type type,
|
||||
CFStringRef name) {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
NSURL* ns_url = GetPlistURL(domain, type, name);
|
||||
NSMutableDictionary* plist =
|
||||
[[NSMutableDictionary alloc] initWithContentsOfURL:ns_url];
|
||||
return base::mac::NSToCFCast(plist);
|
||||
@autoreleasepool {
|
||||
NSURL* ns_url = GetPlistURL(domain, type, name);
|
||||
NSMutableDictionary* plist =
|
||||
[[NSMutableDictionary alloc] initWithContentsOfURL:ns_url];
|
||||
return base::mac::NSToCFCast(plist);
|
||||
}
|
||||
}
|
||||
|
||||
bool Launchd::WritePlistToFile(Domain domain,
|
||||
Type type,
|
||||
CFStringRef name,
|
||||
CFDictionaryRef dict) {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
NSURL* ns_url = GetPlistURL(domain, type, name);
|
||||
return [base::mac::CFToNSCast(dict) writeToURL:ns_url atomically:YES];
|
||||
@autoreleasepool {
|
||||
NSURL* ns_url = GetPlistURL(domain, type, name);
|
||||
return [base::mac::CFToNSCast(dict) writeToURL:ns_url atomically:YES];
|
||||
}
|
||||
}
|
||||
|
||||
bool Launchd::DeletePlist(Domain domain, Type type, CFStringRef name) {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
NSURL* ns_url = GetPlistURL(domain, type, name);
|
||||
NSError* err = nil;
|
||||
if (![[NSFileManager defaultManager] removeItemAtPath:[ns_url path]
|
||||
error:&err]) {
|
||||
if ([err code] != NSFileNoSuchFileError) {
|
||||
DLOG(ERROR) << "DeletePlist: " << base::mac::NSToCFCast(err);
|
||||
@autoreleasepool {
|
||||
NSURL* ns_url = GetPlistURL(domain, type, name);
|
||||
NSError* err = nil;
|
||||
if (![[NSFileManager defaultManager] removeItemAtPath:[ns_url path]
|
||||
error:&err]) {
|
||||
if ([err code] != NSFileNoSuchFileError) {
|
||||
DLOG(ERROR) << "DeletePlist: " << base::mac::NSToCFCast(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "base/mac/bundle_locations.h"
|
||||
#include "base/mac/foundation_util.h"
|
||||
#include "base/mac/mac_util.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "base/metrics/histogram_macros.h"
|
||||
#include "base/path_service.h"
|
||||
@ -37,10 +36,11 @@ namespace {
|
||||
#define kServiceProcessSessionType "Aqua"
|
||||
|
||||
CFStringRef CopyServiceProcessLaunchDName() {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
NSBundle* bundle = base::mac::FrameworkBundle();
|
||||
return CFStringCreateCopy(kCFAllocatorDefault,
|
||||
base::mac::NSToCFCast([bundle bundleIdentifier]));
|
||||
@autoreleasepool {
|
||||
NSBundle* bundle = base::mac::FrameworkBundle();
|
||||
return CFStringCreateCopy(kCFAllocatorDefault,
|
||||
base::mac::NSToCFCast([bundle bundleIdentifier]));
|
||||
}
|
||||
}
|
||||
|
||||
NSString* GetServiceProcessLaunchDLabel() {
|
||||
@ -105,44 +105,46 @@ bool ForceServiceProcessShutdown(const std::string& /* version */,
|
||||
|
||||
bool ServiceProcessState::GetServiceProcessData(std::string* version,
|
||||
base::ProcessId* pid) {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
std::string label = base::SysNSStringToUTF8(GetServiceProcessLaunchDLabel());
|
||||
mac::services::JobInfo info;
|
||||
if (!Launchd::GetInstance()->GetJobInfo(label, &info))
|
||||
return false;
|
||||
// Anything past here will return true in that there does appear
|
||||
// to be a service process of some sort registered with launchd.
|
||||
if (version) {
|
||||
*version = "0";
|
||||
NSString* exe_path = base::SysUTF8ToNSString(info.program);
|
||||
if (exe_path) {
|
||||
NSString* bundle_path = [[[exe_path stringByDeletingLastPathComponent]
|
||||
stringByDeletingLastPathComponent]
|
||||
stringByDeletingLastPathComponent];
|
||||
NSBundle* bundle = [NSBundle bundleWithPath:bundle_path];
|
||||
if (bundle) {
|
||||
NSString* ns_version =
|
||||
[bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
|
||||
if (ns_version) {
|
||||
*version = base::SysNSStringToUTF8(ns_version);
|
||||
@autoreleasepool {
|
||||
std::string label =
|
||||
base::SysNSStringToUTF8(GetServiceProcessLaunchDLabel());
|
||||
mac::services::JobInfo info;
|
||||
if (!Launchd::GetInstance()->GetJobInfo(label, &info))
|
||||
return false;
|
||||
// Anything past here will return true in that there does appear
|
||||
// to be a service process of some sort registered with launchd.
|
||||
if (version) {
|
||||
*version = "0";
|
||||
NSString* exe_path = base::SysUTF8ToNSString(info.program);
|
||||
if (exe_path) {
|
||||
NSString* bundle_path = [[[exe_path stringByDeletingLastPathComponent]
|
||||
stringByDeletingLastPathComponent]
|
||||
stringByDeletingLastPathComponent];
|
||||
NSBundle* bundle = [NSBundle bundleWithPath:bundle_path];
|
||||
if (bundle) {
|
||||
NSString* ns_version =
|
||||
[bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
|
||||
if (ns_version) {
|
||||
*version = base::SysNSStringToUTF8(ns_version);
|
||||
} else {
|
||||
DLOG(ERROR) << "Unable to get version at: "
|
||||
<< reinterpret_cast<CFStringRef>(bundle_path);
|
||||
}
|
||||
} else {
|
||||
DLOG(ERROR) << "Unable to get version at: "
|
||||
// The bundle has been deleted out from underneath the registered
|
||||
// job.
|
||||
DLOG(ERROR) << "Unable to get bundle at: "
|
||||
<< reinterpret_cast<CFStringRef>(bundle_path);
|
||||
}
|
||||
} else {
|
||||
// The bundle has been deleted out from underneath the registered
|
||||
// job.
|
||||
DLOG(ERROR) << "Unable to get bundle at: "
|
||||
<< reinterpret_cast<CFStringRef>(bundle_path);
|
||||
DLOG(ERROR) << "Unable to get executable path for service process";
|
||||
}
|
||||
} else {
|
||||
DLOG(ERROR) << "Unable to get executable path for service process";
|
||||
}
|
||||
if (pid) {
|
||||
*pid = info.pid ? *info.pid : -1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (pid) {
|
||||
*pid = info.pid ? *info.pid : -1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ServiceProcessState::Initialize() {
|
||||
@ -211,43 +213,41 @@ mac::services::JobOptions GetServiceProcessJobOptions(
|
||||
|
||||
CFDictionaryRef CreateServiceProcessLaunchdPlist(base::CommandLine* cmd_line,
|
||||
bool for_auto_launch) {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
NSString* program = base::SysUTF8ToNSString(cmd_line->GetProgram().value());
|
||||
|
||||
NSString* program =
|
||||
base::SysUTF8ToNSString(cmd_line->GetProgram().value());
|
||||
std::vector<std::string> args = cmd_line->argv();
|
||||
NSMutableArray* ns_args = [NSMutableArray arrayWithCapacity:args.size()];
|
||||
|
||||
std::vector<std::string> args = cmd_line->argv();
|
||||
NSMutableArray* ns_args = [NSMutableArray arrayWithCapacity:args.size()];
|
||||
for (std::vector<std::string>::iterator iter = args.begin();
|
||||
iter < args.end(); ++iter) {
|
||||
[ns_args addObject:base::SysUTF8ToNSString(*iter)];
|
||||
}
|
||||
|
||||
for (std::vector<std::string>::iterator iter = args.begin();
|
||||
iter < args.end();
|
||||
++iter) {
|
||||
[ns_args addObject:base::SysUTF8ToNSString(*iter)];
|
||||
// See the man page for launchd.plist.
|
||||
NSMutableDictionary* launchd_plist = [@{
|
||||
@LAUNCH_JOBKEY_LABEL : GetServiceProcessLaunchDLabel(),
|
||||
@LAUNCH_JOBKEY_PROGRAM : program,
|
||||
@LAUNCH_JOBKEY_PROGRAMARGUMENTS : ns_args,
|
||||
@LAUNCH_JOBKEY_MACHSERVICES : GetServiceProcessMachName(),
|
||||
} mutableCopy];
|
||||
|
||||
if (for_auto_launch) {
|
||||
// We want the service process to be able to exit if there are no services
|
||||
// enabled. With a value of NO in the SuccessfulExit key, launchd will
|
||||
// relaunch the service automatically in any other case than exiting
|
||||
// cleanly with a 0 return code.
|
||||
NSDictionary* keep_alive =
|
||||
@{@LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT : @NO};
|
||||
NSDictionary* auto_launchd_plist = @{
|
||||
@LAUNCH_JOBKEY_RUNATLOAD : @YES,
|
||||
@LAUNCH_JOBKEY_KEEPALIVE : keep_alive,
|
||||
@LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE : @kServiceProcessSessionType
|
||||
};
|
||||
[launchd_plist addEntriesFromDictionary:auto_launchd_plist];
|
||||
}
|
||||
return reinterpret_cast<CFDictionaryRef>(launchd_plist);
|
||||
}
|
||||
|
||||
// See the man page for launchd.plist.
|
||||
NSMutableDictionary* launchd_plist = [@{
|
||||
@LAUNCH_JOBKEY_LABEL : GetServiceProcessLaunchDLabel(),
|
||||
@LAUNCH_JOBKEY_PROGRAM : program,
|
||||
@LAUNCH_JOBKEY_PROGRAMARGUMENTS : ns_args,
|
||||
@LAUNCH_JOBKEY_MACHSERVICES : GetServiceProcessMachName(),
|
||||
} mutableCopy];
|
||||
|
||||
if (for_auto_launch) {
|
||||
// We want the service process to be able to exit if there are no services
|
||||
// enabled. With a value of NO in the SuccessfulExit key, launchd will
|
||||
// relaunch the service automatically in any other case than exiting
|
||||
// cleanly with a 0 return code.
|
||||
NSDictionary* keep_alive =
|
||||
@{ @LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT : @NO };
|
||||
NSDictionary* auto_launchd_plist = @{
|
||||
@LAUNCH_JOBKEY_RUNATLOAD : @YES,
|
||||
@LAUNCH_JOBKEY_KEEPALIVE : keep_alive,
|
||||
@LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE : @kServiceProcessSessionType
|
||||
};
|
||||
[launchd_plist addEntriesFromDictionary:auto_launchd_plist];
|
||||
}
|
||||
return reinterpret_cast<CFDictionaryRef>(launchd_plist);
|
||||
}
|
||||
|
||||
// Writes the launchd property list into the user's LaunchAgents directory,
|
||||
@ -272,24 +272,23 @@ bool ServiceProcessState::RemoveFromAutoRun() {
|
||||
}
|
||||
|
||||
bool ServiceProcessState::StateData::WatchExecutable() {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
|
||||
base::FilePath executable_path = base::FilePath(job_info.program);
|
||||
std::unique_ptr<ExecFilePathWatcherCallback> callback(
|
||||
new ExecFilePathWatcherCallback);
|
||||
if (!callback->Init(executable_path)) {
|
||||
DLOG(ERROR) << "executable_watcher.Init " << executable_path.value();
|
||||
return false;
|
||||
@autoreleasepool {
|
||||
base::FilePath executable_path = base::FilePath(job_info.program);
|
||||
std::unique_ptr<ExecFilePathWatcherCallback> callback(
|
||||
new ExecFilePathWatcherCallback);
|
||||
if (!callback->Init(executable_path)) {
|
||||
DLOG(ERROR) << "executable_watcher.Init " << executable_path.value();
|
||||
return false;
|
||||
}
|
||||
if (!executable_watcher.Watch(
|
||||
executable_path, false,
|
||||
base::Bind(&ExecFilePathWatcherCallback::NotifyPathChanged,
|
||||
base::Owned(callback.release())))) {
|
||||
DLOG(ERROR) << "executable_watcher.watch " << executable_path.value();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!executable_watcher.Watch(
|
||||
executable_path,
|
||||
false,
|
||||
base::Bind(&ExecFilePathWatcherCallback::NotifyPathChanged,
|
||||
base::Owned(callback.release())))) {
|
||||
DLOG(ERROR) << "executable_watcher.watch " << executable_path.value();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExecFilePathWatcherCallback::Init(const base::FilePath& path) {
|
||||
@ -306,103 +305,100 @@ void ExecFilePathWatcherCallback::NotifyPathChanged(const base::FilePath& path,
|
||||
return;
|
||||
}
|
||||
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
bool needs_shutdown = false;
|
||||
bool needs_restart = false;
|
||||
bool good_bundle = false;
|
||||
@autoreleasepool {
|
||||
bool needs_shutdown = false;
|
||||
bool needs_restart = false;
|
||||
bool good_bundle = false;
|
||||
|
||||
// Go from bundle/Contents/MacOS/executable to bundle.
|
||||
NSURL* bundle_url = [[[executable_fsref_ URLByDeletingLastPathComponent]
|
||||
URLByDeletingLastPathComponent] URLByDeletingLastPathComponent];
|
||||
if (bundle_url) {
|
||||
base::ScopedCFTypeRef<CFBundleRef> bundle(
|
||||
CFBundleCreate(kCFAllocatorDefault, base::mac::NSToCFCast(bundle_url)));
|
||||
good_bundle = CFBundleGetIdentifier(bundle) != NULL;
|
||||
}
|
||||
|
||||
if (!good_bundle) {
|
||||
needs_shutdown = true;
|
||||
} else {
|
||||
bool in_trash = false;
|
||||
NSFileManager* file_manager = [NSFileManager defaultManager];
|
||||
NSURLRelationship relationship;
|
||||
if ([file_manager getRelationship:&relationship
|
||||
ofDirectory:NSTrashDirectory
|
||||
inDomain:0
|
||||
toItemAtURL:executable_fsref_
|
||||
error:nil]) {
|
||||
in_trash = relationship == NSURLRelationshipContains;
|
||||
// Go from bundle/Contents/MacOS/executable to bundle.
|
||||
NSURL* bundle_url = [[[executable_fsref_ URLByDeletingLastPathComponent]
|
||||
URLByDeletingLastPathComponent] URLByDeletingLastPathComponent];
|
||||
if (bundle_url) {
|
||||
base::ScopedCFTypeRef<CFBundleRef> bundle(CFBundleCreate(
|
||||
kCFAllocatorDefault, base::mac::NSToCFCast(bundle_url)));
|
||||
good_bundle = CFBundleGetIdentifier(bundle) != NULL;
|
||||
}
|
||||
if (in_trash) {
|
||||
|
||||
if (!good_bundle) {
|
||||
needs_shutdown = true;
|
||||
} else {
|
||||
bool was_moved = true;
|
||||
NSString* path_string = base::mac::FilePathToNSString(path);
|
||||
NSURL* path_url = [NSURL fileURLWithPath:path_string isDirectory:NO];
|
||||
NSURL* path_ref = [path_url fileReferenceURL];
|
||||
if (path_ref != nil) {
|
||||
if ([path_ref isEqual:executable_fsref_]) {
|
||||
was_moved = false;
|
||||
bool in_trash = false;
|
||||
NSFileManager* file_manager = [NSFileManager defaultManager];
|
||||
NSURLRelationship relationship;
|
||||
if ([file_manager getRelationship:&relationship
|
||||
ofDirectory:NSTrashDirectory
|
||||
inDomain:0
|
||||
toItemAtURL:executable_fsref_
|
||||
error:nil]) {
|
||||
in_trash = relationship == NSURLRelationshipContains;
|
||||
}
|
||||
if (in_trash) {
|
||||
needs_shutdown = true;
|
||||
} else {
|
||||
bool was_moved = true;
|
||||
NSString* path_string = base::mac::FilePathToNSString(path);
|
||||
NSURL* path_url = [NSURL fileURLWithPath:path_string isDirectory:NO];
|
||||
NSURL* path_ref = [path_url fileReferenceURL];
|
||||
if (path_ref != nil) {
|
||||
if ([path_ref isEqual:executable_fsref_]) {
|
||||
was_moved = false;
|
||||
}
|
||||
}
|
||||
if (was_moved) {
|
||||
needs_restart = true;
|
||||
}
|
||||
}
|
||||
if (was_moved) {
|
||||
needs_restart = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (needs_shutdown || needs_restart) {
|
||||
// First deal with the plist.
|
||||
base::ScopedCFTypeRef<CFStringRef> name(CopyServiceProcessLaunchDName());
|
||||
if (needs_restart) {
|
||||
base::ScopedCFTypeRef<CFMutableDictionaryRef> plist(
|
||||
Launchd::GetInstance()->CreatePlistFromFile(
|
||||
Launchd::User, Launchd::Agent, name));
|
||||
if (plist.get()) {
|
||||
NSMutableDictionary* ns_plist = base::mac::CFToNSCast(plist);
|
||||
NSURL* new_path = [executable_fsref_ filePathURL];
|
||||
DCHECK([new_path isFileURL]);
|
||||
NSString* ns_new_path = [new_path path];
|
||||
ns_plist[@LAUNCH_JOBKEY_PROGRAM] = ns_new_path;
|
||||
base::scoped_nsobject<NSMutableArray> args(
|
||||
[ns_plist[@LAUNCH_JOBKEY_PROGRAMARGUMENTS] mutableCopy]);
|
||||
args[0] = ns_new_path;
|
||||
ns_plist[@LAUNCH_JOBKEY_PROGRAMARGUMENTS] = args;
|
||||
if (!Launchd::GetInstance()->WritePlistToFile(Launchd::User,
|
||||
Launchd::Agent,
|
||||
name,
|
||||
plist)) {
|
||||
DLOG(ERROR) << "Unable to rewrite plist.";
|
||||
if (needs_shutdown || needs_restart) {
|
||||
// First deal with the plist.
|
||||
base::ScopedCFTypeRef<CFStringRef> name(CopyServiceProcessLaunchDName());
|
||||
if (needs_restart) {
|
||||
base::ScopedCFTypeRef<CFMutableDictionaryRef> plist(
|
||||
Launchd::GetInstance()->CreatePlistFromFile(Launchd::User,
|
||||
Launchd::Agent, name));
|
||||
if (plist.get()) {
|
||||
NSMutableDictionary* ns_plist = base::mac::CFToNSCast(plist);
|
||||
NSURL* new_path = [executable_fsref_ filePathURL];
|
||||
DCHECK([new_path isFileURL]);
|
||||
NSString* ns_new_path = [new_path path];
|
||||
ns_plist[@LAUNCH_JOBKEY_PROGRAM] = ns_new_path;
|
||||
base::scoped_nsobject<NSMutableArray> args(
|
||||
[ns_plist[@LAUNCH_JOBKEY_PROGRAMARGUMENTS] mutableCopy]);
|
||||
args[0] = ns_new_path;
|
||||
ns_plist[@LAUNCH_JOBKEY_PROGRAMARGUMENTS] = args;
|
||||
if (!Launchd::GetInstance()->WritePlistToFile(
|
||||
Launchd::User, Launchd::Agent, name, plist)) {
|
||||
DLOG(ERROR) << "Unable to rewrite plist.";
|
||||
needs_shutdown = true;
|
||||
}
|
||||
} else {
|
||||
DLOG(ERROR) << "Unable to read plist.";
|
||||
needs_shutdown = true;
|
||||
}
|
||||
} else {
|
||||
DLOG(ERROR) << "Unable to read plist.";
|
||||
needs_shutdown = true;
|
||||
}
|
||||
}
|
||||
if (needs_shutdown) {
|
||||
if (!RemoveFromLaunchd()) {
|
||||
DLOG(ERROR) << "Unable to RemoveFromLaunchd.";
|
||||
if (needs_shutdown) {
|
||||
if (!RemoveFromLaunchd()) {
|
||||
DLOG(ERROR) << "Unable to RemoveFromLaunchd.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Then deal with the process.
|
||||
CFStringRef session_type = CFSTR(kServiceProcessSessionType);
|
||||
if (needs_restart) {
|
||||
if (!Launchd::GetInstance()->RestartJob(Launchd::User,
|
||||
Launchd::Agent,
|
||||
name,
|
||||
session_type)) {
|
||||
DLOG(ERROR) << "RestartLaunchdJob";
|
||||
needs_shutdown = true;
|
||||
// Then deal with the process.
|
||||
CFStringRef session_type = CFSTR(kServiceProcessSessionType);
|
||||
if (needs_restart) {
|
||||
if (!Launchd::GetInstance()->RestartJob(Launchd::User, Launchd::Agent,
|
||||
name, session_type)) {
|
||||
DLOG(ERROR) << "RestartLaunchdJob";
|
||||
needs_shutdown = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (needs_shutdown) {
|
||||
const std::string& label =
|
||||
base::SysNSStringToUTF8(GetServiceProcessLaunchDLabel());
|
||||
if (!Launchd::GetInstance()->RemoveJob(label)) {
|
||||
DLOG(ERROR) << "RemoveJob " << label;
|
||||
// Exiting with zero, so launchd doesn't restart the process.
|
||||
exit(0);
|
||||
if (needs_shutdown) {
|
||||
const std::string& label =
|
||||
base::SysNSStringToUTF8(GetServiceProcessLaunchDLabel());
|
||||
if (!Launchd::GetInstance()->RemoveJob(label)) {
|
||||
DLOG(ERROR) << "RemoveJob " << label;
|
||||
// Exiting with zero, so launchd doesn't restart the process.
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include "chrome/test/base/in_process_browser_test.h"
|
||||
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "chrome/browser/devtools/devtools_window.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
@ -18,26 +17,26 @@ void InProcessBrowserTest::OpenDevToolsWindow(
|
||||
content::WebContents* web_contents) {
|
||||
// Opening a Devtools Window can cause AppKit to throw objects into the
|
||||
// autorelease pool. Flush the pool when this function returns.
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
|
||||
ASSERT_FALSE(content::DevToolsAgentHost::HasFor(web_contents));
|
||||
DevToolsWindow::OpenDevToolsWindow(web_contents);
|
||||
ASSERT_TRUE(content::DevToolsAgentHost::HasFor(web_contents));
|
||||
@autoreleasepool {
|
||||
ASSERT_FALSE(content::DevToolsAgentHost::HasFor(web_contents));
|
||||
DevToolsWindow::OpenDevToolsWindow(web_contents);
|
||||
ASSERT_TRUE(content::DevToolsAgentHost::HasFor(web_contents));
|
||||
}
|
||||
}
|
||||
|
||||
Browser* InProcessBrowserTest::OpenURLOffTheRecord(Profile* profile,
|
||||
const GURL& url) {
|
||||
// Opening an incognito window can cause AppKit to throw objects into the
|
||||
// autorelease pool. Flush the pool when this function returns.
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
|
||||
chrome::OpenURLOffTheRecord(profile, url);
|
||||
Browser* browser =
|
||||
chrome::FindTabbedBrowser(profile->GetOffTheRecordProfile(), false);
|
||||
content::TestNavigationObserver observer(
|
||||
browser->tab_strip_model()->GetActiveWebContents());
|
||||
observer.Wait();
|
||||
return browser;
|
||||
@autoreleasepool {
|
||||
chrome::OpenURLOffTheRecord(profile, url);
|
||||
Browser* browser =
|
||||
chrome::FindTabbedBrowser(profile->GetOffTheRecordProfile(), false);
|
||||
content::TestNavigationObserver observer(
|
||||
browser->tab_strip_model()->GetActiveWebContents());
|
||||
observer.Wait();
|
||||
return browser;
|
||||
}
|
||||
}
|
||||
|
||||
// Creates a browser with a single tab (about:blank), waits for the tab to
|
||||
@ -45,48 +44,48 @@ Browser* InProcessBrowserTest::OpenURLOffTheRecord(Profile* profile,
|
||||
Browser* InProcessBrowserTest::CreateBrowser(Profile* profile) {
|
||||
// Making a browser window can cause AppKit to throw objects into the
|
||||
// autorelease pool. Flush the pool when this function returns.
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
|
||||
Browser* browser = new Browser(Browser::CreateParams(profile, true));
|
||||
AddBlankTabAndShow(browser);
|
||||
return browser;
|
||||
@autoreleasepool {
|
||||
Browser* browser = new Browser(Browser::CreateParams(profile, true));
|
||||
AddBlankTabAndShow(browser);
|
||||
return browser;
|
||||
}
|
||||
}
|
||||
|
||||
Browser* InProcessBrowserTest::CreateIncognitoBrowser(Profile* profile) {
|
||||
// Making a browser window can cause AppKit to throw objects into the
|
||||
// autorelease pool. Flush the pool when this function returns.
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
// Use active profile if default nullptr was passed.
|
||||
if (!profile)
|
||||
profile = browser()->profile();
|
||||
|
||||
// Use active profile if default nullptr was passed.
|
||||
if (!profile)
|
||||
profile = browser()->profile();
|
||||
|
||||
// Create a new browser with using the incognito profile.
|
||||
Browser* incognito = new Browser(
|
||||
Browser::CreateParams(profile->GetOffTheRecordProfile(), true));
|
||||
AddBlankTabAndShow(incognito);
|
||||
return incognito;
|
||||
// Create a new browser with using the incognito profile.
|
||||
Browser* incognito = new Browser(
|
||||
Browser::CreateParams(profile->GetOffTheRecordProfile(), true));
|
||||
AddBlankTabAndShow(incognito);
|
||||
return incognito;
|
||||
}
|
||||
}
|
||||
|
||||
Browser* InProcessBrowserTest::CreateBrowserForPopup(Profile* profile) {
|
||||
// Making a browser window can cause AppKit to throw objects into the
|
||||
// autorelease pool. Flush the pool when this function returns.
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
|
||||
Browser* browser =
|
||||
new Browser(Browser::CreateParams(Browser::TYPE_POPUP, profile, true));
|
||||
AddBlankTabAndShow(browser);
|
||||
return browser;
|
||||
@autoreleasepool {
|
||||
Browser* browser =
|
||||
new Browser(Browser::CreateParams(Browser::TYPE_POPUP, profile, true));
|
||||
AddBlankTabAndShow(browser);
|
||||
return browser;
|
||||
}
|
||||
}
|
||||
|
||||
Browser* InProcessBrowserTest::CreateBrowserForApp(const std::string& app_name,
|
||||
Profile* profile) {
|
||||
// Making a browser window can cause AppKit to throw objects into the
|
||||
// autorelease pool. Flush the pool when this function returns.
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
|
||||
Browser* browser = new Browser(Browser::CreateParams::CreateForApp(
|
||||
app_name, false /* trusted_source */, gfx::Rect(), profile, true));
|
||||
AddBlankTabAndShow(browser);
|
||||
return browser;
|
||||
@autoreleasepool {
|
||||
Browser* browser = new Browser(Browser::CreateParams::CreateForApp(
|
||||
app_name, false /* trusted_source */, gfx::Rect(), profile, true));
|
||||
AddBlankTabAndShow(browser);
|
||||
return browser;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/i18n/icu_util.h"
|
||||
#include "base/i18n/message_formatter.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "base/strings/string_util.h"
|
||||
@ -154,188 +153,188 @@ const char kAppType_Helper[] = "helper"; // Helper app
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char* const argv[]) {
|
||||
base::mac::ScopedNSAutoreleasePool autorelease_pool;
|
||||
@autoreleasepool {
|
||||
const char* version_file_path = NULL;
|
||||
const char* grit_output_dir = NULL;
|
||||
const char* branding_strings_name = NULL;
|
||||
const char* output_dir = NULL;
|
||||
const char* app_type = kAppType_Main;
|
||||
|
||||
const char* version_file_path = NULL;
|
||||
const char* grit_output_dir = NULL;
|
||||
const char* branding_strings_name = NULL;
|
||||
const char* output_dir = NULL;
|
||||
const char* app_type = kAppType_Main;
|
||||
|
||||
// Process the args
|
||||
int ch;
|
||||
while ((ch = getopt(argc, argv, "t:v:g:b:o:")) != -1) {
|
||||
switch (ch) {
|
||||
case 't':
|
||||
app_type = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
version_file_path = optarg;
|
||||
break;
|
||||
case 'g':
|
||||
grit_output_dir = optarg;
|
||||
break;
|
||||
case 'b':
|
||||
branding_strings_name = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
output_dir = optarg;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "ERROR: bad command line arg\n");
|
||||
exit(1);
|
||||
break;
|
||||
// Process the args
|
||||
int ch;
|
||||
while ((ch = getopt(argc, argv, "t:v:g:b:o:")) != -1) {
|
||||
switch (ch) {
|
||||
case 't':
|
||||
app_type = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
version_file_path = optarg;
|
||||
break;
|
||||
case 'g':
|
||||
grit_output_dir = optarg;
|
||||
break;
|
||||
case 'b':
|
||||
branding_strings_name = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
output_dir = optarg;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "ERROR: bad command line arg\n");
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
#define CHECK_ARG(a, b) \
|
||||
do { \
|
||||
if ((a)) { \
|
||||
fprintf(stderr, "ERROR: " b "\n"); \
|
||||
exit(1); \
|
||||
} \
|
||||
} while (false)
|
||||
do { \
|
||||
if ((a)) { \
|
||||
fprintf(stderr, "ERROR: " b "\n"); \
|
||||
exit(1); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
// Check our args
|
||||
CHECK_ARG(!version_file_path, "Missing VERSION file path");
|
||||
CHECK_ARG(!grit_output_dir, "Missing grit output dir path");
|
||||
CHECK_ARG(!output_dir, "Missing path to write InfoPlist.strings files");
|
||||
CHECK_ARG(!branding_strings_name, "Missing branding strings file name");
|
||||
CHECK_ARG(argc == 0, "Missing language list");
|
||||
CHECK_ARG((strcmp(app_type, kAppType_Main) != 0 &&
|
||||
strcmp(app_type, kAppType_Helper) != 0),
|
||||
"Unknown app type");
|
||||
// Check our args
|
||||
CHECK_ARG(!version_file_path, "Missing VERSION file path");
|
||||
CHECK_ARG(!grit_output_dir, "Missing grit output dir path");
|
||||
CHECK_ARG(!output_dir, "Missing path to write InfoPlist.strings files");
|
||||
CHECK_ARG(!branding_strings_name, "Missing branding strings file name");
|
||||
CHECK_ARG(argc == 0, "Missing language list");
|
||||
CHECK_ARG((strcmp(app_type, kAppType_Main) != 0 &&
|
||||
strcmp(app_type, kAppType_Helper) != 0),
|
||||
"Unknown app type");
|
||||
|
||||
char* const* lang_list = argv;
|
||||
int lang_list_count = argc;
|
||||
char* const* lang_list = argv;
|
||||
int lang_list_count = argc;
|
||||
|
||||
base::i18n::InitializeICU();
|
||||
base::i18n::InitializeICU();
|
||||
|
||||
// Parse the version file and build our string
|
||||
NSString* version_string = ApplicationVersionString(version_file_path);
|
||||
if (!version_string) {
|
||||
fprintf(stderr, "ERROR: failed to get a version string");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
NSFileManager* fm = [NSFileManager defaultManager];
|
||||
|
||||
for (int loop = 0; loop < lang_list_count; ++loop) {
|
||||
const char* cur_lang = lang_list[loop];
|
||||
|
||||
// Open the branded string pak file
|
||||
std::unique_ptr<ui::DataPack> branded_data_pack(
|
||||
LoadResourceDataPack(grit_output_dir, branding_strings_name, cur_lang));
|
||||
if (branded_data_pack.get() == NULL) {
|
||||
fprintf(stderr, "ERROR: Failed to load branded pak for language: %s\n",
|
||||
cur_lang);
|
||||
// Parse the version file and build our string
|
||||
NSString* version_string = ApplicationVersionString(version_file_path);
|
||||
if (!version_string) {
|
||||
fprintf(stderr, "ERROR: failed to get a version string");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
uint32_t name_id = IDS_PRODUCT_NAME;
|
||||
const char* name_id_str = "IDS_PRODUCT_NAME";
|
||||
uint32_t short_name_id = IDS_APP_MENU_PRODUCT_NAME;
|
||||
const char* short_name_id_str = "IDS_APP_MENU_PRODUCT_NAME";
|
||||
if (strcmp(app_type, kAppType_Helper) == 0) {
|
||||
name_id = IDS_HELPER_NAME;
|
||||
name_id_str = "IDS_HELPER_NAME";
|
||||
short_name_id = IDS_SHORT_HELPER_NAME;
|
||||
short_name_id_str = "IDS_SHORT_HELPER_NAME";
|
||||
}
|
||||
NSFileManager* fm = [NSFileManager defaultManager];
|
||||
|
||||
// Fetch the strings.
|
||||
NSString* name =
|
||||
for (int loop = 0; loop < lang_list_count; ++loop) {
|
||||
const char* cur_lang = lang_list[loop];
|
||||
|
||||
// Open the branded string pak file
|
||||
std::unique_ptr<ui::DataPack> branded_data_pack(
|
||||
LoadResourceDataPack(grit_output_dir, branding_strings_name, cur_lang));
|
||||
if (branded_data_pack.get() == NULL) {
|
||||
fprintf(stderr, "ERROR: Failed to load branded pak for language: %s\n",
|
||||
cur_lang);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
uint32_t name_id = IDS_PRODUCT_NAME;
|
||||
const char* name_id_str = "IDS_PRODUCT_NAME";
|
||||
uint32_t short_name_id = IDS_APP_MENU_PRODUCT_NAME;
|
||||
const char* short_name_id_str = "IDS_APP_MENU_PRODUCT_NAME";
|
||||
if (strcmp(app_type, kAppType_Helper) == 0) {
|
||||
name_id = IDS_HELPER_NAME;
|
||||
name_id_str = "IDS_HELPER_NAME";
|
||||
short_name_id = IDS_SHORT_HELPER_NAME;
|
||||
short_name_id_str = "IDS_SHORT_HELPER_NAME";
|
||||
}
|
||||
|
||||
// Fetch the strings.
|
||||
NSString* name =
|
||||
LoadStringFromDataPack(branded_data_pack.get(), cur_lang,
|
||||
name_id, name_id_str);
|
||||
NSString* short_name =
|
||||
LoadStringFromDataPack(branded_data_pack.get(), cur_lang,
|
||||
short_name_id, short_name_id_str);
|
||||
NSString* copyright_format =
|
||||
LoadStringFromDataPack(branded_data_pack.get(), cur_lang,
|
||||
name_id, name_id_str);
|
||||
NSString* short_name =
|
||||
IDS_ABOUT_VERSION_COPYRIGHT,
|
||||
"IDS_ABOUT_VERSION_COPYRIGHT");
|
||||
|
||||
NSString* copyright = base::SysUTF16ToNSString(
|
||||
base::i18n::MessageFormatter::FormatWithNumberedArgs(
|
||||
base::SysNSStringToUTF16(copyright_format), base::Time::Now()));
|
||||
|
||||
NSString* permission_reason =
|
||||
LoadStringFromDataPack(branded_data_pack.get(), cur_lang,
|
||||
short_name_id, short_name_id_str);
|
||||
NSString* copyright_format =
|
||||
LoadStringFromDataPack(branded_data_pack.get(), cur_lang,
|
||||
IDS_ABOUT_VERSION_COPYRIGHT,
|
||||
"IDS_ABOUT_VERSION_COPYRIGHT");
|
||||
IDS_RUNTIME_PERMISSION_OS_REASON_TEXT,
|
||||
"IDS_RUNTIME_PERMISSION_OS_REASON_TEXT");
|
||||
|
||||
NSString* copyright = base::SysUTF16ToNSString(
|
||||
base::i18n::MessageFormatter::FormatWithNumberedArgs(
|
||||
base::SysNSStringToUTF16(copyright_format), base::Time::Now()));
|
||||
// For now, assume this is ok for all languages. If we need to, this could
|
||||
// be moved into generated_resources.grd and fetched.
|
||||
NSString* get_info = [NSString
|
||||
stringWithFormat:@"%@ %@, %@", name, version_string, copyright];
|
||||
|
||||
NSString* permission_reason =
|
||||
LoadStringFromDataPack(branded_data_pack.get(), cur_lang,
|
||||
IDS_RUNTIME_PERMISSION_OS_REASON_TEXT,
|
||||
"IDS_RUNTIME_PERMISSION_OS_REASON_TEXT");
|
||||
// Generate the InfoPlist.strings file contents.
|
||||
NSDictionary<NSString*, NSString*>* infoplist_strings = @{
|
||||
@"CFBundleDisplayName" : name,
|
||||
@"CFBundleGetInfoString" : get_info,
|
||||
@"CFBundleName" : short_name,
|
||||
@"NSHumanReadableCopyright" : copyright,
|
||||
@"NSLocationUsageDescription" : permission_reason,
|
||||
@"NSMicrophoneUsageDescription" : permission_reason,
|
||||
@"NSCameraUsageDescription" : permission_reason,
|
||||
@"NSBluetoothPeripheralUsageDescription" : permission_reason,
|
||||
};
|
||||
base::scoped_nsobject<NSMutableString> strings_file_contents_string(
|
||||
[[NSMutableString alloc] init]);
|
||||
for (NSString* key in infoplist_strings) {
|
||||
[strings_file_contents_string
|
||||
appendFormat:@"%@ = \"%@\";\n", key,
|
||||
EscapeForStringsFileValue(infoplist_strings[key])];
|
||||
}
|
||||
|
||||
// For now, assume this is ok for all languages. If we need to, this could
|
||||
// be moved into generated_resources.grd and fetched.
|
||||
NSString* get_info = [NSString
|
||||
stringWithFormat:@"%@ %@, %@", name, version_string, copyright];
|
||||
// We set up Xcode projects expecting strings files to be UTF8, so make
|
||||
// sure we write the data in that form. When Xcode copies them it will
|
||||
// put them final runtime encoding.
|
||||
NSData* strings_file_contents_utf8 =
|
||||
[strings_file_contents_string dataUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
// Generate the InfoPlist.strings file contents.
|
||||
NSDictionary<NSString*, NSString*>* infoplist_strings = @{
|
||||
@"CFBundleDisplayName" : name,
|
||||
@"CFBundleGetInfoString" : get_info,
|
||||
@"CFBundleName" : short_name,
|
||||
@"NSHumanReadableCopyright" : copyright,
|
||||
@"NSLocationUsageDescription" : permission_reason,
|
||||
@"NSMicrophoneUsageDescription" : permission_reason,
|
||||
@"NSCameraUsageDescription" : permission_reason,
|
||||
@"NSBluetoothPeripheralUsageDescription" : permission_reason,
|
||||
};
|
||||
base::scoped_nsobject<NSMutableString> strings_file_contents_string(
|
||||
[[NSMutableString alloc] init]);
|
||||
for (NSString* key in infoplist_strings) {
|
||||
[strings_file_contents_string
|
||||
appendFormat:@"%@ = \"%@\";\n", key,
|
||||
EscapeForStringsFileValue(infoplist_strings[key])];
|
||||
}
|
||||
|
||||
// We set up Xcode projects expecting strings files to be UTF8, so make
|
||||
// sure we write the data in that form. When Xcode copies them it will
|
||||
// put them final runtime encoding.
|
||||
NSData* strings_file_contents_utf8 =
|
||||
[strings_file_contents_string dataUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
if ([strings_file_contents_utf8 length] == 0) {
|
||||
fprintf(stderr, "ERROR: failed to get the utf8 encoding of the strings "
|
||||
"file for language: %s\n", cur_lang);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// For Cocoa to find the locale at runtime, it needs to use '_' instead of
|
||||
// '-' (http://crbug.com/20441). Also, 'en-US' should be represented
|
||||
// simply as 'en' (http://crbug.com/19165, http://crbug.com/25578).
|
||||
NSString* cur_lang_ns = [NSString stringWithUTF8String:cur_lang];
|
||||
if ([cur_lang_ns isEqualToString:@"en-US"]) {
|
||||
cur_lang_ns = @"en";
|
||||
}
|
||||
cur_lang_ns = [cur_lang_ns stringByReplacingOccurrencesOfString:@"-"
|
||||
withString:@"_"];
|
||||
// Make sure the lproj we write to exists
|
||||
NSString *lproj_name = [NSString stringWithFormat:@"%@.lproj", cur_lang_ns];
|
||||
NSString *output_path =
|
||||
[[NSString stringWithUTF8String:output_dir]
|
||||
stringByAppendingPathComponent:lproj_name];
|
||||
NSError* error = nil;
|
||||
if (![fm fileExistsAtPath:output_path] &&
|
||||
![fm createDirectoryAtPath:output_path
|
||||
withIntermediateDirectories:YES
|
||||
attributes:nil
|
||||
error:&error]) {
|
||||
fprintf(stderr, "ERROR: '%s' didn't exist or we failed to create it\n",
|
||||
[output_path UTF8String]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Write out the file
|
||||
output_path =
|
||||
[output_path stringByAppendingPathComponent:@"InfoPlist.strings"];
|
||||
if (![strings_file_contents_utf8 writeToFile:output_path
|
||||
atomically:YES]) {
|
||||
fprintf(stderr, "ERROR: Failed to write out '%s'\n",
|
||||
[output_path UTF8String]);
|
||||
exit(1);
|
||||
if ([strings_file_contents_utf8 length] == 0) {
|
||||
fprintf(stderr, "ERROR: failed to get the utf8 encoding of the strings "
|
||||
"file for language: %s\n", cur_lang);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// For Cocoa to find the locale at runtime, it needs to use '_' instead of
|
||||
// '-' (http://crbug.com/20441). Also, 'en-US' should be represented
|
||||
// simply as 'en' (http://crbug.com/19165, http://crbug.com/25578).
|
||||
NSString* cur_lang_ns = [NSString stringWithUTF8String:cur_lang];
|
||||
if ([cur_lang_ns isEqualToString:@"en-US"]) {
|
||||
cur_lang_ns = @"en";
|
||||
}
|
||||
cur_lang_ns = [cur_lang_ns stringByReplacingOccurrencesOfString:@"-"
|
||||
withString:@"_"];
|
||||
// Make sure the lproj we write to exists
|
||||
NSString *lproj_name = [NSString stringWithFormat:@"%@.lproj", cur_lang_ns];
|
||||
NSString *output_path =
|
||||
[[NSString stringWithUTF8String:output_dir]
|
||||
stringByAppendingPathComponent:lproj_name];
|
||||
NSError* error = nil;
|
||||
if (![fm fileExistsAtPath:output_path] &&
|
||||
![fm createDirectoryAtPath:output_path
|
||||
withIntermediateDirectories:YES
|
||||
attributes:nil
|
||||
error:&error]) {
|
||||
fprintf(stderr, "ERROR: '%s' didn't exist or we failed to create it\n",
|
||||
[output_path UTF8String]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Write out the file
|
||||
output_path =
|
||||
[output_path stringByAppendingPathComponent:@"InfoPlist.strings"];
|
||||
if (![strings_file_contents_utf8 writeToFile:output_path
|
||||
atomically:YES]) {
|
||||
fprintf(stderr, "ERROR: Failed to write out '%s'\n",
|
||||
[output_path UTF8String]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -7,24 +7,24 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "components/history/core/test/thumbnail-inl.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
|
||||
namespace history {
|
||||
|
||||
gfx::Image CreateGoogleThumbnailForTest() {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
// -[NSData dataWithBytesNoCopy:length:freeWhenDone:] takes it first parameter
|
||||
// as a void* but does not modify it (API is not const clean) so we need to
|
||||
// use const_cast<> here.
|
||||
NSData* data =
|
||||
[NSData dataWithBytesNoCopy:const_cast<void*>(static_cast<const void*>(
|
||||
kGoogleThumbnail))
|
||||
length:sizeof(kGoogleThumbnail)
|
||||
freeWhenDone:NO];
|
||||
UIImage* image = [UIImage imageWithData:data scale:1];
|
||||
return gfx::Image([image retain]);
|
||||
@autoreleasepool {
|
||||
// -[NSData dataWithBytesNoCopy:length:freeWhenDone:] takes its first
|
||||
// parameter as a void* but does not modify it (API is not const clean) so
|
||||
// we need to use const_cast<> here.
|
||||
NSData* data = [NSData
|
||||
dataWithBytesNoCopy:const_cast<void*>(
|
||||
static_cast<const void*>(kGoogleThumbnail))
|
||||
length:sizeof(kGoogleThumbnail)
|
||||
freeWhenDone:NO];
|
||||
UIImage* image = [UIImage imageWithData:data scale:1];
|
||||
return gfx::Image([image retain]);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/mac/foundation_util.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "base/version.h"
|
||||
@ -45,29 +44,28 @@ base::Time GetUpdaterSettingsTime(NSString* value_name) {
|
||||
}
|
||||
|
||||
base::Version GetVersionFromPlist(const base::FilePath& info_plist) {
|
||||
base::mac::ScopedNSAutoreleasePool scoped_pool;
|
||||
NSData* data =
|
||||
[NSData dataWithContentsOfFile:
|
||||
base::mac::FilePathToNSString(info_plist)];
|
||||
if ([data length] == 0) {
|
||||
return base::Version();
|
||||
@autoreleasepool {
|
||||
NSData* data = [NSData
|
||||
dataWithContentsOfFile:base::mac::FilePathToNSString(info_plist)];
|
||||
if ([data length] == 0) {
|
||||
return base::Version();
|
||||
}
|
||||
NSDictionary* all_keys =
|
||||
base::mac::ObjCCastStrict<NSDictionary>([NSPropertyListSerialization
|
||||
propertyListWithData:data
|
||||
options:NSPropertyListImmutable
|
||||
format:nil
|
||||
error:nil]);
|
||||
if (all_keys == nil) {
|
||||
return base::Version();
|
||||
}
|
||||
CFStringRef version = base::mac::GetValueFromDictionary<CFStringRef>(
|
||||
base::mac::NSToCFCast(all_keys), kCFBundleVersionKey);
|
||||
if (version == NULL) {
|
||||
return base::Version();
|
||||
}
|
||||
return base::Version(base::SysCFStringRefToUTF8(version));
|
||||
}
|
||||
NSDictionary* all_keys = base::mac::ObjCCastStrict<NSDictionary>(
|
||||
[NSPropertyListSerialization propertyListWithData:data
|
||||
options:NSPropertyListImmutable
|
||||
format:nil
|
||||
error:nil]);
|
||||
if (all_keys == nil) {
|
||||
return base::Version();
|
||||
}
|
||||
CFStringRef version =
|
||||
base::mac::GetValueFromDictionary<CFStringRef>(
|
||||
base::mac::NSToCFCast(all_keys),
|
||||
kCFBundleVersionKey);
|
||||
if (version == NULL) {
|
||||
return base::Version();
|
||||
}
|
||||
return base::Version(base::SysCFStringRefToUTF8(version));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include "content/browser/renderer_host/input/synthetic_gesture_target_mac.h"
|
||||
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
|
||||
#import "content/app_shim_remote_cocoa/render_widget_host_view_cocoa.h"
|
||||
@ -88,42 +87,42 @@ void SyntheticGestureTargetMac::DispatchWebGestureEventToPlatform(
|
||||
const ui::LatencyInfo& latency_info) {
|
||||
// Create an autorelease pool so that we clean up any synthetic events we
|
||||
// generate.
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
NSPoint content_local = NSMakePoint(
|
||||
web_gesture.PositionInWidget().x,
|
||||
[cocoa_view_ frame].size.height - web_gesture.PositionInWidget().y);
|
||||
NSPoint location_in_window = [cocoa_view_ convertPoint:content_local
|
||||
toView:nil];
|
||||
|
||||
NSPoint content_local = NSMakePoint(
|
||||
web_gesture.PositionInWidget().x,
|
||||
[cocoa_view_ frame].size.height - web_gesture.PositionInWidget().y);
|
||||
NSPoint location_in_window =
|
||||
[cocoa_view_ convertPoint:content_local toView:nil];
|
||||
|
||||
switch (web_gesture.GetType()) {
|
||||
case WebInputEvent::kGesturePinchBegin: {
|
||||
id cocoa_event =
|
||||
[SyntheticPinchEvent eventWithMagnification:0.0f
|
||||
locationInWindow:location_in_window
|
||||
phase:NSEventPhaseBegan];
|
||||
[cocoa_view_ handleBeginGestureWithEvent:cocoa_event
|
||||
isSyntheticallyInjected:YES];
|
||||
return;
|
||||
switch (web_gesture.GetType()) {
|
||||
case WebInputEvent::kGesturePinchBegin: {
|
||||
id cocoa_event =
|
||||
[SyntheticPinchEvent eventWithMagnification:0.0f
|
||||
locationInWindow:location_in_window
|
||||
phase:NSEventPhaseBegan];
|
||||
[cocoa_view_ handleBeginGestureWithEvent:cocoa_event
|
||||
isSyntheticallyInjected:YES];
|
||||
return;
|
||||
}
|
||||
case WebInputEvent::kGesturePinchEnd: {
|
||||
id cocoa_event =
|
||||
[SyntheticPinchEvent eventWithMagnification:0.0f
|
||||
locationInWindow:location_in_window
|
||||
phase:NSEventPhaseEnded];
|
||||
[cocoa_view_ handleEndGestureWithEvent:cocoa_event];
|
||||
return;
|
||||
}
|
||||
case WebInputEvent::kGesturePinchUpdate: {
|
||||
id cocoa_event = [SyntheticPinchEvent
|
||||
eventWithMagnification:web_gesture.data.pinch_update.scale - 1.0f
|
||||
locationInWindow:location_in_window
|
||||
phase:NSEventPhaseChanged];
|
||||
[cocoa_view_ magnifyWithEvent:cocoa_event];
|
||||
return;
|
||||
}
|
||||
default:
|
||||
NOTREACHED();
|
||||
}
|
||||
case WebInputEvent::kGesturePinchEnd: {
|
||||
id cocoa_event =
|
||||
[SyntheticPinchEvent eventWithMagnification:0.0f
|
||||
locationInWindow:location_in_window
|
||||
phase:NSEventPhaseEnded];
|
||||
[cocoa_view_ handleEndGestureWithEvent:cocoa_event];
|
||||
return;
|
||||
}
|
||||
case WebInputEvent::kGesturePinchUpdate: {
|
||||
id cocoa_event = [SyntheticPinchEvent
|
||||
eventWithMagnification:web_gesture.data.pinch_update.scale - 1.0f
|
||||
locationInWindow:location_in_window
|
||||
phase:NSEventPhaseChanged];
|
||||
[cocoa_view_ magnifyWithEvent:cocoa_event];
|
||||
return;
|
||||
}
|
||||
default:
|
||||
NOTREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "ppapi/c/dev/ppb_truetype_font_dev.h"
|
||||
@ -36,47 +35,49 @@ const NSInteger kPepperFontWeightsLength = base::size(kPepperFontWeights);
|
||||
} // namespace
|
||||
|
||||
void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) {
|
||||
base::mac::ScopedNSAutoreleasePool autorelease_pool;
|
||||
NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease];
|
||||
NSArray* fonts = [fontManager availableFontFamilies];
|
||||
font_families->reserve([fonts count]);
|
||||
for (NSString* family_name in fonts)
|
||||
font_families->push_back(base::SysNSStringToUTF8(family_name));
|
||||
@autoreleasepool {
|
||||
NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease];
|
||||
NSArray* fonts = [fontManager availableFontFamilies];
|
||||
font_families->reserve([fonts count]);
|
||||
for (NSString* family_name in fonts)
|
||||
font_families->push_back(base::SysNSStringToUTF8(family_name));
|
||||
}
|
||||
}
|
||||
|
||||
void GetFontsInFamily_SlowBlocking(
|
||||
const std::string& family,
|
||||
std::vector<ppapi::proxy::SerializedTrueTypeFontDesc>* fonts_in_family) {
|
||||
base::mac::ScopedNSAutoreleasePool autorelease_pool;
|
||||
NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease];
|
||||
NSString* ns_family = base::SysUTF8ToNSString(family);
|
||||
NSArray* ns_fonts_in_family =
|
||||
[fontManager availableMembersOfFontFamily:ns_family];
|
||||
@autoreleasepool {
|
||||
NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease];
|
||||
NSString* ns_family = base::SysUTF8ToNSString(family);
|
||||
NSArray* ns_fonts_in_family =
|
||||
[fontManager availableMembersOfFontFamily:ns_family];
|
||||
|
||||
for (NSArray* font_info in ns_fonts_in_family) {
|
||||
ppapi::proxy::SerializedTrueTypeFontDesc desc;
|
||||
desc.family = family;
|
||||
NSInteger font_weight = [[font_info objectAtIndex:2] intValue];
|
||||
font_weight = std::max(static_cast<NSInteger>(0), font_weight);
|
||||
font_weight = std::min(kPepperFontWeightsLength - 1, font_weight);
|
||||
desc.weight = kPepperFontWeights[font_weight];
|
||||
for (NSArray* font_info in ns_fonts_in_family) {
|
||||
ppapi::proxy::SerializedTrueTypeFontDesc desc;
|
||||
desc.family = family;
|
||||
NSInteger font_weight = [[font_info objectAtIndex:2] intValue];
|
||||
font_weight = std::max(static_cast<NSInteger>(0), font_weight);
|
||||
font_weight = std::min(kPepperFontWeightsLength - 1, font_weight);
|
||||
desc.weight = kPepperFontWeights[font_weight];
|
||||
|
||||
NSFontTraitMask font_traits =
|
||||
[[font_info objectAtIndex:3] unsignedIntValue];
|
||||
desc.style = PP_TRUETYPEFONTSTYLE_NORMAL;
|
||||
if (font_traits & NSItalicFontMask)
|
||||
desc.style = PP_TRUETYPEFONTSTYLE_ITALIC;
|
||||
NSFontTraitMask font_traits =
|
||||
[[font_info objectAtIndex:3] unsignedIntValue];
|
||||
desc.style = PP_TRUETYPEFONTSTYLE_NORMAL;
|
||||
if (font_traits & NSItalicFontMask)
|
||||
desc.style = PP_TRUETYPEFONTSTYLE_ITALIC;
|
||||
|
||||
desc.width = PP_TRUETYPEFONTWIDTH_NORMAL;
|
||||
if (font_traits & NSCondensedFontMask)
|
||||
desc.width = PP_TRUETYPEFONTWIDTH_CONDENSED;
|
||||
else if (font_traits & NSExpandedFontMask)
|
||||
desc.width = PP_TRUETYPEFONTWIDTH_EXPANDED;
|
||||
desc.width = PP_TRUETYPEFONTWIDTH_NORMAL;
|
||||
if (font_traits & NSCondensedFontMask)
|
||||
desc.width = PP_TRUETYPEFONTWIDTH_CONDENSED;
|
||||
else if (font_traits & NSExpandedFontMask)
|
||||
desc.width = PP_TRUETYPEFONTWIDTH_EXPANDED;
|
||||
|
||||
// Mac doesn't support requesting non-default character sets.
|
||||
desc.charset = PP_TRUETYPEFONTCHARSET_DEFAULT;
|
||||
// Mac doesn't support requesting non-default character sets.
|
||||
desc.charset = PP_TRUETYPEFONTCHARSET_DEFAULT;
|
||||
|
||||
fonts_in_family->push_back(desc);
|
||||
fonts_in_family->push_back(desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,45 +140,45 @@ TEST_F(RenderWidgetHostViewMacEditCommandHelperWithTaskEnvTest,
|
||||
supported_factors.push_back(ui::SCALE_FACTOR_100P);
|
||||
ui::test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
|
||||
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
int32_t routing_id = process_host->GetNextRoutingID();
|
||||
mojom::WidgetPtr widget;
|
||||
std::unique_ptr<MockWidgetImpl> widget_impl =
|
||||
std::make_unique<MockWidgetImpl>(mojo::MakeRequest(&widget));
|
||||
|
||||
int32_t routing_id = process_host->GetNextRoutingID();
|
||||
mojom::WidgetPtr widget;
|
||||
std::unique_ptr<MockWidgetImpl> widget_impl =
|
||||
std::make_unique<MockWidgetImpl>(mojo::MakeRequest(&widget));
|
||||
RenderWidgetHostImpl* render_widget = new RenderWidgetHostImpl(
|
||||
&delegate, process_host, routing_id, std::move(widget), false);
|
||||
|
||||
RenderWidgetHostImpl* render_widget = new RenderWidgetHostImpl(
|
||||
&delegate, process_host, routing_id, std::move(widget), false);
|
||||
ui::WindowResizeHelperMac::Get()->Init(base::ThreadTaskRunnerHandle::Get());
|
||||
|
||||
ui::WindowResizeHelperMac::Get()->Init(base::ThreadTaskRunnerHandle::Get());
|
||||
// Owned by its |GetInProcessNSView()|, i.e. |rwhv_cocoa|.
|
||||
RenderWidgetHostViewMac* rwhv_mac =
|
||||
new RenderWidgetHostViewMac(render_widget, false);
|
||||
base::scoped_nsobject<RenderWidgetHostViewCocoa> rwhv_cocoa(
|
||||
[rwhv_mac->GetInProcessNSView() retain]);
|
||||
|
||||
// Owned by its |GetInProcessNSView()|, i.e. |rwhv_cocoa|.
|
||||
RenderWidgetHostViewMac* rwhv_mac = new RenderWidgetHostViewMac(
|
||||
render_widget, false);
|
||||
base::scoped_nsobject<RenderWidgetHostViewCocoa> rwhv_cocoa(
|
||||
[rwhv_mac->GetInProcessNSView() retain]);
|
||||
RenderWidgetHostViewMacEditCommandHelper helper;
|
||||
NSArray* edit_command_strings = helper.GetEditSelectorNames();
|
||||
RenderWidgetHostNSViewHostOwner* rwhwvm_owner =
|
||||
[[[RenderWidgetHostNSViewHostOwner alloc]
|
||||
initWithRenderWidgetHostViewMac:rwhv_mac] autorelease];
|
||||
|
||||
RenderWidgetHostViewMacEditCommandHelper helper;
|
||||
NSArray* edit_command_strings = helper.GetEditSelectorNames();
|
||||
RenderWidgetHostNSViewHostOwner* rwhwvm_owner =
|
||||
[[[RenderWidgetHostNSViewHostOwner alloc]
|
||||
initWithRenderWidgetHostViewMac:rwhv_mac] autorelease];
|
||||
helper.AddEditingSelectorsToClass([rwhwvm_owner class]);
|
||||
|
||||
helper.AddEditingSelectorsToClass([rwhwvm_owner class]);
|
||||
for (NSString* edit_command_name in edit_command_strings) {
|
||||
NSString* sel_str = [edit_command_name stringByAppendingString:@":"];
|
||||
[rwhwvm_owner performSelector:NSSelectorFromString(sel_str)
|
||||
withObject:nil];
|
||||
}
|
||||
|
||||
for (NSString* edit_command_name in edit_command_strings) {
|
||||
NSString* sel_str = [edit_command_name stringByAppendingString:@":"];
|
||||
[rwhwvm_owner performSelector:NSSelectorFromString(sel_str) withObject:nil];
|
||||
size_t num_edit_commands = [edit_command_strings count];
|
||||
EXPECT_EQ(delegate.edit_command_message_count_, num_edit_commands);
|
||||
rwhv_cocoa.reset();
|
||||
|
||||
// The |render_widget|'s process needs to be deleted within |message_loop|.
|
||||
delete render_widget;
|
||||
}
|
||||
|
||||
size_t num_edit_commands = [edit_command_strings count];
|
||||
EXPECT_EQ(delegate.edit_command_message_count_, num_edit_commands);
|
||||
rwhv_cocoa.reset();
|
||||
pool.Recycle();
|
||||
|
||||
// The |render_widget|'s process needs to be deleted within |message_loop|.
|
||||
delete render_widget;
|
||||
|
||||
ui::WindowResizeHelperMac::Get()->ShutdownForTests();
|
||||
}
|
||||
|
||||
|
@ -8,38 +8,38 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "base/values.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
std::unique_ptr<base::ListValue> GetFontList_SlowBlocking() {
|
||||
base::mac::ScopedNSAutoreleasePool autorelease_pool;
|
||||
std::unique_ptr<base::ListValue> font_list(new base::ListValue);
|
||||
NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease];
|
||||
NSMutableDictionary* fonts_dict = [NSMutableDictionary dictionary];
|
||||
NSArray* fonts = [fontManager availableFontFamilies];
|
||||
@autoreleasepool {
|
||||
std::unique_ptr<base::ListValue> font_list(new base::ListValue);
|
||||
NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease];
|
||||
NSMutableDictionary* fonts_dict = [NSMutableDictionary dictionary];
|
||||
NSArray* fonts = [fontManager availableFontFamilies];
|
||||
|
||||
for (NSString* family_name in fonts) {
|
||||
NSString* localized_family_name =
|
||||
[fontManager localizedNameForFamily:family_name face:nil];
|
||||
fonts_dict[family_name] = localized_family_name;
|
||||
for (NSString* family_name in fonts) {
|
||||
NSString* localized_family_name =
|
||||
[fontManager localizedNameForFamily:family_name face:nil];
|
||||
fonts_dict[family_name] = localized_family_name;
|
||||
}
|
||||
|
||||
// Sort family names based on localized names.
|
||||
NSArray* sortedFonts = [fonts_dict
|
||||
keysSortedByValueUsingSelector:@selector(localizedStandardCompare:)];
|
||||
|
||||
for (NSString* family_name in sortedFonts) {
|
||||
NSString* localized_family_name = fonts_dict[family_name];
|
||||
auto font_item = std::make_unique<base::ListValue>();
|
||||
font_item->AppendString(base::SysNSStringToUTF16(family_name));
|
||||
font_item->AppendString(base::SysNSStringToUTF16(localized_family_name));
|
||||
font_list->Append(std::move(font_item));
|
||||
}
|
||||
|
||||
return font_list;
|
||||
}
|
||||
|
||||
// Sort family names based on localized names.
|
||||
NSArray* sortedFonts = [fonts_dict
|
||||
keysSortedByValueUsingSelector:@selector(localizedStandardCompare:)];
|
||||
|
||||
for (NSString* family_name in sortedFonts) {
|
||||
NSString* localized_family_name = fonts_dict[family_name];
|
||||
auto font_item = std::make_unique<base::ListValue>();
|
||||
font_item->AppendString(base::SysNSStringToUTF16(family_name));
|
||||
font_item->AppendString(base::SysNSStringToUTF16(localized_family_name));
|
||||
font_list->Append(std::move(font_item));
|
||||
}
|
||||
|
||||
return font_list;
|
||||
}
|
||||
|
||||
} // namespace content
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/mac/scoped_cftyperef.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
@ -87,57 +86,57 @@ void PrintingContextMac::AskUserForSettings(int max_pages,
|
||||
PrintSettingsCallback callback) {
|
||||
// Exceptions can also happen when the NSPrintPanel is being
|
||||
// deallocated, so it must be autoreleased within this scope.
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
DCHECK([NSThread isMainThread]);
|
||||
|
||||
DCHECK([NSThread isMainThread]);
|
||||
// We deliberately don't feed max_pages into the dialog, because setting
|
||||
// NSPrintLastPage makes the print dialog pre-select the option to only
|
||||
// print a range.
|
||||
|
||||
// We deliberately don't feed max_pages into the dialog, because setting
|
||||
// NSPrintLastPage makes the print dialog pre-select the option to only print
|
||||
// a range.
|
||||
// TODO(stuartmorgan): implement 'print selection only' (probably requires
|
||||
// adding a new custom view to the panel on 10.5; 10.6 has
|
||||
// NSPrintPanelShowsPrintSelection).
|
||||
NSPrintPanel* panel = [NSPrintPanel printPanel];
|
||||
NSPrintInfo* printInfo = print_info_.get();
|
||||
|
||||
// TODO(stuartmorgan): implement 'print selection only' (probably requires
|
||||
// adding a new custom view to the panel on 10.5; 10.6 has
|
||||
// NSPrintPanelShowsPrintSelection).
|
||||
NSPrintPanel* panel = [NSPrintPanel printPanel];
|
||||
NSPrintInfo* printInfo = print_info_.get();
|
||||
NSPrintPanelOptions options = [panel options];
|
||||
options |= NSPrintPanelShowsPaperSize;
|
||||
options |= NSPrintPanelShowsOrientation;
|
||||
options |= NSPrintPanelShowsScaling;
|
||||
[panel setOptions:options];
|
||||
|
||||
NSPrintPanelOptions options = [panel options];
|
||||
options |= NSPrintPanelShowsPaperSize;
|
||||
options |= NSPrintPanelShowsOrientation;
|
||||
options |= NSPrintPanelShowsScaling;
|
||||
[panel setOptions:options];
|
||||
|
||||
// Set the print job title text.
|
||||
gfx::NativeView parent_view = delegate_->GetParentView();
|
||||
if (parent_view) {
|
||||
NSString* job_title = [[parent_view.GetNativeNSView() window] title];
|
||||
if (job_title) {
|
||||
PMPrintSettings printSettings =
|
||||
(PMPrintSettings)[printInfo PMPrintSettings];
|
||||
PMPrintSettingsSetJobName(printSettings, (CFStringRef)job_title);
|
||||
[printInfo updateFromPMPrintSettings];
|
||||
// Set the print job title text.
|
||||
gfx::NativeView parent_view = delegate_->GetParentView();
|
||||
if (parent_view) {
|
||||
NSString* job_title = [[parent_view.GetNativeNSView() window] title];
|
||||
if (job_title) {
|
||||
PMPrintSettings printSettings =
|
||||
(PMPrintSettings)[printInfo PMPrintSettings];
|
||||
PMPrintSettingsSetJobName(printSettings, (CFStringRef)job_title);
|
||||
[printInfo updateFromPMPrintSettings];
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(stuartmorgan): We really want a tab sheet here, not a modal window.
|
||||
// Will require restructuring the PrintingContext API to use a callback.
|
||||
|
||||
// This function may be called in the middle of a CATransaction, where
|
||||
// running a modal panel is forbidden. That situation isn't ideal, but from
|
||||
// this code's POV the right answer is to defer running the panel until
|
||||
// after the current transaction. See https://crbug.com/849538.
|
||||
__block auto block_callback = std::move(callback);
|
||||
[CATransaction setCompletionBlock:^{
|
||||
NSInteger selection = [panel runModalWithPrintInfo:printInfo];
|
||||
if (selection == NSOKButton) {
|
||||
print_info_.reset([[panel printInfo] retain]);
|
||||
settings_->set_ranges(GetPageRangesFromPrintInfo());
|
||||
InitPrintSettingsFromPrintInfo();
|
||||
std::move(block_callback).Run(OK);
|
||||
} else {
|
||||
std::move(block_callback).Run(CANCEL);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
// TODO(stuartmorgan): We really want a tab sheet here, not a modal window.
|
||||
// Will require restructuring the PrintingContext API to use a callback.
|
||||
|
||||
// This function may be called in the middle of a CATransaction, where
|
||||
// running a modal panel is forbidden. That situation isn't ideal, but from
|
||||
// this code's POV the right answer is to defer running the panel until after
|
||||
// the current transaction. See https://crbug.com/849538.
|
||||
__block auto block_callback = std::move(callback);
|
||||
[CATransaction setCompletionBlock:^{
|
||||
NSInteger selection = [panel runModalWithPrintInfo:printInfo];
|
||||
if (selection == NSOKButton) {
|
||||
print_info_.reset([[panel printInfo] retain]);
|
||||
settings_->set_ranges(GetPageRangesFromPrintInfo());
|
||||
InitPrintSettingsFromPrintInfo();
|
||||
std::move(block_callback).Run(OK);
|
||||
} else {
|
||||
std::move(block_callback).Run(CANCEL);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
gfx::Size PrintingContextMac::GetPdfPaperSizeDeviceUnits() {
|
||||
|
@ -7,61 +7,58 @@
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
#import "base/mac/scoped_nsautorelease_pool.h"
|
||||
#import "third_party/breakpad/breakpad/src/client/mac/Framework/Breakpad.h"
|
||||
|
||||
namespace remoting {
|
||||
|
||||
void InitializeCrashReporting() {
|
||||
base::mac::ScopedNSAutoreleasePool autorelease_pool;
|
||||
@autoreleasepool {
|
||||
NSBundle* main_bundle = [NSBundle mainBundle];
|
||||
|
||||
NSBundle* main_bundle = [NSBundle mainBundle];
|
||||
// Tell Breakpad where crash_inspector and crash_report_sender are.
|
||||
NSString* resource_path = [main_bundle resourcePath];
|
||||
NSString* inspector_location =
|
||||
[resource_path stringByAppendingPathComponent:@"crash_inspector"];
|
||||
NSString* reporter_bundle_location = [resource_path
|
||||
stringByAppendingPathComponent:@"crash_report_sender.app"];
|
||||
NSString* reporter_location =
|
||||
[[NSBundle bundleWithPath:reporter_bundle_location] executablePath];
|
||||
|
||||
// Tell Breakpad where crash_inspector and crash_report_sender are.
|
||||
NSString* resource_path = [main_bundle resourcePath];
|
||||
NSString* inspector_location =
|
||||
[resource_path stringByAppendingPathComponent:@"crash_inspector"];
|
||||
NSString* reporter_bundle_location =
|
||||
[resource_path stringByAppendingPathComponent:@"crash_report_sender.app"];
|
||||
NSString* reporter_location =
|
||||
[[NSBundle bundleWithPath:reporter_bundle_location] executablePath];
|
||||
NSDictionary* info_dictionary = [main_bundle infoDictionary];
|
||||
NSMutableDictionary* breakpad_config =
|
||||
[[info_dictionary mutableCopy] autorelease];
|
||||
[breakpad_config setObject:inspector_location
|
||||
forKey:@BREAKPAD_INSPECTOR_LOCATION];
|
||||
[breakpad_config setObject:reporter_location
|
||||
forKey:@BREAKPAD_REPORTER_EXE_LOCATION];
|
||||
|
||||
NSDictionary* info_dictionary = [main_bundle infoDictionary];
|
||||
NSMutableDictionary* breakpad_config =
|
||||
[[info_dictionary mutableCopy] autorelease];
|
||||
[breakpad_config setObject:inspector_location
|
||||
forKey:@BREAKPAD_INSPECTOR_LOCATION];
|
||||
[breakpad_config setObject:reporter_location
|
||||
forKey:@BREAKPAD_REPORTER_EXE_LOCATION];
|
||||
// Configure Breakpad settings here, if they are not already customized in
|
||||
// the Info.plist. These settings should be added to the plist, but the
|
||||
// problem is that the Breakpad URL contains a double-slash, which is broken
|
||||
// by the INFOPLIST_PREPROCESS step.
|
||||
// TODO(lambroslambrou): Add these to the Info.plist, similarly to what is
|
||||
// done for Chrome Framework - see 'Tweak Info.plist' in
|
||||
// chrome/chrome_dll_bundle.gypi.
|
||||
if (![breakpad_config objectForKey:@BREAKPAD_SKIP_CONFIRM]) {
|
||||
// Skip the upload confirmation dialog, since this is a remote-access
|
||||
// service that shouldn't rely on a console user to dismiss any prompt.
|
||||
// Also, this may be running in the LoginWindow context, where prompting
|
||||
// might not be possible.
|
||||
[breakpad_config setObject:@"YES" forKey:@BREAKPAD_SKIP_CONFIRM];
|
||||
}
|
||||
if (![breakpad_config objectForKey:@BREAKPAD_REPORT_INTERVAL]) {
|
||||
// Set a minimum 6-hour interval between crash-reports, to match the
|
||||
// throttling used on Windows.
|
||||
[breakpad_config setObject:@"21600" forKey:@BREAKPAD_REPORT_INTERVAL];
|
||||
}
|
||||
if (![breakpad_config objectForKey:@BREAKPAD_URL]) {
|
||||
[breakpad_config setObject:@"https://clients2.google.com/cr/report"
|
||||
forKey:@BREAKPAD_URL];
|
||||
}
|
||||
|
||||
// Configure Breakpad settings here, if they are not already customized in
|
||||
// the Info.plist. These settings should be added to the plist, but the
|
||||
// problem is that the Breakpad URL contains a double-slash, which is broken
|
||||
// by the INFOPLIST_PREPROCESS step.
|
||||
// TODO(lambroslambrou): Add these to the Info.plist, similarly to what is
|
||||
// done for Chrome Framework - see 'Tweak Info.plist' in
|
||||
// chrome/chrome_dll_bundle.gypi.
|
||||
if (![breakpad_config objectForKey:@BREAKPAD_SKIP_CONFIRM]) {
|
||||
// Skip the upload confirmation dialog, since this is a remote-access
|
||||
// service that shouldn't rely on a console user to dismiss any prompt.
|
||||
// Also, this may be running in the LoginWindow context, where prompting
|
||||
// might not be possible.
|
||||
[breakpad_config setObject:@"YES"
|
||||
forKey:@BREAKPAD_SKIP_CONFIRM];
|
||||
}
|
||||
if (![breakpad_config objectForKey:@BREAKPAD_REPORT_INTERVAL]) {
|
||||
// Set a minimum 6-hour interval between crash-reports, to match the
|
||||
// throttling used on Windows.
|
||||
[breakpad_config setObject:@"21600"
|
||||
forKey:@BREAKPAD_REPORT_INTERVAL];
|
||||
}
|
||||
if (![breakpad_config objectForKey:@BREAKPAD_URL]) {
|
||||
[breakpad_config setObject:@"https://clients2.google.com/cr/report"
|
||||
forKey:@BREAKPAD_URL];
|
||||
}
|
||||
|
||||
if (!BreakpadCreate(breakpad_config)) {
|
||||
LOG(ERROR) << "Breakpad initialization failed";
|
||||
if (!BreakpadCreate(breakpad_config)) {
|
||||
LOG(ERROR) << "Breakpad initialization failed";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
@ -62,17 +61,19 @@ ContinueWindowMac::~ContinueWindowMac() {
|
||||
void ContinueWindowMac::ShowUi() {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
controller_.reset(
|
||||
[[ContinueWindowMacController alloc] initWithWindow:this]);
|
||||
[controller_ show];
|
||||
@autoreleasepool {
|
||||
controller_.reset(
|
||||
[[ContinueWindowMacController alloc] initWithWindow:this]);
|
||||
[controller_ show];
|
||||
}
|
||||
}
|
||||
|
||||
void ContinueWindowMac::HideUi() {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
[controller_ hide];
|
||||
@autoreleasepool {
|
||||
[controller_ hide];
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "base/callback.h"
|
||||
#include "base/i18n/message_formatter.h"
|
||||
#include "base/location.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
@ -76,8 +75,9 @@ It2MeConfirmationDialogMac::~It2MeConfirmationDialogMac() {
|
||||
dialog_timer_.Stop();
|
||||
|
||||
if (controller_) {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
[controller_ hide];
|
||||
@autoreleasepool {
|
||||
[controller_ hide];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,20 +92,22 @@ void It2MeConfirmationDialogMac::Show(const std::string& remote_user_email,
|
||||
ResultCallback dialog_action_callback = base::Bind(
|
||||
&It2MeConfirmationDialogMac::OnDialogAction, base::Unretained(this));
|
||||
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
controller_.reset([[It2MeConfirmationDialogMacController alloc]
|
||||
initWithCallback:dialog_action_callback
|
||||
username:remote_user_email]);
|
||||
[controller_ show];
|
||||
@autoreleasepool {
|
||||
controller_.reset([[It2MeConfirmationDialogMacController alloc]
|
||||
initWithCallback:dialog_action_callback
|
||||
username:remote_user_email]);
|
||||
[controller_ show];
|
||||
}
|
||||
}
|
||||
|
||||
void It2MeConfirmationDialogMac::OnDialogAction(Result result) {
|
||||
dialog_timer_.Stop();
|
||||
|
||||
if (controller_) {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
[controller_ hide];
|
||||
controller_.reset();
|
||||
@autoreleasepool {
|
||||
[controller_ hide];
|
||||
controller_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
if (result_callback_) {
|
||||
|
@ -353,15 +353,15 @@ RlzValueStore* ScopedRlzValueStoreLock::GetStore() {
|
||||
namespace testing {
|
||||
|
||||
void SetRlzStoreDirectory(const base::FilePath& directory) {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
|
||||
[g_test_folder release];
|
||||
if (directory.empty()) {
|
||||
g_test_folder = nil;
|
||||
} else {
|
||||
// Not Unsafe on OS X.
|
||||
g_test_folder =
|
||||
[[NSString alloc] initWithUTF8String:directory.AsUTF8Unsafe().c_str()];
|
||||
@autoreleasepool {
|
||||
[g_test_folder release];
|
||||
if (directory.empty()) {
|
||||
g_test_folder = nil;
|
||||
} else {
|
||||
// Not Unsafe on OS X.
|
||||
g_test_folder = [[NSString alloc]
|
||||
initWithUTF8String:directory.AsUTF8Unsafe().c_str()];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
@ -45,71 +44,73 @@ class CoreWlanApi : public WifiDataProviderCommon::WlanApiInterface {
|
||||
};
|
||||
|
||||
bool CoreWlanApi::GetAccessPointData(WifiData::AccessPointDataSet* data) {
|
||||
base::mac::ScopedNSAutoreleasePool auto_pool;
|
||||
// Initialize the scan parameters with scan key merging disabled, so we get
|
||||
// every AP listed in the scan without any SSID de-duping logic.
|
||||
NSDictionary* params = @{ kCWScanKeyMerge : @NO };
|
||||
@autoreleasepool { // Initialize the scan parameters with scan key merging
|
||||
// disabled, so we get
|
||||
// every AP listed in the scan without any SSID de-duping logic.
|
||||
NSDictionary* params = @{kCWScanKeyMerge : @NO};
|
||||
|
||||
NSSet* supported_interfaces = [CWInterface interfaceNames];
|
||||
NSUInteger interface_error_count = 0;
|
||||
for (NSString* interface_name in supported_interfaces) {
|
||||
CWInterface* corewlan_interface =
|
||||
[CWInterface interfaceWithName:interface_name];
|
||||
if (!corewlan_interface) {
|
||||
DLOG(WARNING) << interface_name << ": initWithName failed";
|
||||
++interface_error_count;
|
||||
continue;
|
||||
NSSet* supported_interfaces = [CWInterface interfaceNames];
|
||||
NSUInteger interface_error_count = 0;
|
||||
for (NSString* interface_name in supported_interfaces) {
|
||||
CWInterface* corewlan_interface =
|
||||
[CWInterface interfaceWithName:interface_name];
|
||||
if (!corewlan_interface) {
|
||||
DLOG(WARNING) << interface_name << ": initWithName failed";
|
||||
++interface_error_count;
|
||||
continue;
|
||||
}
|
||||
|
||||
const base::TimeTicks start_time = base::TimeTicks::Now();
|
||||
|
||||
NSError* err = nil;
|
||||
NSArray* scan = [corewlan_interface scanForNetworksWithParameters:params
|
||||
error:&err];
|
||||
const int error_code = [err code];
|
||||
const int count = [scan count];
|
||||
// We could get an error code but count != 0 if the scan was interrupted,
|
||||
// for example. For our purposes this is not fatal, so process as normal.
|
||||
if (error_code && count == 0) {
|
||||
DLOG(WARNING) << interface_name << ": CoreWLAN scan failed with error "
|
||||
<< error_code;
|
||||
++interface_error_count;
|
||||
continue;
|
||||
}
|
||||
|
||||
const base::TimeDelta duration = base::TimeTicks::Now() - start_time;
|
||||
|
||||
UMA_HISTOGRAM_CUSTOM_TIMES("Net.Wifi.ScanLatency", duration,
|
||||
base::TimeDelta::FromMilliseconds(1),
|
||||
base::TimeDelta::FromMinutes(1), 100);
|
||||
|
||||
DVLOG(1) << interface_name << ": found " << count << " wifi APs";
|
||||
|
||||
for (CWNetwork* network in scan) {
|
||||
DCHECK(network);
|
||||
AccessPointData access_point_data;
|
||||
// -[CWNetwork bssid] uses colons to separate the components of the MAC
|
||||
// address, but AccessPointData requires they be separated with a dash.
|
||||
access_point_data.mac_address = base::SysNSStringToUTF16(
|
||||
[[network bssid] stringByReplacingOccurrencesOfString:@":"
|
||||
withString:@"-"]);
|
||||
access_point_data.radio_signal_strength = [network rssiValue];
|
||||
access_point_data.channel = [[network wlanChannel] channelNumber];
|
||||
access_point_data.signal_to_noise =
|
||||
access_point_data.radio_signal_strength -
|
||||
[network noiseMeasurement];
|
||||
access_point_data.ssid = base::SysNSStringToUTF16([network ssid]);
|
||||
data->insert(access_point_data);
|
||||
}
|
||||
}
|
||||
|
||||
const base::TimeTicks start_time = base::TimeTicks::Now();
|
||||
UMA_HISTOGRAM_CUSTOM_COUNTS(
|
||||
"Net.Wifi.InterfaceCount",
|
||||
[supported_interfaces count] - interface_error_count, 1, 5, 6);
|
||||
|
||||
NSError* err = nil;
|
||||
NSArray* scan =
|
||||
[corewlan_interface scanForNetworksWithParameters:params error:&err];
|
||||
const int error_code = [err code];
|
||||
const int count = [scan count];
|
||||
// We could get an error code but count != 0 if the scan was interrupted,
|
||||
// for example. For our purposes this is not fatal, so process as normal.
|
||||
if (error_code && count == 0) {
|
||||
DLOG(WARNING) << interface_name << ": CoreWLAN scan failed with error "
|
||||
<< error_code;
|
||||
++interface_error_count;
|
||||
continue;
|
||||
}
|
||||
|
||||
const base::TimeDelta duration = base::TimeTicks::Now() - start_time;
|
||||
|
||||
UMA_HISTOGRAM_CUSTOM_TIMES("Net.Wifi.ScanLatency", duration,
|
||||
base::TimeDelta::FromMilliseconds(1),
|
||||
base::TimeDelta::FromMinutes(1), 100);
|
||||
|
||||
DVLOG(1) << interface_name << ": found " << count << " wifi APs";
|
||||
|
||||
for (CWNetwork* network in scan) {
|
||||
DCHECK(network);
|
||||
AccessPointData access_point_data;
|
||||
// -[CWNetwork bssid] uses colons to separate the components of the MAC
|
||||
// address, but AccessPointData requires they be separated with a dash.
|
||||
access_point_data.mac_address = base::SysNSStringToUTF16([[network bssid]
|
||||
stringByReplacingOccurrencesOfString:@":"
|
||||
withString:@"-"]);
|
||||
access_point_data.radio_signal_strength = [network rssiValue];
|
||||
access_point_data.channel = [[network wlanChannel] channelNumber];
|
||||
access_point_data.signal_to_noise =
|
||||
access_point_data.radio_signal_strength - [network noiseMeasurement];
|
||||
access_point_data.ssid = base::SysNSStringToUTF16([network ssid]);
|
||||
data->insert(access_point_data);
|
||||
}
|
||||
// Return true even if some interfaces failed to scan, so long as at least
|
||||
// one interface did not fail.
|
||||
return interface_error_count == 0 ||
|
||||
[supported_interfaces count] > interface_error_count;
|
||||
}
|
||||
|
||||
UMA_HISTOGRAM_CUSTOM_COUNTS(
|
||||
"Net.Wifi.InterfaceCount",
|
||||
[supported_interfaces count] - interface_error_count, 1, 5, 6);
|
||||
|
||||
// Return true even if some interfaces failed to scan, so long as at least
|
||||
// one interface did not fail.
|
||||
return interface_error_count == 0 ||
|
||||
[supported_interfaces count] > interface_error_count;
|
||||
}
|
||||
|
||||
// The time periods, in milliseconds, between successive polls of the wifi data.
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "base/mac/mac_util.h"
|
||||
#include "base/mac/mach_port_rendezvous.h"
|
||||
#include "base/mac/scoped_cftyperef.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "base/rand_util.h"
|
||||
#include "base/stl_util.h"
|
||||
@ -83,56 +82,57 @@ const char* SandboxMac::kSandboxBundleVersionPath = "BUNDLE_VERSION_PATH";
|
||||
void SandboxMac::Warmup(SandboxType sandbox_type) {
|
||||
DCHECK_EQ(sandbox_type, SANDBOX_TYPE_GPU);
|
||||
|
||||
base::mac::ScopedNSAutoreleasePool scoped_pool;
|
||||
@autoreleasepool {
|
||||
{ // CGColorSpaceCreateWithName(), CGBitmapContextCreate() - 10.5.6
|
||||
base::ScopedCFTypeRef<CGColorSpaceRef> rgb_colorspace(
|
||||
CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB));
|
||||
|
||||
{ // CGColorSpaceCreateWithName(), CGBitmapContextCreate() - 10.5.6
|
||||
base::ScopedCFTypeRef<CGColorSpaceRef> rgb_colorspace(
|
||||
CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB));
|
||||
// Allocate a 1x1 image.
|
||||
char data[4];
|
||||
base::ScopedCFTypeRef<CGContextRef> context(CGBitmapContextCreate(
|
||||
data, 1, 1, 8, 1 * 4, rgb_colorspace,
|
||||
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
|
||||
|
||||
// Allocate a 1x1 image.
|
||||
char data[4];
|
||||
base::ScopedCFTypeRef<CGContextRef> context(CGBitmapContextCreate(
|
||||
data, 1, 1, 8, 1 * 4, rgb_colorspace,
|
||||
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
|
||||
// Load in the color profiles we'll need (as a side effect).
|
||||
ignore_result(base::mac::GetSRGBColorSpace());
|
||||
ignore_result(base::mac::GetSystemColorSpace());
|
||||
|
||||
// Load in the color profiles we'll need (as a side effect).
|
||||
ignore_result(base::mac::GetSRGBColorSpace());
|
||||
ignore_result(base::mac::GetSystemColorSpace());
|
||||
// CGColorSpaceCreateSystemDefaultCMYK - 10.6
|
||||
base::ScopedCFTypeRef<CGColorSpaceRef> cmyk_colorspace(
|
||||
CGColorSpaceCreateWithName(kCGColorSpaceGenericCMYK));
|
||||
}
|
||||
|
||||
// CGColorSpaceCreateSystemDefaultCMYK - 10.6
|
||||
base::ScopedCFTypeRef<CGColorSpaceRef> cmyk_colorspace(
|
||||
CGColorSpaceCreateWithName(kCGColorSpaceGenericCMYK));
|
||||
}
|
||||
{ // localtime() - 10.5.6
|
||||
time_t tv = {0};
|
||||
localtime(&tv);
|
||||
}
|
||||
|
||||
{ // localtime() - 10.5.6
|
||||
time_t tv = {0};
|
||||
localtime(&tv);
|
||||
}
|
||||
{ // Gestalt() tries to read
|
||||
// /System/Library/CoreServices/SystemVersion.plist
|
||||
// on 10.5.6
|
||||
int32_t tmp;
|
||||
base::SysInfo::OperatingSystemVersionNumbers(&tmp, &tmp, &tmp);
|
||||
}
|
||||
|
||||
{ // Gestalt() tries to read /System/Library/CoreServices/SystemVersion.plist
|
||||
// on 10.5.6
|
||||
int32_t tmp;
|
||||
base::SysInfo::OperatingSystemVersionNumbers(&tmp, &tmp, &tmp);
|
||||
}
|
||||
{ // CGImageSourceGetStatus() - 10.6
|
||||
// Create a png with just enough data to get everything warmed up...
|
||||
char png_header[] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
|
||||
NSData* data = [NSData dataWithBytes:png_header
|
||||
length:base::size(png_header)];
|
||||
base::ScopedCFTypeRef<CGImageSourceRef> img(
|
||||
CGImageSourceCreateWithData((CFDataRef)data, NULL));
|
||||
CGImageSourceGetStatus(img);
|
||||
}
|
||||
|
||||
{ // CGImageSourceGetStatus() - 10.6
|
||||
// Create a png with just enough data to get everything warmed up...
|
||||
char png_header[] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
|
||||
NSData* data = [NSData dataWithBytes:png_header
|
||||
length:base::size(png_header)];
|
||||
base::ScopedCFTypeRef<CGImageSourceRef> img(
|
||||
CGImageSourceCreateWithData((CFDataRef)data, NULL));
|
||||
CGImageSourceGetStatus(img);
|
||||
}
|
||||
{
|
||||
// Allow access to /dev/urandom.
|
||||
base::GetUrandomFD();
|
||||
}
|
||||
|
||||
{
|
||||
// Allow access to /dev/urandom.
|
||||
base::GetUrandomFD();
|
||||
}
|
||||
|
||||
{ // IOSurfaceLookup() - 10.7
|
||||
// Needed by zero-copy texture update framework - crbug.com/323338
|
||||
base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceLookup(0));
|
||||
{ // IOSurfaceLookup() - 10.7
|
||||
// Needed by zero-copy texture update framework - crbug.com/323338
|
||||
base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceLookup(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -212,8 +212,7 @@ void CocoaTest::TearDown() {
|
||||
([start_date timeIntervalSinceNow] > -kCloseTimeoutSeconds);
|
||||
|
||||
// Autorelease anything thrown up by the event loop.
|
||||
{
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
++spins;
|
||||
NSEvent* next_event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
||||
untilDate:nil
|
||||
@ -253,12 +252,13 @@ std::set<NSWindow*> CocoaTest::ApplicationWindows() {
|
||||
|
||||
// Must create a pool here because [NSApp windows] has created an array
|
||||
// with retains on all the windows in it.
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
NSArray* appWindows = [NSApp windows];
|
||||
for (NSWindow* window in appWindows) {
|
||||
windows.insert(window);
|
||||
@autoreleasepool {
|
||||
NSArray* appWindows = [NSApp windows];
|
||||
for (NSWindow* window in appWindows) {
|
||||
windows.insert(window);
|
||||
}
|
||||
return windows;
|
||||
}
|
||||
return windows;
|
||||
}
|
||||
|
||||
std::set<NSWindow*> CocoaTest::WindowsLeft() {
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#import "base/mac/scoped_nsautorelease_pool.h"
|
||||
#import "base/mac/scoped_nsobject.h"
|
||||
#include "base/macros.h"
|
||||
#import "testing/gtest_mac.h"
|
||||
@ -220,8 +219,7 @@ TEST_F(NativeViewHostMacTest, NativeViewHidden) {
|
||||
// Check that we can destroy cleanly even if the native view has already been
|
||||
// released.
|
||||
TEST_F(NativeViewHostMacTest, NativeViewReleased) {
|
||||
{
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
CreateHost();
|
||||
// In practice the native view is a WebContentsViewCocoa which is retained
|
||||
// by its superview (a TabContentsContainerView) and by WebContentsViewMac.
|
||||
|
@ -7,7 +7,6 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "base/bind.h"
|
||||
#import "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "ui/base/test/scoped_fake_full_keyboard_access.h"
|
||||
#include "ui/base/test/scoped_fake_nswindow_focus.h"
|
||||
#include "ui/base/test/scoped_fake_nswindow_fullscreen.h"
|
||||
@ -63,13 +62,14 @@ void ViewsTestHelperMac::TearDown() {
|
||||
// this is handled automatically by views::Widget::CloseAllSecondaryWidgets().
|
||||
// Unit tests on Aura may create Widgets owned by a RootWindow that gets torn
|
||||
// down, but on Mac we need to be more explicit.
|
||||
base::mac::ScopedNSAutoreleasePool pool; // Ensure the NSArray is released.
|
||||
NSArray* native_windows = [NSApp windows];
|
||||
for (NSWindow* window : native_windows)
|
||||
DCHECK(!Widget::GetWidgetForNativeWindow(window)) << "Widget not closed.";
|
||||
@autoreleasepool {
|
||||
NSArray* native_windows = [NSApp windows];
|
||||
for (NSWindow* window : native_windows)
|
||||
DCHECK(!Widget::GetWidgetForNativeWindow(window)) << "Widget not closed.";
|
||||
|
||||
ui::test::EventGeneratorDelegate::SetFactoryFunction(
|
||||
ui::test::EventGeneratorDelegate::FactoryFunction());
|
||||
ui::test::EventGeneratorDelegate::SetFactoryFunction(
|
||||
ui::test::EventGeneratorDelegate::FactoryFunction());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace views
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "base/callback.h"
|
||||
#import "base/mac/foundation_util.h"
|
||||
#include "base/mac/mac_util.h"
|
||||
#import "base/mac/scoped_nsautorelease_pool.h"
|
||||
#import "base/mac/scoped_nsobject.h"
|
||||
#import "base/mac/scoped_objc_class_swizzler.h"
|
||||
#include "base/macros.h"
|
||||
@ -817,10 +816,9 @@ TEST_F(NativeWidgetMacTest, NonWidgetParent) {
|
||||
TEST_F(NativeWidgetMacTest, CloseAllSecondaryWidgetsValidState) {
|
||||
NativeWidgetMacTestWindow* last_window = nil;
|
||||
bool window_deallocated = false;
|
||||
{
|
||||
@autoreleasepool {
|
||||
// First verify the behavior of CloseAllSecondaryWidgets in the normal case,
|
||||
// and how [NSApp windows] changes in response to Widget closure.
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
Widget* widget = CreateWidgetWithTestWindow(
|
||||
Widget::InitParams(Widget::InitParams::TYPE_WINDOW), &last_window);
|
||||
last_window.deallocFlag = &window_deallocated;
|
||||
@ -833,10 +831,9 @@ TEST_F(NativeWidgetMacTest, CloseAllSecondaryWidgetsValidState) {
|
||||
EXPECT_TRUE(window_deallocated);
|
||||
window_deallocated = false;
|
||||
|
||||
{
|
||||
@autoreleasepool {
|
||||
// Repeat, but now retain a reference and close the window before
|
||||
// CloseAllSecondaryWidgets().
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
Widget* widget = CreateWidgetWithTestWindow(
|
||||
Widget::InitParams(Widget::InitParams::TYPE_WINDOW), &last_window);
|
||||
last_window.deallocFlag = &window_deallocated;
|
||||
@ -847,8 +844,7 @@ TEST_F(NativeWidgetMacTest, CloseAllSecondaryWidgetsValidState) {
|
||||
}
|
||||
|
||||
EXPECT_FALSE(window_deallocated);
|
||||
{
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
Widget::CloseAllSecondaryWidgets();
|
||||
[last_window release];
|
||||
}
|
||||
@ -880,8 +876,7 @@ TEST_F(NativeWidgetMacTest, NonWidgetParentLastReference) {
|
||||
bool child_dealloced = false;
|
||||
bool native_parent_dealloced = false;
|
||||
NativeWidgetMacTestWindow* native_parent = nil;
|
||||
{
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
native_parent = MakeBorderlessNativeParent();
|
||||
[native_parent setDeallocFlag:&native_parent_dealloced];
|
||||
|
||||
@ -893,13 +888,12 @@ TEST_F(NativeWidgetMacTest, NonWidgetParentLastReference) {
|
||||
CreateWidgetWithTestWindow(std::move(init_params), &window);
|
||||
[window setDeallocFlag:&child_dealloced];
|
||||
}
|
||||
{
|
||||
@autoreleasepool {
|
||||
// On 10.11, closing a weak reference on the parent window works, but older
|
||||
// versions of AppKit get upset if things are released inside -[NSWindow
|
||||
// close]. This test tries to establish a situation where the last reference
|
||||
// to the child window is released inside WidgetOwnerNSWindowAdapter::
|
||||
// OnWindowWillClose().
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
[native_parent close];
|
||||
EXPECT_TRUE(child_dealloced);
|
||||
}
|
||||
@ -1511,8 +1505,7 @@ TEST_F(NativeWidgetMacTest, CloseWithWindowModalSheet) {
|
||||
|
||||
// Test another hypothetical: What if -sheetDidEnd: was invoked somehow
|
||||
// without going through [NSApp endSheet:] or -[NSWindow endSheet:].
|
||||
{
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
Widget* sheet_widget = ShowWindowModalWidget(native_parent);
|
||||
NSWindow* sheet_window =
|
||||
sheet_widget->GetNativeWindow().GetNativeNSWindow();
|
||||
@ -1548,8 +1541,7 @@ TEST_F(NativeWidgetMacTest, CloseWithWindowModalSheet) {
|
||||
// https://crbug.com/851376.
|
||||
TEST_F(NativeWidgetMacTest, CloseWindowModalSheetWithoutSheetParent) {
|
||||
NSWindow* native_parent = MakeClosableTitledNativeParent();
|
||||
{
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@autoreleasepool {
|
||||
Widget* sheet_widget = ShowWindowModalWidget(native_parent);
|
||||
NSWindow* sheet_window =
|
||||
sheet_widget->GetNativeWindow().GetNativeNSWindow();
|
||||
|
Reference in New Issue
Block a user