Chromium Code Reviews| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 using WebKit::WebDocument; | 70 using WebKit::WebDocument; |
| 71 using WebKit::WebFrame; | 71 using WebKit::WebFrame; |
| 72 using WebKit::WebScopedUserGesture; | 72 using WebKit::WebScopedUserGesture; |
| 73 using WebKit::WebSecurityPolicy; | 73 using WebKit::WebSecurityPolicy; |
| 74 using WebKit::WebString; | 74 using WebKit::WebString; |
| 75 using WebKit::WebVector; | 75 using WebKit::WebVector; |
| 76 using WebKit::WebView; | 76 using WebKit::WebView; |
| 77 using content::RenderThread; | 77 using content::RenderThread; |
| 78 using content::RenderView; | 78 using content::RenderView; |
| 79 using extensions::APIPermission; | 79 using extensions::APIPermission; |
| 80 using extensions::APIPermissionSet; | |
| 80 using extensions::ApiDefinitionsNatives; | 81 using extensions::ApiDefinitionsNatives; |
| 81 using extensions::AppWindowCustomBindings; | 82 using extensions::AppWindowCustomBindings; |
| 82 using extensions::ContextMenusCustomBindings; | 83 using extensions::ContextMenusCustomBindings; |
| 83 using extensions::Extension; | 84 using extensions::Extension; |
| 84 using extensions::ExperimentalAppCustomBindings; | 85 using extensions::ExperimentalAppCustomBindings; |
| 85 using extensions::ExperimentalUsbCustomBindings; | 86 using extensions::ExperimentalUsbCustomBindings; |
| 86 using extensions::ExtensionAPI; | 87 using extensions::ExtensionAPI; |
| 87 using extensions::ExtensionCustomBindings; | 88 using extensions::ExtensionCustomBindings; |
| 88 using extensions::Feature; | 89 using extensions::Feature; |
| 89 using extensions::FileBrowserHandlerCustomBindings; | 90 using extensions::FileBrowserHandlerCustomBindings; |
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 929 // the target tab. This may change. Either way, if this is the target tab it | 930 // the target tab. This may change. Either way, if this is the target tab it |
| 930 // gives us the chance to check against the page ID to avoid races. | 931 // gives us the chance to check against the page ID to avoid races. |
| 931 DCHECK(view); | 932 DCHECK(view); |
| 932 if (view && view->GetPageId() != page_id) | 933 if (view && view->GetPageId() != page_id) |
| 933 return; | 934 return; |
| 934 | 935 |
| 935 const Extension* extension = extensions_.GetByID(extension_id); | 936 const Extension* extension = extensions_.GetByID(extension_id); |
| 936 if (!extension) | 937 if (!extension) |
| 937 return; | 938 return; |
| 938 | 939 |
| 939 extension->SetTabSpecificHostPermissions(tab_id, origin_set); | 940 extension->UpdateTabSpecificPermissions( |
| 941 tab_id, | |
| 942 new PermissionSet(APIPermissionSet(), origin_set, URLPatternSet())); | |
| 940 } | 943 } |
| 941 | 944 |
| 942 void ExtensionDispatcher::OnClearTabSpecificPermissions( | 945 void ExtensionDispatcher::OnClearTabSpecificPermissions( |
| 943 int tab_id, | 946 int tab_id, |
| 944 const std::vector<std::string>& extension_ids) { | 947 const std::vector<std::string>& extension_ids) { |
| 945 for (std::vector<std::string>::const_iterator it = extension_ids.begin(); | 948 for (std::vector<std::string>::const_iterator it = extension_ids.begin(); |
| 946 it != extension_ids.end(); ++it) { | 949 it != extension_ids.end(); ++it) { |
| 947 const Extension* extension = extensions_.GetByID(*it); | 950 const Extension* extension = extensions_.GetByID(*it); |
| 948 if (extension) | 951 if (extension) |
| 949 extension->ClearTabSpecificHostPermissions(tab_id); | 952 extension->ClearTabSpecificPermissions(tab_id); |
| 950 } | 953 } |
| 951 } | 954 } |
| 952 | 955 |
| 953 void ExtensionDispatcher::OnUpdateUserScripts( | 956 void ExtensionDispatcher::OnUpdateUserScripts( |
| 954 base::SharedMemoryHandle scripts) { | 957 base::SharedMemoryHandle scripts) { |
| 955 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle"; | 958 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle"; |
| 956 user_script_slave_->UpdateScripts(scripts); | 959 user_script_slave_->UpdateScripts(scripts); |
| 957 UpdateActiveExtensions(); | 960 UpdateActiveExtensions(); |
| 958 } | 961 } |
| 959 | 962 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1048 } | 1051 } |
| 1049 | 1052 |
| 1050 bool ExtensionDispatcher::CheckCurrentContextAccessToExtensionAPI( | 1053 bool ExtensionDispatcher::CheckCurrentContextAccessToExtensionAPI( |
| 1051 const std::string& function_name) const { | 1054 const std::string& function_name) const { |
| 1052 ChromeV8Context* context = v8_context_set().GetCurrent(); | 1055 ChromeV8Context* context = v8_context_set().GetCurrent(); |
| 1053 if (!context) { | 1056 if (!context) { |
| 1054 DLOG(ERROR) << "Not in a v8::Context"; | 1057 DLOG(ERROR) << "Not in a v8::Context"; |
| 1055 return false; | 1058 return false; |
| 1056 } | 1059 } |
| 1057 | 1060 |
| 1058 if (!context->extension() || | 1061 if (!context->extension()) { |
| 1062 v8::ThrowException( | |
| 1063 v8::Exception::Error(v8::String::New("Not in an extension."))); | |
| 1064 return false; | |
| 1065 } | |
| 1066 | |
| 1067 // Whitelist tabs.executeScript and tabs.insertCSS since they might be | |
| 1068 // controlled by activeTab. The browser will do the relevant access checks. | |
| 1069 // We either do this or propagate all tab IDs to renderers with extensions | |
| 1070 // that have activeTab. | |
| 1071 bool skip_permission_check = (function_name == "tabs.executeScript") || | |
|
Aaron Boodman
2012/07/31 14:53:43
Wait, then why are we sending the active tab permi
not at google - send to devlin
2012/07/31 15:09:05
The renderer does a check in UserScriptScheduler a
not at google - send to devlin
2012/08/01 13:57:04
I remember again why I did this. Oops. Comment upd
| |
| 1072 (function_name == "tabs.insertCSS"); | |
| 1073 | |
| 1074 if (!skip_permission_check && | |
| 1059 !context->extension()->HasAPIPermission(function_name)) { | 1075 !context->extension()->HasAPIPermission(function_name)) { |
| 1060 static const char kMessage[] = | 1076 static const char kMessage[] = |
| 1061 "You do not have permission to use '%s'. Be sure to declare" | 1077 "You do not have permission to use '%s'. Be sure to declare" |
| 1062 " in your manifest what permissions you need."; | 1078 " in your manifest what permissions you need."; |
| 1063 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1079 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
| 1064 v8::ThrowException( | 1080 v8::ThrowException( |
| 1065 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1081 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
| 1066 return false; | 1082 return false; |
| 1067 } | 1083 } |
| 1068 | 1084 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1080 // APIs, they don't get extension bindings injected. If we end up here it | 1096 // APIs, they don't get extension bindings injected. If we end up here it |
| 1081 // means that a sandboxed page somehow managed to invoke an API anyway, so | 1097 // means that a sandboxed page somehow managed to invoke an API anyway, so |
| 1082 // we should abort. | 1098 // we should abort. |
| 1083 WebKit::WebFrame* frame = context->web_frame(); | 1099 WebKit::WebFrame* frame = context->web_frame(); |
| 1084 ExtensionURLInfo url_info(frame->document().securityOrigin(), | 1100 ExtensionURLInfo url_info(frame->document().securityOrigin(), |
| 1085 extensions::UserScriptSlave::GetDataSourceURLForFrame(frame)); | 1101 extensions::UserScriptSlave::GetDataSourceURLForFrame(frame)); |
| 1086 CHECK(!extensions_.IsSandboxedPage(url_info)); | 1102 CHECK(!extensions_.IsSandboxedPage(url_info)); |
| 1087 | 1103 |
| 1088 return true; | 1104 return true; |
| 1089 } | 1105 } |
| OLD | NEW |