OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/runtime_custom_bindings.h" | 5 #include "extensions/renderer/runtime_custom_bindings.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "content/public/child/v8_value_converter.h" | 10 #include "content/public/child/v8_value_converter.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // For messaging APIs, hosted apps should be considered a web page so hide | 62 // For messaging APIs, hosted apps should be considered a web page so hide |
63 // its extension ID. | 63 // its extension ID. |
64 const Extension* extension = context()->extension(); | 64 const Extension* extension = context()->extension(); |
65 if (extension && !extension->is_hosted_app()) | 65 if (extension && !extension->is_hosted_app()) |
66 info.source_id = extension->id(); | 66 info.source_id = extension->id(); |
67 | 67 |
68 info.target_id = *v8::String::Utf8Value(args[0]); | 68 info.target_id = *v8::String::Utf8Value(args[0]); |
69 info.source_url = context()->GetURL(); | 69 info.source_url = context()->GetURL(); |
70 std::string channel_name = *v8::String::Utf8Value(args[1]); | 70 std::string channel_name = *v8::String::Utf8Value(args[1]); |
71 bool include_tls_channel_id = | 71 bool include_tls_channel_id = |
72 args.Length() > 2 ? args[2]->BooleanValue() : false; | 72 args.Length() > 2 ? args[2].As<v8::Boolean>()->Value() : false; |
73 int port_id = -1; | 73 int port_id = -1; |
74 renderframe->Send(new ExtensionHostMsg_OpenChannelToExtension( | 74 renderframe->Send(new ExtensionHostMsg_OpenChannelToExtension( |
75 renderframe->GetRoutingID(), info, channel_name, include_tls_channel_id, | 75 renderframe->GetRoutingID(), info, channel_name, include_tls_channel_id, |
76 &port_id)); | 76 &port_id)); |
77 args.GetReturnValue().Set(static_cast<int32_t>(port_id)); | 77 args.GetReturnValue().Set(static_cast<int32_t>(port_id)); |
78 } | 78 } |
79 | 79 |
80 void RuntimeCustomBindings::OpenChannelToNativeApp( | 80 void RuntimeCustomBindings::OpenChannelToNativeApp( |
81 const v8::FunctionCallbackInfo<v8::Value>& args) { | 81 const v8::FunctionCallbackInfo<v8::Value>& args) { |
82 // Verify that the extension has permission to use native messaging. | 82 // Verify that the extension has permission to use native messaging. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 void RuntimeCustomBindings::GetExtensionViews( | 119 void RuntimeCustomBindings::GetExtensionViews( |
120 const v8::FunctionCallbackInfo<v8::Value>& args) { | 120 const v8::FunctionCallbackInfo<v8::Value>& args) { |
121 if (args.Length() != 2) | 121 if (args.Length() != 2) |
122 return; | 122 return; |
123 | 123 |
124 if (!args[0]->IsInt32() || !args[1]->IsString()) | 124 if (!args[0]->IsInt32() || !args[1]->IsString()) |
125 return; | 125 return; |
126 | 126 |
127 // |browser_window_id| == extension_misc::kUnknownWindowId means getting | 127 // |browser_window_id| == extension_misc::kUnknownWindowId means getting |
128 // all views for the current extension. | 128 // all views for the current extension. |
129 int browser_window_id = args[0]->Int32Value(); | 129 int browser_window_id = args[0].As<v8::Int32>()->Value(); |
130 | 130 |
131 std::string view_type_string = *v8::String::Utf8Value(args[1]); | 131 std::string view_type_string = *v8::String::Utf8Value(args[1]); |
132 StringToUpperASCII(&view_type_string); | 132 StringToUpperASCII(&view_type_string); |
133 // |view_type| == VIEW_TYPE_INVALID means getting any type of | 133 // |view_type| == VIEW_TYPE_INVALID means getting any type of |
134 // views. | 134 // views. |
135 ViewType view_type = VIEW_TYPE_INVALID; | 135 ViewType view_type = VIEW_TYPE_INVALID; |
136 if (view_type_string == kViewTypeBackgroundPage) { | 136 if (view_type_string == kViewTypeBackgroundPage) { |
137 view_type = VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; | 137 view_type = VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; |
138 } else if (view_type_string == kViewTypeTabContents) { | 138 } else if (view_type_string == kViewTypeTabContents) { |
139 view_type = VIEW_TYPE_TAB_CONTENTS; | 139 view_type = VIEW_TYPE_TAB_CONTENTS; |
(...skipping 18 matching lines...) Expand all Loading... |
158 std::vector<content::RenderView*> views = ExtensionHelper::GetExtensionViews( | 158 std::vector<content::RenderView*> views = ExtensionHelper::GetExtensionViews( |
159 extension_id, browser_window_id, view_type); | 159 extension_id, browser_window_id, view_type); |
160 v8::Local<v8::Array> v8_views = v8::Array::New(args.GetIsolate()); | 160 v8::Local<v8::Array> v8_views = v8::Array::New(args.GetIsolate()); |
161 int v8_index = 0; | 161 int v8_index = 0; |
162 for (size_t i = 0; i < views.size(); ++i) { | 162 for (size_t i = 0; i < views.size(); ++i) { |
163 v8::Local<v8::Context> context = | 163 v8::Local<v8::Context> context = |
164 views[i]->GetWebView()->mainFrame()->mainWorldScriptContext(); | 164 views[i]->GetWebView()->mainFrame()->mainWorldScriptContext(); |
165 if (!context.IsEmpty()) { | 165 if (!context.IsEmpty()) { |
166 v8::Local<v8::Value> window = context->Global(); | 166 v8::Local<v8::Value> window = context->Global(); |
167 DCHECK(!window.IsEmpty()); | 167 DCHECK(!window.IsEmpty()); |
168 v8_views->Set(v8::Integer::New(args.GetIsolate(), v8_index++), window); | 168 auto maybe = v8_views->Set( |
| 169 context, v8::Integer::New(args.GetIsolate(), v8_index++), window); |
| 170 if (maybe.IsNothing() || !maybe.FromJust()) |
| 171 return; |
169 } | 172 } |
170 } | 173 } |
171 | 174 |
172 args.GetReturnValue().Set(v8_views); | 175 args.GetReturnValue().Set(v8_views); |
173 } | 176 } |
174 | 177 |
175 } // namespace extensions | 178 } // namespace extensions |
OLD | NEW |