⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243533 in webkit


Ignore:
Timestamp:
Mar 27, 2019, 2:36:29 AM (7 years ago)
Author:
Carlos Garcia Campos
Message:

Geolocation request not complete when watch request was started in a different web process
https://bugs.webkit.org/show_bug.cgi?id=195996

Reviewed by Alex Christensen.

Source/WebKit:

In WebGeolocationManagerProxy::startUpdating() we do nothing when the provider is already updating. We should
reply with a DidChangePosition using the last known position, if available. If we are updating, but we still
don't have a known position, the request will be completed when
WebGeolocationManagerProxy::providerDidChangePosition() is called since it always notifies all web
processes.

  • UIProcess/WebGeolocationManagerProxy.cpp:

(WebKit::WebGeolocationManagerProxy::providerDidChangePosition): Cache the position.
(WebKit::WebGeolocationManagerProxy::startUpdating): Reply using cached position if already known.

  • UIProcess/WebGeolocationManagerProxy.h:

(WebKit::WebGeolocationManagerProxy::lastPosition const): Return cached position.

  • WebProcess/WebCoreSupport/WebGeolocationClient.cpp:

(WebKit::WebGeolocationClient::lastPosition): Remove the FIXME since we don't want this feature.

Tools:

Add a test case.

  • TestWebKitAPI/Tests/WebKit/Geolocation.cpp:

