Merge pull request #2027 from deepak1556/devtools_file_save_patch

devtools: writing to filesystem in FILE thread
This commit is contained in:
Cheng Zhao 2015-06-24 10:45:22 +08:00
commit ab6ed823d1
2 changed files with 51 additions and 11 deletions

View file

@ -15,11 +15,14 @@
#include "chrome/browser/printing/print_preview_message_handler.h" #include "chrome/browser/printing/print_preview_message_handler.h"
#include "chrome/browser/printing/print_view_manager_basic.h" #include "chrome/browser/printing/print_view_manager_basic.h"
#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_dialogs.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "storage/browser/fileapi/isolated_context.h" #include "storage/browser/fileapi/isolated_context.h"
using content::BrowserThread;
namespace atom { namespace atom {
namespace { namespace {
@ -86,6 +89,22 @@ base::DictionaryValue* CreateFileSystemValue(const FileSystem& file_system) {
return file_system_value; return file_system_value;
} }
void WriteToFile(const base::FilePath& path,
const std::string& content) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
DCHECK(!path.empty());
base::WriteFile(path, content.data(), content.size());
}
void AppendToFile(const base::FilePath& path,
const std::string& content) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
DCHECK(!path.empty());
base::AppendToFile(path, content.data(), content.size());
}
} // namespace } // namespace
CommonWebContentsDelegate::CommonWebContentsDelegate(bool is_guest) CommonWebContentsDelegate::CommonWebContentsDelegate(bool is_guest)
@ -237,12 +256,11 @@ void CommonWebContentsDelegate::DevToolsSaveToFile(
} }
saved_files_[url] = path; saved_files_[url] = path;
base::WriteFile(path, content.data(), content.size()); BrowserThread::PostTaskAndReply(
BrowserThread::FILE, FROM_HERE,
// Notify devtools. base::Bind(&WriteToFile, path, content),
base::StringValue url_value(url); base::Bind(&CommonWebContentsDelegate::OnDevToolsSaveToFile,
web_contents_->CallClientFunction( base::Unretained(this), url));
"DevToolsAPI.savedURL", &url_value, nullptr, nullptr);
} }
void CommonWebContentsDelegate::DevToolsAppendToFile( void CommonWebContentsDelegate::DevToolsAppendToFile(
@ -250,12 +268,12 @@ void CommonWebContentsDelegate::DevToolsAppendToFile(
PathsMap::iterator it = saved_files_.find(url); PathsMap::iterator it = saved_files_.find(url);
if (it == saved_files_.end()) if (it == saved_files_.end())
return; return;
base::AppendToFile(it->second, content.data(), content.size());
// Notify devtools. BrowserThread::PostTaskAndReply(
base::StringValue url_value(url); BrowserThread::FILE, FROM_HERE,
web_contents_->CallClientFunction( base::Bind(&AppendToFile, it->second, content),
"DevToolsAPI.appendedToURL", &url_value, nullptr, nullptr); base::Bind(&CommonWebContentsDelegate::OnDevToolsAppendToFile,
base::Unretained(this), url));
} }
void CommonWebContentsDelegate::DevToolsAddFileSystem() { void CommonWebContentsDelegate::DevToolsAddFileSystem() {
@ -318,6 +336,22 @@ void CommonWebContentsDelegate::DevToolsRemoveFileSystem(
nullptr); nullptr);
} }
void CommonWebContentsDelegate::OnDevToolsSaveToFile(
const std::string& url) {
// Notify DevTools.
base::StringValue url_value(url);
web_contents_->CallClientFunction(
"DevToolsAPI.savedURL", &url_value, nullptr, nullptr);
}
void CommonWebContentsDelegate::OnDevToolsAppendToFile(
const std::string& url) {
// Notify DevTools.
base::StringValue url_value(url);
web_contents_->CallClientFunction(
"DevToolsAPI.appendedToURL", &url_value, nullptr, nullptr);
}
void CommonWebContentsDelegate::SetHtmlApiFullscreen(bool enter_fullscreen) { void CommonWebContentsDelegate::SetHtmlApiFullscreen(bool enter_fullscreen) {
// Window is already in fullscreen mode, save the state. // Window is already in fullscreen mode, save the state.
if (enter_fullscreen && owner_window_->IsFullscreen()) { if (enter_fullscreen && owner_window_->IsFullscreen()) {

View file

@ -83,6 +83,12 @@ class CommonWebContentsDelegate
void DevToolsRemoveFileSystem(const std::string& file_system_path) override; void DevToolsRemoveFileSystem(const std::string& file_system_path) override;
private: private:
// Callback for when DevToolsSaveToFile has completed.
void OnDevToolsSaveToFile(const std::string& url);
// Callback for when DevToolsAppendToFile has completed.
void OnDevToolsAppendToFile(const std::string& url);
// Set fullscreen mode triggered by html api. // Set fullscreen mode triggered by html api.
void SetHtmlApiFullscreen(bool enter_fullscreen); void SetHtmlApiFullscreen(bool enter_fullscreen);