Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: chrome/browser/sessions/base_session_service.cc

Issue 10170016: Add info about user agent overrides to WebContents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added SessionService saving Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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;
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
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // If the original URL can't be found, leave it empty.
274 std::string url_spec; 297 std::string url_spec;
275 if (!pickle->ReadString(&iterator, &url_spec)) 298 if (!pickle->ReadString(&iterator, &url_spec))
276 url_spec = std::string(); 299 url_spec = std::string();
277 navigation->set_original_request_url(GURL(url_spec)); 300 navigation->set_original_request_url(GURL(url_spec));
301
302 // Default to not overriding the user agent if we don't have info.
303 bool override_user_agent;
304 if (!pickle->ReadBool(&iterator, &override_user_agent))
305 override_user_agent = false;
306 navigation->set_override_user_agent(override_user_agent);
278 } 307 }
279 308
280 navigation->virtual_url_ = GURL(url_spec); 309 navigation->virtual_url_ = GURL(url_spec);
281 return true; 310 return true;
282 } 311 }
283 312
284 bool BaseSessionService::RestoreSetTabExtensionAppIDCommand( 313 bool BaseSessionService::RestoreSetTabExtensionAppIDCommand(
285 const SessionCommand& command, 314 const SessionCommand& command,
286 SessionID::id_type* tab_id, 315 SessionID::id_type* tab_id,
287 std::string* extension_app_id) { 316 std::string* extension_app_id) {
288 scoped_ptr<Pickle> pickle(command.PayloadAsPickle()); 317 scoped_ptr<Pickle> pickle(command.PayloadAsPickle());
289 if (!pickle.get()) 318 if (!pickle.get())
290 return false; 319 return false;
291 320
292 PickleIterator iterator(*pickle); 321 PickleIterator iterator(*pickle);
293 return pickle->ReadInt(&iterator, tab_id) && 322 return pickle->ReadInt(&iterator, tab_id) &&
294 pickle->ReadString(&iterator, extension_app_id); 323 pickle->ReadString(&iterator, extension_app_id);
295 } 324 }
296 325
326 bool BaseSessionService::RestoreSetTabUserAgentOverrideCommand(
327 const SessionCommand& command,
328 SessionID::id_type* tab_id,
329 std::string* user_agent_override) {
330 scoped_ptr<Pickle> pickle(command.PayloadAsPickle());
331 if (!pickle.get())
332 return false;
333
334 PickleIterator iterator(*pickle);
335 return pickle->ReadInt(&iterator, tab_id) &&
336 pickle->ReadString(&iterator, user_agent_override);
337 }
338
297 bool BaseSessionService::RestoreSetWindowAppNameCommand( 339 bool BaseSessionService::RestoreSetWindowAppNameCommand(
298 const SessionCommand& command, 340 const SessionCommand& command,
299 SessionID::id_type* window_id, 341 SessionID::id_type* window_id,
300 std::string* app_name) { 342 std::string* app_name) {
301 scoped_ptr<Pickle> pickle(command.PayloadAsPickle()); 343 scoped_ptr<Pickle> pickle(command.PayloadAsPickle());
302 if (!pickle.get()) 344 if (!pickle.get())
303 return false; 345 return false;
304 346
305 PickleIterator iterator(*pickle); 347 PickleIterator iterator(*pickle);
306 return pickle->ReadInt(&iterator, window_id) && 348 return pickle->ReadInt(&iterator, window_id) &&
(...skipping 24 matching lines...) Expand all
331 if (profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { 373 if (profile_ && BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) {
332 return BrowserThread::PostTask(BrowserThread::FILE, from_here, task); 374 return BrowserThread::PostTask(BrowserThread::FILE, from_here, task);
333 } else { 375 } else {
334 // Fall back to executing on the main thread if the file thread 376 // 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 377 // has gone away (around shutdown time) or if we're running as
336 // part of a unit test that does not set profile_. 378 // part of a unit test that does not set profile_.
337 task.Run(); 379 task.Run();
338 return true; 380 return true;
339 } 381 }
340 } 382 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698