Synchronous event should be bound to WebContents.
This allows us to reply to synchronous message for arbitrary WebContents.
This commit is contained in:
parent
b1f0c2d174
commit
a80fe40f56
6 changed files with 39 additions and 35 deletions
|
@ -4,10 +4,10 @@
|
||||||
|
|
||||||
#include "atom/browser/api/atom_api_event.h"
|
#include "atom/browser/api/atom_api_event.h"
|
||||||
|
|
||||||
#include "atom/browser/native_window.h"
|
|
||||||
#include "atom/common/api/api_messages.h"
|
#include "atom/common/api/api_messages.h"
|
||||||
#include "atom/common/v8/node_common.h"
|
#include "atom/common/v8/node_common.h"
|
||||||
#include "atom/common/v8/native_type_conversions.h"
|
#include "atom/common/v8/native_type_conversions.h"
|
||||||
|
#include "content/public/browser/web_contents.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -22,8 +22,6 @@ Event::Event()
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::~Event() {
|
Event::~Event() {
|
||||||
if (sender_ != NULL)
|
|
||||||
sender_->RemoveObserver(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
@ -44,16 +42,17 @@ v8::Handle<v8::Object> Event::CreateV8Object() {
|
||||||
return t->NewInstance(0, NULL);
|
return t->NewInstance(0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Event::SetSenderAndMessage(NativeWindow* sender, IPC::Message* message) {
|
void Event::SetSenderAndMessage(content::WebContents* sender,
|
||||||
|
IPC::Message* message) {
|
||||||
DCHECK(!sender_);
|
DCHECK(!sender_);
|
||||||
DCHECK(!message_);
|
DCHECK(!message_);
|
||||||
sender_ = sender;
|
sender_ = sender;
|
||||||
message_ = message;
|
message_ = message;
|
||||||
|
|
||||||
sender_->AddObserver(this);
|
Observe(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Event::OnWindowClosed() {
|
void Event::WebContentsDestroyed(content::WebContents* web_contents) {
|
||||||
sender_ = NULL;
|
sender_ = NULL;
|
||||||
message_ = NULL;
|
message_ = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,11 @@
|
||||||
#ifndef ATOM_BROWSER_API_ATOM_API_EVENT_H_
|
#ifndef ATOM_BROWSER_API_ATOM_API_EVENT_H_
|
||||||
#define ATOM_BROWSER_API_ATOM_API_EVENT_H_
|
#define ATOM_BROWSER_API_ATOM_API_EVENT_H_
|
||||||
|
|
||||||
|
#include "atom/common/v8/scoped_persistent.h"
|
||||||
#include "base/basictypes.h"
|
#include "base/basictypes.h"
|
||||||
#include "base/compiler_specific.h"
|
#include "base/compiler_specific.h"
|
||||||
#include "base/strings/string16.h"
|
#include "base/strings/string16.h"
|
||||||
#include "atom/browser/native_window_observer.h"
|
#include "content/public/browser/web_contents_observer.h"
|
||||||
#include "atom/common/v8/scoped_persistent.h"
|
|
||||||
#include "vendor/node/src/node_object_wrap.h"
|
#include "vendor/node/src/node_object_wrap.h"
|
||||||
|
|
||||||
namespace IPC {
|
namespace IPC {
|
||||||
|
@ -18,12 +18,10 @@ class Message;
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
class NativeWindow;
|
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
class Event : public node::ObjectWrap,
|
class Event : public node::ObjectWrap,
|
||||||
public NativeWindowObserver {
|
public content::WebContentsObserver {
|
||||||
public:
|
public:
|
||||||
virtual ~Event();
|
virtual ~Event();
|
||||||
|
|
||||||
|
@ -31,7 +29,7 @@ class Event : public node::ObjectWrap,
|
||||||
static v8::Handle<v8::Object> CreateV8Object();
|
static v8::Handle<v8::Object> CreateV8Object();
|
||||||
|
|
||||||
// Pass the sender and message to be replied.
|
// Pass the sender and message to be replied.
|
||||||
void SetSenderAndMessage(NativeWindow* sender, IPC::Message* message);
|
void SetSenderAndMessage(content::WebContents* sender, IPC::Message* message);
|
||||||
|
|
||||||
// Whether event.preventDefault() is called.
|
// Whether event.preventDefault() is called.
|
||||||
bool prevent_default() const { return prevent_default_; }
|
bool prevent_default() const { return prevent_default_; }
|
||||||
|
@ -39,8 +37,8 @@ class Event : public node::ObjectWrap,
|
||||||
protected:
|
protected:
|
||||||
Event();
|
Event();
|
||||||
|
|
||||||
// NativeWindowObserver implementations:
|
// content::WebContentsObserver implementations:
|
||||||
virtual void OnWindowClosed() OVERRIDE;
|
virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||||
|
@ -52,7 +50,7 @@ class Event : public node::ObjectWrap,
|
||||||
static ScopedPersistent<v8::Function> constructor_template_;
|
static ScopedPersistent<v8::Function> constructor_template_;
|
||||||
|
|
||||||
// Replyer for the synchronous messages.
|
// Replyer for the synchronous messages.
|
||||||
NativeWindow* sender_;
|
content::WebContents* sender_;
|
||||||
IPC::Message* message_;
|
IPC::Message* message_;
|
||||||
|
|
||||||
bool prevent_default_;
|
bool prevent_default_;
|
||||||
|
|
|
@ -57,7 +57,7 @@ void AtomBrowserBindings::OnRendererMessageSync(
|
||||||
int routing_id,
|
int routing_id,
|
||||||
const string16& channel,
|
const string16& channel,
|
||||||
const base::ListValue& args,
|
const base::ListValue& args,
|
||||||
NativeWindow* sender,
|
content::WebContents* sender,
|
||||||
IPC::Message* message) {
|
IPC::Message* message) {
|
||||||
v8::Locker locker(node_isolate);
|
v8::Locker locker(node_isolate);
|
||||||
v8::HandleScope handle_scope(node_isolate);
|
v8::HandleScope handle_scope(node_isolate);
|
||||||
|
|
|
@ -13,14 +13,16 @@ namespace base {
|
||||||
class ListValue;
|
class ListValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace content {
|
||||||
|
class WebContents;
|
||||||
|
}
|
||||||
|
|
||||||
namespace IPC {
|
namespace IPC {
|
||||||
class Message;
|
class Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
class NativeWindow;
|
|
||||||
|
|
||||||
class AtomBrowserBindings : public AtomBindings {
|
class AtomBrowserBindings : public AtomBindings {
|
||||||
public:
|
public:
|
||||||
AtomBrowserBindings();
|
AtomBrowserBindings();
|
||||||
|
@ -37,7 +39,7 @@ class AtomBrowserBindings : public AtomBindings {
|
||||||
int routing_id,
|
int routing_id,
|
||||||
const string16& channel,
|
const string16& channel,
|
||||||
const base::ListValue& args,
|
const base::ListValue& args,
|
||||||
NativeWindow* sender,
|
content::WebContents* sender,
|
||||||
IPC::Message* message);
|
IPC::Message* message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -8,6 +8,17 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "atom/browser/api/atom_browser_bindings.h"
|
||||||
|
#include "atom/browser/atom_browser_context.h"
|
||||||
|
#include "atom/browser/atom_browser_main_parts.h"
|
||||||
|
#include "atom/browser/atom_javascript_dialog_manager.h"
|
||||||
|
#include "atom/browser/browser.h"
|
||||||
|
#include "atom/browser/devtools_delegate.h"
|
||||||
|
#include "atom/browser/devtools_web_contents_observer.h"
|
||||||
|
#include "atom/browser/window_list.h"
|
||||||
|
#include "atom/common/api/api_messages.h"
|
||||||
|
#include "atom/common/atom_version.h"
|
||||||
|
#include "atom/common/options_switches.h"
|
||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
#include "base/file_util.h"
|
#include "base/file_util.h"
|
||||||
#include "base/prefs/pref_service.h"
|
#include "base/prefs/pref_service.h"
|
||||||
|
@ -15,13 +26,6 @@
|
||||||
#include "base/strings/stringprintf.h"
|
#include "base/strings/stringprintf.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
#include "atom/browser/api/atom_browser_bindings.h"
|
|
||||||
#include "atom/browser/atom_browser_context.h"
|
|
||||||
#include "atom/browser/atom_browser_main_parts.h"
|
|
||||||
#include "atom/browser/atom_javascript_dialog_manager.h"
|
|
||||||
#include "atom/browser/browser.h"
|
|
||||||
#include "atom/browser/devtools_delegate.h"
|
|
||||||
#include "atom/browser/window_list.h"
|
|
||||||
#include "content/public/browser/devtools_agent_host.h"
|
#include "content/public/browser/devtools_agent_host.h"
|
||||||
#include "content/public/browser/invalidate_type.h"
|
#include "content/public/browser/invalidate_type.h"
|
||||||
#include "content/public/browser/navigation_entry.h"
|
#include "content/public/browser/navigation_entry.h"
|
||||||
|
@ -33,9 +37,6 @@
|
||||||
#include "content/public/browser/render_widget_host_view.h"
|
#include "content/public/browser/render_widget_host_view.h"
|
||||||
#include "content/public/browser/web_contents_view.h"
|
#include "content/public/browser/web_contents_view.h"
|
||||||
#include "content/public/common/renderer_preferences.h"
|
#include "content/public/common/renderer_preferences.h"
|
||||||
#include "atom/common/api/api_messages.h"
|
|
||||||
#include "atom/common/atom_version.h"
|
|
||||||
#include "atom/common/options_switches.h"
|
|
||||||
#include "ipc/ipc_message_macros.h"
|
#include "ipc/ipc_message_macros.h"
|
||||||
#include "ui/gfx/codec/png_codec.h"
|
#include "ui/gfx/codec/png_codec.h"
|
||||||
#include "ui/gfx/point.h"
|
#include "ui/gfx/point.h"
|
||||||
|
@ -194,8 +195,12 @@ bool NativeWindow::HasModalDialog() {
|
||||||
void NativeWindow::OpenDevTools() {
|
void NativeWindow::OpenDevTools() {
|
||||||
if (devtools_window_) {
|
if (devtools_window_) {
|
||||||
devtools_window_->Focus(true);
|
devtools_window_->Focus(true);
|
||||||
|
devtools_web_contents_observer_.reset(new DevToolsWebContentsObserver(
|
||||||
|
this, devtools_window_->GetWebContents()));
|
||||||
} else {
|
} else {
|
||||||
inspectable_web_contents()->ShowDevTools();
|
inspectable_web_contents()->ShowDevTools();
|
||||||
|
devtools_web_contents_observer_.reset(new DevToolsWebContentsObserver(
|
||||||
|
this, GetDevToolsWebContents()));
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
// Temporary fix for flashing devtools, try removing this after upgraded to
|
// Temporary fix for flashing devtools, try removing this after upgraded to
|
||||||
// Chrome 32.
|
// Chrome 32.
|
||||||
|
@ -559,7 +564,7 @@ void NativeWindow::OnRendererMessageSync(const string16& channel,
|
||||||
GetWebContents()->GetRoutingID(),
|
GetWebContents()->GetRoutingID(),
|
||||||
channel,
|
channel,
|
||||||
args,
|
args,
|
||||||
this,
|
GetWebContents(),
|
||||||
reply_msg);
|
reply_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,14 +41,11 @@ class Rect;
|
||||||
class Size;
|
class Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace IPC {
|
|
||||||
class Message;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
class AtomJavaScriptDialogManager;
|
class AtomJavaScriptDialogManager;
|
||||||
class DevToolsDelegate;
|
class DevToolsDelegate;
|
||||||
|
class DevToolsWebContentsObserver;
|
||||||
struct DraggableRegion;
|
struct DraggableRegion;
|
||||||
|
|
||||||
class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
|
@ -288,8 +285,11 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
base::WeakPtrFactory<NativeWindow> weak_factory_;
|
base::WeakPtrFactory<NativeWindow> weak_factory_;
|
||||||
|
|
||||||
base::WeakPtr<NativeWindow> devtools_window_;
|
base::WeakPtr<NativeWindow> devtools_window_;
|
||||||
|
|
||||||
scoped_ptr<DevToolsDelegate> devtools_delegate_;
|
scoped_ptr<DevToolsDelegate> devtools_delegate_;
|
||||||
|
|
||||||
|
// WebContentsObserver for the WebContents of devtools.
|
||||||
|
scoped_ptr<DevToolsWebContentsObserver> devtools_web_contents_observer_;
|
||||||
|
|
||||||
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
||||||
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
|
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue