Skip to content

Commit a122d11

Browse files
author
Lars Steiger
committed
Small adjustments.
1 parent 2fa1be8 commit a122d11

3 files changed

Lines changed: 87 additions & 55 deletions

File tree

FsprgEmbeddedStore/FsprgEmbeddedStoreController.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
* Controller for FastSpring's embedded store.
1616
*/
1717
@interface FsprgEmbeddedStoreController : NSObject {
18-
WebView* webView;
19-
id <FsprgEmbeddedStoreDelegate> delegate;
20-
NSString *storeHost;
18+
WebView* webView;
19+
id <FsprgEmbeddedStoreDelegate> delegate;
20+
NSString *storeHost;
21+
NSMutableDictionary *hostCertificates;
22+
NSMapTable *connectionsToRequests;
2123
}
2224

2325
- (WebView *)webView;

FsprgEmbeddedStore/FsprgEmbeddedStoreController.m

Lines changed: 76 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
#import "FsprgOrderView.h"
1111
#import "FsprgOrderDocumentRepresentation.h"
1212

13-
@interface FsprgEmbeddedStoreController ()
14-
15-
@property (nonatomic, retain) NSMutableDictionary *hostCertificates;
16-
@property (nonatomic, retain) NSMapTable *connectionsToRequests;
17-
18-
@end
1913

2014
@interface FsprgEmbeddedStoreController (Private)
2115

@@ -25,12 +19,15 @@ - (void)setIsSecure:(BOOL)aFlag;
2519
- (void)setStoreHost:(NSString *)aHost;
2620
- (void)resizeContentDivE;
2721
- (void)webViewFrameChanged:(NSNotification *)aNotification;
22+
- (NSMutableDictionary *)hostCertificates;
23+
- (void)hostCertificates:(NSMutableDictionary *)aHostCertificates;
24+
- (NSMapTable *)connectionsToRequests;
25+
- (void)setConnectionsToRequests:(NSMapTable *)aConnectionsToRequests;
2826

2927
@end
3028

3129
@implementation FsprgEmbeddedStoreController
3230

33-
@synthesize hostCertificates=_hostCertificates;
3431

3532
+ (void)initialize
3633
{
@@ -46,31 +43,20 @@ - (id) init
4643
[self setWebView:nil];
4744
[self setDelegate:nil];
4845
[self setStoreHost:nil];
49-
self.hostCertificates = [NSMutableDictionary dictionary];
50-
self.connectionsToRequests = [NSMapTable mapTableWithStrongToStrongObjects];
46+
[self setHostCertificates:[NSMutableDictionary dictionary]];
47+
[self setConnectionsToRequests:[NSMapTable mapTableWithStrongToStrongObjects]];
5148
}
5249
return self;
5350
}
5451

55-
- (void)dealloc
56-
{
57-
[self setWebView:nil];
58-
[self setDelegate:nil];
59-
[self setStoreHost:nil];
60-
[_hostCertificates release];
61-
[_connectionsToRequests release];
62-
63-
[super dealloc];
64-
}
65-
6652
- (WebView *)webView
6753
{
68-
return [[webView retain] autorelease];
54+
return [[webView retain] autorelease];
6955
}
7056

7157
- (void)setWebView:(WebView *)aWebView
7258
{
73-
if (webView != aWebView) {
59+
if (webView != aWebView) {
7460
[webView setPostsFrameChangedNotifications:FALSE];
7561
[webView setFrameLoadDelegate:nil];
7662
[webView setUIDelegate:nil];
@@ -79,7 +65,7 @@ - (void)setWebView:(WebView *)aWebView
7965
[[NSNotificationCenter defaultCenter] removeObserver:self];
8066

8167
[webView release];
82-
webView = [aWebView retain];
68+
webView = [aWebView retain];
8369

8470
if (webView) {
8571
[webView setPostsFrameChangedNotifications:TRUE];
@@ -90,17 +76,17 @@ - (void)setWebView:(WebView *)aWebView
9076
[[NSNotificationCenter defaultCenter] addObserver:self
9177
selector:@selector(webViewFrameChanged:)
9278
name:NSViewFrameDidChangeNotification
93-
object:webView];
79+
object:webView];
9480
[[NSNotificationCenter defaultCenter] addObserver:self
9581
selector:@selector(estimatedLoadingProgressChanged:)
9682
name:WebViewProgressStartedNotification
97-
object:webView];
83+
object:webView];
9884
[[NSNotificationCenter defaultCenter] addObserver:self
9985
selector:@selector(estimatedLoadingProgressChanged:)
10086
name:WebViewProgressEstimateChangedNotification
101-
object:webView];
87+
object:webView];
10288
}
103-
}
89+
}
10490
}
10591

