Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: chrome/renderer/extensions/extension_dispatcher.cc

Issue 10815028: Make ActiveTabPermissionManager also grant the tabs permission. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: oops Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 // the target tab. This may change. Either way, if this is the target tab it 987 // the target tab. This may change. Either way, if this is the target tab it
987 // gives us the chance to check against the page ID to avoid races. 988 // gives us the chance to check against the page ID to avoid races.
988 DCHECK(view); 989 DCHECK(view);
989 if (view && view->GetPageId() != page_id) 990 if (view && view->GetPageId() != page_id)
990 return; 991 return;
991 992
992 const Extension* extension = extensions_.GetByID(extension_id); 993 const Extension* extension = extensions_.GetByID(extension_id);
993 if (!extension) 994 if (!extension)
994 return; 995 return;
995 996
996 extension->SetTabSpecificHostPermissions(tab_id, origin_set); 997 extension->UpdateTabSpecificPermissions(
998 tab_id,
999 new PermissionSet(APIPermissionSet(), origin_set, URLPatternSet()));
997 } 1000 }
998 1001
999 void ExtensionDispatcher::OnClearTabSpecificPermissions( 1002 void ExtensionDispatcher::OnClearTabSpecificPermissions(
1000 int tab_id, 1003 int tab_id,
1001 const std::vector<std::string>& extension_ids) { 1004 const std::vector<std::string>& extension_ids) {
1002 for (std::vector<std::string>::const_iterator it = extension_ids.begin(); 1005 for (std::vector<std::string>::const_iterator it = extension_ids.begin();
1003 it != extension_ids.end(); ++it) { 1006 it != extension_ids.end(); ++it) {
1004 const Extension* extension = extensions_.GetByID(*it); 1007 const Extension* extension = extensions_.GetByID(*it);
1005 if (extension) 1008 if (extension)
1006 extension->ClearTabSpecificHostPermissions(tab_id); 1009 extension->ClearTabSpecificPermissions(tab_id);
1007 } 1010 }
1008 } 1011 }
1009 1012
1010 void ExtensionDispatcher::OnUpdateUserScripts( 1013 void ExtensionDispatcher::OnUpdateUserScripts(
1011 base::SharedMemoryHandle scripts) { 1014 base::SharedMemoryHandle scripts) {
1012 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle"; 1015 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle";
1013 user_script_slave_->UpdateScripts(scripts); 1016 user_script_slave_->UpdateScripts(scripts);
1014 UpdateActiveExtensions(); 1017 UpdateActiveExtensions();
1015 } 1018 }
1016 1019
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 } 1108 }
1106 1109
1107 bool ExtensionDispatcher::CheckCurrentContextAccessToExtensionAPI( 1110 bool ExtensionDispatcher::CheckCurrentContextAccessToExtensionAPI(
1108 const std::string& function_name) const { 1111 const std::string& function_name) const {
1109 ChromeV8Context* context = v8_context_set().GetCurrent(); 1112 ChromeV8Context* context = v8_context_set().GetCurrent();
1110 if (!context) { 1113 if (!context) {
1111 DLOG(ERROR) << "Not in a v8::Context"; 1114 DLOG(ERROR) << "Not in a v8::Context";
1112 return false; 1115 return false;
1113 } 1116 }
1114 1117
1115 if (!context->extension() || 1118 if (!context->extension()) {
1119 v8::ThrowException(
1120 v8::Exception::Error(v8::String::New("Not in an extension.")));
1121 return false;
1122 }
1123
1124 // We need to whitelist tabs.executeScript and tabs.insertCSS because they
1125 // are granted under special circumstances with the activeTab permission
1126 // (note that the browser checks too, so this isn't a security problem).
1127 //
1128 // Only the browser knows which tab this call will be sent to... sometimes we
1129 // *could* figure it out (if the extension gives an explicit tab ID in the
1130 // call), but the expected case will be the extension passing through -1,
1131 // meaning the active tab, and only the browser safely knows what this is.
1132 bool skip_permission_check = (function_name == "tabs.executeScript") ||
1133 (function_name == "tabs.insertCSS");
1134
1135 if (!skip_permission_check &&
1116 !context->extension()->HasAPIPermission(function_name)) { 1136 !context->extension()->HasAPIPermission(function_name)) {
1117 static const char kMessage[] = 1137 static const char kMessage[] =
1118 "You do not have permission to use '%s'. Be sure to declare" 1138 "You do not have permission to use '%s'. Be sure to declare"
1119 " in your manifest what permissions you need."; 1139 " in your manifest what permissions you need.";
1120 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); 1140 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
1121 v8::ThrowException( 1141 v8::ThrowException(
1122 v8::Exception::Error(v8::String::New(error_msg.c_str()))); 1142 v8::Exception::Error(v8::String::New(error_msg.c_str())));
1123 return false; 1143 return false;
1124 } 1144 }
1125 1145
(...skipping 11 matching lines...) Expand all
1137 // APIs, they don't get extension bindings injected. If we end up here it 1157 // APIs, they don't get extension bindings injected. If we end up here it
1138 // means that a sandboxed page somehow managed to invoke an API anyway, so 1158 // means that a sandboxed page somehow managed to invoke an API anyway, so
1139 // we should abort. 1159 // we should abort.
1140 WebKit::WebFrame* frame = context->web_frame(); 1160 WebKit::WebFrame* frame = context->web_frame();
1141 ExtensionURLInfo url_info(frame->document().securityOrigin(), 1161 ExtensionURLInfo url_info(frame->document().securityOrigin(),
1142 extensions::UserScriptSlave::GetDataSourceURLForFrame(frame)); 1162 extensions::UserScriptSlave::GetDataSourceURLForFrame(frame));
1143 CHECK(!extensions_.IsSandboxedPage(url_info)); 1163 CHECK(!extensions_.IsSandboxedPage(url_info));
1144 1164
1145 return true; 1165 return true;
1146 } 1166 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/permissions/permission_set.h ('k') | chrome/renderer/resources/extensions/apitest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698