1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: Mozilla-sample-code 1.0
4 * Copyright (c) 2002 Netscape Communications Corporation and
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this Mozilla sample software and associated documentation files
9 * (the "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to permit
12 * persons to whom the Software is furnished to do so, subject to the
13 * following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
27 * Adam Lock <adamlock@netscape.com>
29 * ***** END LICENSE BLOCK ***** */
33 #include "nsIProfile.h"
34 #include "nsIWindowWatcher.h"
36 #include "nsEmbedString.h"
38 #include "BrowserFrame.h"
39 #include "MailFrame.h"
40 #include "ChatFrame.h"
41 #include "EditorFrame.h"
43 #include "GeckoProtocolHandler.h"
44 #include "GeckoWindowCreator.h"
46 class FooCallback
: public GeckoChannelCallback
49 virtual nsresult
GetData(
52 nsACString
&aContentType
,
57 nsCAutoString
txt("<html><body>Hello, your URL was \'");
60 txt
.Append("\'</body></html>");
61 aContentType
.Assign("text/html");
63 size_t size
= txt
.Length();
64 *aData
= (void *) nsMemory::Alloc(size
+ 1);
66 return NS_ERROR_OUT_OF_MEMORY
;
67 memset(*aData
, 0, size
+ 1);
68 memcpy(*aData
, txt
.get(), size
);
74 class EmbedApp
: public wxApp
76 virtual bool OnInit();
80 void OnQuit(wxCommandEvent
&event
);
81 void OnAbout(wxCommandEvent
&event
);
82 void OnMail(wxCommandEvent
&event
);
83 void OnChat(wxCommandEvent
&event
);
84 void OnEditor(wxCommandEvent
&event
);
87 BEGIN_EVENT_TABLE(EmbedApp
, wxApp
)
88 EVT_MENU(XRCID("menu_quit"), EmbedApp::OnQuit
)
89 EVT_MENU(XRCID("menu_about"), EmbedApp::OnAbout
)
90 EVT_MENU(XRCID("menu_mail"), EmbedApp::OnMail
)
91 EVT_MENU(XRCID("menu_chat"), EmbedApp::OnChat
)
92 EVT_MENU(XRCID("menu_editor"), EmbedApp::OnEditor
)
95 ///////////////////////////////////////////////////////////////////////////////
97 IMPLEMENT_APP(EmbedApp
)
99 bool EmbedApp::OnInit()
101 wxImage::AddHandler(new wxGIFHandler
);
102 wxXmlResource::Get()->InitAllHandlers();
105 if (NS_FAILED(NS_InitEmbedding(nsnull
, nsnull
)))
111 nsCOMPtr
<nsIProfile
> profileService
=
112 do_GetService(NS_PROFILE_CONTRACTID
, &rv
);
113 rv
= profileService
->CreateNewProfile(L
"wxEmbed", nsnull
, nsnull
, PR_FALSE
);
114 if (NS_FAILED(rv
)) return FALSE
;
115 rv
= profileService
->SetCurrentProfile(L
"wxEmbed");
116 if (NS_FAILED(rv
)) return FALSE
;
118 GeckoProtocolHandler::RegisterHandler("foo", "Test handler", new FooCallback
);
120 // Register a window creator for popups
121 GeckoWindowCreator
*creatorCallback
= new GeckoWindowCreator();
124 nsCOMPtr
<nsIWindowCreator
> windowCreator(static_cast<nsIWindowCreator
*>(creatorCallback
));
127 nsCOMPtr
<nsIWindowWatcher
> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID
));
130 wwatch
->SetWindowCreator(windowCreator
);
135 // Create the main frame window
136 BrowserFrame
* frame
= new BrowserFrame(NULL
);
138 // frame->OnBrowserHome(wxCommandEvent());
145 int EmbedApp::OnExit()
147 // Shutdown the profile
149 nsCOMPtr
<nsIProfile
> profileService
=
150 do_GetService(NS_PROFILE_CONTRACTID
, &rv
);
151 if (NS_SUCCEEDED(rv
))
153 profileService
->ShutDownCurrentProfile(nsIProfile::SHUTDOWN_PERSIST
);
160 void EmbedApp::OnQuit(wxCommandEvent
& WXUNUSED(event
))
162 wxFrame
* frame
= NULL
;
166 frame = (wxFrame *) wxWindow::FindWindowByName("browser", NULL);;
170 frame = (wxFrame *) wxWindow::FindWindowByName("mail", NULL);;
173 frame = (wxFrame *) wxWindow::FindWindowByName("editor", NULL);;
176 frame = (wxFrame *) wxWindow::FindWindowByName("chat", NULL);;
182 GetTopWindow()->Close(TRUE
);
185 void EmbedApp::OnAbout(wxCommandEvent
& WXUNUSED(event
))
187 (void)wxMessageBox(_T("wxEmbed"), _T("About wxEmbed"));
190 void EmbedApp::OnMail(wxCommandEvent
& WXUNUSED(event
))
192 // Create the mail frame window
193 MailFrame
* frame
= (MailFrame
*) wxWindow::FindWindowByName("mail", NULL
);;
195 frame
= new MailFrame(NULL
);
200 void EmbedApp::OnChat(wxCommandEvent
& WXUNUSED(event
))
202 ChatFrame
* frame
= (ChatFrame
*) wxWindow::FindWindowByName("chat", NULL
);
204 frame
= new ChatFrame(NULL
);
209 void EmbedApp::OnEditor(wxCommandEvent
& WXUNUSED(event
))
211 EditorFrame
* frame
= (EditorFrame
*) wxWindow::FindWindowByName("editor", NULL
);
213 frame
= new EditorFrame(NULL
);