diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-28 22:28:21 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-28 22:28:21 +0000 |
commit | 0e4e115bb7fd55308c8bb244f1d690bb30fc8f9e (patch) | |
tree | f5f56ededd1149464ae4d2ab5b531f12a4f9015e /webkit/glue/glue_serialize.cc | |
parent | b023ab00b46018893c86cf8cde01dc44b961eef6 (diff) | |
download | chromium_src-0e4e115bb7fd55308c8bb244f1d690bb30fc8f9e.zip chromium_src-0e4e115bb7fd55308c8bb244f1d690bb30fc8f9e.tar.gz chromium_src-0e4e115bb7fd55308c8bb244f1d690bb30fc8f9e.tar.bz2 |
Change CreateHistoryStateForURL so that it does not call into WebKit.
This avoids problems related to using WebKit on the browser UI thread.
In particular, it avoids the need to initialize WebKit in unit tests.
R=sky
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/557044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37451 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/glue_serialize.cc')
-rw-r--r-- | webkit/glue/glue_serialize.cc | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/webkit/glue/glue_serialize.cc b/webkit/glue/glue_serialize.cc index 6cbe39b..b285e12 100644 --- a/webkit/glue/glue_serialize.cc +++ b/webkit/glue/glue_serialize.cc @@ -50,6 +50,10 @@ struct SerializeObject { // 4: Adds support for storing FormData::identifier(). // 5: Adds support for empty FormData // Should be const, but unit tests may modify it. +// +// NOTE: If the version is -1, then the pickle contains only a URL string. +// See CreateHistoryStateForURL. +// int kVersion = 5; // A bunch of convenience functions to read/write to SerializeObjects. @@ -119,6 +123,16 @@ inline bool ReadBoolean(const SerializeObject* obj) { return tmp; } +inline void WriteGURL(const GURL& url, SerializeObject* obj) { + obj->pickle.WriteString(url.possibly_invalid_spec()); +} + +inline GURL ReadGURL(const SerializeObject* obj) { + std::string spec; + obj->pickle.ReadString(&obj->iter, &spec); + return GURL(spec); +} + // Read/WriteString pickle the WebString as <int length><WebUChar* data>. // If length == -1, then the WebString itself is NULL (WebString()). // Otherwise the length is the number of WebUChars (not bytes) in the WebString. @@ -293,6 +307,14 @@ static WebHistoryItem ReadHistoryItem( // See note in WriteHistoryItem. on this. obj->version = ReadInteger(obj); + if (obj->version == -1) { + GURL url = ReadGURL(obj); + WebHistoryItem item; + item.initialize(); + item.setURLString(WebString::fromUTF8(url.possibly_invalid_spec())); + return item; + } + if (obj->version > kVersion || obj->version < 1) return WebHistoryItem(); @@ -382,14 +404,20 @@ void HistoryItemToVersionedString(const WebHistoryItem& item, int version, } std::string CreateHistoryStateForURL(const GURL& url) { - WebHistoryItem item; - item.initialize(); - item.setURLString(UTF8ToUTF16(url.spec())); - - return HistoryItemToString(item); + // We avoid using the WebKit API here, so that we do not need to have WebKit + // initialized before calling this method. Instead, we write a simple + // serialization of the given URL with a dummy version number of -1. This + // will be interpreted by ReadHistoryItem as a request to create a default + // WebHistoryItem. + SerializeObject obj; + WriteInteger(-1, &obj); + WriteGURL(url, &obj); + return obj.GetAsString(); } std::string RemoveFormDataFromHistoryState(const std::string& content_state) { + // TODO(darin): We should avoid using the WebKit API here, so that we do not + // need to have WebKit initialized before calling this method. const WebHistoryItem& item = HistoryItemFromString(content_state, false); if (item.isNull()) { // Couldn't parse the string, return an empty string. |