Initial llqtwebkit

This commit is contained in:
Drake Arconis
2012-09-08 02:01:25 -04:00
parent 86ad4aabf3
commit 9b358a1b39
72 changed files with 12876 additions and 30 deletions

View File

@@ -0,0 +1,269 @@
/* Copyright (c) 2006-2010, Linden Research, Inc.
*
* LLQtWebKit Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in GPL-license.txt in this distribution, or online at
* http://secondlifegrid.net/technology-programs/license-virtual-world/viewerlicensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/technology-programs/license-virtual-world/viewerlicensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
*/
#define FREEGLUT_STATIC
#include "zpr.h"
#include "llqtwebkit.h"
#include <iostream>
#include <string>
#include <direct.h>
#include <time.h>
bool gDebugMode = false;
int gBrowserWindowId=-1;
GLuint gBrowserTexture=-1;
GLuint gCheckerTexture=-1;
// manually make part of the browser texture transparent - for testing - LLQtWebKit will handle this eventually
void alphaize_browser_texture(unsigned char* texture_pixels)
{
const int texture_depth=4;
int texture_width = LLQtWebKit::getInstance()->getBrowserWidth(gBrowserWindowId);
int texture_height = LLQtWebKit::getInstance()->getBrowserHeight(gBrowserWindowId);
const int num_squares=16;
int sqr1_alpha=0xff;
int sqr2_alpha=0x00;
for(int y1=0;y1<num_squares;++y1)
{
for(int x1=0;x1<num_squares;++x1)
{
int px_start=texture_width*x1/num_squares;
int px_end=(texture_width*(x1+1))/num_squares;
int py_start=texture_height*y1/num_squares;
int py_end=(texture_height*(y1+1))/num_squares;
for(int y2=py_start;y2<py_end;++y2)
{
for(int x2=px_start;x2<px_end;++x2)
{
int rowspan=texture_width*texture_depth;
if((y1%2)^(x1%2))
{
texture_pixels[y2*rowspan+x2*texture_depth+3]=sqr1_alpha;
}
else
{
texture_pixels[y2*rowspan+x2*texture_depth+3]=sqr2_alpha;
};
};
};
};
};
}
void idle(void)
{
if(!gDebugMode)
{
LLQtWebKit::getInstance()->pump(200);
LLQtWebKit::getInstance()->grabBrowserWindow( gBrowserWindowId );
glutPostRedisplay();
};
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, gCheckerTexture);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.8f, -0.8f, -0.8f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.8f, 0.8f, -0.8f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.8f, 0.8f, -0.8f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.8f, -0.8f, -0.8f);
glEnd();
glBindTexture(GL_TEXTURE_2D, gBrowserTexture);
if(!gDebugMode)
{
const unsigned char* browser_pixels=LLQtWebKit::getInstance()->getBrowserWindowPixels(gBrowserWindowId);
if(browser_pixels)
{
int texture_width = LLQtWebKit::getInstance()->getBrowserWidth(gBrowserWindowId);
int texture_height = LLQtWebKit::getInstance()->getBrowserHeight(gBrowserWindowId);
int texture_depth = 4;
unsigned char* texture_pixels = new unsigned char[texture_width*texture_height*texture_depth];
memcpy(texture_pixels, browser_pixels, texture_width*texture_height*texture_depth);
alphaize_browser_texture(texture_pixels);
glTexSubImage2D(GL_TEXTURE_2D, 0,
0, 0,
texture_width, texture_height,
GL_RGBA,
GL_UNSIGNED_BYTE,
texture_pixels);
delete [] texture_pixels;
};
};
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.8f, -0.8f, 0.8f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.8f, -0.8f, 0.8f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.8f, 0.8f, 0.8f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.8f, 0.8f, 0.8f);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
GLuint make_rgba_texture(int texture_width, int texture_height)
{
const int texture_depth=4;
unsigned char* texture_pixels = new unsigned char[texture_width*texture_height*texture_depth];
const int num_squares=rand()%10+10;
int sqr1_r=rand()%0xa0+0x20;
int sqr1_g=rand()%0xa0+0x20;
int sqr1_b=rand()%0xa0+0x20;
int sqr1_alpha=0xff;
int sqr2_r=rand()%0xa0+0x20;
int sqr2_g=rand()%0xa0+0x20;
int sqr2_b=rand()%0xa0+0x20;
int sqr2_alpha=0x00;
for(int y1=0;y1<num_squares;++y1)
{
for(int x1=0;x1<num_squares;++x1)
{
int px_start=texture_width*x1/num_squares;
int px_end=(texture_width*(x1+1))/num_squares;
int py_start=texture_height*y1/num_squares;
int py_end=(texture_height*(y1+1))/num_squares;
for(int y2=py_start;y2<py_end;++y2)
{
for(int x2=px_start;x2<px_end;++x2)
{
int rowspan=texture_width*texture_depth;
if((y1%2)^(x1%2))
{
texture_pixels[y2*rowspan+x2*texture_depth+0]=sqr1_r;
texture_pixels[y2*rowspan+x2*texture_depth+1]=sqr1_g;
texture_pixels[y2*rowspan+x2*texture_depth+2]=sqr1_b;
texture_pixels[y2*rowspan+x2*texture_depth+3]=sqr1_alpha;
}
else
{
texture_pixels[y2*rowspan+x2*texture_depth+0]=sqr2_r;
texture_pixels[y2*rowspan+x2*texture_depth+1]=sqr2_g;
texture_pixels[y2*rowspan+x2*texture_depth+2]=sqr2_b;
texture_pixels[y2*rowspan+x2*texture_depth+3]=sqr2_alpha;
};
};
};
};
};
GLuint texture_id;
glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_2D, texture_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width, texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture_pixels);
delete [] texture_pixels;
return texture_id;
}
int main(int argc, char* argv[])
{
srand((unsigned int)time(0));
const int browser_width=1024;
const int browser_height=1024;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
glutInitWindowPosition(80, 0);
glutInitWindowSize(600,600);
glutCreateWindow("3D Web Pages in OpenGL");
glutDisplayFunc(display);
glutIdleFunc(idle);
zprInit();
glEnable(GL_TEXTURE_2D);
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
if(gDebugMode)
{
gBrowserTexture = make_rgba_texture(browser_width, browser_height);
}
else
{
glGenTextures(1, &gBrowserTexture);
glBindTexture(GL_TEXTURE_2D, gBrowserTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, browser_width, browser_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0 );
std::string working_dir=_getcwd(NULL, 1024);
std::string app_dir("");
std::string profile_dir=working_dir+"/profile";
std::string cookie_path=profile_dir+"/cookies.txt";
LLQtWebKit::getInstance()->init(std::string(), app_dir, profile_dir, GetDesktopWindow());
LLQtWebKit::getInstance()->enableJavaScript(true);
LLQtWebKit::getInstance()->enableCookies(true);
LLQtWebKit::getInstance()->enablePlugins(true);
const std::string start_url("http://news.google.com");
//const std::string start_url("http://www.youtube.com/watch?v=4Z3r9X8OahA&feature=rbl_entertainment");
gBrowserWindowId=LLQtWebKit::getInstance()->createBrowserWindow(browser_width, browser_height);
LLQtWebKit::getInstance()->setSize(gBrowserWindowId, browser_width, browser_height);
LLQtWebKit::getInstance()->flipWindow(gBrowserWindowId, true);
LLQtWebKit::getInstance()->navigateTo(gBrowserWindowId, start_url);
}
gCheckerTexture = make_rgba_texture( browser_width, browser_height);
glutMainLoop();
return 0;
}

