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/extension_dispatcher.h" | 5 #include "chrome/renderer/extensions/extension_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" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 base::Unretained(this))); | 204 base::Unretained(this))); |
205 } | 205 } |
206 | 206 |
207 v8::Handle<v8::Value> IsDevChannel(const v8::Arguments& args) { | 207 v8::Handle<v8::Value> IsDevChannel(const v8::Arguments& args) { |
208 return v8::Boolean::New(channel_ <= chrome::VersionInfo::CHANNEL_DEV); | 208 return v8::Boolean::New(channel_ <= chrome::VersionInfo::CHANNEL_DEV); |
209 } | 209 } |
210 | 210 |
211 chrome::VersionInfo::Channel channel_; | 211 chrome::VersionInfo::Channel channel_; |
212 }; | 212 }; |
213 | 213 |
214 class LoggingNativeHandler : public NativeHandler { | |
215 public: | |
216 LoggingNativeHandler() { | |
217 RouteFunction("DCHECK", | |
218 base::Bind(&LoggingNativeHandler::Dcheck, | |
219 base::Unretained(this))); | |
220 } | |
221 | |
222 v8::Handle<v8::Value> Dcheck(const v8::Arguments& args) { | |
223 CHECK_LE(args.Length(), 2); | |
224 bool check_value = args[0]->BooleanValue(); | |
225 std::string error_message; | |
226 if (args.Length() == 2) | |
227 error_message += "Error: " + std::string(*v8::String::AsciiValue(args[1])) | |
228 + "\n"; | |
229 | |
230 v8::Handle<v8::Array> stack_trace( | |
231 v8::StackTrace::CurrentStackTrace(10)->AsArray()); | |
232 error_message += "Stack trace: {\n"; | |
233 for (size_t i = 0; i < stack_trace->Length(); i++) { | |
234 error_message += " " | |
235 + std::string(*v8::String::AsciiValue(stack_trace->Get(i))) + "\n"; | |
236 } | |
237 error_message += "}"; | |
238 DCHECK(check_value) << error_message; | |
239 return v8::Undefined(); | |
240 } | |
241 }; | |
242 | |
243 void InstallAppBindings(ModuleSystem* module_system, | 214 void InstallAppBindings(ModuleSystem* module_system, |
244 v8::Handle<v8::Object> chrome, | 215 v8::Handle<v8::Object> chrome, |
245 v8::Handle<v8::Object> chrome_hidden) { | 216 v8::Handle<v8::Object> chrome_hidden) { |
246 module_system->SetLazyField(chrome, "app", "app", "chromeApp"); | 217 module_system->SetLazyField(chrome, "app", "app", "chromeApp"); |
247 module_system->SetLazyField(chrome, "appNotifications", "app", | 218 module_system->SetLazyField(chrome, "appNotifications", "app", |
248 "chromeAppNotifications"); | 219 "chromeAppNotifications"); |
249 module_system->SetLazyField(chrome_hidden, "app", "app", | 220 module_system->SetLazyField(chrome_hidden, "app", "app", |
250 "chromeHiddenApp"); | 221 "chromeHiddenApp"); |
251 } | 222 } |
252 | 223 |
253 void InstallWebstoreBindings(ModuleSystem* module_system, | 224 void InstallWebstoreBindings(ModuleSystem* module_system, |
254 v8::Handle<v8::Object> chrome, | 225 v8::Handle<v8::Object> chrome, |
255 v8::Handle<v8::Object> chrome_hidden) { | 226 v8::Handle<v8::Object> chrome_hidden) { |
256 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore"); | 227 module_system->SetLazyField(chrome, "webstore", "webstore", "chromeWebstore"); |
257 module_system->SetLazyField(chrome_hidden, "webstore", "webstore", | 228 module_system->SetLazyField(chrome_hidden, "webstore", "webstore", |
258 "chromeHiddenWebstore"); | 229 "chromeHiddenWebstore"); |
259 } | 230 } |
260 | 231 |
261 } // namespace | 232 } |
262 | 233 |
263 ExtensionDispatcher::ExtensionDispatcher() | 234 ExtensionDispatcher::ExtensionDispatcher() |
264 : is_webkit_initialized_(false), | 235 : is_webkit_initialized_(false), |
265 webrequest_adblock_(false), | 236 webrequest_adblock_(false), |
266 webrequest_adblock_plus_(false), | 237 webrequest_adblock_plus_(false), |
267 webrequest_other_(false), | 238 webrequest_other_(false), |
268 source_map_(&ResourceBundle::GetSharedInstance()), | 239 source_map_(&ResourceBundle::GetSharedInstance()), |
269 chrome_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN), | 240 chrome_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN), |
270 event_filter_(new extensions::EventFilter) { | 241 event_filter_(new extensions::EventFilter) { |
271 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); | 242 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 | 683 |
713 module_system->RegisterNativeHandler("chrome_hidden", | 684 module_system->RegisterNativeHandler("chrome_hidden", |
714 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); | 685 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); |
715 module_system->RegisterNativeHandler("print", | 686 module_system->RegisterNativeHandler("print", |
716 scoped_ptr<NativeHandler>(new PrintNativeHandler())); | 687 scoped_ptr<NativeHandler>(new PrintNativeHandler())); |
717 module_system->RegisterNativeHandler("lazy_background_page", | 688 module_system->RegisterNativeHandler("lazy_background_page", |
718 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); | 689 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); |
719 module_system->RegisterNativeHandler("channel", | 690 module_system->RegisterNativeHandler("channel", |
720 scoped_ptr<NativeHandler>(new ChannelNativeHandler( | 691 scoped_ptr<NativeHandler>(new ChannelNativeHandler( |
721 static_cast<chrome::VersionInfo::Channel>(chrome_channel_)))); | 692 static_cast<chrome::VersionInfo::Channel>(chrome_channel_)))); |
722 module_system->RegisterNativeHandler("logging", | |
723 scoped_ptr<NativeHandler>(new LoggingNativeHandler())); | |
724 // Create the 'chrome' variable if it doesn't already exist. | 693 // Create the 'chrome' variable if it doesn't already exist. |
725 { | 694 { |
726 v8::HandleScope handle_scope; | 695 v8::HandleScope handle_scope; |
727 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); | 696 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); |
728 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global()); | 697 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global()); |
729 v8::Handle<v8::Value> chrome(global->Get(chrome_string)); | 698 v8::Handle<v8::Value> chrome(global->Get(chrome_string)); |
730 if (chrome.IsEmpty() || chrome->IsUndefined()) | 699 if (chrome.IsEmpty() || chrome->IsUndefined()) |
731 global->Set(chrome_string, v8::Object::New()); | 700 global->Set(chrome_string, v8::Object::New()); |
732 } | 701 } |
733 | 702 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 // APIs, they don't get extension bindings injected. If we end up here it | 1032 // APIs, they don't get extension bindings injected. If we end up here it |
1064 // means that a sandboxed page somehow managed to invoke an API anyway, so | 1033 // means that a sandboxed page somehow managed to invoke an API anyway, so |
1065 // we should abort. | 1034 // we should abort. |
1066 WebKit::WebFrame* frame = context->web_frame(); | 1035 WebKit::WebFrame* frame = context->web_frame(); |
1067 ExtensionURLInfo url_info(frame->document().securityOrigin(), | 1036 ExtensionURLInfo url_info(frame->document().securityOrigin(), |
1068 UserScriptSlave::GetDataSourceURLForFrame(frame)); | 1037 UserScriptSlave::GetDataSourceURLForFrame(frame)); |
1069 CHECK(!extensions_.IsSandboxedPage(url_info)); | 1038 CHECK(!extensions_.IsSandboxedPage(url_info)); |
1070 | 1039 |
1071 return true; | 1040 return true; |
1072 } | 1041 } |
OLD | NEW |