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/debug/alias.h" | 9 #include "base/debug/alias.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 #include "chrome/renderer/extensions/tabs_custom_bindings.h" | 71 #include "chrome/renderer/extensions/tabs_custom_bindings.h" |
72 #include "chrome/renderer/extensions/tts_custom_bindings.h" | 72 #include "chrome/renderer/extensions/tts_custom_bindings.h" |
73 #include "chrome/renderer/extensions/user_script_slave.h" | 73 #include "chrome/renderer/extensions/user_script_slave.h" |
74 #include "chrome/renderer/extensions/web_request_custom_bindings.h" | 74 #include "chrome/renderer/extensions/web_request_custom_bindings.h" |
75 #include "chrome/renderer/extensions/webstore_bindings.h" | 75 #include "chrome/renderer/extensions/webstore_bindings.h" |
76 #include "chrome/renderer/resource_bundle_source_map.h" | 76 #include "chrome/renderer/resource_bundle_source_map.h" |
77 #include "content/public/renderer/render_thread.h" | 77 #include "content/public/renderer/render_thread.h" |
78 #include "content/public/renderer/render_view.h" | 78 #include "content/public/renderer/render_view.h" |
79 #include "content/public/renderer/v8_value_converter.h" | 79 #include "content/public/renderer/v8_value_converter.h" |
80 #include "extensions/common/constants.h" | 80 #include "extensions/common/constants.h" |
| 81 #include "extensions/common/extension_urls.h" |
81 #include "extensions/common/features/feature.h" | 82 #include "extensions/common/features/feature.h" |
82 #include "extensions/common/features/feature_provider.h" | 83 #include "extensions/common/features/feature_provider.h" |
83 #include "extensions/common/manifest.h" | 84 #include "extensions/common/manifest.h" |
84 #include "extensions/common/manifest_constants.h" | 85 #include "extensions/common/manifest_constants.h" |
85 #include "extensions/common/view_type.h" | 86 #include "extensions/common/view_type.h" |
86 #include "grit/common_resources.h" | 87 #include "grit/common_resources.h" |
87 #include "grit/renderer_resources.h" | 88 #include "grit/renderer_resources.h" |
88 #include "third_party/WebKit/public/platform/WebString.h" | 89 #include "third_party/WebKit/public/platform/WebString.h" |
89 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 90 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
90 #include "third_party/WebKit/public/web/WebCustomElement.h" | 91 #include "third_party/WebKit/public/web/WebCustomElement.h" |
(...skipping 20 matching lines...) Expand all Loading... |
111 using content::RenderView; | 112 using content::RenderView; |
112 | 113 |
113 namespace extensions { | 114 namespace extensions { |
114 | 115 |
115 namespace runtime = api::runtime; | 116 namespace runtime = api::runtime; |
116 | 117 |
117 namespace { | 118 namespace { |
118 | 119 |
119 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; | 120 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; |
120 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; | 121 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; |
121 static const char kEventModule[] = "event_bindings"; | |
122 static const char kEventDispatchFunction[] = "dispatchEvent"; | 122 static const char kEventDispatchFunction[] = "dispatchEvent"; |
123 | 123 |
124 // Returns the global value for "chrome" from |context|. If one doesn't exist | 124 // Returns the global value for "chrome" from |context|. If one doesn't exist |
125 // creates a new object for it. | 125 // creates a new object for it. |
126 // | 126 // |
127 // Note that this isn't necessarily an object, since webpages can write, for | 127 // Note that this isn't necessarily an object, since webpages can write, for |
128 // example, "window.chrome = true". | 128 // example, "window.chrome = true". |
129 v8::Handle<v8::Value> GetOrCreateChrome(ChromeV8Context* context) { | 129 v8::Handle<v8::Value> GetOrCreateChrome(ChromeV8Context* context) { |
130 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); | 130 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); |
131 v8::Handle<v8::Object> global(context->v8_context()->Global()); | 131 v8::Handle<v8::Object> global(context->v8_context()->Global()); |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 scoped_ptr<NativeHandler>( | 898 scoped_ptr<NativeHandler>( |
899 new WebRequestCustomBindings(this, context))); | 899 new WebRequestCustomBindings(this, context))); |
900 module_system->RegisterNativeHandler("webstore", | 900 module_system->RegisterNativeHandler("webstore", |
901 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); | 901 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); |
902 } | 902 } |
903 | 903 |
904 void Dispatcher::PopulateSourceMap() { | 904 void Dispatcher::PopulateSourceMap() { |
905 // Libraries. | 905 // Libraries. |
906 source_map_.RegisterSource("contentWatcher", IDR_CONTENT_WATCHER_JS); | 906 source_map_.RegisterSource("contentWatcher", IDR_CONTENT_WATCHER_JS); |
907 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); | 907 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); |
908 source_map_.RegisterSource(kEventModule, IDR_EVENT_BINDINGS_JS); | 908 source_map_.RegisterSource(kEventBindings, IDR_EVENT_BINDINGS_JS); |
909 source_map_.RegisterSource("imageUtil", IDR_IMAGE_UTIL_JS); | 909 source_map_.RegisterSource("imageUtil", IDR_IMAGE_UTIL_JS); |
910 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); | 910 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); |
911 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); | 911 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); |
912 source_map_.RegisterSource("messaging", IDR_MESSAGING_JS); | 912 source_map_.RegisterSource("messaging", IDR_MESSAGING_JS); |
913 source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS); | 913 source_map_.RegisterSource(kSchemaUtils, IDR_SCHEMA_UTILS_JS); |
914 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS); | 914 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS); |
915 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS); | 915 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS); |
916 source_map_.RegisterSource("test", IDR_TEST_CUSTOM_BINDINGS_JS); | 916 source_map_.RegisterSource("test", IDR_TEST_CUSTOM_BINDINGS_JS); |
917 source_map_.RegisterSource("unload_event", IDR_UNLOAD_EVENT_JS); | 917 source_map_.RegisterSource("unload_event", IDR_UNLOAD_EVENT_JS); |
918 source_map_.RegisterSource("utils", IDR_UTILS_JS); | 918 source_map_.RegisterSource("utils", IDR_UTILS_JS); |
919 | 919 |
920 // Custom bindings. | 920 // Custom bindings. |
921 source_map_.RegisterSource("app", IDR_APP_CUSTOM_BINDINGS_JS); | 921 source_map_.RegisterSource("app", IDR_APP_CUSTOM_BINDINGS_JS); |
922 source_map_.RegisterSource("app.runtime", IDR_APP_RUNTIME_CUSTOM_BINDINGS_JS); | 922 source_map_.RegisterSource("app.runtime", IDR_APP_RUNTIME_CUSTOM_BINDINGS_JS); |
923 source_map_.RegisterSource("app.window", IDR_APP_WINDOW_CUSTOM_BINDINGS_JS); | 923 source_map_.RegisterSource("app.window", IDR_APP_WINDOW_CUSTOM_BINDINGS_JS); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 context->GetContextTypeDescription(), | 1084 context->GetContextTypeDescription(), |
1085 ChromeRenderProcessObserver::is_incognito_process(), | 1085 ChromeRenderProcessObserver::is_incognito_process(), |
1086 manifest_version, send_request_disabled))); | 1086 manifest_version, send_request_disabled))); |
1087 | 1087 |
1088 // chrome.Event is part of the public API (although undocumented). Make it | 1088 // chrome.Event is part of the public API (although undocumented). Make it |
1089 // lazily evalulate to Event from event_bindings.js. For extensions only | 1089 // lazily evalulate to Event from event_bindings.js. For extensions only |
1090 // though, not all webpages! | 1090 // though, not all webpages! |
1091 if (context->extension()) { | 1091 if (context->extension()) { |
1092 v8::Handle<v8::Object> chrome = AsObjectOrEmpty(GetOrCreateChrome(context)); | 1092 v8::Handle<v8::Object> chrome = AsObjectOrEmpty(GetOrCreateChrome(context)); |
1093 if (!chrome.IsEmpty()) | 1093 if (!chrome.IsEmpty()) |
1094 module_system->SetLazyField(chrome, "Event", kEventModule, "Event"); | 1094 module_system->SetLazyField(chrome, "Event", kEventBindings, "Event"); |
1095 } | 1095 } |
1096 | 1096 |
1097 AddOrRemoveBindingsForContext(context); | 1097 AddOrRemoveBindingsForContext(context); |
1098 | 1098 |
1099 bool is_within_platform_app = IsWithinPlatformApp(); | 1099 bool is_within_platform_app = IsWithinPlatformApp(); |
1100 // Inject custom JS into the platform app context. | 1100 // Inject custom JS into the platform app context. |
1101 if (is_within_platform_app) { | 1101 if (is_within_platform_app) { |
1102 module_system->Require("platformApp"); | 1102 module_system->Require("platformApp"); |
1103 } | 1103 } |
1104 | 1104 |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 } | 1514 } |
1515 | 1515 |
1516 return availability.is_available(); | 1516 return availability.is_available(); |
1517 } | 1517 } |
1518 | 1518 |
1519 void Dispatcher::DispatchEvent(const std::string& extension_id, | 1519 void Dispatcher::DispatchEvent(const std::string& extension_id, |
1520 const std::string& event_name) const { | 1520 const std::string& event_name) const { |
1521 base::ListValue args; | 1521 base::ListValue args; |
1522 args.Set(0, new base::StringValue(event_name)); | 1522 args.Set(0, new base::StringValue(event_name)); |
1523 args.Set(1, new base::ListValue()); | 1523 args.Set(1, new base::ListValue()); |
| 1524 |
| 1525 // Needed for Windows compilation, since kEventBindings is declared extern. |
| 1526 const char* local_event_bindings = kEventBindings; |
1524 v8_context_set_.ForEach( | 1527 v8_context_set_.ForEach( |
1525 extension_id, | 1528 extension_id, |
1526 NULL, // all render views | 1529 NULL, // all render views |
1527 base::Bind(&CallModuleMethod, | 1530 base::Bind(&CallModuleMethod, |
1528 kEventModule, | 1531 local_event_bindings, |
1529 kEventDispatchFunction, | 1532 kEventDispatchFunction, |
1530 &args)); | 1533 &args)); |
1531 } | 1534 } |
1532 | 1535 |
1533 void Dispatcher::InvokeModuleSystemMethod( | 1536 void Dispatcher::InvokeModuleSystemMethod( |
1534 content::RenderView* render_view, | 1537 content::RenderView* render_view, |
1535 const std::string& extension_id, | 1538 const std::string& extension_id, |
1536 const std::string& module_name, | 1539 const std::string& module_name, |
1537 const std::string& function_name, | 1540 const std::string& function_name, |
1538 const base::ListValue& args, | 1541 const base::ListValue& args, |
(...skipping 11 matching lines...) Expand all Loading... |
1550 // dispatch, for which Invoke is the chokepoint. | 1553 // dispatch, for which Invoke is the chokepoint. |
1551 if (is_extension_process_) { | 1554 if (is_extension_process_) { |
1552 RenderThread::Get()->ScheduleIdleHandler( | 1555 RenderThread::Get()->ScheduleIdleHandler( |
1553 kInitialExtensionIdleHandlerDelayMs); | 1556 kInitialExtensionIdleHandlerDelayMs); |
1554 } | 1557 } |
1555 | 1558 |
1556 // Tell the browser process when an event has been dispatched with a lazy | 1559 // Tell the browser process when an event has been dispatched with a lazy |
1557 // background page active. | 1560 // background page active. |
1558 const Extension* extension = extensions_.GetByID(extension_id); | 1561 const Extension* extension = extensions_.GetByID(extension_id); |
1559 if (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && | 1562 if (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && |
1560 module_name == kEventModule && | 1563 module_name == kEventBindings && |
1561 function_name == kEventDispatchFunction) { | 1564 function_name == kEventDispatchFunction) { |
1562 RenderView* background_view = | 1565 RenderView* background_view = |
1563 ExtensionHelper::GetBackgroundPage(extension_id); | 1566 ExtensionHelper::GetBackgroundPage(extension_id); |
1564 if (background_view) { | 1567 if (background_view) { |
1565 background_view->Send(new ExtensionHostMsg_EventAck( | 1568 background_view->Send(new ExtensionHostMsg_EventAck( |
1566 background_view->GetRoutingID())); | 1569 background_view->GetRoutingID())); |
1567 } | 1570 } |
1568 } | 1571 } |
1569 } | 1572 } |
1570 | 1573 |
1571 } // namespace extensions | 1574 } // namespace extensions |
OLD | NEW |