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

Unified Diff: chrome/browser/extensions/api/runtime/runtime_api.cc

Issue 16470003: Add chrome.runtime.getPackageDirectoryEntry. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 6 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/extensions/api/runtime/runtime_api.cc
diff --git a/chrome/browser/extensions/api/runtime/runtime_api.cc b/chrome/browser/extensions/api/runtime/runtime_api.cc
index fd3a34311fc1e859cffea56dbc4f6497de9be92a..6b65a45de40b17bd1d25cb161f5c77e9af3e7d5b 100644
--- a/chrome/browser/extensions/api/runtime/runtime_api.cc
+++ b/chrome/browser/extensions/api/runtime/runtime_api.cc
@@ -22,8 +22,12 @@
#include "chrome/common/extensions/background_info.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/omaha_query_params/omaha_query_params.h"
+#include "content/public/browser/child_process_security_policy.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_view_host.h"
#include "extensions/common/error_utils.h"
#include "googleurl/src/gurl.h"
+#include "webkit/browser/fileapi/isolated_context.h"
namespace GetPlatformInfo = extensions::api::runtime::GetPlatformInfo;
@@ -52,6 +56,11 @@ const char kUpdateThrottled[] = "throttled";
// A preference key storing the url loaded when an extension is uninstalled.
const char kUninstallUrl[] = "uninstall_url";
+// The name of the directory to be returned by getPackageDirectoryEntry. This
+// particular value does not matter to user code, but is chosen for consistency
+// with the equivalent Pepper API.
+const char kPackageDirectoryPath[] = "crxfs";
+
static void DispatchOnStartupEventImpl(
Profile* profile,
const std::string& extension_id,
@@ -380,4 +389,29 @@ bool RuntimeGetPlatformInfoFunction::RunImpl() {
return true;
}
+bool RuntimeGetPackageDirectoryEntryFunction::RunImpl() {
+ fileapi::IsolatedContext* isolated_context =
+ fileapi::IsolatedContext::GetInstance();
+ DCHECK(isolated_context);
+
+ std::string relative_path = kPackageDirectoryPath;
+ base::FilePath path = extension_->path();
+ std::string filesystem_id = isolated_context->RegisterFileSystemForPath(
+ fileapi::kFileSystemTypeNativeLocal, path, &relative_path);
+
+ int renderer_id = render_view_host_->GetProcess()->GetID();
+ content::ChildProcessSecurityPolicy* policy =
+ content::ChildProcessSecurityPolicy::GetInstance();
+ policy->GrantReadFileSystem(renderer_id, filesystem_id);
+
+ if (!policy->CanReadFile(renderer_id, path))
+ policy->GrantReadFile(renderer_id, path);
+
+ DictionaryValue* dict = new DictionaryValue();
+ SetResult(dict);
+ dict->SetString("fileSystemId", filesystem_id);
+ dict->SetString("baseName", relative_path);
+ return true;
+}
+
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/runtime/runtime_api.h ('k') | chrome/browser/extensions/api/runtime/runtime_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698