(TestWebKitAPI::runJavaScriptAlert):
(TestWebKitAPI::TEST):

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r243531 r243533  
     12019-03-27  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Geolocation request not complete when watch request was started in a different web process
     4        https://bugs.webkit.org/show_bug.cgi?id=195996
     5
     6        Reviewed by Alex Christensen.
     7
     8        In WebGeolocationManagerProxy::startUpdating() we do nothing when the provider is already updating. We should
     9        reply with a DidChangePosition using the last known position, if available. If we are updating, but we still
     10        don't have a known position, the request will be completed when
     11        WebGeolocationManagerProxy::providerDidChangePosition() is called since it always notifies all web
     12        processes.
     13
     14        * UIProcess/WebGeolocationManagerProxy.cpp:
     15        (WebKit::WebGeolocationManagerProxy::providerDidChangePosition): Cache the position.
     16        (WebKit::WebGeolocationManagerProxy::startUpdating): Reply using cached position if already known.
     17        * UIProcess/WebGeolocationManagerProxy.h:
     18        (WebKit::WebGeolocationManagerProxy::lastPosition const): Return cached position.
     19        * WebProcess/WebCoreSupport/WebGeolocationClient.cpp:
     20        (WebKit::WebGeolocationClient::lastPosition): Remove the FIXME since we don't want this feature.
     21
    1222019-03-26  Brent Fulgham  <bfulgham@apple.com>
    223
  • trunk/Source/WebKit/UIProcess/WebGeolocationManagerProxy.cpp

    r237266 r243533  
    8989void WebGeolocationManagerProxy::providerDidChangePosition(WebGeolocationPosition* position)
    9090{
     91    m_lastPosition = position->corePosition();
     92
    9193    if (!processPool())
    9294        return;
    9395
    94     processPool()->sendToAllProcesses(Messages::WebGeolocationManager::DidChangePosition(position->corePosition()));
     96    processPool()->sendToAllProcesses(Messages::WebGeolocationManager::DidChangePosition(m_lastPosition.value()));
    9597}
    9698
     
    117119        m_provider->setEnableHighAccuracy(*this, isHighAccuracyEnabled());
    118120        m_provider->startUpdating(*this);
    119     }
     121    } else if (m_lastPosition)
     122        connection.send(Messages::WebGeolocationManager::DidChangePosition(m_lastPosition.value()), 0);
    120123}
    121124
  • trunk/Source/WebKit/UIProcess/WebGeolocationManagerProxy.h

    r237266 r243533  
    3030#include "MessageReceiver.h"
    3131#include "WebContextSupplement.h"
     32#include <WebCore/GeolocationPosition.h>
    3233#include <wtf/HashSet.h>
    3334#include <wtf/text/WTFString.h>
     
    5556    void resetPermissions();
    5657#endif
     58    const Optional<WebCore::GeolocationPosition>& lastPosition() const { return m_lastPosition; }
    5759
    5860    using API::Object::ref;
     
    8385
    8486    std::unique_ptr<API::GeolocationProvider> m_provider;
     87    Optional<WebCore::GeolocationPosition> m_lastPosition;
    8588};
    8689
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebGeolocationClient.cpp

    r239427 r243533  
    6666Optional<GeolocationPosition> WebGeolocationClient::lastPosition()
    6767{
    68     // FIXME: Implement this.
    6968    return WTF::nullopt;
    7069}
  • trunk/Tools/ChangeLog

    r243527 r243533  
     12019-03-27  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Geolocation request not complete when watch request was started in a different web process
     4        https://bugs.webkit.org/show_bug.cgi?id=195996
     5
     6        Reviewed by Alex Christensen.
     7
     8        Add a test case.
     9
     10        * TestWebKitAPI/Tests/WebKit/Geolocation.cpp:
     11        (TestWebKitAPI::runJavaScriptAlert):
     12        (TestWebKitAPI::TEST):
     13
    1142019-03-26  Keith Rollin  <krollin@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKit/Geolocation.cpp

    r239631 r243533  
    316316};
    317317
     318struct JavaScriptAlertContext {
     319    bool didRun { false };
     320    std::string alertText;
     321};
     322
    318323static void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo)
    319324{
    320     *static_cast<bool*>(const_cast<void*>(clientInfo)) = true;
     325    auto* context = static_cast<JavaScriptAlertContext*>(const_cast<void*>(clientInfo));
     326    context->didRun = true;
     327    context->alertText = Util::toSTD(alertText);
    321328}
    322329
     
    337344    setupView(lowAccuracyWebView);
    338345
    339     bool finishedSecondStep = false;
     346    JavaScriptAlertContext secondStepContext;
    340347
    341348    WKPageUIClientV2 uiClient;
    342349    memset(&uiClient, 0, sizeof(uiClient));
    343350    uiClient.base.version = 2;
    344     uiClient.base.clientInfo = &finishedSecondStep;
     351    uiClient.base.clientInfo = &secondStepContext;
    345352    uiClient.decidePolicyForGeolocationPermissionRequest = decidePolicyForGeolocationPermissionRequestCallBack;
    346353    uiClient.runJavaScriptAlert = runJavaScriptAlert;
     
    349356    WKRetainPtr<WKURLRef> lowAccuracyURL(AdoptWK, Util::createURLForResource("geolocationWatchPosition", "html"));
    350357    WKPageLoadURL(lowAccuracyWebView.page(), lowAccuracyURL.get());
    351     Util::run(&finishedSecondStep);
     358    Util::run(&secondStepContext.didRun);
     359    EXPECT_EQ(secondStepContext.alertText, "SUCCESS");
    352360
    353361    WKRetainPtr<WKURLRef> resetUrl = adoptWK(WKURLCreateWithUTF8CString("about:blank"));
     
    362370}
    363371
     372TEST(WebKit, GeolocationWatchMultiprocess)
     373{
     374    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreateWithConfiguration(nullptr));
     375
     376    GeolocationStateTracker stateTracker;
     377    setupGeolocationProvider(context.get(), &stateTracker);
     378
     379    JavaScriptAlertContext testContext;
     380
     381    WKPageUIClientV2 uiClient;
     382    memset(&uiClient, 0, sizeof(uiClient));
     383    uiClient.base.version = 2;
     384    uiClient.base.clientInfo = &testContext;
     385    uiClient.decidePolicyForGeolocationPermissionRequest = decidePolicyForGeolocationPermissionRequestCallBack;
     386    uiClient.runJavaScriptAlert = runJavaScriptAlert;
     387
     388    PlatformWebView view1(context.get());
     389    WKPageSetPageUIClient(view1.page(), &uiClient.base);
     390    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("geolocationWatchPosition", "html"));
     391    WKPageLoadURL(view1.page(), url.get());
     392    Util::run(&testContext.didRun);
     393    EXPECT_EQ(testContext.alertText, "SUCCESS");
     394    WKPageSetPageUIClient(view1.page(), nullptr);
     395
     396    testContext.didRun = false;
     397    testContext.alertText = { };
     398
     399    PlatformWebView view2(context.get());
     400    WKPageSetPageUIClient(view2.page(), &uiClient.base);
     401    WKPageLoadURL(view2.page(), url.get());
     402    Util::run(&testContext.didRun);
     403    EXPECT_EQ(testContext.alertText, "SUCCESS");
     404
     405    clearGeolocationProvider(context.get());
     406}
     407
    364408} // namespace TestWebKitAPI
    365409
Note: See TracChangeset for help on using the changeset viewer.