Skip to content

Commit d781b7b

Browse files
buildbuild
authored andcommitted
Merge branch 'WD_1.X_dev' of https://portal-ua.globallogic.com/git/wd into WD_1.X_dev
2 parents 2ef3ebc + 0fb1d60 commit d781b7b

File tree

10 files changed

+5408
-11
lines changed

10 files changed

+5408
-11
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ then
1111
platform="desktop"
1212
fi
1313

14-
output_gen=`readlink -f ${output_gen}`
14+
output_gen=`readlink -m ${output_gen}`
1515
base_output_gen=`dirname ${output_gen}`
1616

1717
if [ -z $platform ];

inc/extension_qt/widget_view_executor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class QWidgetXmlSerializer {
4040
supportedClasses_ = classes;
4141
}
4242

43+
void setStylesheet(const QString& stylesheet) {
44+
stylesheet_ = stylesheet;
45+
}
46+
4347
private:
4448
void addWidget(QWidget* widget);
4549
QString getElementName(const QObject* object) const;
@@ -50,6 +54,7 @@ class QWidgetXmlSerializer {
5054
ViewId viewId_;
5155
bool dumpAll_;
5256
QStringList supportedClasses_;
57+
QString stylesheet_;
5358
};
5459

5560
class QWidgetViewCmdExecutorCreator : public ViewCmdExecutorCreator {

src/webdriver/extension_qt/widget_view_executor.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ QWidgetXmlSerializer::QWidgetXmlSerializer(QIODevice* buff)
6767

6868
void QWidgetXmlSerializer::createXml(QWidget* widget) {
6969
writer_.writeStartDocument();
70+
if (!stylesheet_.isEmpty()) {
71+
writer_.writeProcessingInstruction("xml-stylesheet", "href=\"" + stylesheet_ + "\"");
72+
}
7073
addWidget(widget);
7174
writer_.writeEndDocument();
7275
}

src/webdriver/extension_qt/widget_view_visualizer.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ FilePath LookupRecursively(const FilePath& folder, const FilePath& path) {
3838
}
3939

4040
static const FilePath STYLESHEET_PATH = LookupRecursively(CurrentDynamicObjectPath().DirName(), FilePath::FromUTF8Unsafe("src/webdriver/extension_qt/widget_view_visualizer.xsl"));
41+
static const QString STYLESHEET_WEB_PATH = "http://localhost:9517/widget_view_visualizer.xsl";
4142
static const FilePath PROCESSOR_PATH = LookupRecursively(CurrentDynamicObjectPath().DirName(), FilePath::FromUTF8Unsafe("src/third_party/saxon/saxon9he.jar"));
43+
static bool XSLT_PROCESS = false;
44+
static bool XSLT_INJECT_STYLESHEET = false;
4245

4346
QWidgetViewVisualizerSourceCommand::QWidgetViewVisualizerSourceCommand(Session* session, ViewId viewId, QWidget* view)
4447
: session_(session), viewId_(viewId), view_(view)
@@ -54,14 +57,20 @@ void QWidgetViewVisualizerSourceCommand::Execute(std::string* source, Error** er
5457
serializer.setViewId(viewId_);
5558
serializer.setDumpAll(true);
5659
serializer.setSupportedClasses(SUPPORTED_CLASSES);
60+
if (XSLT_INJECT_STYLESHEET) {
61+
serializer.setStylesheet(STYLESHEET_WEB_PATH);
62+
}
5763
serializer.createXml(view_);
5864
*source = byteArray.data();
5965

60-
#if defined(OS_LINUX)
6166
session_->logger().Log(kInfoLogLevel, "[VisualizerSource] before transform:");
6267
session_->logger().Log(kInfoLogLevel, *source);
63-
*source = transform(*source, STYLESHEET_PATH.value());
68+
69+
if (XSLT_PROCESS) {
70+
#if defined(OS_LINUX)
71+
*source = transform(*source, STYLESHEET_PATH.value());
6472
#endif
73+
}
6574
}
6675

6776
#if defined(OS_LINUX)

src/webdriver/webdriver_server.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
//#include "base/command_line.h"
1111
//#include "base/format_macros.h"
12+
#include "base/file_util.h"
1213
#include "base/json/json_reader.h"
1314
#include "base/memory/scoped_ptr.h"
1415
#include "base/string_split.h"
@@ -60,15 +61,15 @@ int Server::Configure(const CommandLine &options) {
6061
std::cerr << "Init failure: can't parse config file, skip options in config." << std::endl;
6162
}
6263

63-
ret_val = InitMongooseOptions();
64+
ret_val = InitLogging();
6465
if (ret_val) {
65-
std::cerr << "Init failure: can't init mongoose options." << std::endl;
66+
std::cerr << "Init failure: can't init logging." << std::endl;
6667
return ret_val;
6768
}
6869

69-
ret_val = InitLogging();
70+
ret_val = InitMongooseOptions();
7071
if (ret_val) {
71-
std::cerr << "Init failure: can't init logging." << std::endl;
72+
std::cerr << "Init failure: can't init mongoose options." << std::endl;
7273
return ret_val;
7374
}
7475

@@ -559,7 +560,7 @@ ListValue* Server::ListCommandSupportedMethods(const Command& command) {
559560

560561
int Server::InitMongooseOptions() {
561562
std::string port = "9517";
562-
std::string root;
563+
std::string root = "./web";
563564
int http_threads = 4;
564565

565566
if (options_->HasSwitch(webdriver::Switches::kPort))
@@ -572,7 +573,7 @@ int Server::InitMongooseOptions() {
572573
if (options_->HasSwitch(webdriver::Switches::kHttpThread)) {
573574
if (!base::StringToInt(options_->GetSwitchValueASCII(webdriver::Switches::kHttpThread),
574575
&http_threads)) {
575-
std::cerr << "'http-threads' option must be an integer";
576+
GlobalLogger::Log(kSevereLogLevel, "'http-threads' option must be an integer");
576577
return 1;
577578
}
578579
}
@@ -584,6 +585,10 @@ int Server::InitMongooseOptions() {
584585
if (!root.empty()) {
585586
mg_options_.push_back("document_root");
586587
mg_options_.push_back(root);
588+
589+
if (!file_util::PathExists(FilePath::FromUTF8Unsafe(root))) {
590+
GlobalLogger::Log(kSevereLogLevel, "Root '" + root + "' does not exist!");
591+
}
587592
}
588593
mg_options_.push_back("extra_mime_types");
589594
mg_options_.push_back(".xhtml=application/xhtml+xml");

web/FileSaver.js

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
/* FileSaver.js
2+
* A saveAs() FileSaver implementation.
3+
* 2013-01-23
4+
*
5+
* By Eli Grey, http://eligrey.com
6+
* License: X11/MIT
7+
* See LICENSE.md
8+
*/
9+
10+
/*global self */
11+
/*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true,
12+
plusplus: true */
13+
14+
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
15+
16+
var saveAs = saveAs
17+
|| (navigator.msSaveOrOpenBlob && navigator.msSaveOrOpenBlob.bind(navigator))
18+
|| (function(view) {
19+
"use strict";
20+
var
21+
doc = view.document
22+
// only get URL when necessary in case BlobBuilder.js hasn't overridden it yet
23+
, get_URL = function() {
24+
return view.URL || view.webkitURL || view;
25+
}
26+
, URL = view.URL || view.webkitURL || view
27+
, save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
28+
, can_use_save_link = !view.externalHost && "download" in save_link
29+
, click = function(node) {
30+
var event = doc.createEvent("MouseEvents");
31+
event.initMouseEvent(
32+
"click", true, false, view, 0, 0, 0, 0, 0
33+
, false, false, false, false, 0, null
34+
);
35+
node.dispatchEvent(event);
36+
}
37+
, webkit_req_fs = view.webkitRequestFileSystem
38+
, req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem
39+
, throw_outside = function (ex) {
40+
(view.setImmediate || view.setTimeout)(function() {
41+
throw ex;
42+
}, 0);
43+
}
44+
, force_saveable_type = "application/octet-stream"
45+
, fs_min_size = 0
46+
, deletion_queue = []
47+
, process_deletion_queue = function() {
48+
var i = deletion_queue.length;
49+
while (i--) {
50+
var file = deletion_queue[i];
51+
if (typeof file === "string") { // file is an object URL
52+
URL.revokeObjectURL(file);
53+
} else { // file is a File
54+
file.remove();
55+
}
56+
}
57+
deletion_queue.length = 0; // clear queue
58+
}
59+
, dispatch = function(filesaver, event_types, event) {
60+
event_types = [].concat(event_types);
61+
var i = event_types.length;
62+
while (i--) {
63+
var listener = filesaver["on" + event_types[i]];
64+
if (typeof listener === "function") {
65+
try {
66+
listener.call(filesaver, event || filesaver);
67+
} catch (ex) {
68+
throw_outside(ex);
69+
}
70+
}
71+
}
72+
}
73+
, FileSaver = function(blob, name) {
74+
// First try a.download, then web filesystem, then object URLs
75+
var
76+
filesaver = this
77+
, type = blob.type
78+
, blob_changed = false
79+
, object_url
80+
, target_view
81+
, get_object_url = function() {
82+
var object_url = get_URL().createObjectURL(blob);
83+
deletion_queue.push(object_url);
84+
return object_url;
85+
}
86+
, dispatch_all = function() {
87+
dispatch(filesaver, "writestart progress write writeend".split(" "));
88+
}
89+
// on any filesys errors revert to saving with object URLs
90+
, fs_error = function() {
91+
// don't create more object URLs than needed
92+
if (blob_changed || !object_url) {
93+
object_url = get_object_url(blob);
94+
}
95+
if (target_view) {
96+
target_view.location.href = object_url;
97+
} else {
98+
window.open(object_url, "_blank");
99+
}
100+
filesaver.readyState = filesaver.DONE;
101+
dispatch_all();
102+
}
103+
, abortable = function(func) {
104+
return function() {
105+
if (filesaver.readyState !== filesaver.DONE) {
106+
return func.apply(this, arguments);
107+
}
108+
};
109+
}
110+
, create_if_not_found = {create: true, exclusive: false}
111+
, slice
112+
;
113+
filesaver.readyState = filesaver.INIT;
114+
if (!name) {
115+
name = "download";
116+
}
117+
if (can_use_save_link) {
118+
object_url = get_object_url(blob);
119+
save_link.href = object_url;
120+
save_link.download = name;
121+
click(save_link);
122+
filesaver.readyState = filesaver.DONE;
123+
dispatch_all();
124+
return;
125+
}
126+
// Object and web filesystem URLs have a problem saving in Google Chrome when
127+
// viewed in a tab, so I force save with application/octet-stream
128+
// http://code.google.com/p/chromium/issues/detail?id=91158
129+
if (view.chrome && type && type !== force_saveable_type) {
130+
slice = blob.slice || blob.webkitSlice;
131+
blob = slice.call(blob, 0, blob.size, force_saveable_type);
132+
blob_changed = true;
133+
}
134+
// Since I can't be sure that the guessed media type will trigger a download
135+
// in WebKit, I append .download to the filename.
136+
// https://bugs.webkit.org/show_bug.cgi?id=65440
137+
if (webkit_req_fs && name !== "download") {
138+
name += ".download";
139+
}
140+
if (type === force_saveable_type || webkit_req_fs) {
141+
target_view = view;
142+
}
143+
if (!req_fs) {
144+
fs_error();
145+
return;
146+
}
147+
fs_min_size += blob.size;
148+
req_fs(view.TEMPORARY, fs_min_size, abortable(function(fs) {
149+
fs.root.getDirectory("saved", create_if_not_found, abortable(function(dir) {
150+
var save = function() {
151+
dir.getFile(name, create_if_not_found, abortable(function(file) {
152+
file.createWriter(abortable(function(writer) {
153+
writer.onwriteend = function(event) {
154+
target_view.location.href = file.toURL();
155+
deletion_queue.push(file);
156+
filesaver.readyState = filesaver.DONE;
157+
dispatch(filesaver, "writeend", event);
158+
};
159+
writer.onerror = function() {
160+
var error = writer.error;
161+
if (error.code !== error.ABORT_ERR) {
162+
fs_error();
163+
}
164+
};
165+
"writestart progress write abort".split(" ").forEach(function(event) {
166+
writer["on" + event] = filesaver["on" + event];
167+
});
168+
writer.write(blob);
169+
filesaver.abort = function() {
170+
writer.abort();
171+
filesaver.readyState = filesaver.DONE;
172+
};
173+
filesaver.readyState = filesaver.WRITING;
174+
}), fs_error);
175+
}), fs_error);
176+
};
177+
dir.getFile(name, {create: false}, abortable(function(file) {
178+
// delete file if it already exists
179+
file.remove();
180+
save();
181+
}), abortable(function(ex) {
182+
if (ex.code === ex.NOT_FOUND_ERR) {
183+
save();
184+
} else {
185+
fs_error();
186+
}
187+
}));
188+
}), fs_error);
189+
}), fs_error);
190+
}
191+
, FS_proto = FileSaver.prototype
192+
, saveAs = function(blob, name) {
193+
return new FileSaver(blob, name);
194+
}
195+
;
196+
FS_proto.abort = function() {
197+
var filesaver = this;
198+
filesaver.readyState = filesaver.DONE;
199+
dispatch(filesaver, "abort");
200+
};
201+
FS_proto.readyState = FS_proto.INIT = 0;
202+
FS_proto.WRITING = 1;
203+
FS_proto.DONE = 2;
204+
205+
FS_proto.error =
206+
FS_proto.onwritestart =
207+
FS_proto.onprogress =
208+
FS_proto.onwrite =
209+
FS_proto.onabort =
210+
FS_proto.onerror =
211+
FS_proto.onwriteend =
212+
null;
213+
214+
view.addEventListener("unload", process_deletion_queue, false);
215+
return saveAs;
216+
}(self));

0 commit comments

Comments
 (0)