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 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 | 869 |
870 return Feature::UNSPECIFIED_CONTEXT; | 870 return Feature::UNSPECIFIED_CONTEXT; |
871 } | 871 } |
872 | 872 |
873 void ExtensionDispatcher::OnExtensionResponse(int request_id, | 873 void ExtensionDispatcher::OnExtensionResponse(int request_id, |
874 bool success, | 874 bool success, |
875 const std::string& response, | 875 const std::string& response, |
876 const std::string& error) { | 876 const std::string& error) { |
877 request_sender_->HandleResponse(request_id, success, response, error); | 877 request_sender_->HandleResponse(request_id, success, response, error); |
878 } | 878 } |
879 | |
880 bool ExtensionDispatcher::CheckCurrentContextAccessToExtensionAPI( | |
881 const std::string& function_name) const { | |
882 ChromeV8Context* context = v8_context_set().GetCurrent(); | |
883 if (!context) { | |
884 DLOG(ERROR) << "Not in a v8::Context"; | |
885 return false; | |
886 } | |
887 | |
888 const ::Extension* extension = NULL; | |
889 if (!context->extension_id().empty()) { | |
890 extension = extensions()->GetByID(context->extension_id()); | |
891 } | |
892 | |
893 if (!extension || !extension->HasAPIPermission(function_name)) { | |
894 static const char kMessage[] = | |
895 "You do not have permission to use '%s'. Be sure to declare" | |
896 " in your manifest what permissions you need."; | |
897 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | |
898 v8::ThrowException( | |
899 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | |
900 return false; | |
901 } | |
902 | |
903 if (!IsExtensionActive(extension->id()) && | |
904 ExtensionAPI::GetSharedInstance()->IsPrivileged(function_name)) { | |
905 static const char kMessage[] = | |
906 "%s can only be used in an extension process."; | |
907 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | |
908 v8::ThrowException( | |
909 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | |
910 return false; | |
911 } | |
912 | |
913 return true; | |
914 } | |
OLD | NEW |