View File

@@ -0,0 +1,38 @@
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
INCLUDEPATH += ../../
CONFIG -= app_bundle
QT += webkit opengl network
!mac {
unix {
DEFINES += LL_LINUX
LIBS += -lglui -lglut
LIBS += $$PWD/../../libllqtwebkit.a
}
}
mac {
DEFINES += LL_OSX
LIBS += -framework GLUT -framework OpenGL
LIBS += $$PWD/libllqtwebkit.dylib
}
win32 {
DEFINES += _WINDOWS
INCLUDEPATH += ../
INCLUDEPATH += $$PWD/../../stage/packages/include
DESTDIR=../build
release {
LIBS += $$PWD/../../Release/llqtwebkit.lib
LIBS += $$PWD/../build/freeglut_static.lib
LIBS += comdlg32.lib
}
}
include(../../static.pri)
SOURCES += 3dgl.cpp zpr.c

View File

@@ -0,0 +1,429 @@
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <math.h>
#include "zpr.h"
/* This code was originally C++ :-) */
#define bool int
#define true 1
#define false 0
static double _left = 0.0;
static double _right = 0.0;
static double _bottom = 0.0;
static double _top = 0.0;
static double _zNear = -10.0;
static double _zFar = 10.0;
static int _mouseX = 0;
static int _mouseY = 0;
static bool _mouseLeft = false;
static bool _mouseMiddle = false;
static bool _mouseRight = false;
static double _dragPosX = 0.0;
static double _dragPosY = 0.0;
static double _dragPosZ = 0.0;
static double _matrix[16];
static double _matrixInverse[16];
static double vlen(double x,double y,double z);
static void pos(double *px,double *py,double *pz,const int x,const int y,const int *viewport);
static void getMatrix();
static void invertMatrix(const GLdouble *m, GLdouble *out );
static void zprReshape(int w,int h);
static void zprMouse(int button, int state, int x, int y);
static void zprMotion(int x, int y);
static void zprPick(GLdouble x, GLdouble y,GLdouble delX, GLdouble delY);
/* Configurable center point for zooming and rotation */
GLfloat zprReferencePoint[4] = { 0,0,0,0 };
void
zprInit()
{
getMatrix();
glutReshapeFunc(zprReshape);
glutMouseFunc(zprMouse);
glutMotionFunc(zprMotion);
}
static void
zprReshape(int w,int h)
{
glViewport(0,0,w,h);
_top = 1.0;
_bottom = -1.0;
_left = -(double)w/(double)h;
_right = -_left;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(_left,_right,_bottom,_top,_zNear,_zFar);
glMatrixMode(GL_MODELVIEW);
}
static void
zprMouse(int button, int state, int x, int y)
{
GLint viewport[4];
/* Do picking */
if (state==GLUT_DOWN)
zprPick(x,glutGet(GLUT_WINDOW_HEIGHT)-1-y,3,3);
_mouseX = x;
_mouseY = y;
if (state==GLUT_UP)
switch (button)
{
case GLUT_LEFT_BUTTON: _mouseLeft = false; break;
case GLUT_MIDDLE_BUTTON: _mouseMiddle = false; break;
case GLUT_RIGHT_BUTTON: _mouseRight = false; break;
}
else
switch (button)
{
case GLUT_LEFT_BUTTON: _mouseLeft = true; break;
case GLUT_MIDDLE_BUTTON: _mouseMiddle = true; break;
case GLUT_RIGHT_BUTTON: _mouseRight = true; break;
}
glGetIntegerv(GL_VIEWPORT,viewport);
pos(&_dragPosX,&_dragPosY,&_dragPosZ,x,y,viewport);
glutPostRedisplay();
}
static void
zprMotion(int x, int y)
{
bool changed = false;
const int dx = x - _mouseX;
const int dy = y - _mouseY;
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT,viewport);
if (dx==0 && dy==0)
return;
if (_mouseMiddle || (_mouseLeft && _mouseRight))
{
double s = exp((double)dy*0.01);
glTranslatef( zprReferencePoint[0], zprReferencePoint[1], zprReferencePoint[2]);
glScalef(s,s,s);
glTranslatef(-zprReferencePoint[0],-zprReferencePoint[1],-zprReferencePoint[2]);
changed = true;
}
else
if (_mouseLeft)
{
double ax,ay,az;
double bx,by,bz;
double angle;
ax = dy;
ay = dx;
az = 0.0;
angle = vlen(ax,ay,az)/(double)(viewport[2]+1)*180.0;
/* Use inverse matrix to determine local axis of rotation */
bx = _matrixInverse[0]*ax + _matrixInverse[4]*ay + _matrixInverse[8] *az;
by = _matrixInverse[1]*ax + _matrixInverse[5]*ay + _matrixInverse[9] *az;
bz = _matrixInverse[2]*ax + _matrixInverse[6]*ay + _matrixInverse[10]*az;
glTranslatef( zprReferencePoint[0], zprReferencePoint[1], zprReferencePoint[2]);
glRotatef(angle,bx,by,bz);
glTranslatef(-zprReferencePoint[0],-zprReferencePoint[1],-zprReferencePoint[2]);
changed = true;
}
else
if (_mouseRight)
{
double px,py,pz;
pos(&px,&py,&pz,x,y,viewport);
glLoadIdentity();
glTranslatef(px-_dragPosX,py-_dragPosY,pz-_dragPosZ);
glMultMatrixd(_matrix);
_dragPosX = px;
_dragPosY = py;
_dragPosZ = pz;
changed = true;
}
_mouseX = x;
_mouseY = y;
if (changed)
{
getMatrix();
glutPostRedisplay();
}
}
/*****************************************************************
* Utility functions
*****************************************************************/
static double
vlen(double x,double y,double z)
{
return sqrt(x*x+y*y+z*z);
}
static void
pos(double *px,double *py,double *pz,const int x,const int y,const int *viewport)
{
/*
Use the ortho projection and viewport information
to map from mouse co-ordinates back into world
co-ordinates
*/
*px = (double)(x-viewport[0])/(double)(viewport[2]);
*py = (double)(y-viewport[1])/(double)(viewport[3]);
*px = _left + (*px)*(_right-_left);
*py = _top + (*py)*(_bottom-_top);
*pz = _zNear;
}
static void
getMatrix()
{
glGetDoublev(GL_MODELVIEW_MATRIX,_matrix);
invertMatrix(_matrix,_matrixInverse);
}
/*
* From Mesa-2.2\src\glu\project.c
*
* Compute the inverse of a 4x4 matrix. Contributed by scotter@lafn.org
*/
static void
invertMatrix(const GLdouble *m, GLdouble *out )
{
/* NB. OpenGL Matrices are COLUMN major. */
#define MAT(m,r,c) (m)[(c)*4+(r)]
/* Here's some shorthand converting standard (row,column) to index. */
#define m11 MAT(m,0,0)
#define m12 MAT(m,0,1)
#define m13 MAT(m,0,2)
#define m14 MAT(m,0,3)
#define m21 MAT(m,1,0)
#define m22 MAT(m,1,1)
#define m23 MAT(m,1,2)
#define m24 MAT(m,1,3)
#define m31 MAT(m,2,0)
#define m32 MAT(m,2,1)
#define m33 MAT(m,2,2)
#define m34 MAT(m,2,3)
#define m41 MAT(m,3,0)
#define m42 MAT(m,3,1)
#define m43 MAT(m,3,2)
#define m44 MAT(m,3,3)
GLdouble det;
GLdouble d12, d13, d23, d24, d34, d41;
GLdouble tmp[16]; /* Allow out == in. */
/* Inverse = adjoint / det. (See linear algebra texts.)*/
/* pre-compute 2x2 dets for last two rows when computing */
/* cofactors of first two rows. */
d12 = (m31*m42-m41*m32);
d13 = (m31*m43-m41*m33);
d23 = (m32*m43-m42*m33);
d24 = (m32*m44-m42*m34);
d34 = (m33*m44-m43*m34);
d41 = (m34*m41-m44*m31);
tmp[0] = (m22 * d34 - m23 * d24 + m24 * d23);
tmp[1] = -(m21 * d34 + m23 * d41 + m24 * d13);
tmp[2] = (m21 * d24 + m22 * d41 + m24 * d12);
tmp[3] = -(m21 * d23 - m22 * d13 + m23 * d12);
/* Compute determinant as early as possible using these cofactors. */
det = m11 * tmp[0] + m12 * tmp[1] + m13 * tmp[2] + m14 * tmp[3];
/* Run singularity test. */
if (det == 0.0) {
/* printf("invert_matrix: Warning: Singular matrix.\n"); */
/* memcpy(out,_identity,16*sizeof(double)); */
}
else {
GLdouble invDet = 1.0 / det;
/* Compute rest of inverse. */
tmp[0] *= invDet;
tmp[1] *= invDet;
tmp[2] *= invDet;
tmp[3] *= invDet;
tmp[4] = -(m12 * d34 - m13 * d24 + m14 * d23) * invDet;
tmp[5] = (m11 * d34 + m13 * d41 + m14 * d13) * invDet;
tmp[6] = -(m11 * d24 + m12 * d41 + m14 * d12) * invDet;
tmp[7] = (m11 * d23 - m12 * d13 + m13 * d12) * invDet;
/* Pre-compute 2x2 dets for first two rows when computing */
/* cofactors of last two rows. */
d12 = m11*m22-m21*m12;
d13 = m11*m23-m21*m13;
d23 = m12*m23-m22*m13;
d24 = m12*m24-m22*m14;
d34 = m13*m24-m23*m14;
d41 = m14*m21-m24*m11;
tmp[8] = (m42 * d34 - m43 * d24 + m44 * d23) * invDet;
tmp[9] = -(m41 * d34 + m43 * d41 + m44 * d13) * invDet;
tmp[10] = (m41 * d24 + m42 * d41 + m44 * d12) * invDet;
tmp[11] = -(m41 * d23 - m42 * d13 + m43 * d12) * invDet;
tmp[12] = -(m32 * d34 - m33 * d24 + m34 * d23) * invDet;
tmp[13] = (m31 * d34 + m33 * d41 + m34 * d13) * invDet;
tmp[14] = -(m31 * d24 + m32 * d41 + m34 * d12) * invDet;
tmp[15] = (m31 * d23 - m32 * d13 + m33 * d12) * invDet;
memcpy(out, tmp, 16*sizeof(GLdouble));
}
#undef m11
#undef m12
#undef m13
#undef m14
#undef m21
#undef m22
#undef m23
#undef m24
#undef m31
#undef m32
#undef m33
#undef m34
#undef m41
#undef m42
#undef m43
#undef m44
#undef MAT
}
/***************************************** Picking ****************************************************/
static void (*selection)(void) = NULL;
static void (*pick)(GLint name) = NULL;
void zprSelectionFunc(void (*f)(void))
{
selection = f;
}
void zprPickFunc(void (*f)(GLint name))
{
pick = f;
}
/* Draw in selection mode */
static void
zprPick(GLdouble x, GLdouble y,GLdouble delX, GLdouble delY)
{
GLuint buffer[1024];
const int bufferSize = sizeof(buffer)/sizeof(GLuint);
GLint viewport[4];
GLdouble projection[16];
GLint hits;
GLint i,j,k;
GLint min = -1;
GLuint minZ = -1;
glSelectBuffer(bufferSize,buffer); /* Selection buffer for hit records */
glRenderMode(GL_SELECT); /* OpenGL selection mode */
glInitNames(); /* Clear OpenGL name stack */
glMatrixMode(GL_PROJECTION);
glPushMatrix(); /* Push current projection matrix */
glGetIntegerv(GL_VIEWPORT,viewport); /* Get the current viewport size */
glGetDoublev(GL_PROJECTION_MATRIX,projection); /* Get the projection matrix */
glLoadIdentity(); /* Reset the projection matrix */
gluPickMatrix(x,y,delX,delY,viewport); /* Set the picking matrix */
glMultMatrixd(projection); /* Apply projection matrix */
glMatrixMode(GL_MODELVIEW);
if (selection)
selection(); /* Draw the scene in selection mode */
hits = glRenderMode(GL_RENDER); /* Return to normal rendering mode */
/* Diagnostic output to stdout */
#ifndef NDEBUG
if (hits!=0)
{
printf("hits = %d\n",hits);
for (i=0,j=0; i<hits; i++)
{
printf("\tsize = %u, min = %u, max = %u : ",buffer[j],buffer[j+1],buffer[j+2]);
for (k=0; k < (GLint) buffer[j]; k++)
printf("%u ",buffer[j+3+k]);
printf("\n");
j += 3 + buffer[j];
}
}
#endif
/* Determine the nearest hit */
if (hits)
{
for (i=0,j=0; i<hits; i++)
{
if (buffer[j+1]<minZ)
{
/* If name stack is empty, return -1 */
/* If name stack is not empty, return top-most name */
if (buffer[j]==0)
min = -1;
else
min = buffer[j+2+buffer[j]];
minZ = buffer[j+1];
}
j += buffer[j] + 3;
}
}
glMatrixMode(GL_PROJECTION);
glPopMatrix(); /* Restore projection matrix */
glMatrixMode(GL_MODELVIEW);
if (pick)
pick(min); /* Pass pick event back to application */
}