10692
- (id <FsprgEmbeddedStoreDelegate>)delegate
@@ -121,8 +107,9 @@ - (void)setDelegate:(id <FsprgEmbeddedStoreDelegate>)aDelegate
121107
- (void)loadWithParameters:(FsprgStoreParameters *)parameters
122108
{
123109
NSURLRequest *urlRequest = [parameters toURLRequest];
124-
if (urlRequest == nil)
110+
if (urlRequest == nil) {
125111
return;
112+
}
126113

127114
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[urlRequest URL]];
128115
NSUInteger i, count = [cookies count];
@@ -180,31 +167,34 @@ - (void)setIsSecure:(BOOL)aFlag
180167

181168
- (NSArray *)securityCertificates
182169
{
183-
if ([self isSecure] == NO)
170+
if ([self isSecure] == NO) {
184171
return nil;
172+
}
173+
185174
NSString *mainFrameURL = [[self webView] mainFrameURL];
186175
NSString *host = [[NSURL URLWithString:mainFrameURL] host];
187-
return [self.hostCertificates objectForKey:host];
176+
return [[self hostCertificates] objectForKey:host];
188177
}
189178

190179
- (NSString *)storeHost
191180
{
192-
return [[storeHost retain] autorelease];
181+
return [[storeHost retain] autorelease];
193182
}
194183

195184
- (void)setStoreHost:(NSString *)aHost
196185
{
197-
if (storeHost != aHost) {
186+
if (storeHost != aHost) {
198187
[storeHost release];
199-
storeHost = [aHost retain];
200-
}
188+
storeHost = [aHost retain];
189+
}
201190
}
202191

