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

Side by Side Diff: chrome/browser/extensions/platform_app_launcher.cc

Issue 10828172: Allow platform apps to respond to Web Intents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: comments Created 8 years, 4 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/platform_app_launcher.h" 5 #include "chrome/browser/extensions/platform_app_launcher.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/extensions/api/app/app_api.h" 14 #include "chrome/browser/extensions/api/app/app_api.h"
15 #include "chrome/browser/extensions/extension_host.h" 15 #include "chrome/browser/extensions/extension_host.h"
16 #include "chrome/browser/extensions/extension_process_manager.h" 16 #include "chrome/browser/extensions/extension_process_manager.h"
17 #include "chrome/browser/extensions/extension_system.h" 17 #include "chrome/browser/extensions/extension_system.h"
18 #include "chrome/browser/extensions/lazy_background_task_queue.h" 18 #include "chrome/browser/extensions/lazy_background_task_queue.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/extensions/extension.h" 20 #include "chrome/common/extensions/extension.h"
21 #include "chrome/common/extensions/extension_messages.h" 21 #include "chrome/common/extensions/extension_messages.h"
22 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/child_process_security_policy.h" 23 #include "content/public/browser/child_process_security_policy.h"
24 #include "content/public/browser/render_process_host.h" 24 #include "content/public/browser/render_process_host.h"
25 #include "content/public/browser/web_intents_dispatcher.h"
25 #include "net/base/mime_util.h" 26 #include "net/base/mime_util.h"
26 #include "net/base/net_util.h" 27 #include "net/base/net_util.h"
27 #include "webkit/fileapi/file_system_types.h" 28 #include "webkit/fileapi/file_system_types.h"
28 #include "webkit/fileapi/isolated_context.h" 29 #include "webkit/fileapi/isolated_context.h"
29 #include "webkit/glue/web_intent_data.h" 30 #include "webkit/glue/web_intent_data.h"
30 #include "webkit/glue/web_intent_service_data.h" 31 #include "webkit/glue/web_intent_service_data.h"
31 32
32 using content::BrowserThread; 33 using content::BrowserThread;
33 using extensions::Extension; 34 using extensions::Extension;
34 using extensions::ExtensionSystem; 35 using extensions::ExtensionSystem;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 // Class to handle launching of platform apps with WebIntent data that is being 229 // Class to handle launching of platform apps with WebIntent data that is being
229 // passed in a a blob. 230 // passed in a a blob.
230 // An instance of this class is created for each launch. The lifetime of these 231 // An instance of this class is created for each launch. The lifetime of these
231 // instances is managed by reference counted pointers. As long as an instance 232 // instances is managed by reference counted pointers. As long as an instance
232 // has outstanding tasks on a message queue it will be retained; once all 233 // has outstanding tasks on a message queue it will be retained; once all
233 // outstanding tasks are completed it will be deleted. 234 // outstanding tasks are completed it will be deleted.
234 class PlatformAppBlobIntentLauncher 235 class PlatformAppBlobIntentLauncher
235 : public base::RefCountedThreadSafe<PlatformAppBlobIntentLauncher> { 236 : public base::RefCountedThreadSafe<PlatformAppBlobIntentLauncher> {
236 public: 237 public:
237 PlatformAppBlobIntentLauncher(Profile* profile, 238 PlatformAppBlobIntentLauncher(Profile* profile,
238 const Extension* extension, 239 const Extension* extension,
239 const webkit_glue::WebIntentData& data) 240 content::WebIntentsDispatcher* intents_dispatcher)
240 : profile_(profile), 241 : profile_(profile),
241 extension_(extension), 242 extension_(extension),
242 data_(data) {} 243 intents_dispatcher_(intents_dispatcher) {}
243 244
244 void Launch() { 245 void Launch() {
245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
246 247
247 // Access needs to be granted to the file for the process associated with 248 // Access needs to be granted to the file for the process associated with
248 // the extension. To do this the ExtensionHost is needed. This might not be 249 // the extension. To do this the ExtensionHost is needed. This might not be
249 // available, or it might be in the process of being unloaded, in which case 250 // available, or it might be in the process of being unloaded, in which case
250 // the lazy background task queue is used to load the extension and then 251 // the lazy background task queue is used to load the extension and then
251 // call back to us. 252 // call back to us.
252 extensions::LazyBackgroundTaskQueue* queue = 253 extensions::LazyBackgroundTaskQueue* queue =
(...skipping 26 matching lines...) Expand all
279 } 280 }
280 281
281 content::ChildProcessSecurityPolicy* policy = 282 content::ChildProcessSecurityPolicy* policy =
282 content::ChildProcessSecurityPolicy::GetInstance(); 283 content::ChildProcessSecurityPolicy::GetInstance();
283 int renderer_id = host->render_process_host()->GetID(); 284 int renderer_id = host->render_process_host()->GetID();
284 285
285 // Granting read file permission to allow reading file content. 286 // Granting read file permission to allow reading file content.
286 // If the renderer already has permission to read these paths, it is not 287 // If the renderer already has permission to read these paths, it is not
287 // regranted, as this would overwrite any other permissions which the 288 // regranted, as this would overwrite any other permissions which the
288 // renderer may already have. 289 // renderer may already have.
289 if (!policy->CanReadFile(renderer_id, data_.blob_file)) 290 webkit_glue::WebIntentData data = intents_dispatcher_->GetIntent();
290 policy->GrantReadFile(renderer_id, data_.blob_file); 291 if (!policy->CanReadFile(renderer_id, data.blob_file))
292 policy->GrantReadFile(renderer_id, data.blob_file);
291 293
292 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( 294 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent(
293 profile_, extension_, data_); 295 profile_, extension_, intents_dispatcher_);
294 } 296 }
295 297
296 // The profile the app should be run in. 298 // The profile the app should be run in.
297 Profile* profile_; 299 Profile* profile_;
298 // The extension providing the app. 300 // The extension providing the app.
299 const Extension* extension_; 301 const Extension* extension_;
300 // The WebIntent data to be passed through to the app. 302 // The dispatcher so that platform apps can respond to this intent.
301 const webkit_glue::WebIntentData data_; 303 content::WebIntentsDispatcher* intents_dispatcher_;
302 304
303 DISALLOW_COPY_AND_ASSIGN(PlatformAppBlobIntentLauncher); 305 DISALLOW_COPY_AND_ASSIGN(PlatformAppBlobIntentLauncher);
304 }; 306 };
305 307
306 } // namespace 308 } // namespace
307 309
308 namespace extensions { 310 namespace extensions {
309 311
310 void LaunchPlatformApp(Profile* profile, 312 void LaunchPlatformApp(Profile* profile,
311 const Extension* extension, 313 const Extension* extension,
312 const CommandLine* command_line, 314 const CommandLine* command_line,
313 const FilePath& current_directory) { 315 const FilePath& current_directory) {
314 // launcher will be freed when nothing has a reference to it. The message 316 // launcher will be freed when nothing has a reference to it. The message
315 // queue will retain a reference for any outstanding task, so when the 317 // queue will retain a reference for any outstanding task, so when the
316 // launcher has finished it will be freed. 318 // launcher has finished it will be freed.
317 scoped_refptr<PlatformAppCommandLineLauncher> launcher = 319 scoped_refptr<PlatformAppCommandLineLauncher> launcher =
318 new PlatformAppCommandLineLauncher(profile, extension, command_line, 320 new PlatformAppCommandLineLauncher(profile, extension, command_line,
319 current_directory); 321 current_directory);
320 launcher->Launch(); 322 launcher->Launch();
321 } 323 }
322 324
323 void LaunchPlatformAppWithWebIntent( 325 void LaunchPlatformAppWithWebIntent(
324 Profile* profile, 326 Profile* profile,
325 const Extension* extension, 327 const Extension* extension,
326 const webkit_glue::WebIntentData& web_intent_data) { 328 content::WebIntentsDispatcher* intents_dispatcher) {
329 webkit_glue::WebIntentData web_intent_data = intents_dispatcher->GetIntent();
327 if (web_intent_data.data_type == webkit_glue::WebIntentData::BLOB) { 330 if (web_intent_data.data_type == webkit_glue::WebIntentData::BLOB) {
328 scoped_refptr<PlatformAppBlobIntentLauncher> launcher = 331 scoped_refptr<PlatformAppBlobIntentLauncher> launcher =
329 new PlatformAppBlobIntentLauncher(profile, extension, web_intent_data); 332 new PlatformAppBlobIntentLauncher(profile, extension,
333 intents_dispatcher);
330 launcher->Launch(); 334 launcher->Launch();
331 return; 335 return;
332 } 336 }
333 337
334 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( 338 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent(
335 profile, extension, web_intent_data); 339 profile, extension, intents_dispatcher);
336 } 340 }
337 341
338 } // namespace extensions 342 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698