summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsesek <rsesek@chromium.org>2015-07-22 09:06:20 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-22 16:07:00 +0000
commit787e2b2d0110448a5added6c9aae8fc7f9134144 (patch)
tree3fcf06af87cdc26c0bedce9600d532bb5246f7a1
parent0b866e1ba9b26a8d39247e552ab5f4d62a8e238c (diff)
downloadchromium_src-787e2b2d0110448a5added6c9aae8fc7f9134144.zip
chromium_src-787e2b2d0110448a5added6c9aae8fc7f9134144.tar.gz
chromium_src-787e2b2d0110448a5added6c9aae8fc7f9134144.tar.bz2
Remove base/mac/scoped_nsexception_enabler.h.
Exception fatalisation is now handled via base::mac::CallWithEHFrame, so this file is unnecessary. The base::mac::ScopedNSExceptionEnabler is removed, since instantiating an NSException is no longer fatal (only an uncaught one is). base::mac::RunBlockIgnoringExceptions has been removed where possible or converted to a @try/@catch to swallow any exceptions. BUG=503128 R=shess@chromium.org Review URL: https://codereview.chromium.org/1233983004 Cr-Commit-Position: refs/heads/master@{#339884}
-rw-r--r--base/BUILD.gn2
-rw-r--r--base/base.gypi2
-rw-r--r--base/mac/scoped_nsexception_enabler.h54
-rw-r--r--base/mac/scoped_nsexception_enabler.mm63
-rw-r--r--chrome/browser/chrome_browser_application_mac.mm16
-rw-r--r--chrome/browser/chrome_browser_application_mac_unittest.mm3
-rw-r--r--chrome/browser/mac/keystone_glue.mm10
-rw-r--r--chrome/browser/spellchecker/spellcheck_platform_mac.mm10
-rw-r--r--components/autofill/core/browser/personal_data_manager_mac.mm9
-rw-r--r--media/capture/video/mac/video_capture_device_qtkit_mac.mm16
-rw-r--r--printing/printing_context_mac.mm6
-rw-r--r--ui/base/clipboard/clipboard_mac.mm10
12 files changed, 24 insertions, 177 deletions
diff --git a/base/BUILD.gn b/base/BUILD.gn
index 6866707..23cc60f 100644
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -306,8 +306,6 @@ component("base") {
"mac/scoped_mach_vm.h",
"mac/scoped_nsautorelease_pool.h",
"mac/scoped_nsautorelease_pool.mm",
- "mac/scoped_nsexception_enabler.h",
- "mac/scoped_nsexception_enabler.mm",
"mac/scoped_nsobject.h",
"mac/scoped_objc_class_swizzler.h",
"mac/scoped_objc_class_swizzler.mm",
diff --git a/base/base.gypi b/base/base.gypi
index 0d0b8e1..efe67c0 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -317,8 +317,6 @@
'mac/scoped_mach_vm.h',
'mac/scoped_nsautorelease_pool.h',
'mac/scoped_nsautorelease_pool.mm',
- 'mac/scoped_nsexception_enabler.h',
- 'mac/scoped_nsexception_enabler.mm',
'mac/scoped_nsobject.h',
'mac/scoped_objc_class_swizzler.h',
'mac/scoped_objc_class_swizzler.mm',
diff --git a/base/mac/scoped_nsexception_enabler.h b/base/mac/scoped_nsexception_enabler.h
deleted file mode 100644
index 484dd53..0000000
--- a/base/mac/scoped_nsexception_enabler.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// 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_
-
-#import <Foundation/Foundation.h>
-
-#include "base/base_export.h"
-#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 BASE_EXPORT 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.
-BASE_EXPORT bool GetNSExceptionsAllowed();
-BASE_EXPORT void SetNSExceptionsAllowed(bool allowed);
-
-// Executes |block| with fatal-exceptions turned off, and returns the
-// result. If an exception is thrown during the perform, nil is
-// returned.
-typedef id (^BlockReturningId)();
-BASE_EXPORT id RunBlockIgnoringExceptions(BlockReturningId block);
-
-} // namespace mac
-} // namespace base
-
-#endif // BASE_MAC_SCOPED_NSEXCEPTION_ENABLER_H_
diff --git a/base/mac/scoped_nsexception_enabler.mm b/base/mac/scoped_nsexception_enabler.mm
deleted file mode 100644
index 7b8ad92..0000000
--- a/base/mac/scoped_nsexception_enabler.mm
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright (c) 2012 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::ThreadLocalBoolean;
-
-// When C++ exceptions are disabled, the C++ library defines |try| and
-// |catch| so as to allow exception-expecting C++ code to build properly when
-// language support for exceptions is not present. These macros interfere
-// with the use of |@try| and |@catch| in Objective-C files such as this one.
-// Undefine these macros here, after everything has been #included, since
-// there will be no C++ uses and only Objective-C uses from this point on.
-#undef try
-#undef catch
-
-namespace {
-
-// Whether to allow NSExceptions to be raised on the current thread.
-LazyInstance<ThreadLocalBoolean>::Leaky
- g_exceptionsAllowed = LAZY_INSTANCE_INITIALIZER;
-
-} // namespace
-
-namespace base {
-namespace mac {
-
-bool GetNSExceptionsAllowed() {
- return g_exceptionsAllowed.Get().Get();
-}
-
-void SetNSExceptionsAllowed(bool allowed) {
- return g_exceptionsAllowed.Get().Set(allowed);
-}
-
-id RunBlockIgnoringExceptions(BlockReturningId block) {
- id ret = nil;
- @try {
- base::mac::ScopedNSExceptionEnabler enable;
- ret = block();
- }
- @catch(id exception) {
- }
- return ret;
-}
-
-ScopedNSExceptionEnabler::ScopedNSExceptionEnabler() {
- was_enabled_ = GetNSExceptionsAllowed();
- SetNSExceptionsAllowed(true);
-}
-
-ScopedNSExceptionEnabler::~ScopedNSExceptionEnabler() {
- SetNSExceptionsAllowed(was_enabled_);
-}
-
-} // namespace mac
-} // namespace base
diff --git a/chrome/browser/chrome_browser_application_mac.mm b/chrome/browser/chrome_browser_application_mac.mm
index 02479c0..6d7c11c 100644
--- a/chrome/browser/chrome_browser_application_mac.mm
+++ b/chrome/browser/chrome_browser_application_mac.mm
@@ -12,7 +12,6 @@
#include "base/debug/stack_trace.h"
#import "base/logging.h"
#include "base/mac/call_with_eh_frame.h"
-#import "base/mac/scoped_nsexception_enabler.h"
#import "base/mac/scoped_nsobject.h"
#import "base/mac/scoped_objc_class_swizzler.h"
#import "base/metrics/histogram.h"
@@ -320,23 +319,8 @@ void CancelTerminate() {
static_cast<long>(tag),
[actionString UTF8String],
aTarget);
-
base::debug::ScopedCrashKey key(crash_keys::mac::kSendAction, value);
- // Certain third-party code, such as print drivers, can still throw
- // exceptions and Chromium cannot fix them. This provides a way to
- // work around those on a spot basis.
- bool enableNSExceptions = false;
-
- // http://crbug.com/80686 , an Epson printer driver.
- if (anAction == @selector(selectPDE:)) {
- enableNSExceptions = true;
- }
-
- // Minimize the window by keeping this close to the super call.
- scoped_ptr<base::mac::ScopedNSExceptionEnabler> enabler;
- if (enableNSExceptions)
- enabler.reset(new base::mac::ScopedNSExceptionEnabler());
return [super sendAction:anAction to:aTarget from:sender];
}
diff --git a/chrome/browser/chrome_browser_application_mac_unittest.mm b/chrome/browser/chrome_browser_application_mac_unittest.mm
index 9c31806..7b2adc9 100644
--- a/chrome/browser/chrome_browser_application_mac_unittest.mm
+++ b/chrome/browser/chrome_browser_application_mac_unittest.mm
@@ -4,7 +4,6 @@
#import <Cocoa/Cocoa.h>
-#import "base/mac/scoped_nsexception_enabler.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_samples.h"
@@ -20,8 +19,6 @@ namespace chrome_browser_application_mac {
// Generate an NSException with the given name.
NSException* ExceptionNamed(NSString* name) {
- base::mac::ScopedNSExceptionEnabler enabler;
-
return [NSException exceptionWithName:name
reason:@"No reason given"
userInfo:nil];
diff --git a/chrome/browser/mac/keystone_glue.mm b/chrome/browser/mac/keystone_glue.mm
index f125fdfc..e1d2db5 100644
--- a/chrome/browser/mac/keystone_glue.mm
+++ b/chrome/browser/mac/keystone_glue.mm
@@ -18,7 +18,6 @@
#include "base/mac/foundation_util.h"
#include "base/mac/mac_logging.h"
#include "base/mac/scoped_nsautorelease_pool.h"
-#include "base/mac/scoped_nsexception_enabler.h"
#include "base/memory/ref_counted.h"
#include "base/strings/sys_string_conversions.h"
#include "base/threading/worker_pool.h"
@@ -542,14 +541,7 @@ NSString* const kVersionKey = @"KSVersion";
[self updateStatus:kAutoupdateRegistering version:nil];
NSDictionary* parameters = [self keystoneParameters];
- BOOL result;
- {
- // TODO(shess): Allows Keystone to throw an exception when
- // /usr/bin/python does not exist (really!).
- // http://crbug.com/86221 and http://crbug.com/87931
- base::mac::ScopedNSExceptionEnabler enabler;
- result = [registration_ registerWithParameters:parameters];
- }
+ BOOL result = [registration_ registerWithParameters:parameters];
if (!result) {
[self updateStatus:kAutoupdateRegisterFailed version:nil];
return;
diff --git a/chrome/browser/spellchecker/spellcheck_platform_mac.mm b/chrome/browser/spellchecker/spellcheck_platform_mac.mm
index 4e5061d..a22f829 100644
--- a/chrome/browser/spellchecker/spellcheck_platform_mac.mm
+++ b/chrome/browser/spellchecker/spellcheck_platform_mac.mm
@@ -12,7 +12,6 @@
#include "base/bind_helpers.h"
#include "base/logging.h"
#include "base/mac/foundation_util.h"
-#include "base/mac/scoped_nsexception_enabler.h"
#include "base/strings/sys_string_conversions.h"
#include "base/time/time.h"
#include "chrome/common/spellcheck_common.h"
@@ -36,10 +35,11 @@ const unsigned int kShortLanguageCodeSize = 2;
// spell-checking will not work, but it also will not crash the
// browser.
NSSpellChecker* SharedSpellChecker() {
- return base::mac::ObjCCastStrict<NSSpellChecker>(
- base::mac::RunBlockIgnoringExceptions(^{
- return [NSSpellChecker sharedSpellChecker];
- }));
+ @try {
+ return [NSSpellChecker sharedSpellChecker];
+ } @catch (id exception) {
+ return nil;
+ }
}
// A private utility function to convert hunspell language codes to OS X
diff --git a/components/autofill/core/browser/personal_data_manager_mac.mm b/components/autofill/core/browser/personal_data_manager_mac.mm
index 1dcfbbc..5dfd5d7 100644
--- a/components/autofill/core/browser/personal_data_manager_mac.mm
+++ b/components/autofill/core/browser/personal_data_manager_mac.mm
@@ -11,7 +11,6 @@
#include "base/format_macros.h"
#include "base/guid.h"
#include "base/logging.h"
-#import "base/mac/scoped_nsexception_enabler.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/metrics/histogram_macros.h"
@@ -122,10 +121,10 @@ ABAddressBook* GetAddressBook(PrefService* pref_service) {
// +[ABAddressBook sharedAddressBook] throws an exception internally in
// circumstances that aren't clear. The exceptions are only observed in crash
// reports, so it is unknown whether they would be caught by AppKit and nil
- // returned, or if they would take down the app. In either case, avoid
- // crashing. http://crbug.com/129022
- ABAddressBook* addressBook = base::mac::RunBlockIgnoringExceptions(
- ^{ return [ABAddressBook sharedAddressBook]; });
+ // returned, or if they would take down the app.
+ // TODO(rsesek): If a crash is observed here, then the exception is not being
+ // caught by AppKit and it should be swallowed. http://crbug.com/129022
+ ABAddressBook* addressBook = [ABAddressBook sharedAddressBook];
UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookAvailable", addressBook != nil);
if (!g_accessed_address_book) {
diff --git a/media/capture/video/mac/video_capture_device_qtkit_mac.mm b/media/capture/video/mac/video_capture_device_qtkit_mac.mm
index 3415e03..2fc0b32 100644
--- a/media/capture/video/mac/video_capture_device_qtkit_mac.mm
+++ b/media/capture/video/mac/video_capture_device_qtkit_mac.mm
@@ -8,7 +8,6 @@
#include "base/debug/crash_logging.h"
#include "base/logging.h"
-#include "base/mac/scoped_nsexception_enabler.h"
#include "media/base/video_capture_types.h"
#include "media/capture/video/mac/video_capture_device_mac.h"
#include "media/capture/video/video_capture_device.h"
@@ -19,13 +18,14 @@
#pragma mark Class methods
+ (void)getDeviceNames:(NSMutableDictionary*)deviceNames {
- // Third-party drivers often throw exceptions, which are fatal in
- // Chromium (see comments in scoped_nsexception_enabler.h). The
- // following catches any exceptions and continues in an orderly
- // fashion with no devices detected.
- NSArray* captureDevices = base::mac::RunBlockIgnoringExceptions(^{
- return [QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo];
- });
+ // Third-party drivers often throw exceptions. The following catches any
+ // exceptions and continues in an orderly fashion with no devices detected.
+ NSArray* captureDevices = nil;
+ @try {
+ captureDevices =
+ [QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo];
+ } @catch (id exception) {
+ }
for (QTCaptureDevice* device in captureDevices) {
if ([[device attributeForKey:QTCaptureDeviceSuspendedAttribute] boolValue])
diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm
index 8689897..36badc3 100644
--- a/printing/printing_context_mac.mm
+++ b/printing/printing_context_mac.mm
@@ -12,7 +12,6 @@
#include "base/logging.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/mac/scoped_nsautorelease_pool.h"
-#include "base/mac/scoped_nsexception_enabler.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
@@ -86,11 +85,6 @@ void PrintingContextMac::AskUserForSettings(
bool has_selection,
bool is_scripted,
const PrintSettingsCallback& callback) {
- // Third-party print drivers seem to be an area prone to raising exceptions.
- // This will allow exceptions to be raised, but does not handle them. The
- // NSPrintPanel appears to have appropriate NSException handlers.
- base::mac::ScopedNSExceptionEnabler enabler;
-
// Exceptions can also happen when the NSPrintPanel is being
// deallocated, so it must be autoreleased within this scope.
base::mac::ScopedNSAutoreleasePool pool;
diff --git a/ui/base/clipboard/clipboard_mac.mm b/ui/base/clipboard/clipboard_mac.mm
index e42a49f..6233194 100644
--- a/ui/base/clipboard/clipboard_mac.mm
+++ b/ui/base/clipboard/clipboard_mac.mm
@@ -11,7 +11,6 @@
#include "base/logging.h"
#include "base/mac/mac_util.h"
#include "base/mac/scoped_cftyperef.h"
-#import "base/mac/scoped_nsexception_enabler.h"
#include "base/mac/scoped_nsobject.h"
#include "base/stl_util.h"
#include "base/strings/sys_string_conversions.h"
@@ -307,9 +306,12 @@ SkBitmap ClipboardMac::ReadImage(ClipboardType type) const {
// If the pasteboard's image data is not to its liking, the guts of NSImage
// may throw, and that exception will leak. Prevent a crash in that case;
// a blank image is better.
- base::scoped_nsobject<NSImage> image(base::mac::RunBlockIgnoringExceptions(^{
- return [[NSImage alloc] initWithPasteboard:GetPasteboard()];
- }));
+ base::scoped_nsobject<NSImage> image;
+ @try {
+ image.reset([[NSImage alloc] initWithPasteboard:GetPasteboard()]);
+ } @catch (id exception) {
+ }
+
SkBitmap bitmap;
if (image.get()) {
bitmap = gfx::NSImageToSkBitmapWithColorSpace(