]> khamidou — GitHub mirrors - electron.git/commitdiff
Allow sending ipc messages to devtools.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 4 Apr 2014 14:05:43 +0000 (22:05 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 4 Apr 2014 14:05:43 +0000 (22:05 +0800)
atom.gyp
atom/browser/devtools_web_contents_observer.cc [new file with mode: 0644]
atom/browser/devtools_web_contents_observer.h [new file with mode: 0644]

index 621555149d499e62e7c7c46b9db938a87a0f34c1..dd634957e3210aabdd8da989ad373c47fdc57e08 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
@@ -94,6 +94,8 @@
       'atom/browser/browser_observer.h',
       'atom/browser/devtools_delegate.cc',
       '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.h',
       'atom/browser/native_window_gtk.cc',
diff --git a/atom/browser/devtools_web_contents_observer.cc b/atom/browser/devtools_web_contents_observer.cc
new file mode 100644 (file)
index 0000000..331a125
--- /dev/null
@@ -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
diff --git a/atom/browser/devtools_web_contents_observer.h b/atom/browser/devtools_web_contents_observer.h
new file mode 100644 (file)
index 0000000..3fc2222
--- /dev/null
@@ -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_