2010-12-02 John Knottenbelt <jknotten@chromium.org>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Dec 2010 18:59:07 +0000 (18:59 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Dec 2010 18:59:07 +0000 (18:59 +0000)
        Reviewed by Steve Block.

        Move requestGeolocationPermissionForFrame to GeolocationClient
        https://bugs.webkit.org/show_bug.cgi?id=50061

        This change facilitates client-based geolocation implementation by
        bringing together permission control into the geolocation client
        interface.

        * page/Chrome.h:
        * page/ChromeClient.h:
        * page/Geolocation.cpp:
        (WebCore::Geolocation::disconnectFrame):
        (WebCore::Geolocation::requestPermission):
        * page/GeolocationClient.h:
        * page/GeolocationController.cpp:
        (WebCore::GeolocationController::requestPermission):
        (WebCore::GeolocationController::cancelPermissionRequest):
        * page/GeolocationController.h:
        * platform/mock/GeolocationClientMock.cpp:
        (WebCore::GeolocationClientMock::GeolocationClientMock):
        (WebCore::GeolocationClientMock::setPermission):
        (WebCore::GeolocationClientMock::requestPermission):
        (WebCore::GeolocationClientMock::cancelPermissionRequest):
        (WebCore::GeolocationClientMock::asyncUpdatePermission):
        (WebCore::GeolocationClientMock::permissionTimerFired):
        (WebCore::GeolocationClientMock::reset):
        (WebCore::GeolocationClientMock::stopUpdating):
        (WebCore::GeolocationClientMock::asyncUpdateController):
        (WebCore::GeolocationClientMock::controllerTimerFired):
        * platform/mock/GeolocationClientMock.h:
2010-12-02  John Knottenbelt  <jknotten@chromium.org>

        Reviewed by Steve Block.

        Move requestGeolocationPermissionForFrame to GeolocationClient
        https://bugs.webkit.org/show_bug.cgi?id=50061

        This change facilitates client-based geolocation implementation by
        bringing together permission control into the geolocation client
        interface.

        Move method ChromeClient::requestGeolocationPermissionForFrame to
        GeolocationClient::requestPermission, and supporting class
        WebGeolocationPolicyListener. The moved code is unchanged except
        that requestPermission now takes only one argument (Geolocation*)
        and the Frame parameter is retrieved from the Geolocation object.

        * WebCoreSupport/WebChromeClient.h:
        * WebCoreSupport/WebChromeClient.mm:
        * WebCoreSupport/WebGeolocationClient.h:
        (WebGeolocationClient::cancelPermissionRequest):
        * WebCoreSupport/WebGeolocationClient.mm:
        (WebGeolocationClient::requestPermission):
        (-[WebGeolocationPolicyListener initWithGeolocation:]):
        (-[WebGeolocationPolicyListener allow]):
        (-[WebGeolocationPolicyListener deny]):
2010-12-02  John Knottenbelt  <jknotten@chromium.org>

        Reviewed by Steve Block.

        Move requestGeolocationPermissionForFrame to GeolocationClient
        https://bugs.webkit.org/show_bug.cgi?id=50061

        This change facilitates client-based geolocation implementation by
        bringing together permission control into the geolocation client
        interface.

        Move method ChromeClient::requestGeolocationPermissionForFrame to
        GeolocationClient::requestPermission. The moved code is unchanged
        except that requestPermission now takes only one argument (Geolocation*),
        the Frame parameter is retrieved from the Geolocation object and we need to
        call m_webView.get() as it is a COMPtr in GeolocationClient.

        * WebCoreSupport/WebChromeClient.cpp:
        * WebCoreSupport/WebChromeClient.h:
        * WebCoreSupport/WebGeolocationClient.cpp:
        (WebGeolocationClient::requestPermission):
        * WebCoreSupport/WebGeolocationClient.h:
        (WebGeolocationClient::cancelPermissionRequest):

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

19 files changed:
WebCore/ChangeLog
WebCore/page/Chrome.h
WebCore/page/ChromeClient.h
WebCore/page/Geolocation.cpp
WebCore/page/GeolocationClient.h
WebCore/page/GeolocationController.cpp
WebCore/page/GeolocationController.h
WebCore/platform/mock/GeolocationClientMock.cpp
WebCore/platform/mock/GeolocationClientMock.h
WebKit/mac/ChangeLog
WebKit/mac/WebCoreSupport/WebChromeClient.h
WebKit/mac/WebCoreSupport/WebChromeClient.mm
WebKit/mac/WebCoreSupport/WebGeolocationClient.h
WebKit/mac/WebCoreSupport/WebGeolocationClient.mm
WebKit/win/ChangeLog
WebKit/win/WebCoreSupport/WebChromeClient.cpp
WebKit/win/WebCoreSupport/WebChromeClient.h
WebKit/win/WebCoreSupport/WebGeolocationClient.cpp
WebKit/win/WebCoreSupport/WebGeolocationClient.h

index 95c0852..3adf279 100644 (file)
@@ -1,3 +1,37 @@
+2010-12-02  John Knottenbelt  <jknotten@chromium.org>
+
+        Reviewed by Steve Block.
+
+        Move requestGeolocationPermissionForFrame to GeolocationClient
+        https://bugs.webkit.org/show_bug.cgi?id=50061
+
+        This change facilitates client-based geolocation implementation by
+        bringing together permission control into the geolocation client
+        interface.
+
+        * page/Chrome.h:
+        * page/ChromeClient.h:
+        * page/Geolocation.cpp:
+        (WebCore::Geolocation::disconnectFrame):
+        (WebCore::Geolocation::requestPermission):
+        * page/GeolocationClient.h:
+        * page/GeolocationController.cpp:
+        (WebCore::GeolocationController::requestPermission):
+        (WebCore::GeolocationController::cancelPermissionRequest):
+        * page/GeolocationController.h:
+        * platform/mock/GeolocationClientMock.cpp:
+        (WebCore::GeolocationClientMock::GeolocationClientMock):
+        (WebCore::GeolocationClientMock::setPermission):
+        (WebCore::GeolocationClientMock::requestPermission):
+        (WebCore::GeolocationClientMock::cancelPermissionRequest):
+        (WebCore::GeolocationClientMock::asyncUpdatePermission):
+        (WebCore::GeolocationClientMock::permissionTimerFired):
+        (WebCore::GeolocationClientMock::reset):
+        (WebCore::GeolocationClientMock::stopUpdating):
+        (WebCore::GeolocationClientMock::asyncUpdateController):
+        (WebCore::GeolocationClientMock::controllerTimerFired):
+        * platform/mock/GeolocationClientMock.h:
+
 2010-12-01  Ilya Tikhonovsky  <loislo@chromium.org>
 
         Reviewed by Pavel Feldman.
index f2c5db4..c9862ad 100644 (file)
@@ -139,6 +139,8 @@ namespace WebCore {
 
         void print(Frame*);
 
+        // FIXME: Remove once all ports are using client-based geolocation. https://bugs.webkit.org/show_bug.cgi?id=40373
+        // For client-based geolocation, these two methods have moved to GeolocationClient. https://bugs.webkit.org/show_bug.cgi?id=50061
         void requestGeolocationPermissionForFrame(Frame*, Geolocation*);
         void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*);
 
index 8a06a8d..d013d1c 100644 (file)
@@ -206,11 +206,13 @@ namespace WebCore {
                                           float value, float proportion, ScrollbarControlPartMask);
         virtual bool paintCustomScrollCorner(GraphicsContext*, const FloatRect&);
 
+        // FIXME: Remove once all ports are using client-based geolocation. https://bugs.webkit.org/show_bug.cgi?id=40373
+        // For client-based geolocation, these two methods have moved to GeolocationClient. https://bugs.webkit.org/show_bug.cgi?id=50061
         // This can be either a synchronous or asynchronous call. The ChromeClient can display UI asking the user for permission
         // to use Geolocation.
         virtual void requestGeolocationPermissionForFrame(Frame*, Geolocation*) = 0;
         virtual void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*) = 0;
