Skip to content

Commit d3a7901

Browse files
committed
Merge pull request electron#4 from atom/master
Update from original
2 parents 25a2f28 + 6c8a9cb commit d3a7901

File tree

110 files changed

+1204
-197
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1204
-197
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ possible with your report. If you can, please include:
3030
* Follow the CoffeeScript, JavaScript, C++ and Python [coding style defined in docs](/docs/development/coding-style.md).
3131
* Write documentation in [Markdown](https://daringfireball.net/projects/markdown).
3232
See the [Documentation Styleguide](/docs/styleguide.md).
33-
* Use short, present tense commit messages. See [Commit Message Styleguide](#git-commit-messages-styleguide).
33+
* Use short, present tense commit messages. See [Commit Message Styleguide](#git-commit-messages).
3434

3535
## Styleguides
3636

README-ko.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Electron을 빌드 하는 방법과 프로젝트에 기여하는 방법도 문
4141
## 참조 문서 (번역)
4242

4343
- [브라질 포르투칼어](https://github.com/atom/electron/tree/master/docs-translations/pt-BR)
44-
- [한국어](https://github.com/atom/electron/tree/master/docs-translations/ko)
44+
- [한국어](https://github.com/atom/electron/tree/master/docs-translations/ko-KR)
4545
- [일본어](https://github.com/atom/electron/tree/master/docs-translations/jp)
4646
- [스페인어](https://github.com/atom/electron/tree/master/docs-translations/es)
4747
- [중국어 간체](https://github.com/atom/electron/tree/master/docs-translations/zh-CN)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ contains documents describing how to build and contribute to Electron.
4747
## Documentation Translations
4848

4949
- [Brazilian Portuguese](https://github.com/atom/electron/tree/master/docs-translations/pt-BR)
50-
- [Korean](https://github.com/atom/electron/tree/master/docs-translations/ko)
50+
- [Korean](https://github.com/atom/electron/tree/master/docs-translations/ko-KR)
5151
- [Japanese](https://github.com/atom/electron/tree/master/docs-translations/jp)
5252
- [Spanish](https://github.com/atom/electron/tree/master/docs-translations/es)
5353
- [Simplified Chinese](https://github.com/atom/electron/tree/master/docs-translations/zh-CN)

atom.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'product_name%': 'Electron',
55
'company_name%': 'GitHub, Inc',
66
'company_abbr%': 'github',
7-
'version%': '0.32.3',
7+
'version%': '0.33.1',
88
},
99
'includes': [
1010
'filenames.gypi',

atom/browser/api/atom_api_app.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "native_mate/dictionary.h"
3131
#include "native_mate/object_template_builder.h"
3232
#include "net/ssl/ssl_cert_request_info.h"
33+
#include "ui/base/l10n/l10n_util.h"
3334

3435
#if defined(OS_WIN)
3536
#include "base/strings/utf_string_conversions.h"
@@ -248,6 +249,10 @@ void App::SetAppUserModelId(const std::string& app_id) {
248249
#endif
249250
}
250251

252+
std::string App::GetLocale() {
253+
return l10n_util::GetApplicationLocale("");
254+
}
255+
251256
v8::Local<v8::Value> App::DefaultSession(v8::Isolate* isolate) {
252257
if (default_session_.IsEmpty())
253258
return v8::Null(isolate);
@@ -278,6 +283,7 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
278283
.SetMethod("getPath", &App::GetPath)
279284
.SetMethod("setDesktopName", &App::SetDesktopName)
280285
.SetMethod("setAppUserModelId", &App::SetAppUserModelId)
286+
.SetMethod("getLocale", &App::GetLocale)
281287
.SetProperty("defaultSession", &App::DefaultSession);
282288
}
283289

atom/browser/api/atom_api_app.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class App : public mate::EventEmitter,
6565

6666
void SetDesktopName(const std::string& desktop_name);
6767
void SetAppUserModelId(const std::string& app_id);
68+
std::string GetLocale();
6869
v8::Local<v8::Value> DefaultSession(v8::Isolate* isolate);
6970

7071
v8::Global<v8::Value> default_session_;

atom/browser/api/atom_api_web_contents.cc

Lines changed: 121 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "atom/browser/web_view_guest_delegate.h"
1616
#include "atom/common/api/api_messages.h"
1717
#include "atom/common/api/event_emitter_caller.h"
18+
#include "atom/common/native_mate_converters/blink_converter.h"
1819
#include "atom/common/native_mate_converters/callback.h"
1920
#include "atom/common/native_mate_converters/file_path_converter.h"
2021
#include "atom/common/native_mate_converters/gfx_converter.h"
@@ -27,13 +28,16 @@
2728
#include "brightray/browser/inspectable_web_contents.h"
2829
#include "chrome/browser/printing/print_view_manager_basic.h"
2930
#include "chrome/browser/printing/print_preview_message_handler.h"
31+
#include "content/common/view_messages.h"
3032
#include "content/public/browser/favicon_status.h"
33+
#include "content/public/browser/native_web_keyboard_event.h"
3134
#include "content/public/browser/navigation_details.h"
3235
#include "content/public/browser/navigation_entry.h"
3336
#include "content/public/browser/plugin_service.h"
3437
#include "content/public/browser/render_frame_host.h"
3538
#include "content/public/browser/render_process_host.h"
3639
#include "content/public/browser/render_view_host.h"
40+
#include "content/public/browser/render_widget_host_view.h"
3741
#include "content/public/browser/resource_request_details.h"
3842
#include "content/public/browser/service_worker_context.h"
3943
#include "content/public/browser/storage_partition.h"
@@ -44,6 +48,7 @@
4448
#include "net/http/http_response_headers.h"
4549
#include "net/url_request/static_http_user_agent_settings.h"
4650
#include "net/url_request/url_request_context.h"
51+
#include "third_party/WebKit/public/web/WebInputEvent.h"
4752

4853
#include "atom/common/node_includes.h"
4954

@@ -115,6 +120,33 @@ struct Converter<WindowOpenDisposition> {
115120
}
116121
};
117122

123+
template<>
124+
struct Converter<net::HttpResponseHeaders*> {
125+
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
126+
net::HttpResponseHeaders* headers) {
127+
base::DictionaryValue response_headers;
128+
if (headers) {
129+
void* iter = nullptr;
130+
std::string key;
131+
std::string value;
132+
while (headers->EnumerateHeaderLines(&iter, &key, &value)) {
133+
key = base::StringToLowerASCII(key);
134+
value = base::StringToLowerASCII(value);
135+
if (response_headers.HasKey(key)) {
136+
base::ListValue* values = nullptr;
137+
if (response_headers.GetList(key, &values))
138+
values->AppendString(value);
139+
} else {
140+
scoped_ptr<base::ListValue> values(new base::ListValue());
141+
values->AppendString(value);
142+
response_headers.Set(key, values.Pass());
143+
}
144+
}
145+
}
146+
return ConvertToV8(isolate, response_headers);
147+
}
148+
};
149+
118150
} // namespace mate
119151

120152

@@ -126,7 +158,7 @@ namespace {
126158

127159
v8::Persistent<v8::ObjectTemplate> template_;
128160

129-
// The wrapWebContents funtion which is implemented in JavaScript
161+
// The wrapWebContents function which is implemented in JavaScript
130162
using WrapWebContentsCallback = base::Callback<void(v8::Local<v8::Value>)>;
131163
WrapWebContentsCallback g_wrap_web_contents;
132164

@@ -196,7 +228,7 @@ WebContents::WebContents(v8::Isolate* isolate,
196228
AttachAsUserData(web_contents);
197229
InitWithWebContents(web_contents);
198230

199-
// Save the preferences.
231+
// Save the preferences in C++.
200232
base::DictionaryValue web_preferences;
201233
mate::ConvertFromV8(isolate, options.GetHandle(), &web_preferences);
202234
new WebContentsPreferences(web_contents, &web_preferences);
@@ -409,38 +441,14 @@ void WebContents::DidStopLoading() {
409441

410442
void WebContents::DidGetResourceResponseStart(
411443
const content::ResourceRequestDetails& details) {
412-
v8::Locker locker(isolate());
413-
v8::HandleScope handle_scope(isolate());
414-
base::DictionaryValue response_headers;
415-
416-
net::HttpResponseHeaders* headers = details.headers.get();
417-
if (!headers)
418-
return;
419-
void* iter = nullptr;
420-
std::string key;
421-
std::string value;
422-
while (headers->EnumerateHeaderLines(&iter, &key, &value)) {
423-
key = base::StringToLowerASCII(key);
424-
value = base::StringToLowerASCII(value);
425-
if (response_headers.HasKey(key)) {
426-
base::ListValue* values = nullptr;
427-
if (response_headers.GetList(key, &values))
428-
values->AppendString(value);
429-
} else {
430-
scoped_ptr<base::ListValue> values(new base::ListValue());
431-
values->AppendString(value);
432-
response_headers.Set(key, values.Pass());
433-
}
434-
}
435-
436444
Emit("did-get-response-details",
437445
details.socket_address.IsEmpty(),
438446
details.url,
439447
details.original_url,
440448
details.http_response_code,
441449
details.method,
442450
details.referrer,
443-
response_headers);
451+
details.headers.get());
444452
}
445453

446454
void WebContents::DidGetRedirectForResourceRequest(
@@ -449,7 +457,11 @@ void WebContents::DidGetRedirectForResourceRequest(
449457
Emit("did-get-redirect-request",
450458
details.url,
451459
details.new_url,
452-
(details.resource_type == content::RESOURCE_TYPE_MAIN_FRAME));
460+
(details.resource_type == content::RESOURCE_TYPE_MAIN_FRAME),
461+
details.http_response_code,
462+
details.method,
463+
details.referrer,
464+
details.headers.get());
453465
}
454466

455467
void WebContents::DidNavigateMainFrame(
@@ -640,6 +652,21 @@ bool WebContents::IsDevToolsOpened() {
640652
return managed_web_contents()->IsDevToolsViewShowing();
641653
}
642654

655+
void WebContents::EnableDeviceEmulation(
656+
const blink::WebDeviceEmulationParams& params) {
657+
if (type_ == REMOTE)
658+
return;
659+
660+
Send(new ViewMsg_EnableDeviceEmulation(routing_id(), params));
661+
}
662+
663+
void WebContents::DisableDeviceEmulation() {
664+
if (type_ == REMOTE)
665+
return;
666+
667+
Send(new ViewMsg_DisableDeviceEmulation(routing_id()));
668+
}
669+
643670
void WebContents::ToggleDevTools() {
644671
if (IsDevToolsOpened())
645672
CloseDevTools();
@@ -796,6 +823,56 @@ bool WebContents::SendIPCMessage(const base::string16& channel,
796823
return Send(new AtomViewMsg_Message(routing_id(), channel, args));
797824
}
798825

826+
void WebContents::SendInputEvent(v8::Isolate* isolate,
827+
v8::Local<v8::Value> input_event) {
828+
const auto view = web_contents()->GetRenderWidgetHostView();
829+
if (!view)
830+
return;
831+
const auto host = view->GetRenderWidgetHost();
832+
if (!host)
833+
return;
834+
835+
int type = mate::GetWebInputEventType(isolate, input_event);
836+
if (blink::WebInputEvent::isMouseEventType(type)) {
837+
blink::WebMouseEvent mouse_event;
838+
if (mate::ConvertFromV8(isolate, input_event, &mouse_event)) {
839+
host->ForwardMouseEvent(mouse_event);
840+
return;
841+
}
842+
} else if (blink::WebInputEvent::isKeyboardEventType(type)) {
843+
content::NativeWebKeyboardEvent keyboard_event;;
844+
if (mate::ConvertFromV8(isolate, input_event, &keyboard_event)) {
845+
host->ForwardKeyboardEvent(keyboard_event);
846+
return;
847+
}
848+
} else if (type == blink::WebInputEvent::MouseWheel) {
849+
blink::WebMouseWheelEvent mouse_wheel_event;
850+
if (mate::ConvertFromV8(isolate, input_event, &mouse_wheel_event)) {
851+
host->ForwardWheelEvent(mouse_wheel_event);
852+
return;
853+
}
854+
}
855+
856+
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
857+
isolate, "Invalid event object")));
858+
}
859+
860+
void WebContents::BeginFrameSubscription(
861+
const FrameSubscriber::FrameCaptureCallback& callback) {
862+
const auto view = web_contents()->GetRenderWidgetHostView();
863+
if (view) {
864+
scoped_ptr<FrameSubscriber> frame_subscriber(new FrameSubscriber(
865+
isolate(), view->GetVisibleViewportSize(), callback));
866+
view->BeginFrameSubscription(frame_subscriber.Pass());
867+
}
868+
}
869+
870+
void WebContents::EndFrameSubscription() {
871+
const auto view = web_contents()->GetRenderWidgetHostView();
872+
if (view)
873+
view->EndFrameSubscription();
874+
}
875+
799876
void WebContents::SetSize(const SetSizeParams& params) {
800877
if (guest_delegate_)
801878
guest_delegate_->SetSize(params);
@@ -810,6 +887,12 @@ bool WebContents::IsGuest() const {
810887
return type_ == WEB_VIEW;
811888
}
812889

890+
v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
891+
WebContentsPreferences* web_preferences =
892+
WebContentsPreferences::FromWebContents(web_contents());
893+
return mate::ConvertToV8(isolate, *web_preferences->web_preferences());
894+
}
895+
813896
mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
814897
v8::Isolate* isolate) {
815898
if (template_.IsEmpty())
@@ -836,6 +919,10 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
836919
.SetMethod("openDevTools", &WebContents::OpenDevTools)
837920
.SetMethod("closeDevTools", &WebContents::CloseDevTools)
838921
.SetMethod("isDevToolsOpened", &WebContents::IsDevToolsOpened)
922+
.SetMethod("enableDeviceEmulation",
923+
&WebContents::EnableDeviceEmulation)
924+
.SetMethod("disableDeviceEmulation",
925+
&WebContents::DisableDeviceEmulation)
839926
.SetMethod("toggleDevTools", &WebContents::ToggleDevTools)
840927
.SetMethod("inspectElement", &WebContents::InspectElement)
841928
.SetMethod("setAudioMuted", &WebContents::SetAudioMuted)
@@ -854,9 +941,14 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
854941
.SetMethod("focus", &WebContents::Focus)
855942
.SetMethod("tabTraverse", &WebContents::TabTraverse)
856943
.SetMethod("_send", &WebContents::SendIPCMessage, true)
944+
.SetMethod("sendInputEvent", &WebContents::SendInputEvent)
945+
.SetMethod("beginFrameSubscription",
946+
&WebContents::BeginFrameSubscription)
947+
.SetMethod("endFrameSubscription", &WebContents::EndFrameSubscription)
857948
.SetMethod("setSize", &WebContents::SetSize)
858949
.SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency)
859950
.SetMethod("isGuest", &WebContents::IsGuest)
951+
.SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
860952
.SetMethod("hasServiceWorker", &WebContents::HasServiceWorker)
861953
.SetMethod("unregisterServiceWorker",
862954
&WebContents::UnregisterServiceWorker)
@@ -910,7 +1002,7 @@ mate::Handle<WebContents> WebContents::CreateFrom(
9101002
// static
9111003
mate::Handle<WebContents> WebContents::Create(
9121004
v8::Isolate* isolate, const mate::Dictionary& options) {
913-
auto handle = mate::CreateHandle(isolate, new WebContents(isolate, options));
1005+
auto handle = mate::CreateHandle(isolate, new WebContents(isolate, options));
9141006
g_wrap_web_contents.Run(handle.ToV8());
9151007
return handle;
9161008
}

atom/browser/api/atom_api_web_contents.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@
88
#include <string>
99
#include <vector>
1010

11+
#include "atom/browser/api/frame_subscriber.h"
1112
#include "atom/browser/api/trackable_object.h"
1213
#include "atom/browser/common_web_contents_delegate.h"
1314
#include "content/public/browser/web_contents_observer.h"
1415
#include "content/public/common/favicon_url.h"
1516
#include "native_mate/handle.h"
1617
#include "ui/gfx/image/image.h"
1718

19+
namespace blink {
20+
struct WebDeviceEmulationParams;
21+
}
22+
1823
namespace brightray {
1924
class InspectableWebContents;
2025
}
@@ -74,6 +79,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
7479
void CloseDevTools();
7580
bool IsDevToolsOpened();
7681
void ToggleDevTools();
82+
void EnableDeviceEmulation(const blink::WebDeviceEmulationParams& params);
83+
void DisableDeviceEmulation();
7784
void InspectElement(int x, int y);
7885
void InspectServiceWorker();
7986
v8::Local<v8::Value> Session(v8::Isolate* isolate);
@@ -108,15 +115,26 @@ class WebContents : public mate::TrackableObject<WebContents>,
108115
void Focus();
109116
void TabTraverse(bool reverse);
110117

111-
// Sending messages to browser.
118+
// Send messages to browser.
112119
bool SendIPCMessage(const base::string16& channel,
113120
const base::ListValue& args);
114121

122+
// Send WebInputEvent to the page.
123+
void SendInputEvent(v8::Isolate* isolate, v8::Local<v8::Value> input_event);
124+
125+
// Subscribe to the frame updates.
126+
void BeginFrameSubscription(
127+
const FrameSubscriber::FrameCaptureCallback& callback);
128+
void EndFrameSubscription();
129+
115130
// Methods for creating <webview>.
116131
void SetSize(const SetSizeParams& params);
117132
void SetAllowTransparency(bool allow);
118133
bool IsGuest() const;
119134

135+
// Returns the web preferences of current WebContents.
136+
v8::Local<v8::Value> GetWebPreferences(v8::Isolate* isolate);
137+
120138
protected:
121139
explicit WebContents(content::WebContents* web_contents);
122140
WebContents(v8::Isolate* isolate, const mate::Dictionary& options);

0 commit comments

Comments
 (0)