зеркало из https://github.com/mozilla/gecko-dev.git
fix bug #41820. The gtk embedding widget will now startup and shutdown XPCOM properly. Also, fix code that was broken when the nsIWebProgress changes happened. Only build tests when tests are built. Add interface to get the nsIWebBrowser object from the embedding widget. r=dougt,bryner a=brendan
This commit is contained in:
Родитель
f1382a220f
Коммит
ae64676a46
|
@ -25,6 +25,10 @@ VPATH = @srcdir@
|
|||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS=src tests
|
||||
DIRS=src
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += tests
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -642,7 +642,7 @@ NS_IMETHODIMP GtkMozEmbedChrome::OnProgressChange(nsIWebProgress *progress, nsIR
|
|||
// call our callback if it's been registered
|
||||
if (mProgressCB)
|
||||
mProgressCB(mProgressCBData, curTotalProgress, maxTotalProgress);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GtkMozEmbedChrome::OnStateChange(nsIWebProgress *progress, nsIRequest *request,
|
||||
|
|
|
@ -32,11 +32,15 @@ REQUIRES = xpcom
|
|||
CPPSRCS = \
|
||||
GtkMozEmbedChrome.cpp \
|
||||
GtkMozEmbedStream.cpp \
|
||||
nsSetupRegistry.cpp \
|
||||
gtkmozembed.cpp
|
||||
|
||||
SHARED_LIBRARY_LIBS= \
|
||||
$(DIST)/lib/libembed_base_s.$(LIB_SUFFIX) \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
gtkmozembed.h
|
||||
gtkmozembed.h \
|
||||
gtkmozembed_internal.h
|
||||
|
||||
EXTRA_DSO_LDOPTS = \
|
||||
$(MOZ_COMPONENT_LIBS) \
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include "gtkmozembed.h"
|
||||
#include "gtkmozembed_internal.h"
|
||||
#include "nsIWebBrowser.h"
|
||||
#include "nsCWebBrowser.h"
|
||||
#include "nsIWebBrowserChrome.h"
|
||||
|
@ -32,6 +33,7 @@
|
|||
#include "nsIEventQueueService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsEmbedAPI.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
|
@ -65,6 +67,10 @@ enum {
|
|||
|
||||
static guint moz_embed_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static char *component_path = NULL;
|
||||
static gint num_widgets = 0;
|
||||
static gint io_identifier = 0;
|
||||
|
||||
/* class and instance initialization */
|
||||
|
||||
static void
|
||||
|
@ -132,13 +138,14 @@ gtk_moz_embed_handle_destroy(void *aData);
|
|||
static PRBool
|
||||
gtk_moz_embed_handle_open_uri(const char *aURI, void *aData);
|
||||
|
||||
static gboolean
|
||||
gtk_moz_embed_startup_xpcom(void);
|
||||
|
||||
static void
|
||||
gtk_moz_embed_shutdown_xpcom(void);
|
||||
|
||||
static GtkBinClass *parent_class;
|
||||
|
||||
static PRBool NS_SetupRegistryCalled = PR_FALSE;
|
||||
static PRBool ThreadQueueSetup = PR_FALSE;
|
||||
|
||||
extern "C" void NS_SetupRegistry();
|
||||
|
||||
// we use this for adding callbacks to the C++ code that doesn't know
|
||||
// anything about the GtkMozEmbed class
|
||||
typedef void (*generic_cb_with_data) (void *);
|
||||
|
@ -187,38 +194,7 @@ gtk_moz_embed_class_init(GtkMozEmbedClass *klass)
|
|||
|
||||
object_class->destroy = gtk_moz_embed_destroy;
|
||||
|
||||
// check to see if NS_SetupRegistry has been called
|
||||
if (!NS_SetupRegistryCalled)
|
||||
{
|
||||
NS_SetupRegistry();
|
||||
NS_SetupRegistryCalled = PR_TRUE;
|
||||
}
|
||||
// check to see if we have to set up our thread event queue
|
||||
if (!ThreadQueueSetup)
|
||||
{
|
||||
nsIEventQueueService* eventQService;
|
||||
nsresult rv;
|
||||
rv = nsServiceManager::GetService(kEventQueueServiceCID,
|
||||
NS_GET_IID(nsIEventQueueService),
|
||||
(nsISupports **)&eventQService);
|
||||
if (NS_OK == rv)
|
||||
{
|
||||
// create the event queue
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
g_return_if_fail(NS_SUCCEEDED(rv));
|
||||
|
||||
nsIEventQueue *eventQueue;
|
||||
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &eventQueue);
|
||||
g_return_if_fail(NS_SUCCEEDED(rv));
|
||||
|
||||
gdk_input_add(eventQueue->GetEventQueueSelectFD(),
|
||||
GDK_INPUT_READ,
|
||||
gtk_moz_embed_handle_event_queue,
|
||||
eventQueue);
|
||||
NS_RELEASE(eventQService);
|
||||
}
|
||||
ThreadQueueSetup = PR_TRUE;
|
||||
}
|
||||
|
||||
// set up our signals
|
||||
|
||||
|
@ -262,7 +238,7 @@ gtk_moz_embed_class_init(GtkMozEmbedClass *klass)
|
|||
GTK_RUN_FIRST,
|
||||
object_class->type,
|
||||
GTK_SIGNAL_OFFSET(GtkMozEmbedClass, net_state),
|
||||
gtk_marshal_NONE__INT,
|
||||
gtk_marshal_NONE__INT_INT,
|
||||
GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_UINT);
|
||||
moz_embed_signals[NET_START] =
|
||||
gtk_signal_new("net_start",
|
||||
|
@ -314,6 +290,16 @@ gtk_moz_embed_class_init(GtkMozEmbedClass *klass)
|
|||
static void
|
||||
gtk_moz_embed_init(GtkMozEmbed *embed)
|
||||
{
|
||||
// before we do anything else we need to fire up XPCOM
|
||||
if (num_widgets == 0)
|
||||
{
|
||||
gboolean retval;
|
||||
retval = gtk_moz_embed_startup_xpcom();
|
||||
g_return_if_fail(retval == TRUE);
|
||||
|
||||
}
|
||||
// increment the number of widgets
|
||||
num_widgets++;
|
||||
GtkMozEmbedPrivate *embed_private;
|
||||
// create our private struct
|
||||
embed_private = new GtkMozEmbedPrivate();
|
||||
|
@ -370,6 +356,18 @@ gtk_moz_embed_new(void)
|
|||
return GTK_WIDGET(gtk_type_new(gtk_moz_embed_get_type()));
|
||||
}
|
||||
|
||||
void
|
||||
gtk_moz_embed_set_comp_path (char *aPath)
|
||||
{
|
||||
// free the old one if we have to
|
||||
if (component_path)
|
||||
g_free(component_path);
|
||||
if (aPath)
|
||||
{
|
||||
component_path = g_strdup(aPath);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gtk_moz_embed_load_url(GtkMozEmbed *embed, const char *url)
|
||||
{
|
||||
|
@ -624,6 +622,21 @@ gtk_moz_embed_get_location (GtkMozEmbed *embed)
|
|||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_moz_embed_get_nsIWebBrowser (GtkMozEmbed *embed, nsIWebBrowser **retval)
|
||||
{
|
||||
GtkMozEmbedPrivate *embed_private;
|
||||
|
||||
g_return_if_fail (embed != NULL);
|
||||
g_return_if_fail (GTK_IS_MOZ_EMBED(embed));
|
||||
g_return_if_fail (retval != NULL);
|
||||
|
||||
embed_private = (GtkMozEmbedPrivate *)embed->data;
|
||||
|
||||
*retval = embed_private->webBrowser.get();
|
||||
NS_IF_ADDREF(*retval);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_moz_embed_realize(GtkWidget *widget)
|
||||
{
|
||||
|
@ -786,6 +799,14 @@ gtk_moz_embed_destroy(GtkObject *object)
|
|||
delete embed_private;
|
||||
embed->data = NULL;
|
||||
}
|
||||
|
||||
num_widgets--;
|
||||
|
||||
// see if we need to shutdown XPCOM
|
||||
if (num_widgets == 0)
|
||||
{
|
||||
gtk_moz_embed_shutdown_xpcom();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -855,12 +876,12 @@ gtk_moz_embed_handle_net(GtkMozEmbed *embed, gint32 flags, guint32 status)
|
|||
g_return_if_fail (GTK_IS_MOZ_EMBED(embed));
|
||||
|
||||
// if we've got the start flag, emit the signal
|
||||
if ((flags & GTK_MOZ_EMBED_FLAG_IS_WINDOW) && (flags & GTK_MOZ_EMBED_FLAG_START))
|
||||
if ((flags & GTK_MOZ_EMBED_FLAG_IS_NETWORK) && (flags & GTK_MOZ_EMBED_FLAG_START))
|
||||
gtk_signal_emit(GTK_OBJECT(embed), moz_embed_signals[NET_START]);
|
||||
// for people who know what they are doing
|
||||
gtk_signal_emit(GTK_OBJECT(embed), moz_embed_signals[NET_STATE], flags, status);
|
||||
// and for stop, too
|
||||
if ((flags & GTK_MOZ_EMBED_FLAG_IS_WINDOW) && (flags & GTK_MOZ_EMBED_FLAG_STOP))
|
||||
if ((flags & GTK_MOZ_EMBED_FLAG_IS_NETWORK) && (flags & GTK_MOZ_EMBED_FLAG_STOP))
|
||||
gtk_signal_emit(GTK_OBJECT(embed), moz_embed_signals[NET_STOP]);
|
||||
|
||||
}
|
||||
|
@ -899,7 +920,7 @@ gtk_moz_embed_handle_visibility(PRBool aVisibility, void *aData)
|
|||
gtk_signal_emit(GTK_OBJECT(embed), moz_embed_signals[VISIBILITY], aVisibility);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
gtk_moz_embed_handle_destroy(void *aData)
|
||||
{
|
||||
GtkMozEmbed *embed = (GtkMozEmbed *)aData;
|
||||
|
@ -907,7 +928,7 @@ gtk_moz_embed_handle_destroy(void *aData)
|
|||
gtk_signal_emit(GTK_OBJECT(embed), moz_embed_signals[DESTROY_BROWSER]);
|
||||
}
|
||||
|
||||
static PRBool
|
||||
PRBool
|
||||
gtk_moz_embed_handle_open_uri(const char *aURI, void *aData)
|
||||
{
|
||||
GtkMozEmbed *embed = (GtkMozEmbed *)aData;
|
||||
|
@ -916,3 +937,46 @@ gtk_moz_embed_handle_open_uri(const char *aURI, void *aData)
|
|||
gtk_signal_emit(GTK_OBJECT(embed), moz_embed_signals[OPEN_URI], aURI, &return_val);
|
||||
return return_val;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gtk_moz_embed_startup_xpcom(void)
|
||||
{
|
||||
nsresult rv;
|
||||
// init our embedding
|
||||
rv = NS_InitEmbedding(component_path);
|
||||
if (NS_FAILED(rv))
|
||||
return FALSE;
|
||||
// set up the thread event queue
|
||||
nsIEventQueueService* eventQService;
|
||||
rv = nsServiceManager::GetService(kEventQueueServiceCID,
|
||||
NS_GET_IID(nsIEventQueueService),
|
||||
(nsISupports **)&eventQService);
|
||||
if (NS_OK == rv)
|
||||
{
|
||||
// get our hands on the thread event queue
|
||||
nsIEventQueue *eventQueue;
|
||||
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &eventQueue);
|
||||
if (NS_FAILED(rv))
|
||||
return FALSE;
|
||||
|
||||
io_identifier = gdk_input_add(eventQueue->GetEventQueueSelectFD(),
|
||||
GDK_INPUT_READ,
|
||||
gtk_moz_embed_handle_event_queue,
|
||||
eventQueue);
|
||||
NS_RELEASE(eventQService);
|
||||
NS_RELEASE(eventQueue);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_moz_embed_shutdown_xpcom(void)
|
||||
{
|
||||
nsresult rv;
|
||||
// remove the IO handler for the thread event queue
|
||||
gdk_input_remove(io_identifier);
|
||||
io_identifier = 0;
|
||||
// shut down XPCOM
|
||||
NS_TermEmbedding();
|
||||
}
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ struct _GtkMozEmbedClass
|
|||
|
||||
extern GtkType gtk_moz_embed_get_type (void);
|
||||
extern GtkWidget *gtk_moz_embed_new (void);
|
||||
extern void gtk_moz_embed_set_comp_path (char *aPath);
|
||||
extern void gtk_moz_embed_load_url (GtkMozEmbed *embed, const char *url);
|
||||
extern void gtk_moz_embed_stop_load (GtkMozEmbed *embed);
|
||||
extern gboolean gtk_moz_embed_can_go_back (GtkMozEmbed *embed);
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
*/
|
||||
|
||||
#ifndef gtkmozembed_internal_h
|
||||
#define gtkmozembed_internal_h
|
||||
|
||||
#include <nsIWebBrowser.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern void gtk_moz_embed_get_nsIWebBrowser (GtkMozEmbed *embed, nsIWebBrowser **retval);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* gtkmozembed_internal_h */
|
||||
|
|
@ -541,6 +541,10 @@ update_status_bar_text(TestGtkBrowser *browser)
|
|||
{
|
||||
g_snprintf(message, 255, "%s (%d bytes loaded)", browser->statusMessage, browser->bytesLoaded);
|
||||
}
|
||||
else if (browser->statusMessage == NULL)
|
||||
{
|
||||
g_snprintf(message, 255, " ");
|
||||
}
|
||||
else
|
||||
{
|
||||
g_snprintf(message, 255, "%s", browser->statusMessage);
|
||||
|
|
Загрузка…
Ссылка в новой задаче