diff options
author | mhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-23 18:26:51 +0000 |
---|---|---|
committer | mhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-23 18:26:51 +0000 |
commit | 98d7127b558c6de8121ed9ff8c299b30afb6143b (patch) | |
tree | 0748804eee8744a5642905ac1c4b496f87fc85e6 | |
parent | 5e34bc403af2328e80765406eace2f49f63e7d79 (diff) | |
download | chromium_src-98d7127b558c6de8121ed9ff8c299b30afb6143b.zip chromium_src-98d7127b558c6de8121ed9ff8c299b30afb6143b.tar.gz chromium_src-98d7127b558c6de8121ed9ff8c299b30afb6143b.tar.bz2 |
Introduce WebScriptController for script related methods.
Made it into a class with static methods.
BUG=24602
TEST=Compiled Webkit/Chromium and Try Bot'd
Review URL: http://codereview.chromium.org/308015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29912 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/renderer/render_thread.cc | 64 | ||||
-rw-r--r-- | chrome/test/render_view_test.cc | 13 | ||||
-rw-r--r-- | webkit/api/public/WebScriptController.h | 44 | ||||
-rw-r--r-- | webkit/api/src/WebScriptController.cpp | 23 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.cc | 3 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_main.cc | 10 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.h | 8 |
7 files changed, 97 insertions, 68 deletions
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index e77e3af..ed2c5dd 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -70,6 +70,7 @@ using WebKit::WebCache; using WebKit::WebCrossOriginPreflightResultCache; using WebKit::WebFontCache; using WebKit::WebSecurityPolicy; +using WebKit::WebScriptController; using WebKit::WebString; using WebKit::WebStorageEventDispatcher; using WebKit::WebView; @@ -442,7 +443,7 @@ void RenderThread::EnsureWebKitInitialized() { webkit_client_.reset(new RendererWebKitClientImpl); WebKit::initialize(webkit_client_.get()); - WebKit::enableV8SingleThreadMode(); + WebScriptController::enableV8SingleThreadMode(); // chrome: pages should not be accessible by normal content, and should // also be unable to script anything but themselves (to help limit the damage @@ -458,43 +459,54 @@ void RenderThread::EnsureWebKitInitialized() { #if defined(OS_WIN) // We don't yet support Gears on non-Windows, so don't tell pages that we do. - WebKit::registerExtension(extensions_v8::GearsExtension::Get()); + WebScriptController::registerExtension(extensions_v8::GearsExtension::Get()); #endif - WebKit::registerExtension(extensions_v8::IntervalExtension::Get()); - WebKit::registerExtension(extensions_v8::LoadTimesExtension::Get()); - WebKit::registerExtension(extensions_v8::ExternalExtension::Get()); + WebScriptController::registerExtension( + extensions_v8::IntervalExtension::Get()); + WebScriptController::registerExtension( + extensions_v8::LoadTimesExtension::Get()); + WebScriptController::registerExtension( + extensions_v8::ExternalExtension::Get()); const WebKit::WebString kExtensionScheme = WebKit::WebString::fromUTF8(chrome::kExtensionScheme); - WebKit::registerExtension(ExtensionProcessBindings::Get(), kExtensionScheme); - - WebKit::registerExtension(BaseJsV8Extension::Get(), - EXTENSION_GROUP_CONTENT_SCRIPTS); - WebKit::registerExtension(BaseJsV8Extension::Get(), kExtensionScheme); - WebKit::registerExtension(JsonSchemaJsV8Extension::Get(), - EXTENSION_GROUP_CONTENT_SCRIPTS); - WebKit::registerExtension(JsonSchemaJsV8Extension::Get(), kExtensionScheme); - WebKit::registerExtension(EventBindings::Get(), - EXTENSION_GROUP_CONTENT_SCRIPTS); - WebKit::registerExtension(EventBindings::Get(), kExtensionScheme); - WebKit::registerExtension(RendererExtensionBindings::Get(), - EXTENSION_GROUP_CONTENT_SCRIPTS); - WebKit::registerExtension(RendererExtensionBindings::Get(), kExtensionScheme); - WebKit::registerExtension(ExtensionApiTestV8Extension::Get(), - kExtensionScheme); - WebKit::registerExtension(ExtensionApiTestV8Extension::Get(), - EXTENSION_GROUP_CONTENT_SCRIPTS); + WebScriptController::registerExtension( + ExtensionProcessBindings::Get(), kExtensionScheme); + + WebScriptController::registerExtension( + BaseJsV8Extension::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS); + WebScriptController::registerExtension( + BaseJsV8Extension::Get(), kExtensionScheme); + WebScriptController::registerExtension( + JsonSchemaJsV8Extension::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS); + WebScriptController::registerExtension(JsonSchemaJsV8Extension::Get(), + kExtensionScheme); + WebScriptController::registerExtension( + EventBindings::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS); + WebScriptController::registerExtension(EventBindings::Get(), + kExtensionScheme); + WebScriptController::registerExtension( + RendererExtensionBindings::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS); + WebScriptController::registerExtension( + RendererExtensionBindings::Get(), kExtensionScheme); + WebScriptController::registerExtension( + ExtensionApiTestV8Extension::Get(), kExtensionScheme); + WebScriptController::registerExtension( + ExtensionApiTestV8Extension::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS); const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - if (command_line.HasSwitch(switches::kEnableBenchmarking)) - WebKit::registerExtension(extensions_v8::BenchmarkingExtension::Get()); + if (command_line.HasSwitch(switches::kEnableBenchmarking)) { + WebScriptController::registerExtension( + extensions_v8::BenchmarkingExtension::Get()); + } if (command_line.HasSwitch(switches::kPlaybackMode) || command_line.HasSwitch(switches::kRecordMode) || command_line.HasSwitch(switches::kNoJsRandomness)) { - WebKit::registerExtension(extensions_v8::PlaybackExtension::Get()); + WebScriptController::registerExtension( + extensions_v8::PlaybackExtension::Get()); } if (RenderProcess::current()->initialized_media_library()) diff --git a/chrome/test/render_view_test.cc b/chrome/test/render_view_test.cc index 69f7d8f..f80c845 100644 --- a/chrome/test/render_view_test.cc +++ b/chrome/test/render_view_test.cc @@ -24,6 +24,7 @@ #include "webkit/glue/webkit_glue.h" using WebKit::WebFrame; +using WebKit::WebScriptController; using WebKit::WebScriptSource; using WebKit::WebString; using WebKit::WebURLRequest; @@ -74,12 +75,12 @@ void RenderViewTest::SetUp() { // hacky, but this is the world we live in... webkit_glue::SetJavaScriptFlags(L" --expose-gc"); WebKit::initialize(&webkitclient_); - WebKit::registerExtension(BaseJsV8Extension::Get()); - WebKit::registerExtension(JsonSchemaJsV8Extension::Get()); - WebKit::registerExtension(EventBindings::Get()); - WebKit::registerExtension(ExtensionApiTestV8Extension::Get()); - WebKit::registerExtension(ExtensionProcessBindings::Get()); - WebKit::registerExtension(RendererExtensionBindings::Get()); + WebScriptController::registerExtension(BaseJsV8Extension::Get()); + WebScriptController::registerExtension(JsonSchemaJsV8Extension::Get()); + WebScriptController::registerExtension(EventBindings::Get()); + WebScriptController::registerExtension(ExtensionApiTestV8Extension::Get()); + WebScriptController::registerExtension(ExtensionProcessBindings::Get()); + WebScriptController::registerExtension(RendererExtensionBindings::Get()); EventBindings::SetRenderThread(&render_thread_); // TODO(aa): Should some of this go to some other inheriting class? diff --git a/webkit/api/public/WebScriptController.h b/webkit/api/public/WebScriptController.h index afed9be..8e2ebb4 100644 --- a/webkit/api/public/WebScriptController.h +++ b/webkit/api/public/WebScriptController.h @@ -40,27 +40,33 @@ namespace v8 { namespace WebKit { class WebString; - // Registers a v8 extension to be available on webpages. The three forms - // offer various restrictions on what types of contexts the extension is - // loaded into. If a scheme is provided, only pages whose URL has the given - // scheme will match. If extensionGroup is provided, the extension will only - // be loaded into scripts run via WebFrame::ExecuteInNewWorld with the - // matching group. - // Will only affect v8 contexts initialized after this call. Takes ownership - // of the v8::Extension object passed. - WEBKIT_API void registerExtension(v8::Extension*); - WEBKIT_API void registerExtension(v8::Extension*, - const WebString& schemeRestriction); - WEBKIT_API void registerExtension(v8::Extension*, int extensionGroup); + class WebScriptController { + public: + // Registers a v8 extension to be available on webpages. The three forms + // offer various restrictions on what types of contexts the extension is + // loaded into. If a scheme is provided, only pages whose URL has the given + // scheme will match. If extensionGroup is provided, the extension will only + // be loaded into scripts run via WebFrame::ExecuteInNewWorld with the + // matching group. + // Will only affect v8 contexts initialized after this call. Takes ownership + // of the v8::Extension object passed. + WEBKIT_API static void registerExtension(v8::Extension*); + WEBKIT_API static void registerExtension(v8::Extension*, + const WebString& schemeRestriction); + WEBKIT_API static void registerExtension(v8::Extension*, int extensionGroup); - // Enables special settings which are only applicable if V8 is executed - // in the single thread which must be the main thread. - // FIXME: make a try to dynamically detect when this condition is broken - // and automatically switch off single thread mode. - WEBKIT_API void enableV8SingleThreadMode(); + // Enables special settings which are only applicable if V8 is executed + // in the single thread which must be the main thread. + // FIXME: make a try to dynamically detect when this condition is broken + // and automatically switch off single thread mode. + WEBKIT_API static void enableV8SingleThreadMode(); - // Process any pending JavaScript console messages. - WEBKIT_API void flushConsoleMessages(); + // Process any pending JavaScript console messages. + WEBKIT_API static void flushConsoleMessages(); + + private: + WebScriptController(); + }; } // namespace WebKit diff --git a/webkit/api/src/WebScriptController.cpp b/webkit/api/src/WebScriptController.cpp index 4282030..9be47a8 100644 --- a/webkit/api/src/WebScriptController.cpp +++ b/webkit/api/src/WebScriptController.cpp @@ -36,30 +36,33 @@ #include "V8Binding.h" #include "V8Proxy.h" +using namespace WebCore; + namespace WebKit { -void registerExtension(v8::Extension* extension) +void WebScriptController::registerExtension(v8::Extension* extension) { - WebCore::V8Proxy::registerExtension(extension, WebString()); + V8Proxy::registerExtension(extension, WebString()); } -void registerExtension(v8::Extension* extension, - const WebString& schemeRestriction) +void WebScriptController::registerExtension(v8::Extension* extension, + const WebString& schemeRestriction) { - WebCore::V8Proxy::registerExtension(extension, schemeRestriction); + V8Proxy::registerExtension(extension, schemeRestriction); } -void registerExtension(v8::Extension* extension, int extensionGroup) +void WebScriptController::registerExtension(v8::Extension* extension, + int extensionGroup) { - WebCore::V8Proxy::registerExtension(extension, extensionGroup); + V8Proxy::registerExtension(extension, extensionGroup); } -void enableV8SingleThreadMode() +void WebScriptController::enableV8SingleThreadMode() { - WebCore::enableStringImplCache(); + enableStringImplCache(); } -void flushConsoleMessages() +void WebScriptController::flushConsoleMessages() { WebCore::V8Proxy::processConsoleMessages(); } diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index 6691f85..a79f39b 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -54,6 +54,7 @@ using WebKit::WebCanvas; using WebKit::WebFrame; using WebKit::WebNavigationPolicy; using WebKit::WebRect; +using WebKit::WebScriptController; using WebKit::WebSize; using WebKit::WebURLRequest; using WebKit::WebView; @@ -195,7 +196,7 @@ void TestShell::Dump(TestShell* shell) { if ((shell == NULL) || ((params = shell->test_params()) == NULL)) return; - WebKit::flushConsoleMessages(); + WebScriptController::flushConsoleMessages(); // Echo the url in the output so we know we're not getting out of sync. printf("#URL:%s\n", params->test_url.c_str()); diff --git a/webkit/tools/test_shell/test_shell_main.cc b/webkit/tools/test_shell/test_shell_main.cc index 8b716b1..9f2ae67 100644 --- a/webkit/tools/test_shell/test_shell_main.cc +++ b/webkit/tools/test_shell/test_shell_main.cc @@ -40,6 +40,8 @@ static const size_t kPathBufSize = 2048; +using WebKit::WebScriptController; + namespace { // StatsTable initialization parameters. @@ -215,10 +217,11 @@ int main(int argc, char* argv[]) { js_flags += L" --expose-gc"; webkit_glue::SetJavaScriptFlags(js_flags); // Expose GCController to JavaScript. - WebKit::registerExtension(extensions_v8::GCExtension::Get()); + WebScriptController::registerExtension(extensions_v8::GCExtension::Get()); if (parsed_command_line.HasSwitch(test_shell::kProfiler)) { - WebKit::registerExtension(extensions_v8::ProfilerExtension::Get()); + WebScriptController::registerExtension( + extensions_v8::ProfilerExtension::Get()); } // Load and initialize the stats table. Attempt to construct a somewhat @@ -235,7 +238,8 @@ int main(int argc, char* argv[]) { if (TestShell::CreateNewWindow(starting_url, &shell)) { if (record_mode || playback_mode) { platform.SetWindowPositionForRecording(shell); - WebKit::registerExtension(extensions_v8::PlaybackExtension::Get()); + WebScriptController::registerExtension( + extensions_v8::PlaybackExtension::Get()); } shell->Show(WebKit::WebNavigationPolicyNewWindow); diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h index 98b0602..4ec7c55 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.h +++ b/webkit/tools/test_shell/test_shell_webkit_init.h @@ -50,9 +50,11 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { ASCIIToUTF16(webkit_glue::GetUIResourceProtocol())); WebKit::WebSecurityPolicy::registerURLSchemeAsNoAccess( ASCIIToUTF16(webkit_glue::GetUIResourceProtocol())); - WebKit::enableV8SingleThreadMode(); - WebKit::registerExtension(extensions_v8::GearsExtension::Get()); - WebKit::registerExtension(extensions_v8::IntervalExtension::Get()); + WebKit::WebScriptController::enableV8SingleThreadMode(); + WebKit::WebScriptController::registerExtension( + extensions_v8::GearsExtension::Get()); + WebKit::WebScriptController::registerExtension( + extensions_v8::IntervalExtension::Get()); WebKit::enableWebSockets(); // Load libraries for media and enable the media player. |