Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added isDevToolsOpen interface and missing impl. #4865

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/api/nw_current_window_internal.idl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace nw.currentWindowInternal {
static void close(optional boolean force);
static void showDevToolsInternal(optional ShowDevToolsCallback callback);
static void closeDevTools();
static void isDevToolsOpen();
static void setBadgeLabel(DOMString badge);
static void requestAttentionInternal(long count);
static void setProgressBar(double progress);
Expand Down
14 changes: 14 additions & 0 deletions src/api/nw_window_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,20 @@ bool NwCurrentWindowInternalCloseDevToolsFunction::RunAsync() {
return true;
}

bool NwCurrentWindowInternalIsDevToolsOpenFunction::RunNWSync(base::ListValue* response, std::string* error) {
content::RenderFrameHost* rfh = render_frame_host();
content::WebContents* web_contents = content::WebContents::FromRenderFrameHost(rfh);
scoped_refptr<content::DevToolsAgentHost> agent(
content::DevToolsAgentHost::GetOrCreateFor(web_contents));
DevToolsWindow* devtools_window =
DevToolsWindow::FindDevToolsWindow(agent.get());
if (devtools_window)
response->AppendBoolean(true);
else
response->AppendBoolean(false);
return true;
}

NwCurrentWindowInternalCapturePageInternalFunction::NwCurrentWindowInternalCapturePageInternalFunction() {
}

Expand Down
12 changes: 12 additions & 0 deletions src/api/nw_window_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ class NwCurrentWindowInternalCloseDevToolsFunction : public AsyncExtensionFuncti
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.closeDevTools", UNKNOWN)
};

class NwCurrentWindowInternalIsDevToolsOpenFunction : public NWSyncExtensionFunction {
public:
NwCurrentWindowInternalIsDevToolsOpenFunction() {};

protected:
~NwCurrentWindowInternalIsDevToolsOpenFunction() override {};
bool RunNWSync(base::ListValue* response, std::string* error) override;

// ExtensionFunction:
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.isDevToolsOpen", UNKNOWN)
};

class NwCurrentWindowInternalCapturePageInternalFunction : public AsyncExtensionFunction {
public:
NwCurrentWindowInternalCapturePageInternalFunction();
Expand Down
2 changes: 1 addition & 1 deletion src/api/window/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void Window::CallSync(const std::string& method,
bool transparent = shell_->window()->IsTransparent();
result->AppendBoolean(transparent);
} else if (method == "IsDevToolsOpen") {
result->AppendBoolean(shell_->devToolsOpen());
result->AppendBoolean(shell_->IsDevToolsOpen());
} else if (method == "ShowDevTools") {
std::string jail_id;
bool headless = false;
Expand Down
4 changes: 2 additions & 2 deletions src/api/window_bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ Window.prototype.__defineSetter__('isFullscreen', function(flag) {
this.leaveFullscreen();
});

Window.prototype.isDevToolsOpen = function () {
Window.prototype.__defineGetter__('isDevToolsOpen' = function () {
var result = CallObjectMethodSync(this, 'IsDevToolsOpen', []);
return Boolean(result[0]);
}
});

Window.prototype.__defineGetter__('isFullscreen', function() {
var result = CallObjectMethodSync(this, 'IsFullscreen', []);
Expand Down
2 changes: 1 addition & 1 deletion src/nw_shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Shell : public WebContentsDelegate,
void ReloadOrStop();
void ShowDevTools(const char* jail_id = NULL, bool headless = false);
void CloseDevTools();
bool devToolsOpen() { return devtools_window_.get() != NULL; }
bool IsDevToolsOpen() { return devtools_window_.get() != NULL; }
// Send an event to renderer.
void SendEvent(const std::string& event, const std::string& arg1 = "");
void SendEvent(const std::string& event, const base::ListValue& args);
Expand Down