platform/iphone/Classes/WebViewController.m in rhodes-1.2.2 vs platform/iphone/Classes/WebViewController.m in rhodes-1.4.0
- old
+ new
@@ -1,21 +1,23 @@
#import "WebViewController.h"
-#import "ruby/ext/rho/rhoruby.h"
+//#import "ruby/ext/rho/rhoruby.h"
//#import "UniversalLock.h"
#import "common/RhoConf.h"
-#import "sync/syncthread.h"
+//#import "sync/syncthread.h"
+#import "common/RhodesApp.h"
#import "logging/RhoLog.h"
#undef DEFAULT_LOGCATEGORY
#define DEFAULT_LOGCATEGORY "WebViewCtrl"
-
+/*
static char currentLocation[4096] = "";
//INIT_LOCK(current_location); // racing condition on thid lock, need to fix it somehow
void set_current_location(CFStringRef location) {
//LOCK(current_location);
CFStringGetCString((CFStringRef)location, currentLocation, sizeof(currentLocation), CFStringGetSystemEncoding());
+
char* fragment = strstr(currentLocation,"#");
if (fragment) *fragment = 0; //cut out fragment
RAWLOG_INFO1("Current location: %s",currentLocation);
//UNLOCK(current_location);
@@ -24,22 +26,26 @@
rho_conf_save();
}
}
-
char* get_current_location() {
//LOCK(current_location);
return currentLocation;
//UNLOCK(current_location);
-}
+}*/
@implementation WebViewController
-@synthesize viewHomeUrl, viewOptionsUrl;
+//@synthesize viewHomeUrl, viewOptionsUrl;
@synthesize actionTarget, onShowLog, toolbar, webView;
+- (void)viewDidAppear:(BOOL)animated
+{
+ [super viewDidAppear:animated];
+}
+
-(void)viewDidLoad {
[super viewDidLoad];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
bool logEnabled = [defaults boolForKey:@"log_enabled_preference"];
@@ -63,49 +69,75 @@
-(void)loadHTMLString:(NSString*)data {
RAWLOG_INFO("Loading specified HTML string");
[webView loadHTMLString:data baseURL: [NSURL URLWithString:@""]];
}
+-(void)showToolbar:(BOOL)show {
+ toolbar.hidden = !show;
+ if (show) {
+ [window sendSubviewToBack:webView];
+ [window bringSubviewToFront:toolbar];
+ }
+ else {
+ [window sendSubviewToBack:toolbar];
+ [window bringSubviewToFront:webView];
+ }
+ [webView sizeToFit];
+}
+
-(void)navigate:(NSString*)url {
- RAWLOG_INFO("Navigating to the specifyed URL");
- [webView loadRequest:[NSURLRequest requestWithURL: [NSURL URLWithString:url]]];
+ //RAWLOG_INFO1("Navigating to the specifyed URL: %s", [url cStringUsingEncoding:[NSString defaultCStringEncoding]]);
+ NSString *escapedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+ [webView loadRequest:[NSURLRequest requestWithURL: [NSURL URLWithString:escapedUrl]]];
}
-(void)executeJs:(JSString*)js {
RAWLOG_INFO1("Executing JS: %s", [js.inputJs UTF8String] );
js.outputJs = [webView stringByEvaluatingJavaScriptFromString:js.inputJs];
}
-(void)navigateRedirect:(NSString*)url {
+ //RAWLOG_INFO1("Navigate (redirect) to: %s", [url cStringUsingEncoding:[NSString defaultCStringEncoding]]);
NSString* escapedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- escapedUrl = [escapedUrl stringByReplacingOccurrencesOfString: @"&" withString: @"%26"];
NSString* redirector = [@"http://localhost:8080/system/redirect_to?url=" stringByAppendingString:escapedUrl];
[webView loadRequest:[NSURLRequest requestWithURL: [NSURL URLWithString:redirector]]];
}
--(IBAction)goBack {
- [webView goBack];
+-(IBAction)goBack
+{
+ const char* szBackUrl = rho_rhodesapp_getappbackurl();
+ if ( szBackUrl && *szBackUrl )
+ [self navigateRedirect:[NSString stringWithCString:szBackUrl encoding:[NSString defaultCStringEncoding]]];
+ else
+ [webView goBack];
}
-(IBAction)goForward {
[webView goForward];
}
-(IBAction)goHome {
- if (viewHomeUrl != NULL) {
- [self navigateRedirect:viewHomeUrl];
- }
+ const char* url = rho_rhodesapp_getstarturl();
+ [self navigateRedirect:[NSString stringWithCString:url encoding:[NSString defaultCStringEncoding]]];
+ //if (viewHomeUrl != NULL) {
+ // [self navigateRedirect:viewHomeUrl];
+ //}
}
-(IBAction)goOptions {
- if (viewOptionsUrl != NULL) {
- [self navigateRedirect:viewOptionsUrl];
- }
+ const char* url = rho_rhodesapp_getoptionsurl();
+ [self navigateRedirect:[NSString stringWithCString:url encoding:[NSString defaultCStringEncoding]]];
+
+ //if (viewOptionsUrl != NULL) {
+ // [self navigateRedirect:viewOptionsUrl];
+ //}
}
-(IBAction)refresh {
[webView reload];
+ //const char* url = rho_rhodesapp_getcurrenturl();
+ //[self navigateRedirect:[NSString stringWithCString:url encoding:[NSString defaultCStringEncoding]]];
}
-(void)setActivityInfo:(NSString *)labelText {
if (!labelText) {
activityInfo.hidden = YES;
@@ -142,18 +174,18 @@
if ([webView canGoForward]) {
forwardBtn.enabled = YES;
} else {
forwardBtn.enabled = NO;
}
-
- NSString* location = [webview stringByEvaluatingJavaScriptFromString:@"location.href"];
- set_current_location((CFStringRef)location);
+
+ //NSString* location = [webview stringByEvaluatingJavaScriptFromString:@"location.href"];
+ //rho_rhodesapp_keeplastvisitedurl( [location cStringUsingEncoding:[NSString defaultCStringEncoding]] );
}
-
+/*
- (void)runSync
{
rho_sync_doSyncAllSources(TRUE);
-}
+}*/
- (void)actionShowLog:(id)sender
{
if(actionTarget && [actionTarget respondsToSelector:onShowLog]) {
[actionTarget performSelector:onShowLog];