| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/extensions/extension_content_settings_api.h" | 5 #include "chrome/browser/extensions/extension_content_settings_api.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 bool SetContentSettingFunction::RunImpl() { | 162 bool SetContentSettingFunction::RunImpl() { |
| 163 std::string content_type_str; | 163 std::string content_type_str; |
| 164 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &content_type_str)); | 164 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &content_type_str)); |
| 165 ContentSettingsType content_type = | 165 ContentSettingsType content_type = |
| 166 helpers::StringToContentSettingsType(content_type_str); | 166 helpers::StringToContentSettingsType(content_type_str); |
| 167 EXTENSION_FUNCTION_VALIDATE(content_type != CONTENT_SETTINGS_TYPE_DEFAULT); | 167 EXTENSION_FUNCTION_VALIDATE(content_type != CONTENT_SETTINGS_TYPE_DEFAULT); |
| 168 | 168 |
| 169 DictionaryValue* details = NULL; | 169 DictionaryValue* details = NULL; |
| 170 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); | 170 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); |
| 171 | 171 |
| 172 DictionaryValue* top_level_pattern_dict = NULL; | 172 std::string top_level_pattern_str; |
| 173 std::string top_level_error; |
| 173 EXTENSION_FUNCTION_VALIDATE( | 174 EXTENSION_FUNCTION_VALIDATE( |
| 174 details->GetDictionary(keys::kTopLevelPatternKey, | 175 details->GetString(keys::kTopLevelPatternKey, &top_level_pattern_str)); |
| 175 &top_level_pattern_dict)); | 176 ContentSettingsPattern top_level_pattern = |
| 176 std::string top_level_pattern_str; | 177 helpers::ParseExtensionPattern(top_level_pattern_str, &top_level_error); |
| 178 if (!top_level_pattern.IsValid()) { |
| 179 error_ = top_level_error; |
| 180 return false; |
| 181 } |
| 182 |
| 183 std::string embedded_pattern_str; |
| 184 std::string embedded_error; |
| 177 EXTENSION_FUNCTION_VALIDATE( | 185 EXTENSION_FUNCTION_VALIDATE( |
| 178 top_level_pattern_dict->GetString(keys::kPatternKey, | 186 details->GetString(keys::kEmbeddedPatternKey, &embedded_pattern_str)); |
| 179 &top_level_pattern_str)); | |
| 180 ContentSettingsPattern top_level_pattern = | |
| 181 ContentSettingsPattern::FromString(top_level_pattern_str); | |
| 182 EXTENSION_FUNCTION_VALIDATE(top_level_pattern.IsValid()); | |
| 183 | |
| 184 DictionaryValue* embedded_pattern_dict = NULL; | |
| 185 EXTENSION_FUNCTION_VALIDATE( | |
| 186 details->GetDictionary(keys::kEmbeddedPatternKey, | |
| 187 &embedded_pattern_dict)); | |
| 188 std::string embedded_pattern_str; | |
| 189 EXTENSION_FUNCTION_VALIDATE( | |
| 190 embedded_pattern_dict->GetString(keys::kPatternKey, | |
| 191 &embedded_pattern_str)); | |
| 192 ContentSettingsPattern embedded_pattern = | 187 ContentSettingsPattern embedded_pattern = |
| 193 ContentSettingsPattern::FromString(embedded_pattern_str); | 188 helpers::ParseExtensionPattern(embedded_pattern_str, &embedded_error); |
| 194 EXTENSION_FUNCTION_VALIDATE(embedded_pattern.IsValid()); | 189 if (!embedded_pattern.IsValid()) { |
| 190 error_ = embedded_error; |
| 191 return false; |
| 192 } |
| 195 | 193 |
| 196 std::string resource_identifier; | 194 std::string resource_identifier; |
| 197 if (details->HasKey(keys::kResourceIdentifierKey)) { | 195 if (details->HasKey(keys::kResourceIdentifierKey)) { |
| 198 DictionaryValue* resource_identifier_dict = NULL; | 196 DictionaryValue* resource_identifier_dict = NULL; |
| 199 EXTENSION_FUNCTION_VALIDATE( | 197 EXTENSION_FUNCTION_VALIDATE( |
| 200 details->GetDictionary(keys::kResourceIdentifierKey, | 198 details->GetDictionary(keys::kResourceIdentifierKey, |
| 201 &resource_identifier_dict)); | 199 &resource_identifier_dict)); |
| 202 EXTENSION_FUNCTION_VALIDATE( | 200 EXTENSION_FUNCTION_VALIDATE( |
| 203 resource_identifier_dict->GetString(keys::kIdKey, | 201 resource_identifier_dict->GetString(keys::kIdKey, |
| 204 &resource_identifier)); | 202 &resource_identifier)); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 BrowserThread::PostTask( | 296 BrowserThread::PostTask( |
| 299 BrowserThread::UI, FROM_HERE, base::Bind( | 297 BrowserThread::UI, FROM_HERE, base::Bind( |
| 300 &GetResourceIdentifiersFunction::SendResponse, this, true)); | 298 &GetResourceIdentifiersFunction::SendResponse, this, true)); |
| 301 } | 299 } |
| 302 | 300 |
| 303 // static | 301 // static |
| 304 void GetResourceIdentifiersFunction::SetPluginListForTesting( | 302 void GetResourceIdentifiersFunction::SetPluginListForTesting( |
| 305 webkit::npapi::PluginList* plugin_list) { | 303 webkit::npapi::PluginList* plugin_list) { |
| 306 g_plugin_list = plugin_list; | 304 g_plugin_list = plugin_list; |
| 307 } | 305 } |
| OLD | NEW |