Created
April 27, 2011 08:22
-
-
Save laiso/943911 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface UIWebViewBaseTest : NSObject <UIApplicationDelegate> { | |
UIWebView* web; | |
} | |
@property (nonatomic, retain) IBOutlet UIWindow *window; | |
@property (nonatomic, retain) UIWebView* web; | |
@end | |
@implementation UIWebViewBaseTest | |
@synthesize window=_window; | |
@synthesize web; | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
[self.window makeKeyAndVisible]; | |
web = [[UIWebView alloc] initWithFrame:self.window.frame]; | |
[self.window addSubview:web]; | |
UIButton* b = [UIButton buttonWithType:UIButtonTypeContactAdd]; | |
b.frame = CGRectMake(0, 0, 100, 100); | |
[b addTarget:self action:@selector(execCode) forControlEvents:UIControlEventTouchDown]; | |
[self.window addSubview:b]; | |
return YES; | |
} | |
-(void)execCode | |
{ | |
NSString* script = | |
@"<script>" | |
@"window.location = 'http://hamachiya.com/junk/gmail_fortune.html';" | |
@"</script>"; | |
[web loadHTMLString:script baseURL:nil]; | |
/* | |
NSString* script = | |
@"window.location = 'http://hamachiya.com/junk/gmail_fortune.html';" | |
NSString* result = [web stringByEvaluatingJavaScriptFromString:script]; | |
NSLog(@"%@", result); | |
*/ | |
/* | |
// 危険なコードを返す | |
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8080/test"]]]; | |
*/ | |
} | |
- (void)dealloc | |
{ | |
[_window release]; | |
[web release]; | |
[super dealloc]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment