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" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/debug/leak_annotations.h" | 12 #include "base/debug/leak_annotations.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/strings/string_tokenizer.h" | 14 #include "base/strings/string_tokenizer.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "gin/array_buffer.h" | 18 #include "gin/array_buffer.h" |
19 #include "gin/public/isolate_holder.h" | 19 #include "gin/public/isolate_holder.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
21 #include "net/base/net_log.h" | 21 #include "net/base/net_log.h" |
22 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
23 #include "net/proxy/proxy_info.h" | 23 #include "net/proxy/proxy_info.h" |
24 #include "net/proxy/proxy_resolver_script.h" | 24 #include "net/proxy/proxy_resolver_script.h" |
25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
26 #include "url/url_canon.h" | 26 #include "url/url_canon.h" |
27 #include "v8/include/v8.h" | 27 #include "v8/include/v8.h" |
28 | 28 |
| 29 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 30 #include "gin/public/isolate_holder.h" |
| 31 #endif |
| 32 |
29 // Notes on the javascript environment: | 33 // Notes on the javascript environment: |
30 // | 34 // |
31 // For the majority of the PAC utility functions, we use the same code | 35 // For the majority of the PAC utility functions, we use the same code |
32 // as Firefox. See the javascript library that proxy_resolver_scipt.h | 36 // as Firefox. See the javascript library that proxy_resolver_scipt.h |
33 // pulls in. | 37 // pulls in. |
34 // | 38 // |
35 // In addition, we implement a subset of Microsoft's extensions to PAC. | 39 // In addition, we implement a subset of Microsoft's extensions to PAC. |
36 // - myIpAddressEx() | 40 // - myIpAddressEx() |
37 // - dnsResolveEx() | 41 // - dnsResolveEx() |
38 // - isResolvableEx() | 42 // - isResolvableEx() |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 int rv = context->InitV8(script_data); | 767 int rv = context->InitV8(script_data); |
764 if (rv == OK) | 768 if (rv == OK) |
765 context_.reset(context.release()); | 769 context_.reset(context.release()); |
766 return rv; | 770 return rv; |
767 } | 771 } |
768 | 772 |
769 // static | 773 // static |
770 void ProxyResolverV8::EnsureIsolateCreated() { | 774 void ProxyResolverV8::EnsureIsolateCreated() { |
771 if (g_proxy_resolver_isolate_) | 775 if (g_proxy_resolver_isolate_) |
772 return; | 776 return; |
| 777 |
| 778 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 779 gin::IsolateHolder::LoadV8Snapshot(); |
| 780 #endif |
773 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, | 781 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, |
774 gin::ArrayBufferAllocator::SharedInstance()); | 782 gin::ArrayBufferAllocator::SharedInstance()); |
775 g_proxy_resolver_isolate_ = new gin::IsolateHolder; | 783 g_proxy_resolver_isolate_ = new gin::IsolateHolder; |
776 ANNOTATE_LEAKING_OBJECT_PTR(g_proxy_resolver_isolate_); | 784 ANNOTATE_LEAKING_OBJECT_PTR(g_proxy_resolver_isolate_); |
777 } | 785 } |
778 | 786 |
779 // static | 787 // static |
780 v8::Isolate* ProxyResolverV8::GetDefaultIsolate() { | 788 v8::Isolate* ProxyResolverV8::GetDefaultIsolate() { |
781 DCHECK(g_proxy_resolver_isolate_) | 789 DCHECK(g_proxy_resolver_isolate_) |
782 << "Must call ProxyResolverV8::EnsureIsolateCreated() first"; | 790 << "Must call ProxyResolverV8::EnsureIsolateCreated() first"; |
(...skipping 20 matching lines...) Expand all Loading... |
803 return 0; | 811 return 0; |
804 | 812 |
805 v8::Locker locked(g_proxy_resolver_isolate_->isolate()); | 813 v8::Locker locked(g_proxy_resolver_isolate_->isolate()); |
806 v8::Isolate::Scope isolate_scope(g_proxy_resolver_isolate_->isolate()); | 814 v8::Isolate::Scope isolate_scope(g_proxy_resolver_isolate_->isolate()); |
807 v8::HeapStatistics heap_statistics; | 815 v8::HeapStatistics heap_statistics; |
808 g_proxy_resolver_isolate_->isolate()->GetHeapStatistics(&heap_statistics); | 816 g_proxy_resolver_isolate_->isolate()->GetHeapStatistics(&heap_statistics); |
809 return heap_statistics.used_heap_size(); | 817 return heap_statistics.used_heap_size(); |
810 } | 818 } |
811 | 819 |
812 } // namespace net | 820 } // namespace net |
OLD | NEW |