]> khamidou — GitHub mirrors - electron.git/commitdiff
webContents: api to add/remove path from devtools workspace
authorRobo <hop2deep@gmail.com>
Fri, 24 Jul 2015 09:39:11 +0000 (15:09 +0530)
committerRobo <hop2deep@gmail.com>
Wed, 29 Jul 2015 03:59:38 +0000 (09:29 +0530)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/browser/common_web_contents_delegate.cc
atom/browser/common_web_contents_delegate.h
docs/api/browser-window.md

index b79338548063045af226bec5210d1dfc2f9bb999..7070b7d6ebabee5f814d89aef8b52a5058aa19ba 100644 (file)
@@ -14,6 +14,7 @@
 #include "atom/browser/web_view_guest_delegate.h"
 #include "atom/common/api/api_messages.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/gurl_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);
 }
 
+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() {
   web_contents()->Undo();
 }
@@ -812,6 +829,8 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
         .SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker)
         .SetMethod("print", &WebContents::Print)
         .SetMethod("_printToPDF", &WebContents::PrintToPDF)
+        .SetMethod("addWorkSpace", &WebContents::AddWorkSpace)
+        .SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace)
         .SetProperty("session", &WebContents::Session)
         .Build());
 
index 1dcf5f4f6d2936749525b5dd7fb2b5d077994131..68e0ad31052995816999c5c85aeebf15020e6d21 100644 (file)
@@ -37,8 +37,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
                     public content::WebContentsObserver {
  public:
   // For node.js callback function type: function(error, buffer)
-  typedef base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>
-      PrintToPDFCallback;
+  using PrintToPDFCallback =
+      base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>;
 
   // Create from an existing WebContents.
   static mate::Handle<WebContents> CreateFrom(
@@ -83,6 +83,10 @@ class WebContents : public mate::TrackableObject<WebContents>,
   void PrintToPDF(const base::DictionaryValue& setting,
                   const PrintToPDFCallback& callback);
 
+  // DevTools workspace api.
+  void AddWorkSpace(const base::FilePath& path);
+  void RemoveWorkSpace(const base::FilePath& path);
+
   // Editing commands.
   void Undo();
   void Redo();
index af429929812ac1b8d891171f1f35333e9e64e4c6..3cef7c6d68cca365ed5f4ab50307eb06a56e2fc6 100644 (file)
@@ -274,16 +274,21 @@ void CommonWebContentsDelegate::DevToolsAppendToFile(
                  base::Unretained(this), url));
 }
 
-void CommonWebContentsDelegate::DevToolsAddFileSystem() {
-  file_dialog::Filters filters;
-  base::FilePath default_path;
-  std::vector<base::FilePath> paths;
-  int flag = file_dialog::FILE_DIALOG_OPEN_DIRECTORY;
-  if (!file_dialog::ShowOpenDialog(owner_window(), "", default_path,
-                                   filters, flag, &paths))
-    return;
+void CommonWebContentsDelegate::DevToolsAddFileSystem(
+    const base::FilePath& file_system_path) {
+  base::FilePath path = file_system_path;
+  if (path.empty()) {
+    file_dialog::Filters filters;
+    base::FilePath default_path;
+    std::vector<base::FilePath> paths;
+    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 file_system_id = RegisterFileSystem(GetDevToolsWebContents(),
                                                   path,
@@ -313,20 +318,20 @@ void CommonWebContentsDelegate::DevToolsAddFileSystem() {
 }
 
 void CommonWebContentsDelegate::DevToolsRemoveFileSystem(
-    const std::string& file_system_path) {
+    const base::FilePath& file_system_path) {
   if (!web_contents_)
     return;
 
-  base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path);
-  storage::IsolatedContext::GetInstance()->RevokeFileSystemByPath(path);
+  storage::IsolatedContext::GetInstance()->
+      RevokeFileSystemByPath(file_system_path);
 
   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);
       break;
     }
 
-  base::StringValue file_system_path_value(file_system_path);
+  base::StringValue file_system_path_value(file_system_path.AsUTF8Unsafe());
   web_contents_->CallClientFunction(
       "DevToolsAPI.fileSystemRemoved",
        &file_system_path_value,
index 8c87548951b2bc8f6226ce9d10318fae09044d3b..e21cd24e91077bb2ddd56f60d98c4e0dd28b271b 100644 (file)
@@ -80,8 +80,9 @@ class CommonWebContentsDelegate
                           bool save_as) override;
   void DevToolsAppendToFile(const std::string& url,
                             const std::string& content) override;
-  void DevToolsAddFileSystem() override;
-  void DevToolsRemoveFileSystem(const std::string& file_system_path) override;
+  void DevToolsAddFileSystem(const base::FilePath& path) override;
+  void DevToolsRemoveFileSystem(
+      const base::FilePath& file_system_path) override;
 
  private:
   // Callback for when DevToolsSaveToFile has completed.
index cee68183f78305fd55fa199816227e0882eb9322..cb4941daaa7f25ff83602a2e943386884f4babd6 100644 (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...])
 
 * `channel` String