]> git.saurik.com Git - cydia.git/commitdiff
Polished browser and finished repotagging.
authorJay Freeman (saurik) <saurik@saurk.com>
Mon, 26 Jan 2009 10:31:46 +0000 (10:31 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Thu, 30 Sep 2010 07:09:40 +0000 (07:09 +0000)
Cydia.mm
UICaboodle/BrowserView.h
UICaboodle/BrowserView.m
control

index 131c0eed28148f7738e70bfe7082ae6f6bf58ff2..92f58229375d10b8f9d63d66cf2b47b2a63f7fde 100644 (file)
--- a/Cydia.mm
+++ b/Cydia.mm
@@ -263,8 +263,7 @@ void NSLogRect(const char *fix, const CGRect &rect) {
 }
 
 - (id) yieldToSelector:(SEL)selector withObject:(id)object {
-    /*[self performSelector:selector withObject:object];
-    return;*/
+    /*return [self performSelector:selector withObject:object];*/
 
     volatile bool stopped(false);
 
@@ -382,9 +381,9 @@ extern NSString * const kCAFilterNearest;
 
 #define lprintf(args...) fprintf(stderr, args)
 
-#define ForRelease 0
+#define ForRelease 1
 #define ForSaurik (1 && !ForRelease)
-#define ShowInternals (0 && !ForRelease)
+#define ShowInternals (1 && !ForRelease)
 #define IgnoreInstall (0 && !ForRelease)
 #define RecycleWebViews 0
 #define AlwaysReload (1 && !ForRelease)
@@ -393,9 +392,9 @@ extern NSString * const kCAFilterNearest;
 #undef _trace
 #define _trace(args...)
 #undef _profile
-#define _profile(name)
+#define _profile(name) {
 #undef _end
-#define _end
+#define _end }
 #define PrintTimes() do {} while (false)
 #endif
 
@@ -787,6 +786,8 @@ static UIFont *Font22Bold_;
 static const char *Machine_ = NULL;
 static const NSString *UniqueID_ = nil;
 static const NSString *Build_ = nil;
+static const NSString *Product_ = nil;
+static const NSString *Safari_ = nil;
 
 CFLocaleRef Locale_;
 CGColorSpaceRef space_;
@@ -4145,6 +4146,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [super webView:sender didClearWindowObject:window forFrame:frame];
 }
 
+- (bool) _allowJavaScriptPanel {
+    return false;
+}
+
 #if !AlwaysReload
 - (void) _rightButtonClicked {
     /*[super _rightButtonClicked];
@@ -4695,7 +4700,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (NSString *) getWarning {
-    NSString *href([href_ stringByAddingPercentEscapesIncludingReserved]);
+    NSString *href(href_);
+    NSRange colon([href rangeOfString:@"://"]);
+    if (colon.location != NSNotFound)
+        href = [href substringFromIndex:(colon.location + 3)];
+    href = [href stringByAddingPercentEscapes];
     href = [@"http://cydia.saurik.com/api/repotag/" stringByAppendingString:href];
     href = [href stringByCachingURLWithCurrentCDN];
 
@@ -4723,17 +4732,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         trivial_bz2_ == nil &&
         trivial_gz_ == nil
     ) {
-        [delegate_ setStatusBarShowsProgress:NO];
-        [delegate_ removeProgressHUD:hud_];
-
-        [hud_ autorelease];
-        hud_ = nil;
+        bool defer(false);
 
         if (trivial_) {
             if (NSString *warning = [self yieldToSelector:@selector(getWarning)]) {
+                defer = true;
+
                 UIActionSheet *sheet = [[[UIActionSheet alloc]
-                    initWithTitle:@"Repository Warning"
-                    buttons:[NSArray arrayWithObjects:@"Add Source", @"Cancel", nil]
+                    initWithTitle:@"Source Warning"
+                    buttons:[NSArray arrayWithObjects:@"Add Anyway", @"Cancel", nil]
                     defaultButtonIndex:0
                     delegate:self
                     context:@"warning"
@@ -4769,8 +4776,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
             [sheet popupAlertAnimated:YES];
         }
 
-        [href_ release];
-        href_ = nil;
+        [delegate_ setStatusBarShowsProgress:NO];
+        [delegate_ removeProgressHUD:hud_];
+
+        [hud_ autorelease];
+        hud_ = nil;
+
+        if (!defer) {
+            [href_ release];
+            href_ = nil;
+        }
 
         if (error_ != nil) {
             [error_ release];
@@ -4860,6 +4875,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
                 _assert(false);
         }
 
+        [href_ release];
+        href_ = nil;
+
         [sheet dismiss];
     }
 }
@@ -6466,8 +6484,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (void) _reloadData {
     UIView *block();
 
+    static bool loaded(false);
     UIProgressHUD *hud([self addProgressHUD]);
-    [hud setText:@"Reloading Data"];
+    [hud setText:(loaded ? @"Reloading Data" : @"Loading Data")];
+    loaded = true;
 
     [database_ yieldToSelector:@selector(reloadData) withObject:nil];
     _trace();
@@ -7323,6 +7343,10 @@ int main(int argc, char *argv[]) { _pooled
 
     if (NSDictionary *system = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"])
         Build_ = [system objectForKey:@"ProductBuildVersion"];
+    if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/MobileSafari.app/Info.plist"]) {
+        Product_ = [info objectForKey:@"SafariProductVersion"];
+        Safari_ = [info objectForKey:@"CFBundleVersion"];
+    }
 
     /*AddPreferences(@"/Applications/Preferences.app/Settings-iPhone.plist");
     AddPreferences(@"/Applications/Preferences.app/Settings-iPod.plist");*/
index 09680e35579ef80a986b727f2bc9df32b9fd37f2..cbb407f7efe2a355213b78f7f31c90d53eec53d0 100644 (file)
@@ -57,6 +57,9 @@
     WebScriptObject *function_;
 
     bool pushed_;
+
+    float width_;
+    bool popup_;
 }
 
 - (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button;
 - (UIWebDocumentView *) documentView;
 
 - (id) initWithBook:(RVBook *)book;
+- (id) initWithBook:(RVBook *)book forWidth:(float)width;
 
 - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame;
 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame;
 
++ (float) defaultWidth;
+
 @end
index fa41f2e9918cb30a70d831691eded66af42959a8..d2a97c840f7eb771ffb7e608aeaabfd751a16392 100644 (file)
@@ -73,6 +73,8 @@
 + (NSString *) webScriptNameForSelector:(SEL)selector {
     if (selector == @selector(getPackageById:))
         return @"getPackageById";
+    else if (selector == @selector(setAutoPopup:))
+        return @"setAutoPopup";
     else if (selector == @selector(setButtonImage:withStyle:toFunction:))
         return @"setButtonImage";
     else if (selector == @selector(setButtonTitle:withStyle:toFunction:))
     return value;
 }
 
+- (void) setAutoPopup:(BOOL)popup {
+    [indirect_ setAutoPopup:popup];
+}
+
 - (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
     [indirect_ setButtonImage:button withStyle:style toFunction:function];
 }
 #endif
 
 - (void) dealloc {
-    NSLog(@"deallocating WebView");
+#if ForSaurik
+    NSLog(@"[BrowserView dealloc]");
+#endif
 
     if (challenge_ != nil)
         [challenge_ release];
     /* XXX: this is where I cry myself to sleep */
 }
 
+- (bool) _allowJavaScriptPanel {
+    return true;
+}
+
 - (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
+    if ([self _allowJavaScriptPanel])
+        return;
+
     UIActionSheet *sheet = [[[UIActionSheet alloc]
         initWithTitle:nil
         buttons:[NSArray arrayWithObjects:@"OK", nil]
 }
 
 - (BOOL) webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
+    if (![self _allowJavaScriptPanel])
+        return NO;
+
     UIActionSheet *sheet = [[[UIActionSheet alloc]
         initWithTitle:nil
         buttons:[NSArray arrayWithObjects:@"OK", @"Cancel", nil]
     return [confirm boolValue];
 }
 
+- (void) setAutoPopup:(BOOL)popup {
+    popup_ = popup;
+}
+
 - (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
     if (button_ != nil)
         [button_ autorelease];
 }
 
 - (void) webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id<WebPolicyDecisionListener>)listener {
+#if ForSaurik
     NSLog(@"nwa:%@", name);
+#endif
 
     if (NSURL *url = [request URL]) {
         if (name == nil) unknown: {
 
             RVPage *page([delegate_ pageForURL:url hasTag:NULL]);
             if (page == nil) {
-                /* XXX: call createWebViewWithRequest instead */
+                /* XXX: call createWebViewWithRequest instead? */
 
                 [self setBackButtonTitle:title_];
 
 
     int store(_not(int));
     if (NSURL *itms = [url itmsURL:&store]) {
+#if ForSaurik
         NSLog(@"itms#%@#%u#%@", url, store, itms);
+#endif
+
         if (
             store == 1 && [capability containsObject:@"com.apple.MobileStore"] ||
             store == 2 && [capability containsObject:@"com.apple.AppStore"]
 }
 
 - (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request windowFeatures:(NSDictionary *)features {
+//- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request userGesture:(BOOL)gesture {
 #if ForSaurik
-    NSLog(@"cwv:%@ (%@)", request, title_);
+    NSLog(@"cwv:%@ (%@): %@", request, title_, features == nil ? @"{}" : [features description]);
+    //NSLog(@"cwv:%@ (%@): %@", request, title_, gesture ? @"Yes" : @"No");
 #endif
 
-    BrowserView *browser = [[[BrowserView alloc] initWithBook:book_] autorelease];
+    NSNumber *value([features objectForKey:@"width"]);
+    float width(value == nil ? [BrowserView defaultWidth] : [value floatValue]);
+
+    RVBook *book(!popup_ ? book_ : [[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]);
+
+    /* XXX: deal with cydia:// pages */
+    BrowserView *browser([[[BrowserView alloc] initWithBook:book forWidth:width] autorelease]);
+
+    if (features == nil && popup_) {
+        [book setDelegate:delegate_];
+        [browser setDelegate:delegate_];
+
+        [browser loadRequest:request];
 
-    if (request == nil) {
+        [book setPage:browser];
+        [book_ pushBook:book];
+    } else if (request == nil) {
         [self setBackButtonTitle:title_];
         [browser setDelegate:delegate_];
         [browser retain];
 
 - (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request {
     return [self webView:sender createWebViewWithRequest:request windowFeatures:nil];
+    //return [self webView:sender createWebViewWithRequest:request userGesture:YES];
 }
 
 - (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
 #endif
 }
 
-- (id) initWithBook:(RVBook *)book {
+- (id) initWithBook:(RVBook *)book forWidth:(float)width {
     if ((self = [super initWithBook:book]) != nil) {
         loading_ = false;
+        width_ = width;
+        popup_ = false;
 
         struct CGRect bounds = [self bounds];
 
             [webview_ setAutoresizes:YES];
 
             [webview_ setMinimumScale:0.25f forDocumentTypes:0x10];
+            [webview_ setMaximumScale:5.00f forDocumentTypes:0x10];
             [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10];
-            [webview_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
+            //[webview_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
 
             [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2];
 
-            [webview_ setMinimumScale:1.0f forDocumentTypes:0x8];
+            [webview_ setMinimumScale:1.00f forDocumentTypes:0x8];
             [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8];
             [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8];
 
             [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeUpdatesScroller];
 
             [webview_ setSmoothsFonts:YES];
-
+            [webview_ setAllowsImageSheet:YES];
             [webview _setUsesLoaderCache:YES];
-            [webview setGroupName:@"Cydia"];
+
+            [webview setGroupName:@"CydiaGroup"];
             [webview _setLayoutInterval:0];
         }
 
+        [webview_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
+
         [webview_ setDelegate:self];
         [webview_ setGestureDelegate:self];
         [scroller_ addSubview:webview_];
             [package installed]
         ];
 
+        if (Product_ != nil)
+            application = [NSString stringWithFormat:@"%@ Version/%@", application, Product_];
         if (Build_ != nil)
-            application = [NSString stringWithFormat:@"Mobile/%@ %@", Build_, application];
+            application = [NSString stringWithFormat:@"%@ Mobile/%@", application, Build_];
+        if (Safari_ != nil)
+            application = [NSString stringWithFormat:@"%@ Safari/%@", application, Safari_];
 
         /* XXX: lookup application directory? */
         /*if (NSDictionary *safari = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/MobileSafari.app/Info.plist"])
     } return self;
 }
 
+- (id) initWithBook:(RVBook *)book {
+    return [self initWithBook:book forWidth:[[self class] defaultWidth]];
+}
+
 - (void) didFinishGesturesInView:(UIView *)view forEvent:(id)event {
     [webview_ redrawScaledDocument];
 }
     pushed_ = pushed;
 }
 
++ (float) defaultWidth {
+    return 980;
+}
+
 @end
diff --git a/control b/control
index 9a3a92d809adf05cfba01a0bb4b4ebc027f4cbfe..92b20a26a2387d4464c5512c2093100410fd8bfd 100644 (file)
--- a/control
+++ b/control
@@ -4,7 +4,7 @@ Priority: required
 Section: Packaging
 Maintainer: Jay Freeman (saurik) <saurik@saurik.com>
 Architecture: iphoneos-arm
-Version: 1.0.2699-41
+Version: 1.0.2705-41
 Replaces: com.sosiphone.addcydia
 Depends: apt, darwintools, pcre, shell-cmds
 Conflicts: com.sosiphone.addcydia