免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2060 | 回复: 0
打印 上一主题 下一主题

gtk+gtkmozembed linux嵌入firefox [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-20 17:25 |只看该作者 |倒序浏览
@auth:gulunmu@163.com

@date:2008-04-13

@des:linux下应用gtkmozembed+gtk嵌入firefox,处理绘图完成后的dom树

code: test.cpp

#include <gtk/gtk.h>
#include <gtkmozembed.h>
#include "gtkmozembed_internal.h"

//#include "MozillaBrowserXPCOM.h"
//#include "XPCOMUtil.h"


#include <nsIURIContentListener.h>
#include <nsIWebBrowser.h>


#include "nsXPCOM.h"
#include "nscore.h"
#include "nsEmbedAPI.h"
#include "nsWeakReference.h"
#include "nsIWebBrowserChrome.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsCOMPtr.h"
#include "nsIInterfaceRequestor.h"
#include "nsEmbedString.h"
#include "nsIWebBrowser.h"
#include "widget/nsIBaseWindow.h"
#include "nsEmbedCID.h"
#include "nsComponentManagerUtils.h"
#include "nsIWebProgressListener.h"
#include "docshell/nsIWebNavigation.h"
#include "docshell/nsIDocShellTreeItem.h"
#include "iostream"

//dom
#include <nsIDOMCSSStyleDeclaration.h>
#include <nsIDOMDocument.h>
#include <nsIDOMDocumentFragment.h>
#include <nsIDOMDocumentRange.h>
#include <nsIDOMElement.h>
#include <nsIDOMElementCSSInlineStyle.h>
#include <nsIDOMMouseEvent.h>
//#include "nsIDOMNSHTMLElement.h"
//#include "nsIDOMNSRange.h"
#include <nsIDOMNodeList.h>
#include <nsIDOMRange.h>
#include <nsIDOMWindow.h>

#define HAS_WEBBROWSER 1


//extern void gtk_moz_embed_get_nsIWebBrowser(GtkMozEmbed *embed, nsIWebBrowser **retval);
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *label;
GtkWidget *mozembed;
GtkWidget *container;
char *url;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);


///////////////////////////////////////////////////////
mozembed = gtk_moz_embed_new();

gtk_signal_connect(GTK_OBJECT(mozembed), "destroy",
    GTK_SIGNAL_FUNC(gtk_main_quit),
    NULL);


gtk_container_add(GTK_CONTAINER(window), mozembed);

/////////////////////////////////////////////////////

gtk_widget_set_usize(window, 800,600);
gtk_widget_show(mozembed);
gtk_widget_show(label);
gtk_widget_show_all(window);

//url = (argc > 1) ? argv[1] : (char *)"www.google.com";
//gtk_moz_embed_load_url(GTK_MOZ_EMBED(mozembed), url);

////////////////////////////////////////////////////
#ifdef HAS_WEBBROWSER
nsCOMPtr<nsIBaseWindow> baseWindow;
nsCOMPtr<nsIWebBrowser> webBrowser;
nsresult rv;


gtk_moz_embed_get_nsIWebBrowser(GTK_MOZ_EMBED(mozembed), getter_AddRefs(webBrowser));
if( webBrowser == nsnull )
{
   printf("webBrowser load error ");
   return -1;
}
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(webBrowser, &rv);
if ( NS_FAILED(rv) ) return rv;
printf(" get nsIWebNavigation success.\n");


baseWindow = do_QueryInterface(webBrowser, &rv);
if ( NS_FAILED(rv) ) return rv;
printf("baseWindow queried.\n");


char asciiURI[] = "http://www.baidu.com";
nsString nsURI = NS_ConvertUTF8toUTF16( asciiURI, strlen(asciiURI) );
if(webNav)
   webNav->LoadURI(nsURI.get(),
     nsIWebNavigation::LOAD_FLAGS_NONE, // Load flags
     nsnull,                            // Referring URI
     nsnull,                            // Post data
     nsnull);

printf("load uri success.\n");

//begin to deal dom
nsCOMPtr<nsIDOMWindow>    DOMWindow;
nsCOMPtr<nsIDOMDocument>       DOMDocument;
webBrowser->GetContentDOMWindow(getter_AddRefs(DOMWindow));
if(nsnull == DOMWindow) {
   g_warning("could not retrieve DOM window...");
   return -1;
}

rv = DOMWindow->GetDocument(getter_AddRefs(DOMDocument));
if( NS_FAILED(rv)) return rv;
      

    //end ceal dom
#endif
    //
    ////////////////////////////////////////////////////
    gtk_main();

    return 0;
    }

makefile:

MOZ_ROOT=/mozilla/xulrunner-build

LDFLAGS=-lpthread -Wl,-rpath -Wl,${MOZ_ROOT}/dist/bin/ -Wl,-rpath -Wl,${MOZ_ROOT}/dist/lib -L${MOZ_ROOT}/dist/lib/ -lxpcom -lnspr4

CXXFLAGS= -ggdb -fno-rtti -fno-exceptions -Wall -Wconversion -Wpointer-arith -Wcast-align -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wno-long-long -pedantic -fshort-wchar -pthread -pipe -DDEGUG -D_DEBUG -DDEBUG_root -DTRACTING -fno-inline -O -DNDEBUG -DTRIMMED -O -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12

COMPILE_CFLAGS= -I ${MOZ_ROOT}/dist/include/system_wrappers -include ${MOZ_ROOT}/../config/gcc_hidden.h -DMOZILLA_STRICT_API -DOSTYPE="Linux2.6.23.1" -DOSARCH="Linux" -DBUILD_ID=0000000000 -I ${MOZ_ROOT}/dist/include/xpcom -I${MOZ_ROOT}/dist/include/intl -I${MOZ_ROOT}/dist/include/embedcomponents -I${MOZ_ROOT}/dist/include   -I${MOZ_ROOT}/dist/include/embed_base -I${MOZ_ROOT}/dist/include/nspr -I${MOZ_ROOT}/dist/include/gtkembedmoz -DMOZ_PNG_READ -DMOZ_PNG_WRITE   -I${MOZ_ROOT}/dist/sdk/include -Wall -W -Wno-unused -Wpointer-arith -Wcast-align -Wno-long-long -pedantic -pthread -pipe -DNDEBUG -DTRIMMED -O   -include ${MOZ_ROOT}/mozilla-config.h -DMOZILLA_CLIENT

all: TTest

#TTest: test.o
# g++ -o TTest $(LDFLAGS) `pkg-config --libs gtk+-2.0` test.o ${MOZ_ROOT}/embedding/base/libembed_base_s.a ${MOZ_ROOT}/xpcom/glue/standalone/libxpcomglue.a ${MOZ_ROOT}/embedding/base/libembed_base_s.a

TTest: test.o
g++ -o TTest $(LDFLAGS) `pkg-config --libs gtk+-2.0` test.o ${MOZ_ROOT}/embedding/base/libembed_base_s.a -L${MOZ_ROOT}/dist/lib -lxpcomglue ${MOZ_ROOT}/embedding/base/libembed_base_s.a -lgtkembedmoz


test.o:test.cpp
g++ -c $(CXXFLAGS) $(COMPILE_CFLAGS) `pkg-config --cflags gtk+-2.0` $< -o $@

clean:
rm *.o TTest
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP