Remove Chromium plumbing for fixed-position-creates-stacking-context
[chromium-blink-merge.git] / content / utility / utility_thread_impl.cc
blobc94312f3787a2d5cc36d245d5fd5f7abaf600704
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/utility/utility_thread_impl.h"
7 #include <stddef.h>
9 #include "base/command_line.h"
10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_vector.h"
12 #include "content/child/blink_platform_impl.h"
13 #include "content/child/child_process.h"
14 #include "content/common/child_process_messages.h"
15 #include "content/common/plugin_list.h"
16 #include "content/common/utility_messages.h"
17 #include "content/public/common/content_switches.h"
18 #include "content/public/utility/content_utility_client.h"
19 #include "ipc/ipc_sync_channel.h"
20 #include "third_party/WebKit/public/web/WebKit.h"
22 namespace content {
24 namespace {
26 template<typename SRC, typename DEST>
27 void ConvertVector(const SRC& src, DEST* dest) {
28 dest->reserve(src.size());
29 for (typename SRC::const_iterator i = src.begin(); i != src.end(); ++i)
30 dest->push_back(typename DEST::value_type(*i));
33 } // namespace
35 UtilityThreadImpl::UtilityThreadImpl() : single_process_(false) {
36 Init();
39 UtilityThreadImpl::UtilityThreadImpl(const std::string& channel_name)
40 : ChildThread(channel_name),
41 single_process_(true) {
42 Init();
45 UtilityThreadImpl::~UtilityThreadImpl() {
48 void UtilityThreadImpl::Shutdown() {
49 ChildThread::Shutdown();
51 if (!single_process_)
52 blink::shutdown();
55 bool UtilityThreadImpl::Send(IPC::Message* msg) {
56 return ChildThread::Send(msg);
59 void UtilityThreadImpl::ReleaseProcessIfNeeded() {
60 if (batch_mode_)
61 return;
63 if (single_process_) {
64 // Close the channel to cause UtilityProcessHostImpl to be deleted. We need
65 // to take a different code path than the multi-process case because that
66 // depends on the child process going away to close the channel, but that
67 // can't happen when we're in single process mode.
68 channel()->Close();
69 } else {
70 ChildProcess::current()->ReleaseProcess();
74 #if defined(OS_WIN)
76 void UtilityThreadImpl::PreCacheFont(const LOGFONT& log_font) {
77 Send(new ChildProcessHostMsg_PreCacheFont(log_font));
80 void UtilityThreadImpl::ReleaseCachedFonts() {
81 Send(new ChildProcessHostMsg_ReleaseCachedFonts());
84 #endif // OS_WIN
86 void UtilityThreadImpl::Init() {
87 batch_mode_ = false;
88 ChildProcess::current()->AddRefProcess();
89 if (!single_process_) {
90 // We can only initialize WebKit on one thread, and in single process mode
91 // we run the utility thread on separate thread. This means that if any code
92 // needs WebKit initialized in the utility process, they need to have
93 // another path to support single process mode.
94 webkit_platform_support_.reset(new BlinkPlatformImpl);
95 blink::initialize(webkit_platform_support_.get());
97 GetContentClient()->utility()->UtilityThreadStarted();
100 bool UtilityThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
101 if (GetContentClient()->utility()->OnMessageReceived(msg))
102 return true;
104 bool handled = true;
105 IPC_BEGIN_MESSAGE_MAP(UtilityThreadImpl, msg)
106 IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Started, OnBatchModeStarted)
107 IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Finished, OnBatchModeFinished)
108 #if defined(OS_POSIX)
109 IPC_MESSAGE_HANDLER(UtilityMsg_LoadPlugins, OnLoadPlugins)
110 #endif // OS_POSIX
111 IPC_MESSAGE_UNHANDLED(handled = false)
112 IPC_END_MESSAGE_MAP()
113 return handled;
116 void UtilityThreadImpl::OnBatchModeStarted() {
117 batch_mode_ = true;
120 void UtilityThreadImpl::OnBatchModeFinished() {
121 batch_mode_ = false;
122 ReleaseProcessIfNeeded();
125 #if defined(OS_POSIX)
126 void UtilityThreadImpl::OnLoadPlugins(
127 const std::vector<base::FilePath>& plugin_paths) {
128 PluginList* plugin_list = PluginList::Singleton();
130 std::vector<WebPluginInfo> plugins;
131 // TODO(bauerb): If we restart loading plug-ins, we might mess up the logic in
132 // PluginList::ShouldLoadPlugin due to missing the previously loaded plug-ins
133 // in |plugin_groups|.
134 for (size_t i = 0; i < plugin_paths.size(); ++i) {
135 WebPluginInfo plugin;
136 if (!plugin_list->LoadPluginIntoPluginList(
137 plugin_paths[i], &plugins, &plugin))
138 Send(new UtilityHostMsg_LoadPluginFailed(i, plugin_paths[i]));
139 else
140 Send(new UtilityHostMsg_LoadedPlugin(i, plugin));
143 ReleaseProcessIfNeeded();
145 #endif
147 } // namespace content