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

Side by Side Diff: chrome/renderer/extensions/renderer_extension_bindings.cc

Issue 150125: Send port disconnect events when a frame is unloaded. (Closed)
Patch Set: from linux Created 11 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/extensions/renderer_extension_bindings.h" 5 #include "chrome/renderer/extensions/renderer_extension_bindings.h"
6 6
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/common/render_messages.h" 10 #include "chrome/common/render_messages.h"
(...skipping 28 matching lines...) Expand all
39 arraysize(kExtensionDeps), kExtensionDeps) { 39 arraysize(kExtensionDeps), kExtensionDeps) {
40 } 40 }
41 ~ExtensionImpl() {} 41 ~ExtensionImpl() {}
42 42
43 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 43 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
44 v8::Handle<v8::String> name) { 44 v8::Handle<v8::String> name) {
45 if (name->Equals(v8::String::New("OpenChannelToExtension"))) { 45 if (name->Equals(v8::String::New("OpenChannelToExtension"))) {
46 return v8::FunctionTemplate::New(OpenChannelToExtension); 46 return v8::FunctionTemplate::New(OpenChannelToExtension);
47 } else if (name->Equals(v8::String::New("PostMessage"))) { 47 } else if (name->Equals(v8::String::New("PostMessage"))) {
48 return v8::FunctionTemplate::New(PostMessage); 48 return v8::FunctionTemplate::New(PostMessage);
49 } else if (name->Equals(v8::String::New("CloseChannel"))) {
50 return v8::FunctionTemplate::New(CloseChannel);
49 } 51 }
50 return ExtensionBase::GetNativeFunction(name); 52 return ExtensionBase::GetNativeFunction(name);
51 } 53 }
52 54
53 // Creates a new messaging channel to the given extension. 55 // Creates a new messaging channel to the given extension.
54 static v8::Handle<v8::Value> OpenChannelToExtension( 56 static v8::Handle<v8::Value> OpenChannelToExtension(
55 const v8::Arguments& args) { 57 const v8::Arguments& args) {
56 // Get the current RenderView so that we can send a routed IPC message from 58 // Get the current RenderView so that we can send a routed IPC message from
57 // the correct source. 59 // the correct source.
58 RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext(); 60 RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext();
(...skipping 17 matching lines...) Expand all
76 return v8::Undefined(); 78 return v8::Undefined();
77 79
78 if (args.Length() >= 2 && args[0]->IsInt32() && args[1]->IsString()) { 80 if (args.Length() >= 2 && args[0]->IsInt32() && args[1]->IsString()) {
79 int port_id = args[0]->Int32Value(); 81 int port_id = args[0]->Int32Value();
80 std::string message = *v8::String::Utf8Value(args[1]->ToString()); 82 std::string message = *v8::String::Utf8Value(args[1]->ToString());
81 renderview->Send(new ViewHostMsg_ExtensionPostMessage( 83 renderview->Send(new ViewHostMsg_ExtensionPostMessage(
82 renderview->routing_id(), port_id, message)); 84 renderview->routing_id(), port_id, message));
83 } 85 }
84 return v8::Undefined(); 86 return v8::Undefined();
85 } 87 }
88
89 // Sends a message along the given channel.
90 static v8::Handle<v8::Value> CloseChannel(const v8::Arguments& args) {
91 if (args.Length() >= 1 && args[0]->IsInt32()) {
92 int port_id = args[0]->Int32Value();
93 // Send via the RenderThread because the RenderView might be closing.
94 EventBindings::GetRenderThread()->Send(
95 new ViewHostMsg_ExtensionCloseChannel(port_id));
96 }
97 return v8::Undefined();
98 }
86 }; 99 };
87 100
88 // Convert a ListValue to a vector of V8 values. 101 // Convert a ListValue to a vector of V8 values.
89 static std::vector< v8::Handle<v8::Value> > ListValueToV8( 102 static std::vector< v8::Handle<v8::Value> > ListValueToV8(
90 const ListValue& value) { 103 const ListValue& value) {
91 std::vector< v8::Handle<v8::Value> > v8_values; 104 std::vector< v8::Handle<v8::Value> > v8_values;
92 105
93 for (size_t i = 0; i < value.GetSize(); ++i) { 106 for (size_t i = 0; i < value.GetSize(); ++i) {
94 Value* elem = NULL; 107 Value* elem = NULL;
95 value.Get(i, &elem); 108 value.Get(i, &elem);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 v8::Extension* RendererExtensionBindings::Get() { 151 v8::Extension* RendererExtensionBindings::Get() {
139 return new ExtensionImpl(); 152 return new ExtensionImpl();
140 } 153 }
141 154
142 void RendererExtensionBindings::Invoke(const std::string& function_name, 155 void RendererExtensionBindings::Invoke(const std::string& function_name,
143 const ListValue& args) { 156 const ListValue& args) {
144 v8::HandleScope handle_scope; 157 v8::HandleScope handle_scope;
145 std::vector< v8::Handle<v8::Value> > argv = ListValueToV8(args); 158 std::vector< v8::Handle<v8::Value> > argv = ListValueToV8(args);
146 EventBindings::CallFunction(function_name, argv.size(), &argv[0]); 159 EventBindings::CallFunction(function_name, argv.size(), &argv[0]);
147 } 160 }
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/event_bindings.h ('k') | chrome/renderer/resources/renderer_extension_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698