8
8
9
9
#import " PBWebController.h"
10
10
#import " PBGitRepository.h"
11
+ #import " PBGitXProtocol.h"
12
+
11
13
#include < SystemConfiguration/SCNetworkReachability.h>
12
14
13
15
@implementation PBWebController
14
16
15
- @synthesize startFile;
17
+ @synthesize startFile, repository ;
16
18
17
19
- (void ) awakeFromNib
18
20
{
@@ -25,6 +27,7 @@ - (void) awakeFromNib
25
27
finishedLoading = NO ;
26
28
[view setUIDelegate: self ];
27
29
[view setFrameLoadDelegate: self ];
30
+ [view setResourceLoadDelegate: self ];
28
31
[[view mainFrame ] loadRequest: request];
29
32
}
30
33
@@ -50,6 +53,26 @@ - (void)webView:(WebView *)webView addMessageToConsole:(NSDictionary *)dictionar
50
53
NSLog (@" Error from webkit: %@ " , dictionary);
51
54
}
52
55
56
+ - (NSURLRequest *)webView : (WebView *)sender
57
+ resource : (id )identifier
58
+ willSendRequest : (NSURLRequest *)request
59
+ redirectResponse : (NSURLResponse *)redirectResponse
60
+ fromDataSource : (WebDataSource *)dataSource
61
+ {
62
+ if (!self.repository )
63
+ return request;
64
+
65
+ // TODO: Change this to canInitWithRequest
66
+ if ([[[request URL ] scheme ] isEqualToString: @" GitX" ]) {
67
+ NSMutableURLRequest *newRequest = [request mutableCopy ];
68
+ [newRequest setRepository: self .repository];
69
+ return newRequest;
70
+ }
71
+
72
+ return request;
73
+ }
74
+
75
+
53
76
+ (BOOL )isSelectorExcludedFromWebScript : (SEL )aSelector
54
77
{
55
78
return NO ;
@@ -81,7 +104,7 @@ - (BOOL) isReachable:(NSString *)hostname
81
104
82
105
#pragma mark Using async function from JS
83
106
84
- - (void ) runCommand : (WebScriptObject *)arguments inRepository : (PBGitRepository *)repository callBack : (WebScriptObject *)callBack
107
+ - (void ) runCommand : (WebScriptObject *)arguments inRepository : (PBGitRepository *)repo callBack : (WebScriptObject *)callBack
85
108
{
86
109
// The JS bridge does not handle JS Arrays, even though the docs say it does. So, we convert it ourselves.
87
110
int length = [[arguments valueForKey: @" length" ] intValue ];
@@ -90,7 +113,7 @@ - (void) runCommand:(WebScriptObject *)arguments inRepository:(PBGitRepository *
90
113
for (i = 0 ; i < length; i++)
91
114
[realArguments addObject: [arguments webScriptValueAtIndex: i]];
92
115
93
- NSFileHandle *handle = [repository handleInWorkDirForArguments: realArguments];
116
+ NSFileHandle *handle = [repo handleInWorkDirForArguments: realArguments];
94
117
[callbacks setObject: callBack forKey: handle];
95
118
[[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (JSRunCommandDone: ) name: NSFileHandleReadToEndOfFileCompletionNotification object: handle];
96
119
[handle readToEndOfFileInBackgroundAndNotify ];
0 commit comments