Reviewed by Antti Koivisto and Kevin Decker.
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Dec 2007 18:44:05 +0000 (18:44 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Dec 2007 18:44:05 +0000 (18:44 +0000)
        - fix <rdar://problem/5601586> QtKit should be dynamically loaded upon need, not linked at startup

        Also did a lot of small tweaks to MediaPlayerPrivateQTKit.

        * WebCore.xcodeproj/project.pbxproj: Don't link to QTKit.

        * platform/graphics/mac/MediaPlayerPrivateQTKit.h: Omit unneeded includes and declarations.
        Made a lot more functions const. Made a few more members private and a couple inline.
        * platform/graphics/mac/MediaPlayerPrivateQTKit.mm: Added soft linking machinery for all the
        things we currently use in QTKit. It's a little more awkward for classes and other data objects
        than it is for functions, but still relatively straightforward, with no changes needed to the
        client code. Added using namespace directives. Made a cuePointTimerInterval constant and put
        it at the top of the file. Use 0 consistently instead of sometimes 0 and sometimes 0.0f.
        (WebCore::MediaPlayerPrivate::MediaPlayerPrivate): Removed unneeded initialization of RetainPtr
        members to nil.
        (WebCore::MediaPlayerPrivate::createQTMovie): Use adoptNS instead of autorelease.
        (WebCore::MediaPlayerPrivate::createQTMovieView): Ditto. Also use -[NSColor clearColor].
        (WebCore::MediaPlayerPrivate::createQTTime): Remove an unneeded type cast that had no effect.
        Changed to use long instead of int because that's the type for a QTTime time scale anyway.
        (WebCore::MediaPlayerPrivate::duration): Use a static_cast instead of a C-style cast.
        (WebCore::MediaPlayerPrivate::currentTime): Ditto. Also merged into a single expression.
        (WebCore::MediaPlayerPrivate::cuePointTimerFired): Added code to make a copy of the cue
        points set to avoid a potential problem with a set being modified as we iterate it.
        (WebCore::MediaPlayerPrivate::bytesLoaded): Removed unneeded null check of m_qtMovie.
        (WebCore::MediaPlayerPrivate::updateStates): Instead of comments explaining the numeric
        values, used the constants from the headers directly.
        (WebCore::MediaPlayerPrivate::getSupportedTypes): Instead of (QTMovieFileTypeOptions)0,
        pass the named constant with value 0, QTIncludeCommonTypes. Skipped the intermediate type
        of NSString to remove one cast. Replaced C-style cast with reinterpret_cast (arguably
        no better). Used RetainPtr instead of explicit CFRelease calls.

        * platform/mac/SoftLinking.h: Added macros to do soft linking for classes and for pointers.
        It's not quite as automatic as the soft linking we can do for functions, since these define
        functions to get the values, so you need to define macros to make what look like variable
        accesses turn into function calls. See MediaPlayerPrivateQTKit for the details.

        * html/HTMLMediaElement.h:
        * html/TimeRanges.h:
        * html/VoidCallback.h:
        * platform/graphics/MediaPlayer.h:
        Use angle brackets for wtf includes. Omit unneeded includes.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28521 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/html/HTMLElementFactory.cpp
WebCore/html/HTMLMediaElement.cpp
WebCore/html/HTMLMediaElement.h
WebCore/html/TimeRanges.h
WebCore/html/VoidCallback.h
WebCore/platform/graphics/MediaPlayer.h
WebCore/platform/graphics/mac/MediaPlayerPrivateQTKit.h
WebCore/platform/graphics/mac/MediaPlayerPrivateQTKit.mm
WebCore/platform/mac/SoftLinking.h

index 7965326405ea1aec24dea7d1ef516ab1b13c9b72..24cd1ce922955049a252db8ad08e04d7fb086283 100644 (file)
@@ -1,3 +1,49 @@
+2007-12-07  Darin Adler  <darin@apple.com>
+
+        Reviewed by Antti Koivisto and Kevin Decker.
+
+        - fix <rdar://problem/5601586> QtKit should be dynamically loaded upon need, not linked at startup
+
+        Also did a lot of small tweaks to MediaPlayerPrivateQTKit.
+
+        * WebCore.xcodeproj/project.pbxproj: Don't link to QTKit.
+
+        * platform/graphics/mac/MediaPlayerPrivateQTKit.h: Omit unneeded includes and declarations.
+        Made a lot more functions const. Made a few more members private and a couple inline.
+        * platform/graphics/mac/MediaPlayerPrivateQTKit.mm: Added soft linking machinery for all the
+        things we currently use in QTKit. It's a little more awkward for classes and other data objects
+        than it is for functions, but still relatively straightforward, with no changes needed to the
+        client code. Added using namespace directives. Made a cuePointTimerInterval constant and put
+        it at the top of the file. Use 0 consistently instead of sometimes 0 and sometimes 0.0f.
+        (WebCore::MediaPlayerPrivate::MediaPlayerPrivate): Removed unneeded initialization of RetainPtr
+        members to nil.
+        (WebCore::MediaPlayerPrivate::createQTMovie): Use adoptNS instead of autorelease.
+        (WebCore::MediaPlayerPrivate::createQTMovieView): Ditto. Also use -[NSColor clearColor].
+        (WebCore::MediaPlayerPrivate::createQTTime): Remove an unneeded type cast that had no effect.
+        Changed to use long instead of int because that's the type for a QTTime time scale anyway.
+        (WebCore::MediaPlayerPrivate::duration): Use a static_cast instead of a C-style cast.
+        (WebCore::MediaPlayerPrivate::currentTime): Ditto. Also merged into a single expression.
+        (WebCore::MediaPlayerPrivate::cuePointTimerFired): Added code to make a copy of the cue
+        points set to avoid a potential problem with a set being modified as we iterate it.
+        (WebCore::MediaPlayerPrivate::bytesLoaded): Removed unneeded null check of m_qtMovie.
+        (WebCore::MediaPlayerPrivate::updateStates): Instead of comments explaining the numeric
+        values, used the constants from the headers directly.
+        (WebCore::MediaPlayerPrivate::getSupportedTypes): Instead of (QTMovieFileTypeOptions)0,
+        pass the named constant with value 0, QTIncludeCommonTypes. Skipped the intermediate type
+        of NSString to remove one cast. Replaced C-style cast with reinterpret_cast (arguably
+        no better). Used RetainPtr instead of explicit CFRelease calls.
+
+        * platform/mac/SoftLinking.h: Added macros to do soft linking for classes and for pointers.
+        It's not quite as automatic as the soft linking we can do for functions, since these define
+        functions to get the values, so you need to define macros to make what look like variable
+        accesses turn into function calls. See MediaPlayerPrivateQTKit for the details.
+
+        * html/HTMLMediaElement.h:
+        * html/TimeRanges.h:
+        * html/VoidCallback.h:
+        * platform/graphics/MediaPlayer.h:
+        Use angle brackets for wtf includes. Omit unneeded includes.
+
 2007-12-07  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Darin Adler.
index e39ead1dcbf1468f24b37a9436a5e55c98c38ad4..ac4afd0e952b084e8460e9101ab38bcd1e8e5cb6 100644 (file)
                E446143E0CD68A2300FADA75 /* JSHTMLAudioElementConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = E4B41E080CBF8F2100AF2ECE /* JSHTMLAudioElementConstructor.h */; };
                E44614510CD68A3500FADA75 /* RenderVideo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B41E330CBFB60900AF2ECE /* RenderVideo.cpp */; };
                E44614520CD68A3500FADA75 /* RenderVideo.h in Headers */ = {isa = PBXBuildFile; fileRef = E4B41E340CBFB60900AF2ECE /* RenderVideo.h */; };
