forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mac] Allow NSExceptions in certain cases.
Thirdy-party print drivers seem to be a source of NSExceptions which Chromium will never be able to fix. ScopedNSExceptionEnabler causes the code which makes throwing an NSException fatal to allow throws. The flag will be reset in -reportException: in most cases. For now, allow exceptions to be thrown for -selectPDE: (bug 80686) and PrintingContextMac::AskUserForSettings() (bug 82589). BUG=80686, 82589 TEST=Monitor crash server. Review URL: http://codereview.chromium.org/7038010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86503 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
shess@chromium.org
committed
May 24, 2011
1 parent
3aca95d
commit 39e3b95
Showing
5 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) 2011 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef BASE_MAC_SCOPED_NSEXCEPTION_ENABLER_H_ | ||
#define BASE_MAC_SCOPED_NSEXCEPTION_ENABLER_H_ | ||
#pragma once | ||
|
||
#include "base/basictypes.h" | ||
|
||
namespace base { | ||
namespace mac { | ||
|
||
// BrowserCrApplication attempts to restrict throwing of NSExceptions | ||
// because they interact badly with C++ scoping rules. Unfortunately, | ||
// there are some cases where exceptions must be supported, such as | ||
// when third-party printer drivers are used. These helpers can be | ||
// used to enable exceptions for narrow windows. | ||
|
||
// Make it easy to safely allow NSException to be thrown in a limited | ||
// scope. Note that if an exception is thrown, then this object will | ||
// not be appropriately destructed! If the exception ends up in the | ||
// top-level event loop, things are cleared in -reportException:. If | ||
// the exception is caught at a lower level, a higher level scoper | ||
// should eventually reset things. | ||
class ScopedNSExceptionEnabler { | ||
public: | ||
ScopedNSExceptionEnabler(); | ||
~ScopedNSExceptionEnabler(); | ||
|
||
private: | ||
bool was_enabled_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(ScopedNSExceptionEnabler); | ||
}; | ||
|
||
// Access the exception setting for the current thread. This is for | ||
// the support code in BrowserCrApplication, other code should use | ||
// the scoper. | ||
bool GetNSExceptionsAllowed(); | ||
void SetNSExceptionsAllowed(bool allowed); | ||
|
||
} // namespace mac | ||
} // namespace base | ||
|
||
#endif // BASE_MAC_SCOPED_NSEXCEPTION_ENABLER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2011 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "base/mac/scoped_nsexception_enabler.h" | ||
|
||
#import "base/lazy_instance.h" | ||
#import "base/threading/thread_local.h" | ||
|
||
// To make the |g_exceptionsAllowed| declaration readable. | ||
using base::LazyInstance; | ||
using base::LeakyLazyInstanceTraits; | ||
using base::ThreadLocalBoolean; | ||
|
||
namespace { | ||
|
||
// Whether to allow NSExceptions to be raised on the current thread. | ||
LazyInstance<ThreadLocalBoolean, LeakyLazyInstanceTraits<ThreadLocalBoolean> > | ||
g_exceptionsAllowed(base::LINKER_INITIALIZED); | ||
|
||
} // namespace | ||
|
||
namespace base { | ||
namespace mac { | ||
|
||
bool GetNSExceptionsAllowed() { | ||
return g_exceptionsAllowed.Get().Get(); | ||
} | ||
|
||
void SetNSExceptionsAllowed(bool allowed) { | ||
return g_exceptionsAllowed.Get().Set(allowed); | ||
} | ||
|
||
ScopedNSExceptionEnabler::ScopedNSExceptionEnabler() { | ||
was_enabled_ = GetNSExceptionsAllowed(); | ||
SetNSExceptionsAllowed(true); | ||
} | ||
|
||
ScopedNSExceptionEnabler::~ScopedNSExceptionEnabler() { | ||
SetNSExceptionsAllowed(was_enabled_); | ||
} | ||
|
||
} // namespace mac | ||
} // namespace base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters