From 8d86fce009d9dc39300a5ec9b0559ce17ff0e44e Mon Sep 17 00:00:00 2001
From: "darin@chromium.org"
 <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Thu, 26 Feb 2009 23:37:55 +0000
Subject: Chrome side to implement WebMimeRegistry.

R=dglazkov

Review URL: http://codereview.chromium.org/27222

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10532 0039d316-1c4b-4281-b951-d872f2087c98
---
 DEPS                                               |  2 +-
 chrome/chrome.xcodeproj/project.pbxproj            |  8 ++-
 chrome/renderer/render_thread.cc                   | 59 ++++++++++-----------
 chrome/renderer/render_thread.h                    | 26 ++++-----
 chrome/renderer/renderer.scons                     |  2 +
 chrome/renderer/renderer.vcproj                    |  8 +++
 chrome/renderer/renderer_glue.cc                   | 41 ---------------
 chrome/renderer/renderer_webkitclient_impl.cc      | 57 ++++++++++++++++++++
 chrome/renderer/renderer_webkitclient_impl.h       | 30 +++++++++++
 webkit/glue/SConscript                             |  3 +-
 webkit/glue/chromium_bridge_impl.cc                | 51 ------------------
 webkit/glue/glue.vcproj                            | 20 ++++---
 webkit/glue/glue_util.cc                           | 19 ++++++-
 webkit/glue/glue_util.h                            |  7 +++
 webkit/glue/plugins/plugin_stream.cc               |  4 +-
 webkit/glue/simple_webmimeregistry_impl.cc         | 61 ++++++++++++++++++++++
 webkit/glue/simple_webmimeregistry_impl.h          | 26 +++++++++
 webkit/glue/webkit_client_impl.cc                  | 19 -------
 webkit/glue/webkit_client_impl.h                   | 26 ---------
 webkit/glue/webkit_glue.h                          | 15 ------
 webkit/glue/webkitclient_impl.cc                   | 17 ++++++
 webkit/glue/webkitclient_impl.h                    | 27 ++++++++++
 .../mac/TestShell.xcodeproj/project.pbxproj        | 15 ++++++
 webkit/tools/test_shell/run_all_tests.cc           |  4 +-
 webkit/tools/test_shell/test_shell.cc              | 15 ------
 webkit/tools/test_shell/test_shell.vcproj          |  4 ++
 webkit/tools/test_shell/test_shell_main.cc         | 12 ++---
 webkit/tools/test_shell/test_shell_webkit_init.h   | 35 +++++++++++++
 webkit/webkit.gyp                                  |  7 ++-
 webkit/webkit.xcodeproj/project.pbxproj            | 26 +++++----
 30 files changed, 402 insertions(+), 244 deletions(-)
 create mode 100644 chrome/renderer/renderer_webkitclient_impl.cc
 create mode 100644 chrome/renderer/renderer_webkitclient_impl.h
 create mode 100644 webkit/glue/simple_webmimeregistry_impl.cc
 create mode 100644 webkit/glue/simple_webmimeregistry_impl.h
 delete mode 100644 webkit/glue/webkit_client_impl.cc
 delete mode 100644 webkit/glue/webkit_client_impl.h
 create mode 100644 webkit/glue/webkitclient_impl.cc
 create mode 100644 webkit/glue/webkitclient_impl.h
 create mode 100644 webkit/tools/test_shell/test_shell_webkit_init.h

diff --git a/DEPS b/DEPS
index 9d057fd..f102a9c 100644
--- a/DEPS
+++ b/DEPS
@@ -19,7 +19,7 @@ deps = {
     "http://googletest.googlecode.com/svn/trunk@167",
 
   "src/third_party/WebKit":
-    "/trunk/deps/third_party/WebKit@10496",
+    "/trunk/deps/third_party/WebKit@10527",
 
   "src/third_party/icu38":
     "/trunk/deps/third_party/icu38@10364",
diff --git a/chrome/chrome.xcodeproj/project.pbxproj b/chrome/chrome.xcodeproj/project.pbxproj
index 07d3200..e1121d5 100644
--- a/chrome/chrome.xcodeproj/project.pbxproj
+++ b/chrome/chrome.xcodeproj/project.pbxproj
@@ -318,6 +318,7 @@
 		8F51B73AAAF1772ECF9BD180 /* url_fetcher.cc in Sources */ = {isa = PBXBuildFile; fileRef = 778D7927798B7E3FAA498D3D /* url_fetcher.cc */; };
 		9084D27A4F8690E6FD31083B /* session_backend.cc in Sources */ = {isa = PBXBuildFile; fileRef = 35AC9D9A03545594C102C5C1 /* session_backend.cc */; };
 		928300674E414B42615BA4F0 /* download_manager.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BF9CE0E9D48CE009A6919 /* download_manager.cc */; };
+		938D10370F57401C009F1128 /* renderer_webkitclient_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 938D10350F57401C009F1128 /* renderer_webkitclient_impl.cc */; };
 		93FB3ECE0F55E38400AA1185 /* libwebkit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E4BD53D90F54AB4300591DFA /* libwebkit.a */; };
 		93FB3ED10F55E38900AA1185 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E45065DD0EEEC6FF003BE099 /* AppKit.framework */; };
 		93FB3ED20F55E38900AA1185 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4DCDB9C0F4091BF0084059A /* ApplicationServices.framework */; };
@@ -2594,6 +2595,8 @@
 		844EA0820F3E0C1000B0EF26 /* debugger_wrapper.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = debugger_wrapper.cc; path = debugger/debugger_wrapper.cc; sourceTree = "<group>"; };
 		844EA0830F3E0C1000B0EF26 /* debugger_wrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = debugger_wrapper.h; path = debugger/debugger_wrapper.h; sourceTree = "<group>"; };
 		90BF0D1189BB7158BD7F1600 /* bookmark_context_menu.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bookmark_context_menu.cc; path = browser/bookmarks/bookmark_context_menu.cc; sourceTree = SOURCE_ROOT; };
+		938D10350F57401C009F1128 /* renderer_webkitclient_impl.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = renderer_webkitclient_impl.cc; sourceTree = "<group>"; };
+		938D10360F57401C009F1128 /* renderer_webkitclient_impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = renderer_webkitclient_impl.h; sourceTree = "<group>"; };
 		A2FC5EE73E0DE8BF6C1C4C0F /* bookmark_utils.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bookmark_utils.cc; path = browser/bookmarks/bookmark_utils.cc; sourceTree = SOURCE_ROOT; };
 		A54612D90EE9957000A8EE5D /* extensions_service.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = extensions_service.cc; sourceTree = "<group>"; };
 		A54612DA0EE9957000A8EE5D /* extensions_service.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = extensions_service.h; sourceTree = "<group>"; };
@@ -3262,7 +3265,6 @@
 				4D640CCF0EAE868600EBCFC0 /* render_process.cc */,
 				4D640CD00EAE868600EBCFC0 /* render_process.h */,
 				3380A9BF0F2FC61E004EF74F /* render_process_unittest.cc */,
-				F4143C8B0F4B1D07008C8F73 /* renderer.sb */,
 				4D640CD10EAE868600EBCFC0 /* render_thread.cc */,
 				4D640CD20EAE868600EBCFC0 /* render_thread.h */,
 				3380A6B50F2E9252004EF74F /* render_thread_unittest.cc */,
@@ -3272,6 +3274,7 @@
 				4D640CD50EAE868600EBCFC0 /* render_widget.cc */,
 				4D640CD60EAE868600EBCFC0 /* render_widget.h */,
 				4D640CD70EAE868600EBCFC0 /* render_widget_unittest.cc */,
