Improve PageVisibility API with enums

https://bugs.webkit.org/show_bug.cgi?id=107364

Reviewed by Sam Weinig.

Source/WebKit/mac:

* WebView/WebView.mm:
* WebView/WebViewPrivate.h:
(corePageVisibilityState):
(-[WebView _setVisibilityState:isInitialState:]):
Switch the private API form int to a WebPageVisibilityState enum.

Source/WebKit2:

* Shared/API/c/WKPageVisibilityTypes.h: Added.
* Shared/API/c/WKSharedAPICast.h:
(WebKit::toPageVisibilityState):
Create an enum for page visibility APIs and a conversion function
for the WK2 values to WebCore values.

* Target.pri:
* GNUmakefile.list.am:
* WebKit2.xcodeproj/project.pbxproj:
Add WKPageVisibilityTypes.h to the build as a private export.

* UIProcess/API/C/WKPage.h:
* UIProcess/API/C/WKPage.cpp:
(WKPageSetVisibilityState):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setVisibilityState):
UIProcess API to set visibility state. WebPageProxy already
had m_visibilityState, so update that when setter is used.

* WebProcess/InjectedBundle/API/c/WKBundle.cpp:
* WebProcess/InjectedBundle/API/c/WKBundlePrivate.h:
* WebProcess/InjectedBundle/InjectedBundle.cpp:
* WebProcess/InjectedBundle/InjectedBundle.h:
Remove the old SPI for WebKitTestRunner. Tests now use the C API.

* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setVisibilityState):
* WebProcess/WebPage/WebPage.messages.in:
Update the existing WebPage API to use uint32_t, which matches
other enum message types.

Tools:

* DumpRenderTree/mac/TestRunnerMac.mm:
(TestRunner::resetPageVisibility):
(TestRunner::setPageVisibility):
Update the WK1 test code to use the new WK1 enums.

* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::setVisibilityState):
* WebKitTestRunner/InjectedBundle/InjectedBundle.h:
(InjectedBundle):
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::setPageVisibility):
(WTR::TestRunner::resetPageVisibility):
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::setVisibilityState):
* WebKitTestRunner/TestController.h:
(TestController):
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
Update the WK2 test code to use the new WK2 API and enums.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/PageVisibilityState.cpp: Added.
(TestWebKitAPI):
(TestWebKitAPI::setPageVisibilityStateWithEvalContinuation):
(TestWebKitAPI::assertSerializedScriptValueIsStringValue):
(TestWebKitAPI::didRunStep1StateChangeVisibleToHidden):
(TestWebKitAPI::didRunStep2StateChangeHiddenToPrerender):
(TestWebKitAPI::didRunStep3StateChangePrerenderToPreview):
(TestWebKitAPI::didRunStep4InStatePreview):
(TestWebKitAPI::TEST):
Test the new WK2 API with all enum types.

Change-Id: I0a057111d7ef26cb87ade328291d4f94322480b7
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@141010 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
[Mac] Update PageVisibilityState when WebView is hidden / visible

https://bugs.webkit.org/show_bug.cgi?id=107509

Source/WebKit/mac:

Reviewed by NOBODY (OOPS!).

* WebView/WebView.mm:
* WebView/WebViewPrivate.h:
(-[WebView _commonInitializationWithFrameName:groupName:]):
Set the initial visibility of the page.

(-[WebView addWindowObserversForWindow:]):
(-[WebView removeWindowObservers]):
(-[WebView _isViewVisible]):
(-[WebView _updateVisibilityState]):
(-[WebView viewDidMoveToWindow]):
(-[WebView _windowVisibilityChanged:]):
Update visibility state in the same ways WK2 does. This involves
listening for some new NSWindow delegates.

Tools:

Add a test that PageVisibility of WK1 WebViews and WK2 WKViews
automatically changes between hidden and visible as the view is added
and removed from window, or when it is in a window that changes
visibility, for instance by minimizing / deminimizing.

Reviewed by NOBODY (OOPS!).

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.html: Added.
* TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm: Added.
(-[PageVisibilityStateDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:]):
(runJavaScriptAlert):
(PageVisibilityStateWithWindowChanges):
(TestWebKitAPI::PageVisibilityStateWithWindowChanges::initializeView):
(TestWebKitAPI::PageVisibilityStateWithWindowChanges::deinitializeView):
(TestWebKitAPI::PageVisibilityStateWithWindowChanges::runTest):
(TestWebKitAPI::TEST_F):
Test visibility state of a page in a WebView/WKView with different window states.

* TestWebKitAPI/mac/WebKitAgnosticTest.h:
* TestWebKitAPI/mac/WebKitAgnosticTest.mm:
(TestWebKitAPI::WebKitAgnosticTest::deinitializeView):
(TestWebKitAPI::WebKitAgnosticTest::runWebKit1Test):
(TestWebKitAPI::WebKitAgnosticTest::runWebKit2Test):
Add a WK1 and WK2 deinitializeView to balance initializeView.

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

Change-Id: Ie9ef191e55f69ee32b01a0e7220820be038ac8a4
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>