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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_split.h" | 8 #include "base/string_split.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/common/extensions/extension_set.h" | 10 #include "chrome/common/extensions/extension_set.h" |
11 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 11 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
12 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
15 #include "v8/include/v8.h" | 15 #include "v8/include/v8.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 const char kChromeHidden[] = "chromeHidden"; | 19 const char kChromeHidden[] = "chromeHidden"; |
20 | 20 |
21 #ifndef NDEBUG | 21 #ifndef NDEBUG |
22 const char kValidateCallbacks[] = "validateCallbacks"; | 22 const char kValidateCallbacks[] = "validateCallbacks"; |
23 const char kValidateAPI[] = "validateAPI"; | |
23 #endif | 24 #endif |
24 | 25 |
25 } // namespace | 26 } // namespace |
26 | 27 |
27 | 28 |
28 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, | 29 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, |
29 WebKit::WebFrame* web_frame, | 30 WebKit::WebFrame* web_frame, |
30 const std::string& extension_id) | 31 const std::string& extension_id) |
31 : v8_context_(v8::Persistent<v8::Context>::New(v8_context)), | 32 : v8_context_(v8::Persistent<v8::Context>::New(v8_context)), |
32 web_frame_(web_frame), | 33 web_frame_(web_frame), |
(...skipping 18 matching lines...) Expand all Loading... | |
51 | 52 |
52 if (hidden.IsEmpty() || hidden->IsUndefined()) { | 53 if (hidden.IsEmpty() || hidden->IsUndefined()) { |
53 hidden = v8::Object::New(); | 54 hidden = v8::Object::New(); |
54 global->SetHiddenValue(v8::String::New(kChromeHidden), hidden); | 55 global->SetHiddenValue(v8::String::New(kChromeHidden), hidden); |
55 | 56 |
56 #ifndef NDEBUG | 57 #ifndef NDEBUG |
57 // Tell schema_generated_bindings.js to validate callbacks and events | 58 // Tell schema_generated_bindings.js to validate callbacks and events |
58 // against their schema definitions. | 59 // against their schema definitions. |
59 v8::Local<v8::Object>::Cast(hidden) | 60 v8::Local<v8::Object>::Cast(hidden) |
60 ->Set(v8::String::New(kValidateCallbacks), v8::True()); | 61 ->Set(v8::String::New(kValidateCallbacks), v8::True()); |
62 // Tell schema_generated_bindings.js to validate API for ambiguity. | |
63 v8::Local<v8::Object>::Cast(hidden) | |
64 ->Set(v8::String::New(kValidateAPI), v8::True()); | |
Aaron Boodman
2012/02/06 01:30:52
Formatting should be:
v8::Local<v8::Object>::Cast
Matt Perry
2012/02/06 21:34:57
btw, the reason for this is that Chrome style is t
| |
61 #endif | 65 #endif |
62 } | 66 } |
63 | 67 |
64 DCHECK(hidden->IsObject()); | 68 DCHECK(hidden->IsObject()); |
65 return v8::Local<v8::Object>::Cast(hidden); | 69 return v8::Local<v8::Object>::Cast(hidden); |
66 } | 70 } |
67 | 71 |
68 v8::Handle<v8::Value> ChromeV8Context::GetChromeHidden() const { | 72 v8::Handle<v8::Value> ChromeV8Context::GetChromeHidden() const { |
69 v8::Local<v8::Object> global = v8_context_->Global(); | 73 v8::Local<v8::Object> global = v8_context_->Global(); |
70 return global->GetHiddenValue(v8::String::New(kChromeHidden)); | 74 return global->GetHiddenValue(v8::String::New(kChromeHidden)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 argv[1] = v8::Boolean::New(is_extension_process); | 124 argv[1] = v8::Boolean::New(is_extension_process); |
121 argv[2] = v8::Boolean::New(is_incognito_process); | 125 argv[2] = v8::Boolean::New(is_incognito_process); |
122 argv[3] = v8::Integer::New(manifest_version); | 126 argv[3] = v8::Integer::New(manifest_version); |
123 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); | 127 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); |
124 } | 128 } |
125 | 129 |
126 void ChromeV8Context::DispatchOnUnloadEvent() const { | 130 void ChromeV8Context::DispatchOnUnloadEvent() const { |
127 v8::HandleScope handle_scope; | 131 v8::HandleScope handle_scope; |
128 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); | 132 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); |
129 } | 133 } |
OLD | NEW |