diff options
author | dimich@google.com <dimich@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-22 00:36:16 +0000 |
---|---|---|
committer | dimich@google.com <dimich@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-22 00:36:16 +0000 |
commit | f2150bad5c549f7693981cfe8c72b3967c1cde18 (patch) | |
tree | d6a5d67f72b681f08dfc902b3e04eaf03bf8c14b /webkit/tools/test_shell | |
parent | a849f497f2707c59d104bef5b62f6e5cf0a9a5ea (diff) | |
download | chromium_src-f2150bad5c549f7693981cfe8c72b3967c1cde18.zip chromium_src-f2150bad5c549f7693981cfe8c72b3967c1cde18.tar.gz chromium_src-f2150bad5c549f7693981cfe8c72b3967c1cde18.tar.bz2 |
Move test_worker dll files in hierarchy to reflect the fact that this dll is only used by the test_shell.
Also inserted a stub WebKitClient implementation into test_worker_main to remove dependency of webkit on chrome.
Review URL: http://codereview.chromium.org/87056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14168 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools/test_shell')
-rw-r--r-- | webkit/tools/test_shell/test_shell.gyp | 7 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_worker/test_webworker.cc | 160 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_worker/test_webworker.h | 67 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_worker/test_worker.def | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_worker/test_worker.exp | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_worker/test_worker.vcproj | 166 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_worker/test_worker.vsprops | 12 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_worker/test_worker_main.cc | 215 |
8 files changed, 627 insertions, 4 deletions
diff --git a/webkit/tools/test_shell/test_shell.gyp b/webkit/tools/test_shell/test_shell.gyp index 3c0f3e7..d6c173c 100644 --- a/webkit/tools/test_shell/test_shell.gyp +++ b/webkit/tools/test_shell/test_shell.gyp @@ -472,7 +472,7 @@ 'target_name': 'test_worker', 'type': 'shared_library', 'xcode_settings': { - 'EXPORTED_SYMBOLS_FILE': '../../../chrome/test/worker/test_worker.exp', + 'EXPORTED_SYMBOLS_FILE': 'test_worker/test_worker.exp', }, 'dependencies': [ '../../../base/base.gyp:base', @@ -485,9 +485,8 @@ '../../webkit.gyp:webkit', ], 'sources': [ - '../../../chrome/test/worker/test_webworker.cc', - '../../../chrome/test/worker/test_worker_main.cc', - '../../../chrome/worker/worker_webkitclient_impl.cc', + 'test_worker/test_webworker.cc', + 'test_worker/test_worker_main.cc', ], }, ], diff --git a/webkit/tools/test_shell/test_worker/test_webworker.cc b/webkit/tools/test_shell/test_worker/test_webworker.cc new file mode 100644 index 0000000..0be6977 --- /dev/null +++ b/webkit/tools/test_shell/test_worker/test_webworker.cc @@ -0,0 +1,160 @@ +// Copyright (c) 2009 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 "config.h" + +#if ENABLE(WORKERS) + +#include "webkit/tools/test_shell/test_worker/test_webworker.h" + +#include "base/compiler_specific.h" +#include "base/task.h" +#undef LOG +#include "webkit/glue/webworkerclient.h" +#include "webkit/glue/webworker_impl.h" +#include "webkit/tools/test_shell/test_webworker_helper.h" + +TestWebWorker::TestWebWorker(WebWorkerClient* client, + TestWebWorkerHelper* webworker_helper) + : webworkerclient_delegate_(client), + webworker_impl_(NULL), + webworker_helper_(webworker_helper) { + AddRef(); // Adds the reference held for worker object. + AddRef(); // Adds the reference held for worker context object. +} + +TestWebWorker::~TestWebWorker() { + if (webworker_helper_) + webworker_helper_->Unload(); +} + +void TestWebWorker::StartWorkerContext(const GURL& script_url, + const string16& user_agent, + const string16& source_code) { + webworker_impl_ = new WebWorkerImpl(this); + + webworker_impl_->StartWorkerContext(script_url, + user_agent, + source_code); + + for (size_t i = 0; i < queued_messages_.size(); ++i) + webworker_impl_->PostMessageToWorkerContext(queued_messages_[i]); + queued_messages_.clear(); +} + +void TestWebWorker::TerminateWorkerContext() { + if (webworker_impl_) + webworker_impl_->TerminateWorkerContext(); +} + +void TestWebWorker::PostMessageToWorkerContext(const string16& message) { + if (webworker_impl_) + webworker_impl_->PostMessageToWorkerContext(message); + else + queued_messages_.push_back(message); +} + +void TestWebWorker::WorkerObjectDestroyed() { + if (webworker_impl_) + webworker_impl_->WorkerObjectDestroyed(); + + webworkerclient_delegate_ = NULL; + Release(); // Releases the reference held for worker object. +} + +void TestWebWorker::PostMessageToWorkerObject(const string16& message) { + if (webworker_helper_->IsMainThread()) { + if (webworkerclient_delegate_) + webworkerclient_delegate_->PostMessageToWorkerObject(message); + } else { + webworker_helper_->DispatchToMainThread( + InvokeMainThreadMethod, NewRunnableMethod( + this, &TestWebWorker::PostMessageToWorkerObject, message)); + } +} + +void TestWebWorker::PostExceptionToWorkerObject(const string16& error_message, + int line_number, + const string16& source_url) { + if (webworker_helper_->IsMainThread()) { + if (webworkerclient_delegate_) + webworkerclient_delegate_->PostExceptionToWorkerObject(error_message, + line_number, + source_url); + } else { + webworker_helper_->DispatchToMainThread( + InvokeMainThreadMethod, NewRunnableMethod( + this, &TestWebWorker::PostExceptionToWorkerObject, + error_message, line_number, source_url)); + } +} + +void TestWebWorker::PostConsoleMessageToWorkerObject( + int destination, + int source, + int level, + const string16& message, + int line_number, + const string16& source_url) { + if (webworker_helper_->IsMainThread()) { + if (webworkerclient_delegate_) + webworkerclient_delegate_->PostConsoleMessageToWorkerObject(destination, + source, + level, + message, + line_number, + source_url); + } else { + webworker_helper_->DispatchToMainThread( + InvokeMainThreadMethod, NewRunnableMethod( + this, &TestWebWorker::PostConsoleMessageToWorkerObject, + destination, source, level, message, line_number, source_url)); + } +} + +void TestWebWorker::ConfirmMessageFromWorkerObject(bool has_pending_activity) { + if (webworker_helper_->IsMainThread()) { + if (webworkerclient_delegate_) + webworkerclient_delegate_->ConfirmMessageFromWorkerObject( + has_pending_activity); + } else { + webworker_helper_->DispatchToMainThread( + InvokeMainThreadMethod, NewRunnableMethod( + this, &TestWebWorker::ConfirmMessageFromWorkerObject, + has_pending_activity)); + } +} + +void TestWebWorker::ReportPendingActivity(bool has_pending_activity) { + if (webworker_helper_->IsMainThread()) { + if (webworkerclient_delegate_) + webworkerclient_delegate_->ReportPendingActivity(has_pending_activity); + } else { + webworker_helper_->DispatchToMainThread( + InvokeMainThreadMethod, NewRunnableMethod( + this, &TestWebWorker::ReportPendingActivity, + has_pending_activity)); + } +} + +void TestWebWorker::WorkerContextDestroyed() { + if (webworker_helper_->IsMainThread()) { + if (webworkerclient_delegate_) + webworkerclient_delegate_->WorkerContextDestroyed(); + Release(); // Releases the reference held for worker context object. + } else { + webworker_impl_ = NULL; + webworker_helper_->DispatchToMainThread( + InvokeMainThreadMethod, NewRunnableMethod( + this, &TestWebWorker::WorkerContextDestroyed)); + } +} + +void TestWebWorker::InvokeMainThreadMethod(void* param) { + Task* task = static_cast<Task*>(param); + task->Run(); + delete task; +} + +#endif diff --git a/webkit/tools/test_shell/test_worker/test_webworker.h b/webkit/tools/test_shell/test_worker/test_webworker.h new file mode 100644 index 0000000..aa192e7 --- /dev/null +++ b/webkit/tools/test_shell/test_worker/test_webworker.h @@ -0,0 +1,67 @@ +// Copyright (c) 2009 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_TEST_WORKER_TEST_WEBWORKER_H_ +#define CHROME_TEST_WORKER_TEST_WEBWORKER_H_ + +#if ENABLE(WORKERS) + +#include <vector> + +#include "base/basictypes.h" +#include "base/ref_counted.h" +#include "webkit/glue/webworker.h" +#include "webkit/glue/webworkerclient.h" + +class GURL; +class TestWebWorkerHelper; + +class TestWebWorker : public WebWorker, + public WebWorkerClient, + public base::RefCounted<TestWebWorker> { + public: + TestWebWorker(WebWorkerClient* client, TestWebWorkerHelper* webworker_helper); + + // WebWorker implementation. + virtual void StartWorkerContext(const GURL& script_url, + const string16& user_agent, + const string16& source_code); + virtual void TerminateWorkerContext(); + virtual void PostMessageToWorkerContext(const string16& message); + virtual void WorkerObjectDestroyed(); + + // WebWorkerClient implementation. + virtual void PostMessageToWorkerObject(const string16& message); + virtual void PostExceptionToWorkerObject( + const string16& error_message, + int line_number, + const string16& source_url); + virtual void PostConsoleMessageToWorkerObject( + int destination, + int source, + int level, + const string16& message, + int line_number, + const string16& source_url); + virtual void ConfirmMessageFromWorkerObject(bool has_pending_activity); + virtual void ReportPendingActivity(bool has_pending_activity); + virtual void WorkerContextDestroyed(); + + private: + friend class base::RefCounted<TestWebWorker>; + virtual ~TestWebWorker(); + + static void InvokeMainThreadMethod(void* param); + + WebWorkerClient* webworkerclient_delegate_; + WebWorker* webworker_impl_; + TestWebWorkerHelper* webworker_helper_; + std::vector<string16> queued_messages_; + + DISALLOW_COPY_AND_ASSIGN(TestWebWorker); +}; + +#endif + +#endif // CHROME_TEST_WORKER_TEST_WEBWORKER_H_ diff --git a/webkit/tools/test_shell/test_worker/test_worker.def b/webkit/tools/test_shell/test_worker/test_worker.def new file mode 100644 index 0000000..7f6db18 --- /dev/null +++ b/webkit/tools/test_shell/test_worker/test_worker.def @@ -0,0 +1,2 @@ +EXPORTS + CreateWebWorker @1 diff --git a/webkit/tools/test_shell/test_worker/test_worker.exp b/webkit/tools/test_shell/test_worker/test_worker.exp new file mode 100644 index 0000000..88f6ee1 --- /dev/null +++ b/webkit/tools/test_shell/test_worker/test_worker.exp @@ -0,0 +1,2 @@ +_CreateWebWorker + diff --git a/webkit/tools/test_shell/test_worker/test_worker.vcproj b/webkit/tools/test_shell/test_worker/test_worker.vcproj new file mode 100644 index 0000000..0332e39 --- /dev/null +++ b/webkit/tools/test_shell/test_worker/test_worker.vcproj @@ -0,0 +1,166 @@ +<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="test_worker"
+ ProjectGUID="{3E03D462-780D-4C4D-B22E-5E095E6CF110}"
+ RootNamespace="test_worker"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ ConfigurationType="2"
+ InheritedPropertySheets="$(SolutionDir)..\build\debug.vsprops;.\test_worker.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ ConfigurationType="2"
+ InheritedPropertySheets="$(SolutionDir)..\build\release.vsprops;.\test_worker.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <File
+ RelativePath="..\..\..\glue\simple_clipboard_impl.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\test_webworker.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\test_webworker.h"
+ >
+ </File>
+ <File
+ RelativePath=".\test_worker.def"
+ >
+ </File>
+ <File
+ RelativePath=".\test_worker_main.cc"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/webkit/tools/test_shell/test_worker/test_worker.vsprops b/webkit/tools/test_shell/test_worker/test_worker.vsprops new file mode 100644 index 0000000..6a5cdcc --- /dev/null +++ b/webkit/tools/test_shell/test_worker/test_worker.vsprops @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioPropertySheet
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="test_worker"
+ InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;..\..\..\webkit\build\webkit_common.vsprops"
+ >
+ <Tool
+ Name="VCLinkerTool"
+ ModuleDefinitionFile="test_worker.def"
+ />
+</VisualStudioPropertySheet>
diff --git a/webkit/tools/test_shell/test_worker/test_worker_main.cc b/webkit/tools/test_shell/test_worker/test_worker_main.cc new file mode 100644 index 0000000..7fe6b61 --- /dev/null +++ b/webkit/tools/test_shell/test_worker/test_worker_main.cc @@ -0,0 +1,215 @@ +// Copyright (c) 2009 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 "config.h" + +#include "base/at_exit.h" +#include "base/gfx/native_widget_types.h" +#include "base/logging.h" +#include "base/path_service.h" +#include "base/scoped_ptr.h" +#include "base/string_util.h" +#include "googleurl/src/gurl.h" +#include "third_party/WebKit/WebKit/chromium/public/WebKit.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" +#include "webkit/glue/resource_loader_bridge.h" +#include "webkit/glue/webkit_glue.h" +#include "webkit/glue/webworker.h" +#include "webkit/glue/webkitclient_impl.h" +#include "webkit/glue/webworkerclient.h" +#include "webkit/tools/test_shell/test_webworker_helper.h" +#include "webkit/tools/test_shell/test_worker/test_webworker.h" + +// Create a global AtExitManager so that our code can use code from base that +// uses Singletons, for example. We don't care about static constructors here. +static base::AtExitManager global_at_exit_manager; + +// Stub WebKit Client. +class WorkerWebKitClientImpl : public webkit_glue::WebKitClientImpl { + public: + // WebKitClient methods: + virtual WebKit::WebClipboard* clipboard() { + NOTREACHED(); + return NULL; + } + + virtual WebKit::WebMimeRegistry* mimeRegistry() { + NOTREACHED(); + return NULL; + } + + virtual WebKit::WebSandboxSupport* sandboxSupport() { + NOTREACHED(); + return NULL; + } + + virtual unsigned long long visitedLinkHash(const char* canonicalURL, + size_t length) { + NOTREACHED(); + return 0; + } + + virtual bool isLinkVisited(unsigned long long linkHash) { + NOTREACHED(); + return false; + } + + virtual void setCookies(const WebKit::WebURL& url, + const WebKit::WebURL& policy_url, + const WebKit::WebString& value) { + NOTREACHED(); + } + + virtual WebKit::WebString cookies(const WebKit::WebURL& url, + const WebKit::WebURL& policy_url) { + NOTREACHED(); + return WebKit::WebString(); + } + + virtual void prefetchHostName(const WebKit::WebString&) { + NOTREACHED(); + } + + virtual WebKit::WebString defaultLocale() { + NOTREACHED(); + return WebKit::WebString(); + } +}; + +// WebKit client used in DLL. +static scoped_ptr<WorkerWebKitClientImpl> webkit_client; + +#if defined(COMPILER_GCC) +#pragma GCC visibility push(default) +#endif +extern "C" { +// DLL entry points +WebWorker* API_CALL CreateWebWorker(WebWorkerClient* webworker_client, + TestWebWorkerHelper* webworker_helper) { + if (!WebKit::webKitClient()) { + webkit_client.reset(new WorkerWebKitClientImpl()); + WebKit::initialize(webkit_client.get()); + } + +#if ENABLE(WORKERS) + return new TestWebWorker(webworker_client, webworker_helper); +#else + return NULL; +#endif +} +} // extern "C" + +// WebKit glue stub functions. +namespace webkit_glue { + +#if defined(COMPILER_GCC) +// GCC hides the class methods like this by default, even in the scope +// of the "#pragma visibility". Need the attribute. +__attribute__((visibility("default"))) +#endif +ResourceLoaderBridge* ResourceLoaderBridge::Create( + const std::string& method, + const GURL& url, + const GURL& policy_url, + const GURL& referrer, + const std::string& frame_origin, + const std::string& main_frame_origin, + const std::string& headers, + int load_flags, + int requestor_pid, + ResourceType::Type request_type, + int app_cache_context_id, + int routing_id) { + return NULL; +} + +string16 GetLocalizedString(int message_id) { + return EmptyString16(); +} + +StringPiece GetDataResource(int resource_id) { + return StringPiece(); +} + +void SetMediaPlayerAvailable(bool value) { +} + +bool IsMediaPlayerAvailable() { + return false; +} + +void PrecacheUrl(const char16* url, int url_length) { +} + +void AppendToLog(const char* file, int line, const char* msg) { + logging::LogMessage(file, line).stream() << msg; +} + +bool GetApplicationDirectory(std::wstring *path) { + return PathService::Get(base::DIR_EXE, path); +} + +GURL GetInspectorURL() { + return GURL("test-shell-resource://inspector/inspector.html"); +} + +std::string GetUIResourceProtocol() { + return "test-shell-resource"; +} + +bool GetExeDirectory(std::wstring *path) { + return PathService::Get(base::DIR_EXE, path); +} + +bool SpellCheckWord(const wchar_t* word, int word_len, + int* misspelling_start, int* misspelling_len) { + // Report all words being correctly spelled. + *misspelling_start = 0; + *misspelling_len = 0; + return true; +} + +bool GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { + return false; +} + +bool IsPluginRunningInRendererProcess() { + return false; +} + +bool GetPluginFinderURL(std::string* plugin_finder_url) { + return false; +} + +bool IsDefaultPluginEnabled() { + return false; +} + +bool FindProxyForUrl(const GURL& url, std::string* proxy_list) { + return false; +} + +std::wstring GetWebKitLocale() { + return L"en-US"; +} + +#if defined(OS_WIN) +HCURSOR LoadCursor(int cursor_id) { + return NULL; +} + +bool EnsureFontLoaded(HFONT font) { + return true; +} + +bool DownloadUrl(const std::string& url, HWND caller_window) { + return false; +} +#endif + +} // namespace webkit_glue + +#if defined(COMPILER_GCC) +#pragma GCC visibility pop +#endif |