Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: chrome/renderer/render_thread.cc

Issue 7254: Initial Greasemonkey support (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/render_thread.h ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <windows.h> 5 #include <windows.h>
6 #include <algorithm> 6 #include <algorithm>
7 7
8 #include "chrome/renderer/render_thread.h" 8 #include "chrome/renderer/render_thread.h"
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/shared_memory.h" 11 #include "base/shared_memory.h"
12 #include "base/thread_local.h" 12 #include "base/thread_local.h"
13 #include "chrome/common/chrome_plugin_lib.h" 13 #include "chrome/common/chrome_plugin_lib.h"
14 #include "chrome/common/ipc_logging.h" 14 #include "chrome/common/ipc_logging.h"
15 #include "chrome/common/notification_service.h" 15 #include "chrome/common/notification_service.h"
16 #include "chrome/plugin/plugin_channel.h" 16 #include "chrome/plugin/plugin_channel.h"
17 #include "chrome/renderer/net/render_dns_master.h" 17 #include "chrome/renderer/net/render_dns_master.h"
18 #include "chrome/renderer/greasemonkey_slave.h"
18 #include "chrome/renderer/render_process.h" 19 #include "chrome/renderer/render_process.h"
19 #include "chrome/renderer/render_view.h" 20 #include "chrome/renderer/render_view.h"
20 #include "chrome/renderer/visitedlink_slave.h" 21 #include "chrome/renderer/visitedlink_slave.h"
21 #include "webkit/glue/cache_manager.h" 22 #include "webkit/glue/cache_manager.h"
22 23
23 static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */; 24 static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */;
24 25
25 // V8 needs a 1MB stack size. 26 // V8 needs a 1MB stack size.
26 static const size_t kStackSize = 1024 * 1024; 27 static const size_t kStackSize = 1024 * 1024;
27 28
28 static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > 29 static base::LazyInstance<base::ThreadLocalPointer<RenderThread> >
29 lazy_tls_ptr(base::LINKER_INITIALIZED); 30 lazy_tls_ptr(base::LINKER_INITIALIZED);
30 31
31 //----------------------------------------------------------------------------- 32 //-----------------------------------------------------------------------------
32 // Methods below are only called on the owner's thread: 33 // Methods below are only called on the owner's thread:
33 34
34 // static 35 // static
35 RenderThread* RenderThread::current() { 36 RenderThread* RenderThread::current() {
36 return lazy_tls_ptr.Pointer()->Get(); 37 return lazy_tls_ptr.Pointer()->Get();
37 } 38 }
38 39
39 RenderThread::RenderThread(const std::wstring& channel_name) 40 RenderThread::RenderThread(const std::wstring& channel_name)
40 : Thread("Chrome_RenderThread"), 41 : Thread("Chrome_RenderThread"),
41 channel_name_(channel_name), 42 channel_name_(channel_name),
42 owner_loop_(MessageLoop::current()), 43 owner_loop_(MessageLoop::current()),
43 visited_link_slave_(NULL), 44 visited_link_slave_(NULL),
45 greasemonkey_slave_(NULL),
44 render_dns_master_(NULL), 46 render_dns_master_(NULL),
45 in_send_(0) { 47 in_send_(0) {
46 DCHECK(owner_loop_); 48 DCHECK(owner_loop_);
47 base::Thread::Options options; 49 base::Thread::Options options;
48 options.stack_size = kStackSize; 50 options.stack_size = kStackSize;
49 // When we run plugins in process, we actually run them on the render thread, 51 // When we run plugins in process, we actually run them on the render thread,
50 // which means that we need to make the render thread pump UI events. 52 // which means that we need to make the render thread pump UI events.
51 if (RenderProcess::ShouldLoadPluginsInProcess()) 53 if (RenderProcess::ShouldLoadPluginsInProcess())
52 options.message_loop_type = MessageLoop::TYPE_UI; 54 options.message_loop_type = MessageLoop::TYPE_UI;
53 StartWithOptions(options); 55 StartWithOptions(options);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 106
105 channel_.reset(new IPC::SyncChannel(channel_name_, 107 channel_.reset(new IPC::SyncChannel(channel_name_,
106 IPC::Channel::MODE_CLIENT, this, NULL, owner_loop_, true, 108 IPC::Channel::MODE_CLIENT, this, NULL, owner_loop_, true,
107 RenderProcess::GetShutDownEvent())); 109 RenderProcess::GetShutDownEvent()));
108 110
109 lazy_tls_ptr.Pointer()->Set(this); 111 lazy_tls_ptr.Pointer()->Set(this);
110 112
111 // The renderer thread should wind-up COM. 113 // The renderer thread should wind-up COM.
112 CoInitialize(0); 114 CoInitialize(0);
113 115
114 // TODO(darin): We should actually try to share this object between
115 // RenderThread instances.
116 visited_link_slave_ = new VisitedLinkSlave(); 116 visited_link_slave_ = new VisitedLinkSlave();
117 greasemonkey_slave_ = new GreasemonkeySlave();
117 118
118 render_dns_master_.reset(new RenderDnsMaster()); 119 render_dns_master_.reset(new RenderDnsMaster());
119 120
120 #ifdef IPC_MESSAGE_LOG_ENABLED 121 #ifdef IPC_MESSAGE_LOG_ENABLED
121 IPC::Logging::current()->SetIPCSender(this); 122 IPC::Logging::current()->SetIPCSender(this);
122 #endif 123 #endif
123 } 124 }
124 125
125 void RenderThread::CleanUp() { 126 void RenderThread::CleanUp() {
126 DCHECK(current() == this); 127 DCHECK(current() == this);
127 128
128 // Need to destruct the SyncChannel to the browser before we go away because 129 // Need to destruct the SyncChannel to the browser before we go away because
129 // it caches a pointer to this thread. 130 // it caches a pointer to this thread.
130 channel_.reset(); 131 channel_.reset();
131 132
132 // Clean up plugin channels before this thread goes away. 133 // Clean up plugin channels before this thread goes away.
133 PluginChannelBase::CleanupChannels(); 134 PluginChannelBase::CleanupChannels();
134 135
135 #ifdef IPC_MESSAGE_LOG_ENABLED 136 #ifdef IPC_MESSAGE_LOG_ENABLED
136 IPC::Logging::current()->SetIPCSender(NULL); 137 IPC::Logging::current()->SetIPCSender(NULL);
137 #endif 138 #endif
138 139
139 notification_service_.reset(); 140 notification_service_.reset();
140 141
141 delete visited_link_slave_; 142 delete visited_link_slave_;
142 visited_link_slave_ = NULL; 143 visited_link_slave_ = NULL;
143 144
145 delete greasemonkey_slave_;
146 greasemonkey_slave_ = NULL;
147
144 CoUninitialize(); 148 CoUninitialize();
145 } 149 }
146 150
147 void RenderThread::OnUpdateVisitedLinks(SharedMemoryHandle table) { 151 void RenderThread::OnUpdateVisitedLinks(SharedMemoryHandle table) {
148 DCHECK(table) << "Bad table handle"; 152 DCHECK(table) << "Bad table handle";
149 visited_link_slave_->Init(table); 153 visited_link_slave_->Init(table);
150 } 154 }
151 155
156 void RenderThread::OnUpdateGreasemonkeyScripts(SharedMemoryHandle scripts) {
157 DCHECK(scripts) << "Bad scripts handle";
158 greasemonkey_slave_->UpdateScripts(scripts);
159 }
160
152 void RenderThread::OnMessageReceived(const IPC::Message& msg) { 161 void RenderThread::OnMessageReceived(const IPC::Message& msg) {
153 // NOTE: We could subclass router_ to intercept OnControlMessageReceived, but 162 // NOTE: We could subclass router_ to intercept OnControlMessageReceived, but
154 // it seems simpler to just process any control messages that we care about 163 // it seems simpler to just process any control messages that we care about
155 // up-front and then send the rest of the messages onto router_. 164 // up-front and then send the rest of the messages onto router_.
156 165
157 if (msg.routing_id() == MSG_ROUTING_CONTROL) { 166 if (msg.routing_id() == MSG_ROUTING_CONTROL) {
158 IPC_BEGIN_MESSAGE_MAP(RenderThread, msg) 167 IPC_BEGIN_MESSAGE_MAP(RenderThread, msg)
159 IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_NewTable, OnUpdateVisitedLinks) 168 IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_NewTable, OnUpdateVisitedLinks)
160 IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID) 169 IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID)
161 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView) 170 IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
162 IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities) 171 IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities)
163 IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, 172 IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats,
164 OnGetCacheResourceStats) 173 OnGetCacheResourceStats)
165 IPC_MESSAGE_HANDLER(ViewMsg_PluginMessage, OnPluginMessage) 174 IPC_MESSAGE_HANDLER(ViewMsg_PluginMessage, OnPluginMessage)
175 IPC_MESSAGE_HANDLER(ViewMsg_Greasemonkey_NewScripts,
176 OnUpdateGreasemonkeyScripts)
166 // send the rest to the router 177 // send the rest to the router
167 IPC_MESSAGE_UNHANDLED(router_.OnMessageReceived(msg)) 178 IPC_MESSAGE_UNHANDLED(router_.OnMessageReceived(msg))
168 IPC_END_MESSAGE_MAP() 179 IPC_END_MESSAGE_MAP()
169 } else { 180 } else {
170 router_.OnMessageReceived(msg); 181 router_.OnMessageReceived(msg);
171 } 182 }
172 } 183 }
173 184
174 void RenderThread::OnPluginMessage(const std::wstring& dll_path, 185 void RenderThread::OnPluginMessage(const std::wstring& dll_path,
175 const std::vector<uint8>& data) { 186 const std::vector<uint8>& data) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // Rate limit informing the host of our cache stats. 232 // Rate limit informing the host of our cache stats.
222 if (!cache_stats_factory_->empty()) 233 if (!cache_stats_factory_->empty())
223 return; 234 return;
224 235
225 MessageLoop::current()->PostDelayedTask(FROM_HERE, 236 MessageLoop::current()->PostDelayedTask(FROM_HERE,
226 cache_stats_factory_->NewRunnableMethod( 237 cache_stats_factory_->NewRunnableMethod(
227 &RenderThread::InformHostOfCacheStats), 238 &RenderThread::InformHostOfCacheStats),
228 kCacheStatsDelayMS); 239 kCacheStatsDelayMS);
229 } 240 }
230 241
OLDNEW
« no previous file with comments | « chrome/renderer/render_thread.h ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698