Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Unified Diff: base/mac/scoped_nsexception_enabler.h

Issue 7038010: [Mac] Allow NSExceptions in certain cases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/mac/scoped_nsexception_enabler.h
diff --git a/base/mac/scoped_nsexception_enabler.h b/base/mac/scoped_nsexception_enabler.h
new file mode 100644
index 0000000000000000000000000000000000000000..d89131c03aa28d30751978bb21dfdc8549e0582d
--- /dev/null
+++ b/base/mac/scoped_nsexception_enabler.h
@@ -0,0 +1,50 @@
+// 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 {
+
+// ChromeBrowserApplication 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 throw in a limited
+// scope. Note that if an exception is throw, 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:
+ // Passing |true| enables exceptions within this scope, passing
+ // |false| leaves the current setting alone. This allows optionally
+ // enabling exceptions without requiring contrived code (like using
+ // |scoped_ptr<ScopedNSExceptionEnabler>|).
+ ScopedNSExceptionEnabler(bool enable);
Mark Mentovai 2011/05/17 19:07:34 Mark this “explicit.”
+ ~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 ChromeBrowserApplication, other code should use
+// the scoper.
+bool GetNSExceptionsAllowed();
+void SetNSExceptionsAllowed(bool allowed);
+
+} // namespace mac
+} // namespace base
+
+#endif BASE_MAC_SCOPED_NSEXCEPTION_ENABLER_H_

Powered by Google App Engine
This is Rietveld 408576698