View File

@@ -0,0 +1,88 @@
#ifndef ZPR_H
#define ZPR_H
/*
* Zoom-pan-rotate mouse manipulation module for GLUT
* Version 0.4, October 2003
*
* Nigel Stewart
* School of Computer Science and Information Technology
* RMIT University
* nigels@cs.rmit.edu.au
*
* Instructions
* ------------
*
* Call zprInit() immediately after your call to glutCreateWindow()
*
* The ZPR module handles glutReshapeFunc(), glutMouseFunc() and glutMotionFunc()
* Applications should not bypass the ZPR handlers for reshape or mouse events.
*
* Mouse manipulation of the GLUT window via the modelview matrix:
*
* Left button -> rotate
* Middle button -> zoom
* Right button -> pan
*
* Picking is also provided via two configurable callbacks:
*
* void zprSelectionFunc(void (*f)(void))
*
* The draw function to be called in OpenGL selection
* mode in response to a mouse-down button event.
*
* void zprPickFunc(void (*f)(GLint name))
*
* The callback function which will receive the
* top-most item of the name stack of the closest selection
* hit. If there is no selection hit, -1
*
* Limitations
* -----------
*
* Works best with zprReferencePoint appropriately configured.
* Works best with ortho projection.
* You may need to use glEnable(GL_NORMALIZATION) for correct lighting.
* Near and far clip planes are hard-coded.
* Zooming and rotation is centered on the origin.
* Only one window can use the callbacks at one time.
*
*/
#ifdef WIN32
#include <windows.h>
#endif
#define FREEGLUT_STATIC
#include <GL/glut.h>
#ifdef __cplusplus
extern "C"
{
#endif
/*
*
*/
/* Mouse Manipulation API */
void zprInit();
extern GLfloat zprReferencePoint[4];
/* Picking API (Optional) */
extern void zprSelectionFunc(void (*f)(void)); /* Selection-mode draw function */
extern void zprPickFunc(void (*f)(GLint name)); /* Pick event handling function */
/*
*
*/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,341 @@
/* Copyright (c) 2006-2010, Linden Research, Inc.
*
* LLQtWebKit Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in GPL-license.txt in this distribution, or online at
* http://secondlifegrid.net/technology-programs/license-virtual-world/viewerlicensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/technology-programs/license-virtual-world/viewerlicensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
*/
#include <QtGui/QtGui>
#include <llqtwebkit.h>
class WebPage : public QWidget, LLEmbeddedBrowserWindowObserver
{
Q_OBJECT
signals:
void locationChanged(const QString &);
void canGoBack(bool);
void canGoForward(bool);
public:
WebPage(QWidget *parent = 0);
~WebPage();
void onCursorChanged(const EventType& event);
void onPageChanged(const EventType& event);
void onNavigateBegin(const EventType& event);
void onNavigateComplete(const EventType& event);
void onUpdateProgress(const EventType& event);
void onStatusTextChange(const EventType& event);
void onLocationChange(const EventType& event);
void onClickLinkHref(const EventType& event);
void onClickLinkNoFollow(const EventType& event);
public slots:
void goBack();
void goForward();
void reload();
void loadUrl(const QString &);
protected:
void resizeEvent(QResizeEvent *event);
void paintEvent(QPaintEvent *event);
void mouseDoubleClickEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event);
private:
void updateSLvariables();
int mBrowserWindowId;
};
WebPage::WebPage(QWidget *parent)
: QWidget(parent)
{
setMouseTracking(true);
std::string applicationDir = std::string();
std::string componentDir = applicationDir;
std::string profileDir = applicationDir + "\\" + "testGL_profile";
LLQtWebKit::getInstance()->init(applicationDir, componentDir, profileDir, 0);
mBrowserWindowId = LLQtWebKit::getInstance()->createBrowserWindow(width(), height());
// observer events that LLQtWebKit emits
LLQtWebKit::getInstance()->addObserver( mBrowserWindowId, this );
// append details to agent string
LLQtWebKit::getInstance()->setBrowserAgentId("testqtapp");
// don't flip bitmap
LLQtWebKit::getInstance()->flipWindow(mBrowserWindowId, false);
// test Second Life viewer specific functions
LLQtWebKit::getInstance()->setSLObjectEnabled( true ); // true means feature is turned on
LLQtWebKit::getInstance()->setAgentLanguage( "tst-en" ); // viewer language selected by agent
LLQtWebKit::getInstance()->setAgentRegion( "QtTestAppRegion" ); // name of region where agent is located
LLQtWebKit::getInstance()->setAgentLocation( 9.8, 7.6, 5.4 ); // agent's x,y,z location within a region
LLQtWebKit::getInstance()->setAgentGlobalLocation( 119.8, 227.6, 335.4 ); // agent's x,y,z location within the grid
LLQtWebKit::getInstance()->setAgentMaturity( "Very immature" ); // selected maturity level of agent
LLQtWebKit::getInstance()->setAgentOrientation( (rand()%36000)/100.0f ); // direction avatar is facing
LLQtWebKit::getInstance()->emitLocation();
LLQtWebKit::getInstance()->emitLanguage();
LLQtWebKit::getInstance()->emitMaturity();
// go to the "home page"
LLQtWebKit::getInstance()->navigateTo(mBrowserWindowId, "http://callum-linden.s3.amazonaws.com/browsertest.html");
}
WebPage::~WebPage()
{
// unhook observer
LLQtWebKit::getInstance()->remObserver( mBrowserWindowId, this );
// clean up
LLQtWebKit::getInstance()->reset();
}
void WebPage::updateSLvariables()
{
// randomly update SL values to test
LLQtWebKit::getInstance()->setAgentOrientation( (rand()%36000)/100.0f );
LLQtWebKit::getInstance()->setAgentLocation( (rand()%25600)/100.0f, (rand()%25600)/100.0f, (rand()%25600)/100.0f );
LLQtWebKit::getInstance()->setAgentGlobalLocation( (rand()%25600)/100.0f, (rand()%25600)/100.0f, (rand()%25600)/100.0f );
if ( rand() % 2 )
LLQtWebKit::getInstance()->setAgentLanguage( "One language" );
else
LLQtWebKit::getInstance()->setAgentLanguage( "Another language" );
if ( rand() % 2 )
LLQtWebKit::getInstance()->setAgentRegion( "Region Wibble" );
else
LLQtWebKit::getInstance()->setAgentRegion( "Region Flasm" );
if ( rand() % 2 )
LLQtWebKit::getInstance()->setAgentMaturity( "Adults only" );
else
LLQtWebKit::getInstance()->setAgentMaturity( "Children only" );
LLQtWebKit::getInstance()->emitLocation();
LLQtWebKit::getInstance()->emitLanguage();
LLQtWebKit::getInstance()->emitMaturity();
}
void WebPage::onCursorChanged(const EventType& event)
{
//qDebug() << __FUNCTION__ << QString::fromStdString(event.getEventUri());
switch (event.getIntValue()) {
case LLQtWebKit::C_ARROW: setCursor(QCursor(Qt::ArrowCursor)); break;
case LLQtWebKit::C_IBEAM: setCursor(QCursor(Qt::IBeamCursor)); break;
case LLQtWebKit::C_SPLITV: setCursor(QCursor(Qt::SplitHCursor)); break;
case LLQtWebKit::C_SPLITH: setCursor(QCursor(Qt::SplitVCursor)); break;
case LLQtWebKit::C_POINTINGHAND: setCursor(QCursor(Qt::PointingHandCursor)); break;
default: break;
}
}
void WebPage::onPageChanged(const EventType& event)
{
Q_UNUSED(event);
LLQtWebKit::getInstance()->grabBrowserWindow( mBrowserWindowId );
//qDebug() << __FUNCTION__ << QString::fromStdString(event.getEventUri());
update();
}
void WebPage::onNavigateBegin(const EventType& event)
{
Q_UNUSED(event);
//qDebug() << __FUNCTION__ << QString::fromStdString(event.getEventUri());
}
void WebPage::onNavigateComplete(const EventType& event)
{
Q_UNUSED(event);
//qDebug() << __FUNCTION__ << QString::fromStdString(event.getEventUri());
}
void WebPage::onUpdateProgress(const EventType& event)
{
Q_UNUSED(event);
}
void WebPage::onStatusTextChange(const EventType& event)
{
Q_UNUSED(event);
}
void WebPage::onLocationChange(const EventType& event)
{
//qDebug() << __FUNCTION__;
emit locationChanged(QString::fromStdString(event.getEventUri()));
//void canGoBack(bool);
//void canGoForward(bool);
}
void WebPage::onClickLinkHref(const EventType& event)
{
Q_UNUSED(event);
}
void WebPage::onClickLinkNoFollow(const EventType& event)
{
Q_UNUSED(event);
}
void WebPage::resizeEvent(QResizeEvent *event)
{
LLQtWebKit::getInstance()->setSize(mBrowserWindowId, event->size().width(), event->size().height());
QWidget::resizeEvent(event);
}
void WebPage::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
int width = LLQtWebKit::getInstance()->getBrowserWidth(mBrowserWindowId);
int height = LLQtWebKit::getInstance()->getBrowserHeight(mBrowserWindowId);
const unsigned char* pixels = LLQtWebKit::getInstance()->getBrowserWindowPixels(mBrowserWindowId);
QImage image(pixels, width, height, QImage::Format_RGB32);
image = image.rgbSwapped();
QPainter painter(this);
painter.drawImage(QPoint(0, 0), image);
}
void WebPage::mouseDoubleClickEvent(QMouseEvent *event)
{
LLQtWebKit::getInstance()->mouseEvent( mBrowserWindowId,
LLQtWebKit::ME_MOUSE_DOUBLE_CLICK,
LLQtWebKit::MB_MOUSE_BUTTON_LEFT,
event->x(), event->y(),
LLQtWebKit::KM_MODIFIER_NONE );
}
void WebPage::mouseMoveEvent(QMouseEvent *event)
{
updateSLvariables();
LLQtWebKit::getInstance()->mouseEvent( mBrowserWindowId,
LLQtWebKit::ME_MOUSE_MOVE,
LLQtWebKit::MB_MOUSE_BUTTON_LEFT,
event->x(), event->y(),
LLQtWebKit::KM_MODIFIER_NONE );
}
void WebPage::mousePressEvent(QMouseEvent *event)
{
LLQtWebKit::getInstance()->mouseEvent( mBrowserWindowId,
LLQtWebKit::ME_MOUSE_DOWN,
LLQtWebKit::MB_MOUSE_BUTTON_LEFT,
event->x(), event->y(),
LLQtWebKit::KM_MODIFIER_NONE );
}
void WebPage::mouseReleaseEvent(QMouseEvent *event)
{
LLQtWebKit::getInstance()->mouseEvent( mBrowserWindowId,
LLQtWebKit::ME_MOUSE_UP,
LLQtWebKit::MB_MOUSE_BUTTON_LEFT,
event->x(), event->y(),
LLQtWebKit::KM_MODIFIER_NONE );
LLQtWebKit::getInstance()->focusBrowser(mBrowserWindowId, true);
}
void WebPage::keyPressEvent(QKeyEvent *event)
{
Q_UNUSED(event);
}
void WebPage::keyReleaseEvent(QKeyEvent *event)
{
Q_UNUSED(event);
//LLQtWebKit::getInstance()->unicodeInput(mBrowserWindowId, event->text().at(0).unicode(),LLQtWebKit::KM_MODIFIER_NONE);
}
void WebPage::goBack()
{
LLQtWebKit::getInstance()->userAction(mBrowserWindowId, LLQtWebKit::UA_NAVIGATE_BACK);
}
void WebPage::goForward()
{
LLQtWebKit::getInstance()->userAction(mBrowserWindowId, LLQtWebKit::UA_NAVIGATE_FORWARD);
}
void WebPage::reload()
{
LLQtWebKit::getInstance()->userAction(mBrowserWindowId, LLQtWebKit::UA_NAVIGATE_RELOAD);
}
void WebPage::loadUrl(const QString &url)
{
LLQtWebKit::getInstance()->navigateTo(mBrowserWindowId, url.toStdString());
}
#include "ui_window.h"
class Window : public QDialog, public Ui_Dialog
{
Q_OBJECT
public:
Window(QWidget *parent = 0);
public slots:
void loadUrl();
};
Window::Window(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
connect(webpage, SIGNAL(locationChanged(const QString &)),
location, SLOT(setText(const QString &)));
connect(webpage, SIGNAL(canGoBack(bool)),
backButton, SLOT(setEnabled(bool)));
connect(webpage, SIGNAL(canGoForward(bool)),
forwardButton, SLOT(setEnabled(bool)));
connect(backButton, SIGNAL(clicked()),
webpage, SLOT(goBack()));
connect(forwardButton, SIGNAL(clicked()),
webpage, SLOT(goForward()));
connect(reloadButton, SIGNAL(clicked()),
webpage, SLOT(reload()));
connect(location, SIGNAL(returnPressed()),
this, SLOT(loadUrl()));
}
void Window::loadUrl()
{
webpage->loadUrl(location->text());
}
int main(int argc, char **argv)
{
QApplication application(argc, argv);
Window window;
window.show();
return application.exec();
}
#include "main.moc"

