Skip to content

Commit 9fd1e2c

Browse files
authored
Merge branch 'master' into felix-notification-docs
2 parents d5c4ad5 + 98d17d6 commit 9fd1e2c

File tree

243 files changed

+6019
-1814
lines changed

Some content is hidden

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

243 files changed

+6019
-1814
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![devDependency Status](https://david-dm.org/electron/electron/dev-status.svg)](https://david-dm.org/electron/electron?type=dev)
66
[![Join the Electron Community on Slack](http://atom-slack.herokuapp.com/badge.svg)](http://atom-slack.herokuapp.com/)
77

8-
:memo: Available Translations: [Korean](https://github.com/electron/electron/tree/master/docs-translations/ko-KR/project/README.md) | [Simplified Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-CN/project/README.md) | [Brazilian Portuguese](https://github.com/electron/electron/tree/master/docs-translations/pt-BR/project/README.md) | [Traditional Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-TW/project/README.md) | [Spanish](https://github.com/electron/electron/tree/master/docs-translations/es/project/README.md)
8+
:memo: Available Translations: [Korean](https://github.com/electron/electron/tree/master/docs-translations/ko-KR/project/README.md) | [Simplified Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-CN/project/README.md) | [Brazilian Portuguese](https://github.com/electron/electron/tree/master/docs-translations/pt-BR/project/README.md) | [Traditional Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-TW/project/README.md) | [Spanish](https://github.com/electron/electron/tree/master/docs-translations/es/project/README.md) | [Turkish](https://github.com/electron/electron/tree/master/docs-translations/tr-TR/project/README.md)
99

1010
The Electron framework lets you write cross-platform desktop applications
1111
using JavaScript, HTML and CSS. It is based on [Node.js](https://nodejs.org/) and
@@ -75,7 +75,7 @@ forums
7575
- [`electron-br`](https://electron-br.slack.com) *(Brazilian Portuguese)*
7676
- [`electron-kr`](http://www.meetup.com/electron-kr/) *(Korean)*
7777
- [`electron-jp`](https://electron-jp.slack.com) *(Japanese)*
78-
- [`electron-tr`](http://www.meetup.com/Electron-JS-Istanbul/) *(Turkish)*
78+
- [`electron-tr`](https://electron-tr.slack.com) *(Turkish)*
7979
- [`electron-id`](https://electron-id.slack.com) *(Indonesia)*
8080

8181
Check out [awesome-electron](https://github.com/sindresorhus/awesome-electron)

atom/app/atom_content_client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ content::PepperPluginInfo CreatePepperFlashInfo(const base::FilePath& path,
4444

4545
std::vector<std::string> flash_version_numbers = base::SplitString(
4646
version, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
47-
if (flash_version_numbers.size() < 1)
47+
if (flash_version_numbers.empty())
4848
flash_version_numbers.push_back("11");
4949
// |SplitString()| puts in an empty string given an empty string. :(
5050
else if (flash_version_numbers[0].empty())

atom/browser/api/atom_api_app.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ void OnClientCertificateSelected(
427427

428428
auto certs = net::X509Certificate::CreateCertificateListFromBytes(
429429
data.c_str(), data.length(), net::X509Certificate::FORMAT_AUTO);
430-
if (certs.size() > 0)
430+
if (!certs.empty())
431431
delegate->ContinueWithCertificate(certs[0].get());
432432
}
433433

@@ -520,7 +520,7 @@ void App::OnQuit() {
520520
int exitCode = AtomBrowserMainParts::Get()->GetExitCode();
521521
Emit("quit", exitCode);
522522

523-
if (process_singleton_.get()) {
523+
if (process_singleton_) {
524524
process_singleton_->Cleanup();
525525
process_singleton_.reset();
526526
}
@@ -655,6 +655,14 @@ void App::OnGpuProcessCrashed(base::TerminationStatus status) {
655655
status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
656656
}
657657

658+
base::FilePath App::GetAppPath() const {
659+
return app_path_;
660+
}
661+
662+
void App::SetAppPath(const base::FilePath& app_path) {
663+
app_path_ = app_path;
664+
}
665+
658666
base::FilePath App::GetPath(mate::Arguments* args, const std::string& name) {
659667
bool succeed = false;
660668
base::FilePath path;
@@ -695,7 +703,7 @@ std::string App::GetLocale() {
695703

696704
bool App::MakeSingleInstance(
697705
const ProcessSingleton::NotificationCallback& callback) {
698-
if (process_singleton_.get())
706+
if (process_singleton_)
699707
return false;
700708

701709
base::FilePath user_dir;
@@ -716,7 +724,7 @@ bool App::MakeSingleInstance(
716724
}
717725

718726
void App::ReleaseSingleInstance() {
719-
if (process_singleton_.get()) {
727+
if (process_singleton_) {
720728
process_singleton_->Cleanup();
721729
process_singleton_.reset();
722730
}
@@ -959,6 +967,8 @@ void App::BuildPrototype(
959967
.SetMethod("isUnityRunning",
960968
base::Bind(&Browser::IsUnityRunning, browser))
961969
#endif
970+
.SetMethod("setAppPath", &App::SetAppPath)
971+
.SetMethod("getAppPath", &App::GetAppPath)
962972
.SetMethod("setPath", &App::SetPath)
963973
.SetMethod("getPath", &App::GetPath)
964974
.SetMethod("setDesktopName", &App::SetDesktopName)

atom/browser/api/atom_api_app.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class App : public AtomBrowserClient::Delegate,
7070
std::unique_ptr<CertificateManagerModel> model);
7171
#endif
7272

73+
base::FilePath GetAppPath() const;
74+
7375
protected:
7476
explicit App(v8::Isolate* isolate);
7577
~App() override;
@@ -115,6 +117,8 @@ class App : public AtomBrowserClient::Delegate,
115117
void OnGpuProcessCrashed(base::TerminationStatus status) override;
116118

117119
private:
120+
void SetAppPath(const base::FilePath& app_path);
121+
118122
// Get/Set the pre-defined path in PathService.
119123
base::FilePath GetPath(mate::Arguments* args, const std::string& name);
120124
void SetPath(mate::Arguments* args,
@@ -154,6 +158,8 @@ class App : public AtomBrowserClient::Delegate,
154158
// Tracks tasks requesting file icons.
155159
base::CancelableTaskTracker cancelable_task_tracker_;
156160

161+
base::FilePath app_path_;
162+
157163
DISALLOW_COPY_AND_ASSIGN(App);
158164
};
159165

atom/browser/api/atom_api_auto_updater.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "atom/browser/browser.h"
88
#include "atom/browser/native_window.h"
99
#include "atom/browser/window_list.h"
10+
#include "atom/common/api/event_emitter_caller.h"
1011
#include "atom/common/native_mate_converters/callback.h"
1112
#include "atom/common/node_includes.h"
1213
#include "base/time/time.h"
@@ -47,7 +48,9 @@ void AutoUpdater::OnError(const std::string& message) {
4748
v8::Locker locker(isolate());
4849
v8::HandleScope handle_scope(isolate());
4950
auto error = v8::Exception::Error(mate::StringToV8(isolate(), message));
50-
EmitCustomEvent(
51+
mate::EmitEvent(
52+
isolate(),
53+
GetWrapper(),
5154
"error",
5255
error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked(),
5356
// Message is also emitted to keep compatibility with old code.
@@ -87,16 +90,14 @@ void AutoUpdater::SetFeedURL(const std::string& url, mate::Arguments* args) {
8790

8891
void AutoUpdater::QuitAndInstall() {
8992
// If we don't have any window then quitAndInstall immediately.
90-
WindowList* window_list = WindowList::GetInstance();
91-
if (window_list->size() == 0) {
93+
if (WindowList::IsEmpty()) {
9294
auto_updater::AutoUpdater::QuitAndInstall();
9395
return;
9496
}
9597

9698
// Otherwise do the restart after all windows have been closed.
97-
window_list->AddObserver(this);
98-
for (NativeWindow* window : *window_list)
99-
window->Close();
99+
WindowList::AddObserver(this);
100+
WindowList::CloseAllWindows();
100101
}
101102

102103
// static
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
// Copyright (c) 2017 GitHub, Inc.
2+
// Use of this source code is governed by the MIT license that can be
3+
// found in the LICENSE file.
4+
5+
#include "atom/browser/api/atom_api_browser_view.h"
6+
7+
#include "atom/browser/api/atom_api_web_contents.h"
8+
#include "atom/browser/browser.h"
9+
#include "atom/browser/native_browser_view.h"
10+
#include "atom/common/color_util.h"
11+
#include "atom/common/native_mate_converters/gfx_converter.h"
12+
#include "atom/common/native_mate_converters/value_converter.h"
13+
#include "atom/common/node_includes.h"
14+
#include "atom/common/options_switches.h"
15+
#include "native_mate/constructor.h"
16+
#include "native_mate/dictionary.h"
17+
#include "ui/gfx/geometry/rect.h"
18+
19+
namespace mate {
20+
21+
template <>
22+
struct Converter<atom::AutoResizeFlags> {
23+
static bool FromV8(v8::Isolate* isolate,
24+
v8::Local<v8::Value> val,
25+
atom::AutoResizeFlags* auto_resize_flags) {
26+
mate::Dictionary params;
27+
if (!ConvertFromV8(isolate, val, &params)) {
28+
return false;
29+
}
30+
31+
uint8_t flags = 0;
32+
bool width = false;
33+
if (params.Get("width", &width) && width) {
34+
flags |= atom::kAutoResizeWidth;
35+
}
36+
bool height = false;
37+
if (params.Get("height", &height) && height) {
38+
flags |= atom::kAutoResizeHeight;
39+
}
40+
41+
*auto_resize_flags = static_cast<atom::AutoResizeFlags>(flags);
42+
return true;
43+
}
44+
};
45+
46+
} // namespace mate
47+
48+
namespace atom {
49+
50+
namespace api {
51+
52+
BrowserView::BrowserView(v8::Isolate* isolate,
53+
v8::Local<v8::Object> wrapper,
54+
const mate::Dictionary& options)
55+
: api_web_contents_(nullptr) {
56+
Init(isolate, wrapper, options);
57+
}
58+
59+
void BrowserView::Init(v8::Isolate* isolate,
60+
v8::Local<v8::Object> wrapper,
61+
const mate::Dictionary& options) {
62+
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
63+
options.Get(options::kWebPreferences, &web_preferences);
64+
web_preferences.Set("isBrowserView", true);
65+
mate::Handle<class WebContents> web_contents =
66+
WebContents::Create(isolate, web_preferences);
67+
68+
web_contents_.Reset(isolate, web_contents.ToV8());
69+
api_web_contents_ = web_contents.get();
70+
71+
view_.reset(NativeBrowserView::Create(
72+
api_web_contents_->managed_web_contents()->GetView()));
73+
74+
InitWith(isolate, wrapper);
75+
}
76+
77+
BrowserView::~BrowserView() {
78+
api_web_contents_->DestroyWebContents(true /* async */);
79+
}
80+
81+
// static
82+
mate::WrappableBase* BrowserView::New(mate::Arguments* args) {
83+
if (!Browser::Get()->is_ready()) {
84+
args->ThrowError("Cannot create BrowserView before app is ready");
85+
return nullptr;
86+
}
87+
88+
if (args->Length() > 1) {
89+
args->ThrowError("Too many arguments");
90+
return nullptr;
91+
}
92+
93+
mate::Dictionary options;
94+
if (!(args->Length() == 1 && args->GetNext(&options))) {
95+
options = mate::Dictionary::CreateEmpty(args->isolate());
96+
}
97+
98+
return new BrowserView(args->isolate(), args->GetThis(), options);
99+
}
100+
101+
int32_t BrowserView::ID() const {
102+
return weak_map_id();
103+
}
104+
105+
void BrowserView::SetAutoResize(AutoResizeFlags flags) {
106+
view_->SetAutoResizeFlags(flags);
107+
}
108+
109+
void BrowserView::SetBounds(const gfx::Rect& bounds) {
110+
view_->SetBounds(bounds);
111+
}
112+
113+
void BrowserView::SetBackgroundColor(const std::string& color_name) {
114+
view_->SetBackgroundColor(ParseHexColor(color_name));
115+
}
116+
117+
v8::Local<v8::Value> BrowserView::WebContents() {
118+
if (web_contents_.IsEmpty()) {
119+
return v8::Null(isolate());
120+
}
121+
122+
return v8::Local<v8::Value>::New(isolate(), web_contents_);
123+
}
124+
125+
// static
126+
void BrowserView::BuildPrototype(v8::Isolate* isolate,
127+
v8::Local<v8::FunctionTemplate> prototype) {
128+
prototype->SetClassName(mate::StringToV8(isolate, "BrowserView"));
129+
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
130+
.MakeDestroyable()
131+
.SetMethod("setAutoResize", &BrowserView::SetAutoResize)
132+
.SetMethod("setBounds", &BrowserView::SetBounds)
133+
.SetMethod("setBackgroundColor", &BrowserView::SetBackgroundColor)
134+
.SetProperty("webContents", &BrowserView::WebContents)
135+
.SetProperty("id", &BrowserView::ID);
136+
}
137+
138+
} // namespace api
139+
140+
} // namespace atom
141+
142+
namespace {
143+
144+
using atom::api::BrowserView;
145+
146+
void Initialize(v8::Local<v8::Object> exports,
147+
v8::Local<v8::Value> unused,
148+
v8::Local<v8::Context> context,
149+
void* priv) {
150+
v8::Isolate* isolate = context->GetIsolate();
151+
BrowserView::SetConstructor(isolate, base::Bind(&BrowserView::New));
152+
153+
mate::Dictionary browser_view(
154+
isolate, BrowserView::GetConstructor(isolate)->GetFunction());
155+
156+
mate::Dictionary dict(isolate, exports);
157+
dict.Set("BrowserView", browser_view);
158+
}
159+
160+
} // namespace
161+
162+
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_browser_view, Initialize)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) 2017 GitHub, Inc.
2+
// Use of this source code is governed by the MIT license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef ATOM_BROWSER_API_ATOM_API_BROWSER_VIEW_H_
6+
#define ATOM_BROWSER_API_ATOM_API_BROWSER_VIEW_H_
7+
8+
#include <memory>
9+
#include <string>
10+
11+
#include "atom/browser/api/trackable_object.h"
12+
#include "atom/browser/native_browser_view.h"
13+
#include "native_mate/handle.h"
14+
15+
namespace gfx {
16+
class Rect;
17+
}
18+
19+
namespace mate {
20+
class Arguments;
21+
class Dictionary;
22+
} // namespace mate
23+
24+
namespace atom {
25+
26+
class NativeBrowserView;
27+
28+
namespace api {
29+
30+
class WebContents;
31+
32+
class BrowserView : public mate::TrackableObject<BrowserView> {
33+
public:
34+
static mate::WrappableBase* New(mate::Arguments* args);
35+
36+
static void BuildPrototype(v8::Isolate* isolate,
37+
v8::Local<v8::FunctionTemplate> prototype);
38+
39+
NativeBrowserView* view() const { return view_.get(); }
40+
41+
int32_t ID() const;
42+
43+
protected:
44+
BrowserView(v8::Isolate* isolate,
45+
v8::Local<v8::Object> wrapper,
46+
const mate::Dictionary& options);
47+
~BrowserView() override;
48+
49+
private:
50+
void Init(v8::Isolate* isolate,
51+
v8::Local<v8::Object> wrapper,
52+
const mate::Dictionary& options);
53+
54+
void SetAutoResize(AutoResizeFlags flags);
55+
void SetBounds(const gfx::Rect& bounds);
56+
void SetBackgroundColor(const std::string& color_name);
57+
58+
v8::Local<v8::Value> WebContents();
59+
60+
v8::Global<v8::Value> web_contents_;
61+
class WebContents* api_web_contents_;
62+
63+
std::unique_ptr<NativeBrowserView> view_;
64+
65+
DISALLOW_COPY_AND_ASSIGN(BrowserView);
66+
};
67+
68+
} // namespace api
69+
70+
} // namespace atom
71+
72+
#endif // ATOM_BROWSER_API_ATOM_API_BROWSER_VIEW_H_

0 commit comments

Comments
 (0)