Issue with invoking Bracket-Shell bespoke Native (C++) Method

I'm currently working on developing a unique C++ function that can be invoked from JavaScript to resize the window.

The necessary components are located in various files:

Within appshell_extensions_platform.h:

#if defined(OS_WIN)
void ResizeWindow(CefRefPtr<CefBrowser> browser, int width, int height);
#endif

Inside appshell_extensions_win.cpp:

void ResizeWindow(CefRefPtr<CefBrowser> browser, int width, int height) {
    OutputDebugString(L"ResizeWindow");
    CefWindowHandle hWnd = browser->GetHost()->GetWindowHandle();
    SetWindowPos(hWnd, 0, 0, 0, width, height, SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
}

Within appshell_extensions.js:

/**
  * Modifies the window size to the specified dimensions.
  *
  * @param {number} width
  * @param {number} height
  *
  * @return None. This function is asynchronous and sends return information to the callback.
 */
 native function ResizeWindow();
 appshell.app.resizeWindow = function (width, height) {
     ResizeWindow(width, height);
 };

In appshell_extensions.cpp:

} else if (message_name == "ResizeWindow") {
    // Parameters:
    //  0: int32 - width
    //  1: int32 - height
    int width = argList->GetInt(0);
    int height = argList->GetInt(1);
    ResizeWindow(browser, width, height);
}

Using Visual Studio 2012, I compile and debug on the Debug Win32 release. The appshell.app.resizeWindow function appears in the console as expected and functions correctly when called. Additional JavaScript code within the function also executes properly.

I've added

OutputDebugString(std::wstring(message_name.begin(), message_name.end()).c_str());
to the function in appshell_extensions.cpp. While it outputs message names for other functions, I receive no output for the function I implemented.

Furthermore, I don't receive any output from the function itself.

It seems like the message isn't reaching the processing function, but I'm unsure of the issue. I'm using the provided solution from brackets-shell (converted to 2012) for compilation. Is there a possible build step that I might be overlooking?

Thank you.

Answer №1

The ProcessMessageDelegate::OnProcessMessageReceived() function (found in appshell_extension.cpp) is responsible for debugging message names and runs within the Renderer process. To properly debug this function, you must attach the Visual Studio debugger to the subprocess rather than the Browser process (main process) you are currently debugging.

To simplify the debugging of subprocesses in a console window, consider creating a separate console window for each subprocess using the following code:

if (show_console) {
    AllocConsole();
    FILE* freopen_file;
    freopen_s(&freopen_file, "CONIN$", "rb", stdin);
    freopen_s(&freopen_file, "CONOUT$", "wb", stdout);
    freopen_s(&freopen_file, "CONOUT$", "wb", stderr);
}

Place this code before the CefExecuteProcess() function that initiates subprocesses.

For an example of how this is implemented in the PHP Desktop project:

  1. Refer to the subprocess_show_console variable in main.cpp. https://code.google.com/p/phpdesktop/source/browse/phpdesktop-chrome/main.cpp?r=6de71bd0217a#126

  2. Initialization of logging using InitializeLogging() includes the above code snippet.

  3. Followed by the call to CefExecuteProcess.


Debugging subprocesses in a console window is simpler on Linux where all output is automatically forwarded from subprocesses to the console. This convenient feature is unfortunately missing on Windows.

Answer №2

I managed to identify the issue.

It turns out that in the JavaScript functions, the first parameter is required to be a callback, even if it is not used.

By modifying the JavaScript section as follows, the problem was resolved:

/**
  * Resize the window to the specified dimensions.
  *
  * @param {number} width
  * @param {number} height
  *
  * @return None. This is an asynchronous call that forwards all return data to the callback.
 */
 native function ResizeWindow();
 appshell.app.resizeWindow = function (width, height) {
     ResizeWindow(_dummyCallback, width, height);
 };

I also encountered a slight complication with the resizing logic itself. It is necessary to utilize the window handle of the parent

browser->getHost()->getWindowHandle()
:

