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 "chrome/renderer/extensions/chrome_v8_context.h" | 5 #include "chrome/renderer/extensions/chrome_v8_context.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/common/extensions/extension_set.h" | 11 #include "chrome/common/extensions/extension_set.h" |
12 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 12 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
13 #include "content/public/renderer/render_view.h" | 13 #include "content/public/renderer/render_view.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
16 #include "v8/include/v8.h" | 16 #include "v8/include/v8.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 const char kChromeHidden[] = "chromeHidden"; | 20 const char kChromeHidden[] = "chromeHidden"; |
21 | 21 |
22 #ifndef NDEBUG | 22 #ifndef NDEBUG |
23 const char kValidateCallbacks[] = "validateCallbacks"; | 23 const char kValidateCallbacks[] = "validateCallbacks"; |
| 24 const char kValidateAPI[] = "validateAPI"; |
24 #endif | 25 #endif |
25 | 26 |
26 std::string GetContextTypeDescription( | 27 std::string GetContextTypeDescription( |
27 ChromeV8Context::ContextType context_type) { | 28 ChromeV8Context::ContextType context_type) { |
28 switch (context_type) { | 29 switch (context_type) { |
29 case ChromeV8Context::OTHER: return "other"; | 30 case ChromeV8Context::OTHER: return "other"; |
30 case ChromeV8Context::CONTENT_SCRIPT: return "content script"; | 31 case ChromeV8Context::CONTENT_SCRIPT: return "content script"; |
31 } | 32 } |
32 NOTREACHED(); | 33 NOTREACHED(); |
33 return ""; | 34 return ""; |
(...skipping 28 matching lines...) Expand all Loading... |
62 v8::Local<v8::Value> hidden = global->GetHiddenValue( | 63 v8::Local<v8::Value> hidden = global->GetHiddenValue( |
63 v8::String::New(kChromeHidden)); | 64 v8::String::New(kChromeHidden)); |
64 | 65 |
65 if (hidden.IsEmpty() || hidden->IsUndefined()) { | 66 if (hidden.IsEmpty() || hidden->IsUndefined()) { |
66 hidden = v8::Object::New(); | 67 hidden = v8::Object::New(); |
67 global->SetHiddenValue(v8::String::New(kChromeHidden), hidden); | 68 global->SetHiddenValue(v8::String::New(kChromeHidden), hidden); |
68 | 69 |
69 #ifndef NDEBUG | 70 #ifndef NDEBUG |
70 // Tell schema_generated_bindings.js to validate callbacks and events | 71 // Tell schema_generated_bindings.js to validate callbacks and events |
71 // against their schema definitions. | 72 // against their schema definitions. |
72 v8::Local<v8::Object>::Cast(hidden) | 73 v8::Local<v8::Object>::Cast(hidden)->Set( |
73 ->Set(v8::String::New(kValidateCallbacks), v8::True()); | 74 v8::String::New(kValidateCallbacks), v8::True()); |
| 75 // Tell schema_generated_bindings.js to validate API for ambiguity. |
| 76 v8::Local<v8::Object>::Cast(hidden)->Set( |
| 77 v8::String::New(kValidateAPI), v8::True()); |
74 #endif | 78 #endif |
75 } | 79 } |
76 | 80 |
77 DCHECK(hidden->IsObject()); | 81 DCHECK(hidden->IsObject()); |
78 return v8::Local<v8::Object>::Cast(hidden); | 82 return v8::Local<v8::Object>::Cast(hidden); |
79 } | 83 } |
80 | 84 |
81 v8::Handle<v8::Value> ChromeV8Context::GetChromeHidden() const { | 85 v8::Handle<v8::Value> ChromeV8Context::GetChromeHidden() const { |
82 v8::Local<v8::Object> global = v8_context_->Global(); | 86 v8::Local<v8::Object> global = v8_context_->Global(); |
83 return global->GetHiddenValue(v8::String::New(kChromeHidden)); | 87 return global->GetHiddenValue(v8::String::New(kChromeHidden)); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 argv[1] = v8::Boolean::New(is_extension_process); | 140 argv[1] = v8::Boolean::New(is_extension_process); |
137 argv[2] = v8::Boolean::New(is_incognito_process); | 141 argv[2] = v8::Boolean::New(is_incognito_process); |
138 argv[3] = v8::Integer::New(manifest_version); | 142 argv[3] = v8::Integer::New(manifest_version); |
139 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); | 143 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); |
140 } | 144 } |
141 | 145 |
142 void ChromeV8Context::DispatchOnUnloadEvent() const { | 146 void ChromeV8Context::DispatchOnUnloadEvent() const { |
143 v8::HandleScope handle_scope; | 147 v8::HandleScope handle_scope; |
144 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); | 148 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); |
145 } | 149 } |
OLD | NEW |