Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: chrome/renderer/extensions/extension_custom_bindings.cc

Issue 12313142: Revert 184837 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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( 29 ExtensionCustomBindings::ExtensionCustomBindings(Dispatcher* dispatcher)
30 Dispatcher* dispatcher, 30 : ChromeV8Extension(dispatcher) {
31 v8::Handle<v8::Context> context)
32 : ChromeV8Extension(dispatcher, context) {
33 RouteStaticFunction("GetExtensionViews", &GetExtensionViews); 31 RouteStaticFunction("GetExtensionViews", &GetExtensionViews);
34 } 32 }
35 33
36 // static 34 // static
37 v8::Handle<v8::Value> ExtensionCustomBindings::GetExtensionViews( 35 v8::Handle<v8::Value> ExtensionCustomBindings::GetExtensionViews(
38 const v8::Arguments& args) { 36 const v8::Arguments& args) {
39 if (args.Length() != 2) 37 if (args.Length() != 2)
40 return v8::Undefined(); 38 return v8::Undefined();
41 39
42 if (!args[0]->IsInt32() || !args[1]->IsString()) 40 if (!args[0]->IsInt32() || !args[1]->IsString())
(...skipping 24 matching lines...) Expand all
67 view_type = chrome::VIEW_TYPE_APP_SHELL; 65 view_type = chrome::VIEW_TYPE_APP_SHELL;
68 } else if (view_type_string == chrome::kViewTypePanel) { 66 } else if (view_type_string == chrome::kViewTypePanel) {
69 view_type = chrome::VIEW_TYPE_PANEL; 67 view_type = chrome::VIEW_TYPE_PANEL;
70 } else if (view_type_string != chrome::kViewTypeAll) { 68 } else if (view_type_string != chrome::kViewTypeAll) {
71 return v8::Undefined(); 69 return v8::Undefined();
72 } 70 }
73 71
74 ExtensionCustomBindings* v8_extension = 72 ExtensionCustomBindings* v8_extension =
75 GetFromArguments<ExtensionCustomBindings>(args); 73 GetFromArguments<ExtensionCustomBindings>(args);
76 const Extension* extension = 74 const Extension* extension =
77 v8_extension->GetExtensionForRenderView(); 75 v8_extension->GetExtensionForCurrentRenderView();
78 if (!extension) 76 if (!extension)
79 return v8::Undefined(); 77 return v8::Undefined();
80 78
81 std::vector<content::RenderView*> views = ExtensionHelper::GetExtensionViews( 79 std::vector<content::RenderView*> views = ExtensionHelper::GetExtensionViews(
82 extension->id(), browser_window_id, view_type); 80 extension->id(), browser_window_id, view_type);
83 v8::Local<v8::Array> v8_views = v8::Array::New(); 81 v8::Local<v8::Array> v8_views = v8::Array::New();
84 int v8_index = 0; 82 int v8_index = 0;
85 for (size_t i = 0; i < views.size(); ++i) { 83 for (size_t i = 0; i < views.size(); ++i) {
86 v8::Local<v8::Context> context = 84 v8::Local<v8::Context> context =
87 views[i]->GetWebView()->mainFrame()->mainWorldScriptContext(); 85 views[i]->GetWebView()->mainFrame()->mainWorldScriptContext();
88 if (!context.IsEmpty()) { 86 if (!context.IsEmpty()) {
89 v8::Local<v8::Value> window = context->Global(); 87 v8::Local<v8::Value> window = context->Global();
90 DCHECK(!window.IsEmpty()); 88 DCHECK(!window.IsEmpty());
91 v8_views->Set(v8::Integer::New(v8_index++), window); 89 v8_views->Set(v8::Integer::New(v8_index++), window);
92 } 90 }
93 } 91 }
94 92
95 return v8_views; 93 return v8_views;
96 } 94 }
97 95
98 } // namespace extensions 96 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/extension_custom_bindings.h ('k') | chrome/renderer/extensions/extension_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698