⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mozembed.cpp

📁 JDesktop Integration Components (JDIC)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* vim:set ts=4 sw=4 sts=4 et cin: *//* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is * Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard.  All Rights Reserved. * Portions created by the Initial Developer are Copyright (C) 2001 * the Initial Developer. All Rights Reserved. * * Contributor(s): *   Christopher Blizzard <blizzard@mozilla.org> * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */#include "MozEmbed.h"#include "MsgServer.h"#include "Message.h"#include "Common.h"// These are included from the Gecko SDK#include "prenv.h"#include "prthread.h"#include "nsXPCOM.h"#include "nsEmbedString.h"#include "nsDebug.h"#include "nsMemory.h"#include "nsIURI.h"#include "nsIComponentManager.h"// These are currently not part of the Gecko SDK, so we include our local// copy of these files.  If these interfaces ever change in the future, then// our application may stop working.#include "nsIWebNavigation.h"#include "nsIStringStream.h"//-----------------------------------------------------------------------------//-----------------------------------------------------------------------------int gTestMode = 0;// the list of pending messagesGList *gMessageList = NULL;// the lock of locking the gMessageListPRLock *gMsgLock;// the array of browser windows currently openWBArray gBrowserArray;//cached url for postchar gCachedURL[1024];// the new event source for socket message#ifdef MOZ_WIDGET_GTKstatic GSourceFuncs event_funcs = {    gs_prepare_cb,    gs_check_cb,    gs_dispatch_cb,};#endif#ifdef MOZ_WIDGET_GTK2static GSourceFuncs event_funcs = {    gs_prepare_cb,    gs_check_cb,    gs_dispatch_cb,};#endifGtkBrowser *new_gtk_browser(guint32 chromeMask){    guint32 actualChromeMask = chromeMask;    GtkBrowser *browser = 0;    browser = g_new0(GtkBrowser, 1);    browser->menuBarOn = FALSE;    browser->toolBarOn = FALSE;    browser->locationBarOn = FALSE;    browser->statusBarOn = FALSE;    g_print("new_gtk_browser\n");    if (chromeMask == GTK_MOZ_EMBED_FLAG_DEFAULTCHROME)        actualChromeMask = GTK_MOZ_EMBED_FLAG_ALLCHROME;    if (actualChromeMask & GTK_MOZ_EMBED_FLAG_MENUBARON)    {        browser->menuBarOn = TRUE;        g_print("\tmenu bar\n");    }    if (actualChromeMask & GTK_MOZ_EMBED_FLAG_TOOLBARON)    {        browser->toolBarOn = TRUE;        g_print("\ttool bar\n");    }    if (actualChromeMask & GTK_MOZ_EMBED_FLAG_LOCATIONBARON)    {        browser->locationBarOn = TRUE;        g_print("\tlocation bar\n");    }    if (actualChromeMask & GTK_MOZ_EMBED_FLAG_STATUSBARON)    {        browser->statusBarOn = TRUE;        g_print("\tstatus bar\n");    }    // create our new toplevel window    browser->topLevelWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);    // new vbox    browser->topLevelVBox = gtk_vbox_new(FALSE, 0);    // add it to the toplevel window    gtk_container_add(GTK_CONTAINER(browser->topLevelWindow),        browser->topLevelVBox);    // create our menu bar    browser->menuBar = gtk_menu_bar_new();    // create the file menu    browser->fileMenuItem = gtk_menu_item_new_with_label("File");    browser->fileMenu = gtk_menu_new();    gtk_menu_item_set_submenu (GTK_MENU_ITEM(browser->fileMenuItem),        browser->fileMenu);    browser->fileClose =        gtk_menu_item_new_with_label("Close");    gtk_menu_append(GTK_MENU(browser->fileMenu),        browser->fileClose);    // append it    gtk_menu_bar_append(GTK_MENU_BAR(browser->menuBar), browser->fileMenuItem);    // add it to the vbox    gtk_box_pack_start(GTK_BOX(browser->topLevelVBox),        browser->menuBar,        FALSE, // expand        FALSE, // fill        0);    // padding    // create the hbox that will contain the toolbar and the url text entry bar    browser->toolbarHBox = gtk_hbox_new(FALSE, 0);    // add that hbox to the vbox    gtk_box_pack_start(GTK_BOX(browser->topLevelVBox),        browser->toolbarHBox,        FALSE, // expand        FALSE, // fill        0);    // padding    // new horiz toolbar with buttons + icons#ifdef MOZ_WIDGET_GTK    browser->toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,        GTK_TOOLBAR_BOTH);#endif /* MOZ_WIDGET_GTK */#ifdef MOZ_WIDGET_GTK2    browser->toolbar = gtk_toolbar_new();    gtk_toolbar_set_orientation(GTK_TOOLBAR(browser->toolbar),        GTK_ORIENTATION_HORIZONTAL);    gtk_toolbar_set_style(GTK_TOOLBAR(browser->toolbar),        GTK_TOOLBAR_BOTH);#endif /* MOZ_WIDGET_GTK2 */    // add it to the hbox    gtk_box_pack_start(GTK_BOX(browser->toolbarHBox), browser->toolbar,        FALSE, // expand        FALSE, // fill        0);    // padding    // new back button    browser->backButton =        gtk_toolbar_append_item(GTK_TOOLBAR(browser->toolbar),        "Back",        "Go Back",        "Go Back",        0, // XXX replace with icon        GTK_SIGNAL_FUNC(back_clicked_cb),        browser);    // new stop button    browser->stopButton =        gtk_toolbar_append_item(GTK_TOOLBAR(browser->toolbar),        "Stop",        "Stop",        "Stop",        0, // XXX replace with icon        GTK_SIGNAL_FUNC(stop_clicked_cb),        browser);    // new forward button    browser->forwardButton =        gtk_toolbar_append_item(GTK_TOOLBAR(browser->toolbar),        "Forward",        "Forward",        "Forward",        0, // XXX replace with icon        GTK_SIGNAL_FUNC(forward_clicked_cb),        browser);    // new reload button    browser->reloadButton =        gtk_toolbar_append_item(GTK_TOOLBAR(browser->toolbar),        "Reload",        "Reload",        "Reload",        0, // XXX replace with icon        GTK_SIGNAL_FUNC(reload_clicked_cb),        browser);    // create the url text entry    browser->urlEntry = gtk_entry_new();    // add it to the hbox    gtk_box_pack_start(GTK_BOX(browser->toolbarHBox), browser->urlEntry,        TRUE, // expand        TRUE, // fill        0);    // padding    // create our new gtk moz embed widget    browser->mozEmbed = gtk_moz_embed_new();    // add it to the toplevel vbox    gtk_box_pack_start(GTK_BOX(browser->topLevelVBox), browser->mozEmbed,        TRUE, // expand        TRUE, // fill        0);   // padding    // create the new hbox for the progress area    browser->progressAreaHBox = gtk_hbox_new(FALSE, 0);    // add it to the vbox    gtk_box_pack_start(GTK_BOX(browser->topLevelVBox), browser->progressAreaHBox,        FALSE, // expand        FALSE, // fill        0);   // padding    // create our new progress bar    browser->progressBar = gtk_progress_bar_new();    // add it to the hbox    gtk_box_pack_start(GTK_BOX(browser->progressAreaHBox), browser->progressBar,        FALSE, // expand        FALSE, // fill        0); // padding    // create our status area and the alignment object that will keep it    // from expanding    browser->statusAlign = gtk_alignment_new(0, 0, 1, 1);    gtk_widget_set_usize(browser->statusAlign, 1, -1);    // create the status bar    browser->statusBar = gtk_statusbar_new();    gtk_container_add(GTK_CONTAINER(browser->statusAlign), browser->statusBar);    // add it to the hbox    gtk_box_pack_start(GTK_BOX(browser->progressAreaHBox), browser->statusAlign,        TRUE, // expand        TRUE, // fill        0);   // padding    // by default none of the buttons are marked as sensitive.    gtk_widget_set_sensitive(browser->backButton, FALSE);    gtk_widget_set_sensitive(browser->stopButton, FALSE);    gtk_widget_set_sensitive(browser->forwardButton, FALSE);    gtk_widget_set_sensitive(browser->reloadButton, FALSE);    // catch the destruction of the toplevel window    gtk_signal_connect(GTK_OBJECT(browser->topLevelWindow), "delete_event",        GTK_SIGNAL_FUNC(delete_cb), browser);    // hook up the activate signal to the right callback    gtk_signal_connect(GTK_OBJECT(browser->urlEntry), "activate",        GTK_SIGNAL_FUNC(url_activate_cb), browser);    // close this window    gtk_signal_connect(GTK_OBJECT(browser->fileClose), "activate",        GTK_SIGNAL_FUNC(menu_close_cb), browser);    install_mozembed_cb(browser);    // set the chrome type so it's stored in the object    gtk_moz_embed_set_chrome_mask(GTK_MOZ_EMBED(browser->mozEmbed),        actualChromeMask);    return browser;}voidset_browser_visibility (GtkBrowser *browser, gboolean visibility){    if (!visibility)    {        gtk_widget_hide(browser->topLevelWindow);        return;    }    if (browser->menuBar) {        if (browser->menuBarOn)            gtk_widget_show_all(browser->menuBar);        else            gtk_widget_hide_all(browser->menuBar);    }    if (browser->toolbarHBox) {        // since they are on the same line here...        if (browser->toolBarOn || browser->locationBarOn)            gtk_widget_show_all(browser->toolbarHBox);        else            gtk_widget_hide_all(browser->toolbarHBox);    }    if (browser->progressAreaHBox) {        if (browser->statusBarOn)            gtk_widget_show_all(browser->progressAreaHBox);        else            gtk_widget_hide_all(browser->progressAreaHBox);    }    if (browser->mozEmbed)        gtk_widget_show(browser->mozEmbed);    if (browser->topLevelVBox)        gtk_widget_show(browser->topLevelVBox);    if (browser->topLevelWindow)        gtk_widget_show(browser->topLevelWindow);}voidOpenURL(GtkBrowser *pBrowser, const char *pUrl, const char *pPostData, const char *pHeader){    nsresult rv;    nsCOMPtr<nsIInputStream> postDataStream;    nsCOMPtr<nsIInputStream> headersStream;    if (pPostData)     {        unsigned long nSizeData = strlen(pPostData);        if (nSizeData > 0)         {            char szCL[64];            sprintf(szCL, "Content-Length: %lu\r\n\r\n", nSizeData);            unsigned long nSizeCL = strlen(szCL);            unsigned long nSize = nSizeCL + nSizeData;            char *tmp = (char *) nsMemory::Alloc(nSize + 1); // byte stream owns this mem            if (tmp)             {                memcpy(tmp, szCL, nSizeCL);                memcpy(tmp + nSizeCL, pPostData, nSizeData);                tmp[nSize] = '\0';                nsCOMPtr<nsIStringInputStream> stream;                rv = CreateInstance("@mozilla.org/io/string-input-stream;1",                                    NS_GET_IID(nsIStringInputStream),                                    getter_AddRefs(stream));                if (NS_FAILED(rv) || !stream)                 {                    NS_ASSERTION(0, "cannot create PostData stream");                    nsMemory::Free(tmp);                    return;                }                stream->AdoptData(tmp, nSize);                postDataStream = do_QueryInterface(stream);            }        }    }        if (pHeader)     {        unsigned long nSize = strlen(pHeader) + 1;        if (nSize > 0)         {            char *tmp = (char *) nsMemory::Alloc(nSize); // byteArray stream owns this mem            if (tmp)             {                memcpy(tmp, pHeader, nSize);                nsCOMPtr<nsIStringInputStream> stream;                rv = CreateInstance("@mozilla.org/io/string-input-stream;1",                                    NS_GET_IID(nsIStringInputStream),                                    getter_AddRefs(stream));                if (NS_FAILED(rv) || !stream)                 {                    NS_ASSERTION(0, "cannot create Header stream");                    nsMemory::Free(tmp);                    return;                }                stream->AdoptData(tmp, nSize);                headersStream = do_QueryInterface(stream);            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -