Changeset 237786 in webkit


Ignore:
Timestamp:
Nov 4, 2018 1:19:44 PM (6 years ago)
Author:
Wenson Hsieh
Message:

[Cocoa] Fold common UIScriptController functionality on macOS and iOS into UIScriptControllerCocoa.mm
https://bugs.webkit.org/show_bug.cgi?id=191231

Reviewed by Simon Fraser.

Moves some UIScriptController method implementations specific to iOS and macOS into UIScriptControllerCocoa, so
it can be shared between iOS-family and macOS platforms. See below for more details.

No change in behavior.

  • DumpRenderTree/ios/UIScriptControllerIOS.mm:

(WTR::UIScriptController::overridePreference):

Add a method stub for DumpRenderTree.

  • TestRunnerShared/UIScriptContext/UIScriptController.cpp:
  • WebKitTestRunner/UIScriptControllerCocoa.mm:

(WTR::UIScriptController::doAsyncTask):
(WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution):

Unify these method implementations.

(WTR::UIScriptController::removeViewFromWindow):
(WTR::UIScriptController::addViewToWindow):

Move the macOS implementation to UIScriptControllerCocoa. On iOS, this method currently only adds the web view
to the window, and does not attempt to invoke the given completion block; additionally, invoking the completion
block after a presentation update (as done on macOS) causes pageoverlay/overlay-remove-reinsert-view.html to
begin failing consistently. This patch does not attempt to change behavior, but adds a FIXME describing this.

(WTR::UIScriptController::overridePreference):
(WTR::UIScriptController::findString):
(WTR::UIScriptController::contentsOfUserInterfaceItem const):

Move these from UIScriptControllerMac to UIScriptControllerCocoa, so that it is now implemented on iOS as well.

  • WebKitTestRunner/ios/UIScriptControllerIOS.mm:

(WTR::UIScriptController::doAsyncTask): Deleted.
(WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution): Deleted.
(WTR::UIScriptController::contentsOfUserInterfaceItem const): Deleted.
(WTR::UIScriptController::findString): Deleted.
(WTR::UIScriptController::removeViewFromWindow): Deleted.
(WTR::UIScriptController::addViewToWindow): Deleted.

  • WebKitTestRunner/mac/UIScriptControllerMac.mm:

(WTR::UIScriptController::doAsyncTask): Deleted.
(WTR::UIScriptController::contentsOfUserInterfaceItem const): Deleted.
(WTR::UIScriptController::overridePreference): Deleted.
(WTR::UIScriptController::findString): Deleted.
(WTR::UIScriptController::removeViewFromWindow): Deleted.
(WTR::UIScriptController::addViewToWindow): Deleted.
(WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution): Deleted.

