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

Side by Side Diff: chrome/browser/extensions/api/messaging/message_service.cc

Issue 10829186: Tabs API is usable without tabs permission. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: ETU now SetString()'s for empty values Created 8 years, 3 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
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/browser/extensions/api/messaging/message_service.h" 5 #include "chrome/browser/extensions/api/messaging/message_service.h"
6 6
7 #include "base/atomic_sequence_num.h" 7 #include "base/atomic_sequence_num.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 // which depends on whether the extension uses spanning or split mode. 212 // which depends on whether the extension uses spanning or split mode.
213 MessagePort receiver(GetExtensionProcess(profile, target_extension_id), 213 MessagePort receiver(GetExtensionProcess(profile, target_extension_id),
214 MSG_ROUTING_CONTROL, 214 MSG_ROUTING_CONTROL,
215 target_extension_id); 215 target_extension_id);
216 WebContents* source_contents = tab_util::GetWebContentsByID( 216 WebContents* source_contents = tab_util::GetWebContentsByID(
217 source_process_id, source_routing_id); 217 source_process_id, source_routing_id);
218 218
219 // Include info about the opener's tab (if it was a tab). 219 // Include info about the opener's tab (if it was a tab).
220 std::string tab_json = "null"; 220 std::string tab_json = "null";
221 if (source_contents) { 221 if (source_contents) {
222 scoped_ptr<DictionaryValue> tab_value( 222 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue(
223 ExtensionTabUtil::CreateTabValue(source_contents)); 223 source_contents,
224 profile->GetExtensionService()->extensions()->GetByID(
225 source_extension_id)));
224 base::JSONWriter::Write(tab_value.get(), &tab_json); 226 base::JSONWriter::Write(tab_value.get(), &tab_json);
225 } 227 }
226 228
227 OpenChannelParams params(source, tab_json, receiver, receiver_port_id, 229 OpenChannelParams params(source, tab_json, receiver, receiver_port_id,
228 source_extension_id, target_extension_id, 230 source_extension_id, target_extension_id,
229 channel_name); 231 channel_name);
230 232
231 // The target might be a lazy background page. In that case, we have to check 233 // The target might be a lazy background page. In that case, we have to check
232 // if it is loaded and ready, and if not, queue up the task and load the 234 // if it is loaded and ready, and if not, queue up the task and load the
233 // page. 235 // page.
(...skipping 30 matching lines...) Expand all
264 GET_OPPOSITE_PORT_ID(receiver_port_id), true); 266 GET_OPPOSITE_PORT_ID(receiver_port_id), true);
265 return; 267 return;
266 } 268 }
267 269
268 WebContents* source_contents = tab_util::GetWebContentsByID( 270 WebContents* source_contents = tab_util::GetWebContentsByID(
269 source_process_id, source_routing_id); 271 source_process_id, source_routing_id);
270 272
271 // Include info about the opener's tab (if it was a tab). 273 // Include info about the opener's tab (if it was a tab).
272 std::string tab_json = "null"; 274 std::string tab_json = "null";
273 if (source_contents) { 275 if (source_contents) {
274 scoped_ptr<DictionaryValue> tab_value( 276 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue(
275 ExtensionTabUtil::CreateTabValue(source_contents)); 277 source_contents,
278 profile->GetExtensionService()->extensions()->GetByID(
279 extension_id)));
276 base::JSONWriter::Write(tab_value.get(), &tab_json); 280 base::JSONWriter::Write(tab_value.get(), &tab_json);
277 } 281 }
278 282
279 OpenChannelParams params(source, tab_json, receiver, receiver_port_id, 283 OpenChannelParams params(source, tab_json, receiver, receiver_port_id,
280 extension_id, extension_id, channel_name); 284 extension_id, extension_id, channel_name);
281 OpenChannelImpl(params); 285 OpenChannelImpl(params);
282 } 286 }
283 287
284 bool MessageService::OpenChannelImpl(const OpenChannelParams& params) { 288 bool MessageService::OpenChannelImpl(const OpenChannelParams& params) {
285 if (!params.source) 289 if (!params.source)
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 if (!params.source) 466 if (!params.source)
463 return; 467 return;
464 468
465 params.receiver = MessagePort(host->render_process_host(), 469 params.receiver = MessagePort(host->render_process_host(),
466 MSG_ROUTING_CONTROL, 470 MSG_ROUTING_CONTROL,
467 params.target_extension_id); 471 params.target_extension_id);
468 OpenChannelImpl(params); 472 OpenChannelImpl(params);
469 } 473 }
470 474
471 } // namespace extensions 475 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/all_urls_apitest.cc ('k') | chrome/browser/extensions/api/tabs/tabs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698