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

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

Issue 10869067: Deliver attach intent to packaged apps (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Allowed file contents to actually be read 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/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"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 224
225 DISALLOW_COPY_AND_ASSIGN(PlatformAppCommandLineLauncher); 225 DISALLOW_COPY_AND_ASSIGN(PlatformAppCommandLineLauncher);
226 }; 226 };
227 227
228 // Class to handle launching of platform apps with WebIntent data that is being 228 // Class to handle launching of platform apps with WebIntent data that is being
229 // passed in a a blob. 229 // passed in a a blob.
230 // An instance of this class is created for each launch. The lifetime of these 230 // 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 231 // 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 232 // has outstanding tasks on a message queue it will be retained; once all
233 // outstanding tasks are completed it will be deleted. 233 // outstanding tasks are completed it will be deleted.
234 class PlatformAppBlobIntentLauncher 234 class PlatformAppGrantIntentLauncher
James Hawkins 2012/08/29 22:46:51 I don't understand the name of this class, specifi
thorogood 2012/08/30 01:36:28 After some discussion here in Sydney, we've change
235 : public base::RefCountedThreadSafe<PlatformAppBlobIntentLauncher> { 235 : public base::RefCountedThreadSafe<PlatformAppGrantIntentLauncher> {
236 public: 236 public:
237 PlatformAppBlobIntentLauncher(Profile* profile, 237 PlatformAppGrantIntentLauncher(Profile* profile,
238 const Extension* extension, 238 const Extension* extension,
239 const webkit_glue::WebIntentData& data) 239 const webkit_glue::WebIntentData& data)
240 : profile_(profile), 240 : profile_(profile),
241 extension_(extension), 241 extension_(extension),
242 data_(data) {} 242 data_(data) {}
243 243
244 void Launch() { 244 void Launch() {
245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
246 246
247 // Access needs to be granted to the file for the process associated with 247 // 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 248 // 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 249 // 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 250 // the lazy background task queue is used to load the extension and then
251 // call back to us. 251 // call back to us.
252 extensions::LazyBackgroundTaskQueue* queue = 252 extensions::LazyBackgroundTaskQueue* queue =
253 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); 253 ExtensionSystem::Get(profile_)->lazy_background_task_queue();
254 if (queue->ShouldEnqueueTask(profile_, extension_)) { 254 if (queue->ShouldEnqueueTask(profile_, extension_)) {
255 queue->AddPendingTask(profile_, extension_->id(), base::Bind( 255 queue->AddPendingTask(profile_, extension_->id(), base::Bind(
256 &PlatformAppBlobIntentLauncher::GrantAccessToFileAndLaunch, 256 &PlatformAppGrantIntentLauncher::GrantAccessToFileAndLaunch,
257 this)); 257 this));
258 return; 258 return;
259 } 259 }
260 260
261 ExtensionProcessManager* process_manager = 261 ExtensionProcessManager* process_manager =
262 ExtensionSystem::Get(profile_)->process_manager(); 262 ExtensionSystem::Get(profile_)->process_manager();
263 extensions::ExtensionHost* host = 263 extensions::ExtensionHost* host =
264 process_manager->GetBackgroundHostForExtension(extension_->id()); 264 process_manager->GetBackgroundHostForExtension(extension_->id());
265 DCHECK(host); 265 DCHECK(host);
266 GrantAccessToFileAndLaunch(host); 266 GrantAccessToFileAndLaunch(host);
267 } 267 }
268 268
269 private: 269 private:
270 friend class base::RefCountedThreadSafe<PlatformAppBlobIntentLauncher>; 270 friend class base::RefCountedThreadSafe<PlatformAppGrantIntentLauncher>;
271 271
272 virtual ~PlatformAppBlobIntentLauncher() {} 272 virtual ~PlatformAppGrantIntentLauncher() {}
273 273
274 void GrantAccessToFileAndLaunch(extensions::ExtensionHost* host) { 274 void GrantAccessToFileAndLaunch(extensions::ExtensionHost* host) {
275 // If there was an error loading the app page, |host| will be NULL. 275 // If there was an error loading the app page, |host| will be NULL.
276 if (!host) { 276 if (!host) {
277 LOG(ERROR) << "Could not load app page for " << extension_->id(); 277 LOG(ERROR) << "Could not load app page for " << extension_->id();
278 return; 278 return;
279 } 279 }
280 280
281 content::ChildProcessSecurityPolicy* policy = 281 content::ChildProcessSecurityPolicy* policy =
282 content::ChildProcessSecurityPolicy::GetInstance(); 282 content::ChildProcessSecurityPolicy::GetInstance();
283 int renderer_id = host->render_process_host()->GetID(); 283 int renderer_id = host->render_process_host()->GetID();
284 284
285 // Granting read file permission to allow reading file content. 285 if (data_.data_type == webkit_glue::WebIntentData::BLOB) {
286 // If the renderer already has permission to read these paths, it is not 286 // Granting read file permission to allow reading file content.
287 // regranted, as this would overwrite any other permissions which the 287 // If the renderer already has permission to read these paths, it is not
288 // renderer may already have. 288 // regranted, as this would overwrite any other permissions which the
289 if (!policy->CanReadFile(renderer_id, data_.blob_file)) 289 // renderer may already have.
290 policy->GrantReadFile(renderer_id, data_.blob_file); 290 if (!policy->CanReadFile(renderer_id, data_.blob_file))
291 policy->GrantReadFile(renderer_id, data_.blob_file);
292 } else if (data_.data_type == webkit_glue::WebIntentData::FILESYSTEM) {
293 // Grant read filesystem and read directory permission to allow reading
294 // any part of the specified filesystem.
295 FilePath path;
296 const bool valid =
297 fileapi::IsolatedContext::GetInstance()->GetRegisteredPath(
298 data_.filesystem_id, &path);
299 DCHECK(valid);
300 if (!policy->CanReadFile(renderer_id, path))
301 policy->GrantReadFile(renderer_id, path);
302 policy->GrantReadFileSystem(renderer_id, data_.filesystem_id);
303 } else {
304 NOTREACHED();
305 }
291 306
292 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( 307 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent(
293 profile_, extension_, data_); 308 profile_, extension_, data_);
294 } 309 }
295 310
296 // The profile the app should be run in. 311 // The profile the app should be run in.
297 Profile* profile_; 312 Profile* profile_;
298 // The extension providing the app. 313 // The extension providing the app.
299 const Extension* extension_; 314 const Extension* extension_;
300 // The WebIntent data to be passed through to the app. 315 // The WebIntent data to be passed through to the app.
301 const webkit_glue::WebIntentData data_; 316 const webkit_glue::WebIntentData data_;
302 317
303 DISALLOW_COPY_AND_ASSIGN(PlatformAppBlobIntentLauncher); 318 DISALLOW_COPY_AND_ASSIGN(PlatformAppGrantIntentLauncher);
304 }; 319 };
305 320
306 } // namespace 321 } // namespace
307 322
308 void LaunchPlatformApp(Profile* profile, 323 void LaunchPlatformApp(Profile* profile,
309 const Extension* extension, 324 const Extension* extension,
310 const CommandLine* command_line, 325 const CommandLine* command_line,
311 const FilePath& current_directory) { 326 const FilePath& current_directory) {
312 // launcher will be freed when nothing has a reference to it. The message 327 // launcher will be freed when nothing has a reference to it. The message
313 // queue will retain a reference for any outstanding task, so when the 328 // queue will retain a reference for any outstanding task, so when the
314 // launcher has finished it will be freed. 329 // launcher has finished it will be freed.
315 scoped_refptr<PlatformAppCommandLineLauncher> launcher = 330 scoped_refptr<PlatformAppCommandLineLauncher> launcher =
316 new PlatformAppCommandLineLauncher(profile, extension, command_line, 331 new PlatformAppCommandLineLauncher(profile, extension, command_line,
317 current_directory); 332 current_directory);
318 launcher->Launch(); 333 launcher->Launch();
319 } 334 }
320 335
321 void LaunchPlatformAppWithWebIntent( 336 void LaunchPlatformAppWithWebIntent(
322 Profile* profile, 337 Profile* profile,
323 const Extension* extension, 338 const Extension* extension,
324 const webkit_glue::WebIntentData& web_intent_data) { 339 const webkit_glue::WebIntentData& web_intent_data) {
325 if (web_intent_data.data_type == webkit_glue::WebIntentData::BLOB) { 340 if (web_intent_data.data_type == webkit_glue::WebIntentData::BLOB ||
326 scoped_refptr<PlatformAppBlobIntentLauncher> launcher = 341 web_intent_data.data_type == webkit_glue::WebIntentData::FILESYSTEM) {
327 new PlatformAppBlobIntentLauncher(profile, extension, web_intent_data); 342 scoped_refptr<PlatformAppGrantIntentLauncher> launcher =
343 new PlatformAppGrantIntentLauncher(profile, extension, web_intent_data);
328 launcher->Launch(); 344 launcher->Launch();
329 return; 345 return;
330 } 346 }
331 347
332 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent( 348 extensions::AppEventRouter::DispatchOnLaunchedEventWithWebIntent(
333 profile, extension, web_intent_data); 349 profile, extension, web_intent_data);
334 } 350 }
335 351
336 } // namespace extensions 352 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698