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

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

Issue 125280: Send port-closed notification when a frame with ports unloads.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/extensions/extension_process_bindings.cc ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 25 matching lines...) Expand all
36 arraysize(kExtensionDeps), kExtensionDeps) { 36 arraysize(kExtensionDeps), kExtensionDeps) {
37 } 37 }
38 ~ExtensionImpl() {} 38 ~ExtensionImpl() {}
39 39
40 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 40 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
41 v8::Handle<v8::String> name) { 41 v8::Handle<v8::String> name) {
42 if (name->Equals(v8::String::New("OpenChannelToExtension"))) { 42 if (name->Equals(v8::String::New("OpenChannelToExtension"))) {
43 return v8::FunctionTemplate::New(OpenChannelToExtension); 43 return v8::FunctionTemplate::New(OpenChannelToExtension);
44 } else if (name->Equals(v8::String::New("PostMessage"))) { 44 } else if (name->Equals(v8::String::New("PostMessage"))) {
45 return v8::FunctionTemplate::New(PostMessage); 45 return v8::FunctionTemplate::New(PostMessage);
46 } else if (name->Equals(v8::String::New("CloseChannel"))) {
47 return v8::FunctionTemplate::New(CloseChannel);
46 } 48 }
47 return v8::Handle<v8::FunctionTemplate>(); 49 return v8::Handle<v8::FunctionTemplate>();
48 } 50 }
49 51
50 // Creates a new messaging channel to the given extension. 52 // Creates a new messaging channel to the given extension.
51 static v8::Handle<v8::Value> OpenChannelToExtension( 53 static v8::Handle<v8::Value> OpenChannelToExtension(
52 const v8::Arguments& args) { 54 const v8::Arguments& args) {
53 // Get the current RenderView so that we can send a routed IPC message from 55 // Get the current RenderView so that we can send a routed IPC message from
54 // the correct source. 56 // the correct source.
55 RenderView* renderview = GetRenderViewForCurrentContext(); 57 RenderView* renderview = GetRenderViewForCurrentContext();
(...skipping 17 matching lines...) Expand all
73 return v8::Undefined(); 75 return v8::Undefined();
74 76
75 if (args.Length() >= 2 && args[0]->IsInt32() && args[1]->IsString()) { 77 if (args.Length() >= 2 && args[0]->IsInt32() && args[1]->IsString()) {
76 int port_id = args[0]->Int32Value(); 78 int port_id = args[0]->Int32Value();
77 std::string message = *v8::String::Utf8Value(args[1]->ToString()); 79 std::string message = *v8::String::Utf8Value(args[1]->ToString());
78 renderview->Send(new ViewHostMsg_ExtensionPostMessage( 80 renderview->Send(new ViewHostMsg_ExtensionPostMessage(
79 renderview->routing_id(), port_id, message)); 81 renderview->routing_id(), port_id, message));
80 } 82 }
81 return v8::Undefined(); 83 return v8::Undefined();
82 } 84 }
85
86 // Sends a message along the given channel.
87 static v8::Handle<v8::Value> CloseChannel(const v8::Arguments& args) {
88 if (args.Length() >= 1 && args[0]->IsInt32()) {
89 int port_id = args[0]->Int32Value();
90 // Send via the RenderThread because the RenderView might be closing.
91 EventBindings::GetRenderThread()->Send(
92 new ViewHostMsg_ExtensionCloseChannel(port_id));
93 }
94 return v8::Undefined();
95 }
83 }; 96 };
84 97
85 // Convert a ListValue to a vector of V8 values. 98 // Convert a ListValue to a vector of V8 values.
86 static std::vector< v8::Handle<v8::Value> > ListValueToV8( 99 static std::vector< v8::Handle<v8::Value> > ListValueToV8(
87 const ListValue& value) { 100 const ListValue& value) {
88 std::vector< v8::Handle<v8::Value> > v8_values; 101 std::vector< v8::Handle<v8::Value> > v8_values;
89 102
90 for (size_t i = 0; i < value.GetSize(); ++i) { 103 for (size_t i = 0; i < value.GetSize(); ++i) {
91 Value* elem = NULL; 104 Value* elem = NULL;
92 value.Get(i, &elem); 105 value.Get(i, &elem);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 v8::Extension* RendererExtensionBindings::Get() { 148 v8::Extension* RendererExtensionBindings::Get() {
136 return new ExtensionImpl(); 149 return new ExtensionImpl();
137 } 150 }
138 151
139 void RendererExtensionBindings::Invoke(const std::string& function_name, 152 void RendererExtensionBindings::Invoke(const std::string& function_name,
140 const ListValue& args) { 153 const ListValue& args) {
141 v8::HandleScope handle_scope; 154 v8::HandleScope handle_scope;
142 std::vector< v8::Handle<v8::Value> > argv = ListValueToV8(args); 155 std::vector< v8::Handle<v8::Value> > argv = ListValueToV8(args);
143 EventBindings::CallFunction(function_name, argv.size(), &argv[0]); 156 EventBindings::CallFunction(function_name, argv.size(), &argv[0]);
144 } 157 }
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/extension_process_bindings.cc ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698