View File

@@ -0,0 +1,38 @@
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
INCLUDEPATH += ../../
CONFIG -= app_bundle
include(../../static.pri)
QT += webkit opengl network
unix {
LIBS += $$PWD/../../libllqtwebkit.a
}
!mac {
unix {
DEFINES += LL_LINUX
}
}
mac {
DEFINES += LL_OSX
}
win32{
DEFINES += _WINDOWS
INCLUDEPATH += ../
DESTDIR=../build
release {
LIBS += $$PWD/../../Release/llqtwebkit.lib
}
}
# Input
SOURCES += main.cpp
FORMS += window.ui

View File

@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>766</width>
<height>613</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<item>
<widget class="QToolButton" name="backButton">
<property name="text">
<string>←</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="forwardButton">
<property name="text">
<string>→</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="reloadButton">
<property name="text">
<string>↺</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="location"/>
</item>
</layout>
</item>
<item>
<widget class="WebPage" name="webpage" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>WebPage</class>
<extends>QWidget</extends>
<header location="global">webpage.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,229 @@
/* Copyright (c) 2006-2010, Linden Research, Inc.
*
* LLQtWebKit Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in GPL-license.txt in this distribution, or online at
* http://secondlifegrid.net/technology-programs/license-virtual-world/viewerlicensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/technology-programs/license-virtual-world/viewerlicensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
*/
#ifndef _WINDOWS
extern "C" {
#include <unistd.h>
}
#endif
#ifdef _WINDOWS
#include <windows.h>
#include <direct.h>
#endif
#include <iostream>
#include <stdlib.h>
#include <fstream>
#ifdef LL_OSX
// I'm not sure why STATIC_QT is getting defined, but the Q_IMPORT_PLUGIN thing doesn't seem to be necessary on the mac.
#undef STATIC_QT
#endif
#ifdef STATIC_QT
#include <QtPlugin>
Q_IMPORT_PLUGIN(qgif)
#endif
#include "llqtwebkit.h"
class sslTest :
public LLEmbeddedBrowserWindowObserver
{
public:
sslTest( std::string url, bool ignore_ca_file, bool ignore_ssl_errors ) :
mBrowserWindowWidth( 512 ),
mBrowserWindowHeight( 512 ),
mBrowserWindowHandle( 0 ),
mNavigateInProgress( true )
{
#ifdef _WINDOWS
std::string cwd = std::string( _getcwd( NULL, 1024) );
std::string profile_dir = cwd + "\\" + "ssltest_profile";
void* native_window_handle = (void*)GetDesktopWindow();
std::string ca_file_loc = cwd + "\\" + "CA.pem";
#else
std::string cwd = std::string( getcwd( NULL, 1024) );
std::string profile_dir = cwd + "/" + "ssltest_profile";
void* native_window_handle = 0;
std::string ca_file_loc = cwd + "/" + "CA.pem";
#endif
std::cout << "ssltest> === begin ===" << std::endl;
std::cout << "ssltest> current working dir is " << cwd << std::endl;
std::cout << "ssltest> profiles dir location is " << profile_dir << std::endl;
LLQtWebKit::getInstance()->init( cwd, cwd, profile_dir, native_window_handle );
LLQtWebKit::getInstance()->enableJavaScript( true );
LLQtWebKit::getInstance()->enablePlugins( true );
mBrowserWindowHandle = LLQtWebKit::getInstance()->createBrowserWindow( mBrowserWindowWidth, mBrowserWindowHeight );
LLQtWebKit::getInstance()->setSize( mBrowserWindowHandle, mBrowserWindowWidth, mBrowserWindowHeight );
LLQtWebKit::getInstance()->addObserver( mBrowserWindowHandle, this );
if ( ! ignore_ca_file )
{
std::cout << "ssltest> Expected certificate authority file location is " << ca_file_loc << std::endl;
LLQtWebKit::getInstance()->setCAFile( ca_file_loc.c_str() );
}
else
{
std::cout << "ssltest> Not loading certificate authority file" << std::endl;
};
if ( ignore_ssl_errors )
{
LLQtWebKit::getInstance()->setIgnoreSSLCertErrors( true );
std::cout << "ssltest> Ignoring SSL errors " << std::endl;
}
else
{
std::cout << "ssltest> Not ignoring SSL errors " << std::endl;
};
LLQtWebKit::getInstance()->navigateTo( mBrowserWindowHandle, url );
std::cout << "ssltest> navigating to " << url << std::endl;
};
bool idle( void )
{
LLQtWebKit::getInstance()->pump( 100 );
#if _WINDOWS
MSG msg;
while ( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
GetMessage( &msg, NULL, 0, 0 );
TranslateMessage( &msg );
DispatchMessage( &msg );
};
#endif
return mNavigateInProgress;
};
~sslTest()
{
LLQtWebKit::getInstance()->remObserver( mBrowserWindowHandle, this );
LLQtWebKit::getInstance()->reset();
std::cout << "ssltest> === end ===" << std::endl;
};
void onNavigateBegin( const EventType& eventIn )
{
mNavigateInProgress = true;
std::cout << "ssltest> Event: begin navigation to " << eventIn.getEventUri() << std::endl;
};
void onNavigateComplete( const EventType& eventIn )
{
std::cout << "ssltest> Event: end navigation to " << eventIn.getEventUri() << std::endl;
mNavigateInProgress = false;
};
void onUpdateProgress( const EventType& eventIn )
{
std::cout << "ssltest> Event: progress value updated to " << eventIn.getIntValue() << std::endl;
};
void onStatusTextChange( const EventType& eventIn )
{
std::cout << "ssltest> Event: status updated to " << eventIn.getStringValue() << std::endl;
};
void onTitleChange( const EventType& eventIn )
{
std::cout << "ssltest> Event: title changed to " << eventIn.getStringValue() << std::endl;
};
void onLocationChange( const EventType& eventIn )
{
std::cout << "ssltest> Event: location changed to " << eventIn.getStringValue() << std::endl;
};
bool onCertError(const std::string &in_url, const std::string &in_msg)
{
std::cout << "ssltest> Cert error triggered\n" << in_url << "\n" << in_msg << std::endl;
return true;
}
private:
int mBrowserWindowWidth;
int mBrowserWindowHeight;
int mBrowserWindowHandle;
bool mNavigateInProgress;
};
int main( int argc, char* argv[] )
{
bool ingore_ssl_errors = false;
bool ignore_ca_file = false;
for( int i = 1; i < argc; ++i )
{
if ( std::string( argv[ i ] ) == "--help" )
{
std::cout << std::endl << "ssltest <url> [--ignoresslerrors] [--ignorecafile]" << std::endl;
std::cout << "Looks for cert file CA.pem in the current working directory";
exit( 0 );
};
if ( std::string( argv[ i ] ) == "--ignoresslerrors" )
ingore_ssl_errors = true;
if ( std::string( argv[ i ] ) == "--ignorecafile" )
ignore_ca_file = true;
};
std::string url ( "https://my.secondlife.com/callum.linden" );
for( int i = 1; i < argc; ++i )
{
if ( std::string( argv[ i ] ).substr( 0, 2 ) != "--" )
{
url = std::string( argv[ i ] );
break;
};
};
std::cout << std::endl << " --------- sslTest application starting --------- " << std::endl;
std::cout << "ssltest> URL specified is " << url << std::endl;
sslTest* app = new sslTest( url, ignore_ca_file, ingore_ssl_errors );
bool result = app->idle();
while( result )
{
result = app->idle();
};
delete app;
std::cout << " --------- sslTest application ending --------- " << std::endl;
return 0;
}

