From 993cf1cc61d1286673af13f8900899ebc3afc811 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 21 Apr 2013 11:01:04 +0800 Subject: [PATCH] Add API messages for IPC. --- atom.gyp | 2 ++ browser/api/atom_api_extensions.h | 2 ++ browser/native_window.cc | 7 +++++++ browser/native_window.h | 5 +++++ common/api_messages.cc | 33 +++++++++++++++++++++++++++++ common/api_messages.h | 35 +++++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+) create mode 100644 common/api_messages.cc create mode 100644 common/api_messages.h diff --git a/atom.gyp b/atom.gyp index 4317261b13c8..0944c1675243 100644 --- a/atom.gyp +++ b/atom.gyp @@ -40,6 +40,8 @@ 'browser/native_window_mac.h', 'browser/native_window_mac.mm', 'browser/native_window_observer.h', + 'common/api_messages.cc', + 'common/api_messages.h', 'common/node_bindings.cc', 'common/node_bindings.h', 'common/node_bindings_mac.h', diff --git a/browser/api/atom_api_extensions.h b/browser/api/atom_api_extensions.h index 0b059011c49b..9e83337bb06e 100644 --- a/browser/api/atom_api_extensions.h +++ b/browser/api/atom_api_extensions.h @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// Multiply-included file, no traditional include guard. + // Used by atom_extensions.cc to declare a list of built-in modules of Atom. NODE_EXT_LIST_START diff --git a/browser/native_window.cc b/browser/native_window.cc index 91e53b7e6bd4..3e301eee9b0b 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -32,6 +32,9 @@ NativeWindow::NativeWindow(content::WebContents* web_contents, web_contents->SetDelegate(this); // Add window as an observer of the web contents. + content::WebContentsObserver::Observe(web_contents); + + // Get notified of title updated message. registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, content::Source(web_contents)); } @@ -125,6 +128,10 @@ void NativeWindow::WebContentsCreated( window->InitFromOptions(options.get()); } +bool NativeWindow::OnMessageReceived(const IPC::Message& message) { + return false; +} + void NativeWindow::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { diff --git a/browser/native_window.h b/browser/native_window.h index 40be8903ee54..ad46d142f59c 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -15,6 +15,7 @@ #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/web_contents_delegate.h" +#include "content/public/browser/web_contents_observer.h" namespace base { class DictionaryValue; @@ -38,6 +39,7 @@ class Size; namespace atom { class NativeWindow : public content::WebContentsDelegate, + public content::WebContentsObserver, public content::NotificationObserver { public: virtual ~NativeWindow(); @@ -108,6 +110,9 @@ class NativeWindow : public content::WebContentsDelegate, const GURL& target_url, content::WebContents* new_contents) OVERRIDE; + // Implementations of content::WebContentsObserver. + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + // Implementations of content::NotificationObserver virtual void Observe(int type, const content::NotificationSource& source, diff --git a/common/api_messages.cc b/common/api_messages.cc new file mode 100644 index 000000000000..ee9b250a4af6 --- /dev/null +++ b/common/api_messages.cc @@ -0,0 +1,33 @@ +// Copyright (c) 2013 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. + +// Get basic type definitions. +#define IPC_MESSAGE_IMPL +#include "common/api_messages.h" + +// Generate constructors. +#include "ipc/struct_constructor_macros.h" +#include "common/api_messages.h" + +// Generate destructors. +#include "ipc/struct_destructor_macros.h" +#include "common/api_messages.h" + +// Generate param traits write methods. +#include "ipc/param_traits_write_macros.h" +namespace IPC { +#include "common/api_messages.h" +} // namespace IPC + +// Generate param traits read methods. +#include "ipc/param_traits_read_macros.h" +namespace IPC { +#include "common/api_messages.h" +} // namespace IPC + +// Generate param traits log methods. +#include "ipc/param_traits_log_macros.h" +namespace IPC { +#include "common/api_messages.h" +} // namespace IPC diff --git a/common/api_messages.h b/common/api_messages.h new file mode 100644 index 000000000000..05f90119f372 --- /dev/null +++ b/common/api_messages.h @@ -0,0 +1,35 @@ +// Copyright (c) 2013 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. + +// Multiply-included file, no traditional include guard. + +#include + +#include "base/values.h" +#include "content/public/common/common_param_traits.h" +#include "ipc/ipc_message_macros.h" + +// The message starter should be declared in ipc/ipc_message_start.h. Since +// we don't wan't to patch Chromium, we just pretend to be Content Shell. + +#define IPC_MESSAGE_START ShellMsgStart + +IPC_SYNC_MESSAGE_CONTROL2_1(AtomViewHostMsg_Allocate_Object, + std::string /* type name */, + DictionaryValue /* options */, + int /* object id */) + +IPC_SYNC_MESSAGE_CONTROL1_0(AtomViewHostMsg_Deallocate_Object, + int /* object id */) + +IPC_SYNC_MESSAGE_CONTROL3_1(AtomViewHostMsg_Call_Object_Method, + int /* object id */, + std::string /* method name */, + ListValue /* arguments */, + DictionaryValue /* return value */) + +IPC_SYNC_MESSAGE_CONTROL2_1(AtomViewMsg_Callback, + int /* callback id */, + ListValue /* arguments */, + DictionaryValue /* return value */)