Location:
trunk/Tools
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r237784 r237786  
     12018-11-04  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [Cocoa] Fold common UIScriptController functionality on macOS and iOS into UIScriptControllerCocoa.mm
     4        https://bugs.webkit.org/show_bug.cgi?id=191231
     5
     6        Reviewed by Simon Fraser.
     7
     8        Moves some UIScriptController method implementations specific to iOS and macOS into UIScriptControllerCocoa, so
     9        it can be shared between iOS-family and macOS platforms. See below for more details.
     10
     11        No change in behavior.
     12
     13        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
     14        (WTR::UIScriptController::overridePreference):
     15
     16        Add a method stub for DumpRenderTree.
     17
     18        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
     19        * WebKitTestRunner/UIScriptControllerCocoa.mm:
     20        (WTR::UIScriptController::doAsyncTask):
     21        (WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution):
     22
     23        Unify these method implementations.
     24
     25        (WTR::UIScriptController::removeViewFromWindow):
     26        (WTR::UIScriptController::addViewToWindow):
     27
     28        Move the macOS implementation to UIScriptControllerCocoa. On iOS, this method currently only adds the web view
     29        to the window, and does not attempt to invoke the given completion block; additionally, invoking the completion
     30        block after a presentation update (as done on macOS) causes pageoverlay/overlay-remove-reinsert-view.html to
     31        begin failing consistently. This patch does not attempt to change behavior, but adds a FIXME describing this.
     32
     33        (WTR::UIScriptController::overridePreference):
     34        (WTR::UIScriptController::findString):
     35        (WTR::UIScriptController::contentsOfUserInterfaceItem const):
     36
     37        Move these from UIScriptControllerMac to UIScriptControllerCocoa, so that it is now implemented on iOS as well.
     38
     39        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
     40        (WTR::UIScriptController::doAsyncTask): Deleted.
     41        (WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution): Deleted.
     42        (WTR::UIScriptController::contentsOfUserInterfaceItem const): Deleted.
     43        (WTR::UIScriptController::findString): Deleted.
     44        (WTR::UIScriptController::removeViewFromWindow): Deleted.
     45        (WTR::UIScriptController::addViewToWindow): Deleted.
     46        * WebKitTestRunner/mac/UIScriptControllerMac.mm:
     47        (WTR::UIScriptController::doAsyncTask): Deleted.
     48        (WTR::UIScriptController::contentsOfUserInterfaceItem const): Deleted.
     49        (WTR::UIScriptController::overridePreference): Deleted.
     50        (WTR::UIScriptController::findString): Deleted.
     51        (WTR::UIScriptController::removeViewFromWindow): Deleted.
     52        (WTR::UIScriptController::addViewToWindow): Deleted.
     53        (WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution): Deleted.
     54
    1552018-11-04  Eric Carlson  <eric.carlson@apple.com>
    256
  • trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm

    r237328 r237786  
    395395}
    396396
     397void UIScriptController::overridePreference(JSStringRef, JSStringRef)
     398{
     399}
     400
    397401}
    398402
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp

    r237328 r237786  
    513513}
    514514
     515void UIScriptController::overridePreference(JSStringRef, JSStringRef)
     516{
     517}
     518
    515519#endif // !PLATFORM(COCOA)
    516520
    517521#if !PLATFORM(MAC)
    518 
    519 void UIScriptController::overridePreference(JSStringRef, JSStringRef)
    520 {
    521 }
    522522
    523523void UIScriptController::replaceTextAtRange(JSStringRef, int, int)
  • trunk/Tools/WebKitTestRunner/UIScriptControllerCocoa.mm

    r237305 r237786  
    2828
    2929#import "PlatformWebView.h"
     30#import "StringFunctions.h"
    3031#import "TestController.h"
    3132#import "TestRunnerWKWebView.h"
     33#import "UIScriptContext.h"
     34#import <JavaScriptCore/JavaScriptCore.h>
    3235#import <WebKit/WKWebViewPrivate.h>
    3336
     
    5053}
    5154
     55void UIScriptController::doAsyncTask(JSValueRef callback)
     56{
     57    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
     58
     59    dispatch_async(dispatch_get_main_queue(), ^{
     60        if (!m_context)
     61            return;
     62        m_context->asyncTaskComplete(callbackID);
     63    });
     64}
     65
     66void UIScriptController::setShareSheetCompletesImmediatelyWithResolution(bool resolved)
     67{
     68#if WK_API_ENABLED
     69    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
     70    [webView _setShareSheetCompletesImmediatelyWithResolutionForTesting:resolved];
     71#else
     72    UNUSED_PARAM(resolved);
     73#endif
     74}
     75
     76void UIScriptController::removeViewFromWindow(JSValueRef callback)
     77{
     78#if WK_API_ENABLED
     79    // FIXME: On iOS, we never invoke the completion callback that's passed in. Fixing this causes the layout
     80    // test pageoverlay/overlay-remove-reinsert-view.html to start failing consistently on iOS. It seems like
     81    // this warrants some more investigation.
     82#if PLATFORM(MAC)
     83    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
     84#else
     85    UNUSED_PARAM(callback);
     86#endif
     87
     88    auto* mainWebView = TestController::singleton().mainWebView();
     89    mainWebView->removeFromWindow();
     90
     91#if PLATFORM(MAC)
     92    [mainWebView->platformView() _doAfterNextPresentationUpdate:^{
     93        if (!m_context)
     94            return;
     95        m_context->asyncTaskComplete(callbackID);
     96    }];
     97#endif // PLATFORM(MAC)
     98#else
     99    UNUSED_PARAM(callback);
     100#endif
     101}
     102
     103void UIScriptController::addViewToWindow(JSValueRef callback)
     104{
     105#if WK_API_ENABLED
     106#if PLATFORM(MAC)
     107    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
     108#else
     109    UNUSED_PARAM(callback);
     110#endif
     111
     112    auto* mainWebView = TestController::singleton().mainWebView();
     113    mainWebView->addToWindow();
     114
     115#if PLATFORM(MAC)
     116    [mainWebView->platformView() _doAfterNextPresentationUpdate:^{
     117        if (!m_context)
     118            return;
     119        m_context->asyncTaskComplete(callbackID);
     120    }];
     121#endif // PLATFORM(MAC)
     122#else
     123    UNUSED_PARAM(callback);
     124#endif
     125}
     126
     127void UIScriptController::overridePreference(JSStringRef preferenceRef, JSStringRef valueRef)
     128{
     129#if WK_API_ENABLED
     130    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
     131    WKPreferences *preferences = webView.configuration.preferences;
     132
     133    String preference = toWTFString(toWK(preferenceRef));
     134    String value = toWTFString(toWK(valueRef));
     135    if (preference == "WebKitMinimumFontSize")
     136        preferences.minimumFontSize = value.toDouble();
     137#else
     138    UNUSED_PARAM(preferenceRef);
     139    UNUSED_PARAM(valueRef);
     140#endif
     141}
     142
     143void UIScriptController::findString(JSStringRef string, unsigned long options, unsigned long maxCount)
     144{
     145#if WK_API_ENABLED
     146    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
     147    [webView _findString:toWTFString(toWK(string)) options:options maxCount:maxCount];
     148#else
     149    UNUSED_PARAM(string);
     150    UNUSED_PARAM(options);
     151    UNUSED_PARAM(maxCount);
     152#endif
     153}
     154
     155JSObjectRef UIScriptController::contentsOfUserInterfaceItem(JSStringRef interfaceItem) const
     156{
     157#if WK_API_ENABLED
     158    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
     159    NSDictionary *contentDictionary = [webView _contentsOfUserInterfaceItem:toWTFString(toWK(interfaceItem))];
     160    return JSValueToObject(m_context->jsContext(), [JSValue valueWithObject:contentDictionary inContext:[JSContext contextWithJSGlobalContextRef:m_context->jsContext()]].JSValueRef, nullptr);
     161#else
     162    UNUSED_PARAM(interfaceItem);
     163    return nullptr;
     164#endif
     165}
     166
    52167} // namespace WTR
  • trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

    r237328 r237786  
    6161}
    6262
    63 void UIScriptController::doAsyncTask(JSValueRef callback)
    64 {
    65     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    66 
    67     dispatch_async(dispatch_get_main_queue(), ^{
    68         if (!m_context)
    69             return;
    70         m_context->asyncTaskComplete(callbackID);
    71     });
    72 }
    73 
    7463void UIScriptController::doAfterPresentationUpdate(JSValueRef callback)
    7564{
     
    411400}
    412401
    413 void UIScriptController::setShareSheetCompletesImmediatelyWithResolution(bool resolved)
    414 {
    415     TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
    416     [webView _setShareSheetCompletesImmediatelyWithResolutionForTesting:resolved];
    417 }
    418    
    419 JSObjectRef UIScriptController::contentsOfUserInterfaceItem(JSStringRef interfaceItem) const
    420 {
    421     TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
    422     NSDictionary *contentDictionary = [webView _contentsOfUserInterfaceItem:toWTFString(toWK(interfaceItem))];
    423     return JSValueToObject(m_context->jsContext(), [JSValue valueWithObject:contentDictionary inContext:[JSContext contextWithJSGlobalContextRef:m_context->jsContext()]].JSValueRef, nullptr);
    424 }
    425 
    426402static CGPoint contentOffsetBoundedInValidRange(UIScrollView *scrollView, CGPoint contentOffset)
    427403{
     
    638614}
    639615
    640 void UIScriptController::findString(JSStringRef string, unsigned long options, unsigned long maxCount)
    641 {
    642     TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
    643     [webView _findString:toWTFString(toWK(string)) options:options maxCount:maxCount];
    644 }
    645 
    646 void UIScriptController::removeViewFromWindow(JSValueRef callback)
    647 {
    648     TestController::singleton().mainWebView()->removeFromWindow();
    649 }
    650 
    651 void UIScriptController::addViewToWindow(JSValueRef callback)
    652 {
    653     TestController::singleton().mainWebView()->addToWindow();
    654 }
    655 
    656616void UIScriptController::platformSetDidStartFormControlInteractionCallback()
    657617{
  • trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm

    r237012 r237786  
    4848{
    4949    return CFBridgingRelease(JSStringCopyCFString(kCFAllocatorDefault, string));
    50 }
    51 
    52 void UIScriptController::doAsyncTask(JSValueRef callback)
    53 {
    54     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    55 
    56     dispatch_async(dispatch_get_main_queue(), ^{
    57         if (!m_context)
    58             return;
    59         m_context->asyncTaskComplete(callbackID);
    60     });
    6150}
    6251
     
    126115}
    127116
    128 JSObjectRef UIScriptController::contentsOfUserInterfaceItem(JSStringRef interfaceItem) const
    129 {
    130 #if WK_API_ENABLED
    131     TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
    132     NSDictionary *contentDictionary = [webView _contentsOfUserInterfaceItem:toWTFString(toWK(interfaceItem))];
    133     return JSValueToObject(m_context->jsContext(), [JSValue valueWithObject:contentDictionary inContext:[JSContext contextWithJSGlobalContextRef:m_context->jsContext()]].JSValueRef, nullptr);
    134 #else
    135     UNUSED_PARAM(interfaceItem);
    136     return nullptr;
    137 #endif
    138 }
    139 
    140 void UIScriptController::overridePreference(JSStringRef preferenceRef, JSStringRef valueRef)
    141 {
    142 #if WK_API_ENABLED
    143     TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
    144     WKPreferences *preferences = webView.configuration.preferences;
    145 
    146     String preference = toWTFString(toWK(preferenceRef));
    147     String value = toWTFString(toWK(valueRef));
    148     if (preference == "WebKitMinimumFontSize")
    149         preferences.minimumFontSize = value.toDouble();
    150 #else
    151     UNUSED_PARAM(preferenceRef);
    152     UNUSED_PARAM(valueRef);
    153 #endif
    154 }
    155 
    156117void UIScriptController::simulateRotation(DeviceOrientation*, JSValueRef)
    157118{
     
    159120
    160121void UIScriptController::simulateRotationLikeSafari(DeviceOrientation*, JSValueRef)
    161 {
    162 }
    163 
    164 void UIScriptController::findString(JSStringRef, unsigned long options, unsigned long maxCount)
    165122{
    166123}
     
    176133#endif
    177134    return false;
    178 }
    179 
    180 void UIScriptController::removeViewFromWindow(JSValueRef callback)
    181 {
    182 #if WK_API_ENABLED
    183     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    184 
    185     auto* mainWebView = TestController::singleton().mainWebView();
    186     mainWebView->removeFromWindow();
    187 
    188     [mainWebView->platformView() _doAfterNextPresentationUpdate: ^ {
    189         if (!m_context)
    190             return;
    191         m_context->asyncTaskComplete(callbackID);
    192     }];
    193 #else
    194     UNUSED_PARAM(callback);
    195 #endif
    196 }
    197 
    198 void UIScriptController::addViewToWindow(JSValueRef callback)
    199 {
    200 #if WK_API_ENABLED
    201     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    202 
    203     auto* mainWebView = TestController::singleton().mainWebView();
    204     mainWebView->addToWindow();
    205 
    206     [mainWebView->platformView() _doAfterNextPresentationUpdate: ^ {
    207         if (!m_context)
    208             return;
    209         m_context->asyncTaskComplete(callbackID);
    210     }];
    211 #else
    212     UNUSED_PARAM(callback);
    213 #endif
    214135}
    215136
     
    271192}
    272193
    273 void UIScriptController::setShareSheetCompletesImmediatelyWithResolution(bool resolved)
    274 {
    275 #if WK_API_ENABLED
    276     TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
    277     [webView _setShareSheetCompletesImmediatelyWithResolutionForTesting:resolved];
    278 #else
    279     UNUSED_PARAM(resolved);
    280 #endif
    281 }
    282 
    283194} // namespace WTR
Note: See TracChangeset for help on using the changeset viewer.