203-
- (void)resizeContentDivE {
204-
if ([self.delegate respondsToSelector:@selector(shouldStoreControllerFixContentDivHeight:)])
205-
{
206-
if ([self.delegate shouldStoreControllerFixContentDivHeight:self] == NO)
192+
- (void)resizeContentDivE
193+
{
194+
if ([[self delegate] respondsToSelector:@selector(shouldStoreControllerFixContentDivHeight:)]) {
195+
if ([[self delegate] shouldStoreControllerFixContentDivHeight:self] == NO) {
207196
return;
197+
}
208198
}
209199

210200
DOMElement *resizableContentE = [[[[self webView] mainFrame] DOMDocument] getElementById:@"FsprgResizableContent"];
@@ -214,8 +204,9 @@ - (void)resizeContentDivE {
214204

215205
float windowHeight = [[self webView] frame].size.height;
216206
id result = [[[self webView] windowScriptObject] evaluateWebScript:@"document.getElementsByClassName('store-page-navigation')[0].clientHeight"];
217-
if (result == [WebUndefined undefined])
207+
if (result == [WebUndefined undefined]) {
218208
return;
209+
}
219210
float pageNavigationHeight = [(NSString *)result floatValue];
220211

221212
DOMCSSStyleDeclaration *cssStyle = [[self webView] computedStyleForElement:resizableContentE pseudoElement:nil];
@@ -231,8 +222,34 @@ - (void)webViewFrameChanged:(NSNotification *)aNotification
231222
[self resizeContentDivE];
232223
}
233224

225+
- (NSMutableDictionary *)hostCertificates
226+
{
227+
return [[hostCertificates retain] autorelease];
228+
}
229+
- (void)setHostCertificates:(NSMutableDictionary *)anHostCertificates
230+
{
231+
if (hostCertificates != anHostCertificates) {
232+
[anHostCertificates retain];
233+
[hostCertificates release];
234+
hostCertificates = anHostCertificates;
235+
}
236+
}
237+
238+
- (NSMapTable *)connectionsToRequests
239+
{
240+
return [[connectionsToRequests retain] autorelease];
241+
}
242+
- (void)setConnectionsToRequests:(NSMapTable *)aConnectionsToRequests
243+
{
244+
if (connectionsToRequests != aConnectionsToRequests) {
245+
[aConnectionsToRequests retain];
246+
[connectionsToRequests release];
247+
connectionsToRequests = aConnectionsToRequests;
248+
}
249+
}
250+
234251

235-
// WebFrameLoadDelegate
252+
#pragma mark - WebFrameLoadDelegate
236253

237254
- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame
238255
{
@@ -278,7 +295,7 @@ - (void)webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame
278295
[[self delegate] webView:sender didFailLoadWithError:error forFrame:frame];
279296
}
280297

281-
// WebUIDelegate
298+
#pragma mark - WebUIDelegate
282299

283300
- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
284301
{
@@ -289,7 +306,7 @@ - (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *
289306

290307
- (NSUInteger)webView:(WebView *)sender dragDestinationActionMaskForDraggingInfo:(id <NSDraggingInfo>)draggingInfo
291308
{
292-
return WebDragDestinationActionNone;
309+
return WebDragDestinationActionNone;
293310
}
294311

295312
- (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request
@@ -312,10 +329,10 @@ - (NSURLRequest *)webView:(WebView *)sender resource:(id)identifier willSendRequ
312329
{
313330
NSURL *URL = [request URL];
314331
NSString *host = [URL host];
315-
if ([self.hostCertificates objectForKey:host] == nil)
332+
if ([[self hostCertificates] objectForKey:host] == nil)
316333
{
317334
NSURLConnection *connection = [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
318-
[self.connectionsToRequests setObject:request forKey:connection];
335+
[[self connectionsToRequests] setObject:request forKey:connection];
319336
}
320337
return request;
321338
}
@@ -342,7 +359,7 @@ - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSUR
342359

343360
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
344361
{
345-
[self.connectionsToRequests setObject:nil forKey:connection];
362+
[[self connectionsToRequests] setObject:nil forKey:connection];
346363
}
347364

348365
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
@@ -364,10 +381,22 @@ - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallen
364381
[certificates addObject:(id)certificateRef];
365382
}
366383

367-
NSURLRequest *request = [self.connectionsToRequests objectForKey:connection];
384+
NSURLRequest *request = [[self connectionsToRequests] objectForKey:connection];
368385
NSURL *URL = [request URL];
369386
NSString *host = [URL host];
370-
[self.hostCertificates setObject:certificates forKey:host];
387+
[[self hostCertificates] setObject:certificates forKey:host];
388+
}
389+
390+
391+
- (void)dealloc
392+
{
393+
[self setWebView:nil];
394+
[self setDelegate:nil];
395+
[self setStoreHost:nil];
396+
[self setHostCertificates:nil];
397+
[self setConnectionsToRequests:nil];
398+
399+
[super dealloc];
371400
}
372401

373402
@end

FsprgEmbeddedStore/FsprgStoreParameters.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ - (void)setRaw:(NSMutableDictionary *)aRaw
105105
- (NSURLRequest *)toURLRequest
106106
{
107107
NSURL *toURL = [self toURL];
108-
if (toURL)
109-
return [NSMutableURLRequest requestWithURL:toURL];
110-
return nil;
108+
if (toURL) {
109+
return [NSMutableURLRequest requestWithURL:toURL];
110+
} else {
111+
return nil;
112+
}
111113
}
112114

113115
- (NSURL *)toURL
@@ -132,8 +134,7 @@ - (NSURL *)toURL
132134
urlAsStr = [NSString stringWithFormat:@"https://sites.fastspring.com/%@/instant/%@", storeIdEncoded, productIdEncoded];
133135
} else if ([kFsprgOrderProcessCheckout isEqualTo:[self orderProcessType]]) {
134136
urlAsStr = [NSString stringWithFormat:@"https://sites.fastspring.com/%@/checkout/%@", storeIdEncoded, productIdEncoded];
135-
}
136-
else {
137+
} else {
137138
NSAssert1(FALSE, @"OrderProcessType '%@' unknown.", [self orderProcessType]);
138139
return nil;
139140
}

0 commit comments

Comments
 (0)