Register a nsIHelperAppLauncherDialog to handle docs out of gtkmozembed (pdfs, ...)
This commit is contained in:
		
							parent
							
								
									fcac3b87ca
								
							
						
					
					
						commit
						15e3a4f791
					
				@ -98,7 +98,8 @@ def start():
 | 
				
			|||||||
	gtkmozembed.set_profile_path(env.get_profile_path(), 'gecko')
 | 
						gtkmozembed.set_profile_path(env.get_profile_path(), 'gecko')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gtkmozembed.push_startup()
 | 
						gtkmozembed.push_startup()
 | 
				
			||||||
	_sugar.startup_browser()
 | 
						if not _sugar.startup_browser():
 | 
				
			||||||
 | 
							raise "Error when initializising the web activity."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	style.load_stylesheet(web.stylesheet)
 | 
						style.load_stylesheet(web.stylesheet)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -56,7 +56,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
(define-function startup_browser
 | 
					(define-function startup_browser
 | 
				
			||||||
  (c-name "sugar_browser_startup")
 | 
					  (c-name "sugar_browser_startup")
 | 
				
			||||||
  (return-type "none")
 | 
					  (return-type "gboolean")
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define-method grab_focus
 | 
					(define-method grab_focus
 | 
				
			||||||
 | 
				
			|||||||
@ -20,7 +20,9 @@ libsugarprivate_la_SOURCES = 	\
 | 
				
			|||||||
	sugar-push-scroller.c	\
 | 
						sugar-push-scroller.c	\
 | 
				
			||||||
	sugar-push-scroller.h	\
 | 
						sugar-push-scroller.h	\
 | 
				
			||||||
	sugar-tray-manager.c	\
 | 
						sugar-tray-manager.c	\
 | 
				
			||||||
	sugar-tray-manager.h
 | 
						sugar-tray-manager.h	\
 | 
				
			||||||
 | 
						sugar-content-handler.h			\
 | 
				
			||||||
 | 
						sugar-content-handler.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
BUILT_SOURCES = 		\
 | 
					BUILT_SOURCES = 		\
 | 
				
			||||||
	sugar-marshal.c		\
 | 
						sugar-marshal.c		\
 | 
				
			||||||
 | 
				
			|||||||
@ -18,6 +18,7 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "sugar-browser.h"
 | 
					#include "sugar-browser.h"
 | 
				
			||||||
 | 
					#include "sugar-content-handler.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <gtkmozembed_internal.h>
 | 
					#include <gtkmozembed_internal.h>
 | 
				
			||||||
#include <nsCOMPtr.h>
 | 
					#include <nsCOMPtr.h>
 | 
				
			||||||
@ -26,6 +27,12 @@
 | 
				
			|||||||
#include <nsIWebBrowser.h>
 | 
					#include <nsIWebBrowser.h>
 | 
				
			||||||
#include <nsIWebBrowserFocus.h>
 | 
					#include <nsIWebBrowserFocus.h>
 | 
				
			||||||
#include <nsIDOMWindow.h>
 | 
					#include <nsIDOMWindow.h>
 | 
				
			||||||
 | 
					#include <nsIGenericFactory.h>
 | 
				
			||||||
 | 
					#include <nsIHelperAppLauncherDialog.h>
 | 
				
			||||||
 | 
					#include <nsIComponentRegistrar.h>
 | 
				
			||||||
 | 
					#include <nsIComponentManager.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					NS_GENERIC_FACTORY_CONSTRUCTOR(GSugarContentHandler)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum {
 | 
					enum {
 | 
				
			||||||
	PROP_0,
 | 
						PROP_0,
 | 
				
			||||||
@ -37,17 +44,27 @@ enum {
 | 
				
			|||||||
	PROP_LOADING
 | 
						PROP_LOADING
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					static const nsModuleComponentInfo sSugarComponents[] = {
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							"Sugar Content Handler",
 | 
				
			||||||
 | 
							G_SUGARCONTENTHANDLER_CID,
 | 
				
			||||||
 | 
							NS_IHELPERAPPLAUNCHERDLG_CONTRACTID,
 | 
				
			||||||
 | 
							GSugarContentHandlerConstructor
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					gboolean
 | 
				
			||||||
sugar_browser_startup(void)
 | 
					sugar_browser_startup(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	nsCOMPtr<nsIPrefService> prefService;
 | 
						nsCOMPtr<nsIPrefService> prefService;
 | 
				
			||||||
 | 
						nsresult rv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	prefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
 | 
						prefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
 | 
				
			||||||
	NS_ENSURE_TRUE(prefService, );
 | 
						NS_ENSURE_TRUE(prefService, FALSE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	nsCOMPtr<nsIPrefBranch> pref;
 | 
						nsCOMPtr<nsIPrefBranch> pref;
 | 
				
			||||||
	prefService->GetBranch("", getter_AddRefs(pref));
 | 
						prefService->GetBranch("", getter_AddRefs(pref));
 | 
				
			||||||
	NS_ENSURE_TRUE(pref, );
 | 
						NS_ENSURE_TRUE(pref, FALSE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Block onload popups */
 | 
						/* Block onload popups */
 | 
				
			||||||
	pref->SetBoolPref("dom.disable_open_during_load", TRUE);
 | 
						pref->SetBoolPref("dom.disable_open_during_load", TRUE);
 | 
				
			||||||
@ -60,6 +77,43 @@ sugar_browser_startup(void)
 | 
				
			|||||||
	pref->SetCharPref("ui.buttonface", "#D3D3DD");
 | 
						pref->SetCharPref("ui.buttonface", "#D3D3DD");
 | 
				
			||||||
	pref->SetCharPref("ui.-moz-field", "#FFFFFF");
 | 
						pref->SetCharPref("ui.-moz-field", "#FFFFFF");
 | 
				
			||||||
	pref->SetCharPref("ui.-moz-fieldtext", "#000000");
 | 
						pref->SetCharPref("ui.-moz-fieldtext", "#000000");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nsCOMPtr<nsIComponentRegistrar> componentRegistrar;
 | 
				
			||||||
 | 
						NS_GetComponentRegistrar(getter_AddRefs(componentRegistrar));
 | 
				
			||||||
 | 
						NS_ENSURE_TRUE (componentRegistrar, FALSE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nsCOMPtr<nsIComponentManager> componentManager;
 | 
				
			||||||
 | 
						NS_GetComponentManager (getter_AddRefs (componentManager));
 | 
				
			||||||
 | 
						NS_ENSURE_TRUE (componentManager, FALSE);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						nsCOMPtr<nsIGenericFactory> componentFactory;
 | 
				
			||||||
 | 
						rv = NS_NewGenericFactory(getter_AddRefs(componentFactory), 
 | 
				
			||||||
 | 
												  &(sSugarComponents[0]));
 | 
				
			||||||
 | 
						if (NS_FAILED(rv) || !componentFactory) {
 | 
				
			||||||
 | 
							g_warning ("Failed to make a factory for %s\n", sSugarComponents[0].mDescription);
 | 
				
			||||||
 | 
							return FALSE;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rv = componentRegistrar->RegisterFactory(sSugarComponents[0].mCID,
 | 
				
			||||||
 | 
										 sSugarComponents[0].mDescription,
 | 
				
			||||||
 | 
										 sSugarComponents[0].mContractID,
 | 
				
			||||||
 | 
										 componentFactory);
 | 
				
			||||||
 | 
						if (NS_FAILED(rv)) {
 | 
				
			||||||
 | 
							g_warning ("Failed to register factory for %s\n", sSugarComponents[0].mDescription);
 | 
				
			||||||
 | 
							return FALSE;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (sSugarComponents[0].mRegisterSelfProc) {
 | 
				
			||||||
 | 
							rv = sSugarComponents[0].mRegisterSelfProc(componentManager, nsnull, 
 | 
				
			||||||
 | 
																	   nsnull, nsnull, 
 | 
				
			||||||
 | 
																	   &sSugarComponents[0]);
 | 
				
			||||||
 | 
							if (NS_FAILED(rv)) {
 | 
				
			||||||
 | 
								g_warning ("Failed to register-self for %s\n", sSugarComponents[0].mDescription);
 | 
				
			||||||
 | 
								return FALSE;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						return TRUE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
G_DEFINE_TYPE(SugarBrowser, sugar_browser, GTK_TYPE_MOZ_EMBED)
 | 
					G_DEFINE_TYPE(SugarBrowser, sugar_browser, GTK_TYPE_MOZ_EMBED)
 | 
				
			||||||
 | 
				
			|||||||
@ -54,7 +54,7 @@ struct _SugarBrowserClass {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GType			sugar_browser_get_type		(void);
 | 
					GType			sugar_browser_get_type		(void);
 | 
				
			||||||
void			sugar_browser_startup		(void);
 | 
					gboolean		sugar_browser_startup		(void);
 | 
				
			||||||
SugarBrowser   *sugar_browser_create_window	(SugarBrowser *browser);
 | 
					SugarBrowser   *sugar_browser_create_window	(SugarBrowser *browser);
 | 
				
			||||||
void			sugar_browser_scroll_pixels (SugarBrowser *browser,
 | 
					void			sugar_browser_scroll_pixels (SugarBrowser *browser,
 | 
				
			||||||
                            				 int           dx,
 | 
					                            				 int           dx,
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										36
									
								
								lib/src/sugar-content-handler.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								lib/src/sugar-content-handler.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "sugar-content-handler.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GSugarContentHandler::GSugarContentHandler()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GSugarContentHandler::~GSugarContentHandler()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					NS_IMPL_ISUPPORTS1(GSugarContentHandler, nsIHelperAppLauncherDialog)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					NS_IMETHODIMP
 | 
				
			||||||
 | 
					GSugarContentHandler::Show (nsIHelperAppLauncher *aLauncher,
 | 
				
			||||||
 | 
							       nsISupports *aContext,
 | 
				
			||||||
 | 
							       PRUint32 aReason)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return NS_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					NS_IMETHODIMP GSugarContentHandler::PromptForSaveToFile(
 | 
				
			||||||
 | 
									    nsIHelperAppLauncher *aLauncher,			    
 | 
				
			||||||
 | 
									    nsISupports *aWindowContext,
 | 
				
			||||||
 | 
									    const PRUnichar *aDefaultFile,
 | 
				
			||||||
 | 
									    const PRUnichar *aSuggestedFileExtension,
 | 
				
			||||||
 | 
									    nsILocalFile **_retval)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						return NS_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										28
									
								
								lib/src/sugar-content-handler.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								lib/src/sugar-content-handler.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					#ifndef __SUGAR_CONTENT_HANDLER_H__
 | 
				
			||||||
 | 
					#define __SUGAR_CONTENT_HANDLER_H__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <nsCOMPtr.h>
 | 
				
			||||||
 | 
					#include <nsIHelperAppLauncherDialog.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define G_SUGARCONTENTHANDLER_CID			     	 \
 | 
				
			||||||
 | 
					{ /* 2321843e-6377-11db-967b-00e08161165f */         \
 | 
				
			||||||
 | 
					    0x2321843e,                                      \
 | 
				
			||||||
 | 
					    0x6377,                                          \
 | 
				
			||||||
 | 
					    0x11db,                                          \
 | 
				
			||||||
 | 
					    {0x96, 0x7b, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f}  \
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class GSugarContentHandler : public nsIHelperAppLauncherDialog
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  public:
 | 
				
			||||||
 | 
						NS_DECL_ISUPPORTS
 | 
				
			||||||
 | 
						NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						GSugarContentHandler();
 | 
				
			||||||
 | 
						virtual ~GSugarContentHandler();
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					  private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* __SUGAR_CONTENT_HANDLER_H */
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user