OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/renderer/render_thread.h" | 5 #include "chrome/renderer/render_thread.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 plugin_refresh_allowed_ = true; | 271 plugin_refresh_allowed_ = true; |
272 cache_stats_task_pending_ = false; | 272 cache_stats_task_pending_ = false; |
273 widget_count_ = 0; | 273 widget_count_ = 0; |
274 hidden_widget_count_ = 0; | 274 hidden_widget_count_ = 0; |
275 idle_notification_delay_in_s_ = is_extension_process_ ? | 275 idle_notification_delay_in_s_ = is_extension_process_ ? |
276 kInitialExtensionIdleHandlerDelayS : kInitialIdleHandlerDelayS; | 276 kInitialExtensionIdleHandlerDelayS : kInitialIdleHandlerDelayS; |
277 task_factory_.reset(new ScopedRunnableMethodFactory<RenderThread>(this)); | 277 task_factory_.reset(new ScopedRunnableMethodFactory<RenderThread>(this)); |
278 callback_factory_.reset(new base::ScopedCallbackFactory<RenderThread>(this)); | 278 callback_factory_.reset(new base::ScopedCallbackFactory<RenderThread>(this)); |
279 | 279 |
280 visited_link_slave_.reset(new VisitedLinkSlave()); | 280 visited_link_slave_.reset(new VisitedLinkSlave()); |
281 user_script_slave_.reset(new UserScriptSlave()); | 281 user_script_slave_.reset(new UserScriptSlave(&extensions_)); |
282 renderer_net_predictor_.reset(new RendererNetPredictor()); | 282 renderer_net_predictor_.reset(new RendererNetPredictor()); |
283 histogram_snapshots_.reset(new RendererHistogramSnapshots()); | 283 histogram_snapshots_.reset(new RendererHistogramSnapshots()); |
284 appcache_dispatcher_.reset(new AppCacheDispatcher(this)); | 284 appcache_dispatcher_.reset(new AppCacheDispatcher(this)); |
285 indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); | 285 indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); |
286 spellchecker_.reset(new SpellCheck()); | 286 spellchecker_.reset(new SpellCheck()); |
287 | 287 |
288 devtools_agent_filter_ = new DevToolsAgentFilter(); | 288 devtools_agent_filter_ = new DevToolsAgentFilter(); |
289 AddFilter(devtools_agent_filter_.get()); | 289 AddFilter(devtools_agent_filter_.get()); |
290 | 290 |
291 db_message_filter_ = new DBMessageFilter(); | 291 db_message_filter_ = new DBMessageFilter(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 RenderView* view = RenderView::FromWebView(frame->view()); | 343 RenderView* view = RenderView::FromWebView(frame->view()); |
344 if (view) | 344 if (view) |
345 routing_id = view->routing_id(); | 345 routing_id = view->routing_id(); |
346 } | 346 } |
347 } else { | 347 } else { |
348 DLOG(WARNING) << "Not called within a script context!"; | 348 DLOG(WARNING) << "Not called within a script context!"; |
349 } | 349 } |
350 return routing_id; | 350 return routing_id; |
351 } | 351 } |
352 | 352 |
| 353 const ExtensionRendererInfo* RenderThread::GetExtensions() const { |
| 354 return &extensions_; |
| 355 } |
| 356 |
353 bool RenderThread::Send(IPC::Message* msg) { | 357 bool RenderThread::Send(IPC::Message* msg) { |
354 // Certain synchronous messages cannot always be processed synchronously by | 358 // Certain synchronous messages cannot always be processed synchronously by |
355 // the browser, e.g., Chrome frame communicating with the embedding browser. | 359 // the browser, e.g., Chrome frame communicating with the embedding browser. |
356 // This could cause a complete hang of Chrome if a windowed plug-in is trying | 360 // This could cause a complete hang of Chrome if a windowed plug-in is trying |
357 // to communicate with the renderer thread since the browser's UI thread | 361 // to communicate with the renderer thread since the browser's UI thread |
358 // could be stuck (within a Windows API call) trying to synchronously | 362 // could be stuck (within a Windows API call) trying to synchronously |
359 // communicate with the plug-in. The remedy is to pump messages on this | 363 // communicate with the plug-in. The remedy is to pump messages on this |
360 // thread while the browser is processing this request. This creates an | 364 // thread while the browser is processing this request. This creates an |
361 // opportunity for re-entrancy into WebKit, so we need to take care to disable | 365 // opportunity for re-entrancy into WebKit, so we need to take care to disable |
362 // callbacks, timers, and pending network loads that could trigger such | 366 // callbacks, timers, and pending network loads that could trigger such |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle"; | 533 DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle"; |
530 user_script_slave_->UpdateScripts(scripts); | 534 user_script_slave_->UpdateScripts(scripts); |
531 UpdateActiveExtensions(); | 535 UpdateActiveExtensions(); |
532 } | 536 } |
533 | 537 |
534 void RenderThread::OnSetExtensionFunctionNames( | 538 void RenderThread::OnSetExtensionFunctionNames( |
535 const std::vector<std::string>& names) { | 539 const std::vector<std::string>& names) { |
536 ExtensionProcessBindings::SetFunctionNames(names); | 540 ExtensionProcessBindings::SetFunctionNames(names); |
537 } | 541 } |
538 | 542 |
539 void RenderThread::OnExtensionsUpdated( | 543 void RenderThread::OnExtensionLoaded( |
540 const ViewMsg_ExtensionsUpdated_Params& params) { | 544 const ViewMsg_ExtensionLoaded_Params& params) { |
541 ExtensionRendererInfo::UpdateExtensions(params); | 545 scoped_refptr<const Extension> extension(params.ConvertToExtension()); |
| 546 CHECK(extension); |
| 547 extensions_.Update(extension); |
| 548 } |
| 549 |
| 550 void RenderThread::OnExtensionUnloaded(const std::string& id) { |
| 551 extensions_.Remove(id); |
542 } | 552 } |
543 | 553 |
544 void RenderThread::OnPageActionsUpdated( | 554 void RenderThread::OnPageActionsUpdated( |
545 const std::string& extension_id, | 555 const std::string& extension_id, |
546 const std::vector<std::string>& page_actions) { | 556 const std::vector<std::string>& page_actions) { |
547 ExtensionProcessBindings::SetPageActions(extension_id, page_actions); | 557 ExtensionProcessBindings::SetPageActions(extension_id, page_actions); |
548 } | 558 } |
549 | 559 |
550 void RenderThread::OnExtensionSetAPIPermissions( | 560 void RenderThread::OnExtensionSetAPIPermissions( |
551 const std::string& extension_id, | 561 const std::string& extension_id, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, | 617 IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, |
608 OnGetCacheResourceStats) | 618 OnGetCacheResourceStats) |
609 IPC_MESSAGE_HANDLER(ViewMsg_UserScripts_UpdatedScripts, | 619 IPC_MESSAGE_HANDLER(ViewMsg_UserScripts_UpdatedScripts, |
610 OnUpdateUserScripts) | 620 OnUpdateUserScripts) |
611 // TODO(rafaelw): create an ExtensionDispatcher that handles extension | 621 // TODO(rafaelw): create an ExtensionDispatcher that handles extension |
612 // messages seperates their handling from the RenderThread. | 622 // messages seperates their handling from the RenderThread. |
613 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, | 623 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, |
614 OnExtensionMessageInvoke) | 624 OnExtensionMessageInvoke) |
615 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetFunctionNames, | 625 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetFunctionNames, |
616 OnSetExtensionFunctionNames) | 626 OnSetExtensionFunctionNames) |
617 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionsUpdated, | 627 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionLoaded, |
618 OnExtensionsUpdated) | 628 OnExtensionLoaded) |
| 629 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionUnloaded, |
| 630 OnExtensionUnloaded) |
619 IPC_MESSAGE_HANDLER(ViewMsg_PurgeMemory, OnPurgeMemory) | 631 IPC_MESSAGE_HANDLER(ViewMsg_PurgeMemory, OnPurgeMemory) |
620 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, | 632 IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, |
621 OnPurgePluginListCache) | 633 OnPurgePluginListCache) |
622 IPC_MESSAGE_HANDLER(ViewMsg_Extension_UpdatePageActions, | 634 IPC_MESSAGE_HANDLER(ViewMsg_Extension_UpdatePageActions, |
623 OnPageActionsUpdated) | 635 OnPageActionsUpdated) |
624 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetAPIPermissions, | 636 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetAPIPermissions, |
625 OnExtensionSetAPIPermissions) | 637 OnExtensionSetAPIPermissions) |
626 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetHostPermissions, | 638 IPC_MESSAGE_HANDLER(ViewMsg_Extension_SetHostPermissions, |
627 OnExtensionSetHostPermissions) | 639 OnExtensionSetHostPermissions) |
628 IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, | 640 IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 return true; | 1137 return true; |
1126 | 1138 |
1127 // If the V8 extension is not restricted, allow it to run anywhere. | 1139 // If the V8 extension is not restricted, allow it to run anywhere. |
1128 bool restrict_to_extensions = v8_extensions_[v8_extension_name]; | 1140 bool restrict_to_extensions = v8_extensions_[v8_extension_name]; |
1129 if (!restrict_to_extensions) | 1141 if (!restrict_to_extensions) |
1130 return true; | 1142 return true; |
1131 | 1143 |
1132 // Extension-only bindings should be restricted to content scripts and | 1144 // Extension-only bindings should be restricted to content scripts and |
1133 // extension-blessed URLs. | 1145 // extension-blessed URLs. |
1134 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS || | 1146 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS || |
1135 ExtensionRendererInfo::ExtensionBindingsAllowed(url)) { | 1147 extensions_.ExtensionBindingsAllowed(url)) { |
1136 return true; | 1148 return true; |
1137 } | 1149 } |
1138 | 1150 |
1139 return false; | 1151 return false; |
1140 } | 1152 } |
1141 | 1153 |
1142 void RenderThread::RegisterExtension(v8::Extension* extension, | 1154 void RenderThread::RegisterExtension(v8::Extension* extension, |
1143 bool restrict_to_extensions) { | 1155 bool restrict_to_extensions) { |
1144 WebScriptController::registerExtension(extension); | 1156 WebScriptController::registerExtension(extension); |
1145 v8_extensions_[extension->name()] = restrict_to_extensions; | 1157 v8_extensions_[extension->name()] = restrict_to_extensions; |
1146 } | 1158 } |
OLD | NEW |