| 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 "base/strings/string_split.h" |
| 11 #include "chrome/common/child_process_logging.h" | 12 #include "chrome/common/child_process_logging.h" |
| 12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/chrome_version_info.h" | 14 #include "chrome/common/chrome_version_info.h" |
| 14 #include "chrome/common/extensions/api/extension_api.h" | 15 #include "chrome/common/extensions/api/extension_api.h" |
| 15 #include "chrome/common/extensions/background_info.h" | 16 #include "chrome/common/extensions/background_info.h" |
| 16 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/common/extensions/extension_messages.h" | 18 #include "chrome/common/extensions/extension_messages.h" |
| 19 #include "chrome/common/extensions/features/feature.h" |
| 18 #include "chrome/common/extensions/manifest.h" | 20 #include "chrome/common/extensions/manifest.h" |
| 19 #include "chrome/common/extensions/permissions/permission_set.h" | 21 #include "chrome/common/extensions/permissions/permission_set.h" |
| 20 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/common/view_type.h" | 23 #include "chrome/common/view_type.h" |
| 22 #include "chrome/renderer/chrome_render_process_observer.h" | 24 #include "chrome/renderer/chrome_render_process_observer.h" |
| 23 #include "chrome/renderer/extensions/api_definitions_natives.h" | 25 #include "chrome/renderer/extensions/api_definitions_natives.h" |
| 24 #include "chrome/renderer/extensions/app_bindings.h" | 26 #include "chrome/renderer/extensions/app_bindings.h" |
| 25 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h" | 27 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h" |
| 26 #include "chrome/renderer/extensions/app_window_custom_bindings.h" | 28 #include "chrome/renderer/extensions/app_window_custom_bindings.h" |
| 29 #include "chrome/renderer/extensions/binding_generating_native_handler.h" |
| 27 #include "chrome/renderer/extensions/chrome_v8_context.h" | 30 #include "chrome/renderer/extensions/chrome_v8_context.h" |
| 28 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 31 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
| 29 #include "chrome/renderer/extensions/content_watcher.h" | 32 #include "chrome/renderer/extensions/content_watcher.h" |
| 30 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" | 33 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" |
| 31 #include "chrome/renderer/extensions/dom_activity_logger.h" | 34 #include "chrome/renderer/extensions/dom_activity_logger.h" |
| 32 #include "chrome/renderer/extensions/event_bindings.h" | 35 #include "chrome/renderer/extensions/event_bindings.h" |
| 33 #include "chrome/renderer/extensions/extension_custom_bindings.h" | 36 #include "chrome/renderer/extensions/extension_custom_bindings.h" |
| 34 #include "chrome/renderer/extensions/extension_groups.h" | 37 #include "chrome/renderer/extensions/extension_groups.h" |
| 35 #include "chrome/renderer/extensions/extension_helper.h" | 38 #include "chrome/renderer/extensions/extension_helper.h" |
| 36 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" | 39 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" |
| 37 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" | 40 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" |
| 38 #include "chrome/renderer/extensions/file_system_natives.h" | 41 #include "chrome/renderer/extensions/file_system_natives.h" |
| 39 #include "chrome/renderer/extensions/i18n_custom_bindings.h" | 42 #include "chrome/renderer/extensions/i18n_custom_bindings.h" |
| 40 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" | 43 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" |
| 41 #include "chrome/renderer/extensions/miscellaneous_bindings.h" | 44 #include "chrome/renderer/extensions/miscellaneous_bindings.h" |
| 42 #include "chrome/renderer/extensions/module_system.h" | 45 #include "chrome/renderer/extensions/module_system.h" |
| 43 #include "chrome/renderer/extensions/native_handler.h" | 46 #include "chrome/renderer/extensions/object_backed_native_handler.h" |
| 44 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" | 47 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" |
| 45 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" | 48 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" |
| 46 #include "chrome/renderer/extensions/request_sender.h" | 49 #include "chrome/renderer/extensions/request_sender.h" |
| 47 #include "chrome/renderer/extensions/runtime_custom_bindings.h" | 50 #include "chrome/renderer/extensions/runtime_custom_bindings.h" |
| 48 #include "chrome/renderer/extensions/send_request_natives.h" | 51 #include "chrome/renderer/extensions/send_request_natives.h" |
| 49 #include "chrome/renderer/extensions/set_icon_natives.h" | 52 #include "chrome/renderer/extensions/set_icon_natives.h" |
| 50 #include "chrome/renderer/extensions/sync_file_system_custom_bindings.h" | 53 #include "chrome/renderer/extensions/sync_file_system_custom_bindings.h" |
| 51 #include "chrome/renderer/extensions/tab_finder.h" | 54 #include "chrome/renderer/extensions/tab_finder.h" |
| 52 #include "chrome/renderer/extensions/tabs_custom_bindings.h" | 55 #include "chrome/renderer/extensions/tabs_custom_bindings.h" |
| 53 #include "chrome/renderer/extensions/tts_custom_bindings.h" | 56 #include "chrome/renderer/extensions/tts_custom_bindings.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 namespace extensions { | 88 namespace extensions { |
| 86 | 89 |
| 87 namespace { | 90 namespace { |
| 88 | 91 |
| 89 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; | 92 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; |
| 90 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; | 93 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; |
| 91 static const char kEventDispatchFunction[] = "Event.dispatchEvent"; | 94 static const char kEventDispatchFunction[] = "Event.dispatchEvent"; |
| 92 static const char kOnSuspendEvent[] = "runtime.onSuspend"; | 95 static const char kOnSuspendEvent[] = "runtime.onSuspend"; |
| 93 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; | 96 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; |
| 94 | 97 |
| 95 class ChromeHiddenNativeHandler : public NativeHandler { | 98 static v8::Handle<v8::Object> GetOrCreateChrome( |
| 99 v8::Handle<v8::Context> context) { |
| 100 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); |
| 101 v8::Handle<v8::Object> global(context->Global()); |
| 102 v8::Handle<v8::Value> chrome(global->Get(chrome_string)); |
| 103 if (chrome.IsEmpty() || chrome->IsUndefined()) { |
| 104 v8::Handle<v8::Object> chrome_object(v8::Object::New()); |
| 105 global->Set(chrome_string, chrome_object); |
| 106 return chrome_object; |
| 107 } |
| 108 CHECK(chrome->IsObject()); |
| 109 return chrome->ToObject(); |
| 110 } |
| 111 |
| 112 class SchemaRegistryNativeHandler : public ObjectBackedNativeHandler { |
| 96 public: | 113 public: |
| 97 explicit ChromeHiddenNativeHandler(v8::Isolate* isolate) | 114 SchemaRegistryNativeHandler(V8SchemaRegistry* registry, |
| 98 : NativeHandler(isolate) { | 115 v8::Handle<v8::Context> context) |
| 116 : ObjectBackedNativeHandler(context), |
| 117 registry_(registry) { |
| 118 RouteFunction("GetSchema", |
| 119 base::Bind(&SchemaRegistryNativeHandler::GetSchema, |
| 120 base::Unretained(this))); |
| 121 } |
| 122 |
| 123 private: |
| 124 v8::Handle<v8::Value> GetSchema(const v8::Arguments& args) { |
| 125 return registry_->GetSchema(*v8::String::AsciiValue(args[0])); |
| 126 } |
| 127 |
| 128 V8SchemaRegistry* registry_; |
| 129 }; |
| 130 |
| 131 class V8ContextNativeHandler : public ObjectBackedNativeHandler { |
| 132 public: |
| 133 explicit V8ContextNativeHandler(ChromeV8Context* context) |
| 134 : ObjectBackedNativeHandler(context->v8_context()), |
| 135 context_(context) { |
| 136 RouteFunction("GetAvailability", |
| 137 base::Bind(&V8ContextNativeHandler::GetAvailability, |
| 138 base::Unretained(this))); |
| 139 } |
| 140 |
| 141 private: |
| 142 v8::Handle<v8::Value> GetAvailability(const v8::Arguments& args) { |
| 143 CHECK_EQ(args.Length(), 1); |
| 144 std::string api_name = *v8::String::AsciiValue(args[0]->ToString()); |
| 145 Feature::Availability availability = context_->GetAvailability(api_name); |
| 146 |
| 147 v8::Handle<v8::Object> ret = v8::Object::New(); |
| 148 ret->Set(v8::String::New("is_available"), |
| 149 v8::Boolean::New(availability.is_available())); |
| 150 ret->Set(v8::String::New("message"), |
| 151 v8::String::New(availability.message().c_str())); |
| 152 return ret; |
| 153 } |
| 154 |
| 155 ChromeV8Context* context_; |
| 156 }; |
| 157 |
| 158 class ChromeHiddenNativeHandler : public ObjectBackedNativeHandler { |
| 159 public: |
| 160 explicit ChromeHiddenNativeHandler(v8::Handle<v8::Context> context) |
| 161 : ObjectBackedNativeHandler(context) { |
| 99 RouteFunction("GetChromeHidden", | 162 RouteFunction("GetChromeHidden", |
| 100 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, | 163 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, |
| 101 base::Unretained(this))); | 164 base::Unretained(this))); |
| 102 } | 165 } |
| 103 | 166 |
| 104 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) { | 167 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) { |
| 105 return ChromeV8Context::GetOrCreateChromeHidden(v8::Context::GetCurrent()); | 168 return ChromeV8Context::GetOrCreateChromeHidden(v8_context()); |
| 106 } | 169 } |
| 107 }; | 170 }; |
| 108 | 171 |
| 109 class PrintNativeHandler : public NativeHandler { | 172 class ChromeNativeHandler : public ObjectBackedNativeHandler { |
| 110 public: | 173 public: |
| 111 explicit PrintNativeHandler(v8::Isolate* isolate) | 174 explicit ChromeNativeHandler(v8::Handle<v8::Context> context) |
| 112 : NativeHandler(isolate) { | 175 : ObjectBackedNativeHandler(context) { |
| 176 RouteFunction("GetChrome", |
| 177 base::Bind(&ChromeNativeHandler::GetChrome, base::Unretained(this))); |
| 178 } |
| 179 |
| 180 v8::Handle<v8::Value> GetChrome(const v8::Arguments& args) { |
| 181 return GetOrCreateChrome(v8_context()); |
| 182 } |
| 183 }; |
| 184 |
| 185 class PrintNativeHandler : public ObjectBackedNativeHandler { |
| 186 public: |
| 187 explicit PrintNativeHandler(v8::Handle<v8::Context> context) |
| 188 : ObjectBackedNativeHandler(context) { |
| 113 RouteFunction("Print", | 189 RouteFunction("Print", |
| 114 base::Bind(&PrintNativeHandler::Print, | 190 base::Bind(&PrintNativeHandler::Print, |
| 115 base::Unretained(this))); | 191 base::Unretained(this))); |
| 116 } | 192 } |
| 117 | 193 |
| 118 v8::Handle<v8::Value> Print(const v8::Arguments& args) { | 194 v8::Handle<v8::Value> Print(const v8::Arguments& args) { |
| 119 if (args.Length() < 1) | 195 if (args.Length() < 1) |
| 120 return v8::Undefined(); | 196 return v8::Undefined(); |
| 121 | 197 |
| 122 std::vector<std::string> components; | 198 std::vector<std::string> components; |
| 123 for (int i = 0; i < args.Length(); ++i) | 199 for (int i = 0; i < args.Length(); ++i) |
| 124 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); | 200 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); |
| 125 | 201 |
| 126 LOG(ERROR) << JoinString(components, ','); | 202 LOG(ERROR) << JoinString(components, ','); |
| 127 return v8::Undefined(); | 203 return v8::Undefined(); |
| 128 } | 204 } |
| 129 }; | 205 }; |
| 130 | 206 |
| 131 class LazyBackgroundPageNativeHandler : public ChromeV8Extension { | 207 class LazyBackgroundPageNativeHandler : public ChromeV8Extension { |
| 132 public: | 208 public: |
| 133 explicit LazyBackgroundPageNativeHandler(Dispatcher* dispatcher) | 209 LazyBackgroundPageNativeHandler(Dispatcher* dispatcher, |
| 134 : ChromeV8Extension(dispatcher) { | 210 v8::Handle<v8::Context> context) |
| 211 : ChromeV8Extension(dispatcher, context) { |
| 135 RouteFunction("IncrementKeepaliveCount", | 212 RouteFunction("IncrementKeepaliveCount", |
| 136 base::Bind(&LazyBackgroundPageNativeHandler::IncrementKeepaliveCount, | 213 base::Bind(&LazyBackgroundPageNativeHandler::IncrementKeepaliveCount, |
| 137 base::Unretained(this))); | 214 base::Unretained(this))); |
| 138 RouteFunction("DecrementKeepaliveCount", | 215 RouteFunction("DecrementKeepaliveCount", |
| 139 base::Bind(&LazyBackgroundPageNativeHandler::DecrementKeepaliveCount, | 216 base::Bind(&LazyBackgroundPageNativeHandler::DecrementKeepaliveCount, |
| 140 base::Unretained(this))); | 217 base::Unretained(this))); |
| 141 } | 218 } |
| 142 | 219 |
| 143 v8::Handle<v8::Value> IncrementKeepaliveCount(const v8::Arguments& args) { | 220 v8::Handle<v8::Value> IncrementKeepaliveCount(const v8::Arguments& args) { |
| 144 ChromeV8Context* context = dispatcher()->v8_context_set().GetCurrent(); | 221 ChromeV8Context* context = |
| 222 dispatcher()->v8_context_set().GetByV8Context(v8_context()); |
| 145 if (!context) | 223 if (!context) |
| 146 return v8::Undefined(); | 224 return v8::Undefined(); |
| 147 RenderView* render_view = context->GetRenderView(); | 225 RenderView* render_view = context->GetRenderView(); |
| 148 if (IsContextLazyBackgroundPage(render_view, context->extension())) { | 226 if (IsContextLazyBackgroundPage(render_view, context->extension())) { |
| 149 render_view->Send(new ExtensionHostMsg_IncrementLazyKeepaliveCount( | 227 render_view->Send(new ExtensionHostMsg_IncrementLazyKeepaliveCount( |
| 150 render_view->GetRoutingID())); | 228 render_view->GetRoutingID())); |
| 151 } | 229 } |
| 152 return v8::Undefined(); | 230 return v8::Undefined(); |
| 153 } | 231 } |
| 154 | 232 |
| 155 v8::Handle<v8::Value> DecrementKeepaliveCount(const v8::Arguments& args) { | 233 v8::Handle<v8::Value> DecrementKeepaliveCount(const v8::Arguments& args) { |
| 156 ChromeV8Context* context = dispatcher()->v8_context_set().GetCurrent(); | 234 ChromeV8Context* context = |
| 235 dispatcher()->v8_context_set().GetByV8Context(v8_context()); |
| 157 if (!context) | 236 if (!context) |
| 158 return v8::Undefined(); | 237 return v8::Undefined(); |
| 159 RenderView* render_view = context->GetRenderView(); | 238 RenderView* render_view = context->GetRenderView(); |
| 160 if (IsContextLazyBackgroundPage(render_view, context->extension())) { | 239 if (IsContextLazyBackgroundPage(render_view, context->extension())) { |
| 161 render_view->Send(new ExtensionHostMsg_DecrementLazyKeepaliveCount( | 240 render_view->Send(new ExtensionHostMsg_DecrementLazyKeepaliveCount( |
| 162 render_view->GetRoutingID())); | 241 render_view->GetRoutingID())); |
| 163 } | 242 } |
| 164 return v8::Undefined(); | 243 return v8::Undefined(); |
| 165 } | 244 } |
| 166 | 245 |
| 167 private: | 246 private: |
| 168 bool IsContextLazyBackgroundPage(RenderView* render_view, | 247 bool IsContextLazyBackgroundPage(RenderView* render_view, |
| 169 const Extension* extension) { | 248 const Extension* extension) { |
| 170 if (!render_view) | 249 if (!render_view) |
| 171 return false; | 250 return false; |
| 172 | 251 |
| 173 ExtensionHelper* helper = ExtensionHelper::Get(render_view); | 252 ExtensionHelper* helper = ExtensionHelper::Get(render_view); |
| 174 return (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && | 253 return (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && |
| 175 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 254 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
| 176 } | 255 } |
| 177 }; | 256 }; |
| 178 | 257 |
| 179 class ProcessInfoNativeHandler : public ChromeV8Extension { | 258 class ProcessInfoNativeHandler : public ChromeV8Extension { |
| 180 public: | 259 public: |
| 181 explicit ProcessInfoNativeHandler( | 260 ProcessInfoNativeHandler(Dispatcher* dispatcher, |
| 182 Dispatcher* dispatcher, | 261 v8::Handle<v8::Context> context, |
| 183 const std::string& extension_id, | 262 const std::string& extension_id, |
| 184 const std::string& context_type, | 263 const std::string& context_type, |
| 185 bool is_incognito_context, | 264 bool is_incognito_context, |
| 186 int manifest_version, | 265 int manifest_version, |
| 187 bool send_request_disabled) | 266 bool send_request_disabled) |
| 188 : ChromeV8Extension(dispatcher), | 267 : ChromeV8Extension(dispatcher, context), |
| 189 extension_id_(extension_id), | 268 extension_id_(extension_id), |
| 190 context_type_(context_type), | 269 context_type_(context_type), |
| 191 is_incognito_context_(is_incognito_context), | 270 is_incognito_context_(is_incognito_context), |
| 192 manifest_version_(manifest_version), | 271 manifest_version_(manifest_version), |
| 193 send_request_disabled_(send_request_disabled) { | 272 send_request_disabled_(send_request_disabled) { |
| 194 RouteFunction("GetExtensionId", | 273 RouteFunction("GetExtensionId", |
| 195 base::Bind(&ProcessInfoNativeHandler::GetExtensionId, | 274 base::Bind(&ProcessInfoNativeHandler::GetExtensionId, |
| 196 base::Unretained(this))); | 275 base::Unretained(this))); |
| 197 RouteFunction("GetContextType", | 276 RouteFunction("GetContextType", |
| 198 base::Bind(&ProcessInfoNativeHandler::GetContextType, | 277 base::Bind(&ProcessInfoNativeHandler::GetContextType, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 313 } |
| 235 | 314 |
| 236 private: | 315 private: |
| 237 std::string extension_id_; | 316 std::string extension_id_; |
| 238 std::string context_type_; | 317 std::string context_type_; |
| 239 bool is_incognito_context_; | 318 bool is_incognito_context_; |
| 240 int manifest_version_; | 319 int manifest_version_; |
| 241 bool send_request_disabled_; | 320 bool send_request_disabled_; |
| 242 }; | 321 }; |
| 243 | 322 |
| 244 class LoggingNativeHandler : public NativeHandler { | 323 class LoggingNativeHandler : public ObjectBackedNativeHandler { |
| 245 public: | 324 public: |
| 246 explicit LoggingNativeHandler(v8::Isolate* isolate) | 325 explicit LoggingNativeHandler(v8::Handle<v8::Context> context) |
| 247 : NativeHandler(isolate) { | 326 : ObjectBackedNativeHandler(context) { |
| 248 RouteFunction("DCHECK", | 327 RouteFunction("DCHECK", |
| 249 base::Bind(&LoggingNativeHandler::Dcheck, | 328 base::Bind(&LoggingNativeHandler::Dcheck, base::Unretained(this))); |
| 250 base::Unretained(this))); | |
| 251 } | 329 } |
| 252 | 330 |
| 253 v8::Handle<v8::Value> Dcheck(const v8::Arguments& args) { | 331 v8::Handle<v8::Value> Dcheck(const v8::Arguments& args) { |
| 254 CHECK_LE(args.Length(), 2); | 332 CHECK_LE(args.Length(), 2); |
| 255 bool check_value = args[0]->BooleanValue(); | 333 bool check_value = args[0]->BooleanValue(); |
| 256 std::string error_message; | 334 std::string error_message; |
| 257 if (args.Length() == 2) | 335 if (args.Length() == 2) |
| 258 error_message = "Error: " + std::string(*v8::String::AsciiValue(args[1])); | 336 error_message = "Error: " + std::string(*v8::String::AsciiValue(args[1])); |
| 259 | 337 |
| 260 v8::Handle<v8::StackTrace> stack_trace = | 338 v8::Handle<v8::StackTrace> stack_trace = |
| 261 v8::StackTrace::CurrentStackTrace(10); | 339 v8::StackTrace::CurrentStackTrace(10); |
| 262 if (stack_trace.IsEmpty() || stack_trace->GetFrameCount() <= 0) { | 340 if (stack_trace.IsEmpty() || stack_trace->GetFrameCount() <= 0) { |
| 263 error_message += "\n <no stack trace>"; | 341 error_message += "\n <no stack trace>"; |
| 264 } else { | 342 } else { |
| 265 for (size_t i = 0; i < (size_t) stack_trace->GetFrameCount(); ++i) { | 343 for (size_t i = 0; i < (size_t) stack_trace->GetFrameCount(); ++i) { |
| 266 v8::Handle<v8::StackFrame> frame = stack_trace->GetFrame(i); | 344 v8::Handle<v8::StackFrame> frame = stack_trace->GetFrame(i); |
| 267 CHECK(!frame.IsEmpty()); | 345 CHECK(!frame.IsEmpty()); |
| 268 error_message += base::StringPrintf("\n at %s (%s:%d:%d)", | 346 error_message += base::StringPrintf("\n at %s (%s:%d:%d)", |
| 269 ToStringOrDefault(frame->GetFunctionName(), "<anonymous>").c_str(), | 347 ToStringOrDefault(frame->GetFunctionName(), "<anonymous>").c_str(), |
| 270 ToStringOrDefault(frame->GetScriptName(), "<anonymous>").c_str(), | 348 ToStringOrDefault(frame->GetScriptName(), "<anonymous>").c_str(), |
| 271 frame->GetLineNumber(), | 349 frame->GetLineNumber(), |
| 272 frame->GetColumn()); | 350 frame->GetColumn()); |
| 273 } | 351 } |
| 274 } | 352 } |
| 275 DCHECK(check_value) << error_message; | 353 DCHECK(check_value) << error_message; |
| 276 LOG(WARNING) << error_message; | |
| 277 return v8::Undefined(); | 354 return v8::Undefined(); |
| 278 } | 355 } |
| 279 | 356 |
| 280 private: | 357 private: |
| 281 std::string ToStringOrDefault(const v8::Handle<v8::String>& v8_string, | 358 std::string ToStringOrDefault(const v8::Handle<v8::String>& v8_string, |
| 282 const std::string& dflt) { | 359 const std::string& dflt) { |
| 283 if (v8_string.IsEmpty()) | 360 if (v8_string.IsEmpty()) |
| 284 return dflt; | 361 return dflt; |
| 285 std::string ascii_value = *v8::String::AsciiValue(v8_string); | 362 std::string ascii_value = *v8::String::AsciiValue(v8_string); |
| 286 return ascii_value.empty() ? dflt : ascii_value; | 363 return ascii_value.empty() ? dflt : ascii_value; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 298 } | 375 } |
| 299 | 376 |
| 300 void InstallWebstoreBindings(ModuleSystem* module_system, | 377 void InstallWebstoreBindings(ModuleSystem* module_system, |
| 301 v8::Handle<v8::Object> chrome, | 378 v8::Handle<v8::Object> chrome, |
| 302 v8::Handle<v8::Object> chrome_hidden) { | 379 v8::Handle<v8::Object> chrome_hidden) { |
| 303 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore"); | 380 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore"); |
| 304 module_system->SetLazyField(chrome_hidden, "webstore", "webstore", | 381 module_system->SetLazyField(chrome_hidden, "webstore", "webstore", |
| 305 "chromeHiddenWebstore"); | 382 "chromeHiddenWebstore"); |
| 306 } | 383 } |
| 307 | 384 |
| 308 static v8::Handle<v8::Object> GetOrCreateChrome( | |
| 309 v8::Handle<v8::Context> context) { | |
| 310 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); | |
| 311 v8::Handle<v8::Object> global(context->Global()); | |
| 312 v8::Handle<v8::Value> chrome(global->Get(chrome_string)); | |
| 313 if (chrome.IsEmpty() || chrome->IsUndefined()) { | |
| 314 v8::Handle<v8::Object> chrome_object(v8::Object::New()); | |
| 315 global->Set(chrome_string, chrome_object); | |
| 316 return chrome_object; | |
| 317 } | |
| 318 CHECK(chrome->IsObject()); | |
| 319 return chrome->ToObject(); | |
| 320 } | |
| 321 | |
| 322 } // namespace | 385 } // namespace |
| 323 | 386 |
| 324 Dispatcher::Dispatcher() | 387 Dispatcher::Dispatcher() |
| 325 : content_watcher_(new ContentWatcher(this)), | 388 : content_watcher_(new ContentWatcher(this)), |
| 326 is_webkit_initialized_(false), | 389 is_webkit_initialized_(false), |
| 327 webrequest_adblock_(false), | 390 webrequest_adblock_(false), |
| 328 webrequest_adblock_plus_(false), | 391 webrequest_adblock_plus_(false), |
| 329 webrequest_other_(false), | 392 webrequest_other_(false), |
| 330 source_map_(&ResourceBundle::GetSharedInstance()) { | 393 source_map_(&ResourceBundle::GetSharedInstance()) { |
| 331 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); | 394 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); |
| 332 is_extension_process_ = | 395 is_extension_process_ = |
| 333 command_line.HasSwitch(switches::kExtensionProcess) || | 396 command_line.HasSwitch(switches::kExtensionProcess) || |
| 334 command_line.HasSwitch(switches::kSingleProcess); | 397 command_line.HasSwitch(switches::kSingleProcess); |
| 335 | 398 |
| 336 if (is_extension_process_) { | 399 if (is_extension_process_) { |
| 337 RenderThread::Get()->SetIdleNotificationDelayInMs( | 400 RenderThread::Get()->SetIdleNotificationDelayInMs( |
| 338 kInitialExtensionIdleHandlerDelayMs); | 401 kInitialExtensionIdleHandlerDelayMs); |
| 339 } | 402 } |
| 340 | 403 |
| 341 user_script_slave_.reset(new UserScriptSlave(&extensions_)); | 404 user_script_slave_.reset(new UserScriptSlave(&extensions_)); |
| 342 request_sender_.reset(new RequestSender(this, &v8_context_set_)); | 405 request_sender_.reset(new RequestSender(this)); |
| 343 PopulateSourceMap(); | 406 PopulateSourceMap(); |
| 344 PopulateLazyBindingsMap(); | 407 PopulateLazyBindingsMap(); |
| 345 } | 408 } |
| 346 | 409 |
| 347 Dispatcher::~Dispatcher() { | 410 Dispatcher::~Dispatcher() { |
| 348 } | 411 } |
| 349 | 412 |
| 350 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { | 413 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { |
| 351 bool handled = true; | 414 bool handled = true; |
| 352 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) | 415 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 } // namespace | 620 } // namespace |
| 558 | 621 |
| 559 bool Dispatcher::AllowScriptExtension(WebFrame* frame, | 622 bool Dispatcher::AllowScriptExtension(WebFrame* frame, |
| 560 const std::string& v8_extension_name, | 623 const std::string& v8_extension_name, |
| 561 int extension_group, | 624 int extension_group, |
| 562 int world_id) { | 625 int world_id) { |
| 563 g_hack_extension_group = extension_group; | 626 g_hack_extension_group = extension_group; |
| 564 return true; | 627 return true; |
| 565 } | 628 } |
| 566 | 629 |
| 630 v8::Handle<v8::Object> Dispatcher::GetOrCreateObject( |
| 631 v8::Handle<v8::Object> object, |
| 632 const std::string& field) { |
| 633 v8::HandleScope handle_scope; |
| 634 v8::Handle<v8::String> key = v8::String::New(field.c_str()); |
| 635 // This little dance is for APIs that may be unavailable but have available |
| 636 // children. For example, chrome.app can be unavailable, while |
| 637 // chrome.app.runtime is available. The lazy getter for chrome.app must be |
| 638 // deleted, so that there isn't an error when accessing chrome.app.runtime. |
| 639 if (object->Has(key)) { |
| 640 v8::Handle<v8::Value> value = object->Get(key); |
| 641 if (value->IsObject()) |
| 642 return handle_scope.Close(v8::Handle<v8::Object>::Cast(value)); |
| 643 else |
| 644 object->Delete(key); |
| 645 } |
| 646 |
| 647 v8::Handle<v8::Object> new_object = v8::Object::New(); |
| 648 object->Set(key, new_object); |
| 649 return handle_scope.Close(new_object); |
| 650 } |
| 651 |
| 652 void Dispatcher::RegisterSchemaGeneratedBindings( |
| 653 ModuleSystem* module_system, |
| 654 ChromeV8Context* context, |
| 655 v8::Handle<v8::Context> v8_context) { |
| 656 std::set<std::string> apis = |
| 657 ExtensionAPI::GetSharedInstance()->GetAllAPINames(); |
| 658 for (std::set<std::string>::iterator it = apis.begin(); |
| 659 it != apis.end(); ++it) { |
| 660 const std::string& api_name = *it; |
| 661 |
| 662 std::vector<std::string> split; |
| 663 base::SplitString(api_name, '.', &split); |
| 664 |
| 665 v8::Handle<v8::Object> bind_object = GetOrCreateChrome(v8_context); |
| 666 for (size_t i = 0; i < split.size() - 1; ++i) |
| 667 bind_object = GetOrCreateObject(bind_object, split[i]); |
| 668 |
| 669 if (lazy_bindings_map_.find(api_name) != lazy_bindings_map_.end()) { |
| 670 InstallBindings(module_system, v8_context, api_name); |
| 671 } else if (!source_map_.Contains(api_name)) { |
| 672 module_system->RegisterNativeHandler( |
| 673 api_name, |
| 674 scoped_ptr<NativeHandler>(new BindingGeneratingNativeHandler( |
| 675 module_system, |
| 676 api_name, |
| 677 "binding"))); |
| 678 module_system->SetNativeLazyField(bind_object, |
| 679 split.back(), |
| 680 api_name, |
| 681 "binding"); |
| 682 } else { |
| 683 module_system->SetLazyField(bind_object, |
| 684 split.back(), |
| 685 api_name, |
| 686 "binding"); |
| 687 } |
| 688 } |
| 689 } |
| 690 |
| 567 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 691 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
| 568 ChromeV8Context* context) { | 692 ChromeV8Context* context) { |
| 693 v8::Handle<v8::Context> v8_context = context->v8_context(); |
| 694 |
| 569 module_system->RegisterNativeHandler("event_bindings", | 695 module_system->RegisterNativeHandler("event_bindings", |
| 570 scoped_ptr<NativeHandler>(EventBindings::Get(this))); | 696 scoped_ptr<NativeHandler>(EventBindings::Create(this, v8_context))); |
| 571 module_system->RegisterNativeHandler("miscellaneous_bindings", | 697 module_system->RegisterNativeHandler("miscellaneous_bindings", |
| 572 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); | 698 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this, v8_context))); |
| 573 module_system->RegisterNativeHandler("apiDefinitions", | 699 module_system->RegisterNativeHandler("apiDefinitions", |
| 574 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); | 700 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this, context))); |
| 575 module_system->RegisterNativeHandler("sendRequest", | 701 module_system->RegisterNativeHandler("sendRequest", |
| 576 scoped_ptr<NativeHandler>( | 702 scoped_ptr<NativeHandler>( |
| 577 new SendRequestNatives(this, request_sender_.get()))); | 703 new SendRequestNatives(this, request_sender_.get(), context))); |
| 578 module_system->RegisterNativeHandler("setIcon", | 704 module_system->RegisterNativeHandler("setIcon", |
| 579 scoped_ptr<NativeHandler>( | 705 scoped_ptr<NativeHandler>( |
| 580 new SetIconNatives(this, request_sender_.get()))); | 706 new SetIconNatives(this, request_sender_.get(), context))); |
| 581 module_system->RegisterNativeHandler("contentWatcherNative", | 707 module_system->RegisterNativeHandler( |
| 582 content_watcher_->MakeNatives()); | 708 "contentWatcherNative", |
| 709 content_watcher_->MakeNatives(v8_context)); |
| 583 | 710 |
| 584 // Natives used by multiple APIs. | 711 // Natives used by multiple APIs. |
| 585 module_system->RegisterNativeHandler("file_system_natives", | 712 module_system->RegisterNativeHandler("file_system_natives", |
| 586 scoped_ptr<NativeHandler>(new FileSystemNatives())); | 713 scoped_ptr<NativeHandler>(new FileSystemNatives(v8_context))); |
| 587 | 714 |
| 588 // Custom bindings. | 715 // Custom bindings. |
| 589 module_system->RegisterNativeHandler("app", | 716 module_system->RegisterNativeHandler("app", |
| 590 scoped_ptr<NativeHandler>(new AppBindings(this, context))); | 717 scoped_ptr<NativeHandler>(new AppBindings(this, context))); |
| 591 module_system->RegisterNativeHandler("app_runtime", | 718 module_system->RegisterNativeHandler("app_runtime", |
| 592 scoped_ptr<NativeHandler>(new AppRuntimeCustomBindings())); | 719 scoped_ptr<NativeHandler>( |
| 720 new AppRuntimeCustomBindings(this, v8_context))); |
| 593 module_system->RegisterNativeHandler("app_window", | 721 module_system->RegisterNativeHandler("app_window", |
| 594 scoped_ptr<NativeHandler>(new AppWindowCustomBindings(this))); | 722 scoped_ptr<NativeHandler>( |
| 723 new AppWindowCustomBindings(this, v8_context))); |
| 595 module_system->RegisterNativeHandler("context_menus", | 724 module_system->RegisterNativeHandler("context_menus", |
| 596 scoped_ptr<NativeHandler>(new ContextMenusCustomBindings())); | 725 scoped_ptr<NativeHandler>( |
| 726 new ContextMenusCustomBindings(this, v8_context))); |
| 597 module_system->RegisterNativeHandler("extension", | 727 module_system->RegisterNativeHandler("extension", |
| 598 scoped_ptr<NativeHandler>( | 728 scoped_ptr<NativeHandler>( |
| 599 new ExtensionCustomBindings(this))); | 729 new ExtensionCustomBindings(this, v8_context))); |
| 600 module_system->RegisterNativeHandler("sync_file_system", | 730 module_system->RegisterNativeHandler("sync_file_system", |
| 601 scoped_ptr<NativeHandler>(new SyncFileSystemCustomBindings())); | 731 scoped_ptr<NativeHandler>( |
| 732 new SyncFileSystemCustomBindings(this, v8_context))); |
| 602 module_system->RegisterNativeHandler("file_browser_handler", | 733 module_system->RegisterNativeHandler("file_browser_handler", |
| 603 scoped_ptr<NativeHandler>(new FileBrowserHandlerCustomBindings())); | 734 scoped_ptr<NativeHandler>(new FileBrowserHandlerCustomBindings( |
| 735 this, v8_context))); |
| 604 module_system->RegisterNativeHandler("file_browser_private", | 736 module_system->RegisterNativeHandler("file_browser_private", |
| 605 scoped_ptr<NativeHandler>(new FileBrowserPrivateCustomBindings())); | 737 scoped_ptr<NativeHandler>(new FileBrowserPrivateCustomBindings( |
| 738 this, v8_context))); |
| 606 module_system->RegisterNativeHandler("i18n", | 739 module_system->RegisterNativeHandler("i18n", |
| 607 scoped_ptr<NativeHandler>(new I18NCustomBindings())); | 740 scoped_ptr<NativeHandler>( |
| 741 new I18NCustomBindings(this, v8_context))); |
| 608 module_system->RegisterNativeHandler("mediaGalleries", | 742 module_system->RegisterNativeHandler("mediaGalleries", |
| 609 scoped_ptr<NativeHandler>(new MediaGalleriesCustomBindings())); | 743 scoped_ptr<NativeHandler>( |
| 744 new MediaGalleriesCustomBindings(this, v8_context))); |
| 610 module_system->RegisterNativeHandler("page_actions", | 745 module_system->RegisterNativeHandler("page_actions", |
| 611 scoped_ptr<NativeHandler>( | 746 scoped_ptr<NativeHandler>( |
| 612 new PageActionsCustomBindings(this))); | 747 new PageActionsCustomBindings(this, v8_context))); |
| 613 module_system->RegisterNativeHandler("page_capture", | 748 module_system->RegisterNativeHandler("page_capture", |
| 614 scoped_ptr<NativeHandler>(new PageCaptureCustomBindings())); | 749 scoped_ptr<NativeHandler>( |
| 750 new PageCaptureCustomBindings(this, v8_context))); |
| 615 module_system->RegisterNativeHandler("runtime", | 751 module_system->RegisterNativeHandler("runtime", |
| 616 scoped_ptr<NativeHandler>(new RuntimeCustomBindings(this, context))); | 752 scoped_ptr<NativeHandler>(new RuntimeCustomBindings(this, context))); |
| 617 module_system->RegisterNativeHandler("tabs", | 753 module_system->RegisterNativeHandler("tabs", |
| 618 scoped_ptr<NativeHandler>(new TabsCustomBindings())); | 754 scoped_ptr<NativeHandler>(new TabsCustomBindings(this, v8_context))); |
| 619 module_system->RegisterNativeHandler("tts", | 755 module_system->RegisterNativeHandler("tts", |
| 620 scoped_ptr<NativeHandler>(new TTSCustomBindings())); | 756 scoped_ptr<NativeHandler>(new TTSCustomBindings(this, v8_context))); |
| 621 module_system->RegisterNativeHandler("web_request", | 757 module_system->RegisterNativeHandler("web_request", |
| 622 scoped_ptr<NativeHandler>(new WebRequestCustomBindings())); | 758 scoped_ptr<NativeHandler>( |
| 759 new WebRequestCustomBindings(this, v8_context))); |
| 623 module_system->RegisterNativeHandler("webstore", | 760 module_system->RegisterNativeHandler("webstore", |
| 624 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); | 761 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); |
| 625 } | 762 } |
| 626 | 763 |
| 627 void Dispatcher::PopulateSourceMap() { | 764 void Dispatcher::PopulateSourceMap() { |
| 628 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); | 765 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); |
| 629 source_map_.RegisterSource("miscellaneous_bindings", | 766 source_map_.RegisterSource("miscellaneous_bindings", |
| 630 IDR_MISCELLANEOUS_BINDINGS_JS); | 767 IDR_MISCELLANEOUS_BINDINGS_JS); |
| 631 source_map_.RegisterSource("schema_generated_bindings", | |
| 632 IDR_SCHEMA_GENERATED_BINDINGS_JS); | |
| 633 source_map_.RegisterSource("json", IDR_JSON_JS); | 768 source_map_.RegisterSource("json", IDR_JSON_JS); |
| 634 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); | 769 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); |
| 635 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS); | 770 source_map_.RegisterSource("test", IDR_TEST_CUSTOM_BINDINGS_JS); |
| 636 | 771 |
| 637 // Libraries. | 772 // Libraries. |
| 638 source_map_.RegisterSource("contentWatcher", IDR_CONTENT_WATCHER_JS); | 773 source_map_.RegisterSource("contentWatcher", IDR_CONTENT_WATCHER_JS); |
| 639 source_map_.RegisterSource("imageUtil", IDR_IMAGE_UTIL_JS); | 774 source_map_.RegisterSource("imageUtil", IDR_IMAGE_UTIL_JS); |
| 640 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); | 775 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); |
| 641 source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS); | 776 source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS); |
| 642 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS); | 777 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS); |
| 643 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS); | 778 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS); |
| 644 source_map_.RegisterSource("utils", IDR_UTILS_JS); | 779 source_map_.RegisterSource("utils", IDR_UTILS_JS); |
| 645 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); | 780 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS); | 829 IDR_SYSTEM_INDICATOR_CUSTOM_BINDINGS_JS); |
| 695 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS); | 830 source_map_.RegisterSource("tabCapture", IDR_TAB_CAPTURE_CUSTOM_BINDINGS_JS); |
| 696 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); | 831 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); |
| 697 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); | 832 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); |
| 698 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); | 833 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); |
| 699 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); | 834 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); |
| 700 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); | 835 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); |
| 701 source_map_.RegisterSource("webRequestInternal", | 836 source_map_.RegisterSource("webRequestInternal", |
| 702 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); | 837 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); |
| 703 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); | 838 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); |
| 839 source_map_.RegisterSource("binding", IDR_BINDING_JS); |
| 704 | 840 |
| 705 // Platform app sources that are not API-specific.. | 841 // Platform app sources that are not API-specific.. |
| 706 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS); | 842 source_map_.RegisterSource("tagWatcher", IDR_TAG_WATCHER_JS); |
| 707 source_map_.RegisterSource("webview", IDR_WEB_VIEW_JS); | 843 // Note: webView not webview so that this doesn't interfere with the |
| 708 source_map_.RegisterSource("webview.experimental", | 844 // chrome.webview API bindings. |
| 845 source_map_.RegisterSource("webView", IDR_WEB_VIEW_JS); |
| 846 source_map_.RegisterSource("webViewExperimental", |
| 709 IDR_WEB_VIEW_EXPERIMENTAL_JS); | 847 IDR_WEB_VIEW_EXPERIMENTAL_JS); |
| 710 source_map_.RegisterSource("denyWebview", IDR_WEB_VIEW_DENY_JS); | 848 source_map_.RegisterSource("denyWebView", IDR_WEB_VIEW_DENY_JS); |
| 711 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); | 849 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); |
| 712 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS); | 850 source_map_.RegisterSource("injectAppTitlebar", IDR_INJECT_APP_TITLEBAR_JS); |
| 713 } | 851 } |
| 714 | 852 |
| 715 void Dispatcher::PopulateLazyBindingsMap() { | 853 void Dispatcher::PopulateLazyBindingsMap() { |
| 716 lazy_bindings_map_["app"] = InstallAppBindings; | 854 lazy_bindings_map_["app"] = InstallAppBindings; |
| 717 lazy_bindings_map_["webstore"] = InstallWebstoreBindings; | 855 lazy_bindings_map_["webstore"] = InstallWebstoreBindings; |
| 718 } | 856 } |
| 719 | 857 |
| 720 void Dispatcher::InstallBindings(ModuleSystem* module_system, | 858 void Dispatcher::InstallBindings(ModuleSystem* module_system, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 new ChromeV8Context(v8_context, frame, extension, context_type); | 910 new ChromeV8Context(v8_context, frame, extension, context_type); |
| 773 v8_context_set_.Add(context); | 911 v8_context_set_.Add(context); |
| 774 | 912 |
| 775 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, | 913 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(v8_context, |
| 776 &source_map_)); | 914 &source_map_)); |
| 777 // Enable natives in startup. | 915 // Enable natives in startup. |
| 778 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); | 916 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system.get()); |
| 779 | 917 |
| 780 RegisterNativeHandlers(module_system.get(), context); | 918 RegisterNativeHandlers(module_system.get(), context); |
| 781 | 919 |
| 782 v8::Isolate* isolate = v8_context->GetIsolate(); | 920 module_system->RegisterNativeHandler("chrome", |
| 921 scoped_ptr<NativeHandler>(new ChromeNativeHandler(v8_context))); |
| 783 module_system->RegisterNativeHandler("chrome_hidden", | 922 module_system->RegisterNativeHandler("chrome_hidden", |
| 784 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler(isolate))); | 923 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler(v8_context))); |
| 785 module_system->RegisterNativeHandler("print", | 924 module_system->RegisterNativeHandler("print", |
| 786 scoped_ptr<NativeHandler>(new PrintNativeHandler(isolate))); | 925 scoped_ptr<NativeHandler>(new PrintNativeHandler(v8_context))); |
| 787 module_system->RegisterNativeHandler("lazy_background_page", | 926 module_system->RegisterNativeHandler("lazy_background_page", |
| 788 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); | 927 scoped_ptr<NativeHandler>( |
| 928 new LazyBackgroundPageNativeHandler(this, v8_context))); |
| 789 module_system->RegisterNativeHandler("logging", | 929 module_system->RegisterNativeHandler("logging", |
| 790 scoped_ptr<NativeHandler>(new LoggingNativeHandler(isolate))); | 930 scoped_ptr<NativeHandler>(new LoggingNativeHandler(v8_context))); |
| 931 module_system->RegisterNativeHandler("schema_registry", |
| 932 scoped_ptr<NativeHandler>( |
| 933 new SchemaRegistryNativeHandler(v8_schema_registry(), v8_context))); |
| 934 module_system->RegisterNativeHandler("v8_context", |
| 935 scoped_ptr<NativeHandler>(new V8ContextNativeHandler(context))); |
| 791 | 936 |
| 792 int manifest_version = extension ? extension->manifest_version() : 1; | 937 int manifest_version = extension ? extension->manifest_version() : 1; |
| 793 bool send_request_disabled = | 938 bool send_request_disabled = |
| 794 (extension && Manifest::IsUnpackedLocation(extension->location()) && | 939 (extension && Manifest::IsUnpackedLocation(extension->location()) && |
| 795 BackgroundInfo::HasLazyBackgroundPage(extension)); | 940 BackgroundInfo::HasLazyBackgroundPage(extension)); |
| 796 module_system->RegisterNativeHandler("process", | 941 module_system->RegisterNativeHandler("process", |
| 797 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 942 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
| 798 this, context->GetExtensionID(), | 943 this, v8_context, context->GetExtensionID(), |
| 799 context->GetContextTypeDescription(), | 944 context->GetContextTypeDescription(), |
| 800 ChromeRenderProcessObserver::is_incognito_process(), | 945 ChromeRenderProcessObserver::is_incognito_process(), |
| 801 manifest_version, send_request_disabled))); | 946 manifest_version, send_request_disabled))); |
| 802 | 947 |
| 803 GetOrCreateChrome(v8_context); | 948 GetOrCreateChrome(v8_context); |
| 804 | 949 |
| 805 // Loading JavaScript is expensive, so only run the full API bindings | 950 // Loading JavaScript is expensive, so only run the full API bindings |
| 806 // generation mechanisms in extension pages (NOT all web pages). | 951 // generation mechanisms in extension pages (NOT all web pages). |
| 807 switch (context_type) { | 952 switch (context_type) { |
| 808 case Feature::UNSPECIFIED_CONTEXT: | 953 case Feature::UNSPECIFIED_CONTEXT: |
| 809 case Feature::WEB_PAGE_CONTEXT: | 954 case Feature::WEB_PAGE_CONTEXT: |
| 810 // TODO(kalman): see comment below about ExtensionAPI. | 955 // TODO(kalman): see comment below about ExtensionAPI. |
| 811 InstallBindings(module_system.get(), v8_context, "app"); | 956 InstallBindings(module_system.get(), v8_context, "app"); |
| 812 InstallBindings(module_system.get(), v8_context, "webstore"); | 957 InstallBindings(module_system.get(), v8_context, "webstore"); |
| 813 break; | 958 break; |
| 814 | |
| 815 case Feature::BLESSED_EXTENSION_CONTEXT: | 959 case Feature::BLESSED_EXTENSION_CONTEXT: |
| 816 case Feature::UNBLESSED_EXTENSION_CONTEXT: | 960 case Feature::UNBLESSED_EXTENSION_CONTEXT: |
| 817 case Feature::CONTENT_SCRIPT_CONTEXT: { | 961 case Feature::CONTENT_SCRIPT_CONTEXT: { |
| 962 if (extension && !extension->is_platform_app()) |
| 963 module_system->Require("miscellaneous_bindings"); |
| 818 module_system->Require("json"); // see paranoid comment in json.js | 964 module_system->Require("json"); // see paranoid comment in json.js |
| 819 module_system->Require("miscellaneous_bindings"); | |
| 820 module_system->Require("schema_generated_bindings"); | |
| 821 module_system->Require("apitest"); | |
| 822 | 965 |
| 823 // TODO(kalman): move this code back out of the switch and execute it | 966 // TODO(kalman): move this code back out of the switch and execute it |
| 824 // regardless of |context_type|. ExtensionAPI knows how to return the | 967 // regardless of |context_type|. ExtensionAPI knows how to return the |
| 825 // correct APIs, however, until it doesn't have a 2MB overhead we can't | 968 // correct APIs, however, until it doesn't have a 2MB overhead we can't |
| 826 // load it in every process. | 969 // load it in every process. |
| 827 const std::set<std::string>& apis = context->GetAvailableExtensionAPIs(); | 970 RegisterSchemaGeneratedBindings(module_system.get(), |
| 828 for (std::set<std::string>::const_iterator i = apis.begin(); | 971 context, |
| 829 i != apis.end(); ++i) { | 972 v8_context); |
| 830 InstallBindings(module_system.get(), v8_context, *i); | |
| 831 } | |
| 832 | |
| 833 break; | 973 break; |
| 834 } | 974 } |
| 835 } | 975 } |
| 836 | 976 |
| 837 // Inject custom JS into the platform app context. | 977 // Inject custom JS into the platform app context. |
| 838 if (IsWithinPlatformApp(frame)) | 978 if (IsWithinPlatformApp(frame)) |
| 839 module_system->Require("platformApp"); | 979 module_system->Require("platformApp"); |
| 840 | 980 |
| 841 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 981 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
| 842 bool has_permission = extension->HasAPIPermission(APIPermission::kWebView); | 982 // Note: setting up the WebView class here, not the chrome.webview API. |
| 843 module_system->Require(has_permission ? "webview" : "denyWebview"); | 983 // The API will be automatically set up when first used. |
| 844 if (has_permission && | 984 if (extension->HasAPIPermission(APIPermission::kWebView)) { |
| 845 Feature::GetCurrentChannel() <= chrome::VersionInfo::CHANNEL_DEV) { | 985 module_system->Require("webView"); |
| 846 module_system->Require("webview.experimental"); | 986 if (Feature::GetCurrentChannel() <= chrome::VersionInfo::CHANNEL_DEV) |
| 987 module_system->Require("webViewExperimental"); |
| 988 } else { |
| 989 module_system->Require("denyWebView"); |
| 847 } | 990 } |
| 848 } | 991 } |
| 849 | 992 |
| 850 context->set_module_system(module_system.Pass()); | 993 context->set_module_system(module_system.Pass()); |
| 851 | 994 |
| 852 context->DispatchOnLoadEvent( | 995 context->DispatchOnLoadEvent( |
| 853 ChromeRenderProcessObserver::is_incognito_process(), | 996 ChromeRenderProcessObserver::is_incognito_process(), |
| 854 manifest_version); | 997 manifest_version); |
| 855 | 998 |
| 856 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); | 999 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 878 return extension && extension->is_platform_app(); | 1021 return extension && extension->is_platform_app(); |
| 879 } | 1022 } |
| 880 | 1023 |
| 881 void Dispatcher::WillReleaseScriptContext( | 1024 void Dispatcher::WillReleaseScriptContext( |
| 882 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { | 1025 WebFrame* frame, v8::Handle<v8::Context> v8_context, int world_id) { |
| 883 ChromeV8Context* context = v8_context_set_.GetByV8Context(v8_context); | 1026 ChromeV8Context* context = v8_context_set_.GetByV8Context(v8_context); |
| 884 if (!context) | 1027 if (!context) |
| 885 return; | 1028 return; |
| 886 | 1029 |
| 887 context->DispatchOnUnloadEvent(); | 1030 context->DispatchOnUnloadEvent(); |
| 1031 // TODO(kalman): add an invalidation observer interface to ChromeV8Context. |
| 1032 request_sender_->InvalidateContext(context); |
| 888 | 1033 |
| 889 v8_context_set_.Remove(context); | 1034 v8_context_set_.Remove(context); |
| 890 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); | 1035 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); |
| 891 } | 1036 } |
| 892 | 1037 |
| 893 void Dispatcher::DidCreateDocumentElement(WebKit::WebFrame* frame) { | 1038 void Dispatcher::DidCreateDocumentElement(WebKit::WebFrame* frame) { |
| 894 if (IsWithinPlatformApp(frame)) { | 1039 if (IsWithinPlatformApp(frame)) { |
| 895 // WebKit doesn't let us define an additional user agent stylesheet, so we | 1040 // WebKit doesn't let us define an additional user agent stylesheet, so we |
| 896 // insert the default platform app stylesheet into all documents that are | 1041 // insert the default platform app stylesheet into all documents that are |
| 897 // loaded in each app. | 1042 // loaded in each app. |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 return Feature::UNSPECIFIED_CONTEXT; | 1267 return Feature::UNSPECIFIED_CONTEXT; |
| 1123 } | 1268 } |
| 1124 | 1269 |
| 1125 void Dispatcher::OnExtensionResponse(int request_id, | 1270 void Dispatcher::OnExtensionResponse(int request_id, |
| 1126 bool success, | 1271 bool success, |
| 1127 const base::ListValue& response, | 1272 const base::ListValue& response, |
| 1128 const std::string& error) { | 1273 const std::string& error) { |
| 1129 request_sender_->HandleResponse(request_id, success, response, error); | 1274 request_sender_->HandleResponse(request_id, success, response, error); |
| 1130 } | 1275 } |
| 1131 | 1276 |
| 1132 bool Dispatcher::CheckCurrentContextAccessToExtensionAPI( | 1277 bool Dispatcher::CheckContextAccessToExtensionAPI( |
| 1133 const std::string& function_name) const { | 1278 const std::string& function_name, ChromeV8Context* context) const { |
| 1134 ChromeV8Context* context = v8_context_set().GetCurrent(); | |
| 1135 if (!context) { | 1279 if (!context) { |
| 1136 DLOG(ERROR) << "Not in a v8::Context"; | 1280 DLOG(ERROR) << "Not in a v8::Context"; |
| 1137 return false; | 1281 return false; |
| 1138 } | 1282 } |
| 1139 | 1283 |
| 1140 if (!context->extension()) { | 1284 if (!context->extension()) { |
| 1141 v8::ThrowException( | 1285 v8::ThrowException( |
| 1142 v8::Exception::Error(v8::String::New("Not in an extension."))); | 1286 v8::Exception::Error(v8::String::New("Not in an extension."))); |
| 1143 return false; | 1287 return false; |
| 1144 } | 1288 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1174 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1318 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
| 1175 v8::ThrowException( | 1319 v8::ThrowException( |
| 1176 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1320 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
| 1177 return false; | 1321 return false; |
| 1178 } | 1322 } |
| 1179 | 1323 |
| 1180 return true; | 1324 return true; |
| 1181 } | 1325 } |
| 1182 | 1326 |
| 1183 } // namespace extensions | 1327 } // namespace extensions |
| OLD | NEW |