| 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 "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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 bool GetHostnameArgument(const v8::FunctionCallbackInfo<v8::Value>& args, | 210 bool GetHostnameArgument(const v8::FunctionCallbackInfo<v8::Value>& args, |
| 211 std::string* hostname) { | 211 std::string* hostname) { |
| 212 // The first argument should be a string. | 212 // The first argument should be a string. |
| 213 if (args.Length() == 0 || args[0].IsEmpty() || !args[0]->IsString()) | 213 if (args.Length() == 0 || args[0].IsEmpty() || !args[0]->IsString()) |
| 214 return false; | 214 return false; |
| 215 | 215 |
| 216 const base::string16 hostname_utf16 = V8StringToUTF16(args[0]->ToString()); | 216 const base::string16 hostname_utf16 = V8StringToUTF16(args[0]->ToString()); |
| 217 | 217 |
| 218 // If the hostname is already in ASCII, simply return it as is. | 218 // If the hostname is already in ASCII, simply return it as is. |
| 219 if (IsStringASCII(hostname_utf16)) { | 219 if (IsStringASCII(hostname_utf16)) { |
| 220 *hostname = UTF16ToASCII(hostname_utf16); | 220 *hostname = base::UTF16ToASCII(hostname_utf16); |
| 221 return true; | 221 return true; |
| 222 } | 222 } |
| 223 | 223 |
| 224 // Otherwise try to convert it from IDN to punycode. | 224 // Otherwise try to convert it from IDN to punycode. |
| 225 const int kInitialBufferSize = 256; | 225 const int kInitialBufferSize = 256; |
| 226 url_canon::RawCanonOutputT<base::char16, kInitialBufferSize> punycode_output; | 226 url_canon::RawCanonOutputT<base::char16, kInitialBufferSize> punycode_output; |
| 227 if (!url_canon::IDNToASCII(hostname_utf16.data(), | 227 if (!url_canon::IDNToASCII(hostname_utf16.data(), |
| 228 hostname_utf16.length(), | 228 hostname_utf16.length(), |
| 229 &punycode_output)) { | 229 &punycode_output)) { |
| 230 return false; | 230 return false; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 // could extend the parsing to handle IDNA hostnames by | 403 // could extend the parsing to handle IDNA hostnames by |
| 404 // converting them to ASCII punycode. | 404 // converting them to ASCII punycode. |
| 405 // crbug.com/47234 | 405 // crbug.com/47234 |
| 406 base::string16 error_message = | 406 base::string16 error_message = |
| 407 base::ASCIIToUTF16("FindProxyForURL() returned a non-ASCII string " | 407 base::ASCIIToUTF16("FindProxyForURL() returned a non-ASCII string " |
| 408 "(crbug.com/47234): ") + ret_str; | 408 "(crbug.com/47234): ") + ret_str; |
| 409 js_bindings()->OnError(-1, error_message); | 409 js_bindings()->OnError(-1, error_message); |
| 410 return ERR_PAC_SCRIPT_FAILED; | 410 return ERR_PAC_SCRIPT_FAILED; |
| 411 } | 411 } |
| 412 | 412 |
| 413 results->UsePacString(UTF16ToASCII(ret_str)); | 413 results->UsePacString(base::UTF16ToASCII(ret_str)); |
| 414 return OK; | 414 return OK; |
| 415 } | 415 } |
| 416 | 416 |
| 417 int InitV8(const scoped_refptr<ProxyResolverScriptData>& pac_script) { | 417 int InitV8(const scoped_refptr<ProxyResolverScriptData>& pac_script) { |
| 418 v8::Locker locked(isolate_); | 418 v8::Locker locked(isolate_); |
| 419 v8::Isolate::Scope isolate_scope(isolate_); | 419 v8::Isolate::Scope isolate_scope(isolate_); |
| 420 v8::HandleScope scope(isolate_); | 420 v8::HandleScope scope(isolate_); |
| 421 | 421 |
| 422 v8_this_.Reset(isolate_, v8::External::New(isolate_, this)); | 422 v8_this_.Reset(isolate_, v8::External::New(isolate_, this)); |
| 423 v8::Local<v8::External> v8_this = | 423 v8::Local<v8::External> v8_this = |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 return 0; | 814 return 0; |
| 815 | 815 |
| 816 v8::Locker locked(g_default_isolate_); | 816 v8::Locker locked(g_default_isolate_); |
| 817 v8::Isolate::Scope isolate_scope(g_default_isolate_); | 817 v8::Isolate::Scope isolate_scope(g_default_isolate_); |
| 818 v8::HeapStatistics heap_statistics; | 818 v8::HeapStatistics heap_statistics; |
| 819 g_default_isolate_->GetHeapStatistics(&heap_statistics); | 819 g_default_isolate_->GetHeapStatistics(&heap_statistics); |
| 820 return heap_statistics.used_heap_size(); | 820 return heap_statistics.used_heap_size(); |
| 821 } | 821 } |
| 822 | 822 |
| 823 } // namespace net | 823 } // namespace net |
| OLD | NEW |