Generalize PageActivityAssertionToken
https://bugs.webkit.org/show_bug.cgi?id=139106

Reviewed by Sam Weinig.

Source/WebCore:

PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler
to count user visible activity in progress on the page (currently page load and media playback).
Use of an RAII type is prevents a number of possible errors, including double counting a single
media element, or failing to decrement the count after a media element has been deallocated.

The current implementation has a number of drawbacks that have been addressed by this refactoring:
 - specific to single use in PageThrottler class - not reusable.
 - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation
   are not encapsulated (are in the client type, PageThrottler).
 - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every
   increment requires an object allocation.
 - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this
   is internally implemented using a reference counted type, resulting in two counters being
   incremented (one in the PageActivityAssertionToken, one in the PageThrottler).

In the reimplementation:
 - a callback is provided via a lambda function, which allows for easy reuse without a lot of
   boilerplate code.
 - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the
   RefCounter type.
 - a single count within RefCounter::Count stores the counter value, and also manage the lifetime
   of this object.
 - standard RefPtrs are used to manage references to the RefCounter::Count.

* WebCore.xcodeproj/project.pbxproj:
    - removed PageActivityAssertionToken.cpp/.h
* html/HTMLMediaElement.cpp:
    - removed PageActivityAssertionToken.h
* html/HTMLMediaElement.h:
    - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count>
* loader/FrameLoader.cpp:
    - removed PageActivityAssertionToken.h
* loader/FrameLoader.h:
    - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count>
* loader/SubresourceLoader.cpp:
    - removed PageActivityAssertionToken.h
* loader/SubresourceLoader.h:
    - removed class PageActivityAssertionToken
* page/Page.cpp:
    - removed PageActivityAssertionToken.h
(WebCore::Page::Page):
    - removed Page* parameter to PageThrottler
* page/Page.h:
    - removed class PageActivityAssertionToken
* page/PageActivityAssertionToken.cpp: Removed.
* page/PageActivityAssertionToken.h: Removed.
    - removed PageActivityAssertionToken.cpp/.h
* page/PageThrottler.cpp:
(WebCore::PageThrottler::PageThrottler):
    - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter.
(WebCore::PageThrottler::mediaActivityToken):
    - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count>
(WebCore::PageThrottler::pageLoadActivityToken):
    - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count>
(WebCore::PageThrottler::pageActivityCounterValueDidChange):
    - merged functionality of incrementActivityCount/decrementActivityCount
(WebCore::PageThrottler::incrementActivityCount): Deleted.
    - see pageActivityCounterValueDidChange
(WebCore::PageThrottler::decrementActivityCount): Deleted.
    - see pageActivityCounterValueDidChange
* page/PageThrottler.h:
(WebCore::PageThrottler::weakPtr): Deleted.
    - no longer required; this functionality is now encapsulated within RefCounter.

Source/WTF:

PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler
to count user visible activity in progress on the page (currently page load and media playback).
Use of an RAII type is prevents a number of possible errors, including double counting a single
media element, or failing to decrement the count after a media element has been deallocated.

The current implementation has a number of drawbacks that have been addressed by this refactoring:
 - specific to single use in PageThrottler class - not reusable.
 - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation
   are not encapsulated (are in the client type, PageThrottler).
 - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every
   increment requires an object allocation.
 - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this
   is internally implemented using a reference counted type, resulting in two counters being
   incremented (one in the PageActivityAssertionToken, one in the PageThrottler).

In the reimplementation:
 - a callback is provided via a lambda function, which allows for easy reuse without a lot of
   boilerplate code.
 - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the
   RefCounter type.
 - a single count within RefCounter::Count stores the counter value, and also manage the lifetime
   of this object.
 - standard RefPtrs are used to manage references to the RefCounter::Count.

* WTF.xcodeproj/project.pbxproj:
    - added RefCounter.cpp/.h
* wtf/RefCounter.cpp: Added.
(WTF::RefCounter::Count::ref):
    - increment the counter.
(WTF::RefCounter::Count::deref):
    - decrement the counter, and delete as necessary.
(WTF::RefCounter::RefCounter):
    - create a RefCounter::Count.
(WTF::RefCounter::~RefCounter):
    - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref.
* wtf/RefCounter.h: Added.
(WTF::RefCounter::Count::Count):
    - initialize count to 0.
(WTF::RefCounter::RefCounter):
    - takes a lambda to be called when the value changes.
(WTF::RefCounter::count):
    - reference the counter (and in doing so increment the count).
(WTF::RefCounter::value):
    - access the current value of the counter.

Tools:

Add an API test for WTF::RefCounter.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added.
(TestWebKitAPI::TEST):
    - added RefCounter test.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Should use standardQuickLookMenuItem for apps that don't implement customizations
