commit
7f1cb9f90a
8 changed files with 104 additions and 10 deletions
|
@ -19,6 +19,8 @@
|
|||
#include "base/prefs/pref_service.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/thread_task_runner_handle.h"
|
||||
#include "brightray/browser/net/devtools_network_conditions.h"
|
||||
#include "brightray/browser/net/devtools_network_controller.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
|
@ -294,6 +296,43 @@ void Session::SetDownloadPath(const base::FilePath& path) {
|
|||
prefs::kDownloadDefaultDirectory, path);
|
||||
}
|
||||
|
||||
void Session::EnableNetworkEmulation(const mate::Dictionary& options) {
|
||||
scoped_ptr<brightray::DevToolsNetworkConditions> conditions;
|
||||
bool offline = false;
|
||||
double latency, download_throughput, upload_throughput;
|
||||
if (options.Get("offline", &offline) && offline) {
|
||||
conditions.reset(new brightray::DevToolsNetworkConditions(offline));
|
||||
} else {
|
||||
options.Get("latency", &latency);
|
||||
options.Get("downloadThroughput", &download_throughput);
|
||||
options.Get("uploadThroughput", &upload_throughput);
|
||||
conditions.reset(
|
||||
new brightray::DevToolsNetworkConditions(false,
|
||||
latency,
|
||||
download_throughput,
|
||||
upload_throughput));
|
||||
}
|
||||
auto controller = browser_context_->GetDevToolsNetworkController();
|
||||
|
||||
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
||||
base::Bind(&brightray::DevToolsNetworkController::SetNetworkState,
|
||||
base::Unretained(controller),
|
||||
std::string(),
|
||||
base::Passed(&conditions)));
|
||||
}
|
||||
|
||||
void Session::DisableNetworkEmulation() {
|
||||
scoped_ptr<brightray::DevToolsNetworkConditions> conditions(
|
||||
new brightray::DevToolsNetworkConditions(false));
|
||||
auto controller = browser_context_->GetDevToolsNetworkController();
|
||||
|
||||
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
||||
base::Bind(&brightray::DevToolsNetworkController::SetNetworkState,
|
||||
base::Unretained(controller),
|
||||
std::string(),
|
||||
base::Passed(&conditions)));
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> Session::Cookies(v8::Isolate* isolate) {
|
||||
if (cookies_.IsEmpty()) {
|
||||
auto handle = atom::api::Cookies::Create(isolate, browser_context());
|
||||
|
@ -310,6 +349,8 @@ mate::ObjectTemplateBuilder Session::GetObjectTemplateBuilder(
|
|||
.SetMethod("clearStorageData", &Session::ClearStorageData)
|
||||
.SetMethod("setProxy", &Session::SetProxy)
|
||||
.SetMethod("setDownloadPath", &Session::SetDownloadPath)
|
||||
.SetMethod("enableNetworkEmulation", &Session::EnableNetworkEmulation)
|
||||
.SetMethod("disableNetworkEmulation", &Session::DisableNetworkEmulation)
|
||||
.SetProperty("cookies", &Session::Cookies);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ class FilePath;
|
|||
|
||||
namespace mate {
|
||||
class Arguments;
|
||||
class Dictionary;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
@ -65,6 +66,8 @@ class Session: public mate::TrackableObject<Session>,
|
|||
void ClearStorageData(mate::Arguments* args);
|
||||
void SetProxy(const std::string& proxy, const base::Closure& callback);
|
||||
void SetDownloadPath(const base::FilePath& path);
|
||||
void EnableNetworkEmulation(const mate::Dictionary& options);
|
||||
void DisableNetworkEmulation();
|
||||
v8::Local<v8::Value> Cookies(v8::Isolate* isolate);
|
||||
|
||||
// Cached object for cookies API.
|
||||
|
|
|
@ -79,6 +79,9 @@ class FileDialog {
|
|||
if (!title.empty())
|
||||
GetPtr()->SetTitle(base::UTF8ToUTF16(title).c_str());
|
||||
|
||||
if (!filterspec.empty())
|
||||
GetPtr()->SetDefaultExtension(filterspec.front().pszSpec);
|
||||
|
||||
SetDefaultFolder(default_path);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "atom/common/keyboad_util.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "content/public/browser/native_web_keyboard_event.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
|
||||
|
@ -29,10 +30,10 @@ int VectorToBitArray(const std::vector<T>& vec) {
|
|||
namespace mate {
|
||||
|
||||
template<>
|
||||
struct Converter<char> {
|
||||
struct Converter<base::char16> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||
char* out) {
|
||||
std::string code = base::StringToLowerASCII(V8ToString(val));
|
||||
base::char16* out) {
|
||||
base::string16 code = base::UTF8ToUTF16(V8ToString(val));
|
||||
if (code.length() != 1)
|
||||
return false;
|
||||
*out = code[0];
|
||||
|
@ -77,6 +78,21 @@ struct Converter<blink::WebInputEvent::Type> {
|
|||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Converter<blink::WebMouseEvent::Button> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||
blink::WebMouseEvent::Button* out) {
|
||||
std::string button = base::StringToLowerASCII(V8ToString(val));
|
||||
if (button == "left")
|
||||
*out = blink::WebMouseEvent::Button::ButtonLeft;
|
||||
else if (button == "middle")
|
||||
*out = blink::WebMouseEvent::Button::ButtonMiddle;
|
||||
else if (button == "right")
|
||||
*out = blink::WebMouseEvent::Button::ButtonRight;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Converter<blink::WebInputEvent::Modifiers> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
||||
|
@ -142,16 +158,19 @@ bool Converter<blink::WebKeyboardEvent>::FromV8(
|
|||
return false;
|
||||
if (!ConvertFromV8(isolate, val, static_cast<blink::WebInputEvent*>(out)))
|
||||
return false;
|
||||
char code;
|
||||
base::char16 code;
|
||||
if (!dict.Get("keyCode", &code))
|
||||
return false;
|
||||
bool shifted = false;
|
||||
out->windowsKeyCode = atom::KeyboardCodeFromCharCode(code, &shifted);
|
||||
if (out->windowsKeyCode == ui::VKEY_UNKNOWN)
|
||||
return false;
|
||||
if (shifted)
|
||||
out->modifiers |= blink::WebInputEvent::ShiftKey;
|
||||
out->setKeyIdentifierFromWindowsKeyCode();
|
||||
if (out->type == blink::WebInputEvent::Char ||
|
||||
out->type == blink::WebInputEvent::RawKeyDown) {
|
||||
out->text[0] = code;
|
||||
out->unmodifiedText[0] = code;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -176,6 +195,7 @@ bool Converter<blink::WebMouseEvent>::FromV8(
|
|||
return false;
|
||||
if (!dict.Get("x", &out->x) || !dict.Get("y", &out->y))
|
||||
return false;
|
||||
dict.Get("button", &out->button);
|
||||
dict.Get("globalX", &out->globalX);
|
||||
dict.Get("globalY", &out->globalY);
|
||||
dict.Get("movementX", &out->movementX);
|
||||
|
|
|
@ -191,3 +191,30 @@ proxy-uri = [<proxy-scheme>"://"]<proxy-host>[":"<proxy-port>]
|
|||
|
||||
Sets download saving directory. By default, the download directory will be the
|
||||
`Downloads` under the respective app folder.
|
||||
|
||||
### `session.enableNetworkEmulation(options)`
|
||||
|
||||
* `options` Object
|
||||
* `offline` Boolean - Whether to emulate network outage.
|
||||
* `latency` Double - RTT in ms
|
||||
* `downloadThroughput` Double - Download rate in Bps
|
||||
* `uploadThroughput` Double - Upload rate in Bps
|
||||
|
||||
Emulates network with the given configuration for the `session`.
|
||||
|
||||
```javascript
|
||||
// To emulate a GPRS connection with 50kbps throughput and 500 ms latency.
|
||||
window.webContents.session.enableNetworkEmulation({
|
||||
latency: 500,
|
||||
downloadThroughput: 6400,
|
||||
uploadThroughput: 6400
|
||||
});
|
||||
|
||||
// To emulate a network outage.
|
||||
window.webContents.session.enableNetworkEmulation({offline: true});
|
||||
```
|
||||
|
||||
### `session.disableNetworkEmulation`
|
||||
|
||||
Disables any network emulation already active for the `session`. Resets to
|
||||
the original network configuration.
|
||||
|
|
|
@ -534,13 +534,13 @@ Sends an input `event` to the page.
|
|||
For keyboard events, the `event` object also have following properties:
|
||||
|
||||
* `keyCode` String (**required**) - A single character that will be sent as
|
||||
keyboard event. Can be any ASCII character on the keyboard, like `a`, `1`
|
||||
and `=`.
|
||||
keyboard event. Can be any UTF-8 character.
|
||||
|
||||
For mouse events, the `event` object also have following properties:
|
||||
|
||||
* `x` Integer (**required**)
|
||||
* `y` Integer (**required**)
|
||||
* `button` String - The button pressed, can be `left`, `middle`, `right`
|
||||
* `globalX` Integer
|
||||
* `globalY` Integer
|
||||
* `movementX` Integer
|
||||
|
|
2
vendor/brightray
vendored
2
vendor/brightray
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 8e443520e695674fd26585cfa24a0ec0b6140c27
|
||||
Subproject commit 75f7d3fd88ae60026a0717b93e3bf7182f827dc3
|
2
vendor/node
vendored
2
vendor/node
vendored
|
@ -1 +1 @@
|
|||
Subproject commit ac25693ad1d4c248e69a89147fd3995c3bf6c946
|
||||
Subproject commit f4243f5c84a371632d8d72a1a2210a0e994afdcc
|
Loading…
Reference in a new issue