Title: [133094] trunk
Revision
133094
Author
[email protected]
Date
2012-10-31 16:27:04 -0700 (Wed, 31 Oct 2012)

Log Message

[BlackBerry] Adding window.external to our port
https://bugs.webkit.org/show_bug.cgi?id=100868

Patch by Otto Derek Cheung <[email protected]> on 2012-10-31
Reviewed by Rob Buis.

Source/WebKit:

Adding ExternalExtension classes to the BB cmake file.

* PlatformBlackBerry.cmake:

Source/WebKit/blackberry:

Attaching the window.external interface to the frame when
it loads up.

When called, the external interface methods call stubs declared
in ChromeClientBlackBerry. The method passes in the url of the search
provider and the url of the frame. Cross-site check has to be done in the
implementation PR.

* WebCoreSupport/ChromeClientBlackBerry.cpp:
(WebCore::ChromeClientBlackBerry::addSearchProvider):
(WebCore):
(WebCore::ChromeClientBlackBerry::isSearchProviderInstalled):
* WebCoreSupport/ChromeClientBlackBerry.h:
(ChromeClientBlackBerry):
* WebCoreSupport/ExternalExtension.cpp: Added.
(addSearchProviderMethod):
(IsSearchProviderInstalledMethod):
(externalExtensionInitialize):
(externalExtensionFinalize):
* WebCoreSupport/ExternalExtension.h: Added.
(WebCore):
* WebCoreSupport/FrameLoaderClientBlackBerry.cpp:
(WebCore::FrameLoaderClientBlackBerry::dispatchDidClearWindowObjectInWorld):

LayoutTests:

Adding BlackBerry platform specific DRT tests for window.external interface.

* platform/blackberry/external/search-provider/search-provider-installed-expected.txt: Added.
* platform/blackberry/external/search-provider/search-provider-installed.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (133093 => 133094)


--- trunk/LayoutTests/ChangeLog	2012-10-31 23:20:35 UTC (rev 133093)
+++ trunk/LayoutTests/ChangeLog	2012-10-31 23:27:04 UTC (rev 133094)
@@ -1,3 +1,15 @@
+2012-10-31  Otto Derek Cheung  <[email protected]>
+
+        [BlackBerry] Adding window.external to our port
+        https://bugs.webkit.org/show_bug.cgi?id=100868
+
+        Reviewed by Rob Buis.
+
+        Adding BlackBerry platform specific DRT tests for window.external interface.
+
+        * platform/blackberry/external/search-provider/search-provider-installed-expected.txt: Added.
+        * platform/blackberry/external/search-provider/search-provider-installed.html: Added.
+
 2012-10-31  Stephen White  <[email protected]>
 
         [chromium] Win rebaselines for media tests.  Unreviewed.

Added: trunk/LayoutTests/platform/blackberry/external/search-provider/search-provider-installed-expected.txt (0 => 133094)


--- trunk/LayoutTests/platform/blackberry/external/search-provider/search-provider-installed-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/blackberry/external/search-provider/search-provider-installed-expected.txt	2012-10-31 23:27:04 UTC (rev 133094)
@@ -0,0 +1,3 @@
+Test if window.external search components are supported, and if it works.
+PASS 'window.external AddSearchProvider is callable.
+PASS 'window.external IsSearchProviderInstalled is callable.

Added: trunk/LayoutTests/platform/blackberry/external/search-provider/search-provider-installed.html (0 => 133094)


--- trunk/LayoutTests/platform/blackberry/external/search-provider/search-provider-installed.html	                        (rev 0)
+++ trunk/LayoutTests/platform/blackberry/external/search-provider/search-provider-installed.html	2012-10-31 23:27:04 UTC (rev 133094)
@@ -0,0 +1,37 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>add-search-provider</title>
+<script src=""
+</script>
+<script type='text/_javascript_'>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+}
+
+function startTest()
+{
+    try {
+        window.external.AddSearchProvider("http://www.search.com");
+        testPassed("'window.external AddSearchProvider is callable.");
+    } catch (ex) {
+        testFailed("Got an exception when calling window.external.AddSearchProvider(url): " + ex);
+    }
+
+    try {
+        window.external.IsSearchProviderInstalled("http://www.search.com");
+        testPassed("''window.external IsSearchProviderInstalled is callable.");
+    } catch (ex) {
+        testFailed("Got an exception when calling window.external.IsSearchProviderInstalled(url): " + ex);
+    }
+}
+
+function loadComplete() { startTest(); layoutTestController.notifyDone();}
+</script>
+</head>
+<body _onload_="loadComplete()">
+<div id="description">Test if window.external search components are supported, and if it works.</div>
+<div id="console"></div>
+</body>
+</html>

