@@ -59,8 +59,10 @@ - (void) _loadContent: (NSNotification*) notification;
59
59
- (void ) _loadContentForWindow : (NSNotification *) notification ;
60
60
61
61
- (NSDictionary *) _flashVarDictionary : (NSString *) flashvarString ;
62
+ - (NSString *) flashvarWithName : (NSString *) argName ;
62
63
- (BOOL ) _hasH264Version ;
63
64
- (BOOL ) _useH264Version ;
65
+ - (NSString *)launchedAppBundleIdentifier ;
64
66
@end
65
67
66
68
@@ -97,15 +99,18 @@ - (id) initWithArguments:(NSDictionary *)arguments
97
99
if (![[NSUserDefaults standardUserDefaults ] objectForKey: sPluginEnabled ]) {
98
100
// Default to enable the plugin
99
101
[[NSUserDefaults standardUserDefaults ] setBool: YES forKey: sPluginEnabled ];
100
- }
102
+ }
103
+
104
+ self.launchedAppBundleIdentifier = [self launchedAppBundleIdentifier ];
101
105
102
106
self.webView = [[[arguments objectForKey: WebPlugInContainerKey ] webFrame ] webView ];
103
107
104
108
self.container = [arguments objectForKey: WebPlugInContainingElementKey ];
105
109
106
110
[self _migrateWhitelist ];
107
111
108
- // Get URL and test against the whitelist
112
+
113
+ // Get URL
109
114
110
115
NSURL *base = [arguments objectForKey: WebPlugInBaseURLKey ];
111
116
self.baseURL = [base absoluteString ];
@@ -114,29 +119,72 @@ - (id) initWithArguments:(NSDictionary *)arguments
114
119
self.attributes = [arguments objectForKey: WebPlugInAttributesKey ];
115
120
NSString *srcAttribute = [self .attributes objectForKey: @" src" ];
116
121
122
+ if (srcAttribute) {
123
+ self.src = srcAttribute;
124
+ } else {
125
+ NSString *dataAttribute = [self .attributes objectForKey: @" data" ];
126
+ if (dataAttribute) self.src = dataAttribute;
127
+ }
128
+
129
+ NSLog (@" self.src: %@ " ,self.src );
130
+
131
+
132
+ // set tooltip
133
+
134
+ if (self.src ) [self setToolTip: self .src];
135
+
136
+
117
137
// Read in flashvars (needed to determine YouTube videos)
118
138
119
139
NSString * flashvars = [ self .attributes objectForKey: @" flashvars" ];
120
140
if ( flashvars != nil )
121
141
_flashVars = [ [ self _flashVarDictionary: flashvars ] retain ];
122
142
123
- #if LOGGING_ENABLED
143
+ #if 1
124
144
NSLog ( @" arguments = %@ " , arguments );
125
145
NSLog ( @" flashvars = %@ " , _flashVars );
126
146
#endif
147
+
148
+ // check whether it's from YouTube and get the video_id
149
+
150
+ _fromYouTube = [self .host isEqualToString: @" www.youtube.com" ]
151
+ || ( flashvars != nil && [flashvars rangeOfString: @" www.youtube.com" ].location != NSNotFound )
152
+ || (self.src != nil && [self .src rangeOfString: @" youtube.com" ].location != NSNotFound );
153
+
154
+ if (_fromYouTube) {
155
+ NSString *videoId = [ self flashvarWithName: @" video_id" ];
156
+ if (videoId != nil ) {
157
+ self.videoId = videoId;
158
+ } else {
159
+ // scrub the URL to determine the video_id
160
+
161
+ NSString *videoIdFromURL = nil ;
162
+ NSScanner *URLScanner = [[NSScanner alloc ] initWithString: self .src];
163
+ [URLScanner scanUpToString: @" youtube.com/v/" intoString: nil ];
164
+ if ([URLScanner scanString: @" youtube.com/v/" intoString: nil ]) {
165
+ // URL is in required format, next characters are the id
166
+
167
+ [URLScanner scanUpToString: @" &" intoString: &videoIdFromURL];
168
+ if (videoIdFromURL) self.videoId = videoIdFromURL;
169
+ }
170
+ [URLScanner release ];
171
+ }
172
+ }
173
+
174
+
175
+ // check whether plugin is disabled, load all content as normal if so
176
+
127
177
if ( ![ [ NSUserDefaults standardUserDefaults ] boolForKey: sPluginEnabled ] ) {
128
- // plugin is disabled, load all content as normal
129
178
_isLoadingFromWhitelist = YES ;
130
179
[self _convertTypesForContainer ];
131
180
return self;
132
181
}
133
-
134
- _fromYouTube = [self .host isEqualToString: @" www.youtube.com" ]
135
- || ( flashvars != nil && [flashvars rangeOfString: @" www.youtube.com" ].location != NSNotFound );
136
-
182
+
183
+
137
184
// Set up main menus
138
185
139
186
[ CTFMenubarMenuController sharedController ]; // trigger the menu items to be added
187
+
140
188
141
189
// Check for sIFR
142
190
@@ -165,6 +213,7 @@ - (id) initWithArguments:(NSDictionary *)arguments
165
213
166
214
BOOL loadFromWhiteList = [self _isHostWhitelisted ];
167
215
216
+
168
217
// Check the SWF src URL itself against the whitelist (allows embbeded videos from whitelisted sites to play, e.g. YouTube)
169
218
170
219
if ( !loadFromWhiteList )
@@ -178,6 +227,7 @@ - (id) initWithArguments:(NSDictionary *)arguments
178
227
}
179
228
}
180
229
}
230
+
181
231
182
232
// Handle if this is loading from whitelist
183
233
@@ -187,15 +237,6 @@ - (id) initWithArguments:(NSDictionary *)arguments
187
237
return self;
188
238
}
189
239
190
- // Set tooltip
191
-
192
- if (srcAttribute)
193
- [self setToolTip: srcAttribute];
194
- else {
195
- NSString *src = [self .attributes objectForKey: @" data" ];
196
- if (src)
197
- [self setToolTip: src];
198
- }
199
240
200
241
// send a notification so that all flash objects can be tracked
201
242
// we only want to track it if we don't auto-load it
@@ -408,11 +449,13 @@ - (NSMenu*) menuForEvent: (NSEvent*) event
408
449
[[self menu ] insertItemWithTitle: NSLocalizedString( @" Download H.264" , " Download H.264 menu item" )
409
450
action: @selector ( downloadH264: ) keyEquivalent: @" " atIndex: 2 ];
410
451
[[[self menu ] itemAtIndex: 1 ] setTarget: self ];
452
+ [[[self menu ] itemAtIndex: 2 ] setTarget: self ];
411
453
} else if (_fromYouTube) {
412
454
// has no H.264 version but is from YouTube; it's an embedded view!
413
455
414
456
[[self menu ] insertItemWithTitle: NSLocalizedString ( @" Load YouTube.com page for this video" , " Load YouTube page menu item" )
415
457
action: @selector (loadYouTubePage: ) keyEquivalent: @" " atIndex: 1 ];
458
+ [[[self menu ] itemAtIndex: 1 ] setTarget: self ];
416
459
}
417
460
}
418
461
}
@@ -686,10 +729,10 @@ - (NSString*) flashvarWithName: (NSString*) argName
686
729
return [ _flashVars objectForKey: argName ];
687
730
}
688
731
689
- - (NSString *) _videoId
732
+ /* - (NSString*) _videoId
690
733
{
691
734
return [ self flashvarWithName: @"video_id" ];
692
- }
735
+ }*/
693
736
694
737
- (NSString *) _videoHash
695
738
{
@@ -699,7 +742,7 @@ - (NSString*) _videoHash
699
742
- (BOOL ) _hasH264Version
700
743
{
701
744
if ( _fromYouTube )
702
- return [ self _videoId ] != nil && [ self _videoHash ] != nil ;
745
+ return self. videoId != nil && [ self _videoHash ] != nil ;
703
746
else
704
747
return NO ;
705
748
}
@@ -713,7 +756,7 @@ - (BOOL) _useH264Version
713
756
714
757
- (void ) _convertElementForMP4: (DOMElement *) element
715
758
{
716
- NSString * video_id = [ self _videoId ] ;
759
+ NSString * video_id = self. videoId ;
717
760
NSString * video_hash = [ self _videoHash ];
718
761
719
762
NSString * src = [ NSString stringWithFormat: @" http://www.youtube.com/get_video?fmt=18&video_id=%@ &t=%@ " ,
@@ -757,14 +800,8 @@ - (void) _convertToMP4ContainerAfterDelay
757
800
self.container = nil ;
758
801
}
759
802
760
- - (IBAction ) downloadH264: ( id )sender
803
+ - (NSString *)launchedAppBundleIdentifier
761
804
{
762
- NSString * video_id = [ self _videoId ];
763
- NSString * video_hash = [ self _videoHash ];
764
-
765
- NSString * src = [ NSString stringWithFormat: @" http://www.youtube.com/get_video?fmt=18&video_id=%@ &t=%@ " ,
766
- video_id, video_hash ];
767
-
768
805
NSString *appBundleIdentifier = [[NSBundle mainBundle ] bundleIdentifier ];
769
806
770
807
if ([appBundleIdentifier isEqualToString: @" com.apple.Safari" ]) {
@@ -796,8 +833,30 @@ - (IBAction)downloadH264:(id)sender
796
833
if (testBundleIdentifier != nil ) appBundleIdentifier = testBundleIdentifier;
797
834
}
798
835
836
+ return appBundleIdentifier;
837
+ }
838
+
839
+ - (IBAction )downloadH264: (id )sender
840
+ {
841
+ NSString * video_id = self.videoId ;
842
+ NSString * video_hash = [ self _videoHash ];
843
+
844
+ NSString * src = [ NSString stringWithFormat: @" http://www.youtube.com/get_video?fmt=18&video_id=%@ &t=%@ " ,
845
+ video_id, video_hash ];
846
+
799
847
[[NSWorkspace sharedWorkspace ] openURLs: [NSArray arrayWithObject: [NSURL URLWithString: src]]
800
- withAppBundleIdentifier: appBundleIdentifier
848
+ withAppBundleIdentifier: self .launchedAppBundleIdentifier
849
+ options: NSWorkspaceLaunchDefault
850
+ additionalEventParamDescriptor: [NSAppleEventDescriptor nullDescriptor ]
851
+ launchIdentifiers: nil ];
852
+ }
853
+
854
+ - (IBAction )loadYouTubePage: (id )sender
855
+ {
856
+ NSString * YouTubePageURL = [ NSString stringWithFormat: @" http://www.youtube.com/watch?v=%@ " ,self .videoId ];
857
+
858
+ [[NSWorkspace sharedWorkspace ] openURLs: [NSArray arrayWithObject: [NSURL URLWithString: YouTubePageURL]]
859
+ withAppBundleIdentifier: self .launchedAppBundleIdentifier
801
860
options: NSWorkspaceLaunchDefault
802
861
additionalEventParamDescriptor: [NSAppleEventDescriptor nullDescriptor ]
803
862
launchIdentifiers: nil ];
@@ -882,5 +941,8 @@ - (void) _revertToOriginalOpacityAttributes
882
941
@synthesize baseURL = _baseURL;
883
942
@synthesize attributes = _attributes;
884
943
@synthesize originalOpacityAttributes = _originalOpacityAttributes;
944
+ @synthesize src = _src;
945
+ @synthesize videoId = _videoId;
946
+ @synthesize launchedAppBundleIdentifier = _launchedAppBundleIdentifier;
885
947
886
948
@end
0 commit comments