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