@@ -405,8 +405,15 @@ - (NSMenu*) menuForEvent: (NSEvent*) event
405
405
if ([self _hasH264Version ]) {
406
406
[[self menu ] insertItemWithTitle: NSLocalizedString( @" Load H.264" , " Load H.264 context menu item" )
407
407
action: @selector ( loadH264: ) keyEquivalent: @" " atIndex: 1 ];
408
+ [[self menu ] insertItemWithTitle: NSLocalizedString( @" Download H.264" , " Download H.264 menu item" )
409
+ action: @selector ( downloadH264: ) keyEquivalent: @" " atIndex: 2 ];
408
410
[[[self menu ] itemAtIndex: 1 ] setTarget: self ];
409
- }
411
+ } else if (_fromYouTube) {
412
+ // has no H.264 version but is from YouTube; it's an embedded view!
413
+
414
+ [[self menu ] insertItemWithTitle: NSLocalizedString ( @" Load YouTube.com page for this video" , " Load YouTube page menu item" )
415
+ action: @selector (loadYouTubePage: ) keyEquivalent: @" " atIndex: 1 ];
416
+ }
410
417
}
411
418
}
412
419
@@ -750,6 +757,52 @@ - (void) _convertToMP4ContainerAfterDelay
750
757
self.container = nil ;
751
758
}
752
759
760
+ - (IBAction )downloadH264: (id )sender
761
+ {
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
+ NSString *appBundleIdentifier = [[NSBundle mainBundle ] bundleIdentifier ];
769
+
770
+ if ([appBundleIdentifier isEqualToString: @" com.apple.Safari" ]) {
771
+ // additional tests need to be performed, because this can indicate
772
+ // either WebKit *or* Safari; according to @bdash on Twitter, we need
773
+ // to check whether the framework bundle that we're using is
774
+ // contained within WebKit.app or not
775
+
776
+ // however, the user may have renamed the bundle, so we have to get
777
+ // its path, then get its bundle identifier
778
+
779
+ NSString *privateFrameworksPath = [[NSBundle bundleForClass: [WebView class ]] privateFrameworksPath ];
780
+
781
+ NSScanner *pathScanner = [[NSScanner alloc ] initWithString: privateFrameworksPath];
782
+ NSString *pathString = nil ;
783
+ [pathScanner scanUpToString: @" .app" intoString: &pathString];
784
+ NSBundle *testBundle = [[NSBundle alloc ] initWithPath: [pathString stringByAppendingPathExtension: @" app" ]];
785
+ NSString *testBundleIdentifier = [testBundle bundleIdentifier ];
786
+ [testBundle release ];
787
+ [pathScanner release ];
788
+
789
+
790
+ // Safari uses the framework inside /System/Library/Frameworks/ , and
791
+ // since there's no ".app" extension in that path, the resulting
792
+ // bundle identifier will be nil; however, if it's WebKit, there *will*
793
+ // be a ".app" in the frameworks path, and we'll get a valid bundle
794
+ // identifier to launch with
795
+
796
+ if (testBundleIdentifier != nil ) appBundleIdentifier = testBundleIdentifier;
797
+ }
798
+
799
+ [[NSWorkspace sharedWorkspace ] openURLs: [NSArray arrayWithObject: [NSURL URLWithString: src]]
800
+ withAppBundleIdentifier: appBundleIdentifier
801
+ options: NSWorkspaceLaunchDefault
802
+ additionalEventParamDescriptor: [NSAppleEventDescriptor nullDescriptor ]
803
+ launchIdentifiers: nil ];
804
+ }
805
+
753
806
754
807
#pragma mark -
755
808
#pragma mark DOM Conversion
0 commit comments