1
1
2
2
#import " AppDelegate.h"
3
- #import " Notification.h"
4
-
5
- #import < Growl/Growl.h>
6
3
7
4
@interface AppDelegate (PrivateMethods)
8
5
- (void )loadUserScripts ;
@@ -17,6 +14,10 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
17
14
[webView setPolicyDelegate: self ];
18
15
[webView setUIDelegate: self ];
19
16
17
+ // webview -> notification center bridge
18
+ notificationProvider = [[NotificationProvider alloc ] init ];
19
+ [webView _setNotificationProvider: notificationProvider];
20
+
20
21
// user agent
21
22
NSString *version = [[NSBundle mainBundle ] objectForInfoDictionaryKey: @" CFBundleShortVersionString" ];
22
23
[webView setApplicationNameForUserAgent: [NSString stringWithFormat: @" nimbus/%@ " , version]];
@@ -27,9 +28,6 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
27
28
options: NSKeyValueObservingOptionNew
28
29
context: NULL ];
29
30
30
- // seems you have to kickstart the GrowlApplicationBridge :|
31
- [GrowlApplicationBridge setGrowlDelegate: nil ];
32
-
33
31
console = [[JSConsole alloc ] init ];
34
32
35
33
[self loadUserScripts ];
@@ -98,7 +96,6 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
98
96
#pragma mark FrameLoadDelegate
99
97
100
98
- (void )webView : (WebView *)sender didClearWindowObject : (WebScriptObject *)windowScriptObject forFrame : (WebFrame *)frame {
101
- [windowScriptObject setValue: self forKey: @" webkitNotifications" ];
102
99
[windowScriptObject setValue: console forKey: @" console" ];
103
100
104
101
// inject userscripts
@@ -132,48 +129,11 @@ - (void)webView:(WebView *)webView addMessageToConsole:(NSDictionary *)dictionar
132
129
NSLog (@" ERROR: %@ " , [dictionary objectForKey: @" message" ]);
133
130
}
134
131
135
- #pragma mark WebkitNotifications
136
-
137
- - (int )checkPermission {
138
- // always grant permission (0 = allow, 1 = unknown, 2 = denied)
139
- return 0 ;
140
- }
141
-
142
- - (WebScriptObject *)createNotificationWithIcon : (NSString *)icon title : (NSString *)title message : (NSString *)message {
143
- Notification *note = [[Notification alloc ] initWithTitle: title message: message];
144
- return (WebScriptObject *)[note autorelease ];
145
- }
146
-
147
- - (void )requestPermissionWithCallback : (WebScriptObject *)callback {
148
- if (callback && [callback isMemberOfClass: [WebScriptObject class ]]) {
149
- [callback callWebScriptMethod: @" call" withArguments: nil ];
150
- }
151
- }
152
-
153
- + (NSString *)webScriptNameForSelector : (SEL )sel {
154
- if (sel == @selector (checkPermission )) {
155
- return @" checkPermission" ;
156
- } else if (sel == @selector (createNotificationWithIcon:title:message: )) {
157
- return @" createNotification" ;
158
- } else if (sel == @selector (requestPermissionWithCallback: )) {
159
- return @" requestPermission" ;
160
- }
161
- return nil ;
162
- }
163
-
164
- + (BOOL )isSelectorExcludedFromWebScript : (SEL )sel {
165
- if (sel == @selector (checkPermission ) ||
166
- sel == @selector (createNotificationWithIcon:title:message: ) ||
167
- sel == @selector (requestPermissionWithCallback: )) {
168
- return NO ;
169
- }
170
- return YES ;
171
- }
172
-
173
132
#pragma mark -
174
133
175
134
- (void )dealloc {
176
135
[console release ];
136
+ [notificationProvider release ];
177
137
[userScripts release ];
178
138
[super dealloc ];
179
139
}
0 commit comments