#include "atom/browser/browser.h"
#include "atom/browser/devtools_delegate.h"
#include "atom/browser/devtools_web_contents_observer.h"
+#include "atom/browser/ui/file_dialog.h"
#include "atom/browser/window_list.h"
#include "atom/common/api/api_messages.h"
#include "atom/common/atom_version.h"
#include "atom/common/options_switches.h"
#include "base/command_line.h"
#include "base/file_util.h"
+#include "base/json/json_writer.h"
#include "base/prefs/pref_service.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/stringprintf.h"
return false;
}
+void NativeWindow::DevToolsSaveToFile(const std::string& url,
+ const std::string& content,
+ bool save_as) {
+ base::FilePath path;
+ PathsMap::iterator it = saved_files_.find(url);
+ if (it != saved_files_.end() && !save_as) {
+ path = it->second;
+ } else {
+ if (!file_dialog::ShowSaveDialog(this, url, base::FilePath(url), &path))
+ return;
+ }
+
+ saved_files_[url] = path;
+ file_util::WriteFile(path, content.data(), content.size());
+
+ // Notify devtools.
+ base::StringValue url_value(url);
+ CallDevToolsFunction("InspectorFrontendAPI.savedURL", &url_value);
+
+ // TODO(zcbenz): In later Chrome we need to call canceledSaveURL when the save
+ // failed.
+}
+
+void NativeWindow::DevToolsAppendToFile(const std::string& url,
+ const std::string& content) {
+ PathsMap::iterator it = saved_files_.find(url);
+ if (it == saved_files_.end())
+ return;
+ file_util::AppendToFile(it->second, content.data(), content.size());
+
+ // Notify devtools.
+ base::StringValue url_value(url);
+ CallDevToolsFunction("InspectorFrontendAPI.appendedToURL", &url_value);
+}
+
void NativeWindow::ScheduleUnresponsiveEvent(int ms) {
window_unresposive_closure_.Reset(
base::Bind(&NativeWindow::NotifyWindowUnresponsive,
callback.Run(data);
}
+void NativeWindow::CallDevToolsFunction(const std::string& function_name,
+ const base::Value* arg1,
+ const base::Value* arg2,
+ const base::Value* arg3) {
+ 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);
+ if (arg3) {
+ base::JSONWriter::Write(arg3, &json);
+ params.append(", " + json);
+ }
+ }
+ }
+ base::string16 javascript =
+ base::ASCIIToUTF16(function_name + "(" + params + ");");
+ GetDevToolsWebContents()->GetRenderViewHost()->ExecuteJavascriptInWebFrame(
+ string16(), javascript);
+}
+
void NativeWindow::OnRendererMessage(const string16& channel,
const base::ListValue& args) {
AtomBrowserMainParts::Get()->atom_bindings()->OnRendererMessage(
virtual bool DevToolsSetDockSide(const std::string& dock_side,
bool* succeed) OVERRIDE;
virtual bool DevToolsShow(std::string* dock_side) OVERRIDE;
+ virtual void DevToolsSaveToFile(const std::string& url,
+ const std::string& content,
+ bool save_as) OVERRIDE;
+ virtual void DevToolsAppendToFile(const std::string& url,
+ const std::string& content) OVERRIDE;
// Whether window has standard frame.
bool has_frame_;
// Dispatch unresponsive event to observers.
void NotifyWindowUnresponsive();
+ // Call a function in devtools.
+ void CallDevToolsFunction(const std::string& function_name,
+ const base::Value* arg1 = NULL,
+ const base::Value* arg2 = NULL,
+ const base::Value* arg3 = NULL);
+
// Called when CapturePage has done.
void OnCapturePageDone(const CapturePageCallback& callback,
bool succeed,
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
+ // Maps url to file path, used by the file requests sent from devtools.
+ typedef std::map<std::string, base::FilePath> PathsMap;
+ PathsMap saved_files_;
+
DISALLOW_COPY_AND_ASSIGN(NativeWindow);
};