| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/in_process_webkit/indexed_db_context.h" | 5 #include "chrome/browser/in_process_webkit/indexed_db_context.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/in_process_webkit/webkit_context.h" | 9 #include "chrome/browser/in_process_webkit/webkit_context.h" |
| 10 #include "googleurl/src/url_util.h" | |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabase.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabase.h" |
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebIDBFactory.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebIDBFactory.h" |
| 14 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" | |
| 15 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 16 #include "webkit/glue/webkit_glue.h" | 14 #include "webkit/glue/webkit_glue.h" |
| 17 | 15 |
| 18 using WebKit::WebIDBDatabase; | 16 using WebKit::WebIDBDatabase; |
| 19 using WebKit::WebIDBFactory; | 17 using WebKit::WebIDBFactory; |
| 20 using WebKit::WebSecurityOrigin; | |
| 21 | 18 |
| 22 const FilePath::CharType IndexedDBContext::kIndexedDBDirectory[] = | 19 const FilePath::CharType IndexedDBContext::kIndexedDBDirectory[] = |
| 23 FILE_PATH_LITERAL("IndexedDB"); | 20 FILE_PATH_LITERAL("IndexedDB"); |
| 24 | 21 |
| 25 const FilePath::CharType IndexedDBContext::kIndexedDBExtension[] = | 22 const FilePath::CharType IndexedDBContext::kIndexedDBExtension[] = |
| 26 FILE_PATH_LITERAL(".indexeddb"); | 23 FILE_PATH_LITERAL(".indexeddb"); |
| 27 | 24 |
| 28 IndexedDBContext::IndexedDBContext(WebKitContext* webkit_context) | 25 IndexedDBContext::IndexedDBContext(WebKitContext* webkit_context) |
| 29 : webkit_context_(webkit_context) { | 26 : webkit_context_(webkit_context) { |
| 30 } | 27 } |
| 31 | 28 |
| 32 IndexedDBContext::~IndexedDBContext() { | 29 IndexedDBContext::~IndexedDBContext() { |
| 33 } | 30 } |
| 34 | 31 |
| 35 WebIDBFactory* IndexedDBContext::GetIDBFactory() { | 32 WebIDBFactory* IndexedDBContext::GetIDBFactory() { |
| 36 if (!idb_factory_.get()) | 33 if (!idb_factory_.get()) |
| 37 idb_factory_.reset(WebIDBFactory::create()); | 34 idb_factory_.reset(WebIDBFactory::create()); |
| 38 DCHECK(idb_factory_.get()); | 35 DCHECK(idb_factory_.get()); |
| 39 return idb_factory_.get(); | 36 return idb_factory_.get(); |
| 40 } | 37 } |
| 41 | 38 |
| 42 FilePath IndexedDBContext::GetIndexedDBFilePath( | 39 FilePath IndexedDBContext::GetIndexedDBFilePath( |
| 43 const string16& database_name, | 40 const string16& origin_id) const { |
| 44 const WebSecurityOrigin& origin) const { | |
| 45 FilePath storage_dir = webkit_context_->data_path().Append( | 41 FilePath storage_dir = webkit_context_->data_path().Append( |
| 46 kIndexedDBDirectory); | 42 kIndexedDBDirectory); |
| 47 FilePath::StringType id = webkit_glue::WebStringToFilePathString( | 43 FilePath::StringType id = webkit_glue::WebStringToFilePathString(origin_id); |
| 48 WebIDBFactory::databaseFileName(database_name, origin)); | 44 return storage_dir.Append(id.append(kIndexedDBExtension)); |
| 49 return storage_dir.Append(id); | |
| 50 } | 45 } |
| 51 | |
| 52 // static | |
| 53 bool IndexedDBContext::SplitIndexedDBFileName( | |
| 54 const FilePath& file_name, | |
| 55 std::string* database_name, | |
| 56 WebSecurityOrigin* security_origin) { | |
| 57 FilePath::StringType base_name = | |
| 58 file_name.BaseName().RemoveExtension().value(); | |
| 59 size_t db_name_separator = base_name.find(FILE_PATH_LITERAL("@")); | |
| 60 if (db_name_separator == FilePath::StringType::npos || | |
| 61 db_name_separator == 0) { | |
| 62 return false; | |
| 63 } | |
| 64 | |
| 65 *security_origin = | |
| 66 WebSecurityOrigin::createFromDatabaseIdentifier( | |
| 67 webkit_glue::FilePathStringToWebString( | |
| 68 base_name.substr(0, db_name_separator))); | |
| 69 #if defined(OS_POSIX) | |
| 70 std::string name = base_name.substr(db_name_separator + 1); | |
| 71 #elif defined(OS_WIN) | |
| 72 std::string name = WideToUTF8(base_name.substr(db_name_separator + 1)); | |
| 73 #endif | |
| 74 url_canon::RawCanonOutputT<char16> output; | |
| 75 url_util::DecodeURLEscapeSequences(name.c_str(), name.length(), &output); | |
| 76 *database_name = UTF16ToUTF8(string16(output.data(), output.length())); | |
| 77 return true; | |
| 78 } | |
| OLD | NEW |