-            
+
         virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) = 0;
         // Asynchronous request to load an icon for specified filenames.
         virtual void chooseIconForFiles(const Vector<String>&, FileChooser*) = 0;
index 9135049..9c6f6d1 100644 (file)
@@ -233,8 +233,13 @@ Geolocation::~Geolocation()
 
 void Geolocation::disconnectFrame()
 {
-    if (m_frame && m_frame->page() && m_allowGeolocation == InProgress)
+    if (m_frame && m_frame->page() && m_allowGeolocation == InProgress) {
+#if ENABLE(CLIENT_BASED_GEOLOCATION)
+        m_frame->page()->geolocationController()->cancelPermissionRequest(this);
+#else
         m_frame->page()->chrome()->cancelGeolocationPermissionRequestForFrame(m_frame, this);
+#endif
+    }
     cancelAllRequests();
     stopUpdating();
     if (m_frame && m_frame->document())
@@ -596,8 +601,12 @@ void Geolocation::requestPermission()
 
     m_allowGeolocation = InProgress;
 
-    // Ask the chrome: it maintains the geolocation challenge policy itself.
+    // Ask the embedder: it maintains the geolocation challenge policy itself.
+#if ENABLE(CLIENT_BASED_GEOLOCATION)
+    page->geolocationController()->requestPermission(this);
+#else
     page->chrome()->requestGeolocationPermissionForFrame(m_frame, this);
+#endif
 }
 
 void Geolocation::positionChangedInternal()
