for my app I implemented CefMessageRouterBrowserSide::Handler and the following functions for the render process.
- OnContextCreated
- OnContextReleased
- OnProcessMessageReceived
- Code: Select all
// Create and send a new query.
if (window.cefQuery) {
requestId = window.cefQuery({
request: 'maximizedListener',
persistent: true,
onSuccess: function (response) {
var value = true;
if (response === 'maximized') {
value = true;
} else {
value = false;
}
$scope.$apply(function () {
$scope.maximized = value;
});
},
onFailure: function () {
$scope.$apply(function () {
requestId = null;
});
}
});
}
It is used to either show a maximize button or a restore button (like the typical Windows controls in the upper right corner of a window).
It works quite well, until I start a file download. For example a pdf download: <a href="pdf/file.pdf">file download</a>. In OnBeforeDownload I open a file save dialog via callback->Continue.
After that, I'm returning to my app, but the query in my MaximizeHandler has been canceled and the callback is now invalid. Does someone have a clue, how to reinstantiate the query or to make it outlive the pdf download in the first place? Because the JavaScript context is not really released here ...
This calling order might be helpful:
- OnBeforeBrowse
- --> OnQueryCanceled
- OnBeforeResourceLoad
- GetResourceHandler
- OnBeforeDownload
This is the code for my handler.
- Code: Select all
const char kMaximizedListener[] = "maximizedListener";
// Handle messages in the browser process.
class MaximizeHandler : public CefMessageRouterBrowserSide::Handler {
public:
MaximizeHandler() : callback_(NULL) {}
CefRefPtr<Callback> GetCallback() {
return callback_;
}
virtual bool OnQuery(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int64 query_id,
const CefString& request,
bool persistent,
CefRefPtr<Callback> callback) OVERRIDE{
const std::string& message_name = request;
if (message_name.compare(kMaximizedListener) == 0) {
callback_ = callback;
return true;
}
return false;
}
virtual void OnQueryCanceled(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int64 query_id) OVERRIDE{
callback_ = NULL;
}
private:
CefRefPtr<Callback> callback_;
};
P.S. I have an idea for a workaround. It is to start the download inside of a hidden iframe. Is this really necessary?