cef/libcef/origin_whitelist_impl.cc
Marshall Greenblatt 6b134b4def - Add CefSettings.local_storage_quota and session_storage_quota options for setting localStorage and sessionStorage quota limits respectively (issue #348).
- Add Cef*Storage() functions and CefStorageVisitor interface for accessing localStorage and sessionStorage data via the native API (issue #361).
- Add a "cache_path" command-line flag option to cef_unittests for running the unit tests with a cache path value (issue #368).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@302 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
2011-10-06 13:34:47 +00:00

105 lines
3.4 KiB
C++

// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "include/cef.h"
#include "cef_context.h"
#include "cef_thread.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
using WebKit::WebSecurityPolicy;
using WebKit::WebString;
bool CefAddCrossOriginWhitelistEntry(const CefString& source_origin,
const CefString& target_protocol,
const CefString& target_domain,
bool allow_target_subdomains)
{
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED();
return false;
}
std::string source_url = source_origin;
GURL gurl = GURL(source_url);
if (gurl.is_empty() || !gurl.is_valid()) {
NOTREACHED() << "Invalid source_origin URL: " << source_url;
return false;
}
if (CefThread::CurrentlyOn(CefThread::UI)) {
std::string target_protocol_str = target_protocol;
std::string target_domain_str = target_domain;
WebSecurityPolicy::addOriginAccessWhitelistEntry(
gurl,
WebString::fromUTF8(target_protocol_str),
WebString::fromUTF8(target_domain_str),
allow_target_subdomains);
} else {
CefThread::PostTask(CefThread::UI, FROM_HERE,
NewRunnableFunction(&CefAddCrossOriginWhitelistEntry, source_origin,
target_protocol, target_domain,
allow_target_subdomains));
}
return true;
}
bool CefRemoveCrossOriginWhitelistEntry(const CefString& source_origin,
const CefString& target_protocol,
const CefString& target_domain,
bool allow_target_subdomains)
{
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED();
return false;
}
std::string source_url = source_origin;
GURL gurl = GURL(source_url);
if (gurl.is_empty() || !gurl.is_valid()) {
NOTREACHED() << "Invalid source_origin URL: " << source_url;
return false;
}
if (CefThread::CurrentlyOn(CefThread::UI)) {
std::string target_protocol_str = target_protocol;
std::string target_domain_str = target_domain;
WebSecurityPolicy::removeOriginAccessWhitelistEntry(
gurl,
WebString::fromUTF8(target_protocol_str),
WebString::fromUTF8(target_domain_str),
allow_target_subdomains);
} else {
CefThread::PostTask(CefThread::UI, FROM_HERE,
NewRunnableFunction(&CefRemoveCrossOriginWhitelistEntry, source_origin,
target_protocol, target_domain,
allow_target_subdomains));
}
return true;
}
bool CefClearCrossOriginWhitelist()
{
// Verify that the context is in a valid state.
if (!CONTEXT_STATE_VALID()) {
NOTREACHED();
return false;
}
if (CefThread::CurrentlyOn(CefThread::UI)) {
WebSecurityPolicy::resetOriginAccessWhitelists();
} else {
CefThread::PostTask(CefThread::UI, FROM_HERE,
NewRunnableFunction(&CefClearCrossOriginWhitelist));
}
return true;
}