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

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

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 189
190 // Stringizes a V8 object by calling its toString() method. Returns true 190 // Stringizes a V8 object by calling its toString() method. Returns true
191 // on success. This may fail if the toString() throws an exception. 191 // on success. This may fail if the toString() throws an exception.
192 bool V8ObjectToUTF16String(v8::Local<v8::Value> object, 192 bool V8ObjectToUTF16String(v8::Local<v8::Value> object,
193 base::string16* utf16_result, 193 base::string16* utf16_result,
194 v8::Isolate* isolate) { 194 v8::Isolate* isolate) {
195 if (object.IsEmpty()) 195 if (object.IsEmpty())
196 return false; 196 return false;
197 197
198 v8::HandleScope scope(isolate); 198 v8::HandleScope scope(isolate);
199 v8::Local<v8::String> str_object = object->ToString(); 199 v8::Local<v8::String> str_object = object->ToString(isolate);
200 if (str_object.IsEmpty()) 200 if (str_object.IsEmpty())
201 return false; 201 return false;
202 *utf16_result = V8StringToUTF16(str_object); 202 *utf16_result = V8StringToUTF16(str_object);
203 return true; 203 return true;
204 } 204 }
205 205
206 // Extracts an hostname argument from |args|. On success returns true 206 // Extracts an hostname argument from |args|. On success returns true
207 // and fills |*hostname| with the result. 207 // and fills |*hostname| with the result.
208 bool GetHostnameArgument(const v8::FunctionCallbackInfo<v8::Value>& args, 208 bool GetHostnameArgument(const v8::FunctionCallbackInfo<v8::Value>& args,
209 std::string* hostname) { 209 std::string* hostname) {
210 // The first argument should be a string. 210 // The first argument should be a string.
211 if (args.Length() == 0 || args[0].IsEmpty() || !args[0]->IsString()) 211 if (args.Length() == 0 || args[0].IsEmpty() || !args[0]->IsString())
212 return false; 212 return false;
213 213
214 const base::string16 hostname_utf16 = V8StringToUTF16(args[0]->ToString()); 214 const base::string16 hostname_utf16 =
215 V8StringToUTF16(v8::Local<v8::String>::Cast(args[0]));
215 216
216 // If the hostname is already in ASCII, simply return it as is. 217 // If the hostname is already in ASCII, simply return it as is.
217 if (base::IsStringASCII(hostname_utf16)) { 218 if (base::IsStringASCII(hostname_utf16)) {
218 *hostname = base::UTF16ToASCII(hostname_utf16); 219 *hostname = base::UTF16ToASCII(hostname_utf16);
219 return true; 220 return true;
220 } 221 }
221 222
222 // Otherwise try to convert it from IDN to punycode. 223 // Otherwise try to convert it from IDN to punycode.
223 const int kInitialBufferSize = 256; 224 const int kInitialBufferSize = 256;
224 url::RawCanonOutputT<base::char16, kInitialBufferSize> punycode_output; 225 url::RawCanonOutputT<base::char16, kInitialBufferSize> punycode_output;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 HandleError(try_catch.Message()); 387 HandleError(try_catch.Message());
387 return ERR_PAC_SCRIPT_FAILED; 388 return ERR_PAC_SCRIPT_FAILED;
388 } 389 }
389 390
390 if (!ret->IsString()) { 391 if (!ret->IsString()) {
391 js_bindings()->OnError( 392 js_bindings()->OnError(
392 -1, base::ASCIIToUTF16("FindProxyForURL() did not return a string.")); 393 -1, base::ASCIIToUTF16("FindProxyForURL() did not return a string."));
393 return ERR_PAC_SCRIPT_FAILED; 394 return ERR_PAC_SCRIPT_FAILED;
394 } 395 }
395 396
396 base::string16 ret_str = V8StringToUTF16(ret->ToString()); 397 base::string16 ret_str = V8StringToUTF16(v8::Local<v8::String>::Cast(ret));
397 398
398 if (!base::IsStringASCII(ret_str)) { 399 if (!base::IsStringASCII(ret_str)) {
399 // TODO(eroman): Rather than failing when a wide string is returned, we 400 // TODO(eroman): Rather than failing when a wide string is returned, we
400 // could extend the parsing to handle IDNA hostnames by 401 // could extend the parsing to handle IDNA hostnames by
401 // converting them to ASCII punycode. 402 // converting them to ASCII punycode.
402 // crbug.com/47234 403 // crbug.com/47234
403 base::string16 error_message = 404 base::string16 error_message =
404 base::ASCIIToUTF16("FindProxyForURL() returned a non-ASCII string " 405 base::ASCIIToUTF16("FindProxyForURL() returned a non-ASCII string "
405 "(crbug.com/47234): ") + ret_str; 406 "(crbug.com/47234): ") + ret_str;
406 js_bindings()->OnError(-1, error_message); 407 js_bindings()->OnError(-1, error_message);
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 650
650 // V8 callback for when "sortIpAddressList()" is invoked by the PAC script. 651 // V8 callback for when "sortIpAddressList()" is invoked by the PAC script.
651 static void SortIpAddressListCallback( 652 static void SortIpAddressListCallback(
652 const v8::FunctionCallbackInfo<v8::Value>& args) { 653 const v8::FunctionCallbackInfo<v8::Value>& args) {
653 // We need at least one string argument. 654 // We need at least one string argument.
654 if (args.Length() == 0 || args[0].IsEmpty() || !args[0]->IsString()) { 655 if (args.Length() == 0 || args[0].IsEmpty() || !args[0]->IsString()) {
655 args.GetReturnValue().SetNull(); 656 args.GetReturnValue().SetNull();
656 return; 657 return;
657 } 658 }
658 659
659 std::string ip_address_list = V8StringToUTF8(args[0]->ToString()); 660 std::string ip_address_list =
661 V8StringToUTF8(v8::Local<v8::String>::Cast(args[0]));
660 if (!base::IsStringASCII(ip_address_list)) { 662 if (!base::IsStringASCII(ip_address_list)) {
661 args.GetReturnValue().SetNull(); 663 args.GetReturnValue().SetNull();
662 return; 664 return;
663 } 665 }
664 std::string sorted_ip_address_list; 666 std::string sorted_ip_address_list;
665 bool success = SortIpAddressList(ip_address_list, &sorted_ip_address_list); 667 bool success = SortIpAddressList(ip_address_list, &sorted_ip_address_list);
666 if (!success) { 668 if (!success) {
667 args.GetReturnValue().Set(false); 669 args.GetReturnValue().Set(false);
668 return; 670 return;
669 } 671 }
670 args.GetReturnValue().Set( 672 args.GetReturnValue().Set(
671 ASCIIStringToV8String(args.GetIsolate(), sorted_ip_address_list)); 673 ASCIIStringToV8String(args.GetIsolate(), sorted_ip_address_list));
672 } 674 }
673 675
674 // V8 callback for when "isInNetEx()" is invoked by the PAC script. 676 // V8 callback for when "isInNetEx()" is invoked by the PAC script.
675 static void IsInNetExCallback( 677 static void IsInNetExCallback(
676 const v8::FunctionCallbackInfo<v8::Value>& args) { 678 const v8::FunctionCallbackInfo<v8::Value>& args) {
677 // We need at least 2 string arguments. 679 // We need at least 2 string arguments.
678 if (args.Length() < 2 || args[0].IsEmpty() || !args[0]->IsString() || 680 if (args.Length() < 2 || args[0].IsEmpty() || !args[0]->IsString() ||
679 args[1].IsEmpty() || !args[1]->IsString()) { 681 args[1].IsEmpty() || !args[1]->IsString()) {
680 args.GetReturnValue().SetNull(); 682 args.GetReturnValue().SetNull();
681 return; 683 return;
682 } 684 }
683 685
684 std::string ip_address = V8StringToUTF8(args[0]->ToString()); 686 std::string ip_address =
687 V8StringToUTF8(v8::Local<v8::String>::Cast(args[0]));
685 if (!base::IsStringASCII(ip_address)) { 688 if (!base::IsStringASCII(ip_address)) {
686 args.GetReturnValue().Set(false); 689 args.GetReturnValue().Set(false);
687 return; 690 return;
688 } 691 }
689 std::string ip_prefix = V8StringToUTF8(args[1]->ToString()); 692 std::string ip_prefix =
693 V8StringToUTF8(v8::Local<v8::String>::Cast(args[1]));
690 if (!base::IsStringASCII(ip_prefix)) { 694 if (!base::IsStringASCII(ip_prefix)) {
691 args.GetReturnValue().Set(false); 695 args.GetReturnValue().Set(false);
692 return; 696 return;
693 } 697 }
694 args.GetReturnValue().Set(IsInNetEx(ip_address, ip_prefix)); 698 args.GetReturnValue().Set(IsInNetEx(ip_address, ip_prefix));
695 } 699 }
696 700
697 mutable base::Lock lock_; 701 mutable base::Lock lock_;
698 ProxyResolverV8* parent_; 702 ProxyResolverV8* parent_;
699 v8::Isolate* isolate_; 703 v8::Isolate* isolate_;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 return 0; 801 return 0;
798 802
799 v8::Locker locked(g_proxy_resolver_isolate_->isolate()); 803 v8::Locker locked(g_proxy_resolver_isolate_->isolate());
800 v8::Isolate::Scope isolate_scope(g_proxy_resolver_isolate_->isolate()); 804 v8::Isolate::Scope isolate_scope(g_proxy_resolver_isolate_->isolate());
801 v8::HeapStatistics heap_statistics; 805 v8::HeapStatistics heap_statistics;
802 g_proxy_resolver_isolate_->isolate()->GetHeapStatistics(&heap_statistics); 806 g_proxy_resolver_isolate_->isolate()->GetHeapStatistics(&heap_statistics);
803 return heap_statistics.used_heap_size(); 807 return heap_statistics.used_heap_size();
804 } 808 }
805 809
806 } // namespace net 810 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_config_service_android.cc ('k') | net/proxy/proxy_script_fetcher_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698