Title: [106731] trunk/Source/WebKit
Revision
106731
Author
[email protected]
Date
2012-02-04 01:24:10 -0800 (Sat, 04 Feb 2012)

Log Message

[BlackBerry] Upstream BlackBerry WebCoreSupport ClientExtension and GeolocationControllerClientBlackBerry classes
https://bugs.webkit.org/show_bug.cgi?id=77751

Patch by Jacky Jiang <[email protected]> on 2012-02-04
Reviewed by Rob Buis.

Initial upstream, no new tests.

* blackberry/WebCoreSupport/ClientExtension.cpp: Added.
* blackberry/WebCoreSupport/ClientExtension.h: Added.
* blackberry/WebCoreSupport/GeolocationControllerClientBlackBerry.cpp: Added.
* blackberry/WebCoreSupport/GeolocationControllerClientBlackBerry.h: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (106730 => 106731)


--- trunk/Source/WebKit/ChangeLog	2012-02-04 09:19:57 UTC (rev 106730)
+++ trunk/Source/WebKit/ChangeLog	2012-02-04 09:24:10 UTC (rev 106731)
@@ -1,3 +1,17 @@
+2012-02-04  Jacky Jiang  <[email protected]>
+
+        [BlackBerry] Upstream BlackBerry WebCoreSupport ClientExtension and GeolocationControllerClientBlackBerry classes
+        https://bugs.webkit.org/show_bug.cgi?id=77751
+
+        Reviewed by Rob Buis.
+
+        Initial upstream, no new tests.
+
+        * blackberry/WebCoreSupport/ClientExtension.cpp: Added.
+        * blackberry/WebCoreSupport/ClientExtension.h: Added.
+        * blackberry/WebCoreSupport/GeolocationControllerClientBlackBerry.cpp: Added.
+        * blackberry/WebCoreSupport/GeolocationControllerClientBlackBerry.h: Added.
+
 2012-01-11  Jacky Jiang  <[email protected]>
 
         [BlackBerry] ASSERT failure in BackingStorePrivate::blitVisibleContents()

Added: trunk/Source/WebKit/blackberry/WebCoreSupport/ClientExtension.cpp (0 => 106731)


