summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CyteKit/WebViewTableViewCell.h60
-rw-r--r--CyteKit/WebViewTableViewCell.mm100
-rw-r--r--MobileCydia.mm113
3 files changed, 273 insertions, 0 deletions
diff --git a/CyteKit/WebViewTableViewCell.h b/CyteKit/WebViewTableViewCell.h
new file mode 100644
index 0000000..c328e33
--- /dev/null
+++ b/CyteKit/WebViewTableViewCell.h
@@ -0,0 +1,60 @@
+/* Cydia - iPhone UIKit Front-End for Debian APT
+ * Copyright (C) 2008-2011 Jay Freeman (saurik)
+*/
+
+/* Modified BSD License {{{ */
+/*
+ * Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation
+ * and/or other materials provided with the
+ * distribution.
+ * 3. The name of the author may not be used to endorse
+ * or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/* }}} */
+
+#ifndef CyteKit_WebViewTableViewCell_H
+#define CyteKit_WebViewTableViewCell_H
+
+#include <UIKit/UIKit.h>
+
+#include "Menes/ObjectHandle.h"
+#include "CyteKit/WebView.h"
+
+@interface CyteWebViewTableViewCell : UITableViewCell {
+ // XXX: I'm not really the delegate here: fix this!
+ _H<CyteWebView, 1> webview_;
+}
+
++ (CyteWebViewTableViewCell *) cellWithRequest:(NSURLRequest *)request;
+- (id) initWithRequest:(NSURLRequest *)request;
+
+- (void) setDelegate:(id)delegate;
+
+@end
+
+#endif//CyteKit_WebViewTableViewCell_H
diff --git a/CyteKit/WebViewTableViewCell.mm b/CyteKit/WebViewTableViewCell.mm
new file mode 100644
index 0000000..54fecd5
--- /dev/null
+++ b/CyteKit/WebViewTableViewCell.mm
@@ -0,0 +1,100 @@
+/* Cydia - iPhone UIKit Front-End for Debian APT
+ * Copyright (C) 2008-2011 Jay Freeman (saurik)
+*/
+
+/* Modified BSD License {{{ */
+/*
+ * Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation
+ * and/or other materials provided with the
+ * distribution.
+ * 3. The name of the author may not be used to endorse
+ * or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/* }}} */
+
+#include "CyteKit/WebViewTableViewCell.h"
+#include "iPhonePrivate.h"
+
+@interface WebView (Apple)
+- (void) _setLayoutInterval:(float)interval;
+- (void) _setAllowsMessaging:(BOOL)allows;
+@end
+
+@implementation CyteWebViewTableViewCell
+
++ (CyteWebViewTableViewCell *) cellWithRequest:(NSURLRequest *)request {
+ CyteWebViewTableViewCell *cell([[[self alloc] initWithRequest:request] autorelease]);
+ return cell;
+}
+
+- (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message {
+ NSLog(@"addMessageToConsole:%@", message);
+}
+
+- (id) initWithRequest:request {
+ if ((self = [super init]) != nil) {
+ UIView *view(self);
+
+ webview_ = [[[CyteWebView alloc] initWithFrame:[view bounds]] autorelease];
+ [webview_ setDelegate:self];
+ [view addSubview:webview_];
+
+ NSLog(@"%@ %p", (id) webview_, (id) webview_);
+
+ [webview_ setScalesPageToFit:YES];
+
+ UIWebDocumentView *document([webview_ _documentView]);
+ WebView *webview([document webView]);
+ [webview setShouldUpdateWhileOffscreen:NO];
+
+ if ([document respondsToSelector:@selector(setAllowsMessaging:)])
+ [document setAllowsMessaging:YES];
+ if ([webview respondsToSelector:@selector(_setAllowsMessaging:)])
+ [webview _setAllowsMessaging:YES];
+
+ UIScrollView *scroller([webview_ scrollView]);
+ [scroller setScrollingEnabled:NO];
+ [scroller setFixedBackgroundPattern:YES];
+ [scroller setBackgroundColor:[UIColor clearColor]];
+
+ WebPreferences *preferences([webview preferences]);
+ [preferences setCacheModel:WebCacheModelDocumentBrowser];
+ [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
+ [preferences setOfflineWebApplicationCacheEnabled:YES];
+
+ [webview_ loadRequest:request];
+
+ [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+ } return self;
+}
+
+- (void) setDelegate:(id)delegate {
+ [webview_ setDelegate:delegate];
+}
+
+@end
diff --git a/MobileCydia.mm b/MobileCydia.mm
index 272d73a..e6e6949 100644
--- a/MobileCydia.mm
+++ b/MobileCydia.mm
@@ -126,10 +126,12 @@ extern "C" {
#include <CydiaSubstrate/CydiaSubstrate.h>
#include "Menes/Menes.h"
+#include "CyteKit/IndirectDelegate.h"
#include "CyteKit/PerlCompatibleRegEx.hpp"
#include "CyteKit/TableViewCell.h"
#include "CyteKit/WebScriptObject-Cyte.h"
#include "CyteKit/WebViewController.h"
+#include "CyteKit/WebViewTableViewCell.h"
#include "CyteKit/stringWithUTF8Bytes.h"
#include "Cydia/MIMEAddress.h"
@@ -247,6 +249,8 @@ union SplitHash {
};
// }}}
+static bool ShowPromoted_;
+
static NSString *Colon_;
NSString *Elision_;
static NSString *Error_;
@@ -4117,6 +4121,8 @@ static _H<NSMutableSet> Diversions_;
return @"setMetadataValue";
else if (selector == @selector(setSessionValue::))
return @"setSessionValue";
+ else if (selector == @selector(setShowPromoted:))
+ return @"setShowPromoted";
else if (selector == @selector(substitutePackageNames:))
return @"substitutePackageNames";
else if (selector == @selector(scrollToBottom:))
@@ -4232,6 +4238,15 @@ static _H<NSMutableSet> Diversions_;
return [Values_ allKeys];
} }
+- (void) _setShowPromoted:(NSNumber *)value {
+ [Metadata_ setObject:value forKey:@"ShowPromoted"];
+ Changed_ = true;
+}
+
+- (void) setShowPromoted:(NSNumber *)value {
+ [self performSelectorOnMainThread:@selector(_setShowPromoted:) withObject:value waitUntilDone:NO];
+}
+
- (id) getMetadataValue:(NSString *)key {
@synchronized (Values_) {
return [Values_ objectForKey:key];
@@ -7198,7 +7213,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
/* Section Controller {{{ */
@interface SectionController : FilteredPackageListController {
+ _H<IndirectDelegate, 1> indirect_;
+ _H<CydiaObject> cydia_;
_H<NSString> section_;
+ std::vector< _H<CyteWebViewTableViewCell, 1> > promoted_;
}
- (id) initWithDatabase:(Database *)database section:(NSString *)section;
@@ -7225,10 +7243,102 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
title = UCLocalize("NO_SECTION");
if ((self = [super initWithDatabase:database title:title filter:@selector(isVisibleInSection:) with:name]) != nil) {
+ indirect_ = [[[IndirectDelegate alloc] initWithDelegate:self] autorelease];
+ cydia_ = [[[CydiaObject alloc] initWithDelegate:indirect_] autorelease];
section_ = name;
} return self;
}
+- (NSInteger) numberOfSectionsInTableView:(UITableView *)list {
+ return [super numberOfSectionsInTableView:list] + 1;
+}
+
+- (NSString *) tableView:(UITableView *)list titleForHeaderInSection:(NSInteger)section {
+ return section == 0 ? nil : [super tableView:list titleForHeaderInSection:(section - 1)];
+}
+
+- (NSInteger) tableView:(UITableView *)list numberOfRowsInSection:(NSInteger)section {
+ return section == 0 ? promoted_.size() : [super tableView:list numberOfRowsInSection:(section - 1)];
+}
+
++ (NSIndexPath *) adjustedIndexPath:(NSIndexPath *)path {
+ return [NSIndexPath indexPathForRow:[path row] inSection:([path section] - 1)];
+}
+
+- (UITableViewCell *) tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {
+ if ([path section] != 0)
+ return [super tableView:table cellForRowAtIndexPath:[SectionController adjustedIndexPath:path]];
+
+ return promoted_[[path row]];
+}
+
+- (void) tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {
+ if ([path section] != 0)
+ return [super tableView:table didSelectRowAtIndexPath:[SectionController adjustedIndexPath:path]];
+}
+
+- (NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
+ NSInteger section([super tableView:tableView sectionForSectionIndexTitle:title atIndex:index]);
+ return section == 0 ? 0 : section + 1;
+}
+
+- (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
+ NSURL *url([request URL]);
+ if (url == nil)
+ return;
+
+ if ([frame isEqualToString:@"_open"])
+ [delegate_ openURL:url];
+ else {
+ CyteViewController *controller([delegate_ pageForURL:url forExternal:NO] ?: [[[CydiaWebViewController alloc] initWithRequest:request] autorelease]);
+ [controller setDelegate:delegate_];
+ [[self navigationController] pushViewController:controller animated:YES];
+ }
+
+ [listener ignore];
+}
+
+- (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
+ return [CydiaWebViewController requestWithHeaders:request];
+}
+
+- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
+ [CydiaWebViewController didClearWindowObject:window forFrame:frame withCydia:cydia_];
+}
+
+- (void) loadView {
+ [super loadView];
+
+ // XXX: this code is horrible. I mean, wtf Jay?
+ if (ShowPromoted_ && [[Metadata_ objectForKey:@"ShowPromoted"] boolValue]) {
+ promoted_.resize(1);
+
+ for (unsigned i(0); i != promoted_.size(); ++i) {
+ CyteWebViewTableViewCell *promoted([CyteWebViewTableViewCell cellWithRequest:[NSURLRequest
+ requestWithURL:[Diversion divertURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/sectionhead/%u/%@",
+ UI_, i, section_ == nil ? @"" : [section_ stringByAddingPercentEscapesIncludingReserved]]
+ ]]
+
+ cachePolicy:NSURLRequestUseProtocolCachePolicy
+ timeoutInterval:120
+ ]]);
+
+ [promoted setDelegate:self];
+ promoted_[i] = promoted;
+ }
+ }
+}
+
+- (void) setDelegate:(id)delegate {
+ [super setDelegate:delegate];
+ [cydia_ setDelegate:delegate];
+}
+
+- (void) releaseSubviews {
+ promoted_.clear();
+ [super releaseSubviews];
+}
+
@end
/* }}} */
/* Sections Controller {{{ */
@@ -10523,6 +10633,9 @@ int main(int argc, char *argv[]) {
//UIKeyboardDisableAutomaticAppearance();
/* }}} */
+ BOOL (*GSSystemHasCapability)(CFStringRef) = reinterpret_cast<BOOL (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemHasCapability"));
+ ShowPromoted_ = GSSystemHasCapability != NULL && GSSystemHasCapability(CFSTR("armv7"));
+
Colon_ = UCLocalize("COLON_DELIMITED");
Elision_ = UCLocalize("ELISION");
Error_ = UCLocalize("ERROR");