Skip to content

Commit 20fbe5f

Browse files
committed
make menu show event sync
Conflicts: src/api/dispatcher_host.cc
1 parent 34d7d50 commit 20fbe5f

File tree

6 files changed

+31
-4
lines changed

6 files changed

+31
-4
lines changed

src/api/app/app.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ void App::Call(const std::string& method,
121121
void App::Call(Shell* shell,
122122
const std::string& method,
123123
const base::ListValue& arguments,
124-
base::ListValue* result) {
124+
base::ListValue* result,
125+
DispatcherHost* dispatcher_host) {
125126
if (method == "GetDataPath") {
126127
ShellBrowserContext* browser_context =
127128
static_cast<ShellBrowserContext*>(shell->web_contents()->GetBrowserContext());
@@ -204,6 +205,9 @@ void App::Call(Shell* shell,
204205
arguments.GetString(0, &proxy_config);
205206
SetProxyConfig(GetRenderProcessHost(), proxy_config);
206207
return;
208+
} else if (method == "DoneMenuShow") {
209+
dispatcher_host->quit_run_loop();
210+
return;
207211
}
208212

209213
NOTREACHED() << "Calling unknown sync method " << method << " of App";

src/api/app/app.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define CONTENT_NW_SRC_API_APP_APP_H_
2323

2424
#include "base/basictypes.h"
25+
#include "../dispatcher_host.h"
2526

2627
#include <string>
2728

@@ -44,7 +45,8 @@ class App {
4445
static void Call(content::Shell* shell,
4546
const std::string& method,
4647
const base::ListValue& arguments,
47-
base::ListValue* result);
48+
base::ListValue* result,
49+
DispatcherHost* dispatcher_host);
4850

4951
// Try to close all windows (then will cause whole app to quit).
5052
static void CloseAllWindows(bool force = false, bool quit = false);

src/api/app/app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ App.prototype.clearCache = function() {
6161
nw.callStaticMethodSync('App', 'ClearCache', [ ]);
6262
}
6363

64+
App.prototype.doneMenuShow = function() {
65+
nw.callStaticMethodSync('App', 'DoneMenuShow', [ ]);
66+
}
67+
6468
App.prototype.getProxyForURL = function (url) {
6569
return nw.callStaticMethodSync('App', 'getProxyForURL', [ url ]);
6670
}

src/api/dispatcher_host.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "content/nw/src/api/dispatcher_host.h"
2222

2323
#include "base/logging.h"
24+
#include "base/run_loop.h"
2425
#include "base/threading/thread_restrictions.h"
2526
#include "base/values.h"
2627
#include "content/browser/child_process_security_policy_impl.h"
@@ -56,7 +57,8 @@ static std::map<content::RenderViewHost*, DispatcherHost*> g_dispatcher_host_map
5657
DispatcherHost::DispatcherHost(content::RenderViewHost* host)
5758
: content::WebContentsObserver(content::WebContents::FromRenderViewHost(host)),
5859
render_view_host_(host),
59-
weak_ptr_factory_(this) {
60+
weak_ptr_factory_(this),
61+
run_loop_(NULL) {
6062
g_dispatcher_host_map[render_view_host_] = this;
6163
}
6264

@@ -103,11 +105,17 @@ bool DispatcherHost::Send(IPC::Message* message) {
103105
return render_view_host_->Send(message);
104106
}
105107

108+
void DispatcherHost::quit_run_loop() {
109+
if (run_loop_)
110+
run_loop_->Quit();
111+
}
112+
106113
bool DispatcherHost::OnMessageReceived(
107114
content::RenderViewHost* render_view_host,
108115
const IPC::Message& message) {
109116
if (render_view_host != render_view_host_)
110117
return false;
118+
111119
bool handled = true;
112120
base::ThreadRestrictions::ScopedAllowIO allow_io;
113121
base::ThreadRestrictions::ScopedAllowWait allow_wait;
@@ -250,7 +258,7 @@ void DispatcherHost::OnCallStaticMethodSync(
250258
if (type == "App") {
251259
content::Shell* shell =
252260
content::Shell::FromRenderViewHost(render_view_host());
253-
nwapi::App::Call(shell, method, arguments, result);
261+
nwapi::App::Call(shell, method, arguments, result, this);
254262
return;
255263
} else if (type == "Screen") {
256264
nwapi::Screen::Call(this, method, arguments, result);

src/api/dispatcher_host.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
namespace base {
3333
class DictionaryValue;
3434
class ListValue;
35+
class RunLoop;
3536
}
3637

3738
namespace WebKit {
@@ -76,6 +77,8 @@ class DispatcherHost : public content::WebContentsObserver {
7677
return render_view_host_;
7778
}
7879

80+
void set_run_loop(base::RunLoop* run_loop) { run_loop_ = run_loop; }
81+
void quit_run_loop();
7982
private:
8083
content::RenderViewHost* render_view_host_;
8184
friend class content::Shell;
@@ -88,6 +91,8 @@ class DispatcherHost : public content::WebContentsObserver {
8891
// Factory to generate weak pointer
8992
base::WeakPtrFactory<DispatcherHost> weak_ptr_factory_;
9093

94+
base::RunLoop* run_loop_;
95+
9196
// RenderViewHostObserver implementation.
9297
// WebContentsObserver implementation:
9398
virtual bool OnMessageReceived(

src/api/menu/menu_delegate_mac.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1919
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2020

21+
#include "base/run_loop.h"
2122
#include "content/nw/src/api/dispatcher_host.h"
2223
#include "content/nw/src/api/menu/menu.h"
2324
#include "content/nw/src/api/menu/menu_delegate_mac.h"
@@ -35,7 +36,10 @@ - (id)initWithMenu:(nwapi::Menu*) menu {
3536

3637
- (void)menuNeedsUpdate:(NSMenu*)menu {
3738
base::ListValue args;
39+
base::RunLoop run_loop;
40+
nwmenu_->dispatcher_host()->set_run_loop(&run_loop);
3841
nwmenu_->dispatcher_host()->SendEvent(nwmenu_, "show", args);
42+
run_loop.Run();
3943
}
4044

4145
@end

0 commit comments

Comments
 (0)