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/extension_dispatcher.h" | 5 #include "chrome/renderer/extensions/extension_dispatcher.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 | 847 |
848 return Feature::UNSPECIFIED_CONTEXT; | 848 return Feature::UNSPECIFIED_CONTEXT; |
849 } | 849 } |
850 | 850 |
851 void ExtensionDispatcher::OnExtensionResponse(int request_id, | 851 void ExtensionDispatcher::OnExtensionResponse(int request_id, |
852 bool success, | 852 bool success, |
853 const std::string& response, | 853 const std::string& response, |
854 const std::string& error) { | 854 const std::string& error) { |
855 request_sender_->HandleResponse(request_id, success, response, error); | 855 request_sender_->HandleResponse(request_id, success, response, error); |
856 } | 856 } |
857 | |
858 bool ExtensionDispatcher::CheckCurrentContextAccessToExtensionAPI( | |
859 const std::string& function_name) const { | |
860 ChromeV8Context* context = v8_context_set().GetCurrent(); | |
861 if (!context) { | |
862 DLOG(ERROR) << "Not in a v8::Context"; | |
863 return false; | |
864 } | |
865 | |
866 if (!context->extension() || | |
867 !context->extension()->HasAPIPermission(function_name)) { | |
868 static const char kMessage[] = | |
869 "You do not have permission to use '%s'. Be sure to declare" | |
870 " in your manifest what permissions you need."; | |
871 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | |
872 v8::ThrowException( | |
873 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | |
874 return false; | |
875 } | |
876 | |
877 if (!IsExtensionActive(context->extension()->id()) && | |
878 ExtensionAPI::GetSharedInstance()->IsPrivileged(function_name)) { | |
879 static const char kMessage[] = | |
880 "%s can only be used in an extension process."; | |
881 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | |
882 v8::ThrowException( | |
883 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | |
884 return false; | |
885 } | |
886 | |
887 return true; | |
888 } | |
OLD | NEW |