index c646f91..44cb909 100644 (file)
@@ -28,6 +28,7 @@
 
 namespace WebCore {
 
+class Geolocation;
 class GeolocationPosition;
 
 class GeolocationClient {
@@ -43,6 +44,9 @@ public:
     virtual void setEnableHighAccuracy(bool) = 0;
     virtual GeolocationPosition* lastPosition() = 0;
 
+    virtual void requestPermission(Geolocation*) = 0;
+    virtual void cancelPermissionRequest(Geolocation*) = 0;
+
 protected:
     virtual ~GeolocationClient() { }
 };
index db4cc23..28d522d 100644 (file)
@@ -78,6 +78,18 @@ void GeolocationController::removeObserver(Geolocation* observer)
     }
 }
 
+void GeolocationController::requestPermission(Geolocation* geolocation)
+{
+    if (m_client)
+        m_client->requestPermission(geolocation);
+}
+
+void GeolocationController::cancelPermissionRequest(Geolocation* geolocation)
+{
+    if (m_client)
+        m_client->cancelPermissionRequest(geolocation);
+}
+
 void GeolocationController::positionChanged(GeolocationPosition* position)
 {
     m_lastPosition = position;
index 2d8106d..7db1951 100644 (file)
@@ -48,6 +48,9 @@ public:
     void addObserver(Geolocation*, bool enableHighAccuracy);
     void removeObserver(Geolocation*);
 
+    void requestPermission(Geolocation*);
+    void cancelPermissionRequest(Geolocation*);
+
     void positionChanged(GeolocationPosition*);
     void errorOccurred(GeolocationError*);
 
index 3c4697f..5255b34 100644 (file)
@@ -41,8 +41,10 @@ namespace WebCore {
 
 GeolocationClientMock::GeolocationClientMock()
     : m_controller(0)
-    , m_timer(this, &GeolocationClientMock::timerFired)
+    , m_controllerTimer(this, &GeolocationClientMock::controllerTimerFired)
+    , m_permissionTimer(this, &GeolocationClientMock::permissionTimerFired)
     , m_isActive(false)
+    , m_permissionState(PermissionStateUnset)
 {
 }
 
@@ -71,10 +73,55 @@ void GeolocationClientMock::setError(PassRefPtr<GeolocationError> error)
     asyncUpdateController();
 }
 
+void GeolocationClientMock::setPermission(bool allowed)
+{
+    m_permissionState = allowed ? PermissionStateAllowed : PermissionStateDenied;
+    asyncUpdatePermission();
+}
+
+void GeolocationClientMock::requestPermission(Geolocation* geolocation)
+{
+    m_pendingPermission.add(geolocation);
+    if (m_permissionState != PermissionStateUnset)
+        asyncUpdatePermission();
+}
+
+void GeolocationClientMock::cancelPermissionRequest(Geolocation* geolocation)
+{
+    // Called from Geolocation::disconnectFrame() in response to Frame destruction.
+    m_pendingPermission.remove(geolocation);
+    if (m_pendingPermission.isEmpty() && m_permissionTimer.isActive())
+        m_permissionTimer.stop();
+}
+
+void GeolocationClientMock::asyncUpdatePermission()
+{
+    ASSERT(m_permissionState != PermissionStateUnset);
+    if (!m_permissionTimer.isActive())
+        m_permissionTimer.startOneShot(0);
+}
+
+void GeolocationClientMock::permissionTimerFired(WebCore::Timer<GeolocationClientMock>* timer)
+{
+    ASSERT_UNUSED(timer, timer == &m_permissionTimer);
+    ASSERT(m_permissionState != PermissionStateUnset);
+    bool allowed = m_permissionState == PermissionStateAllowed;
+    GeolocationSet::iterator end = m_pendingPermission.end();
+
+    // Once permission has been set (or denied) on a Geolocation object, there can be
+    // no further requests for permission to the mock. Consequently the callbacks
+    // which fire synchronously from Geolocation::setIsAllowed() cannot reentrantly modify
+    // m_pendingPermission.
+    for (GeolocationSet::iterator it = m_pendingPermission.begin(); it != end; ++it)
+        (*it)->setIsAllowed(allowed);
+    m_pendingPermission.clear();
+}
+
 void GeolocationClientMock::reset()
 {
     m_lastPosition = 0;
     m_lastError = 0;
+    m_permissionState = PermissionStateUnset;
 }
 
 void GeolocationClientMock::geolocationDestroyed()
@@ -93,7 +140,7 @@ void GeolocationClientMock::stopUpdating()
 {
     ASSERT(m_isActive);
     m_isActive = false;
-    m_timer.stop();
+    m_controllerTimer.stop();
 }
 
 void GeolocationClientMock::setEnableHighAccuracy(bool)
@@ -110,18 +157,13 @@ GeolocationPosition* GeolocationClientMock::lastPosition()
 void GeolocationClientMock::asyncUpdateController()
 {
     ASSERT(m_controller);
-    if (m_isActive && !m_timer.isActive())
-        m_timer.startOneShot(0);
-}
-
-void GeolocationClientMock::timerFired(Timer<GeolocationClientMock>* timer)
-{
-    ASSERT_UNUSED(timer, timer == &m_timer);
-    updateController();
+    if (m_isActive && !m_controllerTimer.isActive())
+        m_controllerTimer.startOneShot(0);
 }
 
-void GeolocationClientMock::updateController()
+void GeolocationClientMock::controllerTimerFired(Timer<GeolocationClientMock>* timer)
 {
+    ASSERT_UNUSED(timer, timer == &m_controllerTimer);
     ASSERT(m_controller);
 
     if (m_lastPosition.get())
index f57afa9..df35316 100644 (file)
@@ -37,6 +37,7 @@
 #include "PlatformString.h"
 #include "Timer.h"
 
+#include <wtf/HashSet.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
 
@@ -57,6 +58,7 @@ public:
 
     void setError(PassRefPtr<GeolocationError>);
     void setPosition(PassRefPtr<GeolocationPosition>);
+    void setPermission(bool allowed);
 
     // GeolocationClient
     virtual void geolocationDestroyed();
@@ -64,17 +66,30 @@ public:
     virtual void stopUpdating();
     virtual void setEnableHighAccuracy(bool);
     virtual GeolocationPosition* lastPosition();
+    virtual void requestPermission(Geolocation*);
+    virtual void cancelPermissionRequest(Geolocation*);
 
 private:
-    void timerFired(Timer<GeolocationClientMock>*);
     void asyncUpdateController();
-    void updateController();
+    void controllerTimerFired(Timer<GeolocationClientMock>*);
+
+    void asyncUpdatePermission();
+    void permissionTimerFired(Timer<GeolocationClientMock>*);
 
     GeolocationController* m_controller;
     RefPtr<GeolocationPosition> m_lastPosition;
     RefPtr<GeolocationError> m_lastError;
-    Timer<GeolocationClientMock> m_timer;
+    Timer<GeolocationClientMock> m_controllerTimer;
+    Timer<GeolocationClientMock> m_permissionTimer;
     bool m_isActive;
+
+    enum PermissionState {
+        PermissionStateUnset,
+        PermissionStateAllowed,
+        PermissionStateDenied,
+    } m_permissionState;
+    typedef WTF::HashSet<RefPtr<Geolocation> > GeolocationSet;
+    GeolocationSet m_pendingPermission;
 };
 
 }
