Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(585)

Side by Side Diff: net/proxy/proxy_resolver_v8.cc

Issue 15796006: Make ProxyResolver not use to-be-deprecated V8 functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/proxy/proxy_resolver_v8.h" 5 #include "net/proxy/proxy_resolver_v8.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstdio> 8 #include <cstdio>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 v8_this_.Dispose(isolate_); 344 v8_this_.Dispose(isolate_);
345 v8_context_.Dispose(isolate_); 345 v8_context_.Dispose(isolate_);
346 } 346 }
347 347
348 JSBindings* js_bindings() { 348 JSBindings* js_bindings() {
349 return parent_->js_bindings_; 349 return parent_->js_bindings_;
350 } 350 }
351 351
352 int ResolveProxy(const GURL& query_url, ProxyInfo* results) { 352 int ResolveProxy(const GURL& query_url, ProxyInfo* results) {
353 v8::Locker locked(isolate_); 353 v8::Locker locked(isolate_);
354 v8::HandleScope scope; 354 v8::HandleScope scope(isolate_);
355 355
356 v8::Context::Scope function_scope(v8_context_); 356 v8::Local<v8::Context> context =
357 v8::Local<v8::Context>::New(isolate_, v8_context_);
358 v8::Context::Scope function_scope(context);
357 359
358 v8::Local<v8::Value> function; 360 v8::Local<v8::Value> function;
359 if (!GetFindProxyForURL(&function)) { 361 if (!GetFindProxyForURL(&function)) {
360 js_bindings()->OnError( 362 js_bindings()->OnError(
361 -1, ASCIIToUTF16("FindProxyForURL() is undefined.")); 363 -1, ASCIIToUTF16("FindProxyForURL() is undefined."));
362 return ERR_PAC_SCRIPT_FAILED; 364 return ERR_PAC_SCRIPT_FAILED;
363 } 365 }
364 366
365 v8::Handle<v8::Value> argv[] = { 367 v8::Handle<v8::Value> argv[] = {
366 ASCIIStringToV8String(query_url.spec()), 368 ASCIIStringToV8String(query_url.spec()),
367 ASCIIStringToV8String(query_url.HostNoBrackets()), 369 ASCIIStringToV8String(query_url.HostNoBrackets()),
368 }; 370 };
369 371
370 v8::TryCatch try_catch; 372 v8::TryCatch try_catch;
371 v8::Local<v8::Value> ret = v8::Function::Cast(*function)->Call( 373 v8::Local<v8::Value> ret = v8::Function::Cast(*function)->Call(
372 v8_context_->Global(), arraysize(argv), argv); 374 context->Global(), arraysize(argv), argv);
373 375
374 if (try_catch.HasCaught()) { 376 if (try_catch.HasCaught()) {
375 HandleError(try_catch.Message()); 377 HandleError(try_catch.Message());
376 return ERR_PAC_SCRIPT_FAILED; 378 return ERR_PAC_SCRIPT_FAILED;
377 } 379 }
378 380
379 if (!ret->IsString()) { 381 if (!ret->IsString()) {
380 js_bindings()->OnError( 382 js_bindings()->OnError(
381 -1, ASCIIToUTF16("FindProxyForURL() did not return a string.")); 383 -1, ASCIIToUTF16("FindProxyForURL() did not return a string."));
382 return ERR_PAC_SCRIPT_FAILED; 384 return ERR_PAC_SCRIPT_FAILED;
(...skipping 12 matching lines...) Expand all
395 js_bindings()->OnError(-1, error_message); 397 js_bindings()->OnError(-1, error_message);
396 return ERR_PAC_SCRIPT_FAILED; 398 return ERR_PAC_SCRIPT_FAILED;
397 } 399 }
398 400
399 results->UsePacString(UTF16ToASCII(ret_str)); 401 results->UsePacString(UTF16ToASCII(ret_str));
400 return OK; 402 return OK;
401 } 403 }
402 404
403 int InitV8(const scoped_refptr<ProxyResolverScriptData>& pac_script) { 405 int InitV8(const scoped_refptr<ProxyResolverScriptData>& pac_script) {
404 v8::Locker locked(isolate_); 406 v8::Locker locked(isolate_);
405 v8::HandleScope scope; 407 v8::HandleScope scope(isolate_);
406 408
407 v8_this_.Reset(isolate_, v8::External::New(this)); 409 v8_this_.Reset(isolate_, v8::External::New(this));
410 v8::Local<v8::External> v8_this =
411 v8::Local<v8::External>::New(isolate_, v8_this_);
408 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 412 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
409 413
410 // Attach the javascript bindings. 414 // Attach the javascript bindings.
411 v8::Local<v8::FunctionTemplate> alert_template = 415 v8::Local<v8::FunctionTemplate> alert_template =
412 v8::FunctionTemplate::New(&AlertCallback, v8_this_); 416 v8::FunctionTemplate::New(&AlertCallback, v8_this);
413 global_template->Set(ASCIILiteralToV8String("alert"), alert_template); 417 global_template->Set(ASCIILiteralToV8String("alert"), alert_template);
414 418
415 v8::Local<v8::FunctionTemplate> my_ip_address_template = 419 v8::Local<v8::FunctionTemplate> my_ip_address_template =
416 v8::FunctionTemplate::New(&MyIpAddressCallback, v8_this_); 420 v8::FunctionTemplate::New(&MyIpAddressCallback, v8_this);
417 global_template->Set(ASCIILiteralToV8String("myIpAddress"), 421 global_template->Set(ASCIILiteralToV8String("myIpAddress"),
418 my_ip_address_template); 422 my_ip_address_template);
419 423
420 v8::Local<v8::FunctionTemplate> dns_resolve_template = 424 v8::Local<v8::FunctionTemplate> dns_resolve_template =
421 v8::FunctionTemplate::New(&DnsResolveCallback, v8_this_); 425 v8::FunctionTemplate::New(&DnsResolveCallback, v8_this);
422 global_template->Set(ASCIILiteralToV8String("dnsResolve"), 426 global_template->Set(ASCIILiteralToV8String("dnsResolve"),
423 dns_resolve_template); 427 dns_resolve_template);
424 428
425 // Microsoft's PAC extensions: 429 // Microsoft's PAC extensions:
426 430
427 v8::Local<v8::FunctionTemplate> dns_resolve_ex_template = 431 v8::Local<v8::FunctionTemplate> dns_resolve_ex_template =
428 v8::FunctionTemplate::New(&DnsResolveExCallback, v8_this_); 432 v8::FunctionTemplate::New(&DnsResolveExCallback, v8_this);
429 global_template->Set(ASCIILiteralToV8String("dnsResolveEx"), 433 global_template->Set(ASCIILiteralToV8String("dnsResolveEx"),
430 dns_resolve_ex_template); 434 dns_resolve_ex_template);
431 435
432 v8::Local<v8::FunctionTemplate> my_ip_address_ex_template = 436 v8::Local<v8::FunctionTemplate> my_ip_address_ex_template =
433 v8::FunctionTemplate::New(&MyIpAddressExCallback, v8_this_); 437 v8::FunctionTemplate::New(&MyIpAddressExCallback, v8_this);
434 global_template->Set(ASCIILiteralToV8String("myIpAddressEx"), 438 global_template->Set(ASCIILiteralToV8String("myIpAddressEx"),
435 my_ip_address_ex_template); 439 my_ip_address_ex_template);
436 440
437 v8::Local<v8::FunctionTemplate> sort_ip_address_list_template = 441 v8::Local<v8::FunctionTemplate> sort_ip_address_list_template =
438 v8::FunctionTemplate::New(&SortIpAddressListCallback, v8_this_); 442 v8::FunctionTemplate::New(&SortIpAddressListCallback, v8_this);
439 global_template->Set(ASCIILiteralToV8String("sortIpAddressList"), 443 global_template->Set(ASCIILiteralToV8String("sortIpAddressList"),
440 sort_ip_address_list_template); 444 sort_ip_address_list_template);
441 445
442 v8::Local<v8::FunctionTemplate> is_in_net_ex_template = 446 v8::Local<v8::FunctionTemplate> is_in_net_ex_template =
443 v8::FunctionTemplate::New(&IsInNetExCallback, v8_this_); 447 v8::FunctionTemplate::New(&IsInNetExCallback, v8_this);
444 global_template->Set(ASCIILiteralToV8String("isInNetEx"), 448 global_template->Set(ASCIILiteralToV8String("isInNetEx"),
445 is_in_net_ex_template); 449 is_in_net_ex_template);
446 450
447 v8_context_.Reset( 451 v8_context_.Reset(
448 isolate_, v8::Context::New(isolate_, NULL, global_template)); 452 isolate_, v8::Context::New(isolate_, NULL, global_template));
449 453
450 v8::Context::Scope ctx(v8_context_); 454 v8::Local<v8::Context> context =
455 v8::Local<v8::Context>::New(isolate_, v8_context_);
456 v8::Context::Scope ctx(context);
451 457
452 // Add the PAC utility functions to the environment. 458 // Add the PAC utility functions to the environment.
453 // (This script should never fail, as it is a string literal!) 459 // (This script should never fail, as it is a string literal!)
454 // Note that the two string literals are concatenated. 460 // Note that the two string literals are concatenated.
455 int rv = RunScript( 461 int rv = RunScript(
456 ASCIILiteralToV8String( 462 ASCIILiteralToV8String(
457 PROXY_RESOLVER_SCRIPT 463 PROXY_RESOLVER_SCRIPT
458 PROXY_RESOLVER_SCRIPT_EX), 464 PROXY_RESOLVER_SCRIPT_EX),
459 kPacUtilityResourceName); 465 kPacUtilityResourceName);
460 if (rv != OK) { 466 if (rv != OK) {
(...skipping 18 matching lines...) Expand all
479 return OK; 485 return OK;
480 } 486 }
481 487
482 void PurgeMemory() { 488 void PurgeMemory() {
483 v8::Locker locked(isolate_); 489 v8::Locker locked(isolate_);
484 v8::V8::LowMemoryNotification(); 490 v8::V8::LowMemoryNotification();
485 } 491 }
486 492
487 private: 493 private:
488 bool GetFindProxyForURL(v8::Local<v8::Value>* function) { 494 bool GetFindProxyForURL(v8::Local<v8::Value>* function) {
489 *function = v8_context_->Global()->Get( 495 v8::Local<v8::Context> context =
490 ASCIILiteralToV8String("FindProxyForURL")); 496 v8::Local<v8::Context>::New(v8::Isolate::GetCurrent(), v8_context_);
497 *function =
498 context->Global()->Get(ASCIILiteralToV8String("FindProxyForURL"));
491 return (*function)->IsFunction(); 499 return (*function)->IsFunction();
492 } 500 }
493 501
494 // Handle an exception thrown by V8. 502 // Handle an exception thrown by V8.
495 void HandleError(v8::Handle<v8::Message> message) { 503 void HandleError(v8::Handle<v8::Message> message) {
496 base::string16 error_message; 504 base::string16 error_message;
497 int line_number = -1; 505 int line_number = -1;
498 506
499 if (!message.IsEmpty()) { 507 if (!message.IsEmpty()) {
500 line_number = message->GetLineNumber(); 508 line_number = message->GetLineNumber();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 if (!g_default_isolate_) 760 if (!g_default_isolate_)
753 return 0; 761 return 0;
754 762
755 v8::Locker locked(g_default_isolate_); 763 v8::Locker locked(g_default_isolate_);
756 v8::HeapStatistics heap_statistics; 764 v8::HeapStatistics heap_statistics;
757 g_default_isolate_->GetHeapStatistics(&heap_statistics); 765 g_default_isolate_->GetHeapStatistics(&heap_statistics);
758 return heap_statistics.used_heap_size(); 766 return heap_statistics.used_heap_size();
759 } 767 }
760 768
761 } // namespace net 769 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698