+				F4143C8B0F4B1D07008C8F73 /* renderer.sb */,
 				4D640CD80EAE868600EBCFC0 /* renderer_glue.cc */,
 				AB3B4B290F549D9E0009E2BF /* renderer_histogram_snapshots.cc */,
 				AB3B4B2A0F549D9E0009E2BF /* renderer_histogram_snapshots.h */,
@@ -3281,6 +3284,8 @@
 				B51F6D120F37C4DC00152D66 /* renderer_main_platform_delegate_win.cc */,
 				B5D030EF0F3A3C43001238AB /* renderer_main_unittest.cc */,
 				4D640CDA0EAE868600EBCFC0 /* renderer_resources.h */,
+				938D10350F57401C009F1128 /* renderer_webkitclient_impl.cc */,
+				938D10360F57401C009F1128 /* renderer_webkitclient_impl.h */,
 				4D640CC90EAE868600EBCFC0 /* user_script_slave.cc */,
 				4D640CCA0EAE868600EBCFC0 /* user_script_slave.h */,
 				4D640CDC0EAE868600EBCFC0 /* visitedlink_slave.cc */,
@@ -5680,6 +5685,7 @@
 				B503E0F00F0175FD00547DC6 /* user_script_slave.cc in Sources */,
 				AB8963020F4E090D009CFFAC /* video_renderer_impl.cc in Sources */,
 				4D640CF50EAE86EF00EBCFC0 /* visitedlink_slave.cc in Sources */,
