forked from WebKit/WebKit-http
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a sample plugin to demonstrate the mute plugin API.
https://bugs.webkit.org/show_bug.cgi?id=139231 Reviewed by Anders Carlsson. * NetscapeMuteAPIPlugin/AudioPlayer.h: Added. * NetscapeMuteAPIPlugin/AudioPlayer.mm: Added. (-[AudioPlayer initWithURL:]): (-[AudioPlayer dealloc]): (-[AudioPlayer isReadyToPlay]): (-[AudioPlayer isPlaying]): (-[AudioPlayer setPlaying:]): (-[AudioPlayer isMuted]): (-[AudioPlayer setMuted:]): (-[AudioPlayer observeValueForKeyPath:ofObject:change:context:]): * NetscapeMuteAPIPlugin/English.lproj/InfoPlist.strings: Added. * NetscapeMuteAPIPlugin/Info.plist: Added. * NetscapeMuteAPIPlugin/MenuHandler.h: Added. * NetscapeMuteAPIPlugin/MenuHandler.m: Added. (-[MenuHandler _play:]): (-[MenuHandler _pause:]): (-[MenuHandler validateUserInterfaceItem:]): (-[MenuHandler initWithAudioPlayer:]): (-[MenuHandler dealloc]): (-[MenuHandler menu]): * NetscapeMuteAPIPlugin/NetscapeMuteAPIPlugin.xcodeproj/project.pbxproj: Added. * NetscapeMuteAPIPlugin/main.m: Added. (-[PluginObject initWithNPP:audioURL:]): (-[PluginObject dealloc]): (-[PluginObject menuHandler]): (-[PluginObject isPlayingAudio]): (-[PluginObject isMuted]): (-[PluginObject setMuted:]): (-[PluginObject readyStateDidChangeForAudioPlayer:]): (-[PluginObject mutedStateDidChangeForAudioPlayer:]): (-[PluginObject playStateDidChangeForAudioPlayer:]): (-[PluginObject _invalidateDisplayString]): (NP_Initialize): (NP_GetEntryPoints): (NP_Shutdown): (NPP_New): (NPP_Destroy): (NPP_SetWindow): (NPP_NewStream): (NPP_DestroyStream): (NPP_WriteReady): (NPP_Write): (NPP_StreamAsFile): (NPP_Print): (handleDraw): (invalidatePlugin): (handleMouseEvent): (NPP_HandleEvent): (NPP_URLNotify): (NPP_GetValue): (NPP_SetValue): * NetscapeMuteAPIPlugin/test.html: Added. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176785 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
adachan@apple.com
committed
Dec 4, 2014
1 parent
fb77811
commit ec7bc50
Showing
10 changed files
with
1,105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in | ||
consideration of your agreement to the following terms, and your use, installation, | ||
modification or redistribution of this Apple software constitutes acceptance of these | ||
terms. If you do not agree with these terms, please do not use, install, modify or | ||
redistribute this Apple software. | ||
In consideration of your agreement to abide by the following terms, and subject to these | ||
terms, Apple grants you a personal, non-exclusive license, under Apple’s copyrights in | ||
this original Apple software (the "Apple Software"), to use, reproduce, modify and | ||
redistribute the Apple Software, with or without modifications, in source and/or binary | ||
forms; provided that if you redistribute the Apple Software in its entirety and without | ||
modifications, you must retain this notice and the following text and disclaimers in all | ||
such redistributions of the Apple Software. Neither the name, trademarks, service marks | ||
or logos of Apple Inc. may be used to endorse or promote products derived from | ||
the Apple Software without specific prior written permission from Apple. Except as expressly | ||
stated in this notice, no other rights or licenses, express or implied, are granted by Apple | ||
herein, including but not limited to any patent rights that may be infringed by your | ||
derivative works or by other works in which the Apple Software may be incorporated. | ||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, | ||
EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, | ||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS | ||
USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. | ||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, | ||
REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND | ||
WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR | ||
OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#import <WebKit/npfunctions.h> | ||
|
||
@class AVPlayer; | ||
@class AVPlayerItem; | ||
@class AudioPlayer; | ||
|
||
@protocol AudioPlayerDelegate <NSObject> | ||
|
||
- (void)readyStateDidChangeForAudioPlayer:(AudioPlayer *)audioPlayer; | ||
- (void)mutedStateDidChangeForAudioPlayer:(AudioPlayer *)audioPlayer; | ||
- (void)playStateDidChangeForAudioPlayer:(AudioPlayer *)audioPlayer; | ||
|
||
@end | ||
|
||
@interface AudioPlayer : NSObject { | ||
BOOL _playing; | ||
AVPlayer *_audioPlayer; | ||
AVPlayerItem *_playerItem; | ||
id<AudioPlayerDelegate> _audioPlayerDelegate; | ||
} | ||
|
||
- (instancetype)initWithURL:(NSURL *)url; | ||
|
||
@property (nonatomic, weak) id<AudioPlayerDelegate> audioPlayerDelegate; | ||
@property (nonatomic, readonly, getter=isReadyToPlay) BOOL readyToPlay; | ||
@property (nonatomic, getter=isPlaying) BOOL playing; | ||
@property (nonatomic, getter=isMuted) BOOL muted; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in | ||
consideration of your agreement to the following terms, and your use, installation, | ||
modification or redistribution of this Apple software constitutes acceptance of these | ||
terms. If you do not agree with these terms, please do not use, install, modify or | ||
redistribute this Apple software. | ||
In consideration of your agreement to abide by the following terms, and subject to these | ||
terms, Apple grants you a personal, non-exclusive license, under Apple’s copyrights in | ||
this original Apple software (the "Apple Software"), to use, reproduce, modify and | ||
redistribute the Apple Software, with or without modifications, in source and/or binary | ||
forms; provided that if you redistribute the Apple Software in its entirety and without | ||
modifications, you must retain this notice and the following text and disclaimers in all | ||
such redistributions of the Apple Software. Neither the name, trademarks, service marks | ||
or logos of Apple Inc. may be used to endorse or promote products derived from | ||
the Apple Software without specific prior written permission from Apple. Except as expressly | ||
stated in this notice, no other rights or licenses, express or implied, are granted by Apple | ||
herein, including but not limited to any patent rights that may be infringed by your | ||
derivative works or by other works in which the Apple Software may be incorporated. | ||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, | ||
EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, | ||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS | ||
USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. | ||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, | ||
REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND | ||
WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR | ||
OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#import "AudioPlayer.h" | ||
|
||
#import <AVFoundation/AVFoundation.h> | ||
|
||
static void *itemStatusKVOContext = &itemStatusKVOContext; | ||
|
||
@implementation AudioPlayer | ||
|
||
@synthesize audioPlayerDelegate=_audioPlayerDelegate; | ||
|
||
- (instancetype)initWithURL:(NSURL *)url | ||
{ | ||
if (!url.absoluteString.length) | ||
return nil; | ||
|
||
if (!(self = [super init])) | ||
return nil; | ||
|
||
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil]; | ||
_playerItem = [[AVPlayerItem alloc] initWithAsset:avAsset]; | ||
[_playerItem addObserver:self forKeyPath:@"status" options:0 context:itemStatusKVOContext]; | ||
_audioPlayer = [[AVPlayer alloc] initWithPlayerItem:_playerItem]; | ||
|
||
return self; | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
[_playerItem removeObserver:self forKeyPath:@"status"]; | ||
[_audioPlayer release]; | ||
[_playerItem release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (BOOL)isReadyToPlay | ||
{ | ||
return _audioPlayer.currentItem.status == AVPlayerItemStatusReadyToPlay; | ||
} | ||
|
||
- (BOOL)isPlaying | ||
{ | ||
return _playing; | ||
} | ||
|
||
- (void)setPlaying:(BOOL)playing | ||
{ | ||
if (_playing == playing) | ||
return; | ||
|
||
if (playing && !self.isReadyToPlay) | ||
return; | ||
|
||
_playing = playing; | ||
|
||
if (_playing) | ||
[_audioPlayer play]; | ||
else | ||
[_audioPlayer pause]; | ||
|
||
[_audioPlayerDelegate playStateDidChangeForAudioPlayer:self]; | ||
} | ||
|
||
- (BOOL)isMuted | ||
{ | ||
return _audioPlayer.isMuted; | ||
} | ||
|
||
- (void)setMuted:(BOOL)muted | ||
{ | ||
if (self.isMuted == muted) | ||
return; | ||
|
||
_audioPlayer.muted = muted; | ||
[_audioPlayerDelegate mutedStateDidChangeForAudioPlayer:self]; | ||
} | ||
|
||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { | ||
|
||
if (context == &itemStatusKVOContext) { | ||
dispatch_async(dispatch_get_main_queue(), ^{ [_audioPlayerDelegate readyStateDidChangeForAudioPlayer:self]; }); | ||
return; | ||
} | ||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; | ||
} | ||
@end |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>English</string> | ||
<key>CFBundleExecutable</key> | ||
<string>NetscapeMuteAPIPlugin</string> | ||
<key>CFBundleIconFile</key> | ||
<string></string> | ||
<key>CFBundleIdentifier</key> | ||
<string>com.apple.netscapemuteapiplugin</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundlePackageType</key> | ||
<string>BRPL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1.0</string> | ||
<key>WebPluginDescription</key> | ||
<string>Simple Netscape plug-in that uses the Mute API</string> | ||
<key>WebPluginMIMETypes</key> | ||
<dict> | ||
<key>test/x-netscape-mute-api-plugin</key> | ||
<dict> | ||
<key>WebPluginTypeDescription</key> | ||
<string>Netscape Cocoa Plug-in</string> | ||
</dict> | ||
</dict> | ||
<key>WebPluginName</key> | ||
<string>Netscape Mute API Plug-in</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in | ||
consideration of your agreement to the following terms, and your use, installation, | ||
modification or redistribution of this Apple software constitutes acceptance of these | ||
terms. If you do not agree with these terms, please do not use, install, modify or | ||
redistribute this Apple software. | ||
In consideration of your agreement to abide by the following terms, and subject to these | ||
terms, Apple grants you a personal, non-exclusive license, under Apple’s copyrights in | ||
this original Apple software (the "Apple Software"), to use, reproduce, modify and | ||
redistribute the Apple Software, with or without modifications, in source and/or binary | ||
forms; provided that if you redistribute the Apple Software in its entirety and without | ||
modifications, you must retain this notice and the following text and disclaimers in all | ||
such redistributions of the Apple Software. Neither the name, trademarks, service marks | ||
or logos of Apple Inc. may be used to endorse or promote products derived from | ||
the Apple Software without specific prior written permission from Apple. Except as expressly | ||
stated in this notice, no other rights or licenses, express or implied, are granted by Apple | ||
herein, including but not limited to any patent rights that may be infringed by your | ||
derivative works or by other works in which the Apple Software may be incorporated. | ||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, | ||
EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, | ||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS | ||
USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. | ||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, | ||
REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND | ||
WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR | ||
OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
@class AudioPlayer; | ||
|
||
@interface MenuHandler : NSObject { | ||
NSMenu *_menu; | ||
AudioPlayer *_audioPlayer; | ||
} | ||
|
||
- (id)initWithAudioPlayer:(AudioPlayer *)audioPlayer; | ||
- (NSMenu *)menu; | ||
|
||
@end |
Oops, something went wrong.