Allow sending ipc messages to devtools.
This commit is contained in:
parent
a80fe40f56
commit
86ebd6e8e3
3 changed files with 107 additions and 0 deletions
2
atom.gyp
2
atom.gyp
|
@ -94,6 +94,8 @@
|
||||||
'atom/browser/browser_observer.h',
|
'atom/browser/browser_observer.h',
|
||||||
'atom/browser/devtools_delegate.cc',
|
'atom/browser/devtools_delegate.cc',
|
||||||
'atom/browser/devtools_delegate.h',
|
'atom/browser/devtools_delegate.h',
|
||||||
|
'atom/browser/devtools_web_contents_observer.cc',
|
||||||
|
'atom/browser/devtools_web_contents_observer.h',
|
||||||
'atom/browser/native_window.cc',
|
'atom/browser/native_window.cc',
|
||||||
'atom/browser/native_window.h',
|
'atom/browser/native_window.h',
|
||||||
'atom/browser/native_window_gtk.cc',
|
'atom/browser/native_window_gtk.cc',
|
||||||
|
|
64
atom/browser/devtools_web_contents_observer.cc
Normal file
64
atom/browser/devtools_web_contents_observer.cc
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "atom/browser/devtools_web_contents_observer.h"
|
||||||
|
|
||||||
|
#include "atom/browser/api/atom_browser_bindings.h"
|
||||||
|
#include "atom/browser/atom_browser_main_parts.h"
|
||||||
|
#include "atom/browser/native_window.h"
|
||||||
|
#include "atom/common/api/api_messages.h"
|
||||||
|
#include "base/logging.h"
|
||||||
|
#include "content/public/browser/render_process_host.h"
|
||||||
|
#include "ipc/ipc_message_macros.h"
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
|
DevToolsWebContentsObserver::DevToolsWebContentsObserver(
|
||||||
|
NativeWindow* native_window,
|
||||||
|
content::WebContents* web_contents)
|
||||||
|
: content::WebContentsObserver(web_contents),
|
||||||
|
inspected_window_(native_window) {
|
||||||
|
DCHECK(native_window);
|
||||||
|
}
|
||||||
|
|
||||||
|
DevToolsWebContentsObserver::~DevToolsWebContentsObserver() {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DevToolsWebContentsObserver::OnMessageReceived(
|
||||||
|
const IPC::Message& message) {
|
||||||
|
bool handled = true;
|
||||||
|
IPC_BEGIN_MESSAGE_MAP(DevToolsWebContentsObserver, message)
|
||||||
|
IPC_MESSAGE_HANDLER(AtomViewHostMsg_Message, OnRendererMessage)
|
||||||
|
IPC_MESSAGE_HANDLER_DELAY_REPLY(AtomViewHostMsg_Message_Sync,
|
||||||
|
OnRendererMessageSync)
|
||||||
|
IPC_MESSAGE_UNHANDLED(handled = false)
|
||||||
|
IPC_END_MESSAGE_MAP()
|
||||||
|
|
||||||
|
return handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DevToolsWebContentsObserver::OnRendererMessage(
|
||||||
|
const string16& channel,
|
||||||
|
const base::ListValue& args) {
|
||||||
|
AtomBrowserMainParts::Get()->atom_bindings()->OnRendererMessage(
|
||||||
|
web_contents()->GetRenderProcessHost()->GetID(),
|
||||||
|
web_contents()->GetRoutingID(),
|
||||||
|
channel,
|
||||||
|
args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DevToolsWebContentsObserver::OnRendererMessageSync(
|
||||||
|
const string16& channel,
|
||||||
|
const base::ListValue& args,
|
||||||
|
IPC::Message* reply_msg) {
|
||||||
|
AtomBrowserMainParts::Get()->atom_bindings()->OnRendererMessageSync(
|
||||||
|
web_contents()->GetRenderProcessHost()->GetID(),
|
||||||
|
web_contents()->GetRoutingID(),
|
||||||
|
channel,
|
||||||
|
args,
|
||||||
|
web_contents(),
|
||||||
|
reply_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace atom
|
41
atom/browser/devtools_web_contents_observer.h
Normal file
41
atom/browser/devtools_web_contents_observer.h
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#ifndef ATOM_BROWSER_DEVTOOLS_WEB_CONTENTS_OBSERVER_H_
|
||||||
|
#define ATOM_BROWSER_DEVTOOLS_WEB_CONTENTS_OBSERVER_H_
|
||||||
|
|
||||||
|
#include "content/public/browser/web_contents_observer.h"
|
||||||
|
|
||||||
|
namespace base {
|
||||||
|
class ListValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
|
class NativeWindow;
|
||||||
|
|
||||||
|
class DevToolsWebContentsObserver : public content::WebContentsObserver {
|
||||||
|
public:
|
||||||
|
DevToolsWebContentsObserver(NativeWindow* native_window,
|
||||||
|
content::WebContents* web_contents);
|
||||||
|
virtual ~DevToolsWebContentsObserver();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
|
||||||
|
|
||||||
|
void OnRendererMessage(const string16& channel,
|
||||||
|
const base::ListValue& args);
|
||||||
|
void OnRendererMessageSync(const string16& channel,
|
||||||
|
const base::ListValue& args,
|
||||||
|
IPC::Message* reply_msg);
|
||||||
|
|
||||||
|
private:
|
||||||
|
NativeWindow* inspected_window_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(DevToolsWebContentsObserver);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace atom
|
||||||
|
|
||||||
|
#endif // ATOM_BROWSER_DEVTOOLS_WEB_CONTENTS_OBSERVER_H_
|
Loading…
Reference in a new issue