index 9de2e2d..edc0e61 100644 (file)
@@ -1,3 +1,30 @@
+2010-12-02  John Knottenbelt  <jknotten@chromium.org>
+
+        Reviewed by Steve Block.
+
+        Move requestGeolocationPermissionForFrame to GeolocationClient
+        https://bugs.webkit.org/show_bug.cgi?id=50061
+
+        This change facilitates client-based geolocation implementation by
+        bringing together permission control into the geolocation client
+        interface.
+
+        Move method ChromeClient::requestGeolocationPermissionForFrame to
+        GeolocationClient::requestPermission, and supporting class
+        WebGeolocationPolicyListener. The moved code is unchanged except
+        that requestPermission now takes only one argument (Geolocation*)
+        and the Frame parameter is retrieved from the Geolocation object.
+
+        * WebCoreSupport/WebChromeClient.h:
+        * WebCoreSupport/WebChromeClient.mm:
+        * WebCoreSupport/WebGeolocationClient.h:
+        (WebGeolocationClient::cancelPermissionRequest):
+        * WebCoreSupport/WebGeolocationClient.mm:
+        (WebGeolocationClient::requestPermission):
+        (-[WebGeolocationPolicyListener initWithGeolocation:]):
+        (-[WebGeolocationPolicyListener allow]):
+        (-[WebGeolocationPolicyListener deny]):
+
 2010-12-02  Joseph Pecoraro  <joepeck@webkit.org>
 
         Reviewed by Eric Carlson.
