blob: cad2d5e838ecdaa9c30b108574fef7e82598d6e8 [file] [log] [blame]
[email protected]f85f0702010-01-30 09:31:011// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
initial.commit09911bf2008-07-26 23:55:295#include "chrome/renderer/render_thread.h"
6
[email protected]da00a2882009-03-09 17:51:197#include <algorithm>
[email protected]61a9b2d82010-02-26 00:31:088#include <limits>
[email protected]75e126b932009-09-28 19:38:499#include <map>
[email protected]da00a2882009-03-09 17:51:1910#include <vector>
11
[email protected]06533c0b2009-03-05 21:39:1112#include "base/command_line.h"
[email protected]58580352010-10-26 04:07:5013#include "base/debug/trace_event.h"
[email protected]94f9a0f682009-06-15 18:30:3014#include "base/lazy_instance.h"
[email protected]bee16aab2009-08-26 15:55:0315#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3816#include "base/metrics/field_trial.h"
17#include "base/metrics/stats_table.h"
[email protected]d41041092009-10-08 06:56:5718#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2919#include "base/shared_memory.h"
[email protected]b7c7bcf2009-10-03 07:07:3420#include "base/string_util.h"
[email protected]46f36a492010-07-28 19:36:4121#include "base/task.h"
[email protected]1357c322010-12-30 22:18:5622#include "base/threading/thread_local.h"
[email protected]be1ce6a72010-08-03 14:35:2223#include "base/utf_string_conversions.h"
[email protected]7a4de7a62010-08-17 18:38:2424#include "base/values.h"
[email protected]f430b5712009-08-21 21:46:3125#include "chrome/common/appcache/appcache_dispatcher.h"
[email protected]c8865962009-12-16 07:47:3926#include "chrome/common/child_process_logging.h"
[email protected]06533c0b2009-03-05 21:39:1127#include "chrome/common/chrome_switches.h"
[email protected]26a9acf2010-12-13 19:35:0528#include "chrome/common/database_messages.h"
[email protected]017022b2009-07-27 23:06:3429#include "chrome/common/db_message_filter.h"
[email protected]56879f932010-12-13 21:05:3730#include "chrome/common/dom_storage_messages.h"
[email protected]ec7db282011-01-29 01:11:3631#include "chrome/common/extensions/extension.h"
[email protected]620161e2011-03-07 18:05:2632#include "chrome/common/extensions/extension_localization_peer.h"
[email protected]ec7db282011-01-29 01:11:3633#include "chrome/common/extensions/extension_set.h"
[email protected]78221322011-01-31 16:29:0434#include "chrome/common/gpu_messages.h"
[email protected]c1f50aa2010-02-18 03:46:5735#include "chrome/common/plugin_messages.h"
[email protected]e09ba552009-02-05 03:26:2936#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0237#include "chrome/common/render_messages_params.h"
[email protected]9b6f40e2009-06-11 15:54:2638#include "chrome/common/renderer_preferences.h"
[email protected]90a3fbb12009-02-28 01:13:4739#include "chrome/common/url_constants.h"
[email protected]2b437e232010-04-02 01:30:0840#include "chrome/common/web_database_observer_impl.h"
[email protected]8930d472009-02-21 08:05:2841#include "chrome/plugin/npobject_util.h"
[email protected]a9602de2010-03-18 23:43:1142#include "chrome/renderer/automation/dom_automation_v8_extension.h"
[email protected]dd9241932010-02-24 19:23:1343#include "chrome/renderer/cookie_message_filter.h"
[email protected]a8624712009-04-17 00:51:3544#include "chrome/renderer/devtools_agent_filter.h"
[email protected]ad1f9bd2009-07-30 20:23:1545#include "chrome/renderer/extension_groups.h"
[email protected]2747dd842010-08-27 14:22:1246#include "chrome/renderer/extensions/chrome_app_bindings.h"
[email protected]a40caa972009-04-08 18:35:3447#include "chrome/renderer/extensions/event_bindings.h"
[email protected]309d7a282009-03-24 09:18:2748#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]be77f0a2009-08-25 08:31:1749#include "chrome/renderer/extensions/js_only_v8_extensions.h"
[email protected]0aa477bd2009-03-23 22:21:4350#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]3c8e3702009-05-01 16:27:4251#include "chrome/renderer/external_extension.h"
[email protected]e13ad79b2010-07-22 21:36:5052#include "chrome/renderer/gpu_channel_host.h"
[email protected]ee68378a2010-08-10 01:05:4153#include "chrome/renderer/gpu_video_service_host.h"
[email protected]70c19a932010-05-14 12:59:1154#include "chrome/renderer/indexed_db_dispatcher.h"
[email protected]0bc46552009-04-07 21:56:4255#include "chrome/renderer/loadtimes_extension_bindings.h"
[email protected]3530cd92010-06-27 06:22:0156#include "chrome/renderer/net/renderer_net_predictor.h"
[email protected]c1f50aa2010-02-18 03:46:5757#include "chrome/renderer/plugin_channel_host.h"
[email protected]00c39612010-03-06 02:53:2858#include "chrome/renderer/render_process_impl.h"
initial.commit09911bf2008-07-26 23:55:2959#include "chrome/renderer/render_view.h"
[email protected]40bd6582009-12-04 23:49:5160#include "chrome/renderer/render_view_visitor.h"
[email protected]e13ad79b2010-07-22 21:36:5061#include "chrome/renderer/renderer_histogram_snapshots.h"
[email protected]7ef8f602010-07-30 11:09:4762#include "chrome/renderer/renderer_webidbfactory_impl.h"
[email protected]8d86fce2009-02-26 23:37:5563#include "chrome/renderer/renderer_webkitclient_impl.h"
[email protected]3ead1322010-11-19 20:01:0064#include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
[email protected]15d9c0c2010-09-10 22:36:2665#include "chrome/renderer/search_extension.h"
[email protected]ce833282010-11-04 15:48:3966#include "chrome/renderer/searchbox_extension.h"
[email protected]620161e2011-03-07 18:05:2667#include "chrome/renderer/security_filter_peer.h"
[email protected]85c55dc2009-11-06 03:05:4668#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3569#include "chrome/renderer/user_script_slave.h"
[email protected]620161e2011-03-07 18:05:2670#include "content/common/resource_dispatcher.h"
[email protected]94dc971d2011-03-05 19:08:3271#include "content/common/resource_messages.h"
[email protected]46f36a492010-07-28 19:36:4172#include "ipc/ipc_channel_handle.h"
[email protected]cb6037d2009-11-16 22:55:1773#include "ipc/ipc_platform_file.h"
[email protected]620161e2011-03-07 18:05:2674#include "net/base/net_errors.h"
[email protected]9d797f32010-04-23 07:17:5475#include "net/base/net_util.h"
[email protected]e33cba42010-08-18 23:37:0376#include "third_party/sqlite/sqlite3.h"
[email protected]1b1f3eb2009-12-01 13:48:0477#include "third_party/tcmalloc/chromium/src/google/malloc_extension.h"
[email protected]8bd0fe62011-01-17 06:44:3778#include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h"
79#include "third_party/WebKit/Source/WebKit/chromium/public/WebColor.h"
80#include "third_party/WebKit/Source/WebKit/chromium/public/WebCrossOriginPreflightResultCache.h"
81#include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h"
82#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
83#include "third_party/WebKit/Source/WebKit/chromium/public/WebFontCache.h"
84#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
85#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
86#include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
87#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h"
88#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
89#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispatcher.h"
90#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
91#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]b07f29092009-06-05 07:33:2192#include "webkit/extensions/v8/benchmarking_extension.h"
[email protected]06533c0b2009-03-05 21:39:1193#include "webkit/extensions/v8/gears_extension.h"
[email protected]06533c0b2009-03-05 21:39:1194#include "webkit/extensions/v8/playback_extension.h"
[email protected]d471190a2011-02-16 14:52:3095#include "webkit/glue/webkit_glue.h"
[email protected]e0d92f282010-04-03 06:04:2796#include "v8/include/v8.h"
[email protected]2c62b562009-01-27 19:04:5097
[email protected]94dc971d2011-03-05 19:08:3298// TODO(port)
99#if defined(OS_WIN)
100#include "chrome/plugin/plugin_channel.h"
101#else
102#include "base/scoped_handle.h"
103#include "chrome/plugin/plugin_channel_base.h"
104#endif
105
[email protected]da00a2882009-03-09 17:51:19106#if defined(OS_WIN)
107#include <windows.h>
108#include <objbase.h>
109#endif
110
[email protected]fe819f52009-12-15 07:58:11111#if defined(OS_MACOSX)
112#include "chrome/app/breakpad_mac.h"
113#endif
114
[email protected]6217d392010-03-25 22:08:35115#if defined(OS_POSIX)
116#include "ipc/ipc_channel_posix.h"
117#endif
118
[email protected]2c434b32009-03-19 06:27:47119using WebKit::WebCache;
[email protected]fede6ca12009-10-08 18:24:26120using WebKit::WebCrossOriginPreflightResultCache;
121using WebKit::WebFontCache;
[email protected]f85f0702010-01-30 09:31:01122using WebKit::WebFrame;
[email protected]adf00bc2009-11-02 18:35:00123using WebKit::WebRuntimeFeatures;
[email protected]204758c2009-10-22 03:56:30124using WebKit::WebSecurityPolicy;
[email protected]98d7127b2009-10-23 18:26:51125using WebKit::WebScriptController;
[email protected]2c434b32009-03-19 06:27:47126using WebKit::WebString;
[email protected]b7c7bcf2009-10-03 07:07:34127using WebKit::WebStorageEventDispatcher;
[email protected]50ae00ef2009-10-19 05:11:03128using WebKit::WebView;
initial.commit09911bf2008-07-26 23:55:29129
[email protected]42f1d7822009-07-23 18:17:55130namespace {
[email protected]2c434b32009-03-19 06:27:47131static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */;
[email protected]bee16aab2009-08-26 15:55:03132static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */;
[email protected]71d6d852009-12-07 22:12:36133static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */;
134static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */;
[email protected]bee16aab2009-08-26 15:55:03135
[email protected]f3ede412010-06-21 22:52:16136// Keep the global RenderThread in a TLS slot so it is impossible to access
137// incorrectly from the wrong thread.
[email protected]94f9a0f682009-06-15 18:30:30138static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls(
139 base::LINKER_INITIALIZED);
[email protected]1edc16b82009-04-07 17:45:54140
[email protected]5fa1c542009-05-05 20:36:07141#if defined(OS_POSIX)
142class SuicideOnChannelErrorFilter : public IPC::ChannelProxy::MessageFilter {
143 void OnChannelError() {
144 // On POSIX, at least, one can install an unload handler which loops
145 // forever and leave behind a renderer process which eats 100% CPU forever.
146 //
147 // This is because the terminate signals (ViewMsg_ShouldClose and the error
148 // from the IPC channel) are routed to the main message loop but never
149 // processed (because that message loop is stuck in V8).
150 //
151 // One could make the browser SIGKILL the renderers, but that leaves open a
152 // large window where a browser failure (or a user, manually terminating
153 // the browser because "it's stuck") will leave behind a process eating all
154 // the CPU.
155 //
156 // So, we install a filter on the channel so that we can process this event
157 // here and kill the process.
[email protected]fe819f52009-12-15 07:58:11158
159#if defined(OS_MACOSX)
160 // TODO(viettrungluu): crbug.com/28547: The following is needed, as a
161 // stopgap, to avoid leaking due to not releasing Breakpad properly.
162 // TODO(viettrungluu): Investigate why this is being called.
163 if (IsCrashReporterEnabled()) {
[email protected]593df612010-10-20 20:20:21164 VLOG(1) << "Cleaning up Breakpad.";
[email protected]fe819f52009-12-15 07:58:11165 DestructCrashReporter();
166 } else {
[email protected]593df612010-10-20 20:20:21167 VLOG(1) << "Breakpad not enabled; no clean-up needed.";
[email protected]fe819f52009-12-15 07:58:11168 }
169#endif // OS_MACOSX
170
[email protected]5fa1c542009-05-05 20:36:07171 _exit(0);
172 }
173};
174#endif
[email protected]40bd6582009-12-04 23:49:51175
[email protected]f85f0702010-01-30 09:31:01176class RenderViewContentSettingsSetter : public RenderViewVisitor {
177 public:
[email protected]0314ae02010-04-08 09:18:29178 RenderViewContentSettingsSetter(const GURL& url,
[email protected]f85f0702010-01-30 09:31:01179 const ContentSettings& content_settings)
[email protected]0314ae02010-04-08 09:18:29180 : url_(url),
[email protected]f85f0702010-01-30 09:31:01181 content_settings_(content_settings) {
182 }
183
184 virtual bool Visit(RenderView* render_view) {
[email protected]0314ae02010-04-08 09:18:29185 if (GURL(render_view->webview()->mainFrame()->url()) == url_)
[email protected]433819d2010-01-30 20:20:01186 render_view->SetContentSettings(content_settings_);
[email protected]f85f0702010-01-30 09:31:01187 return true;
188 }
189
190 private:
[email protected]0314ae02010-04-08 09:18:29191 GURL url_;
[email protected]f85f0702010-01-30 09:31:01192 ContentSettings content_settings_;
193
194 DISALLOW_COPY_AND_ASSIGN(RenderViewContentSettingsSetter);
195};
196
[email protected]40bd6582009-12-04 23:49:51197class RenderViewZoomer : public RenderViewVisitor {
198 public:
[email protected]b75b8292010-10-01 07:28:25199 RenderViewZoomer(const GURL& url, double zoom_level)
[email protected]9d797f32010-04-23 07:17:54200 : zoom_level_(zoom_level) {
201 host_ = net::GetHostOrSpecFromURL(url);
[email protected]40bd6582009-12-04 23:49:51202 }
203
204 virtual bool Visit(RenderView* render_view) {
205 WebView* webview = render_view->webview(); // Guaranteed non-NULL.
[email protected]b75b8292010-10-01 07:28:25206
207 // Don't set zoom level for full-page plugin since they don't use the same
208 // zoom settings.
209 if (webview->mainFrame()->document().isPluginDocument())
210 return true;
211
[email protected]9d797f32010-04-23 07:17:54212 if (net::GetHostOrSpecFromURL(GURL(webview->mainFrame()->url())) == host_)
[email protected]40bd6582009-12-04 23:49:51213 webview->setZoomLevel(false, zoom_level_);
214 return true;
215 }
216
217 private:
218 std::string host_;
[email protected]b75b8292010-10-01 07:28:25219 double zoom_level_;
[email protected]40bd6582009-12-04 23:49:51220
221 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer);
222};
[email protected]0478d0162010-08-28 08:29:40223
[email protected]620161e2011-03-07 18:05:26224class RenderResourceObserver : public ResourceDispatcher::Observer {
225 public:
226 RenderResourceObserver() {
227 }
228
229 virtual webkit_glue::ResourceLoaderBridge::Peer* OnRequestComplete(
230 webkit_glue::ResourceLoaderBridge::Peer* current_peer,
231 ResourceType::Type resource_type,
232 const net::URLRequestStatus& status) {
[email protected]a37ea302011-03-07 18:39:47233 // Update the browser about our cache.
234 RenderThread::current()->InformHostOfCacheStatsLater();
235
[email protected]620161e2011-03-07 18:05:26236 if (status.status() != net::URLRequestStatus::CANCELED ||
237 status.os_error() == net::ERR_ABORTED) {
238 return NULL;
239 }
240
241 // Resource canceled with a specific error are filtered.
242 return SecurityFilterPeer::CreateSecurityFilterPeerForDeniedRequest(
243 resource_type, current_peer, status.os_error());
244 }
245
246 virtual webkit_glue::ResourceLoaderBridge::Peer* OnReceivedResponse(
247 webkit_glue::ResourceLoaderBridge::Peer* current_peer,
248 const std::string& mime_type,
249 const GURL& url) {
250 return ExtensionLocalizationPeer::CreateExtensionLocalizationPeer(
251 current_peer, RenderThread::current(), mime_type, url);
252 }
253
254 private:
255 DISALLOW_COPY_AND_ASSIGN(RenderResourceObserver);
256};
257
[email protected]42f1d7822009-07-23 18:17:55258} // namespace
259
260// When we run plugins in process, we actually run them on the render thread,
261// which means that we need to make the render thread pump UI events.
262RenderThread::RenderThread() {
263 Init();
264}
265
266RenderThread::RenderThread(const std::string& channel_name)
267 : ChildThread(channel_name) {
268 Init();
269}
[email protected]5fa1c542009-05-05 20:36:07270
initial.commit09911bf2008-07-26 23:55:29271void RenderThread::Init() {
[email protected]a872ea1f2010-08-11 04:45:33272 TRACE_EVENT_BEGIN("RenderThread::Init", 0, "");
273
[email protected]94f9a0f682009-06-15 18:30:30274 lazy_tls.Pointer()->Set(this);
[email protected]2c62b562009-01-27 19:04:50275#if defined(OS_WIN)
[email protected]bdef78b52009-04-16 19:31:34276 // If you are running plugins in this thread you need COM active but in
277 // the normal case you don't.
[email protected]00c39612010-03-06 02:53:28278 if (RenderProcessImpl::InProcessPlugins())
[email protected]bdef78b52009-04-16 19:31:34279 CoInitialize(0);
[email protected]2c62b562009-01-27 19:04:50280#endif
initial.commit09911bf2008-07-26 23:55:29281
[email protected]71d6d852009-12-07 22:12:36282 std::string type_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
283 switches::kProcessType);
[email protected]31f87132010-04-21 23:36:21284 // In single process the single process is all there is.
285 is_extension_process_ = type_str == switches::kExtensionProcess ||
286 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess);
[email protected]b2a74ca2010-03-12 17:57:09287 is_incognito_process_ = false;
[email protected]80fc08c52010-03-09 07:43:50288 suspend_webkit_shared_timer_ = true;
289 notify_webkit_of_modal_loop_ = true;
[email protected]42f1d7822009-07-23 18:17:55290 plugin_refresh_allowed_ = true;
[email protected]bee16aab2009-08-26 15:55:03291 cache_stats_task_pending_ = false;
292 widget_count_ = 0;
293 hidden_widget_count_ = 0;
[email protected]71d6d852009-12-07 22:12:36294 idle_notification_delay_in_s_ = is_extension_process_ ?
295 kInitialExtensionIdleHandlerDelayS : kInitialIdleHandlerDelayS;
[email protected]bee16aab2009-08-26 15:55:03296 task_factory_.reset(new ScopedRunnableMethodFactory<RenderThread>(this));
[email protected]8d86fce2009-02-26 23:37:55297
[email protected]620161e2011-03-07 18:05:26298 resource_dispatcher()->set_observer(new RenderResourceObserver());
299
[email protected]8d86fce2009-02-26 23:37:55300 visited_link_slave_.reset(new VisitedLinkSlave());
[email protected]2a521c52011-01-26 18:45:21301 user_script_slave_.reset(new UserScriptSlave(&extensions_));
[email protected]74be069e82010-06-25 00:12:49302 renderer_net_predictor_.reset(new RendererNetPredictor());
[email protected]8d86fce2009-02-26 23:37:55303 histogram_snapshots_.reset(new RendererHistogramSnapshots());
[email protected]f430b5712009-08-21 21:46:31304 appcache_dispatcher_.reset(new AppCacheDispatcher(this));
[email protected]70c19a932010-05-14 12:59:11305 indexed_db_dispatcher_.reset(new IndexedDBDispatcher());
[email protected]dd9241932010-02-24 19:23:13306 spellchecker_.reset(new SpellCheck());
307
[email protected]a8624712009-04-17 00:51:35308 devtools_agent_filter_ = new DevToolsAgentFilter();
309 AddFilter(devtools_agent_filter_.get());
[email protected]dd9241932010-02-24 19:23:13310
[email protected]017022b2009-07-27 23:06:34311 db_message_filter_ = new DBMessageFilter();
312 AddFilter(db_message_filter_.get());
[email protected]dd9241932010-02-24 19:23:13313
314 cookie_message_filter_ = new CookieMessageFilter();
315 AddFilter(cookie_message_filter_.get());
[email protected]5fa1c542009-05-05 20:36:07316
317#if defined(OS_POSIX)
318 suicide_on_channel_error_filter_ = new SuicideOnChannelErrorFilter;
319 AddFilter(suicide_on_channel_error_filter_.get());
320#endif
[email protected]515c7162010-07-12 23:46:17321
[email protected]a872ea1f2010-08-11 04:45:33322 TRACE_EVENT_END("RenderThread::Init", 0, "");
initial.commit09911bf2008-07-26 23:55:29323}
324
[email protected]42f1d7822009-07-23 18:17:55325RenderThread::~RenderThread() {
[email protected]12cbfda32010-01-30 01:04:25326 // Wait for all databases to be closed.
[email protected]2b437e232010-04-02 01:30:08327 if (web_database_observer_impl_.get())
328 web_database_observer_impl_->WaitForAllDatabasesToClose();
[email protected]12cbfda32010-01-30 01:04:25329
[email protected]8d86fce2009-02-26 23:37:55330 // Shutdown in reverse of the initialization order.
[email protected]017022b2009-07-27 23:06:34331 RemoveFilter(db_message_filter_.get());
332 db_message_filter_ = NULL;
[email protected]2b437e232010-04-02 01:30:08333 RemoveFilter(devtools_agent_filter_.get());
[email protected]12cbfda32010-01-30 01:04:25334
[email protected]c6a7b862010-08-20 22:19:38335 // Shutdown the file thread if it's running.
336 if (file_thread_.get())
337 file_thread_->Stop();
338
[email protected]42f1d7822009-07-23 18:17:55339 if (webkit_client_.get())
[email protected]9291ed12009-07-23 17:33:22340 WebKit::shutdown();
[email protected]9291ed12009-07-23 17:33:22341
[email protected]94f9a0f682009-06-15 18:30:30342 lazy_tls.Pointer()->Set(NULL);
[email protected]8fd8de92008-08-12 23:50:30343
[email protected]8d86fce2009-02-26 23:37:55344 // TODO(port)
[email protected]2c62b562009-01-27 19:04:50345#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29346 // Clean up plugin channels before this thread goes away.
347 PluginChannelBase::CleanupChannels();
[email protected]bdef78b52009-04-16 19:31:34348 // Don't call COM if the renderer is in the sandbox.
[email protected]00c39612010-03-06 02:53:28349 if (RenderProcessImpl::InProcessPlugins())
[email protected]bdef78b52009-04-16 19:31:34350 CoUninitialize();
[email protected]2c62b562009-01-27 19:04:50351#endif
initial.commit09911bf2008-07-26 23:55:29352}
353
[email protected]42f1d7822009-07-23 18:17:55354RenderThread* RenderThread::current() {
355 return lazy_tls.Pointer()->Get();
356}
357
[email protected]c1f50aa2010-02-18 03:46:57358int32 RenderThread::RoutingIDForCurrentContext() {
359 int32 routing_id = MSG_ROUTING_CONTROL;
360 if (v8::Context::InContext()) {
[email protected]d5ddf9a2010-03-04 00:48:29361 WebFrame* frame = WebFrame::frameForCurrentContext();
362 if (frame) {
363 RenderView* view = RenderView::FromWebView(frame->view());
364 if (view)
365 routing_id = view->routing_id();
366 }
[email protected]c1f50aa2010-02-18 03:46:57367 } else {
368 DLOG(WARNING) << "Not called within a script context!";
369 }
370 return routing_id;
371}
372
[email protected]ec7db282011-01-29 01:11:36373const ExtensionSet* RenderThread::GetExtensions() const {
[email protected]2a521c52011-01-26 18:45:21374 return &extensions_;
375}
376
[email protected]c1f50aa2010-02-18 03:46:57377bool RenderThread::Send(IPC::Message* msg) {
[email protected]f23d4da92010-11-24 21:36:14378 // Certain synchronous messages cannot always be processed synchronously by
379 // the browser, e.g., Chrome frame communicating with the embedding browser.
[email protected]80fc08c52010-03-09 07:43:50380 // This could cause a complete hang of Chrome if a windowed plug-in is trying
381 // to communicate with the renderer thread since the browser's UI thread
382 // could be stuck (within a Windows API call) trying to synchronously
383 // communicate with the plug-in. The remedy is to pump messages on this
[email protected]f23d4da92010-11-24 21:36:14384 // thread while the browser is processing this request. This creates an
385 // opportunity for re-entrancy into WebKit, so we need to take care to disable
386 // callbacks, timers, and pending network loads that could trigger such
387 // callbacks.
[email protected]80fc08c52010-03-09 07:43:50388 bool pumping_events = false, may_show_cookie_prompt = false;
389 if (msg->is_sync()) {
390 if (msg->is_caller_pumping_messages()) {
391 pumping_events = true;
392 } else {
393 switch (msg->type()) {
394 case ViewHostMsg_GetCookies::ID:
395 case ViewHostMsg_GetRawCookies::ID:
[email protected]f23d4da92010-11-24 21:36:14396 case ViewHostMsg_CookiesEnabled::ID:
[email protected]56879f932010-12-13 21:05:37397 case DOMStorageHostMsg_SetItem::ID:
[email protected]94dc971d2011-03-05 19:08:32398 case ResourceHostMsg_SyncLoad::ID:
[email protected]26a9acf2010-12-13 19:35:05399 case DatabaseHostMsg_Allow::ID:
[email protected]80fc08c52010-03-09 07:43:50400 may_show_cookie_prompt = true;
401 pumping_events = true;
402 break;
403 }
404 }
[email protected]c1f50aa2010-02-18 03:46:57405 }
406
[email protected]80fc08c52010-03-09 07:43:50407 bool suspend_webkit_shared_timer = true; // default value
408 std::swap(suspend_webkit_shared_timer, suspend_webkit_shared_timer_);
[email protected]c1f50aa2010-02-18 03:46:57409
[email protected]80fc08c52010-03-09 07:43:50410 bool notify_webkit_of_modal_loop = true; // default value
411 std::swap(notify_webkit_of_modal_loop, notify_webkit_of_modal_loop_);
412
413 gfx::NativeViewId host_window = 0;
[email protected]c1f50aa2010-02-18 03:46:57414
415 if (pumping_events) {
[email protected]80fc08c52010-03-09 07:43:50416 // See ViewMsg_SignalCookiePromptEvent.
417 if (may_show_cookie_prompt) {
418 static_cast<IPC::SyncMessage*>(msg)->set_pump_messages_event(
419 cookie_message_filter_->pump_messages_event());
420 }
421
422 if (suspend_webkit_shared_timer)
[email protected]c1f50aa2010-02-18 03:46:57423 webkit_client_->SuspendSharedTimer();
424
[email protected]39065d012010-07-09 11:22:46425 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57426 WebView::willEnterModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57427
[email protected]80fc08c52010-03-09 07:43:50428 RenderWidget* widget =
429 static_cast<RenderWidget*>(ResolveRoute(msg->routing_id()));
430 if (widget) {
431 host_window = widget->host_window();
[email protected]c1f50aa2010-02-18 03:46:57432 PluginChannelHost::Broadcast(
433 new PluginMsg_SignalModalDialogEvent(host_window));
434 }
435 }
436
437 bool rv = ChildThread::Send(msg);
438
439 if (pumping_events) {
440 if (host_window) {
441 PluginChannelHost::Broadcast(
442 new PluginMsg_ResetModalDialogEvent(host_window));
443 }
444
[email protected]39065d012010-07-09 11:22:46445 if (notify_webkit_of_modal_loop)
[email protected]c1f50aa2010-02-18 03:46:57446 WebView::didExitModalLoop();
[email protected]c1f50aa2010-02-18 03:46:57447
[email protected]80fc08c52010-03-09 07:43:50448 if (suspend_webkit_shared_timer)
[email protected]c1f50aa2010-02-18 03:46:57449 webkit_client_->ResumeSharedTimer();
[email protected]80fc08c52010-03-09 07:43:50450
451 // We may end up nesting calls to Send, so we defer the reset until we
452 // return to the top-most message loop.
453 if (may_show_cookie_prompt &&
454 cookie_message_filter_->pump_messages_event()->IsSignaled()) {
455 MessageLoop::current()->PostNonNestableTask(FROM_HERE,
456 NewRunnableMethod(cookie_message_filter_.get(),
457 &CookieMessageFilter::ResetPumpMessagesEvent));
458 }
[email protected]c1f50aa2010-02-18 03:46:57459 }
460
461 return rv;
462}
463
464void RenderThread::AddRoute(int32 routing_id,
465 IPC::Channel::Listener* listener) {
466 widget_count_++;
[email protected]3231c2e2010-09-02 12:41:05467 child_process_logging::SetNumberOfViews(widget_count_);
[email protected]c1f50aa2010-02-18 03:46:57468 return ChildThread::AddRoute(routing_id, listener);
469}
470
471void RenderThread::RemoveRoute(int32 routing_id) {
472 widget_count_--;
[email protected]3231c2e2010-09-02 12:41:05473 child_process_logging::SetNumberOfViews(widget_count_);
[email protected]c1f50aa2010-02-18 03:46:57474 return ChildThread::RemoveRoute(routing_id);
475}
476
[email protected]42f1d7822009-07-23 18:17:55477void RenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
478 channel()->AddFilter(filter);
479}
480
481void RenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) {
482 channel()->RemoveFilter(filter);
483}
484
[email protected]bee16aab2009-08-26 15:55:03485void RenderThread::WidgetHidden() {
486 DCHECK(hidden_widget_count_ < widget_count_);
[email protected]4a3dab22009-11-11 17:36:50487 hidden_widget_count_++;
[email protected]b8f41a192010-04-19 18:25:04488 if (!is_extension_process_ &&
[email protected]71d6d852009-12-07 22:12:36489 widget_count_ && hidden_widget_count_ == widget_count_)
490 ScheduleIdleHandler(kInitialIdleHandlerDelayS);
[email protected]bee16aab2009-08-26 15:55:03491}
492
493void RenderThread::WidgetRestored() {
[email protected]61a9b2d82010-02-26 00:31:08494 DCHECK_GT(hidden_widget_count_, 0);
[email protected]bee16aab2009-08-26 15:55:03495 hidden_widget_count_--;
[email protected]b8f41a192010-04-19 18:25:04496 if (!is_extension_process_)
[email protected]71d6d852009-12-07 22:12:36497 idle_timer_.Stop();
[email protected]bee16aab2009-08-26 15:55:03498}
499
[email protected]e4be2dd2010-12-14 00:44:39500bool RenderThread::IsExtensionProcess() const {
501 return is_extension_process_;
502}
503
504bool RenderThread::IsIncognitoProcess() const {
505 return is_incognito_process_;
506}
507
[email protected]c1f50aa2010-02-18 03:46:57508void RenderThread::DoNotSuspendWebKitSharedTimer() {
[email protected]80fc08c52010-03-09 07:43:50509 suspend_webkit_shared_timer_ = false;
[email protected]c1f50aa2010-02-18 03:46:57510}
511
512void RenderThread::DoNotNotifyWebKitOfModalLoop() {
[email protected]80fc08c52010-03-09 07:43:50513 notify_webkit_of_modal_loop_ = false;
[email protected]c1f50aa2010-02-18 03:46:57514}
515
[email protected]42f1d7822009-07-23 18:17:55516void RenderThread::Resolve(const char* name, size_t length) {
[email protected]74be069e82010-06-25 00:12:49517 return renderer_net_predictor_->Resolve(name, length);
[email protected]42f1d7822009-07-23 18:17:55518}
519
520void RenderThread::SendHistograms(int sequence_number) {
521 return histogram_snapshots_->SendHistograms(sequence_number);
522}
523
[email protected]176aa482008-11-14 03:25:15524void RenderThread::OnUpdateVisitedLinks(base::SharedMemoryHandle table) {
[email protected]5fe733de2009-02-11 18:59:20525 DCHECK(base::SharedMemory::IsHandleValid(table)) << "Bad table handle";
initial.commit09911bf2008-07-26 23:55:29526 visited_link_slave_->Init(table);
527}
528
[email protected]3e90d4a2009-07-03 17:38:39529void RenderThread::OnAddVisitedLinks(
530 const VisitedLinkSlave::Fingerprints& fingerprints) {
531 for (size_t i = 0; i < fingerprints.size(); ++i)
[email protected]50ae00ef2009-10-19 05:11:03532 WebView::updateVisitedLinkState(fingerprints[i]);
[email protected]3e90d4a2009-07-03 17:38:39533}
534
535void RenderThread::OnResetVisitedLinks() {
[email protected]50ae00ef2009-10-19 05:11:03536 WebView::resetVisitedLinkState();
[email protected]3e90d4a2009-07-03 17:38:39537}
538
[email protected]0314ae02010-04-08 09:18:29539void RenderThread::OnSetContentSettingsForCurrentURL(
540 const GURL& url,
[email protected]f85f0702010-01-30 09:31:01541 const ContentSettings& content_settings) {
[email protected]0314ae02010-04-08 09:18:29542 RenderViewContentSettingsSetter setter(url, content_settings);
[email protected]f85f0702010-01-30 09:31:01543 RenderView::ForEach(&setter);
544}
545
[email protected]9d797f32010-04-23 07:17:54546void RenderThread::OnSetZoomLevelForCurrentURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:25547 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:54548 RenderViewZoomer zoomer(url, zoom_level);
[email protected]40bd6582009-12-04 23:49:51549 RenderView::ForEach(&zoomer);
550}
551
[email protected]b2a74ca2010-03-12 17:57:09552void RenderThread::OnUpdateUserScripts(base::SharedMemoryHandle scripts) {
[email protected]5fe733de2009-02-11 18:59:20553 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle";
[email protected]ee9080642010-04-07 00:23:06554 user_script_slave_->UpdateScripts(scripts);
[email protected]c8865962009-12-16 07:47:39555 UpdateActiveExtensions();
[email protected]1e0f70402008-10-16 23:57:47556}
557
[email protected]703e807a2009-03-28 19:56:51558void RenderThread::OnSetExtensionFunctionNames(
559 const std::vector<std::string>& names) {
[email protected]a1a0df02009-04-09 08:18:04560 ExtensionProcessBindings::SetFunctionNames(names);
[email protected]703e807a2009-03-28 19:56:51561}
562
[email protected]2a521c52011-01-26 18:45:21563void RenderThread::OnExtensionLoaded(
564 const ViewMsg_ExtensionLoaded_Params& params) {
565 scoped_refptr<const Extension> extension(params.ConvertToExtension());
566 if (!extension) {
567 // This can happen if extension parsing fails for any reason. One reason
568 // this can legitimately happen is if the
569 // --enable-experimental-extension-apis changes at runtime, which happens
570 // during browser tests. Existing renderers won't know about the change.
571 return;
572 }
573
[email protected]ec7db282011-01-29 01:11:36574 extensions_.Insert(extension);
[email protected]2a521c52011-01-26 18:45:21575}
576
577void RenderThread::OnSetExtensionScriptingWhitelist(
578 const Extension::ScriptingWhitelist& extension_ids) {
579 Extension::SetScriptingWhitelist(extension_ids);
580}
581
582void RenderThread::OnExtensionUnloaded(const std::string& id) {
583 extensions_.Remove(id);
[email protected]3a8eecb2010-04-22 23:56:30584}
585
[email protected]45776222009-07-15 20:21:58586void RenderThread::OnPageActionsUpdated(
587 const std::string& extension_id,
588 const std::vector<std::string>& page_actions) {
589 ExtensionProcessBindings::SetPageActions(extension_id, page_actions);
590}
591
[email protected]cccf90932009-08-23 17:56:25592void RenderThread::OnExtensionSetAPIPermissions(
[email protected]35506352009-08-07 18:58:19593 const std::string& extension_id,
[email protected]0df165f2010-09-28 16:49:40594 const std::set<std::string>& permissions) {
[email protected]cccf90932009-08-23 17:56:25595 ExtensionProcessBindings::SetAPIPermissions(extension_id, permissions);
[email protected]71d6d852009-12-07 22:12:36596
597 // This is called when starting a new extension page, so start the idle
598 // handler ticking.
[email protected]71d6d852009-12-07 22:12:36599 ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayS);
[email protected]c8865962009-12-16 07:47:39600
601 UpdateActiveExtensions();
[email protected]cccf90932009-08-23 17:56:25602}
603
604void RenderThread::OnExtensionSetHostPermissions(
605 const GURL& extension_url, const std::vector<URLPattern>& permissions) {
606 ExtensionProcessBindings::SetHostPermissions(extension_url, permissions);
[email protected]35506352009-08-07 18:58:19607}
608
[email protected]c61cc652009-11-04 05:44:40609void RenderThread::OnDOMStorageEvent(
[email protected]56879f932010-12-13 21:05:37610 const DOMStorageMsg_Event_Params& params) {
[email protected]c61cc652009-11-04 05:44:40611 if (!dom_storage_event_dispatcher_.get())
[email protected]b7c7bcf2009-10-03 07:07:34612 dom_storage_event_dispatcher_.reset(WebStorageEventDispatcher::create());
[email protected]56879f932010-12-13 21:05:37613 dom_storage_event_dispatcher_->dispatchStorageEvent(params.key,
614 params.old_value, params.new_value, params.origin, params.url,
615 params.storage_type == DOM_STORAGE_LOCAL);
[email protected]b7c7bcf2009-10-03 07:07:34616}
617
[email protected]a95986a82010-12-24 06:19:28618bool RenderThread::OnControlMessageReceived(const IPC::Message& msg) {
[email protected]70c19a932010-05-14 12:59:11619 // Some messages are handled by delegates.
[email protected]f430b5712009-08-21 21:46:31620 if (appcache_dispatcher_->OnMessageReceived(msg))
[email protected]a95986a82010-12-24 06:19:28621 return true;
[email protected]70c19a932010-05-14 12:59:11622 if (indexed_db_dispatcher_->OnMessageReceived(msg))
[email protected]a95986a82010-12-24 06:19:28623 return true;
[email protected]1edc16b82009-04-07 17:45:54624
[email protected]a95986a82010-12-24 06:19:28625 bool handled = true;
[email protected]8930d472009-02-21 08:05:28626 IPC_BEGIN_MESSAGE_MAP(RenderThread, msg)
627 IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_NewTable, OnUpdateVisitedLinks)
[email protected]3e90d4a2009-07-03 17:38:39628 IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Add, OnAddVisitedLinks)
629 IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Reset, OnResetVisitedLinks)
[email protected]0314ae02010-04-08 09:18:29630 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForCurrentURL,
631 OnSetContentSettingsForCurrentURL)
[email protected]9d797f32010-04-23 07:17:54632 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL,
633 OnSetZoomLevelForCurrentURL)
[email protected]b2a74ca2010-03-12 17:57:09634 IPC_MESSAGE_HANDLER(ViewMsg_SetIsIncognitoProcess, OnSetIsIncognitoProcess)
[email protected]8930d472009-02-21 08:05:28635 IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID)
[email protected]b9ab10c2009-08-07 18:09:55636 IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors)
[email protected]8930d472009-02-21 08:05:28637 // TODO(port): removed from render_messages_internal.h;
638 // is there a new non-windows message I should add here?
639 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
640 IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities)
[email protected]163753f2010-10-01 20:59:03641 IPC_MESSAGE_HANDLER(ViewMsg_ClearCache, OnClearCache)
[email protected]55e57d42009-02-25 06:10:17642 IPC_MESSAGE_HANDLER(ViewMsg_GetRendererHistograms,
[email protected]c9a3ef82009-05-28 22:02:46643 OnGetRendererHistograms)
[email protected]d41041092009-10-08 06:56:57644#if defined(USE_TCMALLOC)
645 IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc,
646 OnGetRendererTcmalloc)
647#endif
[email protected]38b48a82009-11-11 01:51:32648 IPC_MESSAGE_HANDLER(ViewMsg_GetV8HeapStats, OnGetV8HeapStats)
[email protected]8930d472009-02-21 08:05:28649 IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats,
650 OnGetCacheResourceStats)
[email protected]2f2243e2009-05-26 02:27:02651 IPC_MESSAGE_HANDLER(ViewMsg_UserScripts_UpdatedScripts,
[email protected]8930d472009-02-21 08:05:28652 OnUpdateUserScripts)
[email protected]b68d5ed2009-04-16 02:41:28653 // TODO(rafaelw): create an ExtensionDispatcher that handles extension
654 // messages seperates their handling from the RenderThread.
[email protected]dfcb62a2009-06-17 19:32:43655 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
656 OnExtensionMessageInvoke)
[email protected]703e807a2009-03-28 19:56:51657 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetFunctionNames,
658 OnSetExtensionFunctionNames)
[email protected]2a521c52011-01-26 18:45:21659 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionLoaded,
660 OnExtensionLoaded)
661 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionUnloaded,
662 OnExtensionUnloaded)
663 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetScriptingWhitelist,
664 OnSetExtensionScriptingWhitelist)
[email protected]fede6ca12009-10-08 18:24:26665 IPC_MESSAGE_HANDLER(ViewMsg_PurgeMemory, OnPurgeMemory)
[email protected]b547fd42009-04-23 23:16:27666 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache,
667 OnPurgePluginListCache)
[email protected]45776222009-07-15 20:21:58668 IPC_MESSAGE_HANDLER(ViewMsg_Extension_UpdatePageActions,
669 OnPageActionsUpdated)
[email protected]cccf90932009-08-23 17:56:25670 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetAPIPermissions,
671 OnExtensionSetAPIPermissions)
672 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetHostPermissions,
673 OnExtensionSetHostPermissions)
[email protected]56879f932010-12-13 21:05:37674 IPC_MESSAGE_HANDLER(DOMStorageMsg_Event,
[email protected]b7c7bcf2009-10-03 07:07:34675 OnDOMStorageEvent)
[email protected]85c55dc2009-11-06 03:05:46676 IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_Init,
677 OnInitSpellChecker)
678 IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_WordAdded,
679 OnSpellCheckWordAdded)
680 IPC_MESSAGE_HANDLER(ViewMsg_SpellChecker_EnableAutoSpellCorrect,
681 OnSpellCheckEnableAutoSpellCorrect)
[email protected]6217d392010-03-25 22:08:35682 IPC_MESSAGE_HANDLER(ViewMsg_GpuChannelEstablished, OnGpuChannelEstablished)
[email protected]31c90db2010-09-23 00:59:18683 IPC_MESSAGE_HANDLER(ViewMsg_SetPhishingModel, OnSetPhishingModel)
[email protected]a95986a82010-12-24 06:19:28684 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]8930d472009-02-21 08:05:28685 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28686 return handled;
initial.commit09911bf2008-07-26 23:55:29687}
688
689void RenderThread::OnSetNextPageID(int32 next_page_id) {
690 // This should only be called at process initialization time, so we shouldn't
691 // have to worry about thread-safety.
692 RenderView::SetNextPageID(next_page_id);
693}
694
[email protected]b9ab10c2009-08-07 18:09:55695// Called when to register CSS Color name->system color mappings.
696// We update the colors one by one and then tell WebKit to refresh all render
697// views.
698void RenderThread::OnSetCSSColors(
699 const std::vector<CSSColors::CSSColorMapping>& colors) {
[email protected]f5e4b9bf2009-10-08 00:59:59700 EnsureWebKitInitialized();
[email protected]b9ab10c2009-08-07 18:09:55701 size_t num_colors = colors.size();
702 scoped_array<WebKit::WebColorName> color_names(
703 new WebKit::WebColorName[num_colors]);
704 scoped_array<WebKit::WebColor> web_colors(new WebKit::WebColor[num_colors]);
705 size_t i = 0;
706 for (std::vector<CSSColors::CSSColorMapping>::const_iterator it =
707 colors.begin();
708 it != colors.end();
709 ++it, ++i) {
710 color_names[i] = it->first;
711 web_colors[i] = it->second;
712 }
713 WebKit::setNamedColors(color_names.get(), web_colors.get(), num_colors);
714}
715
[email protected]4e6419c2010-01-15 04:50:34716void RenderThread::OnCreateNewView(const ViewMsg_New_Params& params) {
[email protected]90a3fbb12009-02-28 01:13:47717 EnsureWebKitInitialized();
[email protected]be645db2009-02-06 20:36:33718 // When bringing in render_view, also bring in webkit's glue and jsbindings.
initial.commit09911bf2008-07-26 23:55:29719 RenderView::Create(
[email protected]8ab04652010-06-12 02:47:26720 this,
721 params.parent_window,
722 MSG_ROUTING_NONE,
723 params.renderer_preferences,
724 params.web_preferences,
725 new SharedRenderViewCounter(0),
726 params.view_id,
727 params.session_storage_namespace_id,
728 params.frame_name);
[email protected]7f874dec2009-02-06 01:48:27729}
[email protected]4274e582009-01-27 22:09:56730
initial.commit09911bf2008-07-26 23:55:29731void RenderThread::OnSetCacheCapacities(size_t min_dead_capacity,
732 size_t max_dead_capacity,
733 size_t capacity) {
[email protected]90a3fbb12009-02-28 01:13:47734 EnsureWebKitInitialized();
[email protected]2c434b32009-03-19 06:27:47735 WebCache::setCapacities(
736 min_dead_capacity, max_dead_capacity, capacity);
initial.commit09911bf2008-07-26 23:55:29737}
738
[email protected]163753f2010-10-01 20:59:03739void RenderThread::OnClearCache() {
740 EnsureWebKitInitialized();
741 WebCache::clear();
742}
743
initial.commit09911bf2008-07-26 23:55:29744void RenderThread::OnGetCacheResourceStats() {
[email protected]90a3fbb12009-02-28 01:13:47745 EnsureWebKitInitialized();
[email protected]2c434b32009-03-19 06:27:47746 WebCache::ResourceTypeStats stats;
747 WebCache::getResourceTypeStats(&stats);
initial.commit09911bf2008-07-26 23:55:29748 Send(new ViewHostMsg_ResourceTypeStats(stats));
749}
750
[email protected]c9a3ef82009-05-28 22:02:46751void RenderThread::OnGetRendererHistograms(int sequence_number) {
752 SendHistograms(sequence_number);
[email protected]55e57d42009-02-25 06:10:17753}
754
[email protected]d41041092009-10-08 06:56:57755#if defined(USE_TCMALLOC)
756void RenderThread::OnGetRendererTcmalloc() {
757 std::string result;
758 char buffer[1024 * 32];
[email protected]a4dc33f2009-10-20 15:09:55759 base::ProcessId pid = base::GetCurrentProcId();
[email protected]d41041092009-10-08 06:56:57760 MallocExtension::instance()->GetStats(buffer, sizeof(buffer));
761 result.append(buffer);
762 Send(new ViewHostMsg_RendererTcmalloc(pid, result));
763}
764#endif
765
[email protected]38b48a82009-11-11 01:51:32766void RenderThread::OnGetV8HeapStats() {
767 v8::HeapStatistics heap_stats;
768 v8::V8::GetHeapStatistics(&heap_stats);
769 Send(new ViewHostMsg_V8HeapStats(heap_stats.total_heap_size(),
770 heap_stats.used_heap_size()));
771}
772
initial.commit09911bf2008-07-26 23:55:29773void RenderThread::InformHostOfCacheStats() {
[email protected]90a3fbb12009-02-28 01:13:47774 EnsureWebKitInitialized();
[email protected]2c434b32009-03-19 06:27:47775 WebCache::UsageStats stats;
776 WebCache::getUsageStats(&stats);
initial.commit09911bf2008-07-26 23:55:29777 Send(new ViewHostMsg_UpdatedCacheStats(stats));
[email protected]bee16aab2009-08-26 15:55:03778 cache_stats_task_pending_ = false;
initial.commit09911bf2008-07-26 23:55:29779}
780
781void RenderThread::InformHostOfCacheStatsLater() {
782 // Rate limit informing the host of our cache stats.
[email protected]bee16aab2009-08-26 15:55:03783 if (cache_stats_task_pending_)
initial.commit09911bf2008-07-26 23:55:29784 return;
785
[email protected]bee16aab2009-08-26 15:55:03786 cache_stats_task_pending_ = true;
initial.commit09911bf2008-07-26 23:55:29787 MessageLoop::current()->PostDelayedTask(FROM_HERE,
[email protected]bee16aab2009-08-26 15:55:03788 task_factory_->NewRunnableMethod(
initial.commit09911bf2008-07-26 23:55:29789 &RenderThread::InformHostOfCacheStats),
790 kCacheStatsDelayMS);
791}
[email protected]90a3fbb12009-02-28 01:13:47792
[email protected]c40acc32010-01-14 01:02:53793void RenderThread::CloseCurrentConnections() {
794 Send(new ViewHostMsg_CloseCurrentConnections());
[email protected]b07f29092009-06-05 07:33:21795}
796
797void RenderThread::SetCacheMode(bool enabled) {
798 Send(new ViewHostMsg_SetCacheMode(enabled));
799}
800
[email protected]0e34852a2011-02-15 23:14:44801void RenderThread::ClearCache(bool preserve_ssl_host_info) {
[email protected]c5d79342010-06-05 01:27:34802 int rv;
[email protected]0e34852a2011-02-15 23:14:44803 Send(new ViewHostMsg_ClearCache(preserve_ssl_host_info, &rv));
[email protected]c5d79342010-06-05 01:27:34804}
805
[email protected]12893c32010-08-19 17:30:54806void RenderThread::EnableSpdy(bool enable) {
807 Send(new ViewHostMsg_EnableSpdy(enable));
808}
809
[email protected]c8865962009-12-16 07:47:39810void RenderThread::UpdateActiveExtensions() {
811 // In single-process mode, the browser process reports the active extensions.
812 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
813 return;
814
815 std::set<std::string> active_extensions;
816 user_script_slave_->GetActiveExtensions(&active_extensions);
817 ExtensionProcessBindings::GetActiveExtensions(&active_extensions);
818 child_process_logging::SetActiveExtensions(active_extensions);
819}
820
[email protected]6217d392010-03-25 22:08:35821void RenderThread::EstablishGpuChannel() {
822 if (gpu_channel_.get()) {
[email protected]1082b1d2010-03-30 00:31:22823 // Do nothing if we already have a GPU channel or are already
824 // establishing one.
[email protected]e09cee42010-11-09 01:50:08825 if (gpu_channel_->state() == GpuChannelHost::kUnconnected ||
826 gpu_channel_->state() == GpuChannelHost::kConnected)
[email protected]6217d392010-03-25 22:08:35827 return;
828
829 // Recreate the channel if it has been lost.
[email protected]e09cee42010-11-09 01:50:08830 if (gpu_channel_->state() == GpuChannelHost::kLost)
[email protected]6217d392010-03-25 22:08:35831 gpu_channel_ = NULL;
832 }
833
834 if (!gpu_channel_.get())
835 gpu_channel_ = new GpuChannelHost;
836
837 // Ask the browser for the channel name.
[email protected]78221322011-01-31 16:29:04838 Send(new GpuHostMsg_EstablishGpuChannel());
[email protected]6217d392010-03-25 22:08:35839}
840
[email protected]3bf4d532010-03-27 00:23:34841GpuChannelHost* RenderThread::EstablishGpuChannelSync() {
[email protected]f9a2b2fe2010-07-15 21:13:23842 EstablishGpuChannel();
[email protected]78221322011-01-31 16:29:04843 Send(new GpuHostMsg_SynchronizeGpu());
[email protected]f9a2b2fe2010-07-15 21:13:23844 return GetGpuChannel();
[email protected]3bf4d532010-03-27 00:23:34845}
846
[email protected]6217d392010-03-25 22:08:35847GpuChannelHost* RenderThread::GetGpuChannel() {
848 if (!gpu_channel_.get())
849 return NULL;
850
[email protected]e09cee42010-11-09 01:50:08851 if (gpu_channel_->state() != GpuChannelHost::kConnected)
[email protected]6217d392010-03-25 22:08:35852 return NULL;
853
854 return gpu_channel_.get();
855}
856
[email protected]3df0c202009-03-31 23:51:26857static void* CreateHistogram(
858 const char *name, int min, int max, size_t buckets) {
[email protected]e8829a192009-12-06 00:09:37859 if (min <= 0)
860 min = 1;
[email protected]835d7c82010-10-14 04:38:38861 scoped_refptr<base::Histogram> histogram = base::Histogram::FactoryGet(
862 name, min, max, buckets, base::Histogram::kUmaTargetedHistogramFlag);
[email protected]e8829a192009-12-06 00:09:37863 // We'll end up leaking these histograms, unless there is some code hiding in
864 // there to do the dec-ref.
[email protected]2753b392009-12-28 06:59:52865 // TODO(jar): Handle reference counting in webkit glue.
[email protected]e8829a192009-12-06 00:09:37866 histogram->AddRef();
867 return histogram.get();
[email protected]3df0c202009-03-31 23:51:26868}
869
870static void AddHistogramSample(void* hist, int sample) {
[email protected]835d7c82010-10-14 04:38:38871 base::Histogram* histogram = static_cast<base::Histogram*>(hist);
[email protected]3df0c202009-03-31 23:51:26872 histogram->Add(sample);
873}
874
[email protected]90a3fbb12009-02-28 01:13:47875void RenderThread::EnsureWebKitInitialized() {
876 if (webkit_client_.get())
877 return;
[email protected]da00a2882009-03-09 17:51:19878
[email protected]71d6d852009-12-07 22:12:36879 // For extensions, we want to ensure we call the IdleHandler every so often,
880 // even if the extension keeps up activity.
[email protected]b8f41a192010-04-19 18:25:04881 if (is_extension_process_) {
[email protected]71d6d852009-12-07 22:12:36882 forced_idle_timer_.Start(
883 base::TimeDelta::FromSeconds(kMaxExtensionIdleHandlerDelayS),
884 this, &RenderThread::IdleHandler);
885 }
886
[email protected]835d7c82010-10-14 04:38:38887 v8::V8::SetCounterFunction(base::StatsTable::FindLocation);
[email protected]3df0c202009-03-31 23:51:26888 v8::V8::SetCreateHistogramFunction(CreateHistogram);
889 v8::V8::SetAddHistogramSampleFunction(AddHistogramSample);
[email protected]da00a2882009-03-09 17:51:19890
[email protected]90a3fbb12009-02-28 01:13:47891 webkit_client_.reset(new RendererWebKitClientImpl);
892 WebKit::initialize(webkit_client_.get());
[email protected]8881eca82009-03-12 18:20:44893
[email protected]98d7127b2009-10-23 18:26:51894 WebScriptController::enableV8SingleThreadMode();
[email protected]4ea00e82009-07-30 22:59:34895
[email protected]c8310d82011-01-13 23:42:28896 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
897
[email protected]d471190a2011-02-16 14:52:30898 webkit_glue::EnableWebCoreLogChannels(
899 command_line.GetSwitchValueASCII(switches::kWebCoreLogChannels));
900
[email protected]60e448982009-05-06 04:21:16901 // chrome: pages should not be accessible by normal content, and should
[email protected]8881eca82009-03-12 18:20:44902 // also be unable to script anything but themselves (to help limit the damage
[email protected]60e448982009-05-06 04:21:16903 // that a corrupt chrome: page could cause).
[email protected]2c434b32009-03-19 06:27:47904 WebString chrome_ui_scheme(ASCIIToUTF16(chrome::kChromeUIScheme));
[email protected]c931d522011-01-26 22:21:06905 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_ui_scheme);
[email protected]da00a2882009-03-09 17:51:19906
[email protected]b4e75c12010-05-18 18:28:48907 // chrome-extension: resources shouldn't trigger insecure content warnings.
[email protected]37e5a9a2010-03-13 09:42:39908 WebString extension_scheme(ASCIIToUTF16(chrome::kExtensionScheme));
909 WebSecurityPolicy::registerURLSchemeAsSecure(extension_scheme);
910
[email protected]6cf8b1a22009-05-26 23:36:00911#if defined(OS_WIN)
912 // We don't yet support Gears on non-Windows, so don't tell pages that we do.
[email protected]af7eb3fb2010-09-23 21:31:06913 RegisterExtension(extensions_v8::GearsExtension::Get(), false);
[email protected]6cf8b1a22009-05-26 23:36:00914#endif
[email protected]af7eb3fb2010-09-23 21:31:06915 RegisterExtension(extensions_v8::LoadTimesExtension::Get(), false);
916 RegisterExtension(extensions_v8::ChromeAppExtension::Get(), false);
917 RegisterExtension(extensions_v8::ExternalExtension::Get(), false);
[email protected]ce833282010-11-04 15:48:39918 RegisterExtension(extensions_v8::SearchBoxExtension::Get(), false);
[email protected]15d9c0c2010-09-10 22:36:26919 v8::Extension* search_extension = extensions_v8::SearchExtension::Get();
920 // search_extension is null if not enabled.
921 if (search_extension)
[email protected]af7eb3fb2010-09-23 21:31:06922 RegisterExtension(search_extension, false);
[email protected]e2b2d4a2009-10-24 03:32:59923
[email protected]af7eb3fb2010-09-23 21:31:06924 if (command_line.HasSwitch(switches::kEnableBenchmarking))
925 RegisterExtension(extensions_v8::BenchmarkingExtension::Get(), false);
[email protected]b07f29092009-06-05 07:33:21926
[email protected]06533c0b2009-03-05 21:39:11927 if (command_line.HasSwitch(switches::kPlaybackMode) ||
[email protected]ca12c842009-04-14 22:20:18928 command_line.HasSwitch(switches::kRecordMode) ||
929 command_line.HasSwitch(switches::kNoJsRandomness)) {
[email protected]af7eb3fb2010-09-23 21:31:06930 RegisterExtension(extensions_v8::PlaybackExtension::Get(), false);
[email protected]06533c0b2009-03-05 21:39:11931 }
[email protected]2cb82332009-03-18 17:24:55932
[email protected]af7eb3fb2010-09-23 21:31:06933 if (command_line.HasSwitch(switches::kDomAutomationController))
934 RegisterExtension(DomAutomationV8Extension::Get(), false);
935
936 // Add v8 extensions related to chrome extensions.
937 RegisterExtension(ExtensionProcessBindings::Get(), true);
938 RegisterExtension(BaseJsV8Extension::Get(), true);
939 RegisterExtension(JsonSchemaJsV8Extension::Get(), true);
940 RegisterExtension(EventBindings::Get(), true);
941 RegisterExtension(RendererExtensionBindings::Get(), true);
942 RegisterExtension(ExtensionApiTestV8Extension::Get(), true);
943
944 web_database_observer_impl_.reset(new WebDatabaseObserverImpl(this));
945 WebKit::WebDatabase::setObserver(web_database_observer_impl_.get());
[email protected]a9602de2010-03-18 23:43:11946
[email protected]b1b13212009-10-30 06:42:01947 WebRuntimeFeatures::enableMediaPlayer(
[email protected]00c39612010-03-06 02:53:28948 RenderProcess::current()->HasInitializedMediaLibrary());
[email protected]3553c6cc2009-10-20 05:51:55949
[email protected]b1b13212009-10-30 06:42:01950 WebRuntimeFeatures::enableSockets(
[email protected]cdf24782009-11-05 09:32:47951 !command_line.HasSwitch(switches::kDisableWebSockets));
[email protected]0afb9932009-10-24 00:37:58952
[email protected]b1b13212009-10-30 06:42:01953 WebRuntimeFeatures::enableDatabase(
[email protected]90a7ad522009-11-20 22:42:53954 !command_line.HasSwitch(switches::kDisableDatabases));
[email protected]bfa69d492009-10-31 03:27:19955
[email protected]27d27482011-03-08 22:45:39956 WebRuntimeFeatures::enableDataTransferItems(
957 command_line.HasSwitch(switches::kEnableDataTransferItems));
958
[email protected]13bc0d822009-11-07 01:17:14959 WebRuntimeFeatures::enableApplicationCache(
[email protected]425c270642010-01-26 20:42:37960 !command_line.HasSwitch(switches::kDisableApplicationCache));
[email protected]13bc0d822009-11-07 01:17:14961
[email protected]bfa69d492009-10-31 03:27:19962 WebRuntimeFeatures::enableNotifications(
[email protected]380f1862009-11-14 02:48:01963 !command_line.HasSwitch(switches::kDisableDesktopNotifications));
[email protected]7ee66e62009-11-05 09:16:30964
965 WebRuntimeFeatures::enableLocalStorage(
[email protected]5cf18362009-11-06 18:45:01966 !command_line.HasSwitch(switches::kDisableLocalStorage));
[email protected]7ee66e62009-11-05 09:16:30967 WebRuntimeFeatures::enableSessionStorage(
[email protected]03567802010-02-24 11:48:53968 !command_line.HasSwitch(switches::kDisableSessionStorage));
[email protected]2236bd1f2010-01-20 15:17:08969
[email protected]582fab732010-02-02 02:50:28970 WebRuntimeFeatures::enableIndexedDatabase(
[email protected]af1f9f32010-10-09 21:30:26971 !command_line.HasSwitch(switches::kDisableIndexedDatabase));
[email protected]582fab732010-02-02 02:50:28972
[email protected]2236bd1f2010-01-20 15:17:08973 WebRuntimeFeatures::enableGeolocation(
[email protected]d0569f42010-04-01 10:48:18974 !command_line.HasSwitch(switches::kDisableGeolocation));
[email protected]7a716c82010-03-03 10:33:44975
[email protected]8df51192011-01-22 20:05:03976 WebRuntimeFeatures::enableWebAudio(
977 command_line.HasSwitch(switches::kEnableWebAudio));
[email protected]8df51192011-01-22 20:05:03978
[email protected]7a716c82010-03-03 10:33:44979 WebRuntimeFeatures::enableWebGL(
[email protected]97123dc2010-12-21 02:12:33980 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
[email protected]11c4c812010-10-22 19:50:12981 !command_line.HasSwitch(switches::kDisableExperimentalWebGL));
[email protected]ccbe04e2010-03-17 17:58:43982
983 WebRuntimeFeatures::enablePushState(true);
[email protected]f2e3d6c2010-04-30 14:23:04984
985 WebRuntimeFeatures::enableTouch(
986 command_line.HasSwitch(switches::kEnableTouch));
[email protected]66249e22010-07-22 09:55:33987
[email protected]1f501972010-08-09 05:40:02988 WebRuntimeFeatures::enableDeviceMotion(
989 command_line.HasSwitch(switches::kEnableDeviceMotion));
990
[email protected]66249e22010-07-22 09:55:33991 WebRuntimeFeatures::enableDeviceOrientation(
[email protected]71453202010-08-27 15:47:37992 !command_line.HasSwitch(switches::kDisableDeviceOrientation));
[email protected]c8647272010-07-30 21:52:57993
[email protected]21e0cbf62011-03-04 07:55:03994 WebRuntimeFeatures::enableSpeechInput(
995 !command_line.HasSwitch(switches::kDisableSpeechInput));
[email protected]4c56ef52010-09-03 01:56:04996
997 WebRuntimeFeatures::enableFileSystem(
[email protected]2a524d22010-10-16 01:16:23998 !command_line.HasSwitch(switches::kDisableFileSystem));
[email protected]be8a9272011-02-10 22:06:07999
1000 WebRuntimeFeatures::enableJavaScriptI18NAPI(
[email protected]7a0c1432011-03-10 21:33:411001 !command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI));
[email protected]90a3fbb12009-02-28 01:13:471002}
[email protected]75e5a872009-04-02 23:56:111003
[email protected]bee16aab2009-08-26 15:55:031004void RenderThread::IdleHandler() {
[email protected]61a9b2d82010-02-26 00:31:081005#if (defined(OS_WIN) || defined(OS_LINUX)) && defined(USE_TCMALLOC)
[email protected]e94afbb92009-10-01 00:25:411006 MallocExtension::instance()->ReleaseFreeMemory();
[email protected]05001182009-09-15 23:34:221007#endif
[email protected]bee16aab2009-08-26 15:55:031008
[email protected]f5e4b9bf2009-10-08 00:59:591009 v8::V8::IdleNotification();
[email protected]05001182009-09-15 23:34:221010
1011 // Schedule next invocation.
1012 // Dampen the delay using the algorithm:
1013 // delay = delay + 1 / (delay + 2)
1014 // Using floor(delay) has a dampening effect such as:
1015 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ...
1016 // Note that idle_notification_delay_in_s_ would be reset to
1017 // kInitialIdleHandlerDelayS in RenderThread::WidgetHidden.
[email protected]71d6d852009-12-07 22:12:361018 ScheduleIdleHandler(idle_notification_delay_in_s_ +
1019 1.0 / (idle_notification_delay_in_s_ + 2.0));
[email protected]b8f41a192010-04-19 18:25:041020 if (is_extension_process_) {
[email protected]71d6d852009-12-07 22:12:361021 // Dampen the forced delay as well if the extension stays idle for long
1022 // periods of time.
1023 int64 forced_delay_s =
1024 std::max(static_cast<int64>(idle_notification_delay_in_s_),
1025 kMaxExtensionIdleHandlerDelayS);
1026 forced_idle_timer_.Stop();
1027 forced_idle_timer_.Start(
1028 base::TimeDelta::FromSeconds(forced_delay_s),
1029 this, &RenderThread::IdleHandler);
1030 }
1031}
[email protected]05001182009-09-15 23:34:221032
[email protected]71d6d852009-12-07 22:12:361033void RenderThread::ScheduleIdleHandler(double initial_delay_s) {
1034 idle_notification_delay_in_s_ = initial_delay_s;
1035 idle_timer_.Stop();
1036 idle_timer_.Start(
1037 base::TimeDelta::FromSeconds(static_cast<int64>(initial_delay_s)),
1038 this, &RenderThread::IdleHandler);
[email protected]bee16aab2009-08-26 15:55:031039}
1040
[email protected]a7ab1b782010-10-21 23:24:161041void RenderThread::OnExtensionMessageInvoke(const std::string& extension_id,
1042 const std::string& function_name,
[email protected]d7259472010-03-24 08:40:491043 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:191044 const GURL& event_url) {
1045 RendererExtensionBindings::Invoke(
[email protected]a7ab1b782010-10-21 23:24:161046 extension_id, function_name, args, NULL, event_url);
[email protected]71d6d852009-12-07 22:12:361047
1048 // Reset the idle handler each time there's any activity like event or message
1049 // dispatch, for which Invoke is the chokepoint.
[email protected]b8f41a192010-04-19 18:25:041050 if (is_extension_process_)
[email protected]71d6d852009-12-07 22:12:361051 ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayS);
[email protected]b68d5ed2009-04-16 02:41:281052}
[email protected]b547fd42009-04-23 23:16:271053
[email protected]fede6ca12009-10-08 18:24:261054void RenderThread::OnPurgeMemory() {
[email protected]85c55dc2009-11-06 03:05:461055 spellchecker_.reset(new SpellCheck());
[email protected]85c55dc2009-11-06 03:05:461056
[email protected]fede6ca12009-10-08 18:24:261057 EnsureWebKitInitialized();
1058
1059 // Clear the object cache (as much as possible; some live objects cannot be
1060 // freed).
1061 WebCache::clear();
1062
1063 // Clear the font/glyph cache.
1064 WebFontCache::clear();
1065
1066 // Clear the Cross-Origin Preflight cache.
1067 WebCrossOriginPreflightResultCache::clear();
1068
[email protected]adf00bc2009-11-02 18:35:001069 // Release all freeable memory from the SQLite process-global page cache (a
1070 // low-level object which backs the Connection-specific page caches).
[email protected]4a3dab22009-11-11 17:36:501071 while (sqlite3_release_memory(std::numeric_limits<int>::max()) > 0) {
1072 }
[email protected]adf00bc2009-11-02 18:35:001073
[email protected]fede6ca12009-10-08 18:24:261074 // Repeatedly call the V8 idle notification until it returns true ("nothing
1075 // more to free"). Note that it makes more sense to do this than to implement
1076 // a new "delete everything" pass because object references make it difficult
1077 // to free everything possible in just one pass.
[email protected]4a3dab22009-11-11 17:36:501078 while (!v8::V8::IdleNotification()) {
1079 }
[email protected]fede6ca12009-10-08 18:24:261080
[email protected]61a9b2d82010-02-26 00:31:081081#if (defined(OS_WIN) || defined(OS_LINUX)) && defined(USE_TCMALLOC)
[email protected]fede6ca12009-10-08 18:24:261082 // Tell tcmalloc to release any free pages it's still holding.
1083 MallocExtension::instance()->ReleaseFreeMemory();
1084#endif
1085}
1086
[email protected]b78e168b2009-09-21 22:05:451087void RenderThread::OnPurgePluginListCache(bool reload_pages) {
[email protected]f5e4b9bf2009-10-08 00:59:591088 EnsureWebKitInitialized();
[email protected]b547fd42009-04-23 23:16:271089 // The call below will cause a GetPlugins call with refresh=true, but at this
1090 // point we already know that the browser has refreshed its list, so disable
1091 // refresh temporarily to prevent each renderer process causing the list to be
1092 // regenerated.
1093 plugin_refresh_allowed_ = false;
[email protected]b78e168b2009-09-21 22:05:451094 WebKit::resetPluginCache(reload_pages);
[email protected]b547fd42009-04-23 23:16:271095 plugin_refresh_allowed_ = true;
1096}
[email protected]85c55dc2009-11-06 03:05:461097
[email protected]85c55dc2009-11-06 03:05:461098void RenderThread::OnInitSpellChecker(
[email protected]cb6037d2009-11-16 22:55:171099 IPC::PlatformFileForTransit bdict_file,
[email protected]85c55dc2009-11-06 03:05:461100 const std::vector<std::string>& custom_words,
1101 const std::string& language,
1102 bool auto_spell_correct) {
[email protected]cb6037d2009-11-16 22:55:171103 spellchecker_->Init(IPC::PlatformFileForTransitToPlatformFile(bdict_file),
1104 custom_words, language);
[email protected]85c55dc2009-11-06 03:05:461105 spellchecker_->EnableAutoSpellCorrect(auto_spell_correct);
1106}
1107
1108void RenderThread::OnSpellCheckWordAdded(const std::string& word) {
1109 spellchecker_->WordAdded(word);
1110}
1111
1112void RenderThread::OnSpellCheckEnableAutoSpellCorrect(bool enable) {
1113 spellchecker_->EnableAutoSpellCorrect(enable);
1114}
[email protected]b2a74ca2010-03-12 17:57:091115
1116void RenderThread::OnSetIsIncognitoProcess(bool is_incognito_process) {
1117 is_incognito_process_ = is_incognito_process;
1118}
[email protected]6217d392010-03-25 22:08:351119
1120void RenderThread::OnGpuChannelEstablished(
[email protected]0100b7a2011-02-24 22:54:501121 const IPC::ChannelHandle& channel_handle,
1122 base::ProcessHandle renderer_process_for_gpu,
1123 const GPUInfo& gpu_info) {
[email protected]4bce24e2010-09-07 20:45:011124 gpu_channel_->set_gpu_info(gpu_info);
1125
[email protected]6775e40a2011-03-04 21:03:471126 if (!channel_handle.name.empty()) {
[email protected]6217d392010-03-25 22:08:351127 // Connect to the GPU process if a channel name was received.
[email protected]0100b7a2011-02-24 22:54:501128 gpu_channel_->Connect(channel_handle, renderer_process_for_gpu);
[email protected]6217d392010-03-25 22:08:351129 } else {
1130 // Otherwise cancel the connection.
1131 gpu_channel_ = NULL;
1132 }
1133}
[email protected]3a8eecb2010-04-22 23:56:301134
[email protected]31c90db2010-09-23 00:59:181135void RenderThread::OnSetPhishingModel(IPC::PlatformFileForTransit model_file) {
[email protected]28685da92011-02-07 21:49:171136 safe_browsing::PhishingClassifierDelegate::SetPhishingModel(model_file);
[email protected]31c90db2010-09-23 00:59:181137}
1138
[email protected]c6a7b862010-08-20 22:19:381139scoped_refptr<base::MessageLoopProxy>
1140RenderThread::GetFileThreadMessageLoopProxy() {
1141 DCHECK(message_loop() == MessageLoop::current());
1142 if (!file_thread_.get()) {
1143 file_thread_.reset(new base::Thread("Renderer::FILE"));
1144 file_thread_->Start();
1145 }
1146 return file_thread_->message_loop_proxy();
1147}
[email protected]af7eb3fb2010-09-23 21:31:061148
1149bool RenderThread::AllowScriptExtension(const std::string& v8_extension_name,
1150 const GURL& url,
1151 int extension_group) {
1152 // If we don't know about it, it was added by WebCore, so we should allow it.
1153 if (v8_extensions_.find(v8_extension_name) == v8_extensions_.end())
1154 return true;
1155
1156 // If the V8 extension is not restricted, allow it to run anywhere.
1157 bool restrict_to_extensions = v8_extensions_[v8_extension_name];
1158 if (!restrict_to_extensions)
1159 return true;
1160
1161 // Extension-only bindings should be restricted to content scripts and
1162 // extension-blessed URLs.
1163 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS ||
[email protected]2a521c52011-01-26 18:45:211164 extensions_.ExtensionBindingsAllowed(url)) {
[email protected]af7eb3fb2010-09-23 21:31:061165 return true;
1166 }
1167
1168 return false;
1169}
1170
1171void RenderThread::RegisterExtension(v8::Extension* extension,
1172 bool restrict_to_extensions) {
1173 WebScriptController::registerExtension(extension);
1174 v8_extensions_[extension->name()] = restrict_to_extensions;
1175}