| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "chrome/browser/page_state.h" | 8 #include "chrome/browser/page_state.h" |
| 9 #include "chrome/common/json_value_serializer.h" | 9 #include "chrome/common/json_value_serializer.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 url_parse::Component queryComp, keyComp, valueComp; | 21 url_parse::Component queryComp, keyComp, valueComp; |
| 22 queryComp.len = static_cast<int>(query_string.size()); | 22 queryComp.len = static_cast<int>(query_string.size()); |
| 23 while (url_parse::ExtractQueryKeyValue(query_string.c_str(), &queryComp, | 23 while (url_parse::ExtractQueryKeyValue(query_string.c_str(), &queryComp, |
| 24 &keyComp, &valueComp)) { | 24 &keyComp, &valueComp)) { |
| 25 if (keyComp.is_nonempty()) { | 25 if (keyComp.is_nonempty()) { |
| 26 std::string escaped = query_string.substr(valueComp.begin, | 26 std::string escaped = query_string.substr(valueComp.begin, |
| 27 valueComp.len); | 27 valueComp.len); |
| 28 // We know that the query string is UTF-8 since it's an internal URL. | 28 // We know that the query string is UTF-8 since it's an internal URL. |
| 29 std::wstring value = UTF8ToWide( | 29 std::wstring value = UTF8ToWide( |
| 30 UnescapeURLComponent(escaped, UnescapeRule::REPLACE_PLUS_WITH_SPACE)); | 30 UnescapeURLComponent(escaped, UnescapeRule::REPLACE_PLUS_WITH_SPACE)); |
| 31 state_->Set(UTF8ToWide(query_string.substr(keyComp.begin, keyComp.len)), | 31 state_->Set(UTF8ToUTF16(query_string.substr(keyComp.begin, keyComp.len)), |
| 32 new StringValue(value)); | 32 new StringValue(value)); |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 void PageState::InitWithBytes(const std::string& bytes) { | 37 void PageState::InitWithBytes(const std::string& bytes) { |
| 38 // Reset our state. We create a new empty one just in case | 38 // Reset our state. We create a new empty one just in case |
| 39 // deserialization fails | 39 // deserialization fails |
| 40 state_.reset(new DictionaryValue); | 40 state_.reset(new DictionaryValue); |
| 41 | 41 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 52 } | 52 } |
| 53 | 53 |
| 54 void PageState::GetByteRepresentation(std::string* out) const { | 54 void PageState::GetByteRepresentation(std::string* out) const { |
| 55 JSONStringValueSerializer serializer(out); | 55 JSONStringValueSerializer serializer(out); |
| 56 if (!serializer.Serialize(*state_)) | 56 if (!serializer.Serialize(*state_)) |
| 57 NOTREACHED(); | 57 NOTREACHED(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void PageState::SetProperty(const std::wstring& key, | 60 void PageState::SetProperty(const std::wstring& key, |
| 61 const std::wstring& value) { | 61 const std::wstring& value) { |
| 62 state_->Set(key, new StringValue(value)); | 62 state_->Set(WideToUTF16Hack(key), new StringValue(value)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 bool PageState::GetProperty(const std::wstring& key, std::wstring* value) const
{ | 65 bool PageState::GetProperty(const std::wstring& wkey, |
| 66 std::wstring* value) const { |
| 67 string16 key(WideToUTF16(wkey)); |
| 66 if (state_->HasKey(key)) { | 68 if (state_->HasKey(key)) { |
| 67 Value* v; | 69 Value* v; |
| 68 state_->Get(key, &v); | 70 state_->Get(key, &v); |
| 69 if (v->GetType() == Value::TYPE_STRING) { | 71 if (v->GetType() == Value::TYPE_STRING) { |
| 70 StringValue* sv = reinterpret_cast<StringValue*>(v); | 72 StringValue* sv = reinterpret_cast<StringValue*>(v); |
| 71 sv->GetAsString(value); | 73 sv->GetAsString(value); |
| 72 return true; | 74 return true; |
| 73 } | 75 } |
| 74 } | 76 } |
| 75 return false; | 77 return false; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 98 } | 100 } |
| 99 return false; | 101 return false; |
| 100 } | 102 } |
| 101 | 103 |
| 102 PageState* PageState::Copy() const { | 104 PageState* PageState::Copy() const { |
| 103 PageState* copy = new PageState(); | 105 PageState* copy = new PageState(); |
| 104 if (state_.get()) | 106 if (state_.get()) |
| 105 copy->state_.reset(static_cast<DictionaryValue*>(state_->DeepCopy())); | 107 copy->state_.reset(static_cast<DictionaryValue*>(state_->DeepCopy())); |
| 106 return copy; | 108 return copy; |
| 107 } | 109 } |
| OLD | NEW |