index a5f49e3..8649662 100644 (file)
@@ -172,7 +172,9 @@ public:
     virtual void exitFullScreenForElement(WebCore::Element*);
 #endif
 
-    virtual void requestGeolocationPermissionForFrame(WebCore::Frame*, WebCore::Geolocation*);
+    // FIXME: Remove once all ports are using client-based geolocation. https://bugs.webkit.org/show_bug.cgi?id=40373
+    // For client-based geolocation, these two methods have moved to WebGeolocationClient. https://bugs.webkit.org/show_bug.cgi?id=50061
+    virtual void requestGeolocationPermissionForFrame(WebCore::Frame*, WebCore::Geolocation*) { }
     virtual void cancelGeolocationPermissionRequestForFrame(WebCore::Frame*, WebCore::Geolocation*) { }
 
     virtual bool selectItemWritingDirectionIsNatural();
index fe95989..48ccdab 100644 (file)
@@ -55,7 +55,6 @@
 #import <WebCore/FloatRect.h>
 #import <WebCore/Frame.h>
 #import <WebCore/FrameLoadRequest.h>
-#import <WebCore/Geolocation.h>
 #import <WebCore/HTMLNames.h>
 #import <WebCore/HitTestResult.h>
 #import <WebCore/Icon.h>
@@ -102,13 +101,6 @@ using namespace WebCore;
 - (id)initWithChooser:(PassRefPtr<FileChooser>)chooser;
 @end
 
-@interface WebGeolocationPolicyListener : NSObject <WebGeolocationPolicyListener>
-{
-    RefPtr<Geolocation> _geolocation;
-}
-- (id)initWithGeolocation:(Geolocation*)geolocation;
-@end
-
 #if ENABLE(FULLSCREEN_API)
 
 @interface WebKitFullScreenListener : NSObject <WebKitFullScreenListener>
