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

Side by Side Diff: extensions/renderer/runtime_custom_bindings.cc

Issue 709933002: Add frameId to MessageSender (extension messaging API) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test: sender.tab.status = 'complete' Created 6 years, 1 month 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
« no previous file with comments | « extensions/renderer/resources/messaging.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_frame.h"
10 #include "content/public/renderer/render_view.h" 11 #include "content/public/renderer/render_view.h"
11 #include "content/public/renderer/v8_value_converter.h" 12 #include "content/public/renderer/v8_value_converter.h"
12 #include "extensions/common/extension.h" 13 #include "extensions/common/extension.h"
13 #include "extensions/common/extension_messages.h" 14 #include "extensions/common/extension_messages.h"
14 #include "extensions/common/features/feature.h" 15 #include "extensions/common/features/feature.h"
15 #include "extensions/common/features/feature_provider.h" 16 #include "extensions/common/features/feature_provider.h"
16 #include "extensions/common/manifest.h" 17 #include "extensions/common/manifest.h"
17 #include "extensions/renderer/api_activity_logger.h" 18 #include "extensions/renderer/api_activity_logger.h"
18 #include "extensions/renderer/extension_helper.h" 19 #include "extensions/renderer/extension_helper.h"
19 #include "extensions/renderer/script_context.h" 20 #include "extensions/renderer/script_context.h"
(...skipping 19 matching lines...) Expand all
39 RouteFunction("GetExtensionViews", 40 RouteFunction("GetExtensionViews",
40 base::Bind(&RuntimeCustomBindings::GetExtensionViews, 41 base::Bind(&RuntimeCustomBindings::GetExtensionViews,
41 base::Unretained(this))); 42 base::Unretained(this)));
42 } 43 }
43 44
44 RuntimeCustomBindings::~RuntimeCustomBindings() { 45 RuntimeCustomBindings::~RuntimeCustomBindings() {
45 } 46 }
46 47
47 void RuntimeCustomBindings::OpenChannelToExtension( 48 void RuntimeCustomBindings::OpenChannelToExtension(
48 const v8::FunctionCallbackInfo<v8::Value>& args) { 49 const v8::FunctionCallbackInfo<v8::Value>& args) {
49 // Get the current RenderView so that we can send a routed IPC message from 50 // Get the current RenderFrame so that we can send a routed IPC message from
50 // the correct source. 51 // the correct source.
51 content::RenderView* renderview = context()->GetRenderView(); 52 content::RenderFrame* renderframe = context()->GetRenderFrame();
52 if (!renderview) 53 if (!renderframe)
53 return; 54 return;
54 55
55 // The Javascript code should validate/fill the arguments. 56 // The Javascript code should validate/fill the arguments.
56 CHECK_EQ(args.Length(), 3); 57 CHECK_EQ(args.Length(), 3);
57 CHECK(args[0]->IsString() && args[1]->IsString() && args[2]->IsBoolean()); 58 CHECK(args[0]->IsString() && args[1]->IsString() && args[2]->IsBoolean());
58 59
59 ExtensionMsg_ExternalConnectionInfo info; 60 ExtensionMsg_ExternalConnectionInfo info;
60 61
61 // 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
62 // its extension ID. 63 // its extension ID.
63 const Extension* extension = context()->extension(); 64 const Extension* extension = context()->extension();
64 if (extension && !extension->is_hosted_app()) 65 if (extension && !extension->is_hosted_app())
65 info.source_id = extension->id(); 66 info.source_id = extension->id();
66 67
67 info.target_id = *v8::String::Utf8Value(args[0]->ToString()); 68 info.target_id = *v8::String::Utf8Value(args[0]->ToString());
68 info.source_url = context()->GetURL(); 69 info.source_url = context()->GetURL();
69 std::string channel_name = *v8::String::Utf8Value(args[1]->ToString()); 70 std::string channel_name = *v8::String::Utf8Value(args[1]->ToString());
70 bool include_tls_channel_id = 71 bool include_tls_channel_id =
71 args.Length() > 2 ? args[2]->BooleanValue() : false; 72 args.Length() > 2 ? args[2]->BooleanValue() : false;
72 int port_id = -1; 73 int port_id = -1;
73 renderview->Send( 74 renderframe->Send(new ExtensionHostMsg_OpenChannelToExtension(
74 new ExtensionHostMsg_OpenChannelToExtension(renderview->GetRoutingID(), 75 renderframe->GetRoutingID(), info, channel_name, include_tls_channel_id,
75 info, 76 &port_id));
76 channel_name,
77 include_tls_channel_id,
78 &port_id));
79 args.GetReturnValue().Set(static_cast<int32_t>(port_id)); 77 args.GetReturnValue().Set(static_cast<int32_t>(port_id));
80 } 78 }
81 79
82 void RuntimeCustomBindings::OpenChannelToNativeApp( 80 void RuntimeCustomBindings::OpenChannelToNativeApp(
83 const v8::FunctionCallbackInfo<v8::Value>& args) { 81 const v8::FunctionCallbackInfo<v8::Value>& args) {
84 // Verify that the extension has permission to use native messaging. 82 // Verify that the extension has permission to use native messaging.
85 Feature::Availability availability = 83 Feature::Availability availability =
86 FeatureProvider::GetPermissionFeatures() 84 FeatureProvider::GetPermissionFeatures()
87 ->GetFeature("nativeMessaging") 85 ->GetFeature("nativeMessaging")
88 ->IsAvailableToContext(context()->extension(), 86 ->IsAvailableToContext(context()->extension(),
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 v8::Local<v8::Value> window = context->Global(); 168 v8::Local<v8::Value> window = context->Global();
171 DCHECK(!window.IsEmpty()); 169 DCHECK(!window.IsEmpty());
172 v8_views->Set(v8::Integer::New(args.GetIsolate(), v8_index++), window); 170 v8_views->Set(v8::Integer::New(args.GetIsolate(), v8_index++), window);
173 } 171 }
174 } 172 }
175 173
176 args.GetReturnValue().Set(v8_views); 174 args.GetReturnValue().Set(v8_views);
177 } 175 }
178 176
179 } // namespace extensions 177 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/resources/messaging.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698