Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Unified Diff: extensions/renderer/messaging_bindings.h

Issue 2295753003: [Extensions] Clean up MessagingBindings (Closed)
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/messaging_bindings.h
diff --git a/extensions/renderer/messaging_bindings.h b/extensions/renderer/messaging_bindings.h
index 4c52c631ce0eb8125ea354e60095f9d9382a15dc..56a9f7fa0582e5cd946e2cfa9649f0e05387aeec 100644
--- a/extensions/renderer/messaging_bindings.h
+++ b/extensions/renderer/messaging_bindings.h
@@ -7,37 +7,26 @@
#include <string>
-#include "extensions/renderer/script_context_set.h"
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "extensions/renderer/object_backed_native_handler.h"
struct ExtensionMsg_ExternalConnectionInfo;
struct ExtensionMsg_TabConnectionInfo;
-namespace base {
-class DictionaryValue;
-}
-
namespace content {
class RenderFrame;
}
-namespace v8 {
-class Extension;
-}
-
namespace extensions {
struct Message;
-class ObjectBackedNativeHandler;
class ScriptContextSet;
// Manually implements JavaScript bindings for extension messaging.
-//
-// TODO(aa): This should all get re-implemented using SchemaGeneratedBindings.
-// If anything needs to be manual for some reason, it should be implemented in
-// its own class.
-class MessagingBindings {
+class MessagingBindings : public ObjectBackedNativeHandler {
public:
- // Creates an instance of the extension.
- static ObjectBackedNativeHandler* Get(ScriptContext* context);
+ explicit MessagingBindings(ScriptContext* script_context);
+ ~MessagingBindings() override;
// Checks whether the port exists in the given frame. If it does not, a reply
// is sent back to the browser.
@@ -70,6 +59,28 @@ class MessagingBindings {
int port_id,
const std::string& error_message,
content::RenderFrame* restrict_to_render_frame);
+
+ private:
+ // JS Exposed Function: Sends a message along the given channel.
+ void PostMessage(const v8::FunctionCallbackInfo<v8::Value>& args);
+
+ // JS Exposed Function: Close a port, optionally forcefully (i.e. close the
+ // whole channel instead of just the given port).
+ void CloseChannel(const v8::FunctionCallbackInfo<v8::Value>& args);
+
+ // JS Exposed Function: Binds |callback| to be invoked *sometime after*
+ // |object| is garbage collected. We don't call the method re-entrantly so as
+ // to avoid executing JS in some bizarro undefined mid-GC state, nor do we
+ // then call into the script context if it's been invalidated.
+ void BindToGC(const v8::FunctionCallbackInfo<v8::Value>& args);
+
+ // Helper function to close a port. See CloseChannel() for |force_close|
+ // documentation.
+ void ClosePort(int port_id, bool force_close);
+
+ base::WeakPtrFactory<MessagingBindings> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(MessagingBindings);
};
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698