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" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 const char kChromeHidden[] = "chromeHidden"; | 25 const char kChromeHidden[] = "chromeHidden"; |
26 | 26 |
27 #ifndef NDEBUG | 27 #ifndef NDEBUG |
28 const char kValidateCallbacks[] = "validateCallbacks"; | 28 const char kValidateCallbacks[] = "validateCallbacks"; |
29 const char kValidateAPI[] = "validateAPI"; | 29 const char kValidateAPI[] = "validateAPI"; |
30 #endif | 30 #endif |
31 | 31 |
32 std::string GetContextTypeDescription(Feature::Context context_type) { | |
33 switch (context_type) { | |
34 case Feature::UNSPECIFIED_CONTEXT: return "UNSPECIFIED"; | |
35 case Feature::BLESSED_EXTENSION_CONTEXT: return "BLESSED_EXTENSION"; | |
36 case Feature::UNBLESSED_EXTENSION_CONTEXT: return "UNBLESSED_EXTENSION"; | |
37 case Feature::CONTENT_SCRIPT_CONTEXT: return "CONTENT_SCRIPT"; | |
38 case Feature::WEB_PAGE_CONTEXT: return "WEB_PAGE"; | |
39 } | |
40 NOTREACHED(); | |
41 return ""; | |
42 } | |
43 | |
44 } // namespace | 32 } // namespace |
45 | 33 |
46 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, | 34 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, |
47 WebKit::WebFrame* web_frame, | 35 WebKit::WebFrame* web_frame, |
48 const extensions::Extension* extension, | 36 const extensions::Extension* extension, |
49 Feature::Context context_type) | 37 Feature::Context context_type) |
50 : v8_context_(v8::Persistent<v8::Context>::New(v8_context)), | 38 : v8_context_(v8::Persistent<v8::Context>::New(v8_context)), |
51 web_frame_(web_frame), | 39 web_frame_(web_frame), |
52 extension_(extension), | 40 extension_(extension), |
53 context_type_(context_type) { | 41 context_type_(context_type) { |
54 VLOG(1) << "Created context:\n" | 42 VLOG(1) << "Created context:\n" |
55 << " extension id: " << GetExtensionID() << "\n" | 43 << " extension id: " << GetExtensionID() << "\n" |
56 << " frame: " << web_frame_ << "\n" | 44 << " frame: " << web_frame_ << "\n" |
57 << " context type: " << GetContextTypeDescription(context_type); | 45 << " context type: " |
46 << GetContextTypeDescription(); | |
not at google - send to devlin
2012/07/12 05:47:41
Doesn't fit on 1 line?
koz (OOO until 15th September)
2012/07/12 06:06:12
Done.
| |
58 } | 47 } |
59 | 48 |
60 ChromeV8Context::~ChromeV8Context() { | 49 ChromeV8Context::~ChromeV8Context() { |
61 VLOG(1) << "Destroyed context for extension\n" | 50 VLOG(1) << "Destroyed context for extension\n" |
62 << " extension id: " << GetExtensionID(); | 51 << " extension id: " << GetExtensionID(); |
63 v8_context_.Dispose(); | 52 v8_context_.Dispose(); |
64 } | 53 } |
65 | 54 |
66 std::string ChromeV8Context::GetExtensionID() { | 55 std::string ChromeV8Context::GetExtensionID() { |
67 return extension_ ? extension_->id() : ""; | 56 return extension_ ? extension_->id() : ""; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 UserScriptSlave::GetDataSourceURLForFrame(web_frame_)).Pass(); | 151 UserScriptSlave::GetDataSourceURLForFrame(web_frame_)).Pass(); |
163 } | 152 } |
164 return *(available_extension_apis_.get()); | 153 return *(available_extension_apis_.get()); |
165 } | 154 } |
166 | 155 |
167 void ChromeV8Context::DispatchOnLoadEvent(bool is_incognito_process, | 156 void ChromeV8Context::DispatchOnLoadEvent(bool is_incognito_process, |
168 int manifest_version) { | 157 int manifest_version) { |
169 v8::HandleScope handle_scope; | 158 v8::HandleScope handle_scope; |
170 v8::Handle<v8::Value> argv[] = { | 159 v8::Handle<v8::Value> argv[] = { |
171 v8::String::New(GetExtensionID().c_str()), | 160 v8::String::New(GetExtensionID().c_str()), |
172 v8::String::New(GetContextTypeDescription(context_type_).c_str()), | 161 v8::String::New(GetContextTypeDescription().c_str()), |
173 v8::Boolean::New(is_incognito_process), | 162 v8::Boolean::New(is_incognito_process), |
174 v8::Integer::New(manifest_version), | 163 v8::Integer::New(manifest_version), |
175 }; | 164 }; |
176 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); | 165 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); |
177 } | 166 } |
178 | 167 |
179 void ChromeV8Context::DispatchOnUnloadEvent() { | 168 void ChromeV8Context::DispatchOnUnloadEvent() { |
180 v8::HandleScope handle_scope; | 169 v8::HandleScope handle_scope; |
181 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); | 170 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); |
182 } | 171 } |
172 | |
173 std::string ChromeV8Context::GetContextTypeDescription() { | |
174 switch (context_type_) { | |
175 case Feature::UNSPECIFIED_CONTEXT: return "UNSPECIFIED"; | |
176 case Feature::BLESSED_EXTENSION_CONTEXT: return "BLESSED_EXTENSION"; | |
177 case Feature::UNBLESSED_EXTENSION_CONTEXT: return "UNBLESSED_EXTENSION"; | |
178 case Feature::CONTENT_SCRIPT_CONTEXT: return "CONTENT_SCRIPT"; | |
179 case Feature::WEB_PAGE_CONTEXT: return "WEB_PAGE"; | |
180 } | |
181 NOTREACHED(); | |
182 return ""; | |
183 } | |
OLD | NEW |