| OLD | NEW | 
|     1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |     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 |     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 "content/renderer/render_thread_impl.h" |     5 #include "content/renderer/render_thread_impl.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 29 matching lines...) Expand all  Loading... | 
|    40 #include "content/common/view_messages.h" |    40 #include "content/common/view_messages.h" | 
|    41 #include "content/common/web_database_observer_impl.h" |    41 #include "content/common/web_database_observer_impl.h" | 
|    42 #include "content/public/common/content_paths.h" |    42 #include "content/public/common/content_paths.h" | 
|    43 #include "content/public/common/content_switches.h" |    43 #include "content/public/common/content_switches.h" | 
|    44 #include "content/public/common/renderer_preferences.h" |    44 #include "content/public/common/renderer_preferences.h" | 
|    45 #include "content/public/common/url_constants.h" |    45 #include "content/public/common/url_constants.h" | 
|    46 #include "content/public/renderer/content_renderer_client.h" |    46 #include "content/public/renderer/content_renderer_client.h" | 
|    47 #include "content/public/renderer/render_process_observer.h" |    47 #include "content/public/renderer/render_process_observer.h" | 
|    48 #include "content/public/renderer/render_view_visitor.h" |    48 #include "content/public/renderer/render_view_visitor.h" | 
|    49 #include "content/renderer/devtools_agent_filter.h" |    49 #include "content/renderer/devtools_agent_filter.h" | 
 |    50 #include "content/renderer/dom_storage/dom_storage_dispatcher.h" | 
 |    51 #include "content/renderer/dom_storage/webstoragearea_impl.h" | 
 |    52 #include "content/renderer/dom_storage/webstoragenamespace_impl.h" | 
|    50 #include "content/renderer/gpu/compositor_thread.h" |    53 #include "content/renderer/gpu/compositor_thread.h" | 
|    51 #include "content/renderer/media/audio_input_message_filter.h" |    54 #include "content/renderer/media/audio_input_message_filter.h" | 
|    52 #include "content/renderer/media/audio_message_filter.h" |    55 #include "content/renderer/media/audio_message_filter.h" | 
|    53 #include "content/renderer/media/media_stream_center.h" |    56 #include "content/renderer/media/media_stream_center.h" | 
|    54 #include "content/renderer/media/video_capture_impl_manager.h" |    57 #include "content/renderer/media/video_capture_impl_manager.h" | 
|    55 #include "content/renderer/media/video_capture_message_filter.h" |    58 #include "content/renderer/media/video_capture_message_filter.h" | 
|    56 #include "content/renderer/plugin_channel_host.h" |    59 #include "content/renderer/plugin_channel_host.h" | 
|    57 #include "content/renderer/render_process_impl.h" |    60 #include "content/renderer/render_process_impl.h" | 
|    58 #include "content/renderer/render_view_impl.h" |    61 #include "content/renderer/render_view_impl.h" | 
|    59 #include "content/renderer/renderer_webkitplatformsupport_impl.h" |    62 #include "content/renderer/renderer_webkitplatformsupport_impl.h" | 
|    60 #include "content/renderer/renderer_webstoragearea_impl.h" |  | 
|    61 #include "content/renderer/renderer_webstoragenamespace_impl.h" |  | 
|    62 #include "grit/content_resources.h" |    63 #include "grit/content_resources.h" | 
|    63 #include "ipc/ipc_channel_handle.h" |    64 #include "ipc/ipc_channel_handle.h" | 
|    64 #include "ipc/ipc_platform_file.h" |    65 #include "ipc/ipc_platform_file.h" | 
|    65 #include "media/base/media.h" |    66 #include "media/base/media.h" | 
|    66 #include "net/base/net_errors.h" |    67 #include "net/base/net_errors.h" | 
|    67 #include "net/base/net_util.h" |    68 #include "net/base/net_util.h" | 
|    68 #include "third_party/WebKit/Source/WebKit/chromium/public/WebColorName.h" |    69 #include "third_party/WebKit/Source/WebKit/chromium/public/WebColorName.h" | 
|    69 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h" |    70 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h" | 
|    70 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h" |    71 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h" | 
|    71 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |    72 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 
|    72 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |    73 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 
|    73 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |    74 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 
|    74 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifi
      er.h" |    75 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifi
      er.h" | 
