• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1.  Redistributions of source code must retain the above copyright
9 *     notice, this list of conditions and the following disclaimer.
10 * 2.  Redistributions in binary form must reproduce the above copyright
11 *     notice, this list of conditions and the following disclaimer in the
12 *     documentation and/or other materials provided with the distribution.
13 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 *     its contributors may be used to endorse or promote products derived
15 *     from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#import "WebSecurityOriginInternal.h"
30
31#import <WebCore/DatabaseTracker.h>
32#import <WebCore/KURL.h>
33#import <WebCore/SecurityOrigin.h>
34
35using namespace WebCore;
36
37@implementation WebSecurityOrigin
38- (id)initWithURL:(NSURL *)url
39{
40    self = [super init];
41    if (!self)
42        return nil;
43
44    RefPtr<SecurityOrigin> origin = SecurityOrigin::create(KURL([url absoluteURL]));
45    origin->ref();
46    _private = reinterpret_cast<WebSecurityOriginPrivate*>(origin.get());
47
48    return self;
49}
50
51- (NSString*)protocol
52{
53    return reinterpret_cast<SecurityOrigin*>(_private)->protocol();
54}
55
56- (NSString*)host
57{
58    return reinterpret_cast<SecurityOrigin*>(_private)->host();
59}
60
61// Deprecated. Use host instead. This needs to stay here until we ship a new Safari.
62- (NSString*)domain
63{
64    return [self host];
65}
66
67- (unsigned short)port
68{
69    return reinterpret_cast<SecurityOrigin*>(_private)->port();
70}
71
72- (unsigned long long)usage
73{
74#if ENABLE(DATABASE)
75    return DatabaseTracker::tracker().usageForOrigin(reinterpret_cast<SecurityOrigin*>(_private));
76#else
77    return 0;
78#endif
79}
80
81- (unsigned long long)quota
82{
83#if ENABLE(DATABASE)
84    return DatabaseTracker::tracker().quotaForOrigin(reinterpret_cast<SecurityOrigin*>(_private));
85#else
86    return 0;
87#endif
88}
89
90// Sets the storage quota (in bytes)
91// If the quota is set to a value lower than the current usage, that quota will "stick" but no data will be purged to meet the new quota.
92// This will simply prevent new data from being added to databases in that origin
93- (void)setQuota:(unsigned long long)quota
94{
95#if ENABLE(DATABASE)
96    DatabaseTracker::tracker().setQuota(reinterpret_cast<SecurityOrigin*>(_private), quota);
97#endif
98}
99
100- (BOOL)isEqual:(id)anObject
101{
102    if (![anObject isMemberOfClass:[WebSecurityOrigin class]]) {
103        return NO;
104    }
105
106    return [self _core]->equal([anObject _core]);
107}
108
109- (void)dealloc
110{
111    if (_private)
112        reinterpret_cast<SecurityOrigin*>(_private)->deref();
113    [super dealloc];
114}
115
116- (void)finalize
117{
118    if (_private)
119        reinterpret_cast<SecurityOrigin*>(_private)->deref();
120    [super finalize];
121}
122
123@end
124
125@implementation WebSecurityOrigin (WebInternal)
126
127- (id)_initWithWebCoreSecurityOrigin:(SecurityOrigin*)origin
128{
129    ASSERT(origin);
130    self = [super init];
131    if (!self)
132        return nil;
133
134    origin->ref();
135    _private = reinterpret_cast<WebSecurityOriginPrivate*>(origin);
136
137    return self;
138}
139
140- (SecurityOrigin *)_core
141{
142    return reinterpret_cast<SecurityOrigin*>(_private);
143}
144
145@end
146