+				938D10370F57401C009F1128 /* renderer_webkitclient_impl.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index dacbd8a..fb8082b 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -29,10 +29,10 @@
 #include "chrome/renderer/net/render_dns_master.h"
 #include "chrome/renderer/render_process.h"
 #include "chrome/renderer/render_view.h"
+#include "chrome/renderer/renderer_webkitclient_impl.h"
 #include "chrome/renderer/user_script_slave.h"
 #include "chrome/renderer/visitedlink_slave.h"
 #include "webkit/glue/cache_manager.h"
-#include "webkit/glue/webkit_client_impl.h"
 
 #include "WebKit.h"
 
@@ -49,20 +49,13 @@ static const size_t kStackSize = 1024 * 1024;
 RenderThread::RenderThread()
     : ChildThread(
           base::Thread::Options(RenderProcess::InProcessPlugins() ?
-              MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT, kStackSize)),
-      visited_link_slave_(NULL),
-      user_script_slave_(NULL),
-      render_dns_master_(NULL) {
+              MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT, kStackSize)) {
 }
 
 RenderThread::RenderThread(const std::wstring& channel_name)
     : ChildThread(
           base::Thread::Options(RenderProcess::InProcessPlugins() ?
-              MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT, kStackSize)),
-      visited_link_slave_(NULL),
-      user_script_slave_(NULL),
-      render_dns_master_(NULL),
-      renderer_histogram_snapshots_(NULL) {
+              MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT, kStackSize)) {
   SetChannelName(channel_name);
 }
 
@@ -83,50 +76,54 @@ void RenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) {
 }
 
 void RenderThread::Resolve(const char* name, size_t length) {
-  return render_dns_master_->Resolve(name, length);
+  return dns_master_->Resolve(name, length);
 }
 
 void RenderThread::SendHistograms() {
-  return renderer_histogram_snapshots_->SendHistograms();
+  return histogram_snapshots_->SendHistograms();
 }
 
 void RenderThread::Init() {
-  ChildThread::Init();
-  notification_service_.reset(new NotificationService);
-  cache_stats_factory_.reset(
-      new ScopedRunnableMethodFactory<RenderThread>(this));
-
+  // TODO(darin): Why do we need COM here?  This is probably bogus.
 #if defined(OS_WIN)
   // The renderer thread should wind-up COM.
   CoInitialize(0);
 #endif
 
-  webkit_client_impl_.reset(new webkit_glue::WebKitClientImpl);
+  ChildThread::Init();
+  notification_service_.reset(new NotificationService);
+  cache_stats_factory_.reset(
+      new ScopedRunnableMethodFactory<RenderThread>(this));
+
+  webkit_client_impl_.reset(new RendererWebKitClientImpl);
   WebKit::initialize(webkit_client_impl_.get());
 
-  visited_link_slave_ = new VisitedLinkSlave();
-  user_script_slave_ = new UserScriptSlave();
-  render_dns_master_.reset(new RenderDnsMaster());
-  renderer_histogram_snapshots_.reset(new RendererHistogramSnapshots());
+  visited_link_slave_.reset(new VisitedLinkSlave());
+  user_script_slave_.reset(new UserScriptSlave());
+  dns_master_.reset(new RenderDnsMaster());
+  histogram_snapshots_.reset(new RendererHistogramSnapshots());
 }
 
 void RenderThread::CleanUp() {
+  // Shutdown in reverse of the initialization order.
+
+  histogram_snapshots_.reset();
+  dns_master_.reset();
+  user_script_slave_.reset();
+  visited_link_slave_.reset();
+
+  WebKit::shutdown();
+
+  notification_service_.reset();
+
   ChildThread::CleanUp();
 
-// TODO(port)
+  // TODO(port)
 #if defined(OS_WIN)
   // Clean up plugin channels before this thread goes away.
   PluginChannelBase::CleanupChannels();
 #endif
 
-  notification_service_.reset();
-
-  delete visited_link_slave_;
-  visited_link_slave_ = NULL;
-
-  delete user_script_slave_;
-  user_script_slave_ = NULL;
-
 #if defined(OS_WIN)
   CoUninitialize();
 #endif
diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h
index cfc3d9a..8f41cce 100644
--- a/chrome/renderer/render_thread.h
+++ b/chrome/renderer/render_thread.h
@@ -18,16 +18,13 @@ class FilePath;
 class NotificationService;
 class RenderDnsMaster;
 class RendererHistogram;
+class RendererWebKitClientImpl;
 class SkBitmap;
 class UserScriptSlave;
 class VisitedLinkSlave;
 struct ModalDialogEvent;
 struct WebPreferences;
 
-namespace webkit_glue {
-class WebKitClientImpl;
-}
-
 // The RenderThreadBase is the minimal interface that a RenderView/Widget
 // expects from a render thread. The interface basically abstracts a way to send
 // and receive messages.
@@ -83,11 +80,13 @@ class RenderThread : public RenderThreadBase,
   virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
   virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter);
 
-  // Gets the VisitedLinkSlave instance for this thread
-  VisitedLinkSlave* visited_link_slave() const { return visited_link_slave_; }
+  VisitedLinkSlave* visited_link_slave() const {
+    return visited_link_slave_.get();
+  }
 
-  // Gets the UserScriptSlave instance for this thread
-  UserScriptSlave* user_script_slave() const { return user_script_slave_; }
+  UserScriptSlave* user_script_slave() const {
+    return user_script_slave_.get();
+  }
 
   // Do DNS prefetch resolution of a hostname.
   void Resolve(const char* name, size_t length);
@@ -131,18 +130,19 @@ class RenderThread : public RenderThreadBase,
   void InformHostOfCacheStats();
 
   // These objects live solely on the render thread.
-  VisitedLinkSlave* visited_link_slave_;
-  UserScriptSlave* user_script_slave_;
+  scoped_ptr<VisitedLinkSlave> visited_link_slave_;
+
+  scoped_ptr<UserScriptSlave> user_script_slave_;
 
-  scoped_ptr<RenderDnsMaster> render_dns_master_;
+  scoped_ptr<RenderDnsMaster> dns_master_;
 
-  scoped_ptr<RendererHistogramSnapshots> renderer_histogram_snapshots_;
+  scoped_ptr<RendererHistogramSnapshots> histogram_snapshots_;
 
   scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > cache_stats_factory_;
 
   scoped_ptr<NotificationService> notification_service_;
 
-  scoped_ptr<webkit_glue::WebKitClientImpl> webkit_client_impl_;
+  scoped_ptr<RendererWebKitClientImpl> webkit_client_impl_;
 
   DISALLOW_COPY_AND_ASSIGN(RenderThread);
 };
diff --git a/chrome/renderer/renderer.scons b/chrome/renderer/renderer.scons
index 85bfde1..e280cb8 100644
--- a/chrome/renderer/renderer.scons
+++ b/chrome/renderer/renderer.scons
@@ -95,6 +95,8 @@ input_files = ChromeFileList([
     'renderer_glue.cc',
     'renderer_histogram_snapshots.cc',
     'renderer_histogram_snapshots.h',
+    'renderer_webkitclient_impl.cc',
+    'renderer_webkitclient_impl.h',
     'renderer_main.cc',
     'renderer_resources.h',
     'user_script_slave.cc',
diff --git a/chrome/renderer/renderer.vcproj b/chrome/renderer/renderer.vcproj
index 8e81aac..4879a93 100644
--- a/chrome/renderer/renderer.vcproj
+++ b/chrome/renderer/renderer.vcproj
@@ -342,6 +342,14 @@
 			>
 		</File>
 		<File
+			RelativePath=".\renderer_webkitclient_impl.cc"
+			>
+		</File>
+		<File
+			RelativePath=".\renderer_webkitclient_impl.h"
+			>
+		</File>
+		<File
 			RelativePath=".\user_script_slave.cc"
 			>
 		</File>
diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc
index 055f342..1058698 100644
--- a/chrome/renderer/renderer_glue.cc
+++ b/chrome/renderer/renderer_glue.cc
@@ -24,8 +24,6 @@
 #include "chrome/renderer/render_view.h"
 #include "chrome/renderer/visitedlink_slave.h"
 #include "googleurl/src/url_util.h"
-#include "net/base/mime_util.h"
-#include "net/base/net_errors.h"
 #include "webkit/glue/scoped_clipboard_writer_glue.h"
 #include "webkit/glue/webframe.h"
 #include "webkit/glue/webkit_glue.h"
@@ -174,45 +172,6 @@ void AppendToLog(const char* file, int line, const char* msg) {
   logging::LogMessage(file, line).stream() << msg;
 }
 
-bool GetMimeTypeFromExtension(const FilePath::StringType &ext,
-                              std::string *mime_type) {
-  if (IsPluginProcess())
-    return net::GetMimeTypeFromExtension(ext, mime_type);
-
-  // The sandbox restricts our access to the registry, so we need to proxy
-  // these calls over to the browser process.
-  DCHECK(mime_type->empty());
-  RenderThread::current()->Send(
-      new ViewHostMsg_GetMimeTypeFromExtension(ext, mime_type));
-  return !mime_type->empty();
-}
-
-bool GetMimeTypeFromFile(const FilePath &file_path,
-                         std::string *mime_type) {
-  if (IsPluginProcess())
-    return net::GetMimeTypeFromFile(file_path, mime_type);
-
-  // The sandbox restricts our access to the registry, so we need to proxy
-  // these calls over to the browser process.
-  DCHECK(mime_type->empty());
-  RenderThread::current()->Send(
-      new ViewHostMsg_GetMimeTypeFromFile(file_path, mime_type));
-  return !mime_type->empty();
-}
-
-bool GetPreferredExtensionForMimeType(const std::string& mime_type,
-                                      FilePath::StringType* ext) {
-  if (IsPluginProcess())
-    return net::GetPreferredExtensionForMimeType(mime_type, ext);
-
-  // The sandbox restricts our access to the registry, so we need to proxy
-  // these calls over to the browser process.
-  DCHECK(ext->empty());
-  RenderThread::current()->Send(
-      new ViewHostMsg_GetPreferredExtensionForMimeType(mime_type, ext));
-  return !ext->empty();
-}
-
 std::string GetDataResource(int resource_id) {
   return ResourceBundle::GetSharedInstance().GetDataResource(resource_id);
 }
diff --git a/chrome/renderer/renderer_webkitclient_impl.cc b/chrome/renderer/renderer_webkitclient_impl.cc
new file mode 100644
index 0000000..b33d12e
--- /dev/null
+++ b/chrome/renderer/renderer_webkitclient_impl.cc
@@ -0,0 +1,57 @@
+// 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 "chrome/renderer/renderer_webkitclient_impl.h"
+
+#include "WebString.h"
+
+#include "chrome/common/render_messages.h"
+#include "chrome/plugin/npobject_util.h"
+#include "chrome/renderer/render_thread.h"
+#include "webkit/glue/glue_util.h"
+
+using WebKit::WebString;
+
+WebString RendererWebKitClientImpl::MimeRegistry::mimeTypeForExtension(
+    const WebString& file_extension) {
+  if (IsPluginProcess())
+    return SimpleWebMimeRegistryImpl::mimeTypeForExtension(file_extension);
+
+  // The sandbox restricts our access to the registry, so we need to proxy
+  // these calls over to the browser process.
+  std::string mime_type;
+  RenderThread::current()->Send(new ViewHostMsg_GetMimeTypeFromExtension(
+      webkit_glue::WebStringToFilePathString(file_extension), &mime_type));
+  return ASCIIToUTF16(mime_type);
+  
+}
+
+WebString RendererWebKitClientImpl::MimeRegistry::mimeTypeFromFile(
+    const WebString& file_path) {
+  if (IsPluginProcess())
+    return SimpleWebMimeRegistryImpl::mimeTypeFromFile(file_path);
+
+  // The sandbox restricts our access to the registry, so we need to proxy
+  // these calls over to the browser process.
+  std::string mime_type;
+  RenderThread::current()->Send(new ViewHostMsg_GetMimeTypeFromFile(
+      FilePath(webkit_glue::WebStringToFilePathString(file_path)),
+      &mime_type));
+  return ASCIIToUTF16(mime_type);
+  
+}
+
+WebString RendererWebKitClientImpl::MimeRegistry::preferredExtensionForMIMEType(
+    const WebString& mime_type) {
+  if (IsPluginProcess())
+    return SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType(mime_type);
+
+  // The sandbox restricts our access to the registry, so we need to proxy
+  // these calls over to the browser process.
+  FilePath::StringType file_extension;
+  RenderThread::current()->Send(
+      new ViewHostMsg_GetPreferredExtensionForMimeType(UTF16ToASCII(mime_type),
+          &file_extension));
+  return webkit_glue::FilePathStringToWebString(file_extension);
+}
diff --git a/chrome/renderer/renderer_webkitclient_impl.h b/chrome/renderer/renderer_webkitclient_impl.h
new file mode 100644
index 0000000..2e85234
--- /dev/null
+++ b/chrome/renderer/renderer_webkitclient_impl.h
@@ -0,0 +1,30 @@
+// 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_RENDERER_RENDERER_WEBKIT_CLIENT_IMPL_H_
+#define CHROME_RENDERER_RENDERER_WEBKIT_CLIENT_IMPL_H_
+
+#include "webkit/glue/simple_webmimeregistry_impl.h"
+#include "webkit/glue/webkitclient_impl.h"
+
+class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl {
+ public:
+  // WebKitClient methods:
+  virtual WebKit::WebMimeRegistry* mimeRegistry() {
+    return &mime_registry_;
+  }
+
+ private:
+  class MimeRegistry : public webkit_glue::SimpleWebMimeRegistryImpl {
+   public:
+    virtual WebKit::WebString mimeTypeForExtension(const WebKit::WebString&);
+    virtual WebKit::WebString mimeTypeFromFile(const WebKit::WebString&);
+    virtual WebKit::WebString preferredExtensionForMIMEType(
+        const WebKit::WebString&);
+  };
+
+  MimeRegistry mime_registry_;
+};
+
+#endif  // CHROME_RENDERER_WEBKIT_CLIENT_IMPL_H_
diff --git a/webkit/glue/SConscript b/webkit/glue/SConscript
index 375b8de..555f657 100644
--- a/webkit/glue/SConscript
+++ b/webkit/glue/SConscript
@@ -78,6 +78,7 @@ input_files = [
   'resource_handle_impl.cc',
   'resource_loader_bridge.cc',
   'searchable_form_data.cc',
+  'simple_webmimeregistry_impl.cc',
   'stacking_order_iterator.cc',
   'webclipboard_impl.cc',
   'webcursor.cc',
@@ -87,7 +88,7 @@ input_files = [
   'webframe_impl.cc',
   'webframeloaderclient_impl.cc',
   'webhistoryitem_impl.cc',
-  'webkit_client_impl.cc',
+  'webkitclient_impl.cc',
   'webkit_glue.cc',
   'webmediaplayer_impl.cc',
   'webplugin_delegate.cc',
diff --git a/webkit/glue/chromium_bridge_impl.cc b/webkit/glue/chromium_bridge_impl.cc
index aeb5f40..4fb80c4 100644
--- a/webkit/glue/chromium_bridge_impl.cc
+++ b/webkit/glue/chromium_bridge_impl.cc
@@ -34,7 +34,6 @@
 #include "base/trace_event.h"
 #include "build/build_config.h"
 #include "googleurl/src/url_util.h"
-#include "net/base/mime_util.h"
 #include "skia/ext/skia_utils_win.h"
 #if USE(V8)
 #include <v8.h>
@@ -142,56 +141,6 @@ bool ChromiumBridge::layoutTestMode() {
   return webkit_glue::IsLayoutTestMode();
 }
 
-// MimeType -------------------------------------------------------------------
-
-bool ChromiumBridge::isSupportedImageMIMEType(const char* mime_type) {
-  return net::IsSupportedImageMimeType(mime_type);
-}
-
-bool ChromiumBridge::isSupportedJavascriptMIMEType(const char* mime_type) {
-  return net::IsSupportedJavascriptMimeType(mime_type);
-}
-
-bool ChromiumBridge::isSupportedNonImageMIMEType(const char* mime_type) {
-  return net::IsSupportedNonImageMimeType(mime_type);
-}
-
-bool ChromiumBridge::matchesMIMEType(const String& pattern,
-                                     const String& type) {
-  return net::MatchesMimeType(webkit_glue::StringToStdString(pattern),
-                              webkit_glue::StringToStdString(type));
-}
-
-String ChromiumBridge::mimeTypeForExtension(const String& ext) {
-  if (ext.isEmpty())
-    return String();
-
-  std::string type;
-  webkit_glue::GetMimeTypeFromExtension(
-      webkit_glue::StringToFilePathString(ext), &type);
-  return webkit_glue::StdStringToString(type);
-}
-
-String ChromiumBridge::mimeTypeFromFile(const String& file_path) {
-  if (file_path.isEmpty())
-    return String();
-
-  std::string type;
-  webkit_glue::GetMimeTypeFromFile(
-      FilePath(webkit_glue::StringToFilePathString(file_path)), &type);
-  return webkit_glue::StdStringToString(type);
-}
-
-String ChromiumBridge::preferredExtensionForMIMEType(const String& mime_type) {
-  if (mime_type.isEmpty())
-    return String();
-
-  FilePath::StringType stdext;
-  webkit_glue::GetPreferredExtensionForMimeType(
-      webkit_glue::StringToStdString(mime_type), &stdext);
-  return webkit_glue::FilePathStringToString(stdext);
-}
-
 // Plugin ---------------------------------------------------------------------
 
 bool ChromiumBridge::plugins(bool refresh, Vector<PluginInfo*>* results) {
diff --git a/webkit/glue/glue.vcproj b/webkit/glue/glue.vcproj
index 6dae503..bb0d3e3 100644
--- a/webkit/glue/glue.vcproj
+++ b/webkit/glue/glue.vcproj
@@ -525,6 +525,14 @@
 				>
 			</File>
 			<File
+				RelativePath=".\simple_webmimeregistry_impl.cc"
+				>
+			</File>
+			<File
+				RelativePath=".\simple_webmimeregistry_impl.h"
+				>
+			</File>
+			<File
 				RelativePath=".\stacking_order_iterator.cc"
 				>
 			</File>
@@ -609,27 +617,27 @@
 				>
 			</File>
 			<File
-				RelativePath=".\webinputevent_win.cc"
+				RelativePath=".\webinputevent_utils.cc"
 				>
 			</File>
 			<File
-				RelativePath=".\webkit_client_impl.cc"
+				RelativePath=".\webkit_glue.cc"
 				>
 			</File>
 			<File
-				RelativePath=".\webkit_client_impl.h"
+				RelativePath=".\webkit_glue.h"
 				>
 			</File>
 			<File
-				RelativePath=".\webkit_glue.cc"
+				RelativePath=".\webkit_glue_win.cc"
 				>
 			</File>
 			<File
-				RelativePath=".\webkit_glue.h"
+				RelativePath=".\webkitclient_impl.cc"
 				>
 			</File>
 			<File
-				RelativePath=".\webkit_glue_win.cc"
+				RelativePath=".\webkitclient_impl.h"
 				>
 			</File>
 			<File
diff --git a/webkit/glue/glue_util.cc b/webkit/glue/glue_util.cc
index 113d413..359eb40 100644
--- a/webkit/glue/glue_util.cc
+++ b/webkit/glue/glue_util.cc
@@ -16,8 +16,9 @@ MSVC_PUSH_WARNING_LEVEL(0);
 #include "KURL.h"
 MSVC_POP_WARNING();
 
-#undef LOG
+#include "WebString.h"
 
+#undef LOG
 #include "base/compiler_specific.h"
 #include "base/gfx/rect.h"
 #include "base/string_piece.h"
@@ -98,6 +99,22 @@ WebCore::String FilePathStringToString(const FilePath::StringType& str) {
 #endif
 }
 
+FilePath::StringType WebStringToFilePathString(const WebKit::WebString& str) {
+#if defined(OS_POSIX)
+  return base::SysWideToNativeMB(UTF16ToWide(str));
+#elif defined(OS_WIN)
+  return UTF16ToWide(str);
+#endif
+}
+
+WebKit::WebString FilePathStringToWebString(const FilePath::StringType& str) {
+#if defined(OS_POSIX)
+  return WideToUTF16(base::SysNativeMBToWide(str));
+#elif defined(OS_WIN)
+  return WideToUTF16(str);
+#endif
+}
+
 // URL conversions -------------------------------------------------------------
 
 GURL KURLToGURL(const WebCore::KURL& url) {
diff --git a/webkit/glue/glue_util.h b/webkit/glue/glue_util.h
index 576ec34..adbaffc 100644
--- a/webkit/glue/glue_util.h
+++ b/webkit/glue/glue_util.h
@@ -17,6 +17,10 @@ class KURL;
 class String;
 }
 
+namespace WebKit {
+class WebString;
+}
+
 namespace gfx {
 class Rect;
 }
@@ -46,6 +50,9 @@ WebCore::String StdStringToString(const std::string& str);
 FilePath::StringType StringToFilePathString(const WebCore::String& str);
 WebCore::String FilePathStringToString(const FilePath::StringType& str);
 
+FilePath::StringType WebStringToFilePathString(const WebKit::WebString& str);
+WebKit::WebString FilePathStringToWebString(const FilePath::StringType& str);
+
 GURL KURLToGURL(const WebCore::KURL& url);
 WebCore::KURL GURLToKURL(const GURL& url);
 GURL StringToGURL(const WebCore::String& spec);
diff --git a/webkit/glue/plugins/plugin_stream.cc b/webkit/glue/plugins/plugin_stream.cc
index af7fbe9..e66182b 100644
--- a/webkit/glue/plugins/plugin_stream.cc
+++ b/webkit/glue/plugins/plugin_stream.cc
@@ -12,8 +12,8 @@
 
 #include "base/string_util.h"
 #include "base/message_loop.h"
+#include "net/base/mime_util.h"
 #include "webkit/glue/plugins/plugin_instance.h"
-#include "webkit/glue/webkit_glue.h"
 #include "googleurl/src/gurl.h"
 
 namespace NPAPI {
@@ -57,7 +57,7 @@ bool PluginStream::Open(const std::string &mime_type,
 #elif defined(OS_POSIX)
     FilePath path(gurl.path());
 #endif
-    if (webkit_glue::GetMimeTypeFromFile(path, &temp_mime_type))
+    if (net::GetMimeTypeFromFile(path, &temp_mime_type))
       char_mime_type = temp_mime_type.c_str();
   }
 
diff --git a/webkit/glue/simple_webmimeregistry_impl.cc b/webkit/glue/simple_webmimeregistry_impl.cc
new file mode 100644
index 0000000..a662958
--- /dev/null
+++ b/webkit/glue/simple_webmimeregistry_impl.cc
@@ -0,0 +1,61 @@
+// 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.
+
+// TODO(darin): This include should not be necessary, but for some reason the
+// Mac build requires it.
+#include "config.h"
+
+#include "webkit/glue/simple_webmimeregistry_impl.h"
+
+#include "WebString.h"
+
+#include "base/string_util.h"
+#include "base/sys_string_conversions.h"
+#include "net/base/mime_util.h"
+#include "webkit/glue/glue_util.h"
+
+using WebKit::WebString;
+
+namespace webkit_glue {
+
+bool SimpleWebMimeRegistryImpl::supportsImageMIMEType(
+    const WebString& mime_type) {
+  return net::IsSupportedImageMimeType(UTF16ToASCII(mime_type).c_str());
+}
+
+bool SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType(
+    const WebString& mime_type) {
+  return net::IsSupportedJavascriptMimeType(UTF16ToASCII(mime_type).c_str());
+}
+
+bool SimpleWebMimeRegistryImpl::supportsNonImageMIMEType(
+    const WebString& mime_type) {
+  return net::IsSupportedNonImageMimeType(UTF16ToASCII(mime_type).c_str());
+}
+
+WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension(
+    const WebString& file_extension) {
+  std::string mime_type;
+  net::GetMimeTypeFromExtension(
+      WebStringToFilePathString(file_extension), &mime_type);
+  return ASCIIToUTF16(mime_type);
+}
+
+WebString SimpleWebMimeRegistryImpl::mimeTypeFromFile(
+    const WebString& file_path) {
+  std::string mime_type;
+  net::GetMimeTypeFromFile(
+      FilePath(WebStringToFilePathString(file_path)), &mime_type);
+  return ASCIIToUTF16(mime_type);
+}
+
+WebString SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType(
+    const WebString& mime_type) {
+  FilePath::StringType file_extension;
+  net::GetPreferredExtensionForMimeType(UTF16ToASCII(mime_type),
+                                        &file_extension);
+  return FilePathStringToWebString(file_extension);
+}
+
+}  // namespace webkit_glue
diff --git a/webkit/glue/simple_webmimeregistry_impl.h b/webkit/glue/simple_webmimeregistry_impl.h
new file mode 100644
index 0000000..778dee0
--- /dev/null
+++ b/webkit/glue/simple_webmimeregistry_impl.h
@@ -0,0 +1,26 @@
+// 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 WEBMIMEREGISTRY_IMPL_H_
+#define WEBMIMEREGISTRY_IMPL_H_
+
+#include "WebMimeRegistry.h"
+
+namespace webkit_glue {
+
+class SimpleWebMimeRegistryImpl : public WebKit::WebMimeRegistry {
+ public:
+  // WebMimeRegistry methods:
+  virtual bool supportsImageMIMEType(const WebKit::WebString&);
+  virtual bool supportsJavaScriptMIMEType(const WebKit::WebString&);
+  virtual bool supportsNonImageMIMEType(const WebKit::WebString&);
+  virtual WebKit::WebString mimeTypeForExtension(const WebKit::WebString&);
+  virtual WebKit::WebString mimeTypeFromFile(const WebKit::WebString&);
+  virtual WebKit::WebString preferredExtensionForMIMEType(
+      const WebKit::WebString&);
+};
+
+}  // namespace webkit_glue
+
+#endif  // WEBMIMEREGISTRY_IMPL_H_
diff --git a/webkit/glue/webkit_client_impl.cc b/webkit/glue/webkit_client_impl.cc
deleted file mode 100644
index 2389a71..0000000
--- a/webkit/glue/webkit_client_impl.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-// 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.
-
-// TODO(darin): This include should not be necessary, but for some reason the
-// Mac build requires it.
-#include "config.h"
-
-#include "webkit/glue/webkit_client_impl.h"
-
-namespace webkit_glue {
-
-WebKit::WebClipboard* WebKitClientImpl::clipboard() {
-  if (!clipboard_.get())
-    clipboard_.reset(new WebClipboardImpl());
-  return clipboard_.get();
-}
-
-}  // namespace webkit_glue
diff --git a/webkit/glue/webkit_client_impl.h b/webkit/glue/webkit_client_impl.h
deleted file mode 100644
index e2ff98a..0000000
--- a/webkit/glue/webkit_client_impl.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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 WEBKIT_CLIENT_IMPL_H_
-#define WEBKIT_CLIENT_IMPL_H_
-
-#include "WebKitClient.h"
-
-#include "base/scoped_ptr.h"
-#include "webkit/glue/webclipboard_impl.h"
-
-namespace webkit_glue {
-
-class WebKitClientImpl : public WebKit::WebKitClient {
- public:
-  // WebKitClient methods:
-  virtual WebKit::WebClipboard* clipboard();
-
- private:
-  scoped_ptr<WebClipboardImpl> clipboard_;
-};
-
-}  // namespace webkit_glue
-
-#endif  // WEBKIT_CLIENT_IMPL_H_
diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h
index aca3250..579ca5d 100644
--- a/webkit/glue/webkit_glue.h
+++ b/webkit/glue/webkit_glue.h
@@ -162,21 +162,6 @@ void PrecacheUrl(const char16* url, int url_length);
 // This function is called to add a line to the application's log file.
 void AppendToLog(const char* filename, int line, const char* message);
 
-// Get the mime type (if any) that is associated with the given file extension.
-// Returns true if a corresponding mime type exists.
-bool GetMimeTypeFromExtension(const FilePath::StringType& ext,
-                              std::string* mime_type);
-
-// Get the mime type (if any) that is associated with the given file.
-// Returns true if a corresponding mime type exists.
-bool GetMimeTypeFromFile(const FilePath& file_path, std::string* mime_type);
-
-// Get the preferred extension (if any) associated with the given mime type.
-// Returns true if a corresponding file extension exists.  The extension does
-// not include a prefixed dot, ex "html".
-bool GetPreferredExtensionForMimeType(const std::string& mime_type,
-                                      FilePath::StringType* ext);
-
 // Sets a cookie string for the given URL.  The policy_url argument indicates
 // the URL of the topmost frame, which may be useful for determining whether or
 // not to allow this cookie setting.  NOTE: the cookie string is a standard
diff --git a/webkit/glue/webkitclient_impl.cc b/webkit/glue/webkitclient_impl.cc
new file mode 100644
index 0000000..a243716
--- /dev/null
+++ b/webkit/glue/webkitclient_impl.cc
@@ -0,0 +1,17 @@
+// 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.
+
+// TODO(darin): This include should not be necessary, but for some reason the
+// Mac build requires it.
+#include "config.h"
+
+#include "webkit/glue/webkitclient_impl.h"
+
+namespace webkit_glue {
+
+WebKit::WebClipboard* WebKitClientImpl::clipboard() {
+  return &clipboard_;
+}
+
+}  // namespace webkit_glue
diff --git a/webkit/glue/webkitclient_impl.h b/webkit/glue/webkitclient_impl.h
new file mode 100644
index 0000000..481a5fe
--- /dev/null
+++ b/webkit/glue/webkitclient_impl.h
@@ -0,0 +1,27 @@
+// 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 WEBKIT_CLIENT_IMPL_H_
+#define WEBKIT_CLIENT_IMPL_H_
+
+#include "WebKitClient.h"
+
+#include "base/scoped_ptr.h"
+#include "webkit/glue/webclipboard_impl.h"
+
+namespace webkit_glue {
+
+class WebKitClientImpl : public WebKit::WebKitClient {
+ public:
+  // WebKitClient methods:
+  virtual WebKit::WebClipboard* clipboard();
+  virtual WebKit::WebMimeRegistry* mimeRegistry() = 0;
+
+ private:
+  WebClipboardImpl clipboard_;
+};
+
+}  // namespace webkit_glue
+
+#endif  // WEBKIT_CLIENT_IMPL_H_
diff --git a/webkit/tools/test_shell/mac/TestShell.xcodeproj/project.pbxproj b/webkit/tools/test_shell/mac/TestShell.xcodeproj/project.pbxproj
index 6f841f5b..10ce2f9 100644
--- a/webkit/tools/test_shell/mac/TestShell.xcodeproj/project.pbxproj
+++ b/webkit/tools/test_shell/mac/TestShell.xcodeproj/project.pbxproj
@@ -715,6 +715,13 @@
 			remoteGlobalIDString = 937A16010F53326C003E8D2D;
 			remoteInfo = webkit;
 		};
+		938D0FF30F573E28009F1128 /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = 829E2E250DBE7DE200819EBF /* webkit.xcodeproj */;
+			proxyType = 1;
+			remoteGlobalIDString = 937A15B60F53326C003E8D2D /* webkit */;
+			remoteInfo = webkit;
+		};
 		E4506A370EF020EE003BE099 /* PBXContainerItemProxy */ = {
 			isa = PBXContainerItemProxy;
 			containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */;
@@ -796,6 +803,7 @@
 		82F39A1C0E7EF85C00785E15 /* gtest.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = gtest.xcodeproj; path = testing/gtest.xcodeproj; sourceTree = "<group>"; };
 		82F39CFF0E7EF95A00785E15 /* modp_b64.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = modp_b64.xcodeproj; path = third_party/modp_b64/modp_b64.xcodeproj; sourceTree = "<group>"; };
 		8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
+		938D0FAF0F5737AC009F1128 /* test_shell_webkit_init.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = test_shell_webkit_init.h; sourceTree = "<group>"; };
 		93AF4F300EFAFE2C0073C62D /* BMPImageDecoder_unittest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BMPImageDecoder_unittest.cpp; path = ../../webcore_unit_tests/BMPImageDecoder_unittest.cpp; sourceTree = SOURCE_ROOT; };
 		93AF4F310EFAFE2C0073C62D /* GKURL_unittest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = GKURL_unittest.cpp; path = ../../webcore_unit_tests/GKURL_unittest.cpp; sourceTree = SOURCE_ROOT; };
 		93AF4F320EFAFE2C0073C62D /* ICOImageDecoder_unittest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ICOImageDecoder_unittest.cpp; path = ../../webcore_unit_tests/ICOImageDecoder_unittest.cpp; sourceTree = SOURCE_ROOT; };
@@ -1313,6 +1321,7 @@
 				ABCF253B0DB8436B00099567 /* test_shell_switches.h */,
 				AB8A786E0DC5544D005C27B8 /* test_shell_test.h */,
 				AB8A78560DC553C7005C27B8 /* test_shell_test.cc */,
+				938D0FAF0F5737AC009F1128 /* test_shell_webkit_init.h */,
 				F479F6560F2F8319000C19D4 /* test_shell_win.cc */,
 				E44662060ECCD652000B9316 /* test_webview_delegate.cc */,
 				AB8A78590DC553D7005C27B8 /* test_webview_delegate.h */,
@@ -1426,6 +1435,7 @@
 				82F39D4C0E7EFDB500785E15 /* PBXTargetDependency */,
 				82F39D4E0E7EFDB500785E15 /* PBXTargetDependency */,
 				82F39CF70E7EF91900785E15 /* PBXTargetDependency */,
+				938D0FF40F573E28009F1128 /* PBXTargetDependency */,
 			);
 			name = TestShell;
 			productInstallPath = "$(HOME)/Applications";
