| 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/extension_custom_bindings.h" | 5 #include "chrome/renderer/extensions/extension_custom_bindings.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
| 11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 12 #include "chrome/common/view_type.h" | 12 #include "chrome/common/view_type.h" |
| 13 #include "chrome/renderer/extensions/dispatcher.h" | 13 #include "chrome/renderer/extensions/dispatcher.h" |
| 14 #include "chrome/renderer/extensions/extension_helper.h" | 14 #include "chrome/renderer/extensions/extension_helper.h" |
| 15 #include "content/public/renderer/render_view.h" | 15 #include "content/public/renderer/render_view.h" |
| 16 #include "content/public/renderer/v8_value_converter.h" | 16 #include "content/public/renderer/v8_value_converter.h" |
| 17 #include "grit/renderer_resources.h" | 17 #include "grit/renderer_resources.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 20 #include "webkit/glue/webkit_glue.h" | 20 #include "webkit/glue/webkit_glue.h" |
| 21 #include "v8/include/v8.h" | 21 #include "v8/include/v8.h" |
| 22 | 22 |
| 23 namespace extensions { | 23 namespace extensions { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 } // namespace | 27 } // namespace |
| 28 | 28 |
| 29 ExtensionCustomBindings::ExtensionCustomBindings(Dispatcher* dispatcher) | 29 ExtensionCustomBindings::ExtensionCustomBindings( |
| 30 : ChromeV8Extension(dispatcher) { | 30 Dispatcher* dispatcher, |
| 31 v8::Handle<v8::Context> context) |
| 32 : ChromeV8Extension(dispatcher, context) { |
| 31 RouteStaticFunction("GetExtensionViews", &GetExtensionViews); | 33 RouteStaticFunction("GetExtensionViews", &GetExtensionViews); |
| 32 } | 34 } |
| 33 | 35 |
| 34 // static | 36 // static |
| 35 v8::Handle<v8::Value> ExtensionCustomBindings::GetExtensionViews( | 37 v8::Handle<v8::Value> ExtensionCustomBindings::GetExtensionViews( |
| 36 const v8::Arguments& args) { | 38 const v8::Arguments& args) { |
| 37 if (args.Length() != 2) | 39 if (args.Length() != 2) |
| 38 return v8::Undefined(); | 40 return v8::Undefined(); |
| 39 | 41 |
| 40 if (!args[0]->IsInt32() || !args[1]->IsString()) | 42 if (!args[0]->IsInt32() || !args[1]->IsString()) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 65 view_type = chrome::VIEW_TYPE_APP_SHELL; | 67 view_type = chrome::VIEW_TYPE_APP_SHELL; |
| 66 } else if (view_type_string == chrome::kViewTypePanel) { | 68 } else if (view_type_string == chrome::kViewTypePanel) { |
| 67 view_type = chrome::VIEW_TYPE_PANEL; | 69 view_type = chrome::VIEW_TYPE_PANEL; |
| 68 } else if (view_type_string != chrome::kViewTypeAll) { | 70 } else if (view_type_string != chrome::kViewTypeAll) { |
| 69 return v8::Undefined(); | 71 return v8::Undefined(); |
| 70 } | 72 } |
| 71 | 73 |
| 72 ExtensionCustomBindings* v8_extension = | 74 ExtensionCustomBindings* v8_extension = |
| 73 GetFromArguments<ExtensionCustomBindings>(args); | 75 GetFromArguments<ExtensionCustomBindings>(args); |
| 74 const Extension* extension = | 76 const Extension* extension = |
| 75 v8_extension->GetExtensionForCurrentRenderView(); | 77 v8_extension->GetExtensionForRenderView(); |
| 76 if (!extension) | 78 if (!extension) |
| 77 return v8::Undefined(); | 79 return v8::Undefined(); |
| 78 | 80 |
| 79 std::vector<content::RenderView*> views = ExtensionHelper::GetExtensionViews( | 81 std::vector<content::RenderView*> views = ExtensionHelper::GetExtensionViews( |
| 80 extension->id(), browser_window_id, view_type); | 82 extension->id(), browser_window_id, view_type); |
| 81 v8::Local<v8::Array> v8_views = v8::Array::New(); | 83 v8::Local<v8::Array> v8_views = v8::Array::New(); |
| 82 int v8_index = 0; | 84 int v8_index = 0; |
| 83 for (size_t i = 0; i < views.size(); ++i) { | 85 for (size_t i = 0; i < views.size(); ++i) { |
| 84 v8::Local<v8::Context> context = | 86 v8::Local<v8::Context> context = |
| 85 views[i]->GetWebView()->mainFrame()->mainWorldScriptContext(); | 87 views[i]->GetWebView()->mainFrame()->mainWorldScriptContext(); |
| 86 if (!context.IsEmpty()) { | 88 if (!context.IsEmpty()) { |
| 87 v8::Local<v8::Value> window = context->Global(); | 89 v8::Local<v8::Value> window = context->Global(); |
| 88 DCHECK(!window.IsEmpty()); | 90 DCHECK(!window.IsEmpty()); |
| 89 v8_views->Set(v8::Integer::New(v8_index++), window); | 91 v8_views->Set(v8::Integer::New(v8_index++), window); |
| 90 } | 92 } |
| 91 } | 93 } |
| 92 | 94 |
| 93 return v8_views; | 95 return v8_views; |
| 94 } | 96 } |
| 95 | 97 |
| 96 } // namespace extensions | 98 } // namespace extensions |
| OLD | NEW |