-               E4B4232F0CBFB66400AF2ECE /* QTKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4B4232E0CBFB66400AF2ECE /* QTKit.framework */; };
                E4C279580CF9741900E97B98 /* RenderMedia.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C279560CF9741900E97B98 /* RenderMedia.cpp */; };
                E4C279590CF9741900E97B98 /* RenderMedia.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C279570CF9741900E97B98 /* RenderMedia.h */; };
                ED048ABC0833F132006E1E67 /* textAreaResizeCorner.tiff in Resources */ = {isa = PBXBuildFile; fileRef = ED048ABB0833F132006E1E67 /* textAreaResizeCorner.tiff */; };
                E4B41E110CBF90EF00AF2ECE /* MediaPlayerPrivateQTKit.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MediaPlayerPrivateQTKit.mm; sourceTree = "<group>"; };
                E4B41E330CBFB60900AF2ECE /* RenderVideo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderVideo.cpp; sourceTree = "<group>"; };
                E4B41E340CBFB60900AF2ECE /* RenderVideo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderVideo.h; sourceTree = "<group>"; };
-               E4B4232E0CBFB66400AF2ECE /* QTKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QTKit.framework; path = /System/Library/Frameworks/QTKit.framework; sourceTree = "<absolute>"; };
                E4B423710CBFB6E000AF2ECE /* JSHTMLSourceElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLSourceElement.cpp; sourceTree = "<group>"; };
                E4B423720CBFB6E000AF2ECE /* JSHTMLSourceElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLSourceElement.h; sourceTree = "<group>"; };
                E4B4237D0CBFB73C00AF2ECE /* JSHTMLAudioElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLAudioElement.cpp; sourceTree = "<group>"; };
                                93F19B1408245E59001E9ABC /* Carbon.framework in Frameworks */,
                                93F19B1508245E59001E9ABC /* Cocoa.framework in Frameworks */,
                                93F19B1608245E59001E9ABC /* JavaScriptCore.framework in Frameworks */,
-                               E4B4232F0CBFB66400AF2ECE /* QTKit.framework in Frameworks */,
                                A88AD52F09524B92001DD196 /* QuartzCore.framework in Frameworks */,
                                93F19B1708245E59001E9ABC /* libicucore.dylib in Frameworks */,
                                1CFAE3230A6D6A3F0032593D /* libobjc.dylib in Frameworks */,
                                1CFAE3220A6D6A3F0032593D /* libobjc.dylib */,
                                9372560F0A61564200B053B9 /* libsqlite3.dylib */,
                                DD763BB10992C2C900740B8E /* libxml2.dylib */,
-                               E4B4232E0CBFB66400AF2ECE /* QTKit.framework */,
                                A85D7A2F0879EBA9006A9172 /* QuartzCore.framework */,
                        );
                        name = Frameworks;
index 0c3cc55bfc0454a2b119a4cdb9579e64b781f06e..9efdc68951f9e3d025fd2c00f04950a5bc1ff6a9 100644 (file)
 #include "HTMLAppletElement.h"
 #include "HTMLAreaElement.h"
 #include "HTMLAudioElement.h"
-#include "HTMLBaseFontElement.h"
+#include "HTMLBRElement.h"
 #include "HTMLBaseElement.h"
+#include "HTMLBaseFontElement.h"
 #include "HTMLBlockquoteElement.h"
 #include "HTMLBodyElement.h"
-#include "HTMLBRElement.h"
 #include "HTMLButtonElement.h"
 #include "HTMLCanvasElement.h"
-#include "HTMLDivElement.h"
 #include "HTMLDListElement.h"
-#include "HTMLDocument.h"
 #include "HTMLDirectoryElement.h"
