Bug 454558 Null check missing in nsGNOMEShellService::GetShouldCheckDefaultBrowser...
[wine-gecko.git] / embedding / browser / photon / src / PtMozilla.cpp
blob3b179223266b7d892770a68e61f94b63a6483c60
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is mozilla.org code.
16 * The Initial Developer of the Original Code is
17 * Christopher Blizzard.
18 * Portions created by the Initial Developer are Copyright (C) 2001
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Christopher Blizzard <blizzard@mozilla.org>
23 * Ramiro Estrugo <ramiro@eazel.com>
24 * Brian Edmond <briane@qnx.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
39 #include <stdlib.h>
41 #include "nsCWebBrowser.h"
42 #include "nsILocalFile.h"
43 #include "nsISelectionController.h"
44 #include "nsEmbedAPI.h"
46 #include "nsWidgetsCID.h"
47 #include "nsIAppShell.h"
49 #include "nsIContentViewer.h"
50 #include "nsIMarkupDocumentViewer.h"
52 // for profiles
53 #include <nsProfileDirServiceProvider.h>
55 #include "nsIDocumentLoaderFactory.h"
56 #include "nsILoadGroup.h"
57 #include "nsIHistoryEntry.h"
59 #include "nsIWebBrowserPrint.h"
60 #include "nsIPrintOptions.h"
62 #include "nsIDOMEventTarget.h"
63 #include "nsIDOMEventListener.h"
64 #include "nsIDOMKeyListener.h"
65 #include "nsIDOMMouseListener.h"
66 #include "nsIDOMMouseEvent.h"
67 #include "nsIDOMWindow.h"
68 #include "nsNetUtil.h"
69 #include "nsIFocusController.h"
70 #include <nsIWebBrowserFind.h>
72 #include "nsReadableUtils.h"
74 #include "nsIPresShell.h"
76 #include "nsIDirectoryService.h"
77 #include "nsAppDirectoryServiceDefs.h"
78 #include "nsIFile.h"
79 #include "nsIURIFixup.h"
80 #include "nsPIDOMWindow.h"
82 #include "nsIServiceManager.h"
83 #include "nsIComponentRegistrar.h"
84 #include "nsUnknownContentTypeHandler.h"
86 #include "EmbedPrivate.h"
87 #include "EmbedWindow.h"
88 #include "EmbedDownload.h"
89 #include "HeaderSniffer.h"
90 #include "PromptService.h"
91 #include "PtMozilla.h"
93 //#include "nsUnknownContentTypeHandler.h"
95 #ifdef _BUILD_STATIC_BIN
96 #include "nsStaticComponent.h"
97 nsresult PR_CALLBACK
98 ph_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count);
99 #endif
101 // Macro for converting from nscolor to PtColor_t
102 // Photon RGB values are stored as 00 RR GG BB
103 // nscolor RGB values are 00 BB GG RR
104 #define NS_TO_PH_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
105 #define PH_TO_NS_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
107 // Class IDs
108 static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
110 #define NS_PROMPTSERVICE_CID \
111 {0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}
112 static NS_DEFINE_CID(kPromptServiceCID, NS_PROMPTSERVICE_CID);
114 static void mozilla_set_pref( PtWidget_t *widget, char *option, char *value );
115 static void mozilla_get_pref( PtWidget_t *widget, char *option, char *value );
116 static void fix_translation_string( char *string );
118 PtWidgetClass_t *PtCreateMozillaClass( void );
119 #ifndef _PHSLIB
120 PtWidgetClassRef_t __PtMozilla = { NULL, PtCreateMozillaClass };
121 PtWidgetClassRef_t *PtMozilla = &__PtMozilla;
122 #endif
124 /* globals */
125 char *g_Print_Left_Header_String, *g_Print_Right_Header_String, *g_Print_Left_Footer_String, *g_Print_Right_Footer_String;
127 void
128 MozSetPreference(PtWidget_t *widget, int type, char *pref, void *data)
130 PtMozillaWidget_t *moz = (PtMozillaWidget_t *) widget;
131 nsIPref *prefs = moz->EmbedRef->GetPrefs();
133 switch (type)
135 case Pt_MOZ_PREF_CHAR:
136 prefs->SetCharPref(pref, (char *)data);
137 break;
138 case Pt_MOZ_PREF_BOOL:
139 prefs->SetBoolPref(pref, (int)data);
140 break;
141 case Pt_MOZ_PREF_INT:
142 prefs->SetIntPref(pref, (int)data);
143 break;
144 case Pt_MOZ_PREF_COLOR:
145 // not supported yet
146 // prefs->SetColorPrefDWord(pref, (uint32) data);
147 break;
151 static void
152 MozLoadURL(PtMozillaWidget_t *moz, char *url)
154 // If the widget isn't realized, just return.
155 if (!(PtWidgetFlags((PtWidget_t *)moz) & Pt_REALIZED))
156 return;
158 moz->EmbedRef->SetURI(url);
159 moz->EmbedRef->LoadCurrentURI();
162 /* watch for an Ph_EV_INFO event in order to detect an Ph_OFFSCREEN_INVALID */
163 static int EvInfo( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo )
165 if( cbinfo->event && cbinfo->event->type == Ph_EV_INFO && cbinfo->event->subtype == Ph_OFFSCREEN_INVALID ) {
166 PtMozillaWidget_t *moz = ( PtMozillaWidget_t * ) widget;
167 nsIPref *pref = moz->EmbedRef->GetPrefs();
168 PRBool displayInternalChange = PR_FALSE;
169 pref->GetBoolPref("browser.display.internaluse.graphics_changed", &displayInternalChange);
170 pref->SetBoolPref("browser.display.internaluse.graphics_changed", !displayInternalChange);
172 return Pt_CONTINUE;
175 const char* const kPersistContractID = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1";
177 void MozSaveTarget( char *url, PtMozillaWidget_t *moz )
179 nsresult rv;
180 nsCOMPtr<nsIWebBrowserPersist> webPersist(do_CreateInstance(kPersistContractID, &rv));
181 if( !webPersist ) return;
183 nsCOMPtr<nsIURI> uri;
184 NS_NewURI( getter_AddRefs(uri), url );
186 /* create a temporary file */
187 char tmp_path[1024];
188 tmpnam( tmp_path );
189 nsCOMPtr<nsILocalFile> tmpFile;
190 NS_NewNativeLocalFile(nsDependentCString( tmp_path ), PR_TRUE, getter_AddRefs(tmpFile));
192 /* create a download object, use to sniff the headers for a location indication */
193 HeaderSniffer *sniffer = new HeaderSniffer( webPersist, moz, uri, tmpFile );
195 webPersist->SetProgressListener( sniffer );
196 webPersist->SaveURI( uri, nsnull, nsnull, nsnull, nsnull, tmpFile );
199 // defaults function, called on creation of a widget
200 static void
201 mozilla_defaults( PtWidget_t *widget )
203 PtMozillaWidget_t *moz = (PtMozillaWidget_t *) widget;
204 PtBasicWidget_t *basic = (PtBasicWidget_t *) widget;
205 PtContainerWidget_t *cntr = (PtContainerWidget_t*) widget;
207 moz->EmbedRef = new EmbedPrivate();
208 moz->EmbedRef->Init(widget);
209 moz->EmbedRef->Setup();
211 moz->disable_new_windows = 0;
212 moz->disable_exception_dlg = 0;
213 moz->text_zoom = 100;
214 moz->actual_text_zoom = 100;
215 moz->toActivate = 0;
217 // widget related
218 basic->flags = Pt_ALL_OUTLINES | Pt_ALL_BEVELS | Pt_FLAT_FILL;
219 widget->resize_flags &= ~Pt_RESIZE_XY_BITS; // fixed size.
220 widget->anchor_flags = Pt_TOP_ANCHORED_TOP | Pt_LEFT_ANCHORED_LEFT | \
221 Pt_BOTTOM_ANCHORED_TOP | Pt_RIGHT_ANCHORED_LEFT | Pt_ANCHORS_INVALID;
223 cntr->flags |= Pt_CHILD_GETTING_FOCUS;
225 PtAddEventHandler( widget, Ph_EV_INFO, EvInfo, NULL );
228 // widget destroy function
229 static void
230 mozilla_destroy( PtWidget_t *widget )
232 PtMozillaWidget_t *moz = (PtMozillaWidget_t *) widget;
234 if (moz->EmbedRef)
236 moz->EmbedRef->Destroy();
237 delete moz->EmbedRef;
241 static int child_getting_focus( PtWidget_t *widget, PtWidget_t *child, PhEvent_t *ev ) {
242 PtMozillaWidget_t *moz = (PtMozillaWidget_t *) widget;
243 nsCOMPtr<nsPIDOMWindow> piWin;
245 moz->EmbedRef->GetPIDOMWindow( getter_AddRefs( piWin ) );
246 if( !piWin ) return Pt_CONTINUE;
248 nsIFocusController *focusController = piWin->GetRootFocusController();
249 if( focusController )
250 focusController->SetActive( PR_TRUE );
252 if( moz->toActivate ) {
253 moz->toActivate = 0;
254 piWin->Activate();
257 return Pt_CONTINUE;
260 static int child_losing_focus( PtWidget_t *widget, PtWidget_t *child, PhEvent_t *ev ) {
261 PtMozillaWidget_t *moz = (PtMozillaWidget_t *) widget;
262 nsCOMPtr<nsPIDOMWindow> piWin;
264 moz->EmbedRef->GetPIDOMWindow( getter_AddRefs( piWin ) );
265 if( !piWin ) return Pt_CONTINUE;
267 nsIFocusController *focusController = piWin->GetRootFocusController();
268 if( focusController )
269 focusController->SetActive( PR_FALSE );
271 piWin->Deactivate();
272 moz->toActivate = 1;
274 return Pt_CONTINUE;
277 static void
278 mozilla_extent(PtWidget_t *widget)
280 PtMozillaWidget_t *moz = (PtMozillaWidget_t *) widget;
282 PtSuperClassExtent(PtContainer, widget);
284 moz->EmbedRef->Position(widget->area.pos.x, widget->area.pos.y);
285 moz->EmbedRef->Size(widget->area.size.w, widget->area.size.h);
288 // set resources function
289 static void
290 mozilla_modify( PtWidget_t *widget, PtArg_t const *argt, PtResourceRec_t const *mod )
292 PtMozillaWidget_t *moz = (PtMozillaWidget_t *)widget;
293 nsIPref *pref = moz->EmbedRef->GetPrefs();
295 switch( argt->type )
297 case Pt_ARG_MOZ_GET_URL:
298 MozLoadURL(moz, (char *)(argt->value));
299 break;
301 case Pt_ARG_MOZ_NAVIGATE_PAGE:
302 if (moz->EmbedRef)
304 if (argt->value == Pt_WEB_DIRECTION_FWD)
305 moz->EmbedRef->Forward();
306 else if (argt->value == Pt_WEB_DIRECTION_BACK)
307 moz->EmbedRef->Back();
308 else
310 PhDim_t dim;
312 PtWidgetDim(widget, &dim);
313 dim.w = (argt->value * dim.w)/100;
314 dim.h = (argt->value * dim.h)/100;
316 if (argt->value == Pt_WEB_DIRECTION_UP)
317 moz->EmbedRef->ScrollUp(dim.h);
318 else if (argt->value == Pt_WEB_DIRECTION_DOWN)
319 moz->EmbedRef->ScrollDown(dim.h);
320 else if (argt->value == Pt_WEB_DIRECTION_LEFT)
321 moz->EmbedRef->ScrollLeft(dim.w);
322 else if (argt->value == Pt_WEB_DIRECTION_RIGHT)
323 moz->EmbedRef->ScrollRight(dim.w);
326 break;
328 case Pt_ARG_MOZ_STOP:
329 if (moz->EmbedRef)
330 moz->EmbedRef->Stop();
331 break;
333 case Pt_ARG_MOZ_RELOAD:
334 if (moz->EmbedRef)
335 moz->EmbedRef->Reload(0);
336 break;
338 case Pt_ARG_MOZ_PRINT:
340 PpPrintContext_t *pc = ( PpPrintContext_t * ) argt->value;
341 moz->EmbedRef->Print(pc);
343 break;
345 case Pt_ARG_MOZ_OPTION:
346 mozilla_set_pref(widget, (char*)argt->len, (char*)argt->value);
347 break;
349 case Pt_ARG_MOZ_ENCODING: {
350 char translation[1024];
351 strcpy( translation, (char*)argt->value );
352 fix_translation_string( translation );
353 pref->SetUnicharPref( "intl.charset.default", NS_ConvertASCIItoUTF16( translation ).get());
354 pref->SavePrefFile( nsnull );
356 break;
358 case Pt_ARG_MOZ_COMMAND: {
359 PtWebClient2Command_t *wdata = ( PtWebClient2Command_t * ) argt->len;
360 switch ((int)(argt->value))
362 case Pt_MOZ_COMMAND_CUT: {
363 moz->EmbedRef->Cut(wdata?wdata->ClipboardInfo.input_group:1);
365 break;
366 case Pt_MOZ_COMMAND_COPY: {
367 moz->EmbedRef->Copy(wdata?wdata->ClipboardInfo.input_group:1);
369 break;
370 case Pt_MOZ_COMMAND_PASTE: {
371 moz->EmbedRef->Paste(wdata?wdata->ClipboardInfo.input_group:1);
373 break;
374 case Pt_MOZ_COMMAND_SELECTALL: {
375 moz->EmbedRef->SelectAll();
377 break;
378 case Pt_MOZ_COMMAND_CLEAR: {
379 moz->EmbedRef->Clear();
381 break;
383 case Pt_MOZ_COMMAND_FIND: {
384 nsCOMPtr<nsIWebBrowserFind> finder( do_GetInterface( moz->EmbedRef->mWindow->mWebBrowser ) );
385 finder->SetSearchString( NS_ConvertASCIItoUTF16(wdata->FindInfo.string).get() );
386 finder->SetMatchCase( wdata->FindInfo.flags & Pt_WEB_FIND_MATCH_CASE );
387 finder->SetFindBackwards( wdata->FindInfo.flags & Pt_WEB_FIND_GO_BACKWARDS );
388 finder->SetWrapFind( wdata->FindInfo.flags & Pt_WEB_FIND_START_AT_TOP );
389 finder->SetEntireWord( wdata->FindInfo.flags & Pt_WEB_FIND_MATCH_WHOLE_WORDS );
391 PRBool didFind;
392 finder->FindNext( &didFind );
393 break;
396 case Pt_MOZ_COMMAND_SAVEAS: {
397 char *dirname = ( char * ) calloc( 1, strlen( wdata->SaveasInfo.filename + 7 ) );
398 if( dirname ) {
399 sprintf( dirname, "%s_files", wdata->SaveasInfo.filename );
400 moz->EmbedRef->SaveAs( wdata->SaveasInfo.filename, dirname );
401 free( dirname );
403 break;
407 break;
409 case Pt_ARG_MOZ_WEB_DATA_URL:
410 #if 0
411 // moz->MyBrowser->WebBrowserContainer->OpenStream( moz->MyBrowser->WebBrowser, "file://", "text/html" );
412 // strcpy( moz->url, (char*)argt->value );
413 #endif
414 break;
416 case Pt_ARG_MOZ_UNKNOWN_RESP: {
417 PtWebClient2UnknownData_t *unknown = ( PtWebClient2UnknownData_t * ) argt->value;
418 if( unknown->response == Pt_WEB_RESPONSE_CANCEL ) {
419 EmbedDownload *d = FindDownload( moz, unknown->download_ticket );
420 if( d ) {
421 if( d->mLauncher ) d->mLauncher->Cancel(NS_BINDING_ABORTED); /* this will also call the EmbedDownload destructor */
422 else if( d->mPersist ) d->mPersist->CancelSave(); /* this will also call the EmbedDownload destructor */
423 else delete d; /* just in case neither d->mLauncher or d->mPersist was set */
427 break;
429 case Pt_ARG_MOZ_DOWNLOAD:
431 MozSaveTarget( (char*)argt->value, moz );
433 break;
435 case Pt_ARG_MOZ_WEB_DATA: {
436 #if 0
437 WWWRequest *req = ( WWWRequest * ) argt->value;
438 char *hdata;
439 int len;
441 if( strcmp( moz->url, req->DataHdr.url ) ) break;
443 hdata = (char*) argt->len;
444 len = req->DataHdr.length;
446 switch( req->DataHdr.type ) {
447 case Pt_WEB_DATA_HEADER:
448 if( !moz->MyBrowser->WebBrowserContainer->IsStreaming( ) ) break;
450 /* request the document body */
451 if( moz->web_data_req_cb ) {
452 PtCallbackInfo_t cbinfo;
453 PtMozillaDataRequestCb_t cb;
455 memset( &cbinfo, 0, sizeof( cbinfo ) );
456 cbinfo.reason = Pt_CB_MOZ_WEB_DATA_REQ;
457 cbinfo.cbdata = &cb;
458 cb.type = Pt_WEB_DATA_BODY;
459 cb.length = 32768;
460 cb.url = moz->url;
461 PtInvokeCallbackList( moz->web_data_req_cb, (PtWidget_t *)moz, &cbinfo);
463 break;
464 case Pt_WEB_DATA_BODY: {
465 if( !moz->MyBrowser->WebBrowserContainer->IsStreaming( ) ) break;
466 if( len )
467 moz->MyBrowser->WebBrowserContainer->AppendToStream( hdata, len );
468 else moz->MyBrowser->WebBrowserContainer->CloseStream( );
470 /* request the next piece of the body */
471 PtCallbackInfo_t cbinfo;
472 PtMozillaDataRequestCb_t cb;
474 memset( &cbinfo, 0, sizeof( cbinfo ) );
475 cbinfo.reason = Pt_CB_MOZ_WEB_DATA_REQ;
476 cbinfo.cbdata = &cb;
477 cb.type = len ? Pt_WEB_DATA_BODY : Pt_WEB_DATA_CLOSE;
478 cb.length = 32768;
479 cb.url = moz->url;
480 PtInvokeCallbackList( moz->web_data_req_cb, (PtWidget_t *)moz, &cbinfo);
482 break;
483 case Pt_WEB_DATA_CLOSE:
484 if( !moz->MyBrowser->WebBrowserContainer->IsStreaming( ) ) break;
485 moz->MyBrowser->WebBrowserContainer->CloseStream( );
486 break;
488 #endif
490 break;
493 return;
497 // get resources function
498 static int
499 mozilla_get_info( PtWidget_t *widget, PtArg_t *argt, PtResourceRec_t const *mod )
501 PtMozillaWidget_t *moz = (PtMozillaWidget_t *) widget;
502 nsIPref *pref = moz->EmbedRef->GetPrefs();
504 switch (argt->type)
506 case Pt_ARG_MOZ_NAVIGATE_PAGE:
507 moz->navigate_flags = 0;
508 if (moz->EmbedRef->CanGoBack())
509 moz->navigate_flags |= ( 1 << Pt_WEB_DIRECTION_BACK );
510 if (moz->EmbedRef->CanGoForward())
511 moz->navigate_flags |= ( 1 << Pt_WEB_DIRECTION_FWD );
512 *((int **)argt->value) = &moz->navigate_flags;
513 break;
515 case Pt_ARG_MOZ_OPTION:
516 mozilla_get_pref( widget, (char*)argt->len, (char*) argt->value );
517 break;
519 case Pt_ARG_MOZ_GET_CONTEXT: {
520 if( argt->len & Pt_MOZ_CONTEXT_LINK )
521 *(char**) argt->value = moz->rightClickUrl_link;
522 else if( argt->len & Pt_MOZ_CONTEXT_IMAGE )
523 *(char**) argt->value = moz->rightClickUrl_image;
524 else *(char**) argt->value = moz->rightClickUrl_link;
526 break;
528 case Pt_ARG_MOZ_ENCODING:
530 PRUnichar *charset = nsnull;
531 static char encoding[256];
532 pref->GetLocalizedUnicharPref( "intl.charset.default", &charset );
533 strcpy( encoding, NS_ConvertUTF16toUTF8(charset).get() );
534 *(char**)argt->value = encoding;
536 break;
538 case Pt_ARG_MOZ_GET_HISTORY:
540 PtWebClientHistory_t *hist_info = (PtWebClientHistory_t *)argt->len;
541 PtWebClientHistoryData_t *HistoryReplyBuf = (PtWebClientHistoryData_t *) argt->value;
542 int i, j;
543 PRInt32 total;
544 moz->EmbedRef->mSessionHistory->GetCount( &total );
546 for( i=total-2, j=0; i>=0 && j<hist_info->num; i--, j++)
548 nsIHistoryEntry *entry;
549 moz->EmbedRef->mSessionHistory->GetEntryAtIndex( i, PR_FALSE, &entry );
551 PRUnichar *title;
552 nsIURI *url;
553 entry->GetTitle( &title );
554 entry->GetURI( &url );
556 nsString stitle( title );
557 HistoryReplyBuf[j].title = strdup( ToNewCString(stitle) );
559 nsCAutoString specString;
560 url->GetSpec(specString);
561 HistoryReplyBuf[j].url = strdup( (char *) specString.get() );
564 break;
567 return (Pt_CONTINUE);
571 static void
572 mozilla_set_pref( PtWidget_t *widget, char *option, char *value )
574 PtMozillaWidget_t *moz = ( PtMozillaWidget_t * ) widget;
575 nsIPref *pref = moz->EmbedRef->GetPrefs();
576 char buffer[1024];
578 mozilla_get_pref( widget, option, buffer );
579 if( buffer[0] && !strcmp( value, buffer ) )
580 return; /* the option is already set */
582 /* HTML Options */
583 if( !strcmp( option, "A:visited color" ) ) {
584 pref->SetUnicharPref( "browser.visited_color", NS_ConvertASCIItoUTF16(value).get() );
586 else if( !strcmp( option, "A:link color" ) ) {
587 pref->SetUnicharPref( "browser.anchor_color", NS_ConvertASCIItoUTF16(value).get() );
590 /* the mozserver already has A:link color == browser.anchor_color for this */
591 // else if( !strcmp( option, "A:active color" ) ) {
592 // pref->SetUnicharPref( "browser.anchor_color", NS_ConvertASCIItoUTF16(value).get() );
593 // }
595 else if( !strcmp( option, "BODY color" ) ) {
596 pref->SetUnicharPref( "browser.display.foreground_color", NS_ConvertASCIItoUTF16(value).get() );
598 else if( !strcmp( option, "BODY background" ) ) {
599 pref->SetUnicharPref( "browser.display.background_color", NS_ConvertASCIItoUTF16(value).get() );
601 else if( !strcmp( option, "bIgnoreDocumentAttributes" ) )
602 pref->SetBoolPref( "browser.display.use_document_colors", stricmp( value, "TRUE" ) ? PR_FALSE : PR_TRUE );
603 else if( !strcmp( option, "bUnderlineLinks" ) ) {
604 pref->SetBoolPref( "browser.underline_anchors", !stricmp( value, "TRUE" ) ? PR_TRUE : PR_FALSE );
606 else if( !strcmp( option, "iUserTextSize" ) ) {
607 moz->text_zoom = atoi( value );
608 nsCOMPtr<nsIDOMWindow> domWindow;
609 moz->EmbedRef->mWindow->mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
610 if(domWindow) {
611 domWindow->SetTextZoom( moz->text_zoom/100. );
612 float vv;
613 domWindow->GetTextZoom( &vv );
614 moz->actual_text_zoom = (int) ( vv * 100 );
617 else if( !strcmp( option, "BODY font-family" ) ) {
618 /* set the current font */
619 char *font_default = NULL;
620 char preference[256];
622 pref->CopyCharPref( "font.default.x-western", &font_default );
623 if( !font_default ) font_default = "serif";
625 sprintf( preference, "font.name.%s.x-western", font_default );
626 pref->SetCharPref( preference, value );
628 else if( !strcmp( option, "PRE font-family" ) ) {
629 pref->SetCharPref( "font.name.monospace.x-western", value );
631 else if( !strcmp( option, "H* font-family" ) ) {
632 /* do not set these - use the BODY font-family instead */
635 /* SOCKS options */
636 else if( !strcmp( option, "socks_server" ) ) ; /* not used */
637 else if( !strcmp( option, "socks_port" ) ) ; /* not used */
638 else if( !strcmp( option, "socks_user" ) ) ; /* not used */
639 else if( !strcmp( option, "socks_app" ) ) ; /* not used */
641 /* HTTP options */
643 else if( !strcmp( option, "enable_proxy" ) ) {
644 if( value && !stricmp( value, "yes" ) )
645 pref->SetIntPref( "network.proxy.type", 1 );
646 else pref->SetIntPref( "network.proxy.type", 0 );
648 else if( !strcmp( option, "http_proxy_host" ) ) {
649 pref->SetCharPref( "network.proxy.http", value );
651 else if( !strcmp( option, "http_proxy_port" ) ) {
652 pref->SetIntPref( "network.proxy.http_port", atoi(value) );
654 else if( !strcmp( option, "proxy_overrides" ) ) {
655 pref->SetCharPref( "network.proxy.no_proxies_on", value );
657 else if( !strcmp( option, "https_proxy_host" ) ) {
658 pref->SetCharPref( "network.proxy.ssl", value );
660 else if( !strcmp( option, "https_proxy_port" ) ) {
661 pref->SetIntPref( "network.proxy.ssl_port", atoi(value) );
665 /* FTP options */
666 else if( !strcmp( option, "ftp_proxy_host" ) )
667 pref->SetCharPref( "network.proxy.ftp", value );
668 else if( !strcmp( option, "ftp_proxy_port" ) )
669 pref->SetIntPref( "network.proxy.ftp_port", atoi(value) );
670 else if( !strcmp( option, "email_address" ) ) ; /* not used */
672 /* Gopher options */
673 else if( !strcmp( option, "gopher_proxy_host" ) )
674 pref->SetCharPref( "network.proxy.gopher", value );
675 else if( !strcmp( option, "gopher_proxy_port" ) )
676 pref->SetIntPref( "network.proxy.gopher_port", atoi(value) );
678 /* TCP/IP options */
679 else if( !strcmp( option, "max_connections" ) )
680 pref->SetIntPref( "network.http.max-connections", atoi( value ) );
682 /* Disk-cache options */
683 else if( !strcmp( option, "main_cache_kb_size" ) )
684 pref->SetIntPref( "browser.cache.disk.capacity", atoi( value ) );
685 else if( !strcmp( option, "enable_disk_cache" ) )
686 pref->SetBoolPref( "browser.cache.disk.enable", !stricmp( value, "TRUE" ) ? PR_TRUE : PR_FALSE );
687 else if( !strcmp( option, "dcache_verify_policy" ) ) {
688 int n = atoi( value ), moz_value=3;
689 if( n == 0 ) moz_value = 2; /* never */
690 else if( n == 1 ) moz_value = 0; /* once */
691 else if( n == 2 ) moz_value = 1; /* always */
693 // mozilla wants: 0 = once-per-session, 1 = each-time, 2 = never, 3 = when-appropriate/automatically
694 pref->SetIntPref( "browser.cache.check_doc_frequency", moz_value );
696 else if( !strcmp( option, "main_cache_dir" ) ) ; /* not used */
697 else if( !strcmp( option, "main_index_file" ) ) ; /* not used */
698 else if( !strcmp( option, "clear_main_cache_on_exit" ) ) ; /* not used */
699 else if( !strcmp( option, "keep_index_file_updated" ) ) ; /* not used */
701 /* memory cache options */
702 else if( !strcmp( option, "memory_cache_kb_size" ) || !strcmp( option, "image_cache_size_KB" ) ) {
703 int kb = atoi( value );
704 if( kb <= 0 ) kb = 100; /* have a minimum threshold */
705 pref->SetIntPref( "browser.cache.memory.capacity", kb );
708 /* Miscellaneous options */
709 else if( !strcmp( option, "History_Expire" ) )
710 pref->SetIntPref( "browser.history_expire_days", atoi( value ) );
711 else if( !strcmp( option, "Page_History_Length" ) )
712 pref->SetIntPref( "browser.sessionhistory.max_entries", atoi( value ) );
716 /* HTML Options */
717 else if( !strcmp( option, "bAutoLoadImages" ) ) ; /* not used */
718 else if( !strcmp( option, "iReformatHandling" ) ) ; /* not used */
719 else if( !strcmp( option, "BODY margin-top" ) ) ; /* not used */
720 else if( !strcmp( option, "BODY margin-right" ) ) ; /* not used */
721 else if( !strcmp( option, "iScrollbarSize" ) ) ; /* not used */
722 else if( !strcmp( option, "top_focus_color" ) ) ; /* not used */
723 else if( !strcmp( option, "bot_focus_color" ) ) ; /* not used */
724 else if( !strcmp( option, "top_border_color" ) ) ; /* not used */
725 else if( !strcmp( option, "bot_border_color" ) ) ; /* not used */
726 else if( !strcmp( option, "bview_source" ) ) ; /* not used */
727 else if( !strcmp( option, "underline_width" ) ) ; /* not used */
728 else if( !strcmp( option, "bkey_mode" ) ) ; /* not used */
729 else if( !strcmp( option, "mono_form_font" ) ) ; /* not used */
730 else if( !strcmp( option, "form_font" ) ) ; /* not used */
731 else if( !strcmp( option, "frame_spacing" ) ) ; /* not used */
732 else if( !strcmp( option, "disable_new_windows" ) ) /* disable new windows*/
734 if (strcmp(value, "TRUE") == 0)
735 moz->disable_new_windows = 1;
736 else
737 moz->disable_new_windows = 0;
739 else if( !strcmp( option, "disable_exception_dlg" ) ) /* disable exception dialogs */
741 if (strcmp(value, "TRUE") == 0)
742 moz->disable_exception_dlg = 1;
743 else
744 moz->disable_exception_dlg = 0;
747 else if( !strcmp( option, "bDisableHighlight" ) ) ; /* not used */
749 /* HTTP cookie options */
750 else if( !strcmp( option, "cookiejar_path" ) ) ; /* not used */
751 else if( !strcmp( option, "cookiejar_name" ) ) ; /* not used */
752 else if( !strcmp( option, "cookiejar_size" ) ) ; /* not used */
753 else if( !strcmp( option, "cookiejar_save_always" ) ) ; /* not used */
755 /* Authentication options */
756 else if( !strcmp( option, "max_password_guesses" ) ) ; /* not used */
758 /* File options */
759 else if( !strcmp( option, "file_display_dir" ) ) ; /* not used */
761 /* Image options */
762 else if( !strcmp( option, "bProgressiveImageDisplay" ) ) ; /* not used */
763 else if( !strcmp( option, "quantize_jpegs" ) ) ; /* not used */
764 else if( !strcmp( option, "concurrent_decodes" ) ) ; /* not used */
767 /* Print options */
768 else if( !strcmp( option, "Print_Header_Font" ) ) ; /* not used */
769 else if( !strcmp( option, "Print_Header_Font_Size" ) ) ; /* not used */
770 else if( !strcmp( option, "Print_Left_Header_String" ) ) {
771 if( g_Print_Left_Header_String ) free( g_Print_Left_Header_String );
772 g_Print_Left_Header_String = strdup( value );
774 else if( !strcmp( option, "Print_Right_Header_String" ) ) {
775 if( g_Print_Right_Header_String ) free( g_Print_Right_Header_String );
776 g_Print_Right_Header_String = strdup( value );
778 else if( !strcmp( option, "Print_Left_Footer_String" ) ) {
779 if( g_Print_Left_Footer_String ) free( g_Print_Left_Footer_String );
780 g_Print_Left_Footer_String = strdup( value );
782 else if( !strcmp( option, "Print_Right_Footer_String" ) ) {
783 if( g_Print_Right_Footer_String ) free( g_Print_Right_Footer_String );
784 g_Print_Right_Footer_String = strdup( value );
788 /* Miscellaneous options */
789 else if( !strcmp( option, "Global_History_File" ) ) ; /* not used */
790 else if( !strcmp( option, "IBeam_Cursor" ) ) ; /* not used */
791 else if( !strcmp( option, "Image_Cache_Size_KB" ) ) ; /* not used */
792 else if( !strcmp( option, "ImageMap_Cursor" ) ) ; /* not used */
793 else if( !strcmp( option, "ImageMap_Cursor_NoLink" ) ) ; /* not used */
794 else if( !strcmp( option, "Link_Cursor" ) ) ; /* not used */
795 else if( !strcmp( option, "LinkWait_Cursor" ) ) ; /* not used */
796 else if( !strcmp( option, "Normal_Cursor" ) ) ; /* not used */
797 else if( !strcmp( option, "NormalWait_Cursor" ) ) ; /* not used */
798 else if( !strcmp( option, "Page_Cache_Size" ) ) ; /* not used */
799 else if( !strcmp( option, "Safe_Memory_Free" ) ) ; /* not used */
800 else if( !strcmp( option, "Site_History_Length" ) ) ; /* not used */
801 else if( !strcmp( option, "Show_Server_Errors" ) ) ; /* not used */
802 else if( !strcmp( option, "Use_Anti_Alias" ) ) ; /* not used */
803 else if( !strcmp( option, "Use_Explicit_Accept_Headers" ) ) ; /* not used */
804 else if( !strcmp( option, "Visitation_Horizon" ) ) ; /* not used */
806 else if( !strcmp( option, "Print_Frame" ) )
807 pref->SetCharPref( "user.print.print_frame", value );
808 else if( !strcmp( option, "SetPrintBGColors" ) )
809 pref->SetCharPref( "user.print.SetPrintBGColors", value );
810 else if( !strcmp( option, "SetPrintBGImages" ) )
811 pref->SetCharPref( "user.print.SetPrintBGImages", value );
813 pref->SavePrefFile( nsnull );
816 static void mozilla_get_pref( PtWidget_t *widget, char *option, char *value ) {
817 PtMozillaWidget_t *moz = ( PtMozillaWidget_t * ) widget;
818 nsIPref *pref = moz->EmbedRef->GetPrefs();
820 /* HTML Options */
821 if( !strcmp( option, "A:link color" ) || !strcmp( option, "A:active color" ) ) {
822 nsXPIDLCString colorStr;
823 if( pref->CopyCharPref( "browser.anchor_color", getter_Copies(colorStr) ) == NS_OK )
824 strcpy( value, colorStr );
826 else if( !strcmp( option, "A:visited color" ) ) {
827 nsXPIDLCString colorStr;
828 if( pref->CopyCharPref( "browser.visited_color", getter_Copies(colorStr) ) == NS_OK )
829 strcpy( value, colorStr );
831 else if( !strcmp( option, "BODY color" ) ) {
832 nsXPIDLCString colorStr;
833 if( pref->CopyCharPref( "browser.display.foreground_color", getter_Copies(colorStr) ) == NS_OK )
834 strcpy( value, colorStr );
836 else if( !strcmp( option, "BODY background" ) ) {
837 nsXPIDLCString colorStr;
838 if( pref->CopyCharPref( "browser.display.background_color", getter_Copies(colorStr) ) == NS_OK )
839 strcpy( value, colorStr );
841 else if( !strcmp( option, "bIgnoreDocumentAttributes" ) ) {
842 PRBool val;
843 pref->GetBoolPref( "browser.display.use_document_colors", &val );
844 sprintf( value, "%s", val == PR_TRUE ? "FALSE" : "TRUE" );
846 else if( !strcmp( option, "disable_new_windows" ) ) {
847 sprintf( value, "%s", (moz->disable_new_windows == 1) ? "TRUE" : "FALSE" );
849 else if( !strcmp( option, "disable_exception_dlg" ) ) {
850 sprintf( value, "%s", (moz->disable_exception_dlg == 1) ? "TRUE" : "FALSE" );
852 else if( !strcmp( option, "bUnderlineLinks" ) ) {
853 PRBool val;
854 pref->GetBoolPref( "browser.underline_anchors", &val );
855 sprintf( value, "%s", val == PR_TRUE ? "TRUE" : "FALSE" );
857 else if( !strcmp( option, "iUserTextSize" ) ) {
858 sprintf( value, "%d", moz->text_zoom );
860 else if( !strcmp( option, "BODY font-family" ) || !strcmp( option, "H* font-family" ) ) {
861 /* set the current font */
862 char *font_default = NULL, *font;
863 char preference[256];
865 pref->CopyCharPref( "font.default.x-western", &font_default );
866 if( !font_default ) font_default = "serif";
868 sprintf( preference, "font.name.%s.x-western", font_default );
869 if( pref->CopyCharPref( preference, &font ) == NS_OK )
870 strcpy( value, font );
872 else if( !strcmp( option, "PRE font-family" ) ) {
873 /* set the current font */
874 char *font;
875 if( pref->CopyCharPref( "font.name.monospace.x-western", &font ) == NS_OK )
876 strcpy( value, font );
879 /* HTTP options */
880 else if( !strcmp( option, "http_proxy_host" ) ) {
881 char *s;
882 if( pref->CopyCharPref( "network.proxy.http", &s ) == NS_OK )
883 strcpy( value, s );
885 else if( !strcmp( option, "http_proxy_port" ) ) {
886 int n;
887 pref->GetIntPref( "network.proxy.http_port", &n );
888 sprintf( value, "%d", n );
890 else if( !strcmp( option, "proxy_overrides" ) ) {
891 char *s;
892 if( pref->CopyCharPref( "network.proxy.no_proxies_on", &s ) == NS_OK )
893 strcpy( value, s );
895 else if( !strcmp( option, "https_proxy_host" ) ) {
896 char *s;
897 if( pref->CopyCharPref( "network.proxy.ssl", &s ) == NS_OK )
898 strcpy( value, s );
900 else if( !strcmp( option, "https_proxy_port" ) ) {
901 int n;
902 pref->GetIntPref( "network.proxy.ssl_port", &n );
903 sprintf( value, "%d", n );
907 /* FTP options */
908 else if( !strcmp( option, "ftp_proxy_host" ) ) {
909 char *s;
910 if( pref->CopyCharPref( "network.proxy.ftp", &s ) == NS_OK )
911 strcpy( value, s );
913 else if( !strcmp( option, "ftp_proxy_port" ) ) {
914 int n;
915 pref->GetIntPref( "network.proxy.ftp_port", &n );
916 sprintf( value, "%d", n );
919 /* Gopher options */
920 else if( !strcmp( option, "gopher_proxy_host" ) ) {
921 char *s;
922 if( pref->CopyCharPref( "network.proxy.gopher", &s ) == NS_OK )
923 strcpy( value, s );
925 else if( !strcmp( option, "gopher_proxy_port" ) ) {
926 int n;
927 pref->GetIntPref( "gopher_proxy_port", &n );
928 sprintf( value, "%d", n );
931 /* TCP/IP options */
932 else if( !strcmp( option, "max_connections" ) ) {
933 int n;
934 pref->GetIntPref( "network.http.max-connections", &n );
935 sprintf( value, "%d", n );
938 /* Disk-cache options */
939 else if( !strcmp( option, "main_cache_kb_size" ) ) {
940 int n;
941 pref->GetIntPref( "browser.cache.disk.capacity", &n );
942 sprintf( value, "%d", n );
944 else if( !strcmp( option, "enable_disk_cache" ) ) {
945 PRBool val;
946 pref->GetBoolPref( "browser.cache.disk.enable", &val );
947 sprintf( value, "%s", val == PR_TRUE ? "TRUE" : "FALSE" );
949 else if( !strcmp( option, "dcache_verify_policy" ) ) {
950 int n, voyager_value = 0;
951 pref->GetIntPref( "browser.cache.check_doc_frequency", &n );
952 // 0 = once-per-session, 1 = each-time, 2 = never, 3 = when-appropriate/automatically
953 if( n == 0 ) voyager_value = 1; /* voyager: 1 = once per session */
954 else if( n == 1 ) voyager_value = 2; /* voyager: 2 = always */
955 else if( n == 2 ) voyager_value = 0; /* voyager: 0 = never */
956 else voyager_value = 1; /* mapp the when-appropriate/automatically to the once per session */
957 sprintf( value, "%d", voyager_value );
960 /* Miscellaneous options */
961 else if( !strcmp( option, "History_Expire" ) ) {
962 int n;
963 pref->GetIntPref( "browser.history_expire_days", &n );
964 sprintf( value, "%d", n );
966 else if( !strcmp( option, "Page_History_Length" ) ) {
967 int n;
968 pref->GetIntPref( "browser.sessionhistory.max_entries", &n );
969 sprintf( value, "%d", n );
972 else if( !strcmp( option, "clear_main_cache_on_exit" ) ) {
973 strcpy( value, "FALSE" ); /* even if not used, match this with the default value */
975 else if( !strcmp( option, "quantize_jpegs" ) ) {
976 strcpy( value, "FALSE" ); /* even if not used, match this with the default value */
978 else if( !strcmp( option, "ServerId" ) ) {
979 strcpy( value, "mozserver" );
981 else *value = 0;
985 int sProfileDirCreated;
986 static int StartupProfile( char *sProfileDir )
988 // initialize profiles
989 if(sProfileDir)
991 nsresult rv;
992 nsCOMPtr<nsILocalFile> profileDir;
993 PRBool exists = PR_FALSE;
994 PRBool isDir = PR_FALSE;
995 profileDir = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
996 rv = profileDir->InitWithNativePath(nsDependentCString(sProfileDir));
997 if (NS_FAILED(rv))
998 return NS_ERROR_FAILURE;
999 profileDir->Exists(&exists);
1000 profileDir->IsDirectory(&isDir);
1001 // if it exists and it isn't a directory then give up now.
1002 if (!exists)
1004 rv = profileDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
1005 if( NS_FAILED(rv) )
1006 return NS_ERROR_FAILURE;
1007 sProfileDirCreated = 1;
1009 else if (exists && !isDir)
1010 return NS_ERROR_FAILURE;
1012 nsCOMPtr<nsProfileDirServiceProvider> locProvider;
1013 NS_NewProfileDirServiceProvider(PR_TRUE, getter_AddRefs(locProvider));
1014 if (!locProvider)
1015 return NS_ERROR_FAILURE;
1017 // Directory service holds an strong reference to any
1018 // provider that is registered with it. Let it hold the
1019 // only ref. locProvider won't die when we leave this scope.
1020 rv = locProvider->Register();
1021 if (NS_FAILED(rv))
1022 return rv;
1023 rv = locProvider->SetProfileDir(profileDir);
1024 if (NS_FAILED(rv))
1025 return rv;
1028 return NS_OK;
1031 // startup the mozilla embedding engine
1032 static int StartupEmbedding()
1034 nsresult rv;
1036 #ifdef _BUILD_STATIC_BIN
1037 // Initialize XPCOM's module info table
1038 NSGetStaticModuleInfo = ph_getModuleInfo;
1039 #endif
1041 rv = NS_InitEmbedding(nsnull, nsnull);
1042 if( NS_FAILED( rv ) ) return -1;
1044 char *profile_dir;
1045 profile_dir = (char *)alloca(strlen(getenv("HOME")) + strlen("/.ph/mozilla") + 1);
1046 sprintf(profile_dir, "%s/.ph/mozilla", getenv("HOME"));
1047 rv = StartupProfile( profile_dir );
1048 if( NS_FAILED( rv ) )
1049 NS_WARNING("Warning: Failed to start up profiles.\n");
1051 nsCOMPtr<nsIAppShell> appShell;
1052 appShell = do_CreateInstance(kAppShellCID);
1053 if( !appShell ) {
1054 NS_WARNING("Failed to create appshell in EmbedPrivate::PushStartup!\n");
1055 return (-1);
1057 nsIAppShell * sAppShell = appShell.get();
1058 NS_ADDREF(sAppShell);
1059 sAppShell->Create(0, nsnull);
1060 sAppShell->Spinup();
1061 return 0;
1064 /* the translation string that is passed by voyager ( Pt_ARG_WEB_ENCODING ) ( taken from /usr/photon/translations/charsets ->mime field ) */
1065 /* is required to be in a different form by the mozilla browser */
1066 static void fix_translation_string( char *string ) {
1067 /* for instance it has to be windows-1252 not Windows-1252 */
1068 if( !strncmp( string, "Windows", 7 ) ) *string = 'w';
1071 // PtMozilla class creation function
1072 PtWidgetClass_t *PtCreateMozillaClass( void )
1074 static const PtResourceRec_t resources[] =
1076 { Pt_ARG_MOZ_GET_URL, mozilla_modify, Pt_QUERY_PREVENT },
1077 { Pt_ARG_MOZ_NAVIGATE_PAGE, mozilla_modify, mozilla_get_info },
1078 { Pt_ARG_MOZ_RELOAD, mozilla_modify, Pt_QUERY_PREVENT },
1079 { Pt_ARG_MOZ_STOP, mozilla_modify, Pt_QUERY_PREVENT },
1080 { Pt_ARG_MOZ_PRINT, mozilla_modify, Pt_QUERY_PREVENT },
1081 { Pt_ARG_MOZ_COMMAND, mozilla_modify, Pt_QUERY_PREVENT },
1082 { Pt_ARG_MOZ_OPTION, mozilla_modify, mozilla_get_info },
1083 { Pt_ARG_MOZ_GET_CONTEXT, NULL, mozilla_get_info },
1084 { Pt_ARG_MOZ_GET_HISTORY, NULL, mozilla_get_info },
1085 { Pt_ARG_MOZ_ENCODING, mozilla_modify, mozilla_get_info },
1086 { Pt_ARG_MOZ_WEB_DATA_URL, mozilla_modify, Pt_QUERY_PREVENT },
1087 { Pt_ARG_MOZ_WEB_DATA, mozilla_modify, Pt_QUERY_PREVENT },
1088 { Pt_ARG_MOZ_UNKNOWN_RESP, mozilla_modify, Pt_QUERY_PREVENT },
1089 { Pt_ARG_MOZ_DOWNLOAD, mozilla_modify, Pt_QUERY_PREVENT },
1090 { Pt_ARG_MOZ_AUTH_CTRL, NULL, NULL, Pt_ARG_IS_POINTER( PtMozillaWidget_t, moz_auth_ctrl ) },
1091 { Pt_ARG_MOZ_UNKNOWN_CTRL, NULL, NULL, Pt_ARG_IS_POINTER( PtMozillaWidget_t, moz_unknown_ctrl ) },
1092 { Pt_CB_MOZ_INFO, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, info_cb) },
1093 { Pt_CB_MOZ_START, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, start_cb) },
1094 { Pt_CB_MOZ_COMPLETE, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, complete_cb) },
1095 { Pt_CB_MOZ_PROGRESS, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, progress_cb) },
1096 { Pt_CB_MOZ_URL, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, url_cb) },
1097 { Pt_CB_MOZ_EVENT, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, event_cb) },
1098 { Pt_CB_MOZ_NET_STATE, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, net_state_cb) },
1099 { Pt_CB_MOZ_NEW_WINDOW, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, new_window_cb) },
1100 { Pt_CB_MOZ_NEW_AREA, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, resize_cb) },
1101 { Pt_CB_MOZ_DESTROY, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, destroy_cb) },
1102 { Pt_CB_MOZ_VISIBILITY, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, visibility_cb) },
1103 { Pt_CB_MOZ_OPEN, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, open_cb) },
1104 { Pt_CB_MOZ_DIALOG, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, dialog_cb) },
1105 { Pt_CB_MOZ_AUTHENTICATE, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, auth_cb) },
1106 { Pt_CB_MOZ_PROMPT, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, prompt_cb) },
1107 { Pt_CB_MOZ_CONTEXT, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, context_cb) },
1108 { Pt_CB_MOZ_PRINT_STATUS, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, print_status_cb) },
1109 { Pt_CB_MOZ_WEB_DATA_REQ, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, web_data_req_cb) },
1110 { Pt_CB_MOZ_UNKNOWN, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, web_unknown_cb) },
1111 { Pt_CB_MOZ_ERROR, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, web_error_cb) },
1112 { Pt_CB_MOZ_DOWNLOAD, NULL, NULL, Pt_ARG_IS_CALLBACK_LIST(PtMozillaWidget_t, web_download_cb) }
1115 static const PtArg_t args[] =
1117 { Pt_SET_VERSION, 200},
1118 { Pt_SET_STATE_LEN, sizeof( PtMozillaWidget_t ) },
1119 { Pt_SET_DFLTS_F, (long)mozilla_defaults },
1120 { Pt_SET_EXTENT_F, (long)mozilla_extent },
1121 { Pt_SET_FLAGS, Pt_RECTANGULAR, Pt_RECTANGULAR },
1122 { Pt_SET_DESTROY_F, (long) mozilla_destroy },
1123 { Pt_SET_CHILD_GETTING_FOCUS_F, ( long ) child_getting_focus },
1124 { Pt_SET_CHILD_LOSING_FOCUS_F, ( long ) child_losing_focus },
1125 { Pt_SET_RESOURCES, (long) resources },
1126 { Pt_SET_NUM_RESOURCES, sizeof( resources )/sizeof( resources[0] ) },
1127 { Pt_SET_DESCRIPTION, (long) "PtMozilla" },
1130 if (StartupEmbedding() == -1)
1131 return (NULL);
1133 Init_nsUnknownContentTypeHandler_Factory( );
1135 nsCOMPtr<nsIFactory> promptFactory;
1136 NS_NewPromptServiceFactory(getter_AddRefs(promptFactory));
1138 nsCOMPtr<nsIComponentRegistrar> registrar;
1139 NS_GetComponentRegistrar(getter_AddRefs(registrar));
1140 registrar->RegisterFactory(kPromptServiceCID, "Prompt Service",
1141 "@mozilla.org/embedcomp/prompt-service;1",
1142 promptFactory);
1143 PtMozilla->wclass = PtCreateWidgetClass(PtContainer, 0, sizeof(args)/sizeof(args[0]), args);
1145 return (PtMozilla->wclass);