| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/miscellaneous_bindings.h" | 5 #include "chrome/renderer/extensions/miscellaneous_bindings.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 } | 58 } |
| 59 | 59 |
| 60 static void ClearPortData(int port_id) { | 60 static void ClearPortData(int port_id) { |
| 61 g_extension_data.Get().ports.erase(port_id); | 61 g_extension_data.Get().ports.erase(port_id); |
| 62 } | 62 } |
| 63 | 63 |
| 64 const char kPortClosedError[] = "Attempting to use a disconnected port object"; | 64 const char kPortClosedError[] = "Attempting to use a disconnected port object"; |
| 65 | 65 |
| 66 class ExtensionImpl : public extensions::ChromeV8Extension { | 66 class ExtensionImpl : public extensions::ChromeV8Extension { |
| 67 public: | 67 public: |
| 68 explicit ExtensionImpl(extensions::Dispatcher* dispatcher, | 68 explicit ExtensionImpl(extensions::Dispatcher* dispatcher) |
| 69 v8::Handle<v8::Context> context) | 69 : extensions::ChromeV8Extension(dispatcher) { |
| 70 : extensions::ChromeV8Extension(dispatcher, context) { | |
| 71 RouteStaticFunction("CloseChannel", &CloseChannel); | 70 RouteStaticFunction("CloseChannel", &CloseChannel); |
| 72 RouteStaticFunction("PortAddRef", &PortAddRef); | 71 RouteStaticFunction("PortAddRef", &PortAddRef); |
| 73 RouteStaticFunction("PortRelease", &PortRelease); | 72 RouteStaticFunction("PortRelease", &PortRelease); |
| 74 RouteStaticFunction("PostMessage", &PostMessage); | 73 RouteStaticFunction("PostMessage", &PostMessage); |
| 75 RouteStaticFunction("BindToGC", &BindToGC); | 74 RouteStaticFunction("BindToGC", &BindToGC); |
| 76 } | 75 } |
| 77 | 76 |
| 78 virtual ~ExtensionImpl() {} | 77 virtual ~ExtensionImpl() {} |
| 79 | 78 |
| 80 // Sends a message along the given channel. | 79 // Sends a message along the given channel. |
| 81 static v8::Handle<v8::Value> PostMessage(const v8::Arguments& args) { | 80 static v8::Handle<v8::Value> PostMessage(const v8::Arguments& args) { |
| 82 ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args); | 81 content::RenderView* renderview = GetCurrentRenderView(); |
| 83 content::RenderView* renderview = self->GetRenderView(); | |
| 84 if (!renderview) | 82 if (!renderview) |
| 85 return v8::Undefined(); | 83 return v8::Undefined(); |
| 86 | 84 |
| 87 if (args.Length() >= 2 && args[0]->IsInt32() && args[1]->IsString()) { | 85 if (args.Length() >= 2 && args[0]->IsInt32() && args[1]->IsString()) { |
| 88 int port_id = args[0]->Int32Value(); | 86 int port_id = args[0]->Int32Value(); |
| 89 if (!HasPortData(port_id)) { | 87 if (!HasPortData(port_id)) { |
| 90 return v8::ThrowException(v8::Exception::Error( | 88 return v8::ThrowException(v8::Exception::Error( |
| 91 v8::String::New(kPortClosedError))); | 89 v8::String::New(kPortClosedError))); |
| 92 } | 90 } |
| 93 std::string message = *v8::String::Utf8Value(args[1]->ToString()); | 91 std::string message = *v8::String::Utf8Value(args[1]->ToString()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 NOTREACHED(); | 171 NOTREACHED(); |
| 174 } | 172 } |
| 175 return v8::Undefined(); | 173 return v8::Undefined(); |
| 176 } | 174 } |
| 177 }; | 175 }; |
| 178 | 176 |
| 179 } // namespace | 177 } // namespace |
| 180 | 178 |
| 181 namespace extensions { | 179 namespace extensions { |
| 182 | 180 |
| 183 ChromeV8Extension* MiscellaneousBindings::Get( | 181 ChromeV8Extension* MiscellaneousBindings::Get(Dispatcher* dispatcher) { |
| 184 Dispatcher* dispatcher, | 182 return new ExtensionImpl(dispatcher); |
| 185 v8::Handle<v8::Context> context) { | |
| 186 return new ExtensionImpl(dispatcher, context); | |
| 187 } | 183 } |
| 188 | 184 |
| 189 // static | 185 // static |
| 190 void MiscellaneousBindings::DispatchOnConnect( | 186 void MiscellaneousBindings::DispatchOnConnect( |
| 191 const ChromeV8ContextSet::ContextSet& contexts, | 187 const ChromeV8ContextSet::ContextSet& contexts, |
| 192 int target_port_id, | 188 int target_port_id, |
| 193 const std::string& channel_name, | 189 const std::string& channel_name, |
| 194 const std::string& tab_json, | 190 const std::string& tab_json, |
| 195 const std::string& source_extension_id, | 191 const std::string& source_extension_id, |
| 196 const std::string& target_extension_id, | 192 const std::string& target_extension_id, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 std::vector<v8::Handle<v8::Value> > arguments; | 305 std::vector<v8::Handle<v8::Value> > arguments; |
| 310 arguments.push_back(v8::Integer::New(port_id)); | 306 arguments.push_back(v8::Integer::New(port_id)); |
| 311 arguments.push_back(v8::Boolean::New(connection_error)); | 307 arguments.push_back(v8::Boolean::New(connection_error)); |
| 312 (*it)->CallChromeHiddenMethod("Port.dispatchOnDisconnect", | 308 (*it)->CallChromeHiddenMethod("Port.dispatchOnDisconnect", |
| 313 arguments.size(), &arguments[0], | 309 arguments.size(), &arguments[0], |
| 314 NULL); | 310 NULL); |
| 315 } | 311 } |
| 316 } | 312 } |
| 317 | 313 |
| 318 } // namespace extensions | 314 } // namespace extensions |
| OLD | NEW |