diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-17 18:50:43 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-17 18:50:43 +0000 |
commit | 8fb8eeb9607ccd4c3d447563777beb84e24cbd0a (patch) | |
tree | cbb2c507b1db7479a58aa966ca5699c9b10c8c49 /webkit/appcache | |
parent | 28e0a0e1548565a7acaa7de7f246f476ec66917f (diff) | |
download | chromium_src-8fb8eeb9607ccd4c3d447563777beb84e24cbd0a.zip chromium_src-8fb8eeb9607ccd4c3d447563777beb84e24cbd0a.tar.gz chromium_src-8fb8eeb9607ccd4c3d447563777beb84e24cbd0a.tar.bz2 |
AppCacheExecutableHandlers - parse manifest file and store/retrieve the 'bit' indicating executable.
BUG=101800
Review URL: https://codereview.chromium.org/13881003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194642 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache')
-rw-r--r-- | webkit/appcache/appcache_database.cc | 28 | ||||
-rw-r--r-- | webkit/appcache/appcache_entry.h | 2 | ||||
-rw-r--r-- | webkit/appcache/appcache_interfaces.cc | 18 | ||||
-rw-r--r-- | webkit/appcache/appcache_interfaces.h | 6 | ||||
-rw-r--r-- | webkit/appcache/appcache_update_job.cc | 5 | ||||
-rw-r--r-- | webkit/appcache/appcache_url_request_job.cc | 7 | ||||
-rw-r--r-- | webkit/appcache/manifest_parser.cc | 25 |
7 files changed, 80 insertions, 11 deletions
diff --git a/webkit/appcache/appcache_database.cc b/webkit/appcache/appcache_database.cc index 2ec0968..67767eb 100644 --- a/webkit/appcache/appcache_database.cc +++ b/webkit/appcache/appcache_database.cc @@ -5,6 +5,7 @@ #include "webkit/appcache/appcache_database.h" #include "base/auto_reset.h" +#include "base/command_line.h" #include "base/file_util.h" #include "base/logging.h" #include "base/utf_string_conversions.h" @@ -15,6 +16,8 @@ #include "webkit/appcache/appcache_entry.h" #include "webkit/appcache/appcache_histograms.h" +namespace appcache { + // Schema ------------------------------------------------------------------- namespace { @@ -167,13 +170,14 @@ bool CreateIndex(sql::Connection* db, const IndexInfo& info) { } std::string GetActiveExperimentFlags() { + if (CommandLine::ForCurrentProcess()->HasSwitch(kEnableExecutableHandlers)) + return std::string("executableHandlersEnabled"); return std::string(); } } // anon namespace // AppCacheDatabase ---------------------------------------------------------- -namespace appcache { AppCacheDatabase::GroupRecord::GroupRecord() : group_id(0) { @@ -700,10 +704,19 @@ bool AppCacheDatabase::InsertNamespace( " (cache_id, origin, type, namespace_url, target_url, is_pattern)" " VALUES (?, ?, ?, ?, ?, ?)"; + // Note: quick and dirty storage for the 'executable' bit w/o changing + // schemas, we use the high bit of 'type' field. + int type_with_executable_bit = record->namespace_.type; + if (record->namespace_.is_executable) { + type_with_executable_bit |= 0x8000000; + DCHECK(CommandLine::ForCurrentProcess()->HasSwitch( + kEnableExecutableHandlers)); + } + sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); statement.BindInt64(0, record->cache_id); statement.BindString(1, record->origin.spec()); - statement.BindInt(2, record->namespace_.type); + statement.BindInt(2, type_with_executable_bit); statement.BindString(3, record->namespace_.namespace_url.spec()); statement.BindString(4, record->namespace_.target_url.spec()); statement.BindBool(5, record->namespace_.is_pattern); @@ -947,10 +960,19 @@ void AppCacheDatabase::ReadNamespaceRecord( const sql::Statement* statement, NamespaceRecord* record) { record->cache_id = statement->ColumnInt64(0); record->origin = GURL(statement->ColumnString(1)); - record->namespace_.type = static_cast<NamespaceType>(statement->ColumnInt(2)); + int type_with_executable_bit = statement->ColumnInt(2); record->namespace_.namespace_url = GURL(statement->ColumnString(3)); record->namespace_.target_url = GURL(statement->ColumnString(4)); record->namespace_.is_pattern = statement->ColumnBool(5); + + // Note: quick and dirty storage for the 'executable' bit w/o changing + // schemas, we use the high bit of 'type' field. + record->namespace_.type = static_cast<NamespaceType> + (type_with_executable_bit & 0x7ffffff); + record->namespace_.is_executable = + (type_with_executable_bit & 0x80000000) != 0; + DCHECK(!record->namespace_.is_executable || + CommandLine::ForCurrentProcess()->HasSwitch(kEnableExecutableHandlers)); } void AppCacheDatabase::ReadOnlineWhiteListRecord( diff --git a/webkit/appcache/appcache_entry.h b/webkit/appcache/appcache_entry.h index 8f92533..9092172 100644 --- a/webkit/appcache/appcache_entry.h +++ b/webkit/appcache/appcache_entry.h @@ -24,6 +24,7 @@ class AppCacheEntry { FOREIGN = 1 << 3, FALLBACK = 1 << 4, INTERCEPT = 1 << 5, + EXECUTABLE = 1 << 6, }; AppCacheEntry() @@ -46,6 +47,7 @@ class AppCacheEntry { bool IsForeign() const { return (types_ & FOREIGN) != 0; } bool IsFallback() const { return (types_ & FALLBACK) != 0; } bool IsIntercept() const { return (types_ & INTERCEPT) != 0; } + bool IsExecutable() const { return (types_ & EXECUTABLE) != 0; } int64 response_id() const { return response_id_; } void set_response_id(int64 id) { response_id_ = id; } diff --git a/webkit/appcache/appcache_interfaces.cc b/webkit/appcache/appcache_interfaces.cc index d7941be..b62becc 100644 --- a/webkit/appcache/appcache_interfaces.cc +++ b/webkit/appcache/appcache_interfaces.cc @@ -30,6 +30,8 @@ const char kHttpsScheme[] = "https"; const char kHttpGETMethod[] = "GET"; const char kHttpHEADMethod[] = "HEAD"; +const char kEnableExecutableHandlers[] = "enable-appcache-executable-handlers"; + const base::FilePath::CharType kAppCacheDatabaseName[] = FILE_PATH_LITERAL("Index"); @@ -61,7 +63,8 @@ AppCacheResourceInfo::~AppCacheResourceInfo() { Namespace::Namespace() : type(FALLBACK_NAMESPACE), - is_pattern(false) { + is_pattern(false), + is_executable(false) { } Namespace::Namespace( @@ -69,7 +72,18 @@ Namespace::Namespace( : type(type), namespace_url(url), target_url(target), - is_pattern(is_pattern) { + is_pattern(is_pattern), + is_executable(false) { +} + +Namespace::Namespace( + NamespaceType type, const GURL& url, const GURL& target, + bool is_pattern, bool is_executable) + : type(type), + namespace_url(url), + target_url(target), + is_pattern(is_pattern), + is_executable(is_executable) { } Namespace::~Namespace() { diff --git a/webkit/appcache/appcache_interfaces.h b/webkit/appcache/appcache_interfaces.h index 0dfa4c4..168a8d1 100644 --- a/webkit/appcache/appcache_interfaces.h +++ b/webkit/appcache/appcache_interfaces.h @@ -100,6 +100,8 @@ struct WEBKIT_STORAGE_EXPORT Namespace { Namespace(); // Type is set to FALLBACK_NAMESPACE by default. Namespace(NamespaceType type, const GURL& url, const GURL& target, bool is_pattern); + Namespace(NamespaceType type, const GURL& url, const GURL& target, + bool is_pattern, bool is_executable); ~Namespace(); bool IsMatch(const GURL& url) const; @@ -108,6 +110,7 @@ struct WEBKIT_STORAGE_EXPORT Namespace { GURL namespace_url; GURL target_url; bool is_pattern; + bool is_executable; }; typedef std::vector<Namespace> NamespaceVector; @@ -171,6 +174,9 @@ extern const char kHttpsScheme[]; extern const char kHttpGETMethod[]; extern const char kHttpHEADMethod[]; +// CommandLine flag to turn this experimental feature on. +extern const char kEnableExecutableHandlers[]; + WEBKIT_STORAGE_EXPORT void AddSupportedScheme(const char* scheme); bool IsSchemeSupported(const GURL& url); diff --git a/webkit/appcache/appcache_update_job.cc b/webkit/appcache/appcache_update_job.cc index 2874846..04aaa38 100644 --- a/webkit/appcache/appcache_update_job.cc +++ b/webkit/appcache/appcache_update_job.cc @@ -892,7 +892,10 @@ void AppCacheUpdateJob::BuildUrlFileList(const Manifest& manifest) { manifest.intercept_namespaces; for (std::vector<Namespace>::const_iterator it = intercepts.begin(); it != intercepts.end(); ++it) { - AddUrlToFileList(it->target_url, AppCacheEntry::INTERCEPT); + int flags = AppCacheEntry::INTERCEPT; + if (it->is_executable) + flags |= AppCacheEntry::EXECUTABLE; + AddUrlToFileList(it->target_url, flags); } const std::vector<Namespace>& fallbacks = diff --git a/webkit/appcache/appcache_url_request_job.cc b/webkit/appcache/appcache_url_request_job.cc index 93351ac..153421f 100644 --- a/webkit/appcache/appcache_url_request_job.cc +++ b/webkit/appcache/appcache_url_request_job.cc @@ -8,6 +8,7 @@ #include "base/bind.h" #include "base/bind_helpers.h" +#include "base/command_line.h" #include "base/compiler_specific.h" #include "base/message_loop.h" #include "base/string_util.h" @@ -104,6 +105,12 @@ void AppCacheURLRequestJob::BeginDelivery() { break; case APPCACHED_DELIVERY: + if (entry_.IsExecutable()) { + DCHECK(CommandLine::ForCurrentProcess()->HasSwitch( + kEnableExecutableHandlers)); + // TODO(michaeln): do something different here with + // an AppCacheExecutableHandler. + } AppCacheHistograms::AddAppCacheJobStartDelaySample( base::TimeTicks::Now() - start_time_tick_); request()->net_log().AddEvent( diff --git a/webkit/appcache/manifest_parser.cc b/webkit/appcache/manifest_parser.cc index 3afbad7..0e76e93 100644 --- a/webkit/appcache/manifest_parser.cc +++ b/webkit/appcache/manifest_parser.cc @@ -31,6 +31,7 @@ #include "webkit/appcache/manifest_parser.h" +#include "base/command_line.h" #include "base/i18n/icu_string_conversions.h" #include "base/logging.h" #include "base/utf_string_conversions.h" @@ -60,7 +61,13 @@ enum Mode { INTERCEPT, FALLBACK, ONLINE_WHITELIST, - UNKNOWN, + UNKNOWN_MODE, +}; + +enum InterceptVerb { + RETURN, + EXECUTE, + UNKNOWN_VERB, }; Manifest::Manifest() : online_whitelist_all(false) {} @@ -165,8 +172,8 @@ bool ParseManifest(const GURL& manifest_url, const char* data, int length, } else if (line == L"CHROMIUM-INTERCEPT:") { mode = INTERCEPT; } else if (*(line.end() - 1) == ':') { - mode = UNKNOWN; - } else if (mode == UNKNOWN) { + mode = UNKNOWN_MODE; + } else if (mode == UNKNOWN_MODE) { continue; } else if (line == L"*" && mode == ONLINE_WHITELIST) { manifest.online_whitelist_all = true; @@ -250,8 +257,16 @@ bool ParseManifest(const GURL& manifest_url, const char* data, int length, ++line_p; // Look for a type value we understand, otherwise skip the line. + InterceptVerb verb = UNKNOWN_VERB; std::wstring type(type_start, line_p - type_start); - if (type != L"return") + if (type == L"return") { + verb = RETURN; + } else if (type == L"execute" && + CommandLine::ForCurrentProcess()->HasSwitch( + kEnableExecutableHandlers)) { + verb = EXECUTE; + } + if (verb == UNKNOWN_VERB) continue; // Skip whitespace separating type from the target_url. @@ -280,7 +295,7 @@ bool ParseManifest(const GURL& manifest_url, const char* data, int length, bool is_pattern = HasPatternMatchingAnnotation(line_p, line_end); manifest.intercept_namespaces.push_back( Namespace(INTERCEPT_NAMESPACE, namespace_url, - target_url, is_pattern)); + target_url, is_pattern, verb == EXECUTE)); } else if (mode == FALLBACK) { const wchar_t* line_p = line.c_str(); const wchar_t* line_end = line_p + line.length(); |