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 29 matching lines...) Expand all Loading... |
40 #include "chrome/renderer/extensions/extension_groups.h" | 40 #include "chrome/renderer/extensions/extension_groups.h" |
41 #include "chrome/renderer/extensions/extension_helper.h" | 41 #include "chrome/renderer/extensions/extension_helper.h" |
42 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" | 42 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" |
43 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" | 43 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" |
44 #include "chrome/renderer/extensions/file_system_natives.h" | 44 #include "chrome/renderer/extensions/file_system_natives.h" |
45 #include "chrome/renderer/extensions/i18n_custom_bindings.h" | 45 #include "chrome/renderer/extensions/i18n_custom_bindings.h" |
46 #include "chrome/renderer/extensions/id_generator_custom_bindings.h" | 46 #include "chrome/renderer/extensions/id_generator_custom_bindings.h" |
47 #include "chrome/renderer/extensions/logging_native_handler.h" | 47 #include "chrome/renderer/extensions/logging_native_handler.h" |
48 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" | 48 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" |
49 #include "chrome/renderer/extensions/messaging_bindings.h" | 49 #include "chrome/renderer/extensions/messaging_bindings.h" |
50 #include "chrome/renderer/extensions/module_system.h" | |
51 #include "chrome/renderer/extensions/object_backed_native_handler.h" | |
52 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" | 50 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" |
53 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" | 51 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" |
54 #include "chrome/renderer/extensions/pepper_request_natives.h" | 52 #include "chrome/renderer/extensions/pepper_request_natives.h" |
55 #include "chrome/renderer/extensions/render_view_observer_natives.h" | 53 #include "chrome/renderer/extensions/render_view_observer_natives.h" |
56 #include "chrome/renderer/extensions/request_sender.h" | |
57 #include "chrome/renderer/extensions/runtime_custom_bindings.h" | 54 #include "chrome/renderer/extensions/runtime_custom_bindings.h" |
58 #include "chrome/renderer/extensions/safe_builtins.h" | |
59 #include "chrome/renderer/extensions/send_request_natives.h" | 55 #include "chrome/renderer/extensions/send_request_natives.h" |
60 #include "chrome/renderer/extensions/set_icon_natives.h" | 56 #include "chrome/renderer/extensions/set_icon_natives.h" |
61 #include "chrome/renderer/extensions/sync_file_system_custom_bindings.h" | 57 #include "chrome/renderer/extensions/sync_file_system_custom_bindings.h" |
62 #include "chrome/renderer/extensions/tab_finder.h" | 58 #include "chrome/renderer/extensions/tab_finder.h" |
63 #include "chrome/renderer/extensions/tabs_custom_bindings.h" | 59 #include "chrome/renderer/extensions/tabs_custom_bindings.h" |
64 #include "chrome/renderer/extensions/user_script_slave.h" | 60 #include "chrome/renderer/extensions/user_script_slave.h" |
65 #include "chrome/renderer/extensions/utils_native_handler.h" | 61 #include "chrome/renderer/extensions/utils_native_handler.h" |
66 #include "chrome/renderer/extensions/webstore_bindings.h" | 62 #include "chrome/renderer/extensions/webstore_bindings.h" |
67 #include "chrome/renderer/resource_bundle_source_map.h" | 63 #include "chrome/renderer/resource_bundle_source_map.h" |
68 #include "content/public/renderer/render_thread.h" | 64 #include "content/public/renderer/render_thread.h" |
69 #include "content/public/renderer/render_view.h" | 65 #include "content/public/renderer/render_view.h" |
70 #include "content/public/renderer/v8_value_converter.h" | 66 #include "content/public/renderer/v8_value_converter.h" |
71 #include "extensions/common/api/messaging/message.h" | 67 #include "extensions/common/api/messaging/message.h" |
72 #include "extensions/common/constants.h" | 68 #include "extensions/common/constants.h" |
73 #include "extensions/common/extension.h" | 69 #include "extensions/common/extension.h" |
74 #include "extensions/common/extension_api.h" | 70 #include "extensions/common/extension_api.h" |
75 #include "extensions/common/extension_messages.h" | 71 #include "extensions/common/extension_messages.h" |
76 #include "extensions/common/extension_urls.h" | 72 #include "extensions/common/extension_urls.h" |
77 #include "extensions/common/features/feature.h" | 73 #include "extensions/common/features/feature.h" |
78 #include "extensions/common/features/feature_provider.h" | 74 #include "extensions/common/features/feature_provider.h" |
79 #include "extensions/common/manifest.h" | 75 #include "extensions/common/manifest.h" |
80 #include "extensions/common/manifest_constants.h" | 76 #include "extensions/common/manifest_constants.h" |
81 #include "extensions/common/manifest_handlers/background_info.h" | 77 #include "extensions/common/manifest_handlers/background_info.h" |
82 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" | 78 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" |
83 #include "extensions/common/message_bundle.h" | 79 #include "extensions/common/message_bundle.h" |
84 #include "extensions/common/permissions/permission_set.h" | 80 #include "extensions/common/permissions/permission_set.h" |
85 #include "extensions/common/permissions/permissions_data.h" | 81 #include "extensions/common/permissions/permissions_data.h" |
86 #include "extensions/common/switches.h" | 82 #include "extensions/common/switches.h" |
87 #include "extensions/common/view_type.h" | 83 #include "extensions/common/view_type.h" |
| 84 #include "extensions/renderer/module_system.h" |
| 85 #include "extensions/renderer/object_backed_native_handler.h" |
| 86 #include "extensions/renderer/request_sender.h" |
| 87 #include "extensions/renderer/safe_builtins.h" |
| 88 #include "extensions/renderer/script_context.h" |
88 #include "grit/common_resources.h" | 89 #include "grit/common_resources.h" |
89 #include "grit/renderer_resources.h" | 90 #include "grit/renderer_resources.h" |
90 #include "third_party/WebKit/public/platform/WebString.h" | 91 #include "third_party/WebKit/public/platform/WebString.h" |
91 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 92 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
92 #include "third_party/WebKit/public/web/WebCustomElement.h" | 93 #include "third_party/WebKit/public/web/WebCustomElement.h" |
93 #include "third_party/WebKit/public/web/WebDataSource.h" | 94 #include "third_party/WebKit/public/web/WebDataSource.h" |
94 #include "third_party/WebKit/public/web/WebDocument.h" | 95 #include "third_party/WebKit/public/web/WebDocument.h" |
95 #include "third_party/WebKit/public/web/WebFrame.h" | 96 #include "third_party/WebKit/public/web/WebFrame.h" |
96 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 97 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
97 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 98 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
(...skipping 28 matching lines...) Expand all Loading... |
126 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; | 127 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; |
127 static const char kEventDispatchFunction[] = "dispatchEvent"; | 128 static const char kEventDispatchFunction[] = "dispatchEvent"; |
128 static const char kOnSuspendEvent[] = "runtime.onSuspend"; | 129 static const char kOnSuspendEvent[] = "runtime.onSuspend"; |
129 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; | 130 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; |
130 | 131 |
131 // Returns the global value for "chrome" from |context|. If one doesn't exist | 132 // Returns the global value for "chrome" from |context|. If one doesn't exist |
132 // creates a new object for it. | 133 // creates a new object for it. |
133 // | 134 // |
134 // Note that this isn't necessarily an object, since webpages can write, for | 135 // Note that this isn't necessarily an object, since webpages can write, for |
135 // example, "window.chrome = true". | 136 // example, "window.chrome = true". |
136 v8::Handle<v8::Value> GetOrCreateChrome(ChromeV8Context* context) { | 137 v8::Handle<v8::Value> GetOrCreateChrome(ScriptContext* context) { |
137 v8::Handle<v8::String> chrome_string( | 138 v8::Handle<v8::String> chrome_string( |
138 v8::String::NewFromUtf8(context->isolate(), "chrome")); | 139 v8::String::NewFromUtf8(context->isolate(), "chrome")); |
139 v8::Handle<v8::Object> global(context->v8_context()->Global()); | 140 v8::Handle<v8::Object> global(context->v8_context()->Global()); |
140 v8::Handle<v8::Value> chrome(global->Get(chrome_string)); | 141 v8::Handle<v8::Value> chrome(global->Get(chrome_string)); |
141 if (chrome->IsUndefined()) { | 142 if (chrome->IsUndefined()) { |
142 chrome = v8::Object::New(context->isolate()); | 143 chrome = v8::Object::New(context->isolate()); |
143 global->Set(chrome_string, chrome); | 144 global->Set(chrome_string, chrome); |
144 } | 145 } |
145 return chrome; | 146 return chrome; |
146 } | 147 } |
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 // "invalid". This isn't interesting. | 1125 // "invalid". This isn't interesting. |
1125 if (extension_id != "invalid") { | 1126 if (extension_id != "invalid") { |
1126 LOG(ERROR) << "Extension \"" << extension_id << "\" not found"; | 1127 LOG(ERROR) << "Extension \"" << extension_id << "\" not found"; |
1127 RenderThread::Get()->RecordAction( | 1128 RenderThread::Get()->RecordAction( |
1128 UserMetricsAction("ExtensionNotFound_ED")); | 1129 UserMetricsAction("ExtensionNotFound_ED")); |
1129 } | 1130 } |
1130 | 1131 |
1131 extension_id = ""; | 1132 extension_id = ""; |
1132 } | 1133 } |
1133 | 1134 |
1134 Feature::Context context_type = ClassifyJavaScriptContext( | 1135 Feature::Context context_type = |
1135 extension, | 1136 ClassifyJavaScriptContext(extension, |
1136 extension_group, | 1137 extension_group, |
1137 UserScriptSlave::GetDataSourceURLForFrame(frame), | 1138 ScriptContext::GetDataSourceURLForFrame(frame), |
1138 frame->document().securityOrigin()); | 1139 frame->document().securityOrigin()); |
1139 | 1140 |
1140 ChromeV8Context* context = | 1141 ChromeV8Context* context = |
1141 new ChromeV8Context(v8_context, frame, extension, context_type); | 1142 new ChromeV8Context(v8_context, frame, extension, context_type); |
1142 v8_context_set_.Add(context); | 1143 v8_context_set_.Add(context); |
1143 | 1144 |
1144 if (extension) | 1145 if (extension) |
1145 InitOriginPermissions(extension, context_type); | 1146 InitOriginPermissions(extension, context_type); |
1146 | 1147 |
1147 { | 1148 { |
1148 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(context, | 1149 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(context, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 if (world_id != 0) { | 1265 if (world_id != 0) { |
1265 // Isolated worlds (content script). | 1266 // Isolated worlds (content script). |
1266 return user_script_slave_->GetExtensionIdForIsolatedWorld(world_id); | 1267 return user_script_slave_->GetExtensionIdForIsolatedWorld(world_id); |
1267 } | 1268 } |
1268 | 1269 |
1269 // TODO(kalman): Delete this check. | 1270 // TODO(kalman): Delete this check. |
1270 if (frame->document().securityOrigin().isUnique()) | 1271 if (frame->document().securityOrigin().isUnique()) |
1271 return std::string(); | 1272 return std::string(); |
1272 | 1273 |
1273 // Extension pages (chrome-extension:// URLs). | 1274 // Extension pages (chrome-extension:// URLs). |
1274 GURL frame_url = UserScriptSlave::GetDataSourceURLForFrame(frame); | 1275 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame); |
1275 return extensions_.GetExtensionOrAppIDByURL(frame_url); | 1276 return extensions_.GetExtensionOrAppIDByURL(frame_url); |
1276 } | 1277 } |
1277 | 1278 |
1278 bool Dispatcher::IsWithinPlatformApp() { | 1279 bool Dispatcher::IsWithinPlatformApp() { |
1279 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); | 1280 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); |
1280 iter != active_extension_ids_.end(); ++iter) { | 1281 iter != active_extension_ids_.end(); ++iter) { |
1281 const Extension* extension = extensions_.GetByID(*iter); | 1282 const Extension* extension = extensions_.GetByID(*iter); |
1282 if (extension && extension->is_platform_app()) | 1283 if (extension && extension->is_platform_app()) |
1283 return true; | 1284 return true; |
1284 } | 1285 } |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1599 } | 1600 } |
1600 | 1601 |
1601 void Dispatcher::OnExtensionResponse(int request_id, | 1602 void Dispatcher::OnExtensionResponse(int request_id, |
1602 bool success, | 1603 bool success, |
1603 const base::ListValue& response, | 1604 const base::ListValue& response, |
1604 const std::string& error) { | 1605 const std::string& error) { |
1605 request_sender_->HandleResponse(request_id, success, response, error); | 1606 request_sender_->HandleResponse(request_id, success, response, error); |
1606 } | 1607 } |
1607 | 1608 |
1608 bool Dispatcher::CheckContextAccessToExtensionAPI( | 1609 bool Dispatcher::CheckContextAccessToExtensionAPI( |
1609 const std::string& function_name, ChromeV8Context* context) const { | 1610 const std::string& function_name, |
| 1611 ScriptContext* context) const { |
1610 if (!context) { | 1612 if (!context) { |
1611 DLOG(ERROR) << "Not in a v8::Context"; | 1613 DLOG(ERROR) << "Not in a v8::Context"; |
1612 return false; | 1614 return false; |
1613 } | 1615 } |
1614 | 1616 |
1615 if (!context->extension()) { | 1617 if (!context->extension()) { |
1616 context->isolate()->ThrowException(v8::Exception::Error( | 1618 context->isolate()->ThrowException(v8::Exception::Error( |
1617 v8::String::NewFromUtf8(context->isolate(), "Not in an extension."))); | 1619 v8::String::NewFromUtf8(context->isolate(), "Not in an extension."))); |
1618 return false; | 1620 return false; |
1619 } | 1621 } |
1620 | 1622 |
1621 // Theoretically we could end up with bindings being injected into sandboxed | 1623 // Theoretically we could end up with bindings being injected into sandboxed |
1622 // frames, for example content scripts. Don't let them execute API functions. | 1624 // frames, for example content scripts. Don't let them execute API functions. |
1623 blink::WebFrame* frame = context->web_frame(); | 1625 blink::WebFrame* frame = context->web_frame(); |
1624 if (IsSandboxedPage(UserScriptSlave::GetDataSourceURLForFrame(frame))) { | 1626 if (IsSandboxedPage(ScriptContext::GetDataSourceURLForFrame(frame))) { |
1625 static const char kMessage[] = | 1627 static const char kMessage[] = |
1626 "%s cannot be used within a sandboxed frame."; | 1628 "%s cannot be used within a sandboxed frame."; |
1627 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1629 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
1628 context->isolate()->ThrowException(v8::Exception::Error( | 1630 context->isolate()->ThrowException(v8::Exception::Error( |
1629 v8::String::NewFromUtf8(context->isolate(), error_msg.c_str()))); | 1631 v8::String::NewFromUtf8(context->isolate(), error_msg.c_str()))); |
1630 return false; | 1632 return false; |
1631 } | 1633 } |
1632 | 1634 |
1633 Feature::Availability availability = context->GetAvailability(function_name); | 1635 Feature::Availability availability = context->GetAvailability(function_name); |
1634 if (!availability.is_available()) { | 1636 if (!availability.is_available()) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1696 } | 1698 } |
1697 | 1699 |
1698 void Dispatcher::ClearPortData(int port_id) { | 1700 void Dispatcher::ClearPortData(int port_id) { |
1699 // Only the target port side has entries in |port_to_tab_id_map_|. If | 1701 // Only the target port side has entries in |port_to_tab_id_map_|. If |
1700 // |port_id| is a source port, std::map::erase() will just silently fail | 1702 // |port_id| is a source port, std::map::erase() will just silently fail |
1701 // here as a no-op. | 1703 // here as a no-op. |
1702 port_to_tab_id_map_.erase(port_id); | 1704 port_to_tab_id_map_.erase(port_id); |
1703 } | 1705 } |
1704 | 1706 |
1705 } // namespace extensions | 1707 } // namespace extensions |
OLD | NEW |