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/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 CHECK(args[0]->IsString() && args[1]->IsString() && args[2]->IsBoolean()); | 57 CHECK(args[0]->IsString() && args[1]->IsString() && args[2]->IsBoolean()); |
58 | 58 |
59 ExtensionMsg_ExternalConnectionInfo info; | 59 ExtensionMsg_ExternalConnectionInfo info; |
60 | 60 |
61 // For messaging APIs, hosted apps should be considered a web page so hide | 61 // For messaging APIs, hosted apps should be considered a web page so hide |
62 // its extension ID. | 62 // its extension ID. |
63 const Extension* extension = context()->extension(); | 63 const Extension* extension = context()->extension(); |
64 if (extension && !extension->is_hosted_app()) | 64 if (extension && !extension->is_hosted_app()) |
65 info.source_id = extension->id(); | 65 info.source_id = extension->id(); |
66 | 66 |
67 info.target_id = *v8::String::Utf8Value(args[0]->ToString()); | 67 info.target_id = *v8::String::Utf8Value(args[0]); |
68 info.source_url = context()->GetURL(); | 68 info.source_url = context()->GetURL(); |
69 std::string channel_name = *v8::String::Utf8Value(args[1]->ToString()); | 69 std::string channel_name = *v8::String::Utf8Value(args[1]); |
70 bool include_tls_channel_id = | 70 bool include_tls_channel_id = |
71 args.Length() > 2 ? args[2]->BooleanValue() : false; | 71 args.Length() > 2 ? args[2]->BooleanValue() : false; |
72 int port_id = -1; | 72 int port_id = -1; |
73 renderview->Send( | 73 renderview->Send( |
74 new ExtensionHostMsg_OpenChannelToExtension(renderview->GetRoutingID(), | 74 new ExtensionHostMsg_OpenChannelToExtension(renderview->GetRoutingID(), |
75 info, | 75 info, |
76 channel_name, | 76 channel_name, |
77 include_tls_channel_id, | 77 include_tls_channel_id, |
78 &port_id)); | 78 &port_id)); |
79 args.GetReturnValue().Set(static_cast<int32_t>(port_id)); | 79 args.GetReturnValue().Set(static_cast<int32_t>(port_id)); |
(...skipping 13 matching lines...) Expand all Loading... |
93 | 93 |
94 // Get the current RenderView so that we can send a routed IPC message from | 94 // Get the current RenderView so that we can send a routed IPC message from |
95 // the correct source. | 95 // the correct source. |
96 content::RenderView* renderview = context()->GetRenderView(); | 96 content::RenderView* renderview = context()->GetRenderView(); |
97 if (!renderview) | 97 if (!renderview) |
98 return; | 98 return; |
99 | 99 |
100 // The Javascript code should validate/fill the arguments. | 100 // The Javascript code should validate/fill the arguments. |
101 CHECK(args.Length() >= 2 && args[0]->IsString() && args[1]->IsString()); | 101 CHECK(args.Length() >= 2 && args[0]->IsString() && args[1]->IsString()); |
102 | 102 |
103 std::string extension_id = *v8::String::Utf8Value(args[0]->ToString()); | 103 std::string extension_id = *v8::String::Utf8Value(args[0]); |
104 std::string native_app_name = *v8::String::Utf8Value(args[1]->ToString()); | 104 std::string native_app_name = *v8::String::Utf8Value(args[1]); |
105 | 105 |
106 int port_id = -1; | 106 int port_id = -1; |
107 renderview->Send(new ExtensionHostMsg_OpenChannelToNativeApp( | 107 renderview->Send(new ExtensionHostMsg_OpenChannelToNativeApp( |
108 renderview->GetRoutingID(), extension_id, native_app_name, &port_id)); | 108 renderview->GetRoutingID(), extension_id, native_app_name, &port_id)); |
109 args.GetReturnValue().Set(static_cast<int32_t>(port_id)); | 109 args.GetReturnValue().Set(static_cast<int32_t>(port_id)); |
110 } | 110 } |
111 | 111 |
112 void RuntimeCustomBindings::GetManifest( | 112 void RuntimeCustomBindings::GetManifest( |
113 const v8::FunctionCallbackInfo<v8::Value>& args) { | 113 const v8::FunctionCallbackInfo<v8::Value>& args) { |
114 CHECK(context()->extension()); | 114 CHECK(context()->extension()); |
115 | 115 |
116 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 116 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
117 args.GetReturnValue().Set(converter->ToV8Value( | 117 args.GetReturnValue().Set(converter->ToV8Value( |
118 context()->extension()->manifest()->value(), context()->v8_context())); | 118 context()->extension()->manifest()->value(), context()->v8_context())); |
119 } | 119 } |
120 | 120 |
121 void RuntimeCustomBindings::GetExtensionViews( | 121 void RuntimeCustomBindings::GetExtensionViews( |
122 const v8::FunctionCallbackInfo<v8::Value>& args) { | 122 const v8::FunctionCallbackInfo<v8::Value>& args) { |
123 if (args.Length() != 2) | 123 if (args.Length() != 2) |
124 return; | 124 return; |
125 | 125 |
126 if (!args[0]->IsInt32() || !args[1]->IsString()) | 126 if (!args[0]->IsInt32() || !args[1]->IsString()) |
127 return; | 127 return; |
128 | 128 |
129 // |browser_window_id| == extension_misc::kUnknownWindowId means getting | 129 // |browser_window_id| == extension_misc::kUnknownWindowId means getting |
130 // all views for the current extension. | 130 // all views for the current extension. |
131 int browser_window_id = args[0]->Int32Value(); | 131 int browser_window_id = args[0]->Int32Value(); |
132 | 132 |
133 std::string view_type_string = *v8::String::Utf8Value(args[1]->ToString()); | 133 std::string view_type_string = *v8::String::Utf8Value(args[1]); |
134 StringToUpperASCII(&view_type_string); | 134 StringToUpperASCII(&view_type_string); |
135 // |view_type| == VIEW_TYPE_INVALID means getting any type of | 135 // |view_type| == VIEW_TYPE_INVALID means getting any type of |
136 // views. | 136 // views. |
137 ViewType view_type = VIEW_TYPE_INVALID; | 137 ViewType view_type = VIEW_TYPE_INVALID; |
138 if (view_type_string == kViewTypeBackgroundPage) { | 138 if (view_type_string == kViewTypeBackgroundPage) { |
139 view_type = VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; | 139 view_type = VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; |
140 } else if (view_type_string == kViewTypeInfobar) { | 140 } else if (view_type_string == kViewTypeInfobar) { |
141 view_type = VIEW_TYPE_EXTENSION_INFOBAR; | 141 view_type = VIEW_TYPE_EXTENSION_INFOBAR; |
142 } else if (view_type_string == kViewTypeTabContents) { | 142 } else if (view_type_string == kViewTypeTabContents) { |
143 view_type = VIEW_TYPE_TAB_CONTENTS; | 143 view_type = VIEW_TYPE_TAB_CONTENTS; |
(...skipping 26 matching lines...) Expand all Loading... |
170 v8::Local<v8::Value> window = context->Global(); | 170 v8::Local<v8::Value> window = context->Global(); |
171 DCHECK(!window.IsEmpty()); | 171 DCHECK(!window.IsEmpty()); |
172 v8_views->Set(v8::Integer::New(args.GetIsolate(), v8_index++), window); | 172 v8_views->Set(v8::Integer::New(args.GetIsolate(), v8_index++), window); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 args.GetReturnValue().Set(v8_views); | 176 args.GetReturnValue().Set(v8_views); |
177 } | 177 } |
178 | 178 |
179 } // namespace extensions | 179 } // namespace extensions |
OLD | NEW |