View File

@@ -0,0 +1,28 @@
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
INCLUDEPATH += ../../
CONFIG -= app_bundle
CONFIG += console
QT += webkit network
mac {
DEFINES += LL_OSX
LIBS += $$PWD/libllqtwebkit.dylib
}
win32 {
DEFINES += _WINDOWS
INCLUDEPATH += ../
DESTDIR=../build
LIBS += user32.lib
release {
LIBS += $$PWD/../../Release/llqtwebkit.lib
}
}
include(../../static.pri)
SOURCES += ssltest.cpp

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,38 @@
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
INCLUDEPATH += ../../
CONFIG -= app_bundle
QT += webkit opengl network
!mac {
unix {
DEFINES += LL_LINUX
LIBS += -lglui -lglut
LIBS += $$PWD/../../libllqtwebkit.a
}
}
mac {
DEFINES += LL_OSX
LIBS += -framework GLUT -framework OpenGL
LIBS += $$PWD/libllqtwebkit.dylib
}
win32 {
DEFINES += _WINDOWS
INCLUDEPATH += ../
INCLUDEPATH += $$PWD/../../stage/packages/include
DESTDIR=../build
release {
LIBS += $$PWD/../../Release/llqtwebkit.lib
LIBS += $$PWD/../build/freeglut_static.lib
LIBS += comdlg32.lib
}
}
include(../../static.pri)
SOURCES += testgl.cpp