@@ -2154,6 +2164,11 @@
 			name = v8;
 			targetProxy = 82F39D4D0E7EFDB500785E15 /* PBXContainerItemProxy */;
 		};
+		938D0FF40F573E28009F1128 /* PBXTargetDependency */ = {
+			isa = PBXTargetDependency;
+			name = webkit;
+			targetProxy = 938D0FF30F573E28009F1128 /* PBXContainerItemProxy */;
+		};
 		E4506A380EF020EE003BE099 /* PBXTargetDependency */ = {
 			isa = PBXTargetDependency;
 			target = E45067A70EEF2776003BE099 /* test_shell_tests */;
diff --git a/webkit/tools/test_shell/run_all_tests.cc b/webkit/tools/test_shell/run_all_tests.cc
index 579338b..df6a1ae 100644
--- a/webkit/tools/test_shell/run_all_tests.cc
+++ b/webkit/tools/test_shell/run_all_tests.cc
@@ -23,6 +23,7 @@
 #include "webkit/tools/test_shell/test_shell.h"
 #include "webkit/tools/test_shell/test_shell_platform_delegate.h"
 #include "webkit/tools/test_shell/test_shell_test.h"
+#include "webkit/tools/test_shell/test_shell_webkit_init.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 const char* TestShellTest::kJavascriptDelayExitScript = 
@@ -61,7 +62,8 @@ int main(int argc, char* argv[]) {
   // request than automatically quit.
   TestShell::InitializeTestShell(true);
 
-  webkit_glue::InitializeForTesting();
+  // Initialize WebKit for this scope.
+  TestShellWebKitInit test_shell_webkit_init(true);
 
   // Allocate a message loop for this thread.  Although it is not used
   // directly, its constructor sets up some necessary state.
diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc
index 086c305..66a9fc6 100755
--- a/webkit/tools/test_shell/test_shell.cc
+++ b/webkit/tools/test_shell/test_shell.cc
@@ -559,21 +559,6 @@ void AppendToLog(const char* file, int line, const char* msg) {
   logging::LogMessage(file, line).stream() << msg;
 }
 
-bool GetMimeTypeFromExtension(const FilePath::StringType& ext,
-                              std::string *mime_type) {
-  return net::GetMimeTypeFromExtension(ext, mime_type);
-}
-
-bool GetMimeTypeFromFile(const FilePath& file_path,
-                         std::string *mime_type) {
-  return net::GetMimeTypeFromFile(file_path, mime_type);
-}
-
-bool GetPreferredExtensionForMimeType(const std::string& mime_type,
-                                      FilePath::StringType* ext) {
-  return net::GetPreferredExtensionForMimeType(mime_type, ext);
-}
-
 #if defined(OS_MACOSX)
 SkBitmap*
 #else
diff --git a/webkit/tools/test_shell/test_shell.vcproj b/webkit/tools/test_shell/test_shell.vcproj
index 0a02735..6659101 100644
--- a/webkit/tools/test_shell/test_shell.vcproj
+++ b/webkit/tools/test_shell/test_shell.vcproj
@@ -294,6 +294,10 @@
 			>
 		</File>
 		<File
+			RelativePath=".\test_shell_webkit_init.h"
+			>
+		</File>
+		<File
 			RelativePath=".\test_shell_win.cc"
 			>
 		</File>
diff --git a/webkit/tools/test_shell/test_shell_main.cc b/webkit/tools/test_shell/test_shell_main.cc
index 795b17b..d042226 100644
--- a/webkit/tools/test_shell/test_shell_main.cc
+++ b/webkit/tools/test_shell/test_shell_main.cc
@@ -25,7 +25,6 @@
 #include "net/http/http_cache.h"
 #include "net/base/ssl_test_util.h"
 #include "net/url_request/url_request_context.h"
-#include "webkit/glue/webkit_client_impl.h"
 #include "webkit/glue/webkit_glue.h"
 #include "webkit/glue/window_open_disposition.h"
 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
@@ -33,6 +32,7 @@
 #include "webkit/tools/test_shell/test_shell_platform_delegate.h"
 #include "webkit/tools/test_shell/test_shell_request_context.h"
 #include "webkit/tools/test_shell/test_shell_switches.h"
+#include "webkit/tools/test_shell/test_shell_webkit_init.h"
 
 #include "WebKit.h"
 
@@ -88,17 +88,13 @@ int main(int argc, char* argv[]) {
                          layout_test_mode,
                          enable_gp_fault_error_box);
 
-  webkit_glue::WebKitClientImpl webkit_client_impl;
-  WebKit::initialize(&webkit_client_impl);
-
-  // Set this early before we start using WebCore.
-  webkit_glue::SetLayoutTestMode(layout_test_mode);
+  // Initialize WebKit for this scope.
+  TestShellWebKitInit test_shell_webkit_init(layout_test_mode);
 
   // Suppress abort message in v8 library in debugging mode.
   // V8 calls abort() when it hits assertion errors.
-  if (suppress_error_dialogs) {
+  if (suppress_error_dialogs)
     platform.SuppressErrorReporting();
-  }
 
   if (parsed_command_line.HasSwitch(test_shell::kEnableTracing))
     base::TraceLog::StartTracing();
diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h
new file mode 100644
index 0000000..a10102a
--- /dev/null
+++ b/webkit/tools/test_shell/test_shell_webkit_init.h
@@ -0,0 +1,35 @@
+// 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 WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBKIT_INIT_H_
+#define WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBKIT_INIT_H_
+
+#include "webkit/glue/simple_webmimeregistry_impl.h"
+#include "webkit/glue/webkit_glue.h"
+#include "webkit/glue/webkitclient_impl.h"
+
+#include "WebKit.h"
+
+class TestShellWebKitInit : public webkit_glue::WebKitClientImpl {
+ public:
+  TestShellWebKitInit(bool layout_test_mode) {
+    WebKit::initialize(this);
+
+    // TODO(darin): This should eventually be a property of WebKitClientImpl.
+    webkit_glue::SetLayoutTestMode(layout_test_mode);
+  }
+
+  ~TestShellWebKitInit() {
+    WebKit::shutdown();
+  }
+
+  virtual WebKit::WebMimeRegistry* mimeRegistry() {
+    return &mime_registry_;
+  }
+
+ private:
+  webkit_glue::SimpleWebMimeRegistryImpl mime_registry_;
+};
+
+#endif  // WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_WEBKIT_INIT_H_
diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp
index 3533faf..69a5cc5 100644
--- a/webkit/webkit.gyp
+++ b/webkit/webkit.gyp
@@ -4039,6 +4039,7 @@
         '../third_party/WebKit/WebKit/chromium/public/WebImage.h',
         '../third_party/WebKit/WebKit/chromium/public/WebKit.h',
         '../third_party/WebKit/WebKit/chromium/public/WebKitClient.h',
+        '../third_party/WebKit/WebKit/chromium/public/WebMimeRegistry.h',
         '../third_party/WebKit/WebKit/chromium/public/WebPoint.h',
         '../third_party/WebKit/WebKit/chromium/public/WebRect.h',
         '../third_party/WebKit/WebKit/chromium/public/WebSize.h',
@@ -4233,6 +4234,8 @@
         'glue/searchable_form_data.cc',
         'glue/searchable_form_data.h',
         'glue/simple_clipboard_impl.cc',
+        'glue/simple_webmimeregistry_impl.cc',
+        'glue/simple_webmimeregistry_impl.h',
         'glue/stacking_order_iterator.cc',
         'glue/stacking_order_iterator.h',
         'glue/tools_proxy.h',
@@ -4266,8 +4269,8 @@
         'glue/webinputevent_linux.cc',
         'glue/webinputevent_mac.mm',
         'glue/webinputevent_win.cc',
-        'glue/webkit_client_impl.cc',
-        'glue/webkit_client_impl.h',
+        'glue/webkitclient_impl.cc',
+        'glue/webkitclient_impl.h',
         'glue/webkit_glue.cc',
         'glue/webkit_glue.h',
         'glue/webkit_glue_gtk.cc',
diff --git a/webkit/webkit.xcodeproj/project.pbxproj b/webkit/webkit.xcodeproj/project.pbxproj
index b959e0f..1e03a77 100644
--- a/webkit/webkit.xcodeproj/project.pbxproj
+++ b/webkit/webkit.xcodeproj/project.pbxproj
@@ -1319,7 +1319,8 @@
 		9389E8310F55C4550035E7D0 /* WebKit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9389E82C0F55C4550035E7D0 /* WebKit.cpp */; };
 		9389E8320F55C4550035E7D0 /* WebURL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9389E82E0F55C4550035E7D0 /* WebURL.cpp */; };
 		9389E8370F55C4810035E7D0 /* webclipboard_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9389E8330F55C4810035E7D0 /* webclipboard_impl.cc */; };
