| Index: chrome/common/extensions/extension.cc
|
| diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
|
| index fe25d2224609629fca29c6dd841bfafc41bf224e..a83392eccca60a3986407cd771e9149e222a29a7 100644
|
| --- a/chrome/common/extensions/extension.cc
|
| +++ b/chrome/common/extensions/extension.cc
|
| @@ -979,15 +979,6 @@ bool Extension::ShouldDisplayInExtensionSettings() const {
|
| return true;
|
| }
|
|
|
| -bool Extension::HasContentScriptAtURL(const GURL& url) const {
|
| - for (UserScriptList::const_iterator it = content_scripts_.begin();
|
| - it != content_scripts_.end(); ++it) {
|
| - if (it->MatchesURL(url))
|
| - return true;
|
| - }
|
| - return false;
|
| -}
|
| -
|
| scoped_refptr<const PermissionSet> Extension::GetTabSpecificPermissions(
|
| int tab_id) const {
|
| base::AutoLock auto_lock(runtime_data_lock_);
|
| @@ -1927,46 +1918,13 @@ bool Extension::LoadExtensionFeatures(string16* error) {
|
| manifest_->GetBoolean(keys::kConvertedFromUserScript,
|
| &converted_from_user_script_);
|
|
|
| - if (!LoadContentScripts(error) ||
|
| - !LoadSystemIndicator(error) ||
|
| + if (!LoadSystemIndicator(error) ||
|
| !LoadIncognitoMode(error))
|
| return false;
|
|
|
| return true;
|
| }
|
|
|
| -bool Extension::LoadContentScripts(string16* error) {
|
| - if (!manifest_->HasKey(keys::kContentScripts))
|
| - return true;
|
| -
|
| - const ListValue* list_value;
|
| - if (!manifest_->GetList(keys::kContentScripts, &list_value)) {
|
| - *error = ASCIIToUTF16(errors::kInvalidContentScriptsList);
|
| - return false;
|
| - }
|
| -
|
| - for (size_t i = 0; i < list_value->GetSize(); ++i) {
|
| - const DictionaryValue* content_script = NULL;
|
| - if (!list_value->GetDictionary(i, &content_script)) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidContentScript, base::IntToString(i));
|
| - return false;
|
| - }
|
| -
|
| - UserScript script;
|
| - if (!LoadUserScriptHelper(content_script, i, error, &script))
|
| - return false; // Failed to parse script context definition.
|
| -
|
| - script.set_extension_id(id());
|
| - if (converted_from_user_script_) {
|
| - script.set_emulate_greasemonkey(true);
|
| - script.set_match_all_frames(true); // Greasemonkey matches all frames.
|
| - }
|
| - content_scripts_.push_back(script);
|
| - }
|
| - return true;
|
| -}
|
| -
|
| bool Extension::LoadSystemIndicator(string16* error) {
|
| if (!manifest_->HasKey(keys::kSystemIndicator)) {
|
| // There was no manifest entry for the system indicator.
|
| @@ -2015,261 +1973,6 @@ bool Extension::LoadIncognitoMode(string16* error) {
|
| return true;
|
| }
|
|
|
| -// Helper method that loads a UserScript object from a dictionary in the
|
| -// content_script list of the manifest.
|
| -bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script,
|
| - int definition_index,
|
| - string16* error,
|
| - UserScript* result) {
|
| - // run_at
|
| - if (content_script->HasKey(keys::kRunAt)) {
|
| - std::string run_location;
|
| - if (!content_script->GetString(keys::kRunAt, &run_location)) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidRunAt,
|
| - base::IntToString(definition_index));
|
| - return false;
|
| - }
|
| -
|
| - if (run_location == values::kRunAtDocumentStart) {
|
| - result->set_run_location(UserScript::DOCUMENT_START);
|
| - } else if (run_location == values::kRunAtDocumentEnd) {
|
| - result->set_run_location(UserScript::DOCUMENT_END);
|
| - } else if (run_location == values::kRunAtDocumentIdle) {
|
| - result->set_run_location(UserScript::DOCUMENT_IDLE);
|
| - } else {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidRunAt,
|
| - base::IntToString(definition_index));
|
| - return false;
|
| - }
|
| - }
|
| -
|
| - // all frames
|
| - if (content_script->HasKey(keys::kAllFrames)) {
|
| - bool all_frames = false;
|
| - if (!content_script->GetBoolean(keys::kAllFrames, &all_frames)) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidAllFrames, base::IntToString(definition_index));
|
| - return false;
|
| - }
|
| - result->set_match_all_frames(all_frames);
|
| - }
|
| -
|
| - // matches (required)
|
| - const ListValue* matches = NULL;
|
| - if (!content_script->GetList(keys::kMatches, &matches)) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidMatches,
|
| - base::IntToString(definition_index));
|
| - return false;
|
| - }
|
| -
|
| - if (matches->GetSize() == 0) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidMatchCount,
|
| - base::IntToString(definition_index));
|
| - return false;
|
| - }
|
| - for (size_t j = 0; j < matches->GetSize(); ++j) {
|
| - std::string match_str;
|
| - if (!matches->GetString(j, &match_str)) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidMatch,
|
| - base::IntToString(definition_index),
|
| - base::IntToString(j),
|
| - errors::kExpectString);
|
| - return false;
|
| - }
|
| -
|
| - URLPattern pattern(
|
| - UserScript::ValidUserScriptSchemes(CanExecuteScriptEverywhere()));
|
| -
|
| - URLPattern::ParseResult parse_result = pattern.Parse(match_str);
|
| - if (parse_result != URLPattern::PARSE_SUCCESS) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidMatch,
|
| - base::IntToString(definition_index),
|
| - base::IntToString(j),
|
| - URLPattern::GetParseResultString(parse_result));
|
| - return false;
|
| - }
|
| -
|
| - // TODO(aboxhall): check for webstore
|
| - if (!CanExecuteScriptEverywhere() &&
|
| - pattern.scheme() != chrome::kChromeUIScheme) {
|
| - // Exclude SCHEME_CHROMEUI unless it's been explicitly requested.
|
| - // If the --extensions-on-chrome-urls flag has not been passed, requesting
|
| - // a chrome:// url will cause a parse failure above, so there's no need to
|
| - // check the flag here.
|
| - pattern.SetValidSchemes(
|
| - pattern.valid_schemes() & ~URLPattern::SCHEME_CHROMEUI);
|
| - }
|
| -
|
| - if (pattern.MatchesScheme(chrome::kFileScheme) &&
|
| - !CanExecuteScriptEverywhere()) {
|
| - wants_file_access_ = true;
|
| - if (!(creation_flags_ & ALLOW_FILE_ACCESS)) {
|
| - pattern.SetValidSchemes(
|
| - pattern.valid_schemes() & ~URLPattern::SCHEME_FILE);
|
| - }
|
| - }
|
| -
|
| - result->add_url_pattern(pattern);
|
| - }
|
| -
|
| - // exclude_matches
|
| - if (content_script->HasKey(keys::kExcludeMatches)) { // optional
|
| - const ListValue* exclude_matches = NULL;
|
| - if (!content_script->GetList(keys::kExcludeMatches, &exclude_matches)) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidExcludeMatches,
|
| - base::IntToString(definition_index));
|
| - return false;
|
| - }
|
| -
|
| - for (size_t j = 0; j < exclude_matches->GetSize(); ++j) {
|
| - std::string match_str;
|
| - if (!exclude_matches->GetString(j, &match_str)) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidExcludeMatch,
|
| - base::IntToString(definition_index),
|
| - base::IntToString(j),
|
| - errors::kExpectString);
|
| - return false;
|
| - }
|
| -
|
| - int valid_schemes =
|
| - UserScript::ValidUserScriptSchemes(CanExecuteScriptEverywhere());
|
| - URLPattern pattern(valid_schemes);
|
| - URLPattern::ParseResult parse_result = pattern.Parse(match_str);
|
| - if (parse_result != URLPattern::PARSE_SUCCESS) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidExcludeMatch,
|
| - base::IntToString(definition_index), base::IntToString(j),
|
| - URLPattern::GetParseResultString(parse_result));
|
| - return false;
|
| - }
|
| -
|
| - result->add_exclude_url_pattern(pattern);
|
| - }
|
| - }
|
| -
|
| - // include/exclude globs (mostly for Greasemonkey compatibility)
|
| - if (!LoadGlobsHelper(content_script, definition_index, keys::kIncludeGlobs,
|
| - error, &UserScript::add_glob, result)) {
|
| - return false;
|
| - }
|
| -
|
| - if (!LoadGlobsHelper(content_script, definition_index, keys::kExcludeGlobs,
|
| - error, &UserScript::add_exclude_glob, result)) {
|
| - return false;
|
| - }
|
| -
|
| - // js and css keys
|
| - const ListValue* js = NULL;
|
| - if (content_script->HasKey(keys::kJs) &&
|
| - !content_script->GetList(keys::kJs, &js)) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidJsList,
|
| - base::IntToString(definition_index));
|
| - return false;
|
| - }
|
| -
|
| - const ListValue* css = NULL;
|
| - if (content_script->HasKey(keys::kCss) &&
|
| - !content_script->GetList(keys::kCss, &css)) {
|
| - *error = ErrorUtils::
|
| - FormatErrorMessageUTF16(errors::kInvalidCssList,
|
| - base::IntToString(definition_index));
|
| - return false;
|
| - }
|
| -
|
| - // The manifest needs to have at least one js or css user script definition.
|
| - if (((js ? js->GetSize() : 0) + (css ? css->GetSize() : 0)) == 0) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kMissingFile,
|
| - base::IntToString(definition_index));
|
| - return false;
|
| - }
|
| -
|
| - if (js) {
|
| - for (size_t script_index = 0; script_index < js->GetSize();
|
| - ++script_index) {
|
| - const Value* value;
|
| - std::string relative;
|
| - if (!js->Get(script_index, &value) || !value->GetAsString(&relative)) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidJs,
|
| - base::IntToString(definition_index),
|
| - base::IntToString(script_index));
|
| - return false;
|
| - }
|
| - GURL url = GetResourceURL(relative);
|
| - ExtensionResource resource = GetResource(relative);
|
| - result->js_scripts().push_back(UserScript::File(
|
| - resource.extension_root(), resource.relative_path(), url));
|
| - }
|
| - }
|
| -
|
| - if (css) {
|
| - for (size_t script_index = 0; script_index < css->GetSize();
|
| - ++script_index) {
|
| - const Value* value;
|
| - std::string relative;
|
| - if (!css->Get(script_index, &value) || !value->GetAsString(&relative)) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidCss,
|
| - base::IntToString(definition_index),
|
| - base::IntToString(script_index));
|
| - return false;
|
| - }
|
| - GURL url = GetResourceURL(relative);
|
| - ExtensionResource resource = GetResource(relative);
|
| - result->css_scripts().push_back(UserScript::File(
|
| - resource.extension_root(), resource.relative_path(), url));
|
| - }
|
| - }
|
| -
|
| - return true;
|
| -}
|
| -
|
| -bool Extension::LoadGlobsHelper(
|
| - const DictionaryValue* content_script,
|
| - int content_script_index,
|
| - const char* globs_property_name,
|
| - string16* error,
|
| - void(UserScript::*add_method)(const std::string& glob),
|
| - UserScript* instance) {
|
| - if (!content_script->HasKey(globs_property_name))
|
| - return true; // they are optional
|
| -
|
| - const ListValue* list = NULL;
|
| - if (!content_script->GetList(globs_property_name, &list)) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidGlobList,
|
| - base::IntToString(content_script_index),
|
| - globs_property_name);
|
| - return false;
|
| - }
|
| -
|
| - for (size_t i = 0; i < list->GetSize(); ++i) {
|
| - std::string glob;
|
| - if (!list->GetString(i, &glob)) {
|
| - *error = ErrorUtils::FormatErrorMessageUTF16(
|
| - errors::kInvalidGlob,
|
| - base::IntToString(content_script_index),
|
| - globs_property_name,
|
| - base::IntToString(i));
|
| - return false;
|
| - }
|
| -
|
| - (instance->*add_method)(glob);
|
| - }
|
| -
|
| - return true;
|
| -}
|
| -
|
| bool Extension::HasMultipleUISurfaces() const {
|
| int num_surfaces = 0;
|
|
|
|
|