| OLD | NEW |
| 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/extension_process_bindings.h" | 5 #include "chrome/renderer/extensions/extension_process_bindings.h" |
| 6 | 6 |
| 7 #include "base/singleton.h" | 7 #include "base/singleton.h" |
| 8 #include "chrome/common/extensions/extension.h" | 8 #include "chrome/common/extensions/extension.h" |
| 9 #include "chrome/common/extensions/url_pattern.h" | 9 #include "chrome/common/extensions/url_pattern.h" |
| 10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 } else if (name->Equals(v8::String::New("GetExtensionViews"))) { | 99 } else if (name->Equals(v8::String::New("GetExtensionViews"))) { |
| 100 return v8::FunctionTemplate::New(GetExtensionViews); | 100 return v8::FunctionTemplate::New(GetExtensionViews); |
| 101 } else if (name->Equals(v8::String::New("GetNextRequestId"))) { | 101 } else if (name->Equals(v8::String::New("GetNextRequestId"))) { |
| 102 return v8::FunctionTemplate::New(GetNextRequestId); | 102 return v8::FunctionTemplate::New(GetNextRequestId); |
| 103 } else if (name->Equals(v8::String::New("OpenChannelToTab"))) { | 103 } else if (name->Equals(v8::String::New("OpenChannelToTab"))) { |
| 104 return v8::FunctionTemplate::New(OpenChannelToTab); | 104 return v8::FunctionTemplate::New(OpenChannelToTab); |
| 105 } else if (name->Equals(v8::String::New("GetCurrentPageActions"))) { | 105 } else if (name->Equals(v8::String::New("GetCurrentPageActions"))) { |
| 106 return v8::FunctionTemplate::New(GetCurrentPageActions); | 106 return v8::FunctionTemplate::New(GetCurrentPageActions); |
| 107 } else if (name->Equals(v8::String::New("StartRequest"))) { | 107 } else if (name->Equals(v8::String::New("StartRequest"))) { |
| 108 return v8::FunctionTemplate::New(StartRequest); | 108 return v8::FunctionTemplate::New(StartRequest); |
| 109 } else if (name->Equals(v8::String::New("GetRenderViewId"))) { |
| 110 return v8::FunctionTemplate::New(GetRenderViewId); |
| 109 } | 111 } |
| 110 | 112 |
| 111 return ExtensionBase::GetNativeFunction(name); | 113 return ExtensionBase::GetNativeFunction(name); |
| 112 } | 114 } |
| 113 | 115 |
| 114 private: | 116 private: |
| 115 static v8::Handle<v8::Value> GetExtensionAPIDefinition( | 117 static v8::Handle<v8::Value> GetExtensionAPIDefinition( |
| 116 const v8::Arguments& args) { | 118 const v8::Arguments& args) { |
| 117 return v8::String::New(GetStringResource<IDR_EXTENSION_API_JSON>()); | 119 return v8::String::New(GetStringResource<IDR_EXTENSION_API_JSON>()); |
| 118 } | 120 } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 v8::Persistent<v8::Context> current_context = | 263 v8::Persistent<v8::Context> current_context = |
| 262 v8::Persistent<v8::Context>::New(v8::Context::GetCurrent()); | 264 v8::Persistent<v8::Context>::New(v8::Context::GetCurrent()); |
| 263 DCHECK(!current_context.IsEmpty()); | 265 DCHECK(!current_context.IsEmpty()); |
| 264 GetPendingRequestMap()[request_id].reset(new PendingRequest( | 266 GetPendingRequestMap()[request_id].reset(new PendingRequest( |
| 265 current_context, name)); | 267 current_context, name)); |
| 266 | 268 |
| 267 renderview->SendExtensionRequest(name, json_args, request_id, has_callback); | 269 renderview->SendExtensionRequest(name, json_args, request_id, has_callback); |
| 268 | 270 |
| 269 return v8::Undefined(); | 271 return v8::Undefined(); |
| 270 } | 272 } |
| 273 |
| 274 static v8::Handle<v8::Value> GetRenderViewId(const v8::Arguments& args) { |
| 275 RenderView* renderview = bindings_utils::GetRenderViewForCurrentContext(); |
| 276 if (!renderview) |
| 277 return v8::Undefined(); |
| 278 return v8::Integer::New(renderview->routing_id()); |
| 279 } |
| 271 }; | 280 }; |
| 272 | 281 |
| 273 } // namespace | 282 } // namespace |
| 274 | 283 |
| 275 v8::Extension* ExtensionProcessBindings::Get() { | 284 v8::Extension* ExtensionProcessBindings::Get() { |
| 276 static v8::Extension* extension = new ExtensionImpl(); | 285 static v8::Extension* extension = new ExtensionImpl(); |
| 277 return extension; | 286 return extension; |
| 278 } | 287 } |
| 279 | 288 |
| 280 void ExtensionProcessBindings::SetFunctionNames( | 289 void ExtensionProcessBindings::SetFunctionNames( |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 const std::string& function_name) { | 389 const std::string& function_name) { |
| 381 static const char kMessage[] = | 390 static const char kMessage[] = |
| 382 "You do not have permission to use 'chrome.%s'. Be sure to declare" | 391 "You do not have permission to use 'chrome.%s'. Be sure to declare" |
| 383 " in your manifest what permissions you need."; | 392 " in your manifest what permissions you need."; |
| 384 std::string permission_name = GetPermissionName(function_name); | 393 std::string permission_name = GetPermissionName(function_name); |
| 385 std::string error_msg = StringPrintf(kMessage, permission_name.c_str()); | 394 std::string error_msg = StringPrintf(kMessage, permission_name.c_str()); |
| 386 | 395 |
| 387 return v8::ThrowException(v8::Exception::Error( | 396 return v8::ThrowException(v8::Exception::Error( |
| 388 v8::String::New(error_msg.c_str()))); | 397 v8::String::New(error_msg.c_str()))); |
| 389 } | 398 } |
| OLD | NEW |