| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/common/extensions/manifest_handlers/content_scripts_handler.h" | 5 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 26 | 26 |
| 27 namespace extensions { | 27 namespace extensions { |
| 28 | 28 |
| 29 namespace keys = extensions::manifest_keys; | 29 namespace keys = extensions::manifest_keys; |
| 30 namespace values = manifest_values; | 30 namespace values = manifest_values; |
| 31 namespace errors = manifest_errors; | 31 namespace errors = manifest_errors; |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 // The globally-unique id for a user script. | |
| 36 int64 g_next_user_script_id = 0; | |
| 37 | |
| 38 // Helper method that loads either the include_globs or exclude_globs list | 35 // Helper method that loads either the include_globs or exclude_globs list |
| 39 // from an entry in the content_script lists of the manifest. | 36 // from an entry in the content_script lists of the manifest. |
| 40 bool LoadGlobsHelper(const base::DictionaryValue* content_script, | 37 bool LoadGlobsHelper(const base::DictionaryValue* content_script, |
| 41 int content_script_index, | 38 int content_script_index, |
| 42 const char* globs_property_name, | 39 const char* globs_property_name, |
| 43 base::string16* error, | 40 base::string16* error, |
| 44 void(UserScript::*add_method)(const std::string& glob), | 41 void(UserScript::*add_method)(const std::string& glob), |
| 45 UserScript* instance) { | 42 UserScript* instance) { |
| 46 if (!content_script->HasKey(globs_property_name)) | 43 if (!content_script->HasKey(globs_property_name)) |
| 47 return true; // they are optional | 44 return true; // they are optional |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 &user_script)) { | 418 &user_script)) { |
| 422 return false; // Failed to parse script context definition. | 419 return false; // Failed to parse script context definition. |
| 423 } | 420 } |
| 424 | 421 |
| 425 user_script.set_extension_id(extension->id()); | 422 user_script.set_extension_id(extension->id()); |
| 426 if (extension->converted_from_user_script()) { | 423 if (extension->converted_from_user_script()) { |
| 427 user_script.set_emulate_greasemonkey(true); | 424 user_script.set_emulate_greasemonkey(true); |
| 428 // Greasemonkey matches all frames. | 425 // Greasemonkey matches all frames. |
| 429 user_script.set_match_all_frames(true); | 426 user_script.set_match_all_frames(true); |
| 430 } | 427 } |
| 431 user_script.set_id(g_next_user_script_id++); | 428 user_script.set_id(UserScript::GenerateUserScriptID()); |
| 432 content_scripts_info->content_scripts.push_back(user_script); | 429 content_scripts_info->content_scripts.push_back(user_script); |
| 433 } | 430 } |
| 434 extension->SetManifestData(keys::kContentScripts, | 431 extension->SetManifestData(keys::kContentScripts, |
| 435 content_scripts_info.release()); | 432 content_scripts_info.release()); |
| 436 PermissionsParser::SetScriptableHosts( | 433 PermissionsParser::SetScriptableHosts( |
| 437 extension, ContentScriptsInfo::GetScriptableHosts(extension)); | 434 extension, ContentScriptsInfo::GetScriptableHosts(extension)); |
| 438 return true; | 435 return true; |
| 439 } | 436 } |
| 440 | 437 |
| 441 bool ContentScriptsHandler::Validate( | 438 bool ContentScriptsHandler::Validate( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 if (!IsScriptValid(path, css_script.relative_path(), | 472 if (!IsScriptValid(path, css_script.relative_path(), |
| 476 IDS_EXTENSION_LOAD_CSS_FAILED, error)) | 473 IDS_EXTENSION_LOAD_CSS_FAILED, error)) |
| 477 return false; | 474 return false; |
| 478 } | 475 } |
| 479 } | 476 } |
| 480 | 477 |
| 481 return true; | 478 return true; |
| 482 } | 479 } |
| 483 | 480 |
| 484 } // namespace extensions | 481 } // namespace extensions |
| OLD | NEW |