Modified: trunk/Source/WebKit/ChangeLog (133093 => 133094)


--- trunk/Source/WebKit/ChangeLog	2012-10-31 23:20:35 UTC (rev 133093)
+++ trunk/Source/WebKit/ChangeLog	2012-10-31 23:27:04 UTC (rev 133094)
@@ -1,3 +1,14 @@
+2012-10-31  Otto Derek Cheung  <[email protected]>
+
+        [BlackBerry] Adding window.external to our port
+        https://bugs.webkit.org/show_bug.cgi?id=100868
+
+        Reviewed by Rob Buis.
+
+        Adding ExternalExtension classes to the BB cmake file.
+
+        * PlatformBlackBerry.cmake:
+
 2012-10-31  Michał Pakuła vel Rutka  <[email protected]>
 
         [EFL][DRT] EventSender requires contextClick implementation

Modified: trunk/Source/WebKit/PlatformBlackBerry.cmake (133093 => 133094)


--- trunk/Source/WebKit/PlatformBlackBerry.cmake	2012-10-31 23:20:35 UTC (rev 133093)
+++ trunk/Source/WebKit/PlatformBlackBerry.cmake	2012-10-31 23:27:04 UTC (rev 133094)
@@ -107,6 +107,7 @@
     blackberry/WebCoreSupport/DeviceOrientationClientBlackBerry.cpp
     blackberry/WebCoreSupport/DragClientBlackBerry.cpp
     blackberry/WebCoreSupport/EditorClientBlackBerry.cpp
+    blackberry/WebCoreSupport/ExternalExtension.cpp
     blackberry/WebCoreSupport/FrameLoaderClientBlackBerry.cpp
     blackberry/WebCoreSupport/FrameNetworkingContextBlackBerry.cpp
     blackberry/WebCoreSupport/GeolocationClientBlackBerry.cpp

Modified: trunk/Source/WebKit/blackberry/ChangeLog (133093 => 133094)


--- trunk/Source/WebKit/blackberry/ChangeLog	2012-10-31 23:20:35 UTC (rev 133093)
+++ trunk/Source/WebKit/blackberry/ChangeLog	2012-10-31 23:27:04 UTC (rev 133094)
@@ -1,3 +1,34 @@
+2012-10-31  Otto Derek Cheung  <[email protected]>
+
+        [BlackBerry] Adding window.external to our port
+        https://bugs.webkit.org/show_bug.cgi?id=100868
+
+        Reviewed by Rob Buis.
+
+        Attaching the window.external interface to the frame when
+        it loads up.
+
+        When called, the external interface methods call stubs declared
+        in ChromeClientBlackBerry. The method passes in the url of the search
+        provider and the url of the frame. Cross-site check has to be done in the
+        implementation PR.
+
+        * WebCoreSupport/ChromeClientBlackBerry.cpp:
+        (WebCore::ChromeClientBlackBerry::addSearchProvider):
+        (WebCore):
+        (WebCore::ChromeClientBlackBerry::isSearchProviderInstalled):
+        * WebCoreSupport/ChromeClientBlackBerry.h:
+        (ChromeClientBlackBerry):
+        * WebCoreSupport/ExternalExtension.cpp: Added.
+        (addSearchProviderMethod):
+        (IsSearchProviderInstalledMethod):
+        (externalExtensionInitialize):
+        (externalExtensionFinalize):
+        * WebCoreSupport/ExternalExtension.h: Added.
+        (WebCore):
+        * WebCoreSupport/FrameLoaderClientBlackBerry.cpp:
+        (WebCore::FrameLoaderClientBlackBerry::dispatchDidClearWindowObjectInWorld):
+
 2012-10-30  Peter Wang  <[email protected]>
 
         [BlackBerry] Clean the code of "_javascript_DebuggerBlackBerry"

