diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-18 19:26:37 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-18 19:26:37 +0000 |
commit | f45c5f3d74273e913c62598fcbde35e20924ab50 (patch) | |
tree | 6364e206042679e527802f2214132138a731e826 /chrome | |
parent | 55410d7379f605f828d9845ee1ae8f62c0b0b145 (diff) | |
download | chromium_src-f45c5f3d74273e913c62598fcbde35e20924ab50.zip chromium_src-f45c5f3d74273e913c62598fcbde35e20924ab50.tar.gz chromium_src-f45c5f3d74273e913c62598fcbde35e20924ab50.tar.bz2 |
Cleanup of v8 extension stuff. Playback extension is only used in chrome, so move it to chrome\renderer and all of its associated switches to chrome. GC extension is only used by webkit\support, so move it there. The other two profiler extensions aren't used, so remove them.
Review URL: https://chromiumcodereview.appspot.com/10117022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132841 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chrome_content_browser_client.cc | 3 | ||||
-rw-r--r-- | chrome/chrome_renderer.gypi | 2 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 17 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 3 | ||||
-rw-r--r-- | chrome/renderer/chrome_content_renderer_client.cc | 14 | ||||
-rw-r--r-- | chrome/renderer/playback_extension.cc | 48 | ||||
-rw-r--r-- | chrome/renderer/playback_extension.h | 33 |
7 files changed, 116 insertions, 4 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 707ca7a..ee71f09 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -770,7 +770,9 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( switches::kExperimentalSpellcheckerFeatures, switches::kMemoryProfiling, switches::kMessageLoopHistogrammer, + switches::kNoJsRandomness, switches::kNoRunningInsecureContent, + switches::kPlaybackMode, switches::kPpapiFlashArgs, switches::kPpapiFlashInProcess, switches::kPpapiFlashPath, @@ -778,6 +780,7 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( switches::kProfilingAtStart, switches::kProfilingFile, switches::kProfilingFlush, + switches::kRecordMode, switches::kSilentDumpOnDCHECK, switches::kWhitelistedExtensionID, }; diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index f9ce51d..99bd387 100644 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -131,6 +131,8 @@ 'renderer/net/predictor_queue.h', 'renderer/net/renderer_net_predictor.cc', 'renderer/net/renderer_net_predictor.h', + 'renderer/playback_extension.cc', + 'renderer/playback_extension.h', 'renderer/resource_bundle_source_map.cc', 'renderer/resource_bundle_source_map.h', 'renderer/resources/extensions/apitest.js', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 51b273b..bffa62f 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -854,6 +854,13 @@ const char kNoExperiments[] = "no-experiments"; // you're for some reason tempted to pass them both. const char kNoFirstRun[] = "no-first-run"; +// Support a separate switch that enables the v8 playback extension. +// The extension causes javascript calls to Date.now() and Math.random() +// to return consistent values, such that subsequent loads of the same +// page will result in consistent js-generated data and XHR requests. +// Pages may still be able to generate inconsistent data from plugins. +const char kNoJsRandomness[] = "no-js-randomness"; + // Starts the browser outside of managed mode. const char kNoManaged[] = "no-managed"; @@ -937,6 +944,10 @@ const char kPackExtensionKey[] = "pack-extension-key"; // Specifies the path to the user data folder for the parent profile. const char kParentProfile[] = "parent-profile"; +// Read previously recorded data from the cache. Only cached data is read. +// See kRecordMode. +const char kPlaybackMode[] = "playback-mode"; + // Controls the PPAPI Flash field trial. Valid values are defined below. If an // unknown value is supplied on the command line, the switch is ignored. // TODO(yzshen): Remove this flag when the field trial is over. @@ -1040,6 +1051,12 @@ const char kProxyServer[] = "proxy-server"; // NOTE: This is only implemented for Views. const char kPurgeMemoryButton[] = "purge-memory-button"; +// Chrome supports a playback and record mode. Record mode saves *everything* +// to the cache. Playback mode reads data exclusively from the cache. This +// allows us to record a session into the cache and then replay it at will. +// See also kPlaybackMode. +const char kRecordMode[] = "record-mode"; + // Reloads pages that have been killed when they are next focused by the user. const char kReloadKilledTabs[] = "reload-killed-tabs"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index abe4977..f00f873 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -232,6 +232,7 @@ extern const char kNoDisplayingInsecureContent[]; extern const char kNoEvents[]; extern const char kNoExperiments[]; extern const char kNoFirstRun[]; +extern const char kNoJsRandomness[]; extern const char kNoManaged[]; extern const char kNoProxyServer[]; extern const char kNoPings[]; @@ -255,6 +256,7 @@ extern const char kOrganicInstall[]; extern const char kPackExtension[]; extern const char kPackExtensionKey[]; extern const char kParentProfile[]; +extern const char kPlaybackMode[]; extern const char kPpapiFlashFieldTrial[]; extern const char kPpapiFlashFieldTrialDisableByDefault[]; extern const char kPpapiFlashFieldTrialEnableByDefault[]; @@ -282,6 +284,7 @@ extern const char kProxyBypassList[]; extern const char kProxyPacUrl[]; extern const char kProxyServer[]; extern const char kPurgeMemoryButton[]; +extern const char kRecordMode[]; extern const char kReloadKilledTabs[]; extern const char kRemoteDebuggingFrontend[]; extern const char kRendererPrintPreview[]; diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index 9b9fb6c..cd7a2e9 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -47,6 +47,7 @@ #include "chrome/renderer/net/renderer_net_predictor.h" #include "chrome/renderer/page_click_tracker.h" #include "chrome/renderer/page_load_histograms.h" +#include "chrome/renderer/playback_extension.h" #include "chrome/renderer/plugins/plugin_placeholder.h" #include "chrome/renderer/plugins/plugin_uma.h" #include "chrome/renderer/prerender/prerender_dispatcher.h" @@ -179,12 +180,17 @@ void ChromeContentRendererClient::RenderThreadStarted() { if (search_extension) thread->RegisterExtension(search_extension); - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableBenchmarking)) + CommandLine* command_line = CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kEnableBenchmarking)) thread->RegisterExtension(extensions_v8::BenchmarkingExtension::Get()); - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableIPCFuzzing)) { + if (command_line->HasSwitch(switches::kPlaybackMode) || + command_line->HasSwitch(switches::kRecordMode) || + command_line->HasSwitch(switches::kNoJsRandomness)) { + thread->RegisterExtension(extensions_v8::PlaybackExtension::Get()); + } + + if (command_line->HasSwitch(switches::kEnableIPCFuzzing)) { thread->GetChannel()->set_outgoing_message_filter(LoadExternalIPCFuzzer()); } // chrome:, chrome-devtools:, and chrome-internal: pages should not be diff --git a/chrome/renderer/playback_extension.cc b/chrome/renderer/playback_extension.cc new file mode 100644 index 0000000..5f9f017 --- /dev/null +++ b/chrome/renderer/playback_extension.cc @@ -0,0 +1,48 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/renderer/playback_extension.h" + +#include "v8/include/v8.h" + +const char kPlaybackExtensionName[] = "v8/PlaybackMode"; + +namespace extensions_v8 { + +v8::Extension* PlaybackExtension::Get() { + v8::Extension* extension = new v8::Extension( + kPlaybackExtensionName, + "(function () {" + " var orig_date = Date;" + " var x = 0;" + " var time_seed = 1204251968254;" + " Math.random = function() {" + " x += .1;" + " return (x % 1);" + " };" + " Date = function() {" + " if (this instanceof Date) {" + " switch (arguments.length) {" + " case 0: return new orig_date(time_seed += 50);" + " case 1: return new orig_date(arguments[0]);" + " default: return new orig_date(arguments[0], arguments[1]," + " arguments.length >= 3 ? arguments[2] : 1," + " arguments.length >= 4 ? arguments[3] : 0," + " arguments.length >= 5 ? arguments[4] : 0," + " arguments.length >= 6 ? arguments[5] : 0," + " arguments.length >= 7 ? arguments[6] : 0);" + " }" + " }" + " return new Date().toString();" + " };" + " Date.__proto__ = orig_date;" + " Date.prototype.constructor = Date;" + " orig_date.now = function() {" + " return new Date().getTime();" + " };" + "})()"); + return extension; +} + +} // namespace extensions_v8 diff --git a/chrome/renderer/playback_extension.h b/chrome/renderer/playback_extension.h new file mode 100644 index 0000000..6d2a427 --- /dev/null +++ b/chrome/renderer/playback_extension.h @@ -0,0 +1,33 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_RENDERER_PLAYBACK_EXTENSION_H_ +#define CHROME_RENDERER_PLAYBACK_EXTENSION_H_ +#pragma once + +namespace v8 { +class Extension; +} + +namespace extensions_v8 { + +// Inject code which overrides a few common JS functions for implementing +// randomness. In order to implement effective record & playback of +// websites, it is important that the URLs not change. Many popular web +// based apps use randomness in URLs to unique-ify urls for proxies. +// Unfortunately, this breaks playback. +// To work around this, we take the two most common client-side randomness +// generators and make them constant. They really need to be constant +// (rather than a constant seed followed by constant change) +// because the playback mode wants flexibility in how it plays them back +// and cannot always guarantee that requests for randomness are played back +// in exactly the same order in which they were recorded. +class PlaybackExtension { + public: + static v8::Extension* Get(); +}; + +} // namespace extensions_v8 + +#endif // CHROME_RENDERER_PLAYBACK_EXTENSION_H_ |