--- trunk/Source/WebKit/blackberry/WebCoreSupport/ClientExtension.cpp	                        (rev 0)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/ClientExtension.cpp	2012-02-04 09:24:10 UTC (rev 106731)
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "ClientExtension.h"
+
+#include "Frame.h"
+#include "WebPageClient.h"
+#include <_javascript_Core/API/JSCallbackObject.h>
+#include <_javascript_Core/JSObjectRef.h>
+#include <_javascript_Core/JSStringRef.h>
+#include <_javascript_Core/JSValueRef.h>
+#include <_javascript_Core/_javascript_.h>
+#include <string>
+
+using namespace WebCore;
+using namespace BlackBerry::WebKit;
+using namespace std;
+
+static JSValueRef clientExtensionMethod(
+    JSContextRef ctx, JSObjectRef functionObject, JSObjectRef thisObject,
+    size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    JSValueRef jsRetVal = JSValueMakeUndefined(ctx);
+    if (argumentCount <= 0)
+        return jsRetVal;
+
+    char** strArgs = new char*[argumentCount];
+    for (unsigned i = 0; i < argumentCount; ++i) {
+        JSStringRef string = JSValueToStringCopy(ctx, arguments[i], 0);
+        size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string);
+        strArgs[i] = new char[sizeUTF8];
+        JSStringGetUTF8CString(string, strArgs[i], sizeUTF8);
+        JSStringRelease(string);
+    }
+
+    WebPageClient* client = reinterpret_cast<WebPageClient*>(JSObjectGetPrivate(thisObject));
+    string retVal = client->invokeClientJavaScriptCallback(strArgs, argumentCount).utf8();
+    if (!retVal.empty())
+        jsRetVal = JSValueMakeString(ctx, JSStringCreateWithUTF8CString(retVal.c_str()));
+
+    for (unsigned i = 0; i < argumentCount; ++i)
+        delete[] strArgs[i];
+    delete[] strArgs;
+
+    return jsRetVal;
+}
+
+static void clientExtensionInitialize(JSContextRef context, JSObjectRef object)
+{
+    UNUSED_PARAM(context);
+    UNUSED_PARAM(object);
+}
+
+static void clientExtensionFinalize(JSObjectRef object)
+{
+    UNUSED_PARAM(object);
+}
+
+static JSStaticFunction clientExtensionStaticFunctions[] = {
+    { "callExtensionMethod", clientExtensionMethod, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
+};
+
+static JSStaticValue clientExtensionStaticValues[] = {
+    { 0, 0, 0, 0 }
+};
+
+// FIXME: Revisit the creation of this class and make sure this is the best way to approach it.
+void attachExtensionObjectToFrame(Frame* frame, WebPageClient* client)
+{
+    JSC::JSLock lock(JSC::SilenceAssertionsOnly);
+
+    JSDOMWindow* window = frame->script()->windowShell(mainThreadNormalWorld())->window();
+
+    JSC::ExecState* exec = window->globalExec();
+    JSContextRef scriptCtx = toRef(exec);
+
+    JSClassDefinition definition = kJSClassDefinitionEmpty;
+    definition.staticValues = clientExtensionStaticValues;
+    definition.staticFunctions = clientExtensionStaticFunctions;
+    definition.initialize = clientExtensionInitialize;
+    definition.finalize = clientExtensionFinalize;
+    JSClassRef clientClass = JSClassCreate(&definition);
+
+    JSObjectRef clientClassObject = JSObjectMake(scriptCtx, clientClass, 0);
+    JSObjectSetPrivate(clientClassObject, reinterpret_cast<void*>(client));
+
+    JSC::UString name("qnx");
+
+    JSC::PutPropertySlot slot;
+    window->put(window, exec, JSC::Identifier(exec, name), toJS(clientClassObject), slot);
+
+    JSClassRelease(clientClass);
+}

Added: trunk/Source/WebKit/blackberry/WebCoreSupport/ClientExtension.h (0 => 106731)


--- trunk/Source/WebKit/blackberry/WebCoreSupport/ClientExtension.h	                        (rev 0)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/ClientExtension.h	2012-02-04 09:24:10 UTC (rev 106731)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2010, 2011 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef ClientExtension_h
+#define ClientExtension_h
+
+namespace WebCore {
+class Frame;
+}
+
+namespace BlackBerry {
+namespace WebKit {
+class WebPageClient;
+}
+}
+
+void attachExtensionObjectToFrame(WebCore::Frame*, BlackBerry::WebKit::WebPageClient*);
+
+#endif // ClientExtension_h

Added: trunk/Source/WebKit/blackberry/WebCoreSupport/GeolocationControllerClientBlackBerry.cpp (0 => 106731)


--- trunk/Source/WebKit/blackberry/WebCoreSupport/GeolocationControllerClientBlackBerry.cpp	                        (rev 0)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/GeolocationControllerClientBlackBerry.cpp	2012-02-04 09:24:10 UTC (rev 106731)
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "GeolocationControllerClientBlackBerry.h"
+
+#include "Chrome.h"
+#include "Geolocation.h"
+#include "GeolocationController.h"
+#include "GeolocationError.h"
+#include "Page.h"
+#include "WebPage.h"
+#include "WebPage_p.h"
+
+using namespace WebCore;
+
+GeolocationControllerClientBlackBerry::GeolocationControllerClientBlackBerry(BlackBerry::WebKit::WebPage* webPage)
+    : m_webPage(webPage)
+    , m_tracker(0)
+    , m_accuracy(false)
+{
+}
+
+void GeolocationControllerClientBlackBerry::geolocationDestroyed()
+{
+    if (m_tracker)
+        m_tracker->destroy();
+    delete this;
+}
+
+void GeolocationControllerClientBlackBerry::startUpdating()
+{
+    if (m_tracker)
+        m_tracker->resume();
+    else
+        m_tracker = BlackBerry::Platform::GeoTracker::create(this, 0, m_accuracy, -1, -1);
+}
+
+void GeolocationControllerClientBlackBerry::stopUpdating()
+{
+    if (m_tracker)
+        m_tracker->suspend();
+}
+
+GeolocationPosition* GeolocationControllerClientBlackBerry::lastPosition()
+{
+    return m_lastPosition.get();
+}
+
+void GeolocationControllerClientBlackBerry::requestPermission(Geolocation* location)
+{
+    Frame* frame = location->frame();
+    if (!frame)
+        return;
+    m_webPage->d->m_page->chrome()->requestGeolocationPermissionForFrame(frame, location);
+}
+
+void GeolocationControllerClientBlackBerry::cancelPermissionRequest(Geolocation* location)
+{
+    Frame* frame = location->frame();
+    if (!frame)
+        return;
+    m_webPage->d->m_page->chrome()->cancelGeolocationPermissionRequestForFrame(frame, location);
+}
+
+void GeolocationControllerClientBlackBerry::onLocationUpdate(double timestamp, double latitude, double longitude, double accuracy, double altitude, bool altitudeValid,
+                                                             double altitudeAccuracy, bool altitudeAccuracyValid, double speed, bool speedValid, double heading, bool headingValid)
+{
+    m_lastPosition = GeolocationPosition::create(timestamp, latitude, longitude, accuracy, altitudeValid, altitude, altitudeAccuracyValid,
+                                                 altitudeAccuracy, headingValid, heading, speedValid, speed);
+    m_webPage->d->m_page->geolocationController()->positionChanged(m_lastPosition.get());
+}
+
+void GeolocationControllerClientBlackBerry::onLocationError(const char* errorStr)
+{
+    RefPtr<GeolocationError> error = GeolocationError::create(GeolocationError::PositionUnavailable, String::fromUTF8(errorStr));
+    m_webPage->d->m_page->geolocationController()->errorOccurred(error.get());
+}
+
+void GeolocationControllerClientBlackBerry::onPermission(void* context, bool isAllowed)
+{
+    Geolocation* position = static_cast<Geolocation*>(context);
+    position->setIsAllowed(isAllowed);
+}
+
+void GeolocationControllerClientBlackBerry::setEnableHighAccuracy(bool newAccuracy)
+{
+    if (m_accuracy == newAccuracy)
+        return;
+    if (m_tracker) {
+        m_tracker->destroy();
+        m_tracker = BlackBerry::Platform::GeoTracker::create(this, 0, newAccuracy, -1, -1);
+    }
+}
+

Added: trunk/Source/WebKit/blackberry/WebCoreSupport/GeolocationControllerClientBlackBerry.h (0 => 106731)


--- trunk/Source/WebKit/blackberry/WebCoreSupport/GeolocationControllerClientBlackBerry.h	                        (rev 0)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/GeolocationControllerClientBlackBerry.h	2012-02-04 09:24:10 UTC (rev 106731)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef GeolocationControllerClientBlackBerry_h
+#define GeolocationControllerClientBlackBerry_h
+
+#include "WebPage.h"
+#include <BlackBerryPlatformGeoTracker.h>
+#include <BlackBerryPlatformGeoTrackerListener.h>
+#include <GeolocationClient.h>
+#include <GeolocationPosition.h>
+
+namespace WebCore {
+
+class GeolocationControllerClientBlackBerry : public GeolocationClient, public BlackBerry::Platform::GeoTrackerListener {
+public:
+    GeolocationControllerClientBlackBerry(BlackBerry::WebKit::WebPage*);
+
+    virtual void geolocationDestroyed();
+    virtual void startUpdating();
+    virtual void stopUpdating();
+    virtual GeolocationPosition* lastPosition();
+    virtual void setEnableHighAccuracy(bool);
+    virtual void requestPermission(Geolocation*);
+    virtual void cancelPermissionRequest(Geolocation*);
+
+    virtual void onLocationUpdate(double timestamp, double latitude, double longitude, double accuracy, double altitude, bool altitudeValid, double altitudeAccuracy,
+                                  bool altitudeAccuracyValid, double speed, bool speedValid, double heading, bool headingValid);
+    virtual void onLocationError(const char* error);
+    virtual void onPermission(void* context, bool isAllowed);
+    BlackBerry::Platform::GeoTracker* tracker() const { return m_tracker; }
+
+private:
+    BlackBerry::WebKit::WebPage* m_webPage;
+    BlackBerry::Platform::GeoTracker* m_tracker;
+    RefPtr<GeolocationPosition> m_lastPosition;
+    bool m_accuracy;
+};
+}
+
+#endif // GeolocationControllerClientBlackBerry_h
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to