Modified: trunk/Source/WebKit/blackberry/WebCoreSupport/ChromeClientBlackBerry.cpp (133093 => 133094)


--- trunk/Source/WebKit/blackberry/WebCoreSupport/ChromeClientBlackBerry.cpp	2012-10-31 23:20:35 UTC (rev 133093)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/ChromeClientBlackBerry.cpp	2012-10-31 23:27:04 UTC (rev 133094)
@@ -836,4 +836,18 @@
 #endif
 #endif
 
+void ChromeClientBlackBerry::addSearchProvider(const BlackBerry::Platform::String& originURL, const BlackBerry::Platform::String& newURL)
+{
+    notImplemented();
+}
+
+int ChromeClientBlackBerry::isSearchProviderInstalled(const BlackBerry::Platform::String& originURL, const BlackBerry::Platform::String& newURL)
+{
+//    Returns a value based on comparing url to the URLs of the results pages of the installed search engines.
+//    0 - None of the installed search engines match url.
+//    1 - One or more installed search engines match url, but none are the user's default search engine.
+//    2 - The user's default search engine matches url.
+    return 0;
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebKit/blackberry/WebCoreSupport/ChromeClientBlackBerry.h (133093 => 133094)


--- trunk/Source/WebKit/blackberry/WebCoreSupport/ChromeClientBlackBerry.h	2012-10-31 23:20:35 UTC (rev 133093)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/ChromeClientBlackBerry.h	2012-10-31 23:27:04 UTC (rev 133094)
@@ -160,6 +160,9 @@
 #endif
 #endif
 
+    virtual void addSearchProvider(const BlackBerry::Platform::String&, const BlackBerry::Platform::String&);
+    virtual int isSearchProviderInstalled(const BlackBerry::Platform::String&, const BlackBerry::Platform::String&);
+
     BlackBerry::WebKit::WebPagePrivate* webPagePrivate() const { return m_webPagePrivate; }
 
 private:

Added: trunk/Source/WebKit/blackberry/WebCoreSupport/ExternalExtension.cpp (0 => 133094)


--- trunk/Source/WebKit/blackberry/WebCoreSupport/ExternalExtension.cpp	                        (rev 0)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/ExternalExtension.cpp	2012-10-31 23:27:04 UTC (rev 133094)
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 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 "ExternalExtension.h"
+
+#include "Chrome.h"
+#include "ChromeClientBlackBerry.h"
+#include "Frame.h"
+#include "Page.h"
+#include "SecurityOrigin.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 addSearchProviderMethod(
+    JSContextRef ctx, JSObjectRef functionObject, JSObjectRef thisObject,
+    size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    JSValueRef jsRetVal = JSValueMakeUndefined(ctx);
+    if (argumentCount < 1)
+        return jsRetVal;
+
+    // Double check if page chrome client exists
+    Frame* frame = reinterpret_cast<Frame*>(JSObjectGetPrivate(thisObject));
+    if (!frame) {
+        Page* page = frame->page();
+        if (!page || !page->chrome())
+            return jsRetVal;
+
+        JSStringRef string = JSValueToStringCopy(ctx, arguments[0], 0);
+        size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string);
+        char* newURL = new char[sizeUTF8];
+        JSStringGetUTF8CString(string, newURL, sizeUTF8);
+        JSStringRelease(string);
+
+        String originURL = frame->document()->securityOrigin()->toString();
+        ChromeClientBlackBerry* chrome = static_cast<ChromeClientBlackBerry*> (page->chrome()->client());
+        chrome->addSearchProvider(originURL, newURL);
+    }
+
+    return jsRetVal;
+}
+
+static JSValueRef IsSearchProviderInstalledMethod(
+    JSContextRef ctx, JSObjectRef functionObject, JSObjectRef thisObject,
+    size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    JSValueRef jsRetVal = JSValueMakeUndefined(ctx);
+    if (argumentCount < 1)
+        return jsRetVal;
+
+    // Double check if page chrome client exists
+    Frame* frame = reinterpret_cast<Frame*>(JSObjectGetPrivate(thisObject));
+    if (!frame) {
+        Page* page = frame->page();
+        if (!page || !page->chrome())
+            return jsRetVal;
+
+        JSStringRef string = JSValueToStringCopy(ctx, arguments[0], 0);
+        size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string);
+        char* newURL = new char[sizeUTF8];
+        JSStringGetUTF8CString(string, newURL, sizeUTF8);
+        JSStringRelease(string);
+
+        String originURL = frame->document()->securityOrigin()->toString();
+        ChromeClientBlackBerry* chrome = static_cast<ChromeClientBlackBerry*> (page->chrome()->client());
+        int retVal = chrome->isSearchProviderInstalled(originURL, newURL);
+
+        jsRetVal = JSValueMakeNumber(ctx, retVal);
+    }
+
+    return jsRetVal;
+}
+
+static void externalExtensionInitialize(JSContextRef context, JSObjectRef object)
+{
+    UNUSED_PARAM(context);
+    UNUSED_PARAM(object);
+}
+
+static void externalExtensionFinalize(JSObjectRef object)
+{
+    UNUSED_PARAM(object);
+}
+
+static JSStaticFunction externalExtensionStaticFunctions[] = {
+    { "addSearchProvider", addSearchProviderMethod, kJSPropertyAttributeNone },
+    { "isSearchProviderInstalled", IsSearchProviderInstalledMethod, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0 }
+};
+
+static JSStaticValue externalExtensionStaticValues[] = {
+    { 0, 0, 0, 0 }
+};
+
+// FIXME: Revisit the creation of this class and make sure this is the best way to approach it.
+void attachExternalExtensionObjectToFrame(Frame* frame)
+{
+    JSDOMWindow* window = frame->script()->windowShell(mainThreadNormalWorld())->window();
+
+    JSC::ExecState* exec = window->globalExec();
+    JSC::JSLockHolder lock(exec);
+
+    JSContextRef scriptCtx = toRef(exec);
+
+    JSClassDefinition definition = kJSClassDefinitionEmpty;
+    definition.staticValues = externalExtensionStaticValues;
+    definition.staticFunctions = externalExtensionStaticFunctions;
+    definition.initialize = externalExtensionInitialize;
+    definition.finalize = externalExtensionFinalize;
+    JSClassRef clientClass = JSClassCreate(&definition);
+
+    JSObjectRef clientClassObject = JSObjectMake(scriptCtx, clientClass, 0);
+    JSObjectSetPrivate(clientClassObject, reinterpret_cast<void*>(frame));
+
+    String name("external");
+
+    JSC::PutPropertySlot slot;
+    window->put(window, exec, JSC::Identifier(exec, name), toJS(clientClassObject), slot);
+
+    JSClassRelease(clientClass);
+}

