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

Unified Diff: chrome/browser/renderer_host/pepper/pepper_ext_crx_file_system_browser_host.cc

Issue 14188019: CRX FileSystem Pepper private API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/renderer_host/pepper/pepper_ext_crx_file_system_browser_host.cc
diff --git a/chrome/browser/renderer_host/pepper/pepper_ext_crx_file_system_browser_host.cc b/chrome/browser/renderer_host/pepper/pepper_ext_crx_file_system_browser_host.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f479bd9fa7b9765341ed97748cc2982bd000ca0c
--- /dev/null
+++ b/chrome/browser/renderer_host/pepper/pepper_ext_crx_file_system_browser_host.cc
@@ -0,0 +1,133 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/renderer_host/pepper/pepper_ext_crx_file_system_browser_host.h"
+
+#include "base/files/file_path.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/common/extensions/extension.h"
+#include "content/public/browser/browser_ppapi_host.h"
+#include "content/public/browser/child_process_security_policy.h"
+#include "extensions/common/constants.h"
+#include "googleurl/src/gurl.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/host/dispatch_host_message.h"
+#include "ppapi/host/host_message_context.h"
+#include "ppapi/host/ppapi_host.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/resource_message_params.h"
+#include "webkit/fileapi/isolated_context.h"
+
+namespace chrome {
+
+namespace {
+
+// Returns filesystem id of isolated filesystem if accesss, or empty string
Yoyo Zhou 2013/04/19 17:52:56 accesss?
victorhsieh 2013/04/19 22:52:56 Done.
+// otherwise. This is expected to run in UI thread as ProfileManager only
+// allows UI thread access.
Yoyo Zhou 2013/04/19 17:52:56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::U
victorhsieh 2013/04/19 22:52:56 Done.
+std::string MountCrxDirectory(
+ const base::FilePath& profile_directory,
+ const GURL& url) {
+ if (!url.SchemeIs(extensions::kExtensionScheme))
+ return std::string();
+
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ Profile* profile = profile_manager->GetProfile(profile_directory);
+ extensions::ExtensionSystem* extension_system =
+ extensions::ExtensionSystem::Get(profile);
+ if (!extension_system)
+ return std::string();
+
+ const ExtensionService* extension_service =
+ extension_system->extension_service();
+ if (!extension_service)
+ return std::string();
+
+ const extensions::Extension* extension =
+ extension_service->GetExtensionById(url.host(), false);
+ if (!extension)
+ return std::string();
+
+ // First level directory for isolated filesystem to lookup.
+ std::string kFirstLevelDirectory("crxfs");
+ return fileapi::IsolatedContext::GetInstance()->
+ RegisterFileSystemForPath(fileapi::kFileSystemTypeNativeLocal,
+ extension->path(),
+ &kFirstLevelDirectory);
+}
+
+void MakeAndGrantCrxDirectoryAccess(
+ content::BrowserPpapiHost* browser_ppapi_host,
+ ppapi::host::ReplyMessageContext reply_context,
+ PP_Instance instance) {
+ // Create an isolated file system for current extension.
+ const GURL& url = browser_ppapi_host->GetDocumentURLForInstance(instance);
+ std::string fsid = MountCrxDirectory(
+ browser_ppapi_host->GetProfileDataDirectory(), url);
+ if (fsid.empty()) {
+ reply_context.params.set_result(PP_ERROR_NOTSUPPORTED);
+ browser_ppapi_host->GetPpapiHost()->SendReply(
+ reply_context,
+ PpapiPluginMsg_Ext_CrxFileSystem_BrowserOpenReply(std::string(),
+ std::string()));
+ return;
+ }
+
+ // Grant readonly access of isolated filesystem to renderer process.
+ int render_process_id;
+ int unused_render_view_id;
+ browser_ppapi_host->GetRenderViewIDsForInstance(instance,
+ &render_process_id,
+ &unused_render_view_id);
+ content::ChildProcessSecurityPolicy* policy =
+ content::ChildProcessSecurityPolicy::GetInstance();
+ policy->GrantReadFileSystem(render_process_id, fsid);
+
+ reply_context.params.set_result(PP_OK);
+ browser_ppapi_host->GetPpapiHost()->SendReply(
+ reply_context,
+ PpapiPluginMsg_Ext_CrxFileSystem_BrowserOpenReply(url.host(), fsid));
+}
+
+} // namespace
+
+PepperExtCrxFileSystemBrowserHost::PepperExtCrxFileSystemBrowserHost(
+ content::BrowserPpapiHost* host,
+ PP_Instance instance,
+ PP_Resource resource)
+ : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource),
+ browser_ppapi_host_(host) {
+}
+
+PepperExtCrxFileSystemBrowserHost::~PepperExtCrxFileSystemBrowserHost() {
+}
+
+int32_t PepperExtCrxFileSystemBrowserHost::OnResourceMessageReceived(
+ const IPC::Message& msg,
+ ppapi::host::HostMessageContext* context) {
+ IPC_BEGIN_MESSAGE_MAP(PepperExtCrxFileSystemBrowserHost, msg)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
+ PpapiBrowserHostMsg_Ext_CrxFileSystem_Open, OnOpenFileSystem);
+ IPC_END_MESSAGE_MAP()
+ return PP_ERROR_FAILED;
+}
+
+int32_t PepperExtCrxFileSystemBrowserHost::OnOpenFileSystem(
+ ppapi::host::HostMessageContext* context) {
+ // Post to UI thread. We need to get extension by first calling
+ // ProfileManager at this time, and ProfileManager lives in UI thread.
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&MakeAndGrantCrxDirectoryAccess,
+ browser_ppapi_host_,
+ context->MakeReplyMessageContext(),
+ pp_instance()));
+ return PP_OK_COMPLETIONPENDING;
+}
+
+} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698