| 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/dispatcher.h" | 5 #include "chrome/renderer/extensions/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/debug/alias.h" | 9 #include "base/debug/alias.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 15 #include "chrome/common/child_process_logging.h" | 15 #include "chrome/common/child_process_logging.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
| 18 #include "chrome/common/extensions/api/extension_api.h" | 18 #include "chrome/common/extensions/api/extension_api.h" |
| 19 #include "chrome/common/extensions/background_info.h" | 19 #include "chrome/common/extensions/background_info.h" |
| 20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/extensions/extension_messages.h" | 21 #include "chrome/common/extensions/extension_messages.h" |
| 22 #include "chrome/common/extensions/features/base_feature_provider.h" | 22 #include "chrome/common/extensions/features/base_feature_provider.h" |
| 23 #include "chrome/common/extensions/features/feature.h" | 23 #include "chrome/common/extensions/features/feature.h" |
| 24 #include "chrome/common/extensions/manifest.h" | 24 #include "chrome/common/extensions/manifest.h" |
| 25 #include "chrome/common/extensions/message_bundle.h" | 25 #include "chrome/common/extensions/message_bundle.h" |
| 26 #include "chrome/common/extensions/permissions/permission_set.h" | 26 #include "chrome/common/extensions/permissions/permission_set.h" |
| 27 #include "chrome/common/extensions/permissions/permissions_data.h" |
| 27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 28 #include "chrome/renderer/chrome_render_process_observer.h" | 29 #include "chrome/renderer/chrome_render_process_observer.h" |
| 29 #include "chrome/renderer/extensions/api_activity_logger.h" | 30 #include "chrome/renderer/extensions/api_activity_logger.h" |
| 30 #include "chrome/renderer/extensions/api_definitions_natives.h" | 31 #include "chrome/renderer/extensions/api_definitions_natives.h" |
| 31 #include "chrome/renderer/extensions/app_bindings.h" | 32 #include "chrome/renderer/extensions/app_bindings.h" |
| 32 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h" | 33 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h" |
| 33 #include "chrome/renderer/extensions/app_window_custom_bindings.h" | 34 #include "chrome/renderer/extensions/app_window_custom_bindings.h" |
| 34 #include "chrome/renderer/extensions/binding_generating_native_handler.h" | 35 #include "chrome/renderer/extensions/binding_generating_native_handler.h" |
| 35 #include "chrome/renderer/extensions/chrome_v8_context.h" | 36 #include "chrome/renderer/extensions/chrome_v8_context.h" |
| 36 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 37 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
| (...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 const PermissionSet* new_active = NULL; | 1269 const PermissionSet* new_active = NULL; |
| 1269 switch (reason) { | 1270 switch (reason) { |
| 1270 case UpdatedExtensionPermissionsInfo::ADDED: | 1271 case UpdatedExtensionPermissionsInfo::ADDED: |
| 1271 new_active = PermissionSet::CreateUnion(old_active, delta); | 1272 new_active = PermissionSet::CreateUnion(old_active, delta); |
| 1272 break; | 1273 break; |
| 1273 case UpdatedExtensionPermissionsInfo::REMOVED: | 1274 case UpdatedExtensionPermissionsInfo::REMOVED: |
| 1274 new_active = PermissionSet::CreateDifference(old_active, delta); | 1275 new_active = PermissionSet::CreateDifference(old_active, delta); |
| 1275 break; | 1276 break; |
| 1276 } | 1277 } |
| 1277 | 1278 |
| 1278 extension->SetActivePermissions(new_active); | 1279 PermissionsData::SetActivePermissions(extension, new_active); |
| 1279 AddOrRemoveOriginPermissions(reason, extension, explicit_hosts); | 1280 AddOrRemoveOriginPermissions(reason, extension, explicit_hosts); |
| 1280 } | 1281 } |
| 1281 | 1282 |
| 1282 void Dispatcher::OnUpdateTabSpecificPermissions( | 1283 void Dispatcher::OnUpdateTabSpecificPermissions( |
| 1283 int page_id, | 1284 int page_id, |
| 1284 int tab_id, | 1285 int tab_id, |
| 1285 const std::string& extension_id, | 1286 const std::string& extension_id, |
| 1286 const URLPatternSet& origin_set) { | 1287 const URLPatternSet& origin_set) { |
| 1287 RenderView* view = TabFinder::Find(tab_id); | 1288 RenderView* view = TabFinder::Find(tab_id); |
| 1288 | 1289 |
| 1289 // For now, the message should only be sent to the render view that contains | 1290 // For now, the message should only be sent to the render view that contains |
| 1290 // the target tab. This may change. Either way, if this is the target tab it | 1291 // the target tab. This may change. Either way, if this is the target tab it |
| 1291 // gives us the chance to check against the page ID to avoid races. | 1292 // gives us the chance to check against the page ID to avoid races. |
| 1292 DCHECK(view); | 1293 DCHECK(view); |
| 1293 if (view && view->GetPageId() != page_id) | 1294 if (view && view->GetPageId() != page_id) |
| 1294 return; | 1295 return; |
| 1295 | 1296 |
| 1296 const Extension* extension = extensions_.GetByID(extension_id); | 1297 const Extension* extension = extensions_.GetByID(extension_id); |
| 1297 if (!extension) | 1298 if (!extension) |
| 1298 return; | 1299 return; |
| 1299 | 1300 |
| 1300 extension->UpdateTabSpecificPermissions( | 1301 PermissionsData::UpdateTabSpecificPermissions( |
| 1302 extension, |
| 1301 tab_id, | 1303 tab_id, |
| 1302 new PermissionSet(APIPermissionSet(), origin_set, URLPatternSet())); | 1304 new PermissionSet(APIPermissionSet(), origin_set, URLPatternSet())); |
| 1303 } | 1305 } |
| 1304 | 1306 |
| 1305 void Dispatcher::OnClearTabSpecificPermissions( | 1307 void Dispatcher::OnClearTabSpecificPermissions( |
| 1306 int tab_id, | 1308 int tab_id, |
| 1307 const std::vector<std::string>& extension_ids) { | 1309 const std::vector<std::string>& extension_ids) { |
| 1308 for (std::vector<std::string>::const_iterator it = extension_ids.begin(); | 1310 for (std::vector<std::string>::const_iterator it = extension_ids.begin(); |
| 1309 it != extension_ids.end(); ++it) { | 1311 it != extension_ids.end(); ++it) { |
| 1310 const Extension* extension = extensions_.GetByID(*it); | 1312 const Extension* extension = extensions_.GetByID(*it); |
| 1311 if (extension) | 1313 if (extension) |
| 1312 extension->ClearTabSpecificPermissions(tab_id); | 1314 PermissionsData::ClearTabSpecificPermissions(extension, tab_id); |
| 1313 } | 1315 } |
| 1314 } | 1316 } |
| 1315 | 1317 |
| 1316 void Dispatcher::OnUpdateUserScripts( | 1318 void Dispatcher::OnUpdateUserScripts( |
| 1317 base::SharedMemoryHandle scripts) { | 1319 base::SharedMemoryHandle scripts) { |
| 1318 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle"; | 1320 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle"; |
| 1319 user_script_slave_->UpdateScripts(scripts); | 1321 user_script_slave_->UpdateScripts(scripts); |
| 1320 UpdateActiveExtensions(); | 1322 UpdateActiveExtensions(); |
| 1321 } | 1323 } |
| 1322 | 1324 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1451 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1453 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
| 1452 v8::ThrowException( | 1454 v8::ThrowException( |
| 1453 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1455 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
| 1454 return false; | 1456 return false; |
| 1455 } | 1457 } |
| 1456 | 1458 |
| 1457 return true; | 1459 return true; |
| 1458 } | 1460 } |
| 1459 | 1461 |
| 1460 } // namespace extensions | 1462 } // namespace extensions |
| OLD | NEW |