Skip to content

Commit

Permalink
Revert "Added support for custom headers"
Browse files Browse the repository at this point in the history
This reverts commit 3633dbd.

This is a shot at getting iframes to work correctly again.
  • Loading branch information
milgner committed Apr 23, 2015
1 parent bf3f739 commit 0b36673
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 70 deletions.
4 changes: 2 additions & 2 deletions Classes/TiUIWebView+Extend.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

@interface TiUIWebView (Extend)

- (void)setNormalScrollSpeed_:(id)args;
@property (nonatomic, retain) NSDictionary *customHeaders;
- (void)setNormalScrollSpeed_:(id)args;

@end
84 changes: 23 additions & 61 deletions Classes/TiUIWebView+Extend.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@

#import "TiUIWebView+Extend.h"
#import "TiUtils.h"
#import <objc/runtime.h>

@implementation TiUIWebView (Extend)

#pragma mark
#pragma iVars
- (void)setNormalScrollSpeed_:(id)args
{
BOOL normalSpeed = [TiUtils boolValue:args def:NO];
Expand Down Expand Up @@ -54,69 +51,34 @@ - (void)setUserAgentForiOS_:(id)args
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
}

-(NSDictionary *)customHeaders
{
return objc_getAssociatedObject(self, @selector(customHeaders));
}

-(void)setCustomHeaders_:(NSDictionary *)headers
{
objc_setAssociatedObject(self, @selector(customHeaders), headers, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

-(NSDictionary *)customHeaders_
{
return objc_getAssociatedObject(self, @selector(customHeaders));
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
BOOL headerIsPresent = [[request allHTTPHeaderFields] objectForKey:@"x-adp-app"]!=nil;

// Get request URL
NSURL *url = [request URL];

if(headerIsPresent) {//|| self.customHeaders.count == 0
// Get scheme information
NSString *scheme = [[url scheme] lowercaseString];
// Get URL path information
NSString *path = [url path];
// If the path begins with "/"
if([path hasPrefix:@"/"]) {
// Remove the head of the "/"
path = [path substringWithRange:NSMakeRange(1, path.length - 1)];
}
// If the scheme begins with "extendwebview"
if ([scheme isEqualToString:@"extendwebview"]) {
// Get event name from host
NSString *eventName = [url host];
// The same as the event name if it has been registered in the event listener
if ([self.proxy _hasListeners:eventName]){
NSLog(@"[DEBUG] fire: %@",eventName);
// Get event information
NSDictionary *event = [NSDictionary dictionaryWithObjectsAndKeys:path, @"path", eventName, @"event", nil];
// Execute
[self.proxy fireEvent:eventName withObject:event];
}
return NO;
}
return YES;
// Get scheme information
NSString *scheme = [[url scheme] lowercaseString];
// Get URL path information
NSString *path = [url path];
// If the path begins with "/"
if([path hasPrefix:@"/"]) {
// Remove the head of the "/"
path = [path substringWithRange:NSMakeRange(1, path.length - 1)];
}
else
{
// this header is here to determine if the custom headers already has been added or not. this to prevent infinite loop
[request addValue:@"true" forHTTPHeaderField:@"x-adp-app"];

// set the new headers
for(NSString *key in [self.customHeaders allKeys]){
[request addValue:[self.customHeaders objectForKey:key] forHTTPHeaderField:key];
// If the scheme begins with "extendwebview"
if ([scheme isEqualToString:@"extendwebview"]) {
// Get event name from host
NSString *eventName = [url host];
// The same as the event name if it has been registered in the event listener
if ([self.proxy _hasListeners:eventName]){
NSLog(@"[DEBUG] fire: %@",eventName);
// Get event information
NSDictionary *event = [NSDictionary dictionaryWithObjectsAndKeys:path, @"path", eventName, @"event", nil];
// Execute
[self.proxy fireEvent:eventName withObject:event];
}

[webView loadRequest:request];
return NO;
}

return YES;
return NO;
}
return YES;
}

@end
@end
8 changes: 1 addition & 7 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,8 @@ picker.selectionIndicator = true;
window.add(picker);
*/

/*
var webview = Ti.UI.createWebView({
url: 'https://github.com/viezel/NappUI',
scalesPageToFit: true
});

webview.setCustomHeaders({"x-custom-1": "custom-value-1", "x-custom-2": "custom-value-2"});
*/


window.add(view);
window.open();
Expand Down

0 comments on commit 0b36673

Please sign in to comment.