Added: trunk/Source/WebKit/blackberry/WebCoreSupport/ExternalExtension.h (0 => 133094)


--- trunk/Source/WebKit/blackberry/WebCoreSupport/ExternalExtension.h	                        (rev 0)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/ExternalExtension.h	2012-10-31 23:27:04 UTC (rev 133094)
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 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 ExternalExtension_h
+#define ExternalExtension_h
+
+namespace WebCore {
+class Frame;
+}
+
+void attachExternalExtensionObjectToFrame(WebCore::Frame*);
+
+#endif // ExternalExtension_h

Modified: trunk/Source/WebKit/blackberry/WebCoreSupport/FrameLoaderClientBlackBerry.cpp (133093 => 133094)


--- trunk/Source/WebKit/blackberry/WebCoreSupport/FrameLoaderClientBlackBerry.cpp	2012-10-31 23:20:35 UTC (rev 133093)
+++ trunk/Source/WebKit/blackberry/WebCoreSupport/FrameLoaderClientBlackBerry.cpp	2012-10-31 23:27:04 UTC (rev 133094)
@@ -33,6 +33,7 @@
 #include "CredentialManager.h"
 #include "CredentialTransformData.h"
 #include "DumpRenderTreeClient.h"
+#include "ExternalExtension.h"
 #include "FrameNetworkingContextBlackBerry.h"
 #include "FrameView.h"
 #include "HTMLFormElement.h"
@@ -906,6 +907,8 @@
     if (m_webPagePrivate->m_enableQnxJavaScriptObject)
         attachExtensionObjectToFrame(m_frame, m_webPagePrivate->m_client);
 
+    attachExternalExtensionObjectToFrame(m_frame);
+
     m_webPagePrivate->m_client->notifyWindowObjectCleared();
 
     if (m_webPagePrivate->m_dumpRenderTree) {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to