Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit 2bc46af

Browse files
committed
Merge pull request #3 from adobe/glenn/show-dev-tools
Add support for ShowDevelopmentTools
2 parents 650fbff + 13ad1b7 commit 2bc46af

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

appshell/appshell_extensions.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate {
4141
CefRefPtr<CefProcessMessage> message) OVERRIDE {
4242
std::string message_name = message->GetName();
4343
CefRefPtr<CefListValue> argList = message->GetArgumentList();
44-
int32 callbackId;
44+
int32 callbackId = -1;
4545
int32 error = NO_ERROR;
4646
CefRefPtr<CefProcessMessage> response =
4747
CefProcessMessage::Create("invokeCallback");
@@ -53,12 +53,13 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate {
5353
// argument0 - the id of this message. This id is passed back to the
5454
// render process in order to execute callbacks
5555
// argument1 - argumentN - the arguments for the function
56+
//
57+
// Note: Functions without callback can be specified, but they *cannot*
58+
// take any arguments.
5659

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

6364
if (message_name == "ShowOpenDialog") {
6465
// Parameters:
@@ -212,17 +213,24 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate {
212213

213214
// No additional response args for this function
214215
}
216+
} else if (message_name == "ShowDeveloperTools") {
217+
// Parameters - none
218+
219+
handler->ShowDevTools(browser);
220+
215221
} else {
216222
fprintf(stderr, "Native function not implemented yet: %s\n", message_name.c_str());
217223
return false;
218224
}
219225

220-
// Set common response args (callbackId and error)
221-
responseArgs->SetInt(0, callbackId);
222-
responseArgs->SetInt(1, error);
223-
224-
// Send response
225-
browser->SendProcessMessage(PID_RENDERER, response);
226+
if (callbackId != -1) {
227+
// Set common response args (callbackId and error)
228+
responseArgs->SetInt(0, callbackId);
229+
responseArgs->SetInt(1, error);
230+
231+
// Send response
232+
browser->SendProcessMessage(PID_RENDERER, response);
233+
}
226234

227235
return true;
228236
}

appshell/cefclient.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ void AppGetSettings(CefSettings& settings, CefRefPtr<ClientApp> app) {
156156
// Provide a ClientApp instance to handle proxy resolution.
157157
app->SetProxyConfig(proxy_type, proxy_config);
158158
}
159+
160+
// Enable dev tools
161+
settings.remote_debugging_port = 9234;
159162
}
160163

161164
// Returns the application browser settings based on command line arguments.

appshell/client_app.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,30 +144,32 @@ class AppShellExtensionHandler : public CefV8Handler {
144144
const CefV8ValueList& arguments,
145145
CefRefPtr<CefV8Value>& retval,
146146
CefString& exception) {
147-
147+
148148
// The only message that is handled here is getElapsedMilliseconds(). All other
149149
// messages are passed to the browser process.
150150
if (name == "GetElapsedMilliseconds") {
151151
retval = CefV8Value::CreateDouble(client_app_->GetElapsedMilliseconds());
152152
} else {
153153
// Pass all messages to the browser process. Look in appshell_extensions.cpp for implementation.
154154
CefRefPtr<CefBrowser> browser =
155-
CefV8Context::GetCurrentContext()->GetBrowser();
155+
CefV8Context::GetCurrentContext()->GetBrowser();
156156
ASSERT(browser.get());
157157
CefRefPtr<CefProcessMessage> message =
158158
CefProcessMessage::Create(name);
159159
CefRefPtr<CefListValue> messageArgs = message->GetArgumentList();
160160

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

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

172174
// Pass the rest of the arguments
173175
for (unsigned int i = 1; i < arguments.size(); i++)

appshell/client_handler.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "string_util.h"
1515
#include "appshell/appshell_extensions.h"
1616

17-
1817
// Custom menu command Ids.
1918
enum client_menu_ids {
2019
CLIENT_ID_SHOW_DEVTOOLS = MENU_ID_USER_FIRST,
@@ -292,6 +291,13 @@ void ClientHandler::ShowDevTools(CefRefPtr<CefBrowser> browser) {
292291
}
293292
}
294293

294+
bool ClientHandler::OnBeforeUnloadDialog(CefRefPtr<CefBrowser> browser,
295+
const CefString& message_text,
296+
bool is_reload,
297+
CefRefPtr<CefJSDialogCallback> callback) {
298+
return false;
299+
}
300+
295301
// static
296302
void ClientHandler::CreateProcessMessageDelegates(
297303
ProcessMessageDelegateSet& delegates) {

appshell/client_handler.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class ClientHandler : public CefClient,
2525
public CefRequestHandler,
2626
public CefDisplayHandler,
2727
public CefGeolocationHandler,
28-
public CefContextMenuHandler {
28+
public CefContextMenuHandler,
29+
public CefJSDialogHandler {
2930
public:
3031
// Interface for process message delegates. Do not perform work in the
3132
// RenderDelegate constructor.
@@ -85,6 +86,10 @@ class ClientHandler : public CefClient,
8586
virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() OVERRIDE {
8687
return this;
8788
}
89+
virtual CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() OVERRIDE {
90+
return this;
91+
}
92+
8893
virtual bool OnProcessMessageRecieved(CefRefPtr<CefBrowser> browser,
8994
CefProcessId source_process,
9095
CefRefPtr<CefProcessMessage> message)
@@ -180,6 +185,12 @@ class ClientHandler : public CefClient,
180185

181186
void ShowDevTools(CefRefPtr<CefBrowser> browser);
182187

188+
// CefJSDialogHandler methods
189+
virtual bool OnBeforeUnloadDialog(CefRefPtr<CefBrowser> browser,
190+
const CefString& message_text,
191+
bool is_reload,
192+
CefRefPtr<CefJSDialogCallback> callback);
193+
183194
protected:
184195
void SetLoading(bool isLoading);
185196
void SetNavState(bool canGoBack, bool canGoForward);
@@ -217,7 +228,7 @@ class ClientHandler : public CefClient,
217228
CefWindowHandle m_ForwardHwnd;
218229
CefWindowHandle m_StopHwnd;
219230
CefWindowHandle m_ReloadHwnd;
220-
231+
221232
// Support for logging.
222233
std::string m_LogFile;
223234

0 commit comments

Comments
 (0)