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

Unified Diff: chrome/browser/devtools/devtools_window.cc

Issue 11570081: Support file system access in DevTools with isolated file system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renamed methods and added CHECK() Created 8 years 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/devtools/devtools_window.cc
diff --git a/chrome/browser/devtools/devtools_window.cc b/chrome/browser/devtools/devtools_window.cc
index 8c9fbe1dc719d1ce6b91dac0c92b4945af8fd7ef..19594574e26c155b362ee613067628307efcb5a4 100644
--- a/chrome/browser/devtools/devtools_window.cc
+++ b/chrome/browser/devtools/devtools_window.cc
@@ -46,6 +46,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/common/bindings_policy.h"
+#include "content/public/common/content_client.h"
#include "content/public/common/page_transition_types.h"
#include "grit/generated_resources.h"
@@ -96,6 +97,8 @@ void DevToolsWindow::RegisterUserPrefs(PrefServiceSyncable* prefs) {
PrefServiceSyncable::UNSYNCABLE_PREF);
prefs->RegisterDictionaryPref(prefs::kDevToolsEditedFiles,
PrefServiceSyncable::UNSYNCABLE_PREF);
+ prefs->RegisterDictionaryPref(prefs::kDevToolsFilesystemPaths,
+ PrefServiceSyncable::UNSYNCABLE_PREF);
}
// static
@@ -215,7 +218,7 @@ DevToolsWindow::DevToolsWindow(WebContents* web_contents,
height_(-1) {
frontend_host_ = DevToolsClientHost::CreateDevToolsFrontendHost(web_contents,
this);
- file_helper_.reset(new DevToolsFileHelper(profile));
+ file_helper_.reset(new DevToolsFileHelper(web_contents, profile));
g_instances.Get().push_back(this);
// Wipe out page icon so that the default application icon is used.
@@ -507,13 +510,19 @@ WebContents* DevToolsWindow::OpenURLFromTab(WebContents* source,
}
void DevToolsWindow::CallClientFunction(const std::string& function_name,
- const Value* arg) {
- std::string json;
- if (arg)
- base::JSONWriter::Write(arg, &json);
-
- string16 javascript =
- ASCIIToUTF16(function_name + "(" + json + ");");
+ const Value* arg1,
+ const Value* arg2) {
+ std::string params;
+ if (arg1) {
+ std::string json;
+ base::JSONWriter::Write(arg1, &json);
+ params.append(json);
+ if (arg2) {
+ base::JSONWriter::Write(arg2, &json);
+ params.append(", " + json);
+ }
+ }
+ string16 javascript = ASCIIToUTF16(function_name + "(" + params + ");");
web_contents_->GetRenderViewHost()->
ExecuteJavascriptInWebFrame(string16(), javascript);
}
@@ -826,6 +835,39 @@ void DevToolsWindow::AppendToFile(const std::string& url,
url));
}
+namespace {
+
+DictionaryValue* CreateFilesystemValue(
+ DevToolsFileHelper::Filesystem filesystem) {
+ DictionaryValue* filesystem_value = new DictionaryValue();
+ filesystem_value->SetString("filesystemId", filesystem.filesystem_id);
+ filesystem_value->SetString("registeredName", filesystem.registered_name);
+ filesystem_value->SetString("filesystemPath", filesystem.filesystem_path);
+ return filesystem_value;
+}
+
+} // namespace
+
+void DevToolsWindow::RequestFilesystems() {
+ CHECK(content::GetContentClient()->HasWebUIScheme(web_contents_->GetURL()));
+ file_helper_->RequestFilesystems(
+ Bind(&DevToolsWindow::FilesystemsLoaded, weak_factory_.GetWeakPtr()));
+}
+
+void DevToolsWindow::AddFilesystem() {
+ CHECK(content::GetContentClient()->HasWebUIScheme(web_contents_->GetURL()));
+ file_helper_->AddFilesystem(
+ Bind(&DevToolsWindow::FilesystemAdded, weak_factory_.GetWeakPtr()));
+}
+
+void DevToolsWindow::RemoveFilesystem(const std::string& filesystem_path) {
+ CHECK(content::GetContentClient()->HasWebUIScheme(web_contents_->GetURL()));
+ file_helper_->RemoveFilesystem(filesystem_path);
+ StringValue filesystem_path_value(filesystem_path);
+ CallClientFunction("InspectorFrontendAPI.filesystemRemoved",
+ &filesystem_path_value);
+}
+
void DevToolsWindow::FileSavedAs(const std::string& url) {
StringValue url_value(url);
CallClientFunction("InspectorFrontendAPI.savedURL", &url_value);
@@ -836,6 +878,30 @@ void DevToolsWindow::AppendedTo(const std::string& url) {
CallClientFunction("InspectorFrontendAPI.appendedToURL", &url_value);
}
+void DevToolsWindow::FilesystemsLoaded(
+ const std::vector<DevToolsFileHelper::Filesystem>& filesystems) {
+ ListValue filesystems_value;
+ for (size_t i = 0; i < filesystems.size(); ++i) {
+ filesystems_value.Append(CreateFilesystemValue(filesystems[i]));
+ }
+ CallClientFunction("InspectorFrontendAPI.filesystemsLoaded",
+ &filesystems_value);
+}
+
+void DevToolsWindow::FilesystemAdded(
+ std::string error_string,
+ const DevToolsFileHelper::Filesystem& filesystem) {
+ StringValue error_string_value(error_string);
+ DictionaryValue* filesystem_value = NULL;
+ if (!filesystem.filesystem_path.empty())
+ filesystem_value = CreateFilesystemValue(filesystem);
+ CallClientFunction("InspectorFrontendAPI.filesystemAdded",
+ &error_string_value,
+ filesystem_value);
+ if (filesystem_value)
+ delete filesystem_value;
+}
+
content::JavaScriptDialogCreator* DevToolsWindow::GetJavaScriptDialogCreator() {
if (inspected_web_contents_ && inspected_web_contents_->GetDelegate()) {
return inspected_web_contents_->GetDelegate()->

Powered by Google App Engine
This is Rietveld 408576698