https://bugs.webkit.org/show_bug.cgi?id=139193
-and corresponding-
rdar://problem/18944696

Reviewed by Anders Carlsson.

Source/WebCore:

New SPI headers.
* WebCore.xcodeproj/project.pbxproj:
* platform/spi/mac/NSMenuSPI.h: Added.
* platform/spi/mac/QuickLookMacSPI.h: Added.

Source/WebKit/mac:

Use [NSMenuItem standardQuickLookMenuItem].
* WebView/WebActionMenuController.mm:
(-[WebActionMenuController _defaultMenuItemsForLink]):

Delegate methods to set up the standardQuickLookMenuItem.
(-[WebActionMenuController menuItem:viewAtScreenPoint:]):
(-[WebActionMenuController menuItem:previewItemAtPoint:]):
(-[WebActionMenuController menuItem:preferredEdgeForPoint:]):

Remove all of the old QLPreviewBubble code.
(-[WebActionMenuController _createActionMenuItemForTag:]):
(-[WebActionMenuController _quickLookURLFromActionMenu:]): Deleted.

Source/WebKit2:

New SPI will allow clients to opt-out of the standardQuickLookMenuItem. By 
default, opt in.
* UIProcess/API/Cocoa/WKViewPrivate.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView _shouldUseStandardQuickLookPreview]):
* UIProcess/mac/WKActionMenuController.mm:

Use [NSMenuItem standardQuickLookMenuItem] unless the client has requested 
otherwise.
(-[WKActionMenuController _defaultMenuItemsForLink]):

Delegate methods to set up the standardQuickLookMenuItem.
(-[WKActionMenuController menuItem:viewAtScreenPoint:]):
(-[WKActionMenuController menuItem:previewItemAtPoint:]):
(-[WKActionMenuController menuItem:preferredEdgeForPoint:]):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176684 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Unreviewed, fix typo introduced in r176673.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::platformDuration):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176685 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Remove more Windows cruft
https://bugs.webkit.org/show_bug.cgi?id=139189

Reviewed by Andreas Kling.

* WebCoreSupport/WebFrameLoaderClient.cpp:
(WebFrameLoaderClient::createNetworkingContext):
* WebCoreSupport/WebFrameNetworkingContext.h:
(WebFrameNetworkingContext::create):
(WebFrameNetworkingContext::WebFrameNetworkingContext):
(WebFrameNetworkingContext::userAgent): Deleted.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176686 268f45cc-cd09-0410-ab3c-d52691b4dbfc
REGRESSION: Dragging selected text changes the selection
https://bugs.webkit.org/show_bug.cgi?id=139110

Reviewed by Simon Fraser.

After it sent the UI process the message to start dragging, the Web process handled mouse
move events that had already been in flight, interpreting them as a drag to start a new
selection. This is fixed by ignoring any mouse events received after asking the UI process
to start dragging.

* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::setDragImage): Send the new DidStartDrag message back to the Web
process, so that it stops ignoring mouse events.

* WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
(WebKit::WebDragClient::startDrag): Call the new WebPage::willStartDrag, so that it starts
ignoring mouse events.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage): Initialize new member variable.
(WebKit::WebPage::mouseEvent): Don’t handle the event if we have asked the UI process to
start dragging.

* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::willStartDrag): Added. Sets new member variable m_isStartingDrag to true.
(WebKit::WebPage::didStartDrag): Added. Handles the message from the UI process by setting
m_isStartingDrag back to false.

* WebProcess/WebPage/WebPage.messages.in: Added DidStartDrag.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176687 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Speculative build fix.

* platform/spi/mac/QuickLookMacSPI.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176688 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Speculative build fix.

* platform/spi/mac/QuickLookMacSPI.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176689 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebKit/mac:
More build fixing.

* WebView/WebActionMenuController.mm:
(-[WebActionMenuController _defaultMenuItemsForLink]):

Source/WebKit2:
More build fix.

* UIProcess/mac/WKActionMenuController.mm:
(-[WKActionMenuController _defaultMenuItemsForLink]):



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

Source/WebKit/mac:

* WebView/WebActionMenuController.mm:
(-[WebActionMenuController _defaultMenuItemsForLink]):

Source/WebKit2:

* UIProcess/mac/WKActionMenuController.mm:
(-[WKActionMenuController _defaultMenuItemsForLink]):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176691 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Another build fix.

* platform/spi/mac/NSMenuSPI.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176692 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Yet another build fix.

* WebView/WebActionMenuController.mm:
(-[WebActionMenuController _defaultMenuItemsForLink]):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176693 268f45cc-cd09-0410-ab3c-d52691b4dbfc
More build fixing.

* platform/spi/mac/QuickLookMacSPI.h:



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