Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions appshell/appshell_extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate {
CefRefPtr<CefProcessMessage> message) OVERRIDE {
std::string message_name = message->GetName();
CefRefPtr<CefListValue> argList = message->GetArgumentList();
int32 callbackId;
int32 callbackId = -1;
int32 error = NO_ERROR;
CefRefPtr<CefProcessMessage> response =
CefProcessMessage::Create("invokeCallback");
Expand All @@ -53,12 +53,13 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate {
// argument0 - the id of this message. This id is passed back to the
// render process in order to execute callbacks
// argument1 - argumentN - the arguments for the function
//
// Note: Functions without callback can be specified, but they *cannot*
// take any arguments.

if (argList->GetSize() < 1) {
fprintf(stderr, "No callback id specified for function %s\n", message_name.c_str());
return false;
}
callbackId = argList->GetInt(0);
// If we have any arguments, the first is the callbackId
if (argList->GetSize() > 0)
callbackId = argList->GetInt(0);

if (message_name == "ShowOpenDialog") {
// Parameters:
Expand Down Expand Up @@ -212,17 +213,24 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate {

// No additional response args for this function
}
} else if (message_name == "ShowDeveloperTools") {
// Parameters - none

handler->ShowDevTools(browser);

} else {
fprintf(stderr, "Native function not implemented yet: %s\n", message_name.c_str());
return false;
}

// Set common response args (callbackId and error)
responseArgs->SetInt(0, callbackId);
responseArgs->SetInt(1, error);

// Send response
browser->SendProcessMessage(PID_RENDERER, response);
if (callbackId != -1) {
// Set common response args (callbackId and error)
responseArgs->SetInt(0, callbackId);
responseArgs->SetInt(1, error);

// Send response
browser->SendProcessMessage(PID_RENDERER, response);
}

return true;
}
Expand Down
3 changes: 3 additions & 0 deletions appshell/cefclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ void AppGetSettings(CefSettings& settings, CefRefPtr<ClientApp> app) {
// Provide a ClientApp instance to handle proxy resolution.
app->SetProxyConfig(proxy_type, proxy_config);
}

// Enable dev tools
settings.remote_debugging_port = 9234;
}

// Returns the application browser settings based on command line arguments.
Expand Down
14 changes: 8 additions & 6 deletions appshell/client_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,30 +144,32 @@ class AppShellExtensionHandler : public CefV8Handler {
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
CefString& exception) {

// The only message that is handled here is getElapsedMilliseconds(). All other
// messages are passed to the browser process.
if (name == "GetElapsedMilliseconds") {
retval = CefV8Value::CreateDouble(client_app_->GetElapsedMilliseconds());
} else {
// Pass all messages to the browser process. Look in appshell_extensions.cpp for implementation.
CefRefPtr<CefBrowser> browser =
CefV8Context::GetCurrentContext()->GetBrowser();
CefV8Context::GetCurrentContext()->GetBrowser();
ASSERT(browser.get());
CefRefPtr<CefProcessMessage> message =
CefProcessMessage::Create(name);
CefRefPtr<CefListValue> messageArgs = message->GetArgumentList();

// The first argument must be a callback function
if (arguments.size() < 1 || !arguments[0]->IsFunction()) {
if (arguments.size() > 0 && !arguments[0]->IsFunction()) {
std::string functionName = name;
fprintf(stderr, "Function called without callback param: %s\n", functionName.c_str());
return false;
}

// The first argument is the message id
client_app_->AddCallback(messageId, CefV8Context::GetCurrentContext(), arguments[0]);
SetListValue(messageArgs, 0, CefV8Value::CreateInt(messageId));
if (arguments.size() > 0) {
// The first argument is the message id
client_app_->AddCallback(messageId, CefV8Context::GetCurrentContext(), arguments[0]);
SetListValue(messageArgs, 0, CefV8Value::CreateInt(messageId));
}

// Pass the rest of the arguments
for (unsigned int i = 1; i < arguments.size(); i++)
Expand Down
8 changes: 7 additions & 1 deletion appshell/client_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "string_util.h"
#include "appshell/appshell_extensions.h"


// Custom menu command Ids.
enum client_menu_ids {
CLIENT_ID_SHOW_DEVTOOLS = MENU_ID_USER_FIRST,
Expand Down Expand Up @@ -292,6 +291,13 @@ void ClientHandler::ShowDevTools(CefRefPtr<CefBrowser> browser) {
}
}

bool ClientHandler::OnBeforeUnloadDialog(CefRefPtr<CefBrowser> browser,
const CefString& message_text,
bool is_reload,
CefRefPtr<CefJSDialogCallback> callback) {
return false;
}

// static
void ClientHandler::CreateProcessMessageDelegates(
ProcessMessageDelegateSet& delegates) {
Expand Down
15 changes: 13 additions & 2 deletions appshell/client_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class ClientHandler : public CefClient,
public CefRequestHandler,
public CefDisplayHandler,
public CefGeolocationHandler,
public CefContextMenuHandler {
public CefContextMenuHandler,
public CefJSDialogHandler {
public:
// Interface for process message delegates. Do not perform work in the
// RenderDelegate constructor.
Expand Down Expand Up @@ -85,6 +86,10 @@ class ClientHandler : public CefClient,
virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() OVERRIDE {
return this;
}

virtual bool OnProcessMessageRecieved(CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message)
Expand Down Expand Up @@ -180,6 +185,12 @@ class ClientHandler : public CefClient,

void ShowDevTools(CefRefPtr<CefBrowser> browser);

// CefJSDialogHandler methods
virtual bool OnBeforeUnloadDialog(CefRefPtr<CefBrowser> browser,
const CefString& message_text,
bool is_reload,
CefRefPtr<CefJSDialogCallback> callback);

protected:
void SetLoading(bool isLoading);
void SetNavState(bool canGoBack, bool canGoForward);
Expand Down Expand Up @@ -217,7 +228,7 @@ class ClientHandler : public CefClient,
CefWindowHandle m_ForwardHwnd;
CefWindowHandle m_StopHwnd;
CefWindowHandle m_ReloadHwnd;

// Support for logging.
std::string m_LogFile;

Expand Down