Index: chrome/browser/extensions/platform_app_launcher.cc |
diff --git a/chrome/browser/extensions/platform_app_launcher.cc b/chrome/browser/extensions/platform_app_launcher.cc |
index 78548d843f1770c1da2402e30cb077b8a1116dac..0119fbdee611ff2094fc5f2a0a5a8ed165e6e322 100644 |
--- a/chrome/browser/extensions/platform_app_launcher.cc |
+++ b/chrome/browser/extensions/platform_app_launcher.cc |
@@ -13,8 +13,11 @@ |
#include "base/utf_string_conversions.h" |
#include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" |
#include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
+#include "chrome/browser/extensions/api/file_system/file_system_api.h" |
#include "chrome/browser/extensions/extension_host.h" |
+#include "chrome/browser/extensions/extension_prefs.h" |
#include "chrome/browser/extensions/extension_process_manager.h" |
+#include "chrome/browser/extensions/extension_service.h" |
#include "chrome/browser/extensions/extension_system.h" |
#include "chrome/browser/extensions/lazy_background_task_queue.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -33,6 +36,9 @@ using content::BrowserThread; |
using extensions::app_file_handler_util::FileHandlerForId; |
using extensions::app_file_handler_util::FileHandlerCanHandleFileWithMimeType; |
using extensions::app_file_handler_util::FirstFileHandlerForMimeType; |
+using extensions::app_file_handler_util::CreateFileEntry; |
+using extensions::app_file_handler_util::GrantedFileEntry; |
+using extensions::app_file_handler_util::SavedFileEntry; |
namespace extensions { |
@@ -239,6 +245,177 @@ class PlatformAppPathLauncher |
DISALLOW_COPY_AND_ASSIGN(PlatformAppPathLauncher); |
}; |
+class SavedFileEntryLauncher |
+ : public base::RefCountedThreadSafe<SavedFileEntryLauncher> { |
+ public: |
+ SavedFileEntryLauncher( |
+ Profile* profile, |
+ const Extension* extension, |
+ const std::vector<SavedFileEntry>& file_entries) |
+ : profile_(profile), |
+ extension_(extension), |
+ file_entries_(file_entries) {} |
+ |
+ void Launch() { |
+ // Access needs to be granted to the file or filesystem for the process |
+ // associated with the extension. To do this the ExtensionHost is needed. |
+ // This might not be available, or it might be in the process of being |
+ // unloaded, in which case the lazy background task queue is used to load |
+ // he extension and then call back to us. |
+ extensions::LazyBackgroundTaskQueue* queue = |
+ ExtensionSystem::Get(profile_)->lazy_background_task_queue(); |
+ if (queue->ShouldEnqueueTask(profile_, extension_)) { |
+ queue->AddPendingTask(profile_, extension_->id(), base::Bind( |
+ &SavedFileEntryLauncher::GrantAccessToFilesAndLaunch, |
+ this)); |
+ return; |
+ } |
+ ExtensionProcessManager* process_manager = |
+ ExtensionSystem::Get(profile_)->process_manager(); |
+ extensions::ExtensionHost* host = |
+ process_manager->GetBackgroundHostForExtension(extension_->id()); |
+ DCHECK(host); |
+ GrantAccessToFilesAndLaunch(host); |
+ } |
+ |
+ private: |
+ void GrantAccessToFilesAndLaunch(ExtensionHost* host) { |
+ int renderer_id = host->render_process_host()->GetID(); |
+ std::vector<GrantedFileEntry> granted_file_entries; |
+ for (std::vector<SavedFileEntry>::const_iterator it = |
+ file_entries_.begin(); it != file_entries_.end(); ++it) { |
+ GrantedFileEntry file_entry = CreateFileEntry( |
+ profile_, extension_->id(), renderer_id, it->path, it->writable); |
+ file_entry.id = it->id; |
+ granted_file_entries.push_back(file_entry); |
+ |
+ // Record that we have granted this file permission. |
+ ExtensionPrefs* extension_prefs = ExtensionSystem::Get(profile_)-> |
+ extension_service()->extension_prefs(); |
+ extension_prefs->AddSavedFileEntry( |
+ host->extension()->id(), it->id, it->path, it->writable); |
+ } |
+ extensions::AppEventRouter::DispatchOnRestartedEvent( |
+ profile_, extension_, granted_file_entries); |
+ } |
+ |
+ // The profile the app should be run in. |
+ Profile* profile_; |
+ // The extension providing the app. |
+ const Extension* extension_; |
+ |
+ std::vector<SavedFileEntry> file_entries_; |
+}; |
+ |
+/* |
+// Class to handle launching of platform apps with WebIntent data. |
+// An instance of this class is created for each launch. The lifetime of these |
+// instances is managed by reference counted pointers. As long as an instance |
+// has outstanding tasks on a message queue it will be retained; once all |
+// outstanding tasks are completed it will be deleted. |
+class PlatformAppWebIntentLauncher |
benwells
2013/03/13 03:58:29
This guy has been deleted.
koz (OOO until 15th September)
2013/03/13 05:01:13
Oops, and commented out in my change, too.
Removed
|
+ : public base::RefCountedThreadSafe<PlatformAppWebIntentLauncher> { |
+ public: |
+ PlatformAppWebIntentLauncher( |
+ Profile* profile, |
+ const Extension* extension, |
+ content::WebIntentsDispatcher* intents_dispatcher, |
+ content::WebContents* source) |
+ : profile_(profile), |
+ extension_(extension), |
+ intents_dispatcher_(intents_dispatcher), |
+ source_(source), |
+ data_(intents_dispatcher->GetIntent()) {} |
+ |
+ void Launch() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (data_.data_type != webkit_glue::WebIntentData::BLOB && |
+ data_.data_type != webkit_glue::WebIntentData::FILESYSTEM) { |
+ InternalLaunch(); |
+ return; |
+ } |
+ |
+ // Access needs to be granted to the file or filesystem for the process |
+ // associated with the extension. To do this the ExtensionHost is needed. |
+ // This might not be available, or it might be in the process of being |
+ // unloaded, in which case the lazy background task queue is used to load |
+ // he extension and then call back to us. |
+ LazyBackgroundTaskQueue* queue = |
+ ExtensionSystem::Get(profile_)->lazy_background_task_queue(); |
+ if (queue->ShouldEnqueueTask(profile_, extension_)) { |
+ queue->AddPendingTask(profile_, extension_->id(), base::Bind( |
+ &PlatformAppWebIntentLauncher::GrantAccessToFileAndLaunch, |
+ this)); |
+ return; |
+ } |
+ ExtensionProcessManager* process_manager = |
+ ExtensionSystem::Get(profile_)->process_manager(); |
+ ExtensionHost* host = |
+ process_manager->GetBackgroundHostForExtension(extension_->id()); |
+ DCHECK(host); |
+ GrantAccessToFileAndLaunch(host); |
+ } |
+ |
+ private: |
+ friend class base::RefCountedThreadSafe<PlatformAppWebIntentLauncher>; |
+ |
+ virtual ~PlatformAppWebIntentLauncher() {} |
+ |
+ void GrantAccessToFileAndLaunch(ExtensionHost* host) { |
+ // If there was an error loading the app page, |host| will be NULL. |
+ if (!host) { |
+ LOG(ERROR) << "Could not load app page for " << extension_->id(); |
+ return; |
+ } |
+ |
+ content::ChildProcessSecurityPolicy* policy = |
+ content::ChildProcessSecurityPolicy::GetInstance(); |
+ int renderer_id = host->render_process_host()->GetID(); |
+ |
+ if (data_.data_type == webkit_glue::WebIntentData::BLOB) { |
+ // Granting read file permission to allow reading file content. |
+ // If the renderer already has permission to read these paths, it is not |
+ // regranted, as this would overwrite any other permissions which the |
+ // renderer may already have. |
+ if (!policy->CanReadFile(renderer_id, data_.blob_file)) |
+ policy->GrantReadFile(renderer_id, data_.blob_file); |
+ } else if (data_.data_type == webkit_glue::WebIntentData::FILESYSTEM) { |
+ // Grant read filesystem and read directory permission to allow reading |
+ // any part of the specified filesystem. |
+ FilePath path; |
+ const bool valid = |
+ fileapi::IsolatedContext::GetInstance()->GetRegisteredPath( |
+ data_.filesystem_id, &path); |
+ DCHECK(valid); |
+ if (!policy->CanReadFile(renderer_id, path)) |
+ policy->GrantReadFile(renderer_id, path); |
+ policy->GrantReadFileSystem(renderer_id, data_.filesystem_id); |
+ } else { |
+ NOTREACHED(); |
+ } |
+ InternalLaunch(); |
+ } |
+ |
+ void InternalLaunch() { |
+ AppEventRouter::DispatchOnLaunchedEventWithWebIntent( |
+ profile_, extension_, intents_dispatcher_, source_); |
+ } |
+ |
+ // The profile the app should be run in. |
+ Profile* profile_; |
+ // The extension providing the app. |
+ const Extension* extension_; |
+ // The dispatcher so that platform apps can respond to this intent. |
+ content::WebIntentsDispatcher* intents_dispatcher_; |
+ // The source of this intent. |
+ content::WebContents* source_; |
+ // The WebIntent data from the dispatcher. |
+ const webkit_glue::WebIntentData data_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PlatformAppWebIntentLauncher); |
+}; |
+*/ |
+ |
} // namespace |
void LaunchPlatformApp(Profile* profile, |
@@ -275,4 +452,13 @@ void LaunchPlatformAppWithFileHandler(Profile* profile, |
launcher->LaunchWithHandler(handler_id); |
} |
+void RestartPlatformAppWithFileEntries( |
+ Profile* profile, |
+ const Extension* extension, |
+ const std::vector<SavedFileEntry>& file_entries) { |
+ scoped_refptr<SavedFileEntryLauncher> launcher = new SavedFileEntryLauncher( |
+ profile, extension, file_entries); |
+ launcher->Launch(); |
+} |
+ |
} // namespace extensions |