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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 module_system->RegisterNativeHandler("print", | 774 module_system->RegisterNativeHandler("print", |
774 scoped_ptr<NativeHandler>(new PrintNativeHandler(isolate))); | 775 scoped_ptr<NativeHandler>(new PrintNativeHandler(isolate))); |
775 module_system->RegisterNativeHandler("lazy_background_page", | 776 module_system->RegisterNativeHandler("lazy_background_page", |
776 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); | 777 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); |
777 module_system->RegisterNativeHandler("logging", | 778 module_system->RegisterNativeHandler("logging", |
778 scoped_ptr<NativeHandler>(new LoggingNativeHandler(isolate))); | 779 scoped_ptr<NativeHandler>(new LoggingNativeHandler(isolate))); |
779 | 780 |
780 int manifest_version = extension ? extension->manifest_version() : 1; | 781 int manifest_version = extension ? extension->manifest_version() : 1; |
781 bool send_request_disabled = | 782 bool send_request_disabled = |
782 (extension && extension->location() == Manifest::LOAD && | 783 (extension && extension->location() == Manifest::LOAD && |
783 extension->has_lazy_background_page()); | 784 BackgroundInfo::HasLazyBackgroundPage(extension)); |
784 module_system->RegisterNativeHandler("process", | 785 module_system->RegisterNativeHandler("process", |
785 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 786 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
786 this, context->GetExtensionID(), | 787 this, context->GetExtensionID(), |
787 context->GetContextTypeDescription(), | 788 context->GetContextTypeDescription(), |
788 ChromeRenderProcessObserver::is_incognito_process(), | 789 ChromeRenderProcessObserver::is_incognito_process(), |
789 manifest_version, send_request_disabled))); | 790 manifest_version, send_request_disabled))); |
790 | 791 |
791 GetOrCreateChrome(v8_context); | 792 GetOrCreateChrome(v8_context); |
792 | 793 |
793 // Loading JavaScript is expensive, so only run the full API bindings | 794 // Loading JavaScript is expensive, so only run the full API bindings |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1150 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
1150 v8::ThrowException( | 1151 v8::ThrowException( |
1151 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1152 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
1152 return false; | 1153 return false; |
1153 } | 1154 } |
1154 | 1155 |
1155 return true; | 1156 return true; |
1156 } | 1157 } |
1157 | 1158 |
1158 } // namespace extensions | 1159 } // namespace extensions |
OLD | NEW |