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 1452 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 } |
(...skipping 76 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 |