Commit message: None
CVE: None
Vulnerability description: None

Project: Chrome

  bool CanRequestURL(const GURL& url) {
    SchemeMap::const_iterator judgment(scheme_policy_.find(url.scheme()));

    if (judgment == scheme_policy_.end())
      return false;  // Unmentioned schemes are disallowed.

    return judgment->second;
  }

Project: Chrome

  bool CanUploadFile(const FilePath& file) {
    return uploadable_files_.find(file) != uploadable_files_.end();
  }

Project: Chrome

bool ChildProcessSecurityPolicy::CanUploadFile(int renderer_id,
                                               const FilePath& file) {
  AutoLock lock(lock_);

  SecurityStateMap::iterator state = security_state_.find(renderer_id);
  if (state == security_state_.end())
    return false;

  return state->second->CanUploadFile(file);
}

Project: Chrome

ChildProcessSecurityPolicy* ChildProcessSecurityPolicy::GetInstance() {
  return Singleton<ChildProcessSecurityPolicy>::get();
}

Project: Chrome

  void GrantBindings(int bindings) {
    enabled_bindings_ |= bindings;
  }

Project: Chrome

void ChildProcessSecurityPolicy::GrantDOMUIBindings(int renderer_id) {
  AutoLock lock(lock_);

  SecurityStateMap::iterator state = security_state_.find(renderer_id);
  if (state == security_state_.end())
    return;

  state->second->GrantBindings(BindingsPolicy::DOM_UI);

  state->second->GrantScheme(chrome::kChromeUIScheme);

  state->second->GrantScheme(chrome::kPrintScheme);

  state->second->GrantScheme(chrome::kFileScheme);
}

Project: Chrome

void ChildProcessSecurityPolicy::GrantInspectElement(int renderer_id) {
  AutoLock lock(lock_);

  SecurityStateMap::iterator state = security_state_.find(renderer_id);
  if (state == security_state_.end())
    return;

  state->second->GrantScheme(chrome::kChromeUIScheme);
}

Project: Chrome

  void GrantReadRawCookies() {
    can_read_raw_cookies_ = true;
  }

Project: Chrome

void ChildProcessSecurityPolicy::GrantReadRawCookies(int renderer_id) {
  AutoLock lock(lock_);

  SecurityStateMap::iterator state = security_state_.find(renderer_id);
  if (state == security_state_.end())
    return;

  state->second->GrantReadRawCookies();
}

Project: Chrome

void ChildProcessSecurityPolicy::GrantRequestURL(
    int renderer_id, const GURL& url) {

  if (!url.is_valid())
    return;  // Can't grant the capability to request invalid URLs.

  if (IsWebSafeScheme(url.scheme()))
    return;  // The scheme has already been white-listed for every renderer.

  if (IsPseudoScheme(url.scheme())) {
    if (url.SchemeIs(chrome::kViewSourceScheme) ||
        url.SchemeIs(chrome::kPrintScheme)) {
      GrantRequestURL(renderer_id, GURL(url.path()));
    }

    return;  // Can't grant the capability to request pseudo schemes.
  }

  {
    AutoLock lock(lock_);
    SecurityStateMap::iterator state = security_state_.find(renderer_id);
    if (state == security_state_.end())
      return;

    state->second->GrantScheme(url.scheme());
  }
}

Project: Chrome

  void GrantScheme(const std::string& scheme) {
    scheme_policy_[scheme] = true;
  }

Project: Chrome

  void GrantUploadFile(const FilePath& file) {
    uploadable_files_.insert(file);
  }

Project: Chrome

bool ChildProcessSecurityPolicy::HasDOMUIBindings(int renderer_id) {
  AutoLock lock(lock_);

  SecurityStateMap::iterator state = security_state_.find(renderer_id);
  if (state == security_state_.end())
    return false;

  return state->second->has_dom_ui_bindings();
}

Project: Chrome

bool ChildProcessSecurityPolicy::HasExtensionBindings(int renderer_id) {
  AutoLock lock(lock_);

  SecurityStateMap::iterator state = security_state_.find(renderer_id);
  if (state == security_state_.end())
    return false;

  return state->second->has_extension_bindings();
}

Project: Chrome

bool ChildProcessSecurityPolicy::IsWebSafeScheme(const std::string& scheme) {
  AutoLock lock(lock_);

  return (web_safe_schemes_.find(scheme) != web_safe_schemes_.end());
}

Project: Chrome

void ChildProcessSecurityPolicy::RegisterPseudoScheme(
    const std::string& scheme) {
  AutoLock lock(lock_);
  DCHECK(pseudo_schemes_.count(scheme) == 0) << "Add schemes at most once.";
  DCHECK(web_safe_schemes_.count(scheme) == 0) <<
      "Psuedo implies not web-safe.";

  pseudo_schemes_.insert(scheme);
}

Project: Chrome

void ChildProcessSecurityPolicy::RegisterWebSafeScheme(
    const std::string& scheme) {
  AutoLock lock(lock_);
  DCHECK(web_safe_schemes_.count(scheme) == 0) << "Add schemes at most once.";
  DCHECK(pseudo_schemes_.count(scheme) == 0) << "Web-safe implies not psuedo.";

  web_safe_schemes_.insert(scheme);
}

Project: Chrome

void ChildProcessSecurityPolicy::Remove(int renderer_id) {
  AutoLock lock(lock_);
  if (!security_state_.count(renderer_id))
    return;  // May be called multiple times.

  delete security_state_[renderer_id];
  security_state_.erase(renderer_id);
}

Project: Chrome

  void RevokeReadRawCookies() {
    can_read_raw_cookies_ = false;
  }

Project: Chrome

void ChildProcessSecurityPolicy::RevokeReadRawCookies(int renderer_id) {
  AutoLock lock(lock_);

  SecurityStateMap::iterator state = security_state_.find(renderer_id);
  if (state == security_state_.end())
    return;

  state->second->RevokeReadRawCookies();
}

Project: Chrome

  void RevokeScheme(const std::string& scheme) {
    scheme_policy_[scheme] = false;
  }

Project: Chrome

  SecurityState()
    : enabled_bindings_(0),
      can_read_raw_cookies_(false) { }

Project: Chrome

  bool can_read_raw_cookies() const {
    return can_read_raw_cookies_;
  }

Project: Chrome

  bool has_dom_ui_bindings() const {
    return BindingsPolicy::is_dom_ui_enabled(enabled_bindings_);
  }

Project: Chrome

  bool has_extension_bindings() const {
    return BindingsPolicy::is_extension_enabled(enabled_bindings_);
  }

Project: Chrome

ChildProcessSecurityPolicy::~ChildProcessSecurityPolicy() {
  web_safe_schemes_.clear();
  pseudo_schemes_.clear();
  STLDeleteContainerPairSecondPointers(security_state_.begin(),
                                       security_state_.end());
  security_state_.clear();
}

Project: Chrome

  ~SecurityState() {
    scheme_policy_.clear();
  }

Project: Chrome

  virtual void SetUp() {
    URLRequest::RegisterProtocolFactory(chrome::kChromeUIScheme,
                                        &URLRequestTestJob::Factory);
  }