-		9389E8380F55C4810035E7D0 /* webkit_client_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9389E8350F55C4810035E7D0 /* webkit_client_impl.cc */; };
+		938D0F750F573770009F1128 /* simple_webmimeregistry_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 938D0F710F573770009F1128 /* simple_webmimeregistry_impl.cc */; };
+		938D0F760F573770009F1128 /* webkitclient_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 938D0F730F573770009F1128 /* webkitclient_impl.cc */; };
 		93AF52490F001CAB0073C62D /* media_player_private_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 93AF52480F001CAB0073C62D /* media_player_private_impl.cc */; };
 		93AF57990F0198CD0073C62D /* webkit_glue_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93AF57980F0198CD0073C62D /* webkit_glue_mac.mm */; };
 		A5779DD6BC0DA17AB7DE63D4 /* GCController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 715E874BCC05E0A3DD5E5D8F /* GCController.cpp */; };
@@ -4138,8 +4139,11 @@
 		9389E82E0F55C4550035E7D0 /* WebURL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebURL.cpp; path = ../third_party/WebKit/WebKit/chromium/src/WebURL.cpp; sourceTree = SOURCE_ROOT; };
 		9389E8330F55C4810035E7D0 /* webclipboard_impl.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = webclipboard_impl.cc; sourceTree = "<group>"; };
 		9389E8340F55C4810035E7D0 /* webclipboard_impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = webclipboard_impl.h; sourceTree = "<group>"; };
-		9389E8350F55C4810035E7D0 /* webkit_client_impl.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = webkit_client_impl.cc; sourceTree = "<group>"; };
-		9389E8360F55C4810035E7D0 /* webkit_client_impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = webkit_client_impl.h; sourceTree = "<group>"; };
+		938D0F700F573741009F1128 /* WebMimeRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebMimeRegistry.h; path = ../third_party/WebKit/WebKit/chromium/public/WebMimeRegistry.h; sourceTree = SOURCE_ROOT; };
+		938D0F710F573770009F1128 /* simple_webmimeregistry_impl.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = simple_webmimeregistry_impl.cc; sourceTree = "<group>"; };
+		938D0F720F573770009F1128 /* simple_webmimeregistry_impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = simple_webmimeregistry_impl.h; sourceTree = "<group>"; };
+		938D0F730F573770009F1128 /* webkitclient_impl.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = webkitclient_impl.cc; sourceTree = "<group>"; };
+		938D0F740F573770009F1128 /* webkitclient_impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = webkitclient_impl.h; sourceTree = "<group>"; };
 		93AF4D040EFAF0090073C62D /* ScrollView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollView.cpp; sourceTree = "<group>"; };
 		93AF52480F001CAB0073C62D /* media_player_private_impl.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = media_player_private_impl.cc; sourceTree = "<group>"; };
 		93AF525D0F002E930073C62D /* KURLGoogle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KURLGoogle.cpp; sourceTree = "<group>"; };
@@ -7711,8 +7715,8 @@
 				825405080D92E3DA0006B936 /* dragclient_impl.h */,
 				825405090D92E3DA0006B936 /* editor_client_impl.cc */,
 				8254050A0D92E3DA0006B936 /* editor_client_impl.h */,