+#include "HTMLDivElement.h"
+#include "HTMLDocument.h"
 #include "HTMLEmbedElement.h"
-#include "HTMLFontElement.h"
-#include "HTMLFrameSetElement.h"
 #include "HTMLFieldSetElement.h"
+#include "HTMLFontElement.h"
 #include "HTMLFormElement.h"
+#include "HTMLFrameElement.h"
+#include "HTMLFrameSetElement.h"
+#include "HTMLHRElement.h"
 #include "HTMLHeadElement.h"
 #include "HTMLHeadingElement.h"
-#include "HTMLHRElement.h"
 #include "HTMLHtmlElement.h"
-#include "HTMLFrameElement.h"
 #include "HTMLIFrameElement.h"
 #include "HTMLImageElement.h"
 #include "HTMLIsIndexElement.h"
 #include "HTMLKeygenElement.h"
+#include "HTMLLIElement.h"
 #include "HTMLLabelElement.h"
 #include "HTMLLegendElement.h"
-#include "HTMLLIElement.h"
 #include "HTMLLinkElement.h"
 #include "HTMLMapElement.h"
 #include "HTMLMarqueeElement.h"
 #include "HTMLMetaElement.h"
 #include "HTMLModElement.h"
 #include "HTMLNames.h"
-#include "HTMLObjectElement.h"
 #include "HTMLOListElement.h"
+#include "HTMLObjectElement.h"
 #include "HTMLOptGroupElement.h"
 #include "HTMLOptionElement.h"
 #include "HTMLParagraphElement.h"
 #include "HTMLParamElement.h"
 #include "HTMLPreElement.h"
+#include "HTMLQuoteElement.h"
 #include "HTMLScriptElement.h"
 #include "HTMLSelectElement.h"
 #include "HTMLSourceElement.h"
 #include "HTMLStyleElement.h"
-#include "HTMLTextAreaElement.h"
-#include "HTMLTableElement.h"
 #include "HTMLTableCaptionElement.h"
 #include "HTMLTableCellElement.h"
 #include "HTMLTableColElement.h"
+#include "HTMLTableElement.h"
 #include "HTMLTableRowElement.h"
 #include "HTMLTableSectionElement.h"
+#include "HTMLTextAreaElement.h"
 #include "HTMLTitleElement.h"
-#include "HTMLVideoElement.h"
 #include "HTMLUListElement.h"
