How to access DOM of a web page in QtWebKit?
I don't see any methods exposing DOM in QtWebKit...
Currently, you need to do DOM manipulation via JavaScript, injected via
QVariant QWebFrame::evaluateJavaScript(const QString & scriptSource);
Right now as of Qt 4.4/4.5 I don't think there are any direct way, but it's coming. See http://labs.trolltech.com/blogs/2009/04/07/qwebelement-sees-the-light-do-i-hear-a-booyakasha/
the DOM manipulation via javascript method is incredibly poor. for any serious usage it very quickly becomes apparent that it is completely unusable. an experiment was made to create a runtime for pyjamas-desktop using pywebkitqt4 and it utterly, utterly failed. quite a lot was achieved - such as event callbacks written in python - but they had to be set up... by creating a javascript code-snippet! this approach is truly insane. every time you want to manipulate the DOM model from python you have to go via a crap language like javascript? anybody who thinks that's a good idea is completely off their heads.
fortunately at some point in the future i will be extending pythonwebkit to allow full access to DOM functions: it will be quite easy to do this, but i just don't have the time spare at the moment to compile up webkit for qt4 (it takes 90 mins for webkit with gtk as it is).
Related
I'm developing a Clojure application, which downloads images from the web and analyzes them for certain criteria.
Whatever this might mean, the important part is, that there will be some quite expensive functions in the app, which take a while until they are processed.
In the end, there will be an API that exposes the app's functionality to a web frontend. This is meant to be a second step though.
Since the app has a lot to do with graphics, it makes sense to visualize the outputs of the functions I'm writing during the development process.
Basically I'm looking for an easy way / environment to archive this.
More precisely: Whenever I created a new function, I want to test it's functionality inside a browser: E.g. plot the output, draw some intermediate steps, maybe create some small interactive scripts, that help me to supervise that the algorithms are doing what I intend to. Note: I don't want to to transform the functions to ClojureScript and let them run in the browser, the browser should be just a "display".
Some approaches that came to my mind:
Writing a little backend-server that exposes all the functions of a namespace. So the front-end could access all these functions simply by sending an ajax request to the server, that includes the function and it's parameters in a string, or maybe better in edn format. The back-end receives the request, calls the requested function and sends back the result whenever the calculation is done. Is there maybe already a project, that does exactly this?
Using a project like "Gorilla Repl" This would be a good option, and maybe I'm going to use it. However, I could not yet figure out if it's mechanism covers a way to interactively influence the rendered outputs. It rather works as a worksheet with static renderings.
How would you guys do this? Any suggestions are appreciated.
I have been working on similar problems and I think that you could use the combination of Lighttable + Clojure + Nerdy-painter (plugin).
Nerdy-painter allows you to display images on Lighttable (IDE). Very useful for data exploration or anything that has to do with graphics/plots.
Disclaimer: I am the author of nerdy-painter, still I think the fastest/elegant solution is the one I described above. All other solutions add (IMHO) too much overhead to the development cycle.
A possibility is to use a Jupyter's clojure kernel to interact with clojure. Jupyter runs in a browser and you can add custom binding to simplify access to the DOM.
Here's a clojure kernel: https://github.com/roryk/clojupyter
Does anybody know any libraries which allow to create GWT DOM tree without having a browser running. I need this for fast test. It seems to me that DOM classes contain a lot of native methods, which are almost impossible to mock.
Phantom JS may be suitable for your task. It runs WebKit in memory without any graphical interface so it works much faster then the "normal" browser.
Searching other stuff on internet I found it. I have no idea if it works for you, if yes, share your experience because your topic is useful:
https://github.com/gwt-test-utils/gwt-test-utils/wiki/Browser-simulation
I am a Firefox C++ extension newbie. I need to get access to DOM mutation events in my extension during page load. Firefox by default doesn't send DOM mutation events during page load to improve page load performance.
I understand the reason, but understanding the consequences I still need access to the DOM mutation events. I read somewhere that nsIMutationObserver still gets invoked during page load (and is bit more efficient then DOM mutation events as don't have to walk up the DOM tree looking for listeners), however it's only available to native code.
So I have following questions :
Is nsIMutationObserver and nsIMutationObserver2 available to Firefox extensions?
If yes, how can I write a simple Firefox extension in C++ to get access to it and expose it to Javascript?
If folks can point me to a existing extension that does this forwarding from C++ land to JS, that will be highly appreciated.
Or can I use JS-CTypes to get access to that functionality from my Javascript based extension?
BTW, I asked this question in Firefox's extension forum, but no replies there.
Thanks in advance
Is nsIMutationObserver and nsIMutationObserver2 available to Firefox extensions?
Yes, binary Firefox extensions can use it. Of course, the drawback is that your binary XPCOM component will only work with one Firefox release - it will have to be recompiled for each new release.
If yes, how can I write a simple Firefox extension in C++ to get access to it and expose it to Javascript?
You create an XPCOM component (see example code) and implement nsIMutationObserver interface. You then attach this mutation observer to documents like this:
NS_IMETHODIMP
MyMutationObserver::AttachToDocument(nsIDOMDocument* document)
{
nsCOMPtr<nsINode> node(do_QueryInterface(document));
node->AddMutationObserver(this);
}
For reference: nsINode interface
If folks can point me to a existing extension that does this forwarding from C++ land to JS, that will be highly appreciated.
Sorry, don't know any. But your XPCOM component can expose an additional interface that your JavaScript code will use - e.g. to register a callback. You have to consider that it might not be safe to run JavaScript when the mutation observer gets called. Important methods here: nsContentUtils::IsSafeToRunScript() and nsContentUtils::AddScriptRunner() (see nsContentUtils.h).
Or can I use JS-CTypes to get access to that functionality from my Javascript based extension?
No, you cannot. These are Gecko internals, they aren't exposed to js-ctypes.
A binary extension can use nsIMutationObserver, but unless it's very very careful about what it does when it's notified (see the big WARNING above the interface declaration) it'll cause crashes and various other broken behavior and is likely to introduce security bugs. Like any other internal API, this is a footgun; probably a fatal one if not used extremely carefully. Things that are fine to do in a DOM mutation listener are NOT OK in an nsIMutationObserver.
I am planning to use yui or jquery ui as front end for native c++ applications. I found no bindings present for this purpose. Will it be feasible/possible to do this ? If it is so, then how shall i proceed? please suggest advice.thanks
#rwik - I can see your point and desire to do what you intend and I would presume it to be a wise move to be making at this point in time considering the vast facilities browsers bring to the table as well as other aspects... I know we are in September now and I have come across this pretty late, but this is also for others who have a similar problem...
As far as I know, descending from JavaScript in to C++ is pretty murky, mostly due to the heterogenous nature of Javascript engines [Rhino, Tracemonkey, Spidermonkey, V8, Caracan,Charka, etc] employed by different browsers. But there are indeed ways to do this - depending on how dirty you want to get your hands and, indeed, on your abilities...
If you were to go with Google as a browser, you should take a look at projects such as cproxyv8 - http://code.google.com/p/cproxyv8/ or v8-juice - http://code.google.com/p/v8-juice/ which both offer interesting facilities...
My preference however is with Mozilla - simply because of XML User-Interface Language (XUL) which, if you do not know, allows you to speedily create your own user interfaces by giving direct access to its layout engine. I.e., you can even do away with the browser look and have your own independent layout while still having all browser facilities at your disposal.
With respect to C++/Javascript interaction - projects should exist for all alternatives - it pays to check.
I wish you good luck if you haven't already solved this problem.
I'd recommend QT instead.
However since native C++ has nothing to do with GUI I'm going to assume you are making a library in C++. However Yui is basically just JavaScript as is jQuery. So if you're asking can a web page or script be a C++ application the answer is not really.
What you could do is create a web service which uses your C++ library and exposes an interface for your web based application to call it indirectly.
One way to accomplish this is to embed WebKit into your application and provide your custom C++ functionality via a plugin. Both the WebKit framework on OSX and the Chromium Embedded Framework on Windows allow this style of application development. This allows you to write a UI using local Javascript/HTML files without the need for a webserver.
There are no direct bindings in JQuery and YUI because these libraries run in a web browser. Thus unless you’re planning to write your own browser plugins, the integration with the C++ will happen at the webserver that serves the data to the browser.
You could feed the data from your C++ code directly into JQuery/YUI by building web services directly in C++. But you might want to build a web application that will be serving your JQuery/YUI pages and that act as user interface controller (like in the MVC pattern). Web application languages like Java, PHP, etc. all have ways to call native code. Java has JNDI and in PHP you build extensions that link to C++ code.
Currently I'm working with ASP.NET 2.0, which may explain why I'm not as up on this as I might be. However, I don't see a full solution in my Googling of ASP.NET MVC, etc.
Here's my background thinking.
Firstly, data-bound templates are really useful. I'm currently dealing with lots of legacy code whereby people are building up controls programmatically, both on the client and the server, and it's a huge pain.
Secondly, sometimes you want controls to be data-bound on the client, sometimes on the server. The most obvious case for databinding on the server is where you're trying to account for people turning off javascript. But issues of speed, caching, bandwidth etc. all play their part as to deciding where to bind.
Now, on the server I can write UserControls with databinding points. And on the client I can write templates and bind them with JQuery (I'm currently using the microtemplating engine by John Resig as amended by Rick Strahl). But ideally there should be a way to write a template once and let the plumbing make it available for both server and client-side data binding. I guess that XML/XSLT would be one approach to this, but a horrible one. So what else is there? It needn't be an ASP.NET 2.0 solution; I'd just like to think that somewhere there is a fix.
HAML
You can create "datasource" objects that are independent of our databound controls / templates.
To use them with your databound control, instead of attaching them declaratively, e.g.:
<asp:gridview ...datasource="myDataSource"...>
you can attach them with code:
(some event)
me.Gridview1.datasource = "myXMLDataSource"
---or---
me.Gridview1.datasource = "mySQLDataSource"
If you set the datasources up ahead of time (either in the .aspx or in the code-behind is OK), then in this way, you can switch datasources based on some event, or logic, when you want to, without having to re-code / re-publish anything.