~ubuntu-branches/ubuntu/karmic/gears/karmic

« back to all changes in this revision

Viewing changes to gears/base/common/common_sf.h

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Lesicnik
  • Date: 2009-04-30 19:15:25 UTC
  • Revision ID: james.westby@ubuntu.com-20090430191525-0790sb5wzg8ou0xb
Tags: upstream-0.5.21.0~svn3334+dfsg
ImportĀ upstreamĀ versionĀ 0.5.21.0~svn3334+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2007, Google Inc.
 
2
//
 
3
// Redistribution and use in source and binary forms, with or without
 
4
// modification, are permitted provided that the following conditions are met:
 
5
//
 
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.
 
14
//
 
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.
 
25
 
 
26
// Common definitions and functions for Gears Safari.
 
27
 
 
28
#ifndef GEARS_BASE_COMMON_COMMON_SF_H__
 
29
#define GEARS_BASE_COMMON_COMMON_SF_H__
 
30
 
 
31
#include <CoreFoundation/CoreFoundation.h>
 
32
#ifdef __OBJC__
 
33
#import <Foundation/Foundation.h>
 
34
#endif
 
35
 
 
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"
 
40
 
 
41
struct NPObject;
 
42
 
 
43
#if defined(__cplusplus)
 
44
extern "C" {
 
45
#endif
 
46
 
 
47
#ifdef __OBJC__
 
48
 
 
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;
 
54
#else
 
55
typedef int NSInteger;
 
56
typedef unsigned int NSUInteger;
 
57
#endif
 
58
 
 
59
NSString *StringWithLocalizedKey(NSString *key, ...);
 
60
void ThrowExceptionKey(NSString *key, ...);
 
61
#endif
 
62
 
 
63
#if defined(__cplusplus)
 
64
}
 
65
#endif
 
66
 
 
67
// Wrappers for throwing localized vararg exceptions
 
68
#ifdef __OBJC__
 
69
#define ThrowExceptionKeyAndReturn(key, ...) \
 
70
  do { \
 
71
    ThrowExceptionKey(key, ##__VA_ARGS__); \
 
72
    return; \
 
73
  } while(0)
 
74
 
 
75
#define ThrowExceptionKeyAndReturnNil(key, ...) \
 
76
  do { \
 
77
    ThrowExceptionKey(key, ##__VA_ARGS__); \
 
78
    return nil; \
 
79
  } while(0)
 
80
 
 
81
#define ThrowExceptionKeyAndReturnNo(key, ...) \
 
82
  do { \
 
83
    ThrowExceptionKey(key, ##__VA_ARGS__); \
 
84
    return NO; \
 
85
  } while(0)
 
86
 
 
87
#endif  // __OBJC__
 
88
 
 
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 
 
93
// fix details.
 
94
bool NeedsSafariNPN_SetExceptionWorkaround();
 
95
 
 
96
// Throw exception via WebKit's WebScriptObject interface.
 
97
void WebKitNPN_SetException(NPObject* obj, const char *message);
 
98
 
 
99
// Check system version.
 
100
bool IsLeopardOrGreater();
 
101
 
 
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)
 
106
#ifdef DEBUG
 
107
 
 
108
class CurrentThreadID {
 
109
 public:
 
110
  CurrentThreadID() {
 
111
    id_ = pthread_self();
 
112
  }
 
113
  pthread_t get() {
 
114
    return id_;
 
115
  }
 
116
 private:
 
117
  pthread_t id_;
 
118
};
 
119
 
 
120
#define DECL_SINGLE_THREAD \
 
121
  CurrentThreadID current_thread_id_;
 
122
 
 
123
#define ASSERT_SINGLE_THREAD() \
 
124
assert(pthread_equal(current_thread_id_.get(), pthread_self()))
 
125
 
 
126
#define ASSERT_IS_RUNNING_ON_MAIN_THREAD() \
 
127
assert(pthread_main_np() != 0)
 
128
#else
 
129
#define DECL_SINGLE_THREAD
 
130
#define ASSERT_SINGLE_THREAD()
 
131
#define ASSERT_IS_RUNNING_ON_MAIN_THREAD()
 
132
#endif  // DEBUG
 
133
#endif  // C++
 
134
 
 
135
#endif  // GEARS_BASE_COMMON_COMMON_SF_H__