| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/renderer_host/renderer_security_policy.h" | 5 #include "chrome/browser/renderer_host/renderer_security_policy.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 // Grant permission to upload the specified file to the web. | 30 // Grant permission to upload the specified file to the web. |
| 31 void GrantUploadFile(const FilePath& file) { | 31 void GrantUploadFile(const FilePath& file) { |
| 32 uploadable_files_.insert(file); | 32 uploadable_files_.insert(file); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void GrantDOMUIBindings() { | 35 void GrantDOMUIBindings() { |
| 36 has_dom_ui_bindings_ = true; | 36 has_dom_ui_bindings_ = true; |
| 37 } | 37 } |
| 38 | 38 |
| 39 void GrantNativeViewId(gfx::NativeViewId view_id) { |
| 40 native_view_ids_.insert(view_id); |
| 41 } |
| 42 |
| 39 // Determine whether permission has been granted to request url. | 43 // Determine whether permission has been granted to request url. |
| 40 // Schemes that have not been granted default to being denied. | 44 // Schemes that have not been granted default to being denied. |
| 41 bool CanRequestURL(const GURL& url) { | 45 bool CanRequestURL(const GURL& url) { |
| 42 SchemeMap::const_iterator judgment(scheme_policy_.find(url.scheme())); | 46 SchemeMap::const_iterator judgment(scheme_policy_.find(url.scheme())); |
| 43 | 47 |
| 44 if (judgment == scheme_policy_.end()) | 48 if (judgment == scheme_policy_.end()) |
| 45 return false; // Unmentioned schemes are disallowed. | 49 return false; // Unmentioned schemes are disallowed. |
| 46 | 50 |
| 47 return judgment->second; | 51 return judgment->second; |
| 48 } | 52 } |
| 49 | 53 |
| 50 // Determine whether permission has been granted to upload file. | 54 // Determine whether permission has been granted to upload file. |
| 51 // Files that have not been granted default to being denied. | 55 // Files that have not been granted default to being denied. |
| 52 bool CanUploadFile(const FilePath& file) { | 56 bool CanUploadFile(const FilePath& file) { |
| 53 return uploadable_files_.find(file) != uploadable_files_.end(); | 57 return uploadable_files_.find(file) != uploadable_files_.end(); |
| 54 } | 58 } |
| 55 | 59 |
| 56 bool has_dom_ui_bindings() const { return has_dom_ui_bindings_; } | 60 bool has_dom_ui_bindings() const { return has_dom_ui_bindings_; } |
| 57 | 61 |
| 62 bool HasNativeViewId(gfx::NativeViewId view_id) { |
| 63 return native_view_ids_.find(view_id) != native_view_ids_.end(); |
| 64 } |
| 65 |
| 58 private: | 66 private: |
| 59 typedef std::map<std::string, bool> SchemeMap; | 67 typedef std::map<std::string, bool> SchemeMap; |
| 60 typedef std::set<FilePath> FileSet; | 68 typedef std::set<FilePath> FileSet; |
| 69 typedef std::set<gfx::NativeViewId> NativeViewIdSet; |
| 61 | 70 |
| 62 // Maps URL schemes to whether permission has been granted or revoked: | 71 // Maps URL schemes to whether permission has been granted or revoked: |
| 63 // |true| means the scheme has been granted. | 72 // |true| means the scheme has been granted. |
| 64 // |false| means the scheme has been revoked. | 73 // |false| means the scheme has been revoked. |
| 65 // If a scheme is not present in the map, then it has never been granted | 74 // If a scheme is not present in the map, then it has never been granted |
| 66 // or revoked. | 75 // or revoked. |
| 67 SchemeMap scheme_policy_; | 76 SchemeMap scheme_policy_; |
| 68 | 77 |
| 69 // The set of files the renderer is permited to upload to the web. | 78 // The set of files the renderer is permited to upload to the web. |
| 70 FileSet uploadable_files_; | 79 FileSet uploadable_files_; |
| 71 | 80 |
| 81 // The set of gfx::NativeViewIds the renderer is permitted to interact with. |
| 82 NativeViewIdSet native_view_ids_; |
| 83 |
| 72 bool has_dom_ui_bindings_; | 84 bool has_dom_ui_bindings_; |
| 73 | 85 |
| 74 DISALLOW_COPY_AND_ASSIGN(SecurityState); | 86 DISALLOW_COPY_AND_ASSIGN(SecurityState); |
| 75 }; | 87 }; |
| 76 | 88 |
| 77 RendererSecurityPolicy::RendererSecurityPolicy() { | 89 RendererSecurityPolicy::RendererSecurityPolicy() { |
| 78 // We know about these schemes and believe them to be safe. | 90 // We know about these schemes and believe them to be safe. |
| 79 RegisterWebSafeScheme(chrome::kHttpScheme); | 91 RegisterWebSafeScheme(chrome::kHttpScheme); |
| 80 RegisterWebSafeScheme(chrome::kHttpsScheme); | 92 RegisterWebSafeScheme(chrome::kHttpsScheme); |
| 81 RegisterWebSafeScheme(chrome::kFtpScheme); | 93 RegisterWebSafeScheme(chrome::kFtpScheme); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 222 |
| 211 state->second->GrantDOMUIBindings(); | 223 state->second->GrantDOMUIBindings(); |
| 212 | 224 |
| 213 // DOM UI bindings need the ability to request chrome-ui URLs. | 225 // DOM UI bindings need the ability to request chrome-ui URLs. |
| 214 state->second->GrantScheme(chrome::kChromeUIScheme); | 226 state->second->GrantScheme(chrome::kChromeUIScheme); |
| 215 | 227 |
| 216 // DOM UI pages can contain links to file:// URLs. | 228 // DOM UI pages can contain links to file:// URLs. |
| 217 state->second->GrantScheme(chrome::kFileScheme); | 229 state->second->GrantScheme(chrome::kFileScheme); |
| 218 } | 230 } |
| 219 | 231 |
| 232 void RendererSecurityPolicy::GrantNativeViewId(int renderer_id, |
| 233 gfx::NativeViewId view_id) { |
| 234 AutoLock lock(lock_); |
| 235 |
| 236 SecurityStateMap::iterator state = security_state_.find(renderer_id); |
| 237 if (state == security_state_.end()) |
| 238 return; |
| 239 |
| 240 state->second->GrantNativeViewId(view_id); |
| 241 } |
| 242 |
| 220 bool RendererSecurityPolicy::CanRequestURL(int renderer_id, const GURL& url) { | 243 bool RendererSecurityPolicy::CanRequestURL(int renderer_id, const GURL& url) { |
| 221 if (!url.is_valid()) | 244 if (!url.is_valid()) |
| 222 return false; // Can't request invalid URLs. | 245 return false; // Can't request invalid URLs. |
| 223 | 246 |
| 224 if (IsWebSafeScheme(url.scheme())) | 247 if (IsWebSafeScheme(url.scheme())) |
| 225 return true; // The scheme has been white-listed for every renderer. | 248 return true; // The scheme has been white-listed for every renderer. |
| 226 | 249 |
| 227 if (IsPseudoScheme(url.scheme())) { | 250 if (IsPseudoScheme(url.scheme())) { |
| 228 // There are a number of special cases for pseudo schemes. | 251 // There are a number of special cases for pseudo schemes. |
| 229 | 252 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 294 |
| 272 bool RendererSecurityPolicy::HasDOMUIBindings(int renderer_id) { | 295 bool RendererSecurityPolicy::HasDOMUIBindings(int renderer_id) { |
| 273 AutoLock lock(lock_); | 296 AutoLock lock(lock_); |
| 274 | 297 |
| 275 SecurityStateMap::iterator state = security_state_.find(renderer_id); | 298 SecurityStateMap::iterator state = security_state_.find(renderer_id); |
| 276 if (state == security_state_.end()) | 299 if (state == security_state_.end()) |
| 277 return false; | 300 return false; |
| 278 | 301 |
| 279 return state->second->has_dom_ui_bindings(); | 302 return state->second->has_dom_ui_bindings(); |
| 280 } | 303 } |
| 304 |
| 305 bool RendererSecurityPolicy::HasNativeViewId(int renderer_id, |
| 306 gfx::NativeViewId view_id) { |
| 307 AutoLock lock(lock_); |
| 308 |
| 309 SecurityStateMap::iterator state = security_state_.find(renderer_id); |
| 310 if (state == security_state_.end()) |
| 311 return false; |
| 312 |
| 313 return state->second->HasNativeViewId(view_id); |
| 314 } |
| OLD | NEW |