-#include "HTMLQuoteElement.h"
+#include "HTMLVideoElement.h"
 
 namespace WebCore {
 
index 39d5a49d153f59eb15b052645ecdf818ff28a5cc..a76c6fd1d9cdf75435e1bd4ad6abb8d0f0c357d1 100644 (file)
@@ -47,7 +47,6 @@
 #include "RenderVideo.h"
 #include "SystemTime.h"
 #include "TimeRanges.h"
-#include "VoidCallback.h"
 #include <wtf/MathExtras.h>
 
 using namespace std;
index 58efb616ede7597b46f3908a168a81aafae6e347..271fb1a85839bfb6613aa68b7e6e25a5e03ed279 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "HTMLElement.h"
 #include "MediaPlayer.h"
 #include "Timer.h"
-#include "StringHash.h"
 #include "VoidCallback.h"
-#include "wtf/HashMap.h"
-#include "wtf/HashSet.h"
-#include "wtf/RefPtr.h"
-#include "wtf/Vector.h"
 
 namespace WebCore {
 
index f0c2ad0e275930c04183f8ff2fafbaab231fb4e0..16b0c25b635983c71ea99bc9e38c7b8958a831b3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,7 +28,7 @@
 
 #include "ExceptionCode.h"
 #include <wtf/RefCounted.h>
-#include "wtf/Vector.h"
+#include <wtf/Vector.h>
 
 namespace WebCore {
 
@@ -38,8 +38,8 @@ public:
     TimeRanges(float start, float end);
     
     unsigned length() const { return m_ranges.size(); }
-    float start(unsigned index, ExceptionCode& ec) const;
-    float end(unsigned index, ExceptionCode& ec) const;
+    float start(unsigned index, ExceptionCode&) const;
+    float end(unsigned index, ExceptionCode&) const;
     
     void add(float start, float end);
     
index 8c09447897ee48bc6352df82587eac1da4e088d4..478e2fc1226cbc940736b83cc2fcf6e7710a03d4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #ifndef VoidCallback_h
 #define VoidCallback_h
 
-#include <kjs/protect.h>
 #include <wtf/RefCounted.h>
-#include "wtf/PassRefPtr.h"
 
 namespace WebCore {
 
-class Frame;
-    
 class VoidCallback : public RefCounted<VoidCallback> {
 public:
     VoidCallback() { }
index 2609556baa364b4131b4ee6aeea1608fdeb814f5..7ea09788035b518febda6c5146a89ace3497d510 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -30,8 +30,8 @@
 
 #include "IntRect.h"
 #include "StringHash.h"
-#include "wtf/HashSet.h"
-#include "wtf/Noncopyable.h"
+#include <wtf/HashSet.h>
+#include <wtf/Noncopyable.h>
 
 namespace WebCore {
 
index abfd784ed8ef28774cdb42aae0b6c99aa8b20ae1..e65acb4bbe358c93cefb9a23c6ed6234f196b979 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #include "MediaPlayer.h"
 #include "Timer.h"
-#include "wtf/RetainPtr.h"
-#include "wtf/Noncopyable.h"
+#include <wtf/RetainPtr.h>
 
 #ifdef __OBJC__
-#import "QTKit/QTTime.h"
+#import <QTKit/QTTime.h>
 @class QTMovie;
 @class QTMovieView;
 @class WebCoreMovieObserver;
@@ -47,21 +46,15 @@ class WebCoreMovieObserver;
 
 namespace WebCore {
 
-class GraphicsContext;
-class IntSize;
-class IntRect;
-class String;
-
-class MediaPlayerPrivate : Noncopyable
-{
+class MediaPlayerPrivate : Noncopyable {
 public:
     MediaPlayerPrivate(MediaPlayer*);
     ~MediaPlayerPrivate();
     
-    IntSize naturalSize();
-    bool hasVideo();
+    IntSize naturalSize() const;
+    bool hasVideo() const;
     
-    void load(String url);
+    void load(const String& url);
     void cancelLoad();
     
     void play();
@@ -85,14 +78,14 @@ public:
     
     int dataRate() const;
     
-    MediaPlayer::NetworkState networkState();
-    MediaPlayer::ReadyState readyState();
+    MediaPlayer::NetworkState networkState() const { return m_networkState; }
+    MediaPlayer::ReadyState readyState() const { return m_readyState; }
     
-    float maxTimeBuffered();
-    float maxTimeSeekable();
-    unsigned bytesLoaded();
-    bool totalBytesKnown();
-    unsigned totalBytes();
+    float maxTimeBuffered() const;
+    float maxTimeSeekable() const;
+    unsigned bytesLoaded() const;
+    bool totalBytesKnown() const;
+    unsigned totalBytes() const;
     
     void setVisible(bool);
     void setRect(const IntRect& r);
@@ -104,24 +97,23 @@ public:
     void volumeChanged();
     void didEnd();
     
-    void paint(GraphicsContext* p, const IntRect& r);
-    
-    void createQTMovie(String url);
-    void createQTMovieView();
-    QTTime createQTTime(float time);
+    void paint(GraphicsContext*, const IntRect&);
     
     static void getSupportedTypes(HashSet<String>& types);
     
 private:
+    void createQTMovie(const String& url);
+    void createQTMovieView();
+    QTTime createQTTime(float time) const;
+    
     void updateStates();
     void doSeek();
     void cancelSeek();
     void seekTimerFired(Timer<MediaPlayerPrivate>*);
     void cuePointTimerFired(Timer<MediaPlayerPrivate>*);
-    float maxTimeLoaded();
+    float maxTimeLoaded() const;
     void startCuePointTimerIfNeeded();
-    
-private:    
+
     MediaPlayer* m_player;
     RetainPtr<QTMovie> m_qtMovie;
     RetainPtr<QTMovieView> m_qtMovieView;
index 1780506aca9cff67d01b952d2f78e54ac31d30d0..3ea920b9a2d61946abe02ce2ee3bf9e2f6b21968 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #import "config.h"
 
 #if ENABLE(VIDEO)
+
 #import "MediaPlayerPrivateQTKit.h"
 
 #import "BlockExceptions.h"
 #import "DeprecatedString.h"
 #import "GraphicsContext.h"
-#import "IntRect.h"
 #import "KURL.h"
-#import <limits>
-#import "MIMETypeRegistry.h"
-#import "MediaPlayer.h"
-#import <QTKit/QTKit.h>
 #import "ScrollView.h"
+#import "SoftLinking.h"
 #import "WebCoreSystemInterface.h"
-#import "Widget.h"
-#import "wtf/RetainPtr.h"
+#import <QTKit/QTKit.h>
+#import <objc/runtime.h>
+
+SOFT_LINK_FRAMEWORK(QTKit)
+
+SOFT_LINK(QTKit, QTMakeTime, QTTime, (long long timeValue, long timeScale), (timeValue, timeScale))
+
+SOFT_LINK_CLASS(QTKit, QTMovie)
+SOFT_LINK_CLASS(QTKit, QTMovieView)
+
+SOFT_LINK_POINTER(QTKit, QTMovieDataSizeAttribute, NSString *)
+SOFT_LINK_POINTER(QTKit, QTMovieDidEndNotification, NSString *)
+SOFT_LINK_POINTER(QTKit, QTMovieHasVideoAttribute, NSString *)
+SOFT_LINK_POINTER(QTKit, QTMovieLoadStateAttribute, NSString *)
+SOFT_LINK_POINTER(QTKit, QTMovieLoadStateDidChangeNotification, NSString *)
+SOFT_LINK_POINTER(QTKit, QTMovieNaturalSizeAttribute, NSString *)
+SOFT_LINK_POINTER(QTKit, QTMovieRateDidChangeNotification, NSString *)
+SOFT_LINK_POINTER(QTKit, QTMovieSizeDidChangeNotification, NSString *)
+SOFT_LINK_POINTER(QTKit, QTMovieTimeDidChangeNotification, NSString *)
+SOFT_LINK_POINTER(QTKit, QTMovieTimeScaleAttribute, NSString *)
+SOFT_LINK_POINTER(QTKit, QTMovieVolumeDidChangeNotification, NSString *)
+
+#define QTMovie getQTMovieClass()
+#define QTMovieView getQTMovieViewClass()
+
+#define QTMovieDataSizeAttribute getQTMovieDataSizeAttribute()
+#define QTMovieDidEndNotification getQTMovieDidEndNotification()
+#define QTMovieHasVideoAttribute getQTMovieHasVideoAttribute()
+#define QTMovieLoadStateAttribute getQTMovieLoadStateAttribute()
+#define QTMovieLoadStateDidChangeNotification getQTMovieLoadStateDidChangeNotification()
+#define QTMovieNaturalSizeAttribute getQTMovieNaturalSizeAttribute()
+#define QTMovieRateDidChangeNotification getQTMovieRateDidChangeNotification()
+#define QTMovieSizeDidChangeNotification getQTMovieSizeDidChangeNotification()
+#define QTMovieTimeDidChangeNotification getQTMovieTimeDidChangeNotification()
+#define QTMovieTimeScaleAttribute getQTMovieTimeScaleAttribute()
+#define QTMovieVolumeDidChangeNotification getQTMovieVolumeDidChangeNotification()
+
+using namespace WebCore;
+using namespace std;
 
 @interface WebCoreMovieObserver : NSObject
 {
-    WebCore::MediaPlayerPrivate* _callback;
-    BOOL _delayCallbacks;
+    MediaPlayerPrivate* m_callback;
+    BOOL m_delayCallbacks;
 }
--(id)initWithCallback:(WebCore::MediaPlayerPrivate *)c;
+-(id)initWithCallback:(MediaPlayerPrivate*)callback;
 -(void)disconnect;
--(void)setDelayCallbacks:(BOOL)b;
+-(void)setDelayCallbacks:(BOOL)shouldDelay;
 -(void)loadStateChanged:(NSNotification *)notification;
 -(void)rateChanged:(NSNotification *)notification;
 -(void)sizeChanged:(NSNotification *)notification;
 @end
 
 namespace WebCore {
+
+static const float cuePointTimerInterval = 0.020f;
     
 MediaPlayerPrivate::MediaPlayerPrivate(MediaPlayer* player)
     : m_player(player)
-    , m_qtMovie(nil)
-    , m_qtMovieView(nil)
     , m_objcObserver(AdoptNS, [[WebCoreMovieObserver alloc] initWithCallback:this])
     , m_seekTo(-1)
-    , m_endTime(std::numeric_limits<float>::infinity())
+    , m_endTime(numeric_limits<float>::infinity())
     , m_seekTimer(this, &MediaPlayerPrivate::seekTimerFired)
     , m_cuePointTimer(this, &MediaPlayerPrivate::cuePointTimerFired)
     , m_previousTimeCueTimerFired(0)
@@ -77,7 +111,6 @@ MediaPlayerPrivate::MediaPlayerPrivate(MediaPlayer* player)
 {
 }
 
-
 MediaPlayerPrivate::~MediaPlayerPrivate()
 {
     if (m_qtMovieView)
@@ -86,23 +119,21 @@ MediaPlayerPrivate::~MediaPlayerPrivate()
     [m_objcObserver.get() disconnect];
 }
 
-void MediaPlayerPrivate::createQTMovie(String url)
+void MediaPlayerPrivate::createQTMovie(const String& url)
 {
     [[NSNotificationCenter defaultCenter] removeObserver:m_objcObserver.get()];
     
-    m_qtMovie = nil;
-    
     NSError* error = nil;
-    m_qtMovie = [[[QTMovie alloc] initWithURL:KURL(url.deprecatedString()).getNSURL() error:&error] autorelease];
+    m_qtMovie.adoptNS([[QTMovie alloc] initWithURL:KURL(url.deprecatedString()).getNSURL() error:&error]);
     
-    // FIXME: find a proper way to do this
+    // FIXME: Find a proper way to detect streaming content.
     m_isStreaming = url.startsWith("rtsp:");
     
     if (!m_qtMovie)
         return;
     
-    [m_qtMovie.get() setVolume: m_player->volume()];
-    [m_qtMovie.get() setMuted: m_player->muted()];
+    [m_qtMovie.get() setVolume:m_player->volume()];
+    [m_qtMovie.get() setMuted:m_player->muted()];
     
     [[NSNotificationCenter defaultCenter] addObserver:m_objcObserver.get()
                                              selector:@selector(loadStateChanged:) 
@@ -138,27 +169,26 @@ void MediaPlayerPrivate::createQTMovieView()
     }
     if (!m_player->m_parentWidget || !m_qtMovie)
         return;
-    m_qtMovieView = [[[QTMovieView alloc] initWithFrame:m_player->rect()] autorelease];
+    m_qtMovieView.adoptNS([[QTMovieView alloc] initWithFrame:m_player->rect()]);
     NSView* parentView = static_cast<ScrollView*>(m_player->m_parentWidget)->getDocumentView();
     [parentView addSubview:m_qtMovieView.get()];
     [m_qtMovieView.get() setMovie:m_qtMovie.get()];
     [m_qtMovieView.get() setControllerVisible:NO];
     [m_qtMovieView.get() setPreservesAspectRatio:YES];
     // the area not covered by video should be transparent
-    NSColor* transparent = [NSColor colorWithDeviceRed: 0.0f green: 0.0f blue: 0.0f alpha: 0.0f];
-    [m_qtMovieView.get() setFillColor:transparent];
+    [m_qtMovieView.get() setFillColor:[NSColor clearColor]];
     wkQTMovieViewSetDrawSynchronously(m_qtMovieView.get(), YES);
 }
 
-QTTime MediaPlayerPrivate::createQTTime(float time)
+QTTime MediaPlayerPrivate::createQTTime(float time) const
 {
     if (!m_qtMovie)
         return QTMakeTime(0, 600);
-    int timeScale = [[m_qtMovie.get() attributeForKey:QTMovieTimeScaleAttribute] intValue];
-    return QTMakeTime((long long)(time * timeScale), timeScale);
+    long timeScale = [[m_qtMovie.get() attributeForKey:QTMovieTimeScaleAttribute] longValue];
+    return QTMakeTime(time * timeScale, timeScale);
 }
 
-void MediaPlayerPrivate::load(String url)
+void MediaPlayerPrivate::load(const String& url)
 {
     if (m_networkState != MediaPlayer::Loading) {
         m_networkState = MediaPlayer::Loading;
@@ -187,7 +217,7 @@ void MediaPlayerPrivate::play()
         return;
     m_startedPlaying = true;
     [m_objcObserver.get() setDelayCallbacks:YES];
-    [m_qtMovie.get() setRate: m_player->rate()];
+    [m_qtMovie.get() setRate:m_player->rate()];
     [m_objcObserver.get() setDelayCallbacks:NO];
     startCuePointTimerIfNeeded();
 }
@@ -209,8 +239,8 @@ float MediaPlayerPrivate::duration() const
         return 0;
     QTTime time = [m_qtMovie.get() duration];
     if (time.flags == kQTTimeIsIndefinite)
-        return std::numeric_limits<float>::infinity();
-    return (float)time.timeValue / time.timeScale;
+        return numeric_limits<float>::infinity();
+    return static_cast<float>(time.timeValue) / time.timeScale;
 }
 
 float MediaPlayerPrivate::currentTime() const
@@ -218,9 +248,7 @@ float MediaPlayerPrivate::currentTime() const
     if (!m_qtMovie)
         return 0;
     QTTime time = [m_qtMovie.get() currentTime];
-    float current = (float)time.timeValue / time.timeScale;    
-    current = std::min(current, m_endTime);
-    return current;
+    return min(static_cast<float>(time.timeValue) / time.timeScale, m_endTime);
 }
 
 void MediaPlayerPrivate::seek(float time)
@@ -239,7 +267,7 @@ void MediaPlayerPrivate::seek(float time)
     else 
         m_seekTimer.start(0, 0.5f);
 }
-    
+
 void MediaPlayerPrivate::doSeek() 
 {
     QTTime qttime = createQTTime(m_seekTo);
@@ -247,7 +275,7 @@ void MediaPlayerPrivate::doSeek()
     [m_objcObserver.get() setDelayCallbacks:YES];
     float oldRate = [m_qtMovie.get() rate];
     [m_qtMovie.get() setRate:0];
-    [m_qtMovie.get() setCurrentTime: qttime];
+    [m_qtMovie.get() setCurrentTime:qttime];
     float timeAfterSeek = currentTime();
     // restore playback only if not at end, othewise QTMovie will loop
     if (timeAfterSeek < duration() && timeAfterSeek < m_endTime)
@@ -289,13 +317,13 @@ void MediaPlayerPrivate::setEndTime(float time)
     startCuePointTimerIfNeeded();
 }
 
-void MediaPlayerPrivate::addCuePoint(float time)
+void MediaPlayerPrivate::addCuePoint(float /*time*/)
 {
-    // FIXME: simulate with timer for now
+    // FIXME: Eventually we'd like an approach that doesn't involve a timer.
     startCuePointTimerIfNeeded();
 }
 
-void MediaPlayerPrivate::removeCuePoint(float time)
+void MediaPlayerPrivate::removeCuePoint(float /*time*/)
 {
 }
 
@@ -308,7 +336,7 @@ void MediaPlayerPrivate::startCuePointTimerIfNeeded()
     if ((m_endTime < duration() || !m_player->m_cuePoints.isEmpty())
         && m_startedPlaying && !m_cuePointTimer.isActive()) {
         m_previousTimeCueTimerFired = currentTime();
-        m_cuePointTimer.startRepeating(0.020f);
+        m_cuePointTimer.startRepeating(cuePointTimerInterval);
     }
 }
 
@@ -323,9 +351,13 @@ void MediaPlayerPrivate::cuePointTimerFired(Timer<MediaPlayerPrivate>*)
         pause();
         didEnd();
     }
-    HashSet<float>::const_iterator end = m_player->m_cuePoints.end();
-    for (HashSet<float>::const_iterator it = m_player->m_cuePoints.begin(); it != end; ++it) {
-        float cueTime = *it;
+
+    // Make a copy since m_cuePoints could change as we deliver JavaScript calls.
+    Vector<float> cuePoints;
+    copyToVector(m_player->m_cuePoints, cuePoints);
+    size_t numCuePoints = cuePoints.size();
+    for (size_t i = 0; i < numCuePoints; ++i) {
+        float cueTime = cuePoints[i];
         if (previousTime < cueTime && cueTime <= time)
             m_player->cuePointReached(cueTime);
     }
@@ -335,7 +367,7 @@ bool MediaPlayerPrivate::paused() const
 {
     if (!m_qtMovie)
         return true;
-    return [m_qtMovie.get() rate] == 0.0f;
+    return [m_qtMovie.get() rate] == 0;
 }
 
 bool MediaPlayerPrivate::seeking() const
@@ -345,20 +377,18 @@ bool MediaPlayerPrivate::seeking() const
     return m_seekTo >= 0;
 }
 
-IntSize MediaPlayerPrivate::naturalSize()
+IntSize MediaPlayerPrivate::naturalSize() const
 {
     if (!m_qtMovie)
         return IntSize();
-    NSSize val = [[m_qtMovie.get() attributeForKey:QTMovieNaturalSizeAttribute] sizeValue];
-    return IntSize(val);
+    return IntSize([[m_qtMovie.get() attributeForKey:QTMovieNaturalSizeAttribute] sizeValue]);
 }
 
-bool MediaPlayerPrivate::hasVideo()
+bool MediaPlayerPrivate::hasVideo() const
 {
     if (!m_qtMovie)
         return false;
-    BOOL val = [[m_qtMovie.get() attributeForKey: QTMovieHasVideoAttribute] boolValue];
-    return val;
+    return [[m_qtMovie.get() attributeForKey:QTMovieHasVideoAttribute] boolValue];
 }
 
 void MediaPlayerPrivate::setVolume(float volume)
@@ -391,61 +421,48 @@ int MediaPlayerPrivate::dataRate() const
 }
 
 
-MediaPlayer::NetworkState MediaPlayerPrivate::networkState()
-{
-    return m_networkState;
-}
-
-MediaPlayer::ReadyState MediaPlayerPrivate::readyState()
-{
-    return m_readyState;
-}
-
-float MediaPlayerPrivate::maxTimeBuffered()
+float MediaPlayerPrivate::maxTimeBuffered() const
 {
     // rtsp streams are not buffered
     return m_isStreaming ? 0 : maxTimeLoaded();
 }
 
-float MediaPlayerPrivate::maxTimeSeekable()
+float MediaPlayerPrivate::maxTimeSeekable() const
 {
     // infinite duration means live stream
     return isinf(duration()) ? 0 : maxTimeLoaded();
 }
 
-float MediaPlayerPrivate::maxTimeLoaded()
+float MediaPlayerPrivate::maxTimeLoaded() const
 {
     if (!m_qtMovie)
         return 0;
     return wkQTMovieMaxTimeLoaded(m_qtMovie.get()); 
 }
 
-unsigned MediaPlayerPrivate::bytesLoaded()
+unsigned MediaPlayerPrivate::bytesLoaded() const
 {
-    if (!m_qtMovie)
-        return 0;
     float dur = duration();
-    float maxTime = maxTimeLoaded();
     if (!dur)
         return 0;
-    return totalBytes() * maxTime / dur;
+    return totalBytes() * maxTimeLoaded() / dur;
 }
 
-bool MediaPlayerPrivate::totalBytesKnown()
+bool MediaPlayerPrivate::totalBytesKnown() const
 {
     return totalBytes() > 0;
 }
 
-unsigned MediaPlayerPrivate::totalBytes()
+unsigned MediaPlayerPrivate::totalBytes() const
 {
     if (!m_qtMovie)
         return 0;
-    return [[m_qtMovie.get() attributeForKey: QTMovieDataSizeAttribute] intValue];
+    return [[m_qtMovie.get() attributeForKey:QTMovieDataSizeAttribute] intValue];
 }
 
 void MediaPlayerPrivate::cancelLoad()
 {
-    // FIXME better way to do this?
+    // FIXME: Is there a better way to check for this?
     if (m_networkState < MediaPlayer::Loading || m_networkState == MediaPlayer::Loaded)
         return;
     
@@ -464,24 +481,20 @@ void MediaPlayerPrivate::updateStates()
     MediaPlayer::ReadyState oldReadyState = m_readyState;
     
     long loadState = m_qtMovie ? [[m_qtMovie.get() attributeForKey:QTMovieLoadStateAttribute] longValue] : -1;
-    // "Loaded" is reserved for fully buffered movies, never the case when rtsp streaming
-    if (loadState >= 100000 && !m_isStreaming) {
-        // 100000 is kMovieLoadStateComplete
+    // "Loaded" is reserved for fully buffered movies, never the case when streaming
+    if (loadState >= kMovieLoadStateComplete && !m_isStreaming) {
         if (m_networkState < MediaPlayer::Loaded)
             m_networkState = MediaPlayer::Loaded;
         m_readyState = MediaPlayer::CanPlayThrough;
-    } else if (loadState >= 20000) {
-        // 20000 is kMovieLoadStatePlaythroughOK
+    } else if (loadState >= kMovieLoadStatePlaythroughOK) {
         if (m_networkState < MediaPlayer::LoadedFirstFrame && !seeking())
             m_networkState = MediaPlayer::LoadedFirstFrame;
-        m_readyState = ([m_qtMovie.get() rate] == 0.0f && m_startedPlaying) ? MediaPlayer::DataUnavailable : MediaPlayer::CanPlayThrough;
-    } else if (loadState >= 10000) {
-        // 10000 is kMovieLoadStatePlayable
+        m_readyState = ([m_qtMovie.get() rate] == 0 && m_startedPlaying) ? MediaPlayer::DataUnavailable : MediaPlayer::CanPlayThrough;
+    } else if (loadState >= kMovieLoadStatePlayable) {
         if (m_networkState < MediaPlayer::LoadedFirstFrame && !seeking())
             m_networkState = MediaPlayer::LoadedFirstFrame;
-        m_readyState = ([m_qtMovie.get() rate] == 0.0f && m_startedPlaying) ? MediaPlayer::DataUnavailable : MediaPlayer::CanPlay;
-    } else if (loadState >= 2000) {
-        // 10000 is kMovieLoadStateLoaded
+        m_readyState = ([m_qtMovie.get() rate] == 0 && m_startedPlaying) ? MediaPlayer::DataUnavailable : MediaPlayer::CanPlay;
+    } else if (loadState >= kMovieLoadStateLoaded) {
         if (m_networkState < MediaPlayer::LoadedMetaData)
             m_networkState = MediaPlayer::LoadedMetaData;
         m_readyState = MediaPlayer::DataUnavailable;
@@ -540,7 +553,7 @@ void MediaPlayerPrivate::didEnd()
 void MediaPlayerPrivate::setRect(const IntRect& r) 
 { 
     if (m_qtMovieView)
-        [m_qtMovieView.get() setFrame: r];
+        [m_qtMovieView.get() setFrame:r];
 }
 
 void MediaPlayerPrivate::setVisible(bool b)
@@ -553,9 +566,9 @@ void MediaPlayerPrivate::setVisible(bool b)
     }
 }
 
-void MediaPlayerPrivate::paint(GraphicsContext* p, const IntRect& r)
+void MediaPlayerPrivate::paint(GraphicsContext* context, const IntRect& r)
 {
-    if (p->paintingDisabled())
+    if (context->paintingDisabled())
         return;
     NSView *view = m_qtMovieView.get();
     if (view == nil)
@@ -569,82 +582,89 @@ void MediaPlayerPrivate::paint(GraphicsContext* p, const IntRect& r)
 
 void MediaPlayerPrivate::getSupportedTypes(HashSet<String>& types)
 {
-    NSArray* fileTypes = [QTMovie movieFileTypes:(QTMovieFileTypeOptions)0];
+    NSArray* fileTypes = [QTMovie movieFileTypes:QTIncludeCommonTypes];
     int count = [fileTypes count];
     for (int n = 0; n < count; n++) {
-        NSString* ext = (NSString*)[fileTypes objectAtIndex:n];
-        CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)ext, NULL);
+        CFStringRef ext = reinterpret_cast<CFStringRef>([fileTypes objectAtIndex:n]);
+        RetainPtr<CFStringRef> uti(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, ext, NULL));
         if (!uti)
             continue;
-        CFStringRef mime = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType);
-        CFRelease(uti);
+        RetainPtr<CFStringRef> mime(AdoptCF, UTTypeCopyPreferredTagWithClass(uti.get(), kUTTagClassMIMEType));
         if (!mime)
             continue;
-        types.add(String((NSString*)mime));
-        CFRelease(mime);
+        types.add(mime.get());
     }
 } 
 
 }
 
 @implementation WebCoreMovieObserver
--(id)initWithCallback:(WebCore::MediaPlayerPrivate *)c
+
+- (id)initWithCallback:(MediaPlayerPrivate *)callback
 {
-    _callback = c;
+    m_callback = callback;
     return [super init];
 }
--(void)disconnect
+
+- (void)disconnect
 {
     [NSObject cancelPreviousPerformRequestsWithTarget:self];
-    _callback = 0;
+    m_callback = 0;
 }
--(void)loadStateChanged:(NSNotification *)notification
+
+- (void)loadStateChanged:(NSNotification *)notification
 {
-    if (_delayCallbacks)
-        [self performSelector:@selector(loadStateChanged:) withObject:nil afterDelay:0];
+    if (m_delayCallbacks)
+        [self performSelector:_cmd withObject:nil afterDelay:0];
     else
-        _callback->loadStateChanged();
+        m_callback->loadStateChanged();
 }
--(void)rateChanged:(NSNotification *)notification
+
+- (void)rateChanged:(NSNotification *)notification
 {
-    if (_delayCallbacks)
-        [self performSelector:@selector(rateChanged:) withObject:nil afterDelay:0];
+    if (m_delayCallbacks)
+        [self performSelector:_cmd withObject:nil afterDelay:0];
     else
-        _callback->rateChanged();
+        m_callback->rateChanged();
 }
--(void)sizeChanged:(NSNotification *)notification
+
+- (void)sizeChanged:(NSNotification *)notification
 {
-    if (_delayCallbacks)
-        [self performSelector:@selector(sizeChanged:) withObject:nil afterDelay:0];
+    if (m_delayCallbacks)
+        [self performSelector:_cmd withObject:nil afterDelay:0];
     else
-        _callback->sizeChanged();
+        m_callback->sizeChanged();
 }
--(void)timeChanged:(NSNotification *)notification
+
+- (void)timeChanged:(NSNotification *)notification
 {
-    if (_delayCallbacks)
-        [self performSelector:@selector(timeChanged:) withObject:nil afterDelay:0];
+    if (m_delayCallbacks)
+        [self performSelector:_cmd withObject:nil afterDelay:0];
     else
-        _callback->timeChanged();
+        m_callback->timeChanged();
 }
--(void)volumeChanged:(NSNotification *)notification
+
+- (void)volumeChanged:(NSNotification *)notification
 {
-    if (_delayCallbacks)
-        [self performSelector:@selector(volumeChanged:) withObject:nil afterDelay:0];
+    if (m_delayCallbacks)
+        [self performSelector:_cmd withObject:nil afterDelay:0];
     else
-        _callback->volumeChanged();
+        m_callback->volumeChanged();
 }
--(void)didEnd:(NSNotification *)notification
+
+- (void)didEnd:(NSNotification *)notification
 {
-    if (_delayCallbacks)
-        [self performSelector:@selector(didEnd:) withObject:nil afterDelay:0];
+    if (m_delayCallbacks)
+        [self performSelector:_cmd withObject:nil afterDelay:0];
     else
-        _callback->didEnd();
+        m_callback->didEnd();
 }
--(void)setDelayCallbacks:(BOOL)b
+
+- (void)setDelayCallbacks:(BOOL)shouldDelay
 {
-    _delayCallbacks = b;
+    m_delayCallbacks = shouldDelay;
 }
+
 @end
 
 #endif
-
index 2b2a744858379bc59ff9e704613a20e4dd229a5f..d470b2959b2fb7714b238754d6de6afe4c1d5397 100644 (file)
     {\
         return softLink##functionName parameterNames; \
     }
+
+#define SOFT_LINK_CLASS(framework, className) \
+    static Class init##className(); \
+    static Class (*get##className##Class)() = init##className; \
+    static Class class##className; \
+    \
+    static Class className##Function() \
+    { \
+        return class##className; \
+    }\
+    \
+    static Class init##className() \
+    { \
+        framework##Library(); \
+        class##className = objc_getClass(#className); \
+        ASSERT(class##className); \
+        get##className##Class = className##Function; \
+        return class##className; \
+    }
+
+#define SOFT_LINK_POINTER(framework, name, type) \
+    static type init##name(); \
+    static type (*get##name)() = init##name; \
+    static type pointer##name; \
+    \
+    static type name##Function() \
+    { \
+        return pointer##name; \
+    }\
+    \
+    static type init##name() \
+    { \
+        void** pointer = static_cast<void**>(dlsym(framework##Library(), #name)); \
+        ASSERT(pointer); \
+        pointer##name = static_cast<type>(*pointer); \
+        get##name = name##Function; \
+        return pointer##name; \
+    }