-				E4506C0E0EF03A2F003BE099 /* entity_map.h */,
 				E4506C0F0EF03A2F003BE099 /* entity_map.cc */,
+				E4506C0E0EF03A2F003BE099 /* entity_map.h */,
 				8254050B0D92E3DA0006B936 /* event_conversion.cc */,
 				8254050C0D92E3DA0006B936 /* event_conversion.h */,
 				8254050F0D92E3DA0006B936 /* feed_preview.cc */,
@@ -7752,6 +7756,8 @@
 				8254052C0D92E3DA0006B936 /* searchable_form_data.cc */,
 				8254052D0D92E3DA0006B936 /* searchable_form_data.h */,
 				8254052E0D92E3DA0006B936 /* simple_clipboard_impl.cc */,
+				938D0F710F573770009F1128 /* simple_webmimeregistry_impl.cc */,
+				938D0F720F573770009F1128 /* simple_webmimeregistry_impl.h */,
 				AB9552AD0F37AC0B0015C8FB /* stacking_order_iterator.cc */,
 				8254052F0D92E3DA0006B936 /* unittest_test_server.h */,
 				9389E8330F55C4810035E7D0 /* webclipboard_impl.cc */,
@@ -7779,12 +7785,12 @@
 				825405420D92E3DA0006B936 /* webhistoryitem_impl.h */,
 				825405450D92E3DA0006B936 /* webinputevent.h */,
 				825405440D92E3DA0006B936 /* webinputevent_mac.mm */,
