summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-26 23:37:55 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-26 23:37:55 +0000
commit8d86fce009d9dc39300a5ec9b0559ce17ff0e44e (patch)
tree74d2f7779a00c20f7ca9ef5e88852b01f4f4619d /chrome/renderer
parent5c935c135c544163d9b3923fd9e6d612cedf05c1 (diff)
downloadchromium_src-8d86fce009d9dc39300a5ec9b0559ce17ff0e44e.zip
chromium_src-8d86fce009d9dc39300a5ec9b0559ce17ff0e44e.tar.gz
chromium_src-8d86fce009d9dc39300a5ec9b0559ce17ff0e44e.tar.bz2
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
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/render_thread.cc59
-rw-r--r--chrome/renderer/render_thread.h26
-rw-r--r--chrome/renderer/renderer.scons2
-rw-r--r--chrome/renderer/renderer.vcproj8
-rw-r--r--chrome/renderer/renderer_glue.cc41
-rw-r--r--chrome/renderer/renderer_webkitclient_impl.cc57
-rw-r--r--chrome/renderer/renderer_webkitclient_impl.h30
7 files changed, 138 insertions, 85 deletions
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_