@@ -849,27 +841,6 @@ void WebChromeClient::exitFullScreenForElement(Element* element)
 
 #endif
 
-void WebChromeClient::requestGeolocationPermissionForFrame(Frame* frame, Geolocation* geolocation)
-{
-    BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
-    SEL selector = @selector(webView:decidePolicyForGeolocationRequestFromOrigin:frame:listener:);
-    if (![[m_webView UIDelegate] respondsToSelector:selector]) {
-        geolocation->setIsAllowed(false);
-        return;
-    }
-
-    WebSecurityOrigin *webOrigin = [[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:frame->document()->securityOrigin()];
-    WebGeolocationPolicyListener* listener = [[WebGeolocationPolicyListener alloc] initWithGeolocation:geolocation];
-
-    CallUIDelegate(m_webView, selector, webOrigin, kit(frame), listener);
-
-    [webOrigin release];
-    [listener release];
-
-    END_BLOCK_OBJC_EXCEPTIONS;
-}
-
 @implementation WebOpenPanelResultListener
 
 - (id)initWithChooser:(PassRefPtr<FileChooser>)chooser
@@ -932,28 +903,6 @@ void WebChromeClient::requestGeolocationPermissionForFrame(Frame* frame, Geoloca
 
 @end
 
-@implementation WebGeolocationPolicyListener
-
-- (id)initWithGeolocation:(Geolocation*)geolocation
-{
-    if (!(self = [super init]))
-        return nil;
-    _geolocation = geolocation;
-    return self;
-}
-
-- (void)allow
-{
-    _geolocation->setIsAllowed(true);
-}
-
-- (void)deny
-{
-    _geolocation->setIsAllowed(false);
-}
-
-@end
-
 #if ENABLE(FULLSCREEN_API)
 
 @implementation WebKitFullScreenListener
index 5ea3369..b8e7b87 100644 (file)
@@ -26,7 +26,8 @@
 #import <WebCore/GeolocationClient.h>
 
 namespace WebCore {
-    class GeolocationPosition;
+class Geolocation;
+class GeolocationPosition;
 }
 
 @class WebView;
@@ -43,6 +44,9 @@ public:
 
     WebCore::GeolocationPosition* lastPosition();
 
+    void requestPermission(WebCore::Geolocation*);
+    void cancelPermissionRequest(WebCore::Geolocation*) { };
+
 private:
     WebView *m_webView;
 };
index a635b44..b52b7bc 100644 (file)
 
 #import "WebGeolocationClient.h"
 
+#import "WebDelegateImplementationCaching.h"
+#import "WebFrameInternal.h"
 #import "WebGeolocationPositionInternal.h"
+#import "WebSecurityOriginInternal.h"
+#import "WebUIDelegatePrivate.h"
 #import "WebViewInternal.h"
+#import <WebCore/BlockExceptions.h>
+#import <WebCore/Frame.h>
+#import <WebCore/Geolocation.h>
 
 using namespace WebCore;
 
+@interface WebGeolocationPolicyListener : NSObject <WebGeolocationPolicyListener>
+{
+    RefPtr<Geolocation> _geolocation;
+}
+- (id)initWithGeolocation:(Geolocation*)geolocation;
+@end
+
 WebGeolocationClient::WebGeolocationClient(WebView *webView)
     : m_webView(webView)
 {
@@ -50,6 +64,28 @@ void WebGeolocationClient::stopUpdating()
     [[m_webView _geolocationProvider] unregisterWebView:m_webView];
 }
 
+void WebGeolocationClient::requestPermission(Geolocation* geolocation)
+{
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+    SEL selector = @selector(webView:decidePolicyForGeolocationRequestFromOrigin:frame:listener:);
+    if (![[m_webView UIDelegate] respondsToSelector:selector]) {
+        geolocation->setIsAllowed(false);
+        return;
+    }
+
+    Frame *frame = geolocation->frame();
+    WebSecurityOrigin *webOrigin = [[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:frame->document()->securityOrigin()];
+    WebGeolocationPolicyListener* listener = [[WebGeolocationPolicyListener alloc] initWithGeolocation:geolocation];
+
+    CallUIDelegate(m_webView, selector, webOrigin, kit(frame), listener);
+
+    [webOrigin release];
+    [listener release];
+
+    END_BLOCK_OBJC_EXCEPTIONS;
+}
+
 GeolocationPosition* WebGeolocationClient::lastPosition()
 {
 #if ENABLE(CLIENT_BASED_GEOLOCATION)
@@ -58,3 +94,26 @@ GeolocationPosition* WebGeolocationClient::lastPosition()
     return 0;
 #endif
 }
+
+@implementation WebGeolocationPolicyListener
+
+- (id)initWithGeolocation:(Geolocation*)geolocation
+{
+    if (!(self = [super init]))
+        return nil;
+    _geolocation = geolocation;
+    return self;
+}
+
+- (void)allow
+{
+    _geolocation->setIsAllowed(true);
+}
+
+- (void)deny
+{
+    _geolocation->setIsAllowed(false);
+}
+
+@end
+
index ed946c8..69f6af1 100644 (file)
@@ -1,3 +1,27 @@
+2010-12-02  John Knottenbelt  <jknotten@chromium.org>
+
+        Reviewed by Steve Block.
+
+        Move requestGeolocationPermissionForFrame to GeolocationClient
+        https://bugs.webkit.org/show_bug.cgi?id=50061
+
+        This change facilitates client-based geolocation implementation by
+        bringing together permission control into the geolocation client
+        interface.
+
+        Move method ChromeClient::requestGeolocationPermissionForFrame to
+        GeolocationClient::requestPermission. The moved code is unchanged
+        except that requestPermission now takes only one argument (Geolocation*),
+        the Frame parameter is retrieved from the Geolocation object and we need to
+        call m_webView.get() as it is a COMPtr in GeolocationClient.
+
+        * WebCoreSupport/WebChromeClient.cpp:
+        * WebCoreSupport/WebChromeClient.h:
+        * WebCoreSupport/WebGeolocationClient.cpp:
+        (WebGeolocationClient::requestPermission):
+        * WebCoreSupport/WebGeolocationClient.h:
+        (WebGeolocationClient::cancelPermissionRequest):
+
 2010-12-01  Jia Pu  <jpu@apple.com>
 
         Reviewed by Darin Adler.
index d046c21..884d4dc 100644 (file)
@@ -32,7 +32,6 @@
 #include "DOMCoreClasses.h"
 #include "WebElementPropertyBag.h"
 #include "WebFrame.h"
-#include "WebGeolocationPolicyListener.h"
 #include "WebHistory.h"
 #include "WebMutableURLRequest.h"
 #include "WebDesktopNotificationsDelegate.h"
@@ -46,7 +45,6 @@
 #include <WebCore/FloatRect.h>
 #include <WebCore/FrameLoadRequest.h>
 #include <WebCore/FrameView.h>
-#include <WebCore/Geolocation.h>
 #include <WebCore/HTMLNames.h>
 #include <WebCore/Icon.h>
 #include <WebCore/LocalWindowsContext.h>
@@ -817,29 +815,6 @@ void WebChromeClient::setLastSetCursorToCurrentCursor()
     m_webView->setLastCursor(::GetCursor());
 }
 
-void WebChromeClient::requestGeolocationPermissionForFrame(Frame* frame, Geolocation* geolocation)
-{
-    COMPtr<IWebUIDelegate> uiDelegate;
-    if (FAILED(m_webView->uiDelegate(&uiDelegate))) {
-        geolocation->setIsAllowed(false);
-        return;
-    }
-
-    COMPtr<IWebUIDelegatePrivate2> uiDelegatePrivate2(Query, uiDelegate);
-    if (!uiDelegatePrivate2) {
-        geolocation->setIsAllowed(false);
-        return;
-    }
-
-    COMPtr<WebSecurityOrigin> origin(AdoptCOM, WebSecurityOrigin::createInstance(frame->document()->securityOrigin()));
-    COMPtr<WebGeolocationPolicyListener> listener = WebGeolocationPolicyListener::createInstance(geolocation);
-    HRESULT hr = uiDelegatePrivate2->decidePolicyForGeolocationRequest(m_webView, kit(frame), origin.get(), listener.get());
-    if (hr != E_NOTIMPL)
-        return;
-
-    geolocation->setIsAllowed(false);
-}
-
 #if USE(ACCELERATED_COMPOSITING)
 void WebChromeClient::attachRootGraphicsLayer(Frame* frame, GraphicsLayer* graphicsLayer)
 {
index 55167b6..b6c2525 100644 (file)
@@ -159,7 +159,9 @@ public:
 
     virtual void scrollRectIntoView(const WebCore::IntRect&, const WebCore::ScrollView*) const {}
 
-    virtual void requestGeolocationPermissionForFrame(WebCore::Frame*, WebCore::Geolocation*);
+    // FIXME: Remove once all ports are using client-based geolocation. https://bugs.webkit.org/show_bug.cgi?id=40373
+    // For client-based geolocation, these two methods have been moved to WebGeolocationClient. https://bugs.webkit.org/show_bug.cgi?id=50061
+    virtual void requestGeolocationPermissionForFrame(WebCore::Frame*, WebCore::Geolocation*) { }
     virtual void cancelGeolocationPermissionRequestForFrame(WebCore::Frame*, WebCore::Geolocation*) { }
 
 #if ENABLE(VIDEO)
index 8a526c4..b1d83fb 100644 (file)
 #include "WebKitDLL.h"
 #include "WebGeolocationClient.h"
 
+#include "WebFrame.h"
+#include "WebGeolocationPolicyListener.h"
 #include "WebGeolocationPosition.h"
+#include "WebSecurityOrigin.h"
 #include "WebView.h"
+#include <WebCore/Frame.h>
+#include <WebCore/Geolocation.h>
+#include <WebCore/SecurityOrigin.h>
 
 using namespace WebCore;
 
@@ -72,3 +78,27 @@ GeolocationPosition* WebGeolocationClient::lastPosition()
     return 0;
 #endif
 }
+
+void WebGeolocationClient::requestPermission(Geolocation* geolocation)
+{
+    COMPtr<IWebUIDelegate> uiDelegate;
+    if (FAILED(m_webView->uiDelegate(&uiDelegate))) {
+        geolocation->setIsAllowed(false);
+        return;
+    }
+
+    COMPtr<IWebUIDelegatePrivate2> uiDelegatePrivate2(Query, uiDelegate);
+    if (!uiDelegatePrivate2) {
+        geolocation->setIsAllowed(false);
+        return;
+    }
+
+    Frame* frame = geolocation->frame();
+    COMPtr<WebSecurityOrigin> origin(AdoptCOM, WebSecurityOrigin::createInstance(frame->document()->securityOrigin()));
+    COMPtr<WebGeolocationPolicyListener> listener = WebGeolocationPolicyListener::createInstance(geolocation);
+    HRESULT hr = uiDelegatePrivate2->decidePolicyForGeolocationRequest(m_webView.get(), kit(frame), origin.get(), listener.get());
+    if (hr != E_NOTIMPL)
+        return;
+
+    geolocation->setIsAllowed(false);
+}
index 2422ae5..c5db134 100644 (file)
@@ -30,7 +30,8 @@
 #include <WebCore/GeolocationClient.h>
 
 namespace WebCore {
-    class GeolocationPosition;
+class Geolocation;
+class GeolocationPosition;
 }
 
 class WebView;
@@ -45,6 +46,9 @@ public:
     virtual void setEnableHighAccuracy(bool) { }
     virtual WebCore::GeolocationPosition* lastPosition();
 
+    virtual void requestPermission(WebCore::Geolocation*);
+    virtual void cancelPermissionRequest(WebCore::Geolocation*) { }
+
 private:
     COMPtr<WebView> m_webView;
 };