-				9389E8350F55C4810035E7D0 /* webkit_client_impl.cc */,
-				9389E8360F55C4810035E7D0 /* webkit_client_impl.h */,
-				825405470D92E3DB0006B936 /* webkit_glue.h */,
 				825405460D92E3DA0006B936 /* webkit_glue.cc */,
+				825405470D92E3DB0006B936 /* webkit_glue.h */,
 				93AF57980F0198CD0073C62D /* webkit_glue_mac.mm */,
 				8254054A0D92E3DB0006B936 /* webkit_strings.grd */,
+				938D0F730F573770009F1128 /* webkitclient_impl.cc */,
+				938D0F740F573770009F1128 /* webkitclient_impl.h */,
 				8254054F0D92E3DB0006B936 /* webplugin.h */,
 				1459AC310DEBF6A597167F45 /* webplugin_delegate.cc */,
 				8254054B0D92E3DB0006B936 /* webplugin_delegate.h */,
@@ -7863,6 +7869,7 @@
 		937A15B10F5331F7003E8D2D /* public */ = {
 			isa = PBXGroup;
 			children = (
+				938D0F700F573741009F1128 /* WebMimeRegistry.h */,
 				9389E81F0F55C4110035E7D0 /* WebClipboard.h */,
 				937A15B40F533249003E8D2D /* WebCommon.h */,
 				9389E8200F55C4110035E7D0 /* WebCString.h */,
@@ -9791,7 +9798,8 @@
 				E45626F30E268F03005E4685 /* webwidget_impl.cc in Sources */,
 				ABF923090F3A388C009B64EC /* webplugin_delegate_impl_mac.cc in Sources */,
 				9389E8370F55C4810035E7D0 /* webclipboard_impl.cc in Sources */,
-				9389E8380F55C4810035E7D0 /* webkit_client_impl.cc in Sources */,
+				938D0F750F573770009F1128 /* simple_webmimeregistry_impl.cc in Sources */,
+				938D0F760F573770009F1128 /* webkitclient_impl.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -10410,7 +10418,6 @@
 			isa = XCBuildConfiguration;
 			baseConfigurationReference = 7BF884300E71C120000BAF8A /* staticlib.xcconfig */;
 			buildSettings = {
-				GCC_PREFIX_HEADER = ../third_party/WebKit/WebCore/WebCorePrefix.h;
 				HEADER_SEARCH_PATHS = (
 					"$(HEADER_SEARCH_PATHS)",
 					"$(CONFIGURATION_TEMP_DIR)/generated/DerivedSources/v8/bindings",
@@ -10427,7 +10434,6 @@
 			isa = XCBuildConfiguration;
 			baseConfigurationReference = 7BF884300E71C120000BAF8A /* staticlib.xcconfig */;
 			buildSettings = {
-				GCC_PREFIX_HEADER = ../third_party/WebKit/WebCore/WebCorePrefix.h;
 				HEADER_SEARCH_PATHS = (
 					"$(HEADER_SEARCH_PATHS)",
 					"$(CONFIGURATION_TEMP_DIR)/generated/DerivedSources/v8/bindings",
-- 
cgit v1.1