diff --git a/atom.gyp b/atom.gyp index 621555149d49..dd634957e321 100644 --- 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 index 000000000000..331a1253ca6c --- /dev/null +++ b/atom/browser/devtools_web_contents_observer.cc @@ -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 index 000000000000..3fc2222a43b7 --- /dev/null +++ b/atom/browser/devtools_web_contents_observer.h @@ -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_