DOM timer throttling for hidden plugins
https://bugs.webkit.org/show_bug.cgi?id=136197

Patch by Gavin Barraclough <barraclough@apple.com> on 2014-09-17
Reviewed by Geoff Garen & Andreas Kling.

For non-visible web pages we slow timers (since they can't be driving animations, etc).
We should do the same for plugins.

Source/WebCore:

There are a few steps to this:
    - JSPluginElementFunctions notifies DOMTimer when script interacts with a plugin.
    - DOMTimerFireState keeps a record of events that occur while a timer is firing.
    - DOMTimer::fired detects timers that interact with invisible/inaudible plugins, and flags itself for throtting.
    - DOMTimer::intervalClampedToMinimum sets timer intervals appropriately.

* bindings/js/JSPluginElementFunctions.cpp:
(WebCore::pluginScriptObject):
    - notify DOMTimer when script interacts with a plugin.
* html/HTMLPlugInElement.cpp:
(WebCore::HTMLPlugInElement::isDetectable):
* html/HTMLPlugInElement.h:
    - added isDetectable, to check for visible / audible plugins.
* page/DOMTimer.cpp:
(WebCore::DOMTimerFireState::DOMTimerFireState):
(WebCore::DOMTimerFireState::~DOMTimerFireState):
    - track current DOMTimerFireState.
(WebCore::DOMTimer::DOMTimer):
    - initialize m_throttleState.
(WebCore::DOMTimer::scriptDidInteractWithPlugin):
    - if interaction with a plugin occurs while a timer is firing, record on the DOMTimerFireState.
(WebCore::DOMTimer::fired):
    - set DOMTimerFireState, and update m_throttleState accordingly.
(WebCore::DOMTimer::updateTimerIntervalIfNecessary):
    - remove redundant check of maxTimerNestingLevel (covered by intervalClampedToMinimum).
(WebCore::DOMTimer::intervalClampedToMinimum):
    - Also take m_throttleState into account when throttling.
* page/DOMTimer.h:
    - added scriptDidInteractWithPlugin, m_throttleState.
* platform/audio/AudioHardwareListener.h:
    - enum -> enum class.
* plugins/PluginViewBase.h:
(WebCore::PluginViewBase::audioHardwareActivity):
    - expose audioHardwareActivity on PluginViewBase (previously available in subclass).

Source/WebKit2:

* PluginProcess/WebProcessConnection.cpp:
* WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp:
    - remove now redundant includes.
* WebProcess/Plugins/PluginView.h:
    - audioHardwareActivity is now virtual, override.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@173694 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[iOS] Make WebCore build with public iOS SDK
https://bugs.webkit.org/show_bug.cgi?id=136487

Reviewed by David Kilzer.

Source/WebCore:

Add headers that wrap Mac and iOS SPIs and update WebCore source files to include these
headers instead of the corresponding actual SPI header(s).

* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.vcxproj/WebCoreCG.props:
* WebCore.vcxproj/copyForwardingHeaders.cmd:
* WebCore.xcodeproj/project.pbxproj:
* bindings/objc/DOMInternal.mm:
* bridge/objc/objc_instance.mm:
* platform/audio/ios/MediaSessionManagerIOS.mm:
* platform/cocoa/DisplaySleepDisablerCocoa.cpp:
* platform/cocoa/MemoryPressureHandlerCocoa.mm:
* platform/graphics/SimpleFontData.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
* platform/graphics/ca/mac/PlatformCALayerMac.mm:
* platform/graphics/cg/BitmapImageCG.cpp:
* platform/graphics/cg/ColorCG.cpp:
* platform/graphics/cg/GraphicsContextCG.cpp:
* platform/graphics/cg/ImageSourceCG.cpp:
* platform/graphics/cg/PDFDocumentImage.cpp:
* platform/graphics/cocoa/FontPlatformDataCocoa.mm:
* platform/graphics/ios/FontCacheIOS.mm:
* platform/graphics/ios/FontServicesIOS.mm:
* platform/graphics/ios/SimpleFontDataIOS.mm:
* platform/graphics/mac/FontMac.mm:
* platform/graphics/mac/GlyphPageTreeNodeMac.cpp:
* platform/graphics/mac/MediaPlayerProxy.h:
* platform/graphics/mac/SimpleFontDataMac.mm:
* platform/ios/LegacyTileCache.mm:
* platform/ios/LegacyTileGrid.mm:
* platform/ios/LegacyTileGridTile.mm:
* platform/ios/PlatformEventFactoryIOS.mm:
* platform/ios/PlatformScreenIOS.mm:
* platform/ios/WebEvent.mm:
* platform/ios/WebVideoFullscreenInterfaceAVKit.mm:
* platform/ios/wak/WAKAppKitStubs.h:
* platform/ios/wak/WAKView.h:
* platform/ios/wak/WKGraphics.h:
* platform/ios/wak/WKGraphics.mm:
* platform/ios/wak/WebCoreThread.mm:
* platform/network/ios/QuickLook.mm:
* platform/spi/ca/CALayerSPI.h: Added.
* platform/spi/ca/CATiledLayerSPI.h: Added.
* platform/spi/cf/CFLocaleSPI.h: Modified to use EXTERN_C.
* platform/spi/cf/CFNetworkConnectionCacheSPI.h: Ditto. Also changed header visibility from private to project.
* platform/spi/cf/CFURLRequestSPI.h: Ditto. Also modified to unconditionally include header <CoreFoundation/CFBase.h>.
* platform/spi/cg/CGColorTransformSPI.h: Added.
* platform/spi/cg/CGContextSPI.h: Added.
* platform/spi/cg/CGFloatSPI.h: Added.
* platform/spi/cg/CGFontGlyphSupportSPI.h: Added.
* platform/spi/cg/CGFontInfoSPI.h: Added.
* platform/spi/cg/CGFontRenderingSPI.h: Added.
* platform/spi/cg/CGFontUnicodeSupportSPI.h: Added.
* platform/spi/cg/CGImageSPI.h: Added.
* platform/spi/cg/CGSRegionSPI.h: Added.
* platform/spi/cocoa/DispatchSPI.h: Added.
* platform/spi/cocoa/IOPMLibSPI.h: Added.
* platform/spi/cocoa/MachVMSPI.h: Added.
* platform/spi/cocoa/NSFileManagerSPI.h: Added.
* platform/spi/cocoa/NSGeometrySPI.h: Added.
* platform/spi/cocoa/NSPointerFunctionsSPI.h: Added.
* platform/spi/cocoa/dyldSPI.h: Added.
* platform/spi/ios/AVPlayerControllerSPI.h: Added.
* platform/spi/ios/AVPlayerViewControllerSPI.h: Added.
* platform/spi/ios/AVValueTimingSPI.h: Added.
* platform/spi/ios/AVVideoLayerSPI.h: Added.
* platform/spi/ios/CTFontDescriptorSPI.h: Added.
* platform/spi/ios/CTFontSPI.h: Added.
* platform/spi/ios/CUICatalogSPI.h: Added.
* platform/spi/ios/CUIStyleEffectConfigurationSPI.h: Added.
* platform/spi/ios/MPAVRoutingControllerSPI.h: Added.
* platform/spi/ios/MobileGestaltSPI.h: Added.
* platform/spi/ios/QLPreviewConverterSPI.h: Added.
* platform/spi/ios/QuickLookSPI.h: Added.
* rendering/RenderThemeIOS.mm:

Source/WebKit/ios:

Substitute <WebCore/CGFloatSPI.h> for <CoreGraphics/CGFloat.h>.

* WebCoreSupport/WebFixedPositionContent.mm:

Source/WebKit/mac:

Update WebKit1 source files to include the wrapper SPI headers instead of the corresponding
actual SPI header(s).

* DOM/WebDOMOperationsPrivate.h:
* MigrateHeaders.make: Modified to only modify the include path of a "<WebCore/"-prefixed header
file if its filename doesn't end in "SPI.h" as an alternative to having MigrateHeaders.make copy
such files into the WebKit framework as private headers.
* WebCoreSupport/WebFrameLoaderClient.mm:
* WebInspector/WebNodeHighlight.mm:
* WebView/WebIndicateLayer.mm:
* WebView/WebRenderLayer.h:
* WebView/WebView.mm:

Source/WebKit2:

Update WebKit2 source files to include the wrapper SPI headers instead of the corresponding
actual SPI header(s).

* Platform/mac/SharedMemoryMac.cpp:
* Shared/ios/NativeWebTouchEventIOS.mm:
* Shared/mac/RemoteLayerBackingStore.mm:
* Shared/mac/RemoteLayerTreePropertyApplier.mm:
* UIProcess/API/Cocoa/WKWebView.mm:
* UIProcess/ios/WKPDFPageNumberIndicator.mm:
* UIProcess/ios/WKScrollView.mm:
* UIProcess/ios/WebMemoryPressureHandlerIOS.mm:
* UIProcess/ios/forms/WKAirPlayRoutePicker.mm:
* WebProcess/WebPage/WebPage.cpp:

Source/WTF:

Define convenience macro EXTERN_C that can be used to specify the C linkage convention
for a declaration. For example, the declaration "EXTERN_C const int x;" will expand to:

extern const int x;

and

extern "C" const int x;

when used in a C and C++ file, respectively.

* wtf/Compiler.h:

Tools:

Substitute <WebCore/MachVMSPI.h> for <mach/mach_vm.h>.

* DumpRenderTree/mac/CheckedMalloc.cpp:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@173695 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Aways have a PageThrottler (sometimes have a UserActivity::Impl)
https://bugs.webkit.org/show_bug.cgi?id=136892

Reviewed by Geoffrey Garen.

Some instances of Page have a PageThrottler to track activity on the Page, and some do not.
(Specifically, those created from WebPage in WK2 do, those related to WK1, SVG & inspector do not).

We do this for three reasons:
    * We do not need to take AppNap assertions on WK1.
    * Some Pages do not track their visibility correctly, and would always claim to be visible.
    * Page VisibilityState is not set until after construction, so if we instantiate

Creating the entire PageThrottler lazily has the drawback that we have to check for its existence at
numerous points throughout the code, and we'll miss activity that occurs between the Page being created
& the PageThrottler added to it (really a theoretical problem right now, since they're currently always
created pretty much back to back).

Instead, Page should always have a PageThrottler, & instead make the UserActivity::Impl on the
PageThrottler be added later.

Source/WebCore:

* WebCore.exp.in:
    - createPageThrottler -> enablePageThrottler
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::parseAttribute):
    - Page::pageThrottler now returns a reference rather than a pointer
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::started):
    - Page::pageThrottler now returns a reference rather than a pointer