|    75 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" |    76 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" | 
|    76 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" |    77 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" | 
|    77 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h
      " |    78 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h
      " | 
|    78 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |    79 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" | 
|    79 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispat
      cher.h" |  | 
|    80 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |    80 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 
|    81 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |    81 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 
|    82 #include "ui/base/ui_base_switches.h" |    82 #include "ui/base/ui_base_switches.h" | 
|    83 #include "v8/include/v8.h" |    83 #include "v8/include/v8.h" | 
|    84 #include "webkit/glue/webkit_glue.h" |    84 #include "webkit/glue/webkit_glue.h" | 
|    85  |    85  | 
|    86 // TODO(port) |    86 // TODO(port) | 
|    87 #if !defined(OS_WIN) |    87 #if !defined(OS_WIN) | 
|    88 #include "base/memory/scoped_handle.h" |    88 #include "base/memory/scoped_handle.h" | 
|    89 #include "content/common/np_channel_base.h" |    89 #include "content/common/np_channel_base.h" | 
|    90 #endif |    90 #endif | 
|    91  |    91  | 
|    92 #if defined(OS_WIN) |    92 #if defined(OS_WIN) | 
|    93 #include <windows.h> |    93 #include <windows.h> | 
|    94 #include <objbase.h> |    94 #include <objbase.h> | 
|    95 #endif |    95 #endif | 
|    96  |    96  | 
|    97 #if defined(OS_POSIX) |    97 #if defined(OS_POSIX) | 
|    98 #include "ipc/ipc_channel_posix.h" |    98 #include "ipc/ipc_channel_posix.h" | 
|    99 #endif |    99 #endif | 
|   100  |   100  | 
|   101 using WebKit::WebDocument; |   101 using WebKit::WebDocument; | 
|   102 using WebKit::WebFrame; |   102 using WebKit::WebFrame; | 
|   103 using WebKit::WebNetworkStateNotifier; |   103 using WebKit::WebNetworkStateNotifier; | 
|   104 using WebKit::WebRuntimeFeatures; |   104 using WebKit::WebRuntimeFeatures; | 
|   105 using WebKit::WebScriptController; |   105 using WebKit::WebScriptController; | 
|   106 using WebKit::WebSecurityPolicy; |   106 using WebKit::WebSecurityPolicy; | 
|   107 using WebKit::WebString; |   107 using WebKit::WebString; | 
|   108 using WebKit::WebStorageEventDispatcher; |  | 
|   109 using WebKit::WebView; |   108 using WebKit::WebView; | 
|   110 using content::RenderProcessObserver; |   109 using content::RenderProcessObserver; | 
|   111  |   110  | 
|   112 namespace { |   111 namespace { | 
|   113  |   112  | 
|   114 const int64 kInitialIdleHandlerDelayMs = 1000; |   113 const int64 kInitialIdleHandlerDelayMs = 1000; | 
|   115 const int64 kShortIdleHandlerDelayMs = 1000; |   114 const int64 kShortIdleHandlerDelayMs = 1000; | 
|   116 const int64 kLongIdleHandlerDelayMs = 30*1000; |   115 const int64 kLongIdleHandlerDelayMs = 30*1000; | 
|   117 const int kIdleCPUUsageThresholdInPercents = 3; |   116 const int kIdleCPUUsageThresholdInPercents = 3; | 
|   118  |   117  | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   203   suspend_webkit_shared_timer_ = true; |   202   suspend_webkit_shared_timer_ = true; | 
|   204   notify_webkit_of_modal_loop_ = true; |   203   notify_webkit_of_modal_loop_ = true; | 
|   205   plugin_refresh_allowed_ = true; |   204   plugin_refresh_allowed_ = true; | 
|   206   widget_count_ = 0; |   205   widget_count_ = 0; | 
|   207   hidden_widget_count_ = 0; |   206   hidden_widget_count_ = 0; | 
|   208   idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs; |   207   idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs; | 
|   209   idle_notifications_to_skip_ = 0; |   208   idle_notifications_to_skip_ = 0; | 
|   210   compositor_initialized_ = false; |   209   compositor_initialized_ = false; | 
|   211  |   210  | 
|   212   appcache_dispatcher_.reset(new AppCacheDispatcher(Get())); |   211   appcache_dispatcher_.reset(new AppCacheDispatcher(Get())); | 
 |   212   dom_storage_dispatcher_.reset(new DomStorageDispatcher()); | 
|   213   main_thread_indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); |   213   main_thread_indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); | 
|   214  |   214  | 
|   215   media_stream_center_ = NULL; |   215   media_stream_center_ = NULL; | 
|   216  |   216  | 
|   217   db_message_filter_ = new DBMessageFilter(); |   217   db_message_filter_ = new DBMessageFilter(); | 
|   218   AddFilter(db_message_filter_.get()); |   218   AddFilter(db_message_filter_.get()); | 
|   219  |   219  | 
|   220   vc_manager_ = new VideoCaptureImplManager(); |   220   vc_manager_ = new VideoCaptureImplManager(); | 
|   221   AddFilter(vc_manager_->video_capture_message_filter()); |   221   AddFilter(vc_manager_->video_capture_message_filter()); | 
|   222  |   222  | 
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   799 void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { |   799 void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { | 
|   800   notify_webkit_of_modal_loop_ = false; |   800   notify_webkit_of_modal_loop_ = false; | 
|   801 } |   801 } | 
|   802  |   802  | 
|   803 void RenderThreadImpl::OnSetZoomLevelForCurrentURL(const std::string& host, |   803 void RenderThreadImpl::OnSetZoomLevelForCurrentURL(const std::string& host, | 
|   804                                                    double zoom_level) { |   804                                                    double zoom_level) { | 
|   805   RenderViewZoomer zoomer(host, zoom_level); |   805   RenderViewZoomer zoomer(host, zoom_level); | 
|   806   content::RenderView::ForEach(&zoomer); |   806   content::RenderView::ForEach(&zoomer); | 
|   807 } |   807 } | 
|   808  |   808  | 
|   809 void RenderThreadImpl::OnDOMStorageEvent( |  | 
|   810     const DOMStorageMsg_Event_Params& params) { |  | 
|   811   EnsureWebKitInitialized(); |  | 
|   812  |  | 
|   813   bool originated_in_process = params.connection_id != 0; |  | 
|   814   RendererWebStorageAreaImpl* originating_area = NULL; |  | 
|   815   if (originated_in_process) { |  | 
|   816     originating_area = RendererWebStorageAreaImpl::FromConnectionId( |  | 
|   817         params.connection_id); |  | 
|   818   } |  | 
|   819  |  | 
|   820   if (params.namespace_id == dom_storage::kLocalStorageNamespaceId) { |  | 
|   821     WebStorageEventDispatcher::dispatchLocalStorageEvent( |  | 
|   822         params.key, |  | 
|   823         params.old_value, |  | 
|   824         params.new_value, |  | 
|   825         params.origin, |  | 
|   826         params.page_url, |  | 
|   827         originating_area, |  | 
|   828         originated_in_process); |  | 
|   829   } else if (originated_in_process) { |  | 
|   830     // TODO(michaeln): For now, we only raise session storage events into the |  | 
|   831     // process which caused the event to occur. However there are cases where |  | 
|   832     // sessions can span process boundaries, so there are correctness issues. |  | 
|   833     RendererWebStorageNamespaceImpl |  | 
|   834         session_namespace_for_event_dispatch(params.namespace_id); |  | 
|   835     WebStorageEventDispatcher::dispatchSessionStorageEvent( |  | 
|   836         params.key, |  | 
|   837         params.old_value, |  | 
|   838         params.new_value, |  | 
|   839         params.origin, |  | 
|   840         params.page_url, |  | 
|   841         session_namespace_for_event_dispatch, |  | 
|   842         originating_area, |  | 
|   843         originated_in_process); |  | 
|   844   } |  | 
|   845 } |  | 
|   846  |  | 
|   847 bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { |   809 bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { | 
|   848   ObserverListBase<RenderProcessObserver>::Iterator it(observers_); |   810   ObserverListBase<RenderProcessObserver>::Iterator it(observers_); | 
|   849   RenderProcessObserver* observer; |   811   RenderProcessObserver* observer; | 
|   850   while ((observer = it.GetNext()) != NULL) { |   812   while ((observer = it.GetNext()) != NULL) { | 
|   851     if (observer->OnControlMessageReceived(msg)) |   813     if (observer->OnControlMessageReceived(msg)) | 
|   852       return true; |   814       return true; | 
|   853   } |   815   } | 
|   854  |   816  | 
|   855   // Some messages are handled by delegates. |   817   // Some messages are handled by delegates. | 
|   856   if (appcache_dispatcher_->OnMessageReceived(msg)) |   818   if (appcache_dispatcher_->OnMessageReceived(msg) || | 
 |   819       dom_storage_dispatcher_->OnMessageReceived(msg)) { | 
|   857     return true; |   820     return true; | 
 |   821   } | 
|   858  |   822  | 
|   859   bool handled = true; |   823   bool handled = true; | 
|   860   IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg) |   824   IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg) | 
|   861     IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL, |   825     IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL, | 
|   862                         OnSetZoomLevelForCurrentURL) |   826                         OnSetZoomLevelForCurrentURL) | 
|   863     IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors) |   827     IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors) | 
|   864     // TODO(port): removed from render_messages_internal.h; |   828     // TODO(port): removed from render_messages_internal.h; | 
|   865     // is there a new non-windows message I should add here? |   829     // is there a new non-windows message I should add here? | 
|   866     IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView) |   830     IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView) | 
|   867     IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache) |   831     IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache) | 
|   868     IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged) |   832     IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged) | 
|   869     IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, OnDOMStorageEvent) |  | 
|   870     IPC_MESSAGE_HANDLER(ViewMsg_TempCrashWithData, OnTempCrashWithData) |   833     IPC_MESSAGE_HANDLER(ViewMsg_TempCrashWithData, OnTempCrashWithData) | 
|   871     IPC_MESSAGE_UNHANDLED(handled = false) |   834     IPC_MESSAGE_UNHANDLED(handled = false) | 
|   872   IPC_END_MESSAGE_MAP() |   835   IPC_END_MESSAGE_MAP() | 
|   873   return handled; |   836   return handled; | 
|   874 } |   837 } | 
|   875  |   838  | 
|   876 // Called when to register CSS Color name->system color mappings. |   839 // Called when to register CSS Color name->system color mappings. | 
|   877 // We update the colors one by one and then tell WebKit to refresh all render |   840 // We update the colors one by one and then tell WebKit to refresh all render | 
|   878 // views. |   841 // views. | 
|   879 void RenderThreadImpl::OnSetCSSColors( |   842 void RenderThreadImpl::OnSetCSSColors( | 
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1003  |   966  | 
|  1004 scoped_refptr<base::MessageLoopProxy> |   967 scoped_refptr<base::MessageLoopProxy> | 
|  1005 RenderThreadImpl::GetFileThreadMessageLoopProxy() { |   968 RenderThreadImpl::GetFileThreadMessageLoopProxy() { | 
|  1006   DCHECK(message_loop() == MessageLoop::current()); |   969   DCHECK(message_loop() == MessageLoop::current()); | 
|  1007   if (!file_thread_.get()) { |   970   if (!file_thread_.get()) { | 
|  1008     file_thread_.reset(new base::Thread("Renderer::FILE")); |   971     file_thread_.reset(new base::Thread("Renderer::FILE")); | 
|  1009     file_thread_->Start(); |   972     file_thread_->Start(); | 
|  1010   } |   973   } | 
|  1011   return file_thread_->message_loop_proxy(); |   974   return file_thread_->message_loop_proxy(); | 
|  1012 } |   975 } | 
| OLD | NEW |