OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sessions/base_session_service.h" | 5 #include "chrome/browser/sessions/base_session_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 | 180 |
181 pickle.WriteInt(entry.GetTransitionType()); | 181 pickle.WriteInt(entry.GetTransitionType()); |
182 int type_mask = entry.GetHasPostData() ? TabNavigation::HAS_POST_DATA : 0; | 182 int type_mask = entry.GetHasPostData() ? TabNavigation::HAS_POST_DATA : 0; |
183 pickle.WriteInt(type_mask); | 183 pickle.WriteInt(type_mask); |
184 | 184 |
185 WriteStringToPickle(pickle, &bytes_written, max_state_size, | 185 WriteStringToPickle(pickle, &bytes_written, max_state_size, |
186 entry.GetReferrer().url.is_valid() ? | 186 entry.GetReferrer().url.is_valid() ? |
187 entry.GetReferrer().url.spec() : std::string()); | 187 entry.GetReferrer().url.spec() : std::string()); |
188 pickle.WriteInt(entry.GetReferrer().policy); | 188 pickle.WriteInt(entry.GetReferrer().policy); |
189 | 189 |
190 // Save info required to override the user agent. | |
190 WriteStringToPickle(pickle, &bytes_written, max_state_size, | 191 WriteStringToPickle(pickle, &bytes_written, max_state_size, |
191 entry.GetOriginalRequestURL().is_valid() ? | 192 entry.GetOriginalRequestURL().is_valid() ? |
192 entry.GetOriginalRequestURL().spec() : std::string()); | 193 entry.GetOriginalRequestURL().spec() : std::string()); |
194 pickle.WriteBool(entry.GetOverrideUserAgent()); | |
193 | 195 |
194 return new SessionCommand(command_id, pickle); | 196 return new SessionCommand(command_id, pickle); |
195 } | 197 } |
196 | 198 |
197 SessionCommand* BaseSessionService::CreateSetTabExtensionAppIDCommand( | 199 SessionCommand* BaseSessionService::CreateSetTabExtensionAppIDCommand( |
198 SessionID::id_type command_id, | 200 SessionID::id_type command_id, |
199 SessionID::id_type tab_id, | 201 SessionID::id_type tab_id, |
200 const std::string& extension_id) { | 202 const std::string& extension_id) { |
201 // Use pickle to handle marshalling. | 203 // Use pickle to handle marshalling. |
202 Pickle pickle; | 204 Pickle pickle; |
203 pickle.WriteInt(tab_id); | 205 pickle.WriteInt(tab_id); |
204 | 206 |
205 // Enforce a max for ids. They should never be anywhere near this size. | 207 // Enforce a max for ids. They should never be anywhere near this size. |
206 static const SessionCommand::size_type max_id_size = | 208 static const SessionCommand::size_type max_id_size = |
207 std::numeric_limits<SessionCommand::size_type>::max() - 1024; | 209 std::numeric_limits<SessionCommand::size_type>::max() - 1024; |
208 | 210 |
209 int bytes_written = 0; | 211 int bytes_written = 0; |
210 | 212 |
211 WriteStringToPickle(pickle, &bytes_written, max_id_size, extension_id); | 213 WriteStringToPickle(pickle, &bytes_written, max_id_size, extension_id); |
212 | 214 |
213 return new SessionCommand(command_id, pickle); | 215 return new SessionCommand(command_id, pickle); |
214 } | 216 } |
215 | 217 |
218 SessionCommand* BaseSessionService::CreateSetTabUserAgentOverrideCommand( | |
219 SessionID::id_type command_id, | |
220 SessionID::id_type tab_id, | |
221 const std::string& user_agent_override) { | |
222 // Use pickle to handle marshalling. | |
223 Pickle pickle; | |
224 pickle.WriteInt(tab_id); | |
225 | |
226 // Enforce a max for the user agent length. They should never be anywhere | |
227 // near this size. | |
228 static const SessionCommand::size_type max_user_agent_size = | |
229 std::numeric_limits<SessionCommand::size_type>::max() - 1024; | |
230 | |
231 int bytes_written = 0; | |
232 | |
233 WriteStringToPickle(pickle, &bytes_written, max_user_agent_size, | |
234 user_agent_override); | |
235 | |
236 return new SessionCommand(command_id, pickle); | |
237 } | |
238 | |
216 SessionCommand* BaseSessionService::CreateSetWindowAppNameCommand( | 239 SessionCommand* BaseSessionService::CreateSetWindowAppNameCommand( |
217 SessionID::id_type command_id, | 240 SessionID::id_type command_id, |
218 SessionID::id_type window_id, | 241 SessionID::id_type window_id, |
219 const std::string& app_name) { | 242 const std::string& app_name) { |
220 // Use pickle to handle marshalling. | 243 // Use pickle to handle marshalling. |
221 Pickle pickle; | 244 Pickle pickle; |
222 pickle.WriteInt(window_id); | 245 pickle.WriteInt(window_id); |
223 | 246 |
224 // Enforce a max for ids. They should never be anywhere near this size. | 247 // Enforce a max for ids. They should never be anywhere near this size. |
225 static const SessionCommand::size_type max_id_size = | 248 static const SessionCommand::size_type max_id_size = |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 int policy_int; | 286 int policy_int; |
264 WebReferrerPolicy policy; | 287 WebReferrerPolicy policy; |
265 if (pickle->ReadInt(&iterator, &policy_int)) | 288 if (pickle->ReadInt(&iterator, &policy_int)) |
266 policy = static_cast<WebReferrerPolicy>(policy_int); | 289 policy = static_cast<WebReferrerPolicy>(policy_int); |
267 else | 290 else |
268 policy = WebKit::WebReferrerPolicyDefault; | 291 policy = WebKit::WebReferrerPolicyDefault; |
269 navigation->referrer_ = content::Referrer( | 292 navigation->referrer_ = content::Referrer( |
270 referrer_spec.empty() ? GURL() : GURL(referrer_spec), | 293 referrer_spec.empty() ? GURL() : GURL(referrer_spec), |
271 policy); | 294 policy); |
272 | 295 |
273 // If the original URL can't be found, leave it empty. | 296 // Default to not overriding the user agent if we don't have enough info. |
274 std::string url_spec; | 297 std::string url_spec; |
275 if (!pickle->ReadString(&iterator, &url_spec)) | 298 bool override_user_agent; |
299 if (!pickle->ReadString(&iterator, &url_spec) || | |
300 !pickle->ReadBool(&iterator, &override_user_agent)) { | |
276 url_spec = std::string(); | 301 url_spec = std::string(); |
sky
2012/04/23 23:30:15
I think you want the override_user_agent in an els
gone
2012/04/24 09:30:37
Current version splits it off.
| |
302 override_user_agent = false; | |
303 } | |
277 navigation->set_original_request_url(GURL(url_spec)); | 304 navigation->set_original_request_url(GURL(url_spec)); |
305 navigation->set_override_user_agent(override_user_agent); | |
278 } | 306 } |
279 | 307 |
280 navigation->virtual_url_ = GURL(url_spec); | 308 navigation->virtual_url_ = GURL(url_spec); |
281 return true; | 309 return true; |
282 } | 310 } |
283 | 311 |
284 bool BaseSessionService::RestoreSetTabExtensionAppIDCommand( | 312 bool BaseSessionService::RestoreSetTabExtensionAppIDCommand( |
285 const SessionCommand& command, | 313 const SessionCommand& command, |
286 SessionID::id_type* tab_id, | 314 SessionID::id_type* tab_id, |
287 std::string* extension_app_id) { | 315 std::string* extension_app_id) { |
288 scoped_ptr<Pickle> pickle(command.PayloadAsPickle()); | 316 scoped_ptr<Pickle> pickle(command.PayloadAsPickle()); |
289 if (!pickle.get()) | 317 if (!pickle.get()) |
290 return false; | 318 return false; |
291 | 319 |
292 PickleIterator iterator(*pickle); | 320 PickleIterator iterator(*pickle); |
293 return pickle->ReadInt(&iterator, tab_id) && | 321 return pickle->ReadInt(&iterator, tab_id) && |
294 pickle->ReadString(&iterator, extension_app_id); | 322 pickle->ReadString(&iterator, extension_app_id); |
295 } | 323 } |
296 | 324 |
325 bool BaseSessionService::RestoreSetTabUserAgentOverrideCommand( | |
326 const SessionCommand& command, | |
327 SessionID::id_type* tab_id, | |
328 std::string* user_agent_override) { | |
329 scoped_ptr<Pickle> pickle(command.PayloadAsPickle()); | |
330 if (!pickle.get()) | |
331 return false; | |
332 | |
333 PickleIterator iterator(*pickle); | |
334 return pickle->ReadInt(&iterator, tab_id) && | |
335 pickle->ReadString(&iterator, user_agent_override); | |
336 } | |
337 | |
297 bool BaseSessionService::RestoreSetWindowAppNameCommand( | 338 bool BaseSessionService::RestoreSetWindowAppNameCommand( |
298 const SessionCommand& command, | 339 const SessionCommand& command, |
299 SessionID::id_type* window_id, | 340 SessionID::id_type* window_id, |
300 std::string* app_name) { | 341 std::string* app_name) { |
301 scoped_ptr<Pickle> pickle(command.PayloadAsPickle()); | 342 scoped_ptr<Pickle> pickle(command.PayloadAsPickle()); |
302 if (!pickle.get()) | 343 if (!pickle.get()) |
303 return false; | 344 return false; |
304 | 345 |
305 PickleIterator iterator(*pickle); | 346 PickleIterator iterator(*pickle); |
306 return pickle->ReadInt(&iterator, window_id) && | 347 return pickle->ReadInt(&iterator, window_id) && |
(...skipping 24 matching lines...) Expand all Loading... | |
331 if (profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { | 372 if (profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { |
332 return BrowserThread::PostTask(BrowserThread::FILE, from_here, task); | 373 return BrowserThread::PostTask(BrowserThread::FILE, from_here, task); |
333 } else { | 374 } else { |
334 // Fall back to executing on the main thread if the file thread | 375 // Fall back to executing on the main thread if the file thread |
335 // has gone away (around shutdown time) or if we're running as | 376 // has gone away (around shutdown time) or if we're running as |
336 // part of a unit test that does not set profile_. | 377 // part of a unit test that does not set profile_. |
337 task.Run(); | 378 task.Run(); |
338 return true; | 379 return true; |
339 } | 380 } |
340 } | 381 } |
OLD | NEW |