Difference between revisions of "Mozilla.dev.embedding"
m (→How to start Embedding) |
|||
(15 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Newsgroup == | == Newsgroup == | ||
− | Mozilla.dev.embedding | + | [http://groups.google.com/group/mozilla.dev.embedding Mozilla.dev.embedding] <br/> |
== Authors == | == Authors == | ||
Line 7: | Line 7: | ||
# Cesar | # Cesar | ||
− | == | + | == Notice == |
− | [[20060929embedding| September 22, 2006 - September 29, 2009]] | + | There is already an [http://developer.mozilla.org/en/docs/Mozilla_Embedding_FAQ embedding FAQ on mozilla] that probably wasn't properly linked in with Mozilla's FAQ page. Instead, I am going to make a list of asked questions on this page and mozilla can put it into their FAQ at their discretion. |
+ | <!--[[20060929embedding| September 22, 2006 - September 29, 2009]] <br> | ||
+ | [http://developer.mozilla.org/en/docs/Newsgroup_summaries:mozilla-dev-embedding September 29, 2006 - October 6, 2006] | ||
+ | The newsgroup is more FAQ than discussion. So you can find the FAQ on [http://developer.mozilla.org/en/docs/embedding_FAQ mozilla]--> | ||
+ | |||
+ | == Important GtkMozEmbed 1.9 information == | ||
+ | |||
+ | Timeless has become the new owner of GtkMozEmbed. You can read about some of the changes [http://groups.google.ca/group/mozilla.dev.embedding/browse_thread/thread/3c786f3d7140a6da/beebaa4f5fd822a9?hl=en#beebaa4f5fd822a9 here] | ||
== FAQ == | == FAQ == | ||
+ | |||
===How to start Embedding=== | ===How to start Embedding=== | ||
You can find a examples, FAQs, and the API from [http://www.mozilla.org/projects/embedding/ mozilla] itself. <br/> | You can find a examples, FAQs, and the API from [http://www.mozilla.org/projects/embedding/ mozilla] itself. <br/> | ||
− | You can get more detailed information on what interfaces are required and which are optional to | + | You can get more detailed information on what interfaces are required and which are optional to impelement [http://developer.mozilla.org/en/docs/Gecko_Embedding_Basics here]. Scroll down to "Initalization and Teardown. |
+ | |||
+ | ===How to customize document retrieval=== | ||
+ | One method is to implement your own protocol method. You can find more information on adding new protocols [http://kb.mozillazine.org/Dev_:_Protocol_Handlers here] | ||
+ | |||
+ | ===How to embedding mozilla inside of Java=== | ||
+ | There hasn't been any good code examples found. However, there is a stripped down, uncommented code with eclipse libraries in [http://groups.google.com/group/mozilla.dev.embedding/browse_thread/thread/46c259db088ee584/76f2073388eaffdd#76f2073388eaffdd this] thread. Here is the code : | ||
+ | <pre> | ||
+ | import org.eclipse.swt.SWT; | ||
+ | import org.eclipse.swt.browser.MozillaBrowser; | ||
+ | import org.eclipse.swt.browser.ProgressEvent; | ||
+ | import org.eclipse.swt.browser.ProgressListener; | ||
+ | import org.eclipse.swt.widgets.Display; | ||
+ | import org.eclipse.swt.widgets.Shell; | ||
+ | import org.mozilla.xpcom.nsIDOMDocument; | ||
+ | |||
+ | public class Test { | ||
+ | public static void main(String args[]) { | ||
+ | Display display = new Display(); | ||
+ | Shell shell = new Shell(display); | ||
+ | |||
+ | final MozillaBrowser browser = new MozillaBrowser(shell,WT.BORDER); | ||
+ | browser.setUrl("http://www.google.com"); | ||
+ | browser.addProgressListener(new ProgressListener() { | ||
+ | public void changed(ProgressEvent event) { | ||
+ | } | ||
+ | |||
+ | public void completed(ProgressEvent event) { | ||
+ | nsIDOMDocument doc = browser.getDocument(); | ||
+ | System.out.println(doc); | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | while (!shell.isDisposed()) { | ||
+ | if (!display.readAndDispatch()) { | ||
+ | display.sleep(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | ===How to map a Javascript function to a C++ function=== | ||
+ | Define an XPCOM class defining the function you'll be doing in javascript. Then pass the object to your XPCOM coded object and call it from C++. You can find a better quality answer repeated and with an example in [http://groups.google.com/group/mozilla.dev.embedding/browse_thread/thread/af33a04e00387f5d/34d897200d736061#34d897200d736061 this newsgroup thread]. | ||
+ | |||
+ | ===nsIPromptService with secure sites=== | ||
+ | The problem is getting "Security Error: Domain Name Mismatch" when visting certain secure sites. You get no text and no functionality. There are two possible solutions to this error. | ||
+ | #The Dialog is not handled by the prompt service. You must implement another interface (for example, nsIBadCertListener) | ||
+ | #The original dialog does not work correctly because your application is not handling chrome correctly. Here are some things other people have used to solve their problems : | ||
+ | #*This will get the text in the security popup and allow you to view the certificate : <br/> In the nsIWindowCreator::CreateChromeWindow() implementation, change the doc shell tree item's type to ''nsIDocShellTreeItem::typeChromeWrapper'' to ''nsIDocShellTreeItem::typeContentWrapper'' to view the certificate. You can nsIWebBrowserChrome::CHROME_OPENAS_CHROME to check when to use typeChromeWrapper and typeContentWrapper | ||
+ | #*This will tell the browser to progress to the secure site | ||
+ | <code> | ||
+ | :nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1")); | ||
+ | if (stack && NS_SUCCEEDED(stack->Push(nsnull))) { | ||
+ | /* Display the modal window here */ | ||
+ | JSContext* cx; | ||
+ | stack->Pop(&cx); | ||
+ | }</code> | ||
+ | |||
+ | === How to control what is, and what is not, loaded === | ||
+ | Some people have complained that nsIURIContentListener::OnStartURIOpen() is not called for logos (images) and CSS. This is because you must use [http://developer.mozilla.org/en/docs/index.php?title=Creating_XPCOM_Components:Finishing_the_Component&redirect=no#Implementing_the_nsIContentPolicy nsIContentPolicy]. | ||
+ | |||
+ | === What is winEmbed? === | ||
+ | It is the window class associated with the mozilla custom control. | ||
+ | |||
+ | === How can I use the new nsIWindowProvider in Mozilla 1.8.1? === | ||
+ | If you have SetWebBrowserChrome on the tree owner, just implement the nsIInterfaceRequestor on that object and call the GetInterface implementation, which returns an nsIwindowsProvider. | ||
+ | |||
+ | [http://lxr.mozilla.org/mozilla/source/camino/src/embedding/CHBrowserListener.mm This] was marked as a good example, but no line number was given. | ||
+ | |||
+ | === How do I save HTML as an image === | ||
+ | There is a test application that allows you to take a snapshot of rendered HTML and save it as an image. The program and code is available [http://ubrowser.com/testapps.php here] | ||
+ | |||
+ | === Why does TestGTKEmbed give an error message when I download something and 'save as/ open with' pops up? === | ||
+ | You have to implement your own download UI as gtkmozembed doesn't have one. Alternatively, you can download files using nsIWebBrowserPersist if UI isn't a concern. | ||
+ | |||
+ | === How to rebuild tests in only part of the Mozilla Suite === | ||
+ | Go into the folder where the tests are found and issue make. If you built mozilla with an object directory, you must change into that directory into there first. | ||
+ | |||
+ | === How do I render strings provided by the user? === | ||
+ | use the nsIWebBrowserStream. You can get it by a do_QueryInterface() on the nsIWebBrowser you use. Look at the file [http://lxr.mozilla.org/mozilla1.8.0/source/embedding/browser/gtk/src/EmbedPrivate.cpp embedding/browser/gtk/src/EmbedPrivate.cpp] and the methods OpenStream(), AppendToStream(), and CloseStream() to get sample implementations | ||
+ | |||
+ | === Is there any support for the Firefox XPI extensions in gtkmozembed? === | ||
+ | No. It is not planned for the future. | ||
+ | |||
+ | === Why does mfcembed crash when accessing secure sites? === | ||
+ | There may be multiple solutions to this problem. One possible solution is that you tried to use nss without probing it first to initialize itself. |
Latest revision as of 20:11, 30 November 2006
Contents
- 1 Newsgroup
- 2 Authors
- 3 Notice
- 4 Important GtkMozEmbed 1.9 information
- 5 FAQ
- 5.1 How to start Embedding
- 5.2 How to customize document retrieval
- 5.3 How to embedding mozilla inside of Java
- 5.4 How to map a Javascript function to a C++ function
- 5.5 nsIPromptService with secure sites
- 5.6 How to control what is, and what is not, loaded
- 5.7 What is winEmbed?
- 5.8 How can I use the new nsIWindowProvider in Mozilla 1.8.1?
- 5.9 How do I save HTML as an image
- 5.10 Why does TestGTKEmbed give an error message when I download something and 'save as/ open with' pops up?
- 5.11 How to rebuild tests in only part of the Mozilla Suite
- 5.12 How do I render strings provided by the user?
- 5.13 Is there any support for the Firefox XPI extensions in gtkmozembed?
- 5.14 Why does mfcembed crash when accessing secure sites?
Newsgroup
Authors
- Cesar
Notice
There is already an embedding FAQ on mozilla that probably wasn't properly linked in with Mozilla's FAQ page. Instead, I am going to make a list of asked questions on this page and mozilla can put it into their FAQ at their discretion.
Important GtkMozEmbed 1.9 information
Timeless has become the new owner of GtkMozEmbed. You can read about some of the changes here
FAQ
How to start Embedding
You can find a examples, FAQs, and the API from mozilla itself.
You can get more detailed information on what interfaces are required and which are optional to impelement here. Scroll down to "Initalization and Teardown.
How to customize document retrieval
One method is to implement your own protocol method. You can find more information on adding new protocols here
How to embedding mozilla inside of Java
There hasn't been any good code examples found. However, there is a stripped down, uncommented code with eclipse libraries in this thread. Here is the code :
import org.eclipse.swt.SWT; import org.eclipse.swt.browser.MozillaBrowser; import org.eclipse.swt.browser.ProgressEvent; import org.eclipse.swt.browser.ProgressListener; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.mozilla.xpcom.nsIDOMDocument; public class Test { public static void main(String args[]) { Display display = new Display(); Shell shell = new Shell(display); final MozillaBrowser browser = new MozillaBrowser(shell,WT.BORDER); browser.setUrl("http://www.google.com"); browser.addProgressListener(new ProgressListener() { public void changed(ProgressEvent event) { } public void completed(ProgressEvent event) { nsIDOMDocument doc = browser.getDocument(); System.out.println(doc); } }); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
How to map a Javascript function to a C++ function
Define an XPCOM class defining the function you'll be doing in javascript. Then pass the object to your XPCOM coded object and call it from C++. You can find a better quality answer repeated and with an example in this newsgroup thread.
nsIPromptService with secure sites
The problem is getting "Security Error: Domain Name Mismatch" when visting certain secure sites. You get no text and no functionality. There are two possible solutions to this error.
- The Dialog is not handled by the prompt service. You must implement another interface (for example, nsIBadCertListener)
- The original dialog does not work correctly because your application is not handling chrome correctly. Here are some things other people have used to solve their problems :
- This will get the text in the security popup and allow you to view the certificate :
In the nsIWindowCreator::CreateChromeWindow() implementation, change the doc shell tree item's type to nsIDocShellTreeItem::typeChromeWrapper to nsIDocShellTreeItem::typeContentWrapper to view the certificate. You can nsIWebBrowserChrome::CHROME_OPENAS_CHROME to check when to use typeChromeWrapper and typeContentWrapper - This will tell the browser to progress to the secure site
- This will get the text in the security popup and allow you to view the certificate :
:nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1")); if (stack && NS_SUCCEEDED(stack->Push(nsnull))) { /* Display the modal window here */ JSContext* cx; stack->Pop(&cx); }
How to control what is, and what is not, loaded
Some people have complained that nsIURIContentListener::OnStartURIOpen() is not called for logos (images) and CSS. This is because you must use nsIContentPolicy.
What is winEmbed?
It is the window class associated with the mozilla custom control.
How can I use the new nsIWindowProvider in Mozilla 1.8.1?
If you have SetWebBrowserChrome on the tree owner, just implement the nsIInterfaceRequestor on that object and call the GetInterface implementation, which returns an nsIwindowsProvider.
This was marked as a good example, but no line number was given.
How do I save HTML as an image
There is a test application that allows you to take a snapshot of rendered HTML and save it as an image. The program and code is available here
Why does TestGTKEmbed give an error message when I download something and 'save as/ open with' pops up?
You have to implement your own download UI as gtkmozembed doesn't have one. Alternatively, you can download files using nsIWebBrowserPersist if UI isn't a concern.
How to rebuild tests in only part of the Mozilla Suite
Go into the folder where the tests are found and issue make. If you built mozilla with an object directory, you must change into that directory into there first.
How do I render strings provided by the user?
use the nsIWebBrowserStream. You can get it by a do_QueryInterface() on the nsIWebBrowser you use. Look at the file embedding/browser/gtk/src/EmbedPrivate.cpp and the methods OpenStream(), AppendToStream(), and CloseStream() to get sample implementations
Is there any support for the Firefox XPI extensions in gtkmozembed?
No. It is not planned for the future.
Why does mfcembed crash when accessing secure sites?
There may be multiple solutions to this problem. One possible solution is that you tried to use nss without probing it first to initialize itself.