* page/Page.cpp:
(WebCore::Page::Page):
    - instantiate PageThrottler in constructor
(WebCore::Page::enablePageThrottler):
    - renamed from createPageThrottler, instead of creating the PageThrottler this method now
      instruct PageThrottler to create a UserActivity::Impl
(WebCore::Page::setViewState):
    - m_pageThrottler is not a pointer
(WebCore::Page::createPageThrottler): Deleted.
    - renamed to enablePageThrottler
* page/Page.h:
(WebCore::Page::pageThrottler):
    - now returns a reference
* page/PageThrottler.cpp:
(WebCore::PageThrottler::PageThrottler):
    - no longer instantiate m_activity
(WebCore::PageThrottler::createUserActivity):
    - lazily instantiate m_activity, call updateUserActivity
(WebCore::PageThrottler::updateUserActivity):
    - m_activity may not yet be instantiated; added early return
* page/PageThrottler.h:
    - m_activity becomes a std::unique_ptr, added createUserActivity

Source/WebKit2:

* WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp:
(WebKit::NPRuntimeObjectMap::evaluate):
    - createPageThrottler -> enablePageThrottler
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
(WebKit::WebPage::mouseEvent):
(WebKit::WebPage::wheelEvent):
(WebKit::WebPage::keyEvent):
    - Page::pageThrottler now returns a reference rather than a pointer



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