Merge pull request #2327 from deepak1556/devtools_api_patch

webContents: api to add/remove path from devtools workspace
This commit is contained in:
Cheng Zhao 2015-07-29 17:16:02 +08:00
commit d719244d1e
5 changed files with 59 additions and 18 deletions

View file

@ -14,6 +14,7 @@
#include "atom/browser/web_view_guest_delegate.h" #include "atom/browser/web_view_guest_delegate.h"
#include "atom/common/api/api_messages.h" #include "atom/common/api/api_messages.h"
#include "atom/common/event_emitter_caller.h" #include "atom/common/event_emitter_caller.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "atom/common/native_mate_converters/gfx_converter.h" #include "atom/common/native_mate_converters/gfx_converter.h"
#include "atom/common/native_mate_converters/gurl_converter.h" #include "atom/common/native_mate_converters/gurl_converter.h"
#include "atom/common/native_mate_converters/image_converter.h" #include "atom/common/native_mate_converters/image_converter.h"
@ -689,6 +690,22 @@ void WebContents::PrintToPDF(const base::DictionaryValue& setting,
PrintToPDF(setting, callback); PrintToPDF(setting, callback);
} }
void WebContents::AddWorkSpace(const base::FilePath& path) {
if (path.empty()) {
node::ThrowError(isolate(), "path cannot be empty");
return;
}
DevToolsAddFileSystem(path);
}
void WebContents::RemoveWorkSpace(const base::FilePath& path) {
if (path.empty()) {
node::ThrowError(isolate(), "path cannot be empty");
return;
}
DevToolsRemoveFileSystem(path);
}
void WebContents::Undo() { void WebContents::Undo() {
web_contents()->Undo(); web_contents()->Undo();
} }
@ -812,6 +829,8 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
.SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker) .SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker)
.SetMethod("print", &WebContents::Print) .SetMethod("print", &WebContents::Print)
.SetMethod("_printToPDF", &WebContents::PrintToPDF) .SetMethod("_printToPDF", &WebContents::PrintToPDF)
.SetMethod("addWorkSpace", &WebContents::AddWorkSpace)
.SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace)
.SetProperty("session", &WebContents::Session) .SetProperty("session", &WebContents::Session)
.Build()); .Build());

View file

@ -37,8 +37,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
public content::WebContentsObserver { public content::WebContentsObserver {
public: public:
// For node.js callback function type: function(error, buffer) // For node.js callback function type: function(error, buffer)
typedef base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)> using PrintToPDFCallback =
PrintToPDFCallback; base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>;
// Create from an existing WebContents. // Create from an existing WebContents.
static mate::Handle<WebContents> CreateFrom( static mate::Handle<WebContents> CreateFrom(
@ -83,6 +83,10 @@ class WebContents : public mate::TrackableObject<WebContents>,
void PrintToPDF(const base::DictionaryValue& setting, void PrintToPDF(const base::DictionaryValue& setting,
const PrintToPDFCallback& callback); const PrintToPDFCallback& callback);
// DevTools workspace api.
void AddWorkSpace(const base::FilePath& path);
void RemoveWorkSpace(const base::FilePath& path);
// Editing commands. // Editing commands.
void Undo(); void Undo();
void Redo(); void Redo();

View file

@ -274,16 +274,21 @@ void CommonWebContentsDelegate::DevToolsAppendToFile(
base::Unretained(this), url)); base::Unretained(this), url));
} }
void CommonWebContentsDelegate::DevToolsAddFileSystem() { void CommonWebContentsDelegate::DevToolsAddFileSystem(
file_dialog::Filters filters; const base::FilePath& file_system_path) {
base::FilePath default_path; base::FilePath path = file_system_path;
std::vector<base::FilePath> paths; if (path.empty()) {
int flag = file_dialog::FILE_DIALOG_OPEN_DIRECTORY; file_dialog::Filters filters;
if (!file_dialog::ShowOpenDialog(owner_window(), "", default_path, base::FilePath default_path;
filters, flag, &paths)) std::vector<base::FilePath> paths;
return; int flag = file_dialog::FILE_DIALOG_OPEN_DIRECTORY;
if (!file_dialog::ShowOpenDialog(owner_window(), "", default_path,
filters, flag, &paths))
return;
path = paths[0];
}
base::FilePath path = paths[0];
std::string registered_name; std::string registered_name;
std::string file_system_id = RegisterFileSystem(GetDevToolsWebContents(), std::string file_system_id = RegisterFileSystem(GetDevToolsWebContents(),
path, path,
@ -313,20 +318,20 @@ void CommonWebContentsDelegate::DevToolsAddFileSystem() {
} }
void CommonWebContentsDelegate::DevToolsRemoveFileSystem( void CommonWebContentsDelegate::DevToolsRemoveFileSystem(
const std::string& file_system_path) { const base::FilePath& file_system_path) {
if (!web_contents_) if (!web_contents_)
return; return;
base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path); storage::IsolatedContext::GetInstance()->
storage::IsolatedContext::GetInstance()->RevokeFileSystemByPath(path); RevokeFileSystemByPath(file_system_path);
for (auto it = saved_paths_.begin(); it != saved_paths_.end(); ++it) for (auto it = saved_paths_.begin(); it != saved_paths_.end(); ++it)
if (it->second == path) { if (it->second == file_system_path) {
saved_paths_.erase(it); saved_paths_.erase(it);
break; break;
} }
base::StringValue file_system_path_value(file_system_path); base::StringValue file_system_path_value(file_system_path.AsUTF8Unsafe());
web_contents_->CallClientFunction( web_contents_->CallClientFunction(
"DevToolsAPI.fileSystemRemoved", "DevToolsAPI.fileSystemRemoved",
&file_system_path_value, &file_system_path_value,

View file

@ -80,8 +80,9 @@ class CommonWebContentsDelegate
bool save_as) override; bool save_as) override;
void DevToolsAppendToFile(const std::string& url, void DevToolsAppendToFile(const std::string& url,
const std::string& content) override; const std::string& content) override;
void DevToolsAddFileSystem() override; void DevToolsAddFileSystem(const base::FilePath& path) override;
void DevToolsRemoveFileSystem(const std::string& file_system_path) override; void DevToolsRemoveFileSystem(
const base::FilePath& file_system_path) override;
private: private:
// Callback for when DevToolsSaveToFile has completed. // Callback for when DevToolsSaveToFile has completed.

View file

@ -1042,6 +1042,18 @@ win.webContents.on("did-finish-load", function() {
}); });
``` ```
### WebContents.addWorkSpace(path)
* `path` String
Adds the specified path to devtools workspace.
### WebContents.removeWorkSpace(path)
* `path` String
Removes the specified path from devtools workspace.
### WebContents.send(channel[, args...]) ### WebContents.send(channel[, args...])
* `channel` String * `channel` String