View File

@@ -0,0 +1,292 @@
/* Copyright (c) 2006-2010, Linden Research, Inc.
*
* LLQtWebKit Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in GPL-license.txt in this distribution, or online at
* http://secondlifegrid.net/technology-programs/license-virtual-world/viewerlicensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/technology-programs/license-virtual-world/viewerlicensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
*/
#ifndef _WINDOWS
extern "C" {
#include <unistd.h>
}
#endif
#ifdef _WINDOWS
#include <windows.h>
#include <direct.h>
#endif
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <ctime>
#include <sstream>
#include <fstream>
#ifdef LL_OSX
// I'm not sure why STATIC_QT is getting defined, but the Q_IMPORT_PLUGIN thing doesn't seem to be necessary on the mac.
#undef STATIC_QT
#endif
#ifdef STATIC_QT
#include <QtPlugin>
Q_IMPORT_PLUGIN(qgif)
#endif
#include "llqtwebkit.h"
class textMode :
public LLEmbeddedBrowserWindowObserver
{
public:
textMode( std::string url, bool ignore_ca_file, bool ignore_ssl_errors ) :
mBrowserWindowWidth( 512 ),
mBrowserWindowHeight( 512 ),
mBrowserWindowHandle( 0 ),
mNavigateInProgress( true ),
mLogLine( "" )
{
#ifdef _WINDOWS
std::string cwd = std::string( _getcwd( NULL, 1024) );
std::string profile_dir = cwd + "\\" + "textmode_profile";
void* native_window_handle = (void*)GetDesktopWindow();
std::string ca_file_loc = cwd + "\\" + "CA.pem";
#else
std::string cwd = std::string( getcwd( NULL, 1024) );
std::string profile_dir = cwd + "/" + "textmode_profile";
void* native_window_handle = 0;
std::string ca_file_loc = cwd + "/" + "CA.pem";
#endif
mLogLine << "Current working dir is " << cwd << std::endl;
mLogLine << "Profiles dir is " << profile_dir;
writeLine( mLogLine.str() );
LLQtWebKit::getInstance()->init( cwd, cwd, profile_dir, native_window_handle );
LLQtWebKit::getInstance()->enableQtMessageHandler( true );
LLQtWebKit::getInstance()->enableJavaScript( true );
LLQtWebKit::getInstance()->enablePlugins( true );
mBrowserWindowHandle = LLQtWebKit::getInstance()->createBrowserWindow( mBrowserWindowWidth, mBrowserWindowHeight );
LLQtWebKit::getInstance()->setSize( mBrowserWindowHandle, mBrowserWindowWidth, mBrowserWindowHeight );
LLQtWebKit::getInstance()->addObserver( mBrowserWindowHandle, this );
if ( ! ignore_ca_file )
{
mLogLine.str("");
mLogLine << "Expected certificate authority file location is " << ca_file_loc;
writeLine( mLogLine.str() );
LLQtWebKit::getInstance()->setCAFile( ca_file_loc.c_str() );
}
else
{
mLogLine.str("");
mLogLine << "Not loading certificate authority file";
writeLine( mLogLine.str() );
};
if ( ignore_ssl_errors )
{
LLQtWebKit::getInstance()->setIgnoreSSLCertErrors( true );
mLogLine.str("");
mLogLine << "Ignoring SSL errors";
writeLine( mLogLine.str() );
}
else
{
mLogLine.str("");
mLogLine << "Not ignoring SSL errors";
writeLine( mLogLine.str() );
};
mLogLine.str("");
mLogLine << "Navigating to " << url;
writeLine( mLogLine.str() );
LLQtWebKit::getInstance()->navigateTo( mBrowserWindowHandle, url );
};
bool idle( void )
{
LLQtWebKit::getInstance()->pump( 100 );
#if _WINDOWS
MSG msg;
while ( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
GetMessage( &msg, NULL, 0, 0 );
TranslateMessage( &msg );
DispatchMessage( &msg );
};
#endif
return mNavigateInProgress;
};
~textMode()
{
LLQtWebKit::getInstance()->remObserver( mBrowserWindowHandle, this );
LLQtWebKit::getInstance()->reset();
};
void onNavigateBegin( const EventType& eventIn )
{
mNavigateInProgress = true;
mLogLine.str("");
mLogLine << "Event: Begin navigation to " << eventIn.getEventUri();
writeLine( mLogLine.str() );
};
void onNavigateComplete( const EventType& eventIn )
{
mLogLine.str("");
mLogLine << "Event: End navigation to " << eventIn.getEventUri();
writeLine( mLogLine.str() );
mNavigateInProgress = false;
};
void onUpdateProgress( const EventType& eventIn )
{
mLogLine.str("");
mLogLine << "Event: progress value updated to " << eventIn.getIntValue();
writeLine( mLogLine.str() );
};
void onStatusTextChange( const EventType& eventIn )
{
mLogLine.str("");
mLogLine << "Event: status updated to " << eventIn.getStringValue();
writeLine( mLogLine.str() );
};
void onTitleChange( const EventType& eventIn )
{
mLogLine.str("");
mLogLine << "Event: title change to " << eventIn.getStringValue();
writeLine( mLogLine.str() );
};
void onLocationChange( const EventType& eventIn )
{
mLogLine.str("");
mLogLine << "Event: location changed to " << eventIn.getStringValue();
writeLine( mLogLine.str() );
};
bool onCertError(const std::string &in_url, const std::string &in_msg)
{
mLogLine.str("");
mLogLine << "Cert error triggered: " << std::endl << in_url << "\n" << in_msg;
writeLine( mLogLine.str() );
return true;
}
void onCookieChanged(const EventType& event)
{
std::string url = event.getEventUri();
std::string cookie = event.getStringValue();
int dead = event.getIntValue();
mLogLine.str("");
if ( ! dead )
mLogLine << "Cookie added:" << cookie;
else
mLogLine << "Cookie deleted:" << cookie;
writeLine( mLogLine.str() );
}
virtual void onQtDebugMessage( const std::string& msg, const std::string& msg_type)
{
mLogLine.str("");
mLogLine << "QtDebugMsg (" << msg_type << "): " << msg.substr(msg.length() - 1);
writeLine( mLogLine.str() );
}
void writeLine( std::string line )
{
double elapsed_seconds = (double)clock() / (double)CLOCKS_PER_SEC;
std::cout << "[" << std::setprecision(7) << std::setw(3) << std::setfill('0') << elapsed_seconds << "] ";
const int max_len = 140;
if ( line.length() > max_len )
{
std::cout << line.substr(0, max_len);
std::cout << "....";
}
else
{
std::cout << line;
}
std::cout << std::endl;
//std::cout << std::endl;
}
private:
int mBrowserWindowWidth;
int mBrowserWindowHeight;
int mBrowserWindowHandle;
bool mNavigateInProgress;
std::ostringstream mLogLine;
};
int main( int argc, char* argv[] )
{
bool ingore_ssl_errors = false;
bool ignore_ca_file = false;
for( int i = 1; i < argc; ++i )
{
if ( std::string( argv[ i ] ) == "--help" )
{
std::cout << std::endl << "textmode <url>" << std::endl;
exit( 0 );
};
if ( std::string( argv[ i ] ) == "--ignoresslerrors" )
ingore_ssl_errors = true;
if ( std::string( argv[ i ] ) == "--ignorecafile" )
ignore_ca_file = true;
};
std::string url ( "https://my.secondlife.com/callum.linden" );
for( int i = 1; i < argc; ++i )
{
if ( std::string( argv[ i ] ).substr( 0, 2 ) != "--" )
{
url = std::string( argv[ i ] );
break;
};
};
textMode* app = new textMode( url, ignore_ca_file, ingore_ssl_errors );
bool result = app->idle();
while( result )
{
result = app->idle();
};
delete app;
return 0;
}

View File

@@ -0,0 +1,28 @@
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
INCLUDEPATH += ../../
CONFIG -= app_bundle
CONFIG += console
QT += webkit network
mac {
DEFINES += LL_OSX
LIBS += $$PWD/libllqtwebkit.dylib
}
win32 {
DEFINES += _WINDOWS
INCLUDEPATH += ../
DESTDIR=../build
LIBS += user32.lib
release {
LIBS += $$PWD/../../Release/llqtwebkit.lib
}
}
include(../../static.pri)
SOURCES += textmode.cpp