`CefWindowHandle hWnd = getParent(browser->GetHost()->GetWindowHandle());

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring the power of Cucumber, Ruby, Capybara, and Selenium: Enhancing the 'visit' method to handle dynamic content delays

For weeks now, I've been dealing with an issue that seems to have no solution found online... like waiting for ajax, etc... Check out the versions of gems: capybara (2.10.1, 2.7.1) selenium-webdriver (3.0.1, 3.0.0) rspec (3.5.0) running ruby 2.2.5 ...

Is it possible to convert a blob to an image file using the FileReader in HTML

client side code <head> <script> var reader = new FileReader(); var objVal; var image = new Image(); reader.onload = function(e) { document.getElementById('propertyImg').setAttribute('src', e.target.result); }; fun ...

What are the best methods for detecting devices in order to create customized CSS styles for iPad and Galaxy Tab?

Ensuring my web application is compatible with various devices is crucial. While I have created a common CSS for all mobile and tablet devices, it seems to be causing some problems specifically on the iPad. After finding a fix tailored for the iPad, I now ...

Tips for successfully sending an array of arrays with jQuery ajax

I have an array in PHP that looks like this: $treearr = array( array("root","search","Search",false,"xpLens.gif"), array("root","hometab","Home Tab",false,"home.gif"), array("root","stafftab","Staff Tab",false,"person.gif"), array ("stafftab","new ...

Investigating and solving issues in Javascript and JQuery

Let me walk you through the JavaScript process I am working on: When a text is entered in the input bar and submitted, the script dynamically creates a new "div" element and places the text inside it. This new div is then appended to an existing div calle ...

The jQuery function is running double even after I cleared the DOM with the empty() method

Twice, or multiple times if going back and forth, the Jquery function is triggered. Upon loading LoginMenu.jsp, WorkOrder.jsp is loaded within a specified ID. Once WorkOrder.jsp loads, it then loads schedule.jsp in the schedule tab defined in WorkOrders.j ...

Rotate arrows by 90 degrees instead of 180 degrees in Bootstrap 5 Accordion

I have customized a Bootstrap 5 Accordion according to the guide provided at https://getbootstrap.com/docs/5.0/components/accordion/. The default behavior rotates the arrows 180 degrees when an item is opened, changing from 'v' to '^'. ...

Obtain cell information when clicking on a specific field within a material-table

import MaterialTable from "material-table"; import ShipmentContext from "../context/ShipmentContext"; const ItemsTable: React.FC = () => { const shipmentcontext = useContext(ShipmentContext); const { filtered } = shipmentcontex ...

Dealing with JWT management in the absence of Cookies

After doing some research on JSON Web Token (which is a new concept to me), I have learned about its secure mechanism for transmitting information between parties without the need for server Sessions. Currently, I am in the process of building a web app f ...

Elements on the page appear and disappear as you scroll down

Whenever my scroll reaches the bottom of element B, I want my hidden sticky element to appear. And when I scroll back up to the top of element B, the sticky element should be hidden again. Here are my codes: https://i.sstatic.net/J49dT.jpg HTML <htm ...

Creating Threads in OpenMP

Within the following code snippet, does the OpenMP runtime recreate threads or reuse previously created threads, essentially utilizing a thread pool? There was debate among colleagues regarding this matter, as some argued that threads would be recreated d ...

Unable to zoom in on D3 Group Bar Chart

I've designed a group bar chart and attempted to implement zoom functionality. However, I noticed that the zoom only works for the first group of bars and not for the entire chart. Any assistance on this matter would be highly appreciated. Thank you i ...

Persistent NW.js Local Storage Cache Remains Present even After Deleting Application

I have been encountering an issue in my NW.js app where I store data in the Local Storage. Even after deleting the app and cleaning up cache information, the Local Storage data seems to persist. When I reinstall the app, the stored data reappears as if it ...

Prop in a React component is undergoing mutation

I encountered a strange situation where a prop in a React component is being changed. Although it's technically not a mutation since it's an array in JavaScript, it should not be modified. To replicate the issue, I created a simple example: htt ...

Having trouble retrieving data through AJAX requests

My goal is to verify the existence of a user email on "blur()" using AJAX to send textbox data to PHP. Even though I can see the posted data in Firebug, I keep encountering an error: Undefined index: data. Despite numerous attempts, I have been unable to r ...

Angular2 - HTML not displaying the response

I am currently mastering angularjs2. In my latest project, I attempted to fetch data from an API and received a response successfully. However, I encountered an issue where the response is not rendering in homepage.component.html as expected. I am unsure o ...

Eliminating an ngRepeat item from the $rootScope array does not automatically result in the item being removed from the html code

Attempting to eliminate an li from a ul using angular. Although the element is successfully removed from the array, AngularJS does not remove the li until it is interacted with, such as being hovered over or clicked. See the code below: app.js myApp.run( ...

User retrieval failed following successful passport authentication

After a successful authentication, the user is directed to the "/profile" route, as demonstrated in the code snippet below. app.get( "/auth/google/callback", passport.authenticate("google", { successRedirect: "/profile", failureRedirect: " ...

Creating a Regular Expression that excludes all white spaces, including those at the start or end of the string

I attempted to implement this solution, however, I am encountering some issues: Click here to see the demo <form name="myform1"> Valid? {{ myform1.$valid }} <input type="text" name="username1" ng-model="username1" ng-pattern="/^\S.*?&bso ...

Transform a <td> into a table-row (<tr>) nested within a parent <tr> inside an umbrella structure

Similar questions have been asked in the past, but I still haven't found a solution to my specific inquiry. Here it is: I have a table that needs to be sortable using a JavaScript plugin like ListJS. The key requirement is that I must have only one & ...