| 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 "chrome/renderer/extensions/dispatcher.h" | 5 #include "chrome/renderer/extensions/dispatcher.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
| 11 #include "chrome/common/child_process_logging.h" | 11 #include "chrome/common/child_process_logging.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/chrome_version_info.h" | 13 #include "chrome/common/chrome_version_info.h" |
| 14 #include "chrome/common/extensions/api/extension_api.h" | 14 #include "chrome/common/extensions/api/extension_api.h" |
| 15 #include "chrome/common/extensions/background_info.h" |
| 15 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/extensions/extension_messages.h" | 17 #include "chrome/common/extensions/extension_messages.h" |
| 17 #include "chrome/common/extensions/manifest.h" | 18 #include "chrome/common/extensions/manifest.h" |
| 18 #include "chrome/common/extensions/permissions/permission_set.h" | 19 #include "chrome/common/extensions/permissions/permission_set.h" |
| 19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 20 #include "chrome/common/view_type.h" | 21 #include "chrome/common/view_type.h" |
| 21 #include "chrome/renderer/chrome_render_process_observer.h" | 22 #include "chrome/renderer/chrome_render_process_observer.h" |
| 22 #include "chrome/renderer/extensions/api_definitions_natives.h" | 23 #include "chrome/renderer/extensions/api_definitions_natives.h" |
| 23 #include "chrome/renderer/extensions/app_bindings.h" | 24 #include "chrome/renderer/extensions/app_bindings.h" |
| 24 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h" | 25 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 return v8::Undefined(); | 162 return v8::Undefined(); |
| 162 } | 163 } |
| 163 | 164 |
| 164 private: | 165 private: |
| 165 bool IsContextLazyBackgroundPage(RenderView* render_view, | 166 bool IsContextLazyBackgroundPage(RenderView* render_view, |
| 166 const Extension* extension) { | 167 const Extension* extension) { |
| 167 if (!render_view) | 168 if (!render_view) |
| 168 return false; | 169 return false; |
| 169 | 170 |
| 170 ExtensionHelper* helper = ExtensionHelper::Get(render_view); | 171 ExtensionHelper* helper = ExtensionHelper::Get(render_view); |
| 171 return (extension && extension->has_lazy_background_page() && | 172 return (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && |
| 172 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 173 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
| 173 } | 174 } |
| 174 }; | 175 }; |
| 175 | 176 |
| 176 class ProcessInfoNativeHandler : public ChromeV8Extension { | 177 class ProcessInfoNativeHandler : public ChromeV8Extension { |
| 177 public: | 178 public: |
| 178 explicit ProcessInfoNativeHandler( | 179 explicit ProcessInfoNativeHandler( |
| 179 Dispatcher* dispatcher, | 180 Dispatcher* dispatcher, |
| 180 const std::string& extension_id, | 181 const std::string& extension_id, |
| 181 const std::string& context_type, | 182 const std::string& context_type, |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 // Reset the idle handler each time there's any activity like event or message | 441 // Reset the idle handler each time there's any activity like event or message |
| 441 // dispatch, for which Invoke is the chokepoint. | 442 // dispatch, for which Invoke is the chokepoint. |
| 442 if (is_extension_process_) { | 443 if (is_extension_process_) { |
| 443 RenderThread::Get()->ScheduleIdleHandler( | 444 RenderThread::Get()->ScheduleIdleHandler( |
| 444 kInitialExtensionIdleHandlerDelayMs); | 445 kInitialExtensionIdleHandlerDelayMs); |
| 445 } | 446 } |
| 446 | 447 |
| 447 // Tell the browser process when an event has been dispatched with a lazy | 448 // Tell the browser process when an event has been dispatched with a lazy |
| 448 // background page active. | 449 // background page active. |
| 449 const Extension* extension = extensions_.GetByID(extension_id); | 450 const Extension* extension = extensions_.GetByID(extension_id); |
| 450 if (extension && extension->has_lazy_background_page() && | 451 if (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && |
| 451 function_name == kEventDispatchFunction) { | 452 function_name == kEventDispatchFunction) { |
| 452 RenderView* background_view = | 453 RenderView* background_view = |
| 453 ExtensionHelper::GetBackgroundPage(extension_id); | 454 ExtensionHelper::GetBackgroundPage(extension_id); |
| 454 if (background_view) { | 455 if (background_view) { |
| 455 background_view->Send(new ExtensionHostMsg_EventAck( | 456 background_view->Send(new ExtensionHostMsg_EventAck( |
| 456 background_view->GetRoutingID())); | 457 background_view->GetRoutingID())); |
| 457 } | 458 } |
| 458 } | 459 } |
| 459 } | 460 } |
| 460 | 461 |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 module_system->RegisterNativeHandler("print", | 778 module_system->RegisterNativeHandler("print", |
| 778 scoped_ptr<NativeHandler>(new PrintNativeHandler(isolate))); | 779 scoped_ptr<NativeHandler>(new PrintNativeHandler(isolate))); |
| 779 module_system->RegisterNativeHandler("lazy_background_page", | 780 module_system->RegisterNativeHandler("lazy_background_page", |
| 780 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); | 781 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); |
| 781 module_system->RegisterNativeHandler("logging", | 782 module_system->RegisterNativeHandler("logging", |
| 782 scoped_ptr<NativeHandler>(new LoggingNativeHandler(isolate))); | 783 scoped_ptr<NativeHandler>(new LoggingNativeHandler(isolate))); |
| 783 | 784 |
| 784 int manifest_version = extension ? extension->manifest_version() : 1; | 785 int manifest_version = extension ? extension->manifest_version() : 1; |
| 785 bool send_request_disabled = | 786 bool send_request_disabled = |
| 786 (extension && Manifest::IsUnpackedLocation(extension->location()) && | 787 (extension && Manifest::IsUnpackedLocation(extension->location()) && |
| 787 extension->has_lazy_background_page()); | 788 BackgroundInfo::HasLazyBackgroundPage(extension)); |
| 788 module_system->RegisterNativeHandler("process", | 789 module_system->RegisterNativeHandler("process", |
| 789 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 790 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
| 790 this, context->GetExtensionID(), | 791 this, context->GetExtensionID(), |
| 791 context->GetContextTypeDescription(), | 792 context->GetContextTypeDescription(), |
| 792 ChromeRenderProcessObserver::is_incognito_process(), | 793 ChromeRenderProcessObserver::is_incognito_process(), |
| 793 manifest_version, send_request_disabled))); | 794 manifest_version, send_request_disabled))); |
| 794 | 795 |
| 795 GetOrCreateChrome(v8_context); | 796 GetOrCreateChrome(v8_context); |
| 796 | 797 |
| 797 // Loading JavaScript is expensive, so only run the full API bindings | 798 // Loading JavaScript is expensive, so only run the full API bindings |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1155 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
| 1155 v8::ThrowException( | 1156 v8::ThrowException( |
| 1156 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1157 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
| 1157 return false; | 1158 return false; |
| 1158 } | 1159 } |
| 1159 | 1160 |
| 1160 return true; | 1161 return true; |
| 1161 } | 1162 } |
| 1162 | 1163 |
| 1163 } // namespace extensions | 1164 } // namespace extensions |
| OLD | NEW |