| 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 using extensions::Feature; |
| 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 const char kChromeHidden[] = "chromeHidden"; | 22 const char kChromeHidden[] = "chromeHidden"; |
| 21 | 23 |
| 22 #ifndef NDEBUG | 24 #ifndef NDEBUG |
| 23 const char kValidateCallbacks[] = "validateCallbacks"; | 25 const char kValidateCallbacks[] = "validateCallbacks"; |
| 24 const char kValidateAPI[] = "validateAPI"; | 26 const char kValidateAPI[] = "validateAPI"; |
| 25 #endif | 27 #endif |
| 26 | 28 |
| 27 std::string GetContextTypeDescription( | 29 std::string GetContextTypeDescription(Feature::Context context_type) { |
| 28 ChromeV8Context::ContextType context_type) { | |
| 29 switch (context_type) { | 30 switch (context_type) { |
| 30 case ChromeV8Context::OTHER: return "other"; | 31 case Feature::UNSPECIFIED_CONTEXT: return "unspecified"; |
| 31 case ChromeV8Context::CONTENT_SCRIPT: return "content script"; | 32 case Feature::PRIVILEGED_CONTEXT: return "privileged"; |
| 33 case Feature::UNPRIVILEGED_CONTEXT: return "unprivileged"; |
| 34 case Feature::CONTENT_SCRIPT_CONTEXT: return "content script"; |
| 35 case Feature::WEB_PAGE_CONTEXT: return "web page"; |
| 32 } | 36 } |
| 33 NOTREACHED(); | 37 NOTREACHED(); |
| 34 return ""; | 38 return ""; |
| 35 } | 39 } |
| 36 | 40 |
| 37 } // namespace | 41 } // namespace |
| 38 | 42 |
| 39 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, | 43 ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context, |
| 40 WebKit::WebFrame* web_frame, | 44 WebKit::WebFrame* web_frame, |
| 41 const std::string& extension_id, | 45 const std::string& extension_id, |
| 42 ChromeV8Context::ContextType context_type) | 46 Feature::Context context_type) |
| 43 : v8_context_(v8::Persistent<v8::Context>::New(v8_context)), | 47 : v8_context_(v8::Persistent<v8::Context>::New(v8_context)), |
| 44 web_frame_(web_frame), | 48 web_frame_(web_frame), |
| 45 extension_id_(extension_id), | 49 extension_id_(extension_id), |
| 46 context_type_(context_type) { | 50 context_type_(context_type) { |
| 47 VLOG(1) << "Created context for extension\n" | 51 VLOG(1) << "Created context for extension\n" |
| 48 << " id: " << extension_id << "\n" | 52 << " id: " << extension_id << "\n" |
| 49 << " frame: " << web_frame_ << "\n" | 53 << " frame: " << web_frame_ << "\n" |
| 50 << " context type: " << GetContextTypeDescription(context_type); | 54 << " context type: " << GetContextTypeDescription(context_type); |
| 51 } | 55 } |
| 52 | 56 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 argv[1] = v8::Boolean::New(is_extension_process); | 144 argv[1] = v8::Boolean::New(is_extension_process); |
| 141 argv[2] = v8::Boolean::New(is_incognito_process); | 145 argv[2] = v8::Boolean::New(is_incognito_process); |
| 142 argv[3] = v8::Integer::New(manifest_version); | 146 argv[3] = v8::Integer::New(manifest_version); |
| 143 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); | 147 CallChromeHiddenMethod("dispatchOnLoad", arraysize(argv), argv, NULL); |
| 144 } | 148 } |
| 145 | 149 |
| 146 void ChromeV8Context::DispatchOnUnloadEvent() const { | 150 void ChromeV8Context::DispatchOnUnloadEvent() const { |
| 147 v8::HandleScope handle_scope; | 151 v8::HandleScope handle_scope; |
| 148 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); | 152 CallChromeHiddenMethod("dispatchOnUnload", 0, NULL, NULL); |
| 149 } | 153 } |
| OLD | NEW |