From 4c78520978776973a39f5a76adbceed2e84b951b Mon Sep 17 00:00:00 2001
From: Tianyan Liu <tianyan.liu@movial.com>
Date: Mon, 14 Jun 2010 18:29:18 +0300
Subject: [PATCH 1/2] Added API to extract the JavaScript execution context from QWebFrame.

Changed project file for WebCore to install JavaScriptCore headers. With
these two changes, the users of the QtWebKit library will have direct
access to JavaScriptCore functionalities.
---
 WebCore/WebCore.pro         |   15 +++++++++++++++
 WebKit/qt/Api/qwebframe.cpp |   15 +++++++++++++++
 WebKit/qt/Api/qwebframe.h   |    3 +++
 3 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro
index 0fcbd67..a93e862 100644
--- a/WebCore/WebCore.pro
+++ b/WebCore/WebCore.pro
@@ -2995,3 +2995,18 @@ symbian {
 
 # Disable C++0x mode in WebCore for those who enabled it in their Qt's mkspec
 *-g++*:QMAKE_CXXFLAGS -= -std=c++0x -std=gnu++0x
+
+# Section to install the JavaScriptCore header files
+jscheaders.files = $$PWD/../JavaScriptCore/API/JSBase.h \
+                   $$PWD/../JavaScriptCore/API/JSContextRef.h \
+                   $$PWD/../JavaScriptCore/API/JSObjectRef.h \
+                   $$PWD/../JavaScriptCore/API/JSStringRef.h \
+                   $$PWD/../JavaScriptCore/API/JSStringRefCF.h \
+                   $$PWD/../JavaScriptCore/API/JSStringRefBSTR.h \
+                   $$PWD/../JavaScriptCore/API/JSValueRef.h \
+                   $$PWD/../JavaScriptCore/API/JavaScript.h \
+                   $$PWD/../JavaScriptCore/API/JavaScriptCore.h \
+                   $$PWD/../JavaScriptCore/API/WebKitAvailability.h
+
+jscheaders.path = $$[QT_INSTALL_HEADERS]/JavaScriptCore
+INSTALLS += jscheaders
diff --git a/WebKit/qt/Api/qwebframe.cpp b/WebKit/qt/Api/qwebframe.cpp
index 4fe784f..8211ce7 100644
--- a/WebKit/qt/Api/qwebframe.cpp
+++ b/WebKit/qt/Api/qwebframe.cpp
@@ -81,6 +81,8 @@
 #include <qregion.h>
 #include <qnetworkrequest.h>
 
+#include <JavaScriptCore/APICast.h>
+
 using namespace WebCore;
 
 // from text/qfont.cpp
@@ -678,6 +680,19 @@ void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object
 }
 
 /*!
+    Returns the global JavaScript execution context. Use this function to bridge to JavaScriptCore APIs.
+*/
+JSGlobalContextRef QWebFrame::getGlobalContext() const
+{
+    JSDOMWindow* window = toJSDOMWindow(d->frame, mainThreadNormalWorld());
+    if (!window) {
+        qDebug() << "Warning: couldn't get window object";
+        return 0;
+    }
+    return toGlobalRef(window->globalExec());
+}
+
+/*!
     Returns the frame's content as HTML, enclosed in HTML and BODY tags.
 
     \sa setHtml(), toPlainText()
diff --git a/WebKit/qt/Api/qwebframe.h b/WebKit/qt/Api/qwebframe.h
index ce9805b..d1ac54a 100644
--- a/WebKit/qt/Api/qwebframe.h
+++ b/WebKit/qt/Api/qwebframe.h
@@ -29,6 +29,8 @@
 #include <QtNetwork/qnetworkaccessmanager.h>
 #include "qwebkitglobal.h"
 
+#include <JavaScriptCore/JSBase.h>
+
 QT_BEGIN_NAMESPACE
 class QRect;
 class QPoint;
@@ -129,6 +131,7 @@ public:
 
     void addToJavaScriptWindowObject(const QString &name, QObject *object);
     void addToJavaScriptWindowObject(const QString &name, QObject *object, QScriptEngine::ValueOwnership ownership);
+    JSGlobalContextRef getGlobalContext() const;
     QString toHtml() const;
     QString toPlainText() const;
     QString renderTreeDump() const;
-- 
1.6.3.3


