1
// Copyright 2007, Google Inc.
3
// Redistribution and use in source and binary forms, with or without
4
// modification, are permitted provided that the following conditions are met:
6
// 1. Redistributions of source code must retain the above copyright notice,
7
// this list of conditions and the following disclaimer.
8
// 2. Redistributions in binary form must reproduce the above copyright notice,
9
// this list of conditions and the following disclaimer in the documentation
10
// and/or other materials provided with the distribution.
11
// 3. Neither the name of Google Inc. nor the names of its contributors may be
12
// used to endorse or promote products derived from this software without
13
// specific prior written permission.
15
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
// Common definitions and functions for Gears Safari.
28
#ifndef GEARS_BASE_COMMON_COMMON_SF_H__
29
#define GEARS_BASE_COMMON_COMMON_SF_H__
31
#include <CoreFoundation/CoreFoundation.h>
33
#import <Foundation/Foundation.h>
36
#include "genfiles/product_constants.h"
37
#include "gears/base/common/basictypes.h"
38
#include "gears/base/common/string_utils.h"
39
#include "gears/base/common/string_utils_osx.h"
43
#if defined(__cplusplus)
49
// NSInteger is a new type defined in Leopard, add these typedefs so code
50
// using it will work with pre-10.5 SDKs.
51
#if __LP64__ || NS_BUILD_32_LIKE_64
52
typedef long NSInteger;
53
typedef unsigned long NSUInteger;
55
typedef int NSInteger;
56
typedef unsigned int NSUInteger;
59
NSString *StringWithLocalizedKey(NSString *key, ...);
60
void ThrowExceptionKey(NSString *key, ...);
63
#if defined(__cplusplus)
67
// Wrappers for throwing localized vararg exceptions
69
#define ThrowExceptionKeyAndReturn(key, ...) \
71
ThrowExceptionKey(key, ##__VA_ARGS__); \
75
#define ThrowExceptionKeyAndReturnNil(key, ...) \
77
ThrowExceptionKey(key, ##__VA_ARGS__); \
81
#define ThrowExceptionKeyAndReturnNo(key, ...) \
83
ThrowExceptionKey(key, ##__VA_ARGS__); \
89
// The following two functions are needed to work around
90
// http://bugs.webkit.org/show_bug.cgi?id=16829
91
// this is fixed in newer versions of Safari v4 and WebKit trunk
92
// >r39912 see https://bugs.webkit.org/show_bug.cgi?id=23201 for
94
bool NeedsSafariNPN_SetExceptionWorkaround();
96
// Throw exception via WebKit's WebScriptObject interface.
97
void WebKitNPN_SetException(NPObject* obj, const char *message);
99
// Check system version.
100
bool IsLeopardOrGreater();
102
// Debug only code to help us assert that class methods are restricted to a
103
// single thread. To use, add a DECL_SINGLE_THREAD to your class declaration.
104
// Then, add ASSERT_SINGLE_THREAD() calls to the top of each class method.
105
#if defined(__cplusplus)
108
class CurrentThreadID {
111
id_ = pthread_self();
120
#define DECL_SINGLE_THREAD \
121
CurrentThreadID current_thread_id_;
123
#define ASSERT_SINGLE_THREAD() \
124
assert(pthread_equal(current_thread_id_.get(), pthread_self()))
126
#define ASSERT_IS_RUNNING_ON_MAIN_THREAD() \
127
assert(pthread_main_np() != 0)
129
#define DECL_SINGLE_THREAD
130
#define ASSERT_SINGLE_THREAD()
131
#define ASSERT_IS_RUNNING_ON_MAIN_THREAD()
135
#endif // GEARS_BASE_COMMON_COMMON_SF_H__