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

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

Issue 812543002: Update from https://crrev.com/308331 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « net/proxy/proxy_resolver_script.h ('k') | net/quic/quic_stream_factory.cc » ('j') | 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 // Both |address| and |prefix| must be of the same type (IPv4 or IPv6). 327 // Both |address| and |prefix| must be of the same type (IPv4 or IPv6).
328 if (address.size() != prefix.size()) 328 if (address.size() != prefix.size())
329 return false; 329 return false;
330 330
331 DCHECK((address.size() == 4 && prefix.size() == 4) || 331 DCHECK((address.size() == 4 && prefix.size() == 4) ||
332 (address.size() == 16 && prefix.size() == 16)); 332 (address.size() == 16 && prefix.size() == 16));
333 333
334 return IPNumberMatchesPrefix(address, prefix, prefix_length_in_bits); 334 return IPNumberMatchesPrefix(address, prefix, prefix_length_in_bits);
335 } 335 }
336 336
337 // Consider only single component domains like 'foo' as plain host names.
338 bool IsPlainHostName(const std::string& hostname_utf8) {
339 if (hostname_utf8.find('.') != std::string::npos)
340 return false;
341
342 // IPv6 addresses may not contain periods, however are not be considered a
343 // plain host name.
344 IPAddressNumber unused;
345 return !ParseIPLiteralToNumber(hostname_utf8, &unused);
346 }
347
337 } // namespace 348 } // namespace
338 349
339 // ProxyResolverV8::Context --------------------------------------------------- 350 // ProxyResolverV8::Context ---------------------------------------------------
340 351
341 class ProxyResolverV8::Context { 352 class ProxyResolverV8::Context {
342 public: 353 public:
343 Context(ProxyResolverV8* parent, v8::Isolate* isolate) 354 Context(ProxyResolverV8* parent, v8::Isolate* isolate)
344 : parent_(parent), 355 : parent_(parent),
345 isolate_(isolate) { 356 isolate_(isolate) {
346 DCHECK(isolate); 357 DCHECK(isolate);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 v8::Local<v8::FunctionTemplate> my_ip_address_template = 443 v8::Local<v8::FunctionTemplate> my_ip_address_template =
433 v8::FunctionTemplate::New(isolate_, &MyIpAddressCallback, v8_this); 444 v8::FunctionTemplate::New(isolate_, &MyIpAddressCallback, v8_this);
434 global_template->Set(ASCIILiteralToV8String(isolate_, "myIpAddress"), 445 global_template->Set(ASCIILiteralToV8String(isolate_, "myIpAddress"),
435 my_ip_address_template); 446 my_ip_address_template);
436 447
437 v8::Local<v8::FunctionTemplate> dns_resolve_template = 448 v8::Local<v8::FunctionTemplate> dns_resolve_template =
438 v8::FunctionTemplate::New(isolate_, &DnsResolveCallback, v8_this); 449 v8::FunctionTemplate::New(isolate_, &DnsResolveCallback, v8_this);
439 global_template->Set(ASCIILiteralToV8String(isolate_, "dnsResolve"), 450 global_template->Set(ASCIILiteralToV8String(isolate_, "dnsResolve"),
440 dns_resolve_template); 451 dns_resolve_template);
441 452
453 v8::Local<v8::FunctionTemplate> is_plain_host_name_template =
454 v8::FunctionTemplate::New(isolate_, &IsPlainHostNameCallback, v8_this);
455 global_template->Set(ASCIILiteralToV8String(isolate_, "isPlainHostName"),
456 is_plain_host_name_template);
457
442 // Microsoft's PAC extensions: 458 // Microsoft's PAC extensions:
443 459
444 v8::Local<v8::FunctionTemplate> dns_resolve_ex_template = 460 v8::Local<v8::FunctionTemplate> dns_resolve_ex_template =
445 v8::FunctionTemplate::New(isolate_, &DnsResolveExCallback, v8_this); 461 v8::FunctionTemplate::New(isolate_, &DnsResolveExCallback, v8_this);
446 global_template->Set(ASCIILiteralToV8String(isolate_, "dnsResolveEx"), 462 global_template->Set(ASCIILiteralToV8String(isolate_, "dnsResolveEx"),
447 dns_resolve_ex_template); 463 dns_resolve_ex_template);
448 464
449 v8::Local<v8::FunctionTemplate> my_ip_address_ex_template = 465 v8::Local<v8::FunctionTemplate> my_ip_address_ex_template =
450 v8::FunctionTemplate::New(isolate_, &MyIpAddressExCallback, v8_this); 466 v8::FunctionTemplate::New(isolate_, &MyIpAddressExCallback, v8_this);
451 global_template->Set(ASCIILiteralToV8String(isolate_, "myIpAddressEx"), 467 global_template->Set(ASCIILiteralToV8String(isolate_, "myIpAddressEx"),
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 } 707 }
692 std::string ip_prefix = 708 std::string ip_prefix =
693 V8StringToUTF8(v8::Local<v8::String>::Cast(args[1])); 709 V8StringToUTF8(v8::Local<v8::String>::Cast(args[1]));
694 if (!base::IsStringASCII(ip_prefix)) { 710 if (!base::IsStringASCII(ip_prefix)) {
695 args.GetReturnValue().Set(false); 711 args.GetReturnValue().Set(false);
696 return; 712 return;
697 } 713 }
698 args.GetReturnValue().Set(IsInNetEx(ip_address, ip_prefix)); 714 args.GetReturnValue().Set(IsInNetEx(ip_address, ip_prefix));
699 } 715 }
700 716
717 // V8 callback for when "isPlainHostName()" is invoked by the PAC script.
718 static void IsPlainHostNameCallback(
719 const v8::FunctionCallbackInfo<v8::Value>& args) {
720 // Need at least 1 string arguments.
721 if (args.Length() < 1 || args[0].IsEmpty() || !args[0]->IsString()) {
722 args.GetIsolate()->ThrowException(
723 v8::Exception::TypeError(ASCIIStringToV8String(
724 args.GetIsolate(), "Requires 1 string parameter")));
725 return;
726 }
727
728 std::string hostname_utf8 =
729 V8StringToUTF8(v8::Local<v8::String>::Cast(args[0]));
730 args.GetReturnValue().Set(IsPlainHostName(hostname_utf8));
731 }
732
701 mutable base::Lock lock_; 733 mutable base::Lock lock_;
702 ProxyResolverV8* parent_; 734 ProxyResolverV8* parent_;
703 v8::Isolate* isolate_; 735 v8::Isolate* isolate_;
704 v8::Persistent<v8::External> v8_this_; 736 v8::Persistent<v8::External> v8_this_;
705 v8::Persistent<v8::Context> v8_context_; 737 v8::Persistent<v8::Context> v8_context_;
706 }; 738 };
707 739
708 // ProxyResolverV8 ------------------------------------------------------------ 740 // ProxyResolverV8 ------------------------------------------------------------
709 741
710 ProxyResolverV8::ProxyResolverV8() 742 ProxyResolverV8::ProxyResolverV8()
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 return 0; 833 return 0;
802 834
803 v8::Locker locked(g_proxy_resolver_isolate_->isolate()); 835 v8::Locker locked(g_proxy_resolver_isolate_->isolate());
804 v8::Isolate::Scope isolate_scope(g_proxy_resolver_isolate_->isolate()); 836 v8::Isolate::Scope isolate_scope(g_proxy_resolver_isolate_->isolate());
805 v8::HeapStatistics heap_statistics; 837 v8::HeapStatistics heap_statistics;
806 g_proxy_resolver_isolate_->isolate()->GetHeapStatistics(&heap_statistics); 838 g_proxy_resolver_isolate_->isolate()->GetHeapStatistics(&heap_statistics);
807 return heap_statistics.used_heap_size(); 839 return heap_statistics.used_heap_size();
808 } 840 }
809 841
810 } // namespace net 842 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_script.h ('k') | net/quic/quic_stream_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698