Chromium Code Reviews| Index: chrome/browser/sessions/base_session_service.cc |
| diff --git a/chrome/browser/sessions/base_session_service.cc b/chrome/browser/sessions/base_session_service.cc |
| index 54ec8ba501498994d9985e1c0d7769891708564e..888c86c0687f2b9edbfee32478ef9c803208331b 100644 |
| --- a/chrome/browser/sessions/base_session_service.cc |
| +++ b/chrome/browser/sessions/base_session_service.cc |
| @@ -187,9 +187,11 @@ SessionCommand* BaseSessionService::CreateUpdateTabNavigationCommand( |
| entry.GetReferrer().url.spec() : std::string()); |
| pickle.WriteInt(entry.GetReferrer().policy); |
| + // Save info required to override the user agent. |
| WriteStringToPickle(pickle, &bytes_written, max_state_size, |
| entry.GetOriginalRequestURL().is_valid() ? |
| entry.GetOriginalRequestURL().spec() : std::string()); |
| + pickle.WriteBool(entry.GetOverrideUserAgent()); |
| return new SessionCommand(command_id, pickle); |
| } |
| @@ -213,6 +215,27 @@ SessionCommand* BaseSessionService::CreateSetTabExtensionAppIDCommand( |
| return new SessionCommand(command_id, pickle); |
| } |
| +SessionCommand* BaseSessionService::CreateSetTabUserAgentOverrideCommand( |
| + SessionID::id_type command_id, |
| + SessionID::id_type tab_id, |
| + const std::string& user_agent_override) { |
| + // Use pickle to handle marshalling. |
| + Pickle pickle; |
| + pickle.WriteInt(tab_id); |
| + |
| + // Enforce a max for the user agent length. They should never be anywhere |
| + // near this size. |
| + static const SessionCommand::size_type max_user_agent_size = |
| + std::numeric_limits<SessionCommand::size_type>::max() - 1024; |
|
tony
2012/05/10 18:40:59
How did you pick this size? Why subtract 1024? M
gone
2012/05/11 15:40:30
Yeah, I copied it from above, which appears to be
|
| + |
| + int bytes_written = 0; |
| + |
| + WriteStringToPickle(pickle, &bytes_written, max_user_agent_size, |
| + user_agent_override); |
| + |
| + return new SessionCommand(command_id, pickle); |
| +} |
| + |
| SessionCommand* BaseSessionService::CreateSetWindowAppNameCommand( |
| SessionID::id_type command_id, |
| SessionID::id_type window_id, |
| @@ -275,6 +298,12 @@ bool BaseSessionService::RestoreUpdateTabNavigationCommand( |
| if (!pickle->ReadString(&iterator, &url_spec)) |
| url_spec = std::string(); |
| navigation->set_original_request_url(GURL(url_spec)); |
| + |
| + // Default to not overriding the user agent if we don't have info. |
| + bool override_user_agent; |
| + if (!pickle->ReadBool(&iterator, &override_user_agent)) |
| + override_user_agent = false; |
| + navigation->set_override_user_agent(override_user_agent); |
| } |
| navigation->virtual_url_ = GURL(url_spec); |
| @@ -294,6 +323,19 @@ bool BaseSessionService::RestoreSetTabExtensionAppIDCommand( |
| pickle->ReadString(&iterator, extension_app_id); |
| } |
| +bool BaseSessionService::RestoreSetTabUserAgentOverrideCommand( |
| + const SessionCommand& command, |
| + SessionID::id_type* tab_id, |
| + std::string* user_agent_override) { |
| + scoped_ptr<Pickle> pickle(command.PayloadAsPickle()); |
| + if (!pickle.get()) |
| + return false; |
| + |
| + PickleIterator iterator(*pickle); |
| + return pickle->ReadInt(&iterator, tab_id) && |
| + pickle->ReadString(&iterator, user_agent_override); |
| +} |
| + |
| bool BaseSessionService::RestoreSetWindowAppNameCommand( |
| const SessionCommand& command, |
| SessionID::id_type* window_id, |