OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/bindings_utils.h" | 5 #include "chrome/renderer/extensions/bindings_utils.h" |
6 | 6 |
| 7 #include "base/string_split.h" |
7 #include "base/string_util.h" | 8 #include "base/string_util.h" |
8 #include "chrome/renderer/render_view.h" | 9 #include "chrome/renderer/render_view.h" |
9 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
10 | 11 |
11 using WebKit::WebFrame; | 12 using WebKit::WebFrame; |
12 using WebKit::WebView; | 13 using WebKit::WebView; |
13 | 14 |
14 namespace bindings_utils { | 15 namespace bindings_utils { |
15 | 16 |
16 const char* kChromeHidden = "chromeHidden"; | 17 const char* kChromeHidden = "chromeHidden"; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 v8::Handle<v8::Value> CallFunctionInContext(v8::Handle<v8::Context> context, | 121 v8::Handle<v8::Value> CallFunctionInContext(v8::Handle<v8::Context> context, |
121 const std::string& function_name, int argc, | 122 const std::string& function_name, int argc, |
122 v8::Handle<v8::Value>* argv) { | 123 v8::Handle<v8::Value>* argv) { |
123 v8::Context::Scope context_scope(context); | 124 v8::Context::Scope context_scope(context); |
124 | 125 |
125 // Look up the function name, which may be a sub-property like | 126 // Look up the function name, which may be a sub-property like |
126 // "Port.dispatchOnMessage" in the hidden global variable. | 127 // "Port.dispatchOnMessage" in the hidden global variable. |
127 v8::Local<v8::Value> value = | 128 v8::Local<v8::Value> value = |
128 context->Global()->GetHiddenValue(v8::String::New(kChromeHidden)); | 129 context->Global()->GetHiddenValue(v8::String::New(kChromeHidden)); |
129 std::vector<std::string> components; | 130 std::vector<std::string> components; |
130 SplitStringDontTrim(function_name, '.', &components); | 131 base::SplitStringDontTrim(function_name, '.', &components); |
131 for (size_t i = 0; i < components.size(); ++i) { | 132 for (size_t i = 0; i < components.size(); ++i) { |
132 if (!value.IsEmpty() && value->IsObject()) | 133 if (!value.IsEmpty() && value->IsObject()) |
133 value = value->ToObject()->Get(v8::String::New(components[i].c_str())); | 134 value = value->ToObject()->Get(v8::String::New(components[i].c_str())); |
134 } | 135 } |
135 if (value.IsEmpty() || !value->IsFunction()) { | 136 if (value.IsEmpty() || !value->IsFunction()) { |
136 NOTREACHED(); | 137 NOTREACHED(); |
137 return v8::Undefined(); | 138 return v8::Undefined(); |
138 } | 139 } |
139 | 140 |
140 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); | 141 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); |
141 if (!function.IsEmpty()) | 142 if (!function.IsEmpty()) |
142 return function->Call(v8::Object::New(), argc, argv); | 143 return function->Call(v8::Object::New(), argc, argv); |
143 | 144 |
144 return v8::Undefined(); | 145 return v8::Undefined(); |
145 } | 146 } |
146 | 147 |
147 } // namespace bindings_utils | 148 } // namespace bindings_utils |
OLD | NEW |