Skip to content

Commit

Permalink
Merge pull request #10 from electron/master
Browse files Browse the repository at this point in the history
update as upstream
  • Loading branch information
brenca committed Jun 11, 2016
2 parents 9aaa6c7 + c68ca16 commit 70aa706
Show file tree
Hide file tree
Showing 108 changed files with 1,477 additions and 586 deletions.
2 changes: 1 addition & 1 deletion .node-version
@@ -1 +1 @@
v5.10.0
v6.1.0
20 changes: 17 additions & 3 deletions atom/browser/api/atom_api_app.cc
Expand Up @@ -110,6 +110,8 @@ int GetPathConstant(const std::string& name) {
return chrome::DIR_USER_PICTURES;
else if (name == "videos")
return chrome::DIR_USER_VIDEOS;
else if (name == "pepperFlashSystemPlugin")
return chrome::FILE_PEPPER_FLASH_SYSTEM_PLUGIN;
else
return -1;
}
Expand Down Expand Up @@ -261,13 +263,14 @@ void App::OnContinueUserActivity(
}
#endif

void App::OnLogin(LoginHandler* login_handler) {
void App::OnLogin(LoginHandler* login_handler,
const base::DictionaryValue& request_details) {
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
bool prevent_default = Emit(
"login",
WebContents::CreateFrom(isolate(), login_handler->GetWebContents()),
login_handler->request(),
request_details,
login_handler->auth_info(),
base::Bind(&PassLoginInformation, make_scoped_refptr(login_handler)));

Expand Down Expand Up @@ -447,6 +450,15 @@ bool App::Relaunch(mate::Arguments* js_args) {
return relauncher::RelaunchApp(argv);
}

void App::DisableHardwareAcceleration(mate::Arguments* args) {
if (Browser::Get()->is_ready()) {
args->ThrowError("app.disableHardwareAcceleration() can only be called "
"before app is ready");
return;
}
content::GpuDataManager::GetInstance()->DisableHardwareAcceleration();
}

#if defined(USE_NSS_CERTS)
void App::ImportCertificate(
const base::DictionaryValue& options,
Expand Down Expand Up @@ -528,7 +540,9 @@ void App::BuildPrototype(
#endif
.SetMethod("makeSingleInstance", &App::MakeSingleInstance)
.SetMethod("releaseSingleInstance", &App::ReleaseSingleInstance)
.SetMethod("relaunch", &App::Relaunch);
.SetMethod("relaunch", &App::Relaunch)
.SetMethod("disableHardwareAcceleration",
&App::DisableHardwareAcceleration);
}

} // namespace api
Expand Down
5 changes: 3 additions & 2 deletions atom/browser/api/atom_api_app.h
Expand Up @@ -70,7 +70,8 @@ class App : public AtomBrowserClient::Delegate,
void OnActivate(bool has_visible_windows) override;
void OnWillFinishLaunching() override;
void OnFinishLaunching() override;
void OnLogin(LoginHandler* login_handler) override;
void OnLogin(LoginHandler* login_handler,
const base::DictionaryValue& request_details) override;
#if defined(OS_MACOSX)
void OnContinueUserActivity(
bool* prevent_default,
Expand Down Expand Up @@ -111,7 +112,7 @@ class App : public AtomBrowserClient::Delegate,
const ProcessSingleton::NotificationCallback& callback);
void ReleaseSingleInstance();
bool Relaunch(mate::Arguments* args);

void DisableHardwareAcceleration(mate::Arguments* args);
#if defined(USE_NSS_CERTS)
void ImportCertificate(const base::DictionaryValue& options,
const net::CompletionCallback& callback);
Expand Down
25 changes: 24 additions & 1 deletion atom/browser/api/atom_api_download_item.cc
Expand Up @@ -25,6 +25,9 @@ struct Converter<content::DownloadItem::DownloadState> {
content::DownloadItem::DownloadState state) {
std::string download_state;
switch (state) {
case content::DownloadItem::IN_PROGRESS:
download_state = "progressing";
break;
case content::DownloadItem::COMPLETE:
download_state = "completed";
break;
Expand Down Expand Up @@ -85,7 +88,7 @@ void DownloadItem::OnDownloadUpdated(content::DownloadItem* item) {
// Destroy the item once item is downloaded.
base::MessageLoop::current()->PostTask(FROM_HERE, GetDestroyClosure());
} else {
Emit("updated");
Emit("updated", item->GetState());
}
}

Expand All @@ -99,10 +102,18 @@ void DownloadItem::Pause() {
download_item_->Pause();
}

bool DownloadItem::IsPaused() const {
return download_item_->IsPaused();
}

void DownloadItem::Resume() {
download_item_->Resume();
}

bool DownloadItem::CanResume() const {
return download_item_->CanResume();
}

void DownloadItem::Cancel() {
download_item_->Cancel(true);
download_item_->Remove();
Expand Down Expand Up @@ -141,6 +152,14 @@ const GURL& DownloadItem::GetURL() const {
return download_item_->GetURL();
}

content::DownloadItem::DownloadState DownloadItem::GetState() const {
return download_item_->GetState();
}

bool DownloadItem::IsDone() const {
return download_item_->IsDone();
}

void DownloadItem::SetSavePath(const base::FilePath& path) {
save_path_ = path;
}
Expand All @@ -155,7 +174,9 @@ void DownloadItem::BuildPrototype(v8::Isolate* isolate,
mate::ObjectTemplateBuilder(isolate, prototype)
.MakeDestroyable()
.SetMethod("pause", &DownloadItem::Pause)
.SetMethod("isPaused", &DownloadItem::IsPaused)
.SetMethod("resume", &DownloadItem::Resume)
.SetMethod("canResume", &DownloadItem::CanResume)
.SetMethod("cancel", &DownloadItem::Cancel)
.SetMethod("getReceivedBytes", &DownloadItem::GetReceivedBytes)
.SetMethod("getTotalBytes", &DownloadItem::GetTotalBytes)
Expand All @@ -164,6 +185,8 @@ void DownloadItem::BuildPrototype(v8::Isolate* isolate,
.SetMethod("getFilename", &DownloadItem::GetFilename)
.SetMethod("getContentDisposition", &DownloadItem::GetContentDisposition)
.SetMethod("getURL", &DownloadItem::GetURL)
.SetMethod("getState", &DownloadItem::GetState)
.SetMethod("isDone", &DownloadItem::IsDone)
.SetMethod("setSavePath", &DownloadItem::SetSavePath)
.SetMethod("getSavePath", &DownloadItem::GetSavePath);
}
Expand Down
4 changes: 4 additions & 0 deletions atom/browser/api/atom_api_download_item.h
Expand Up @@ -27,7 +27,9 @@ class DownloadItem : public mate::TrackableObject<DownloadItem>,
v8::Local<v8::ObjectTemplate> prototype);

void Pause();
bool IsPaused() const;
void Resume();
bool CanResume() const;
void Cancel();
int64_t GetReceivedBytes() const;
int64_t GetTotalBytes() const;
Expand All @@ -36,6 +38,8 @@ class DownloadItem : public mate::TrackableObject<DownloadItem>,
std::string GetFilename() const;
std::string GetContentDisposition() const;
const GURL& GetURL() const;
content::DownloadItem::DownloadState GetState() const;
bool IsDone() const;
void SetSavePath(const base::FilePath& path);
base::FilePath GetSavePath() const;

Expand Down
20 changes: 12 additions & 8 deletions atom/browser/api/atom_api_protocol.cc
Expand Up @@ -12,8 +12,12 @@
#include "atom/browser/net/url_request_fetch_job.h"
#include "atom/browser/net/url_request_string_job.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/net_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/node_includes.h"
#include "atom/common/options_switches.h"
#include "base/command_line.h"
#include "base/strings/string_util.h"
#include "content/public/browser/child_process_security_policy.h"
#include "native_mate/dictionary.h"
#include "url/url_util.h"

Expand Down Expand Up @@ -158,21 +162,21 @@ namespace {

void RegisterStandardSchemes(
const std::vector<std::string>& schemes) {
for (const auto& scheme : schemes)
auto policy = content::ChildProcessSecurityPolicy::GetInstance();
for (const auto& scheme : schemes) {
url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITHOUT_PORT);
}
policy->RegisterWebSafeScheme(scheme);
}

mate::Handle<atom::api::Protocol> CreateProtocol(v8::Isolate* isolate) {
auto browser_context = static_cast<atom::AtomBrowserContext*>(
atom::AtomBrowserMainParts::Get()->browser_context());
return atom::api::Protocol::Create(isolate, browser_context);
auto command_line = base::CommandLine::ForCurrentProcess();
command_line->AppendSwitchASCII(atom::switches::kStandardSchemes,
base::JoinString(schemes, ","));
}

void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.SetMethod("createProtocolObject", base::Bind(&CreateProtocol, isolate));
dict.SetMethod("registerStandardSchemes", &RegisterStandardSchemes);
}

Expand Down
10 changes: 7 additions & 3 deletions atom/browser/api/atom_api_protocol.h
Expand Up @@ -9,14 +9,18 @@
#include <map>
#include <vector>

#include "atom/browser/api/trackable_object.h"
#include "atom/browser/net/atom_url_request_job_factory.h"
#include "base/callback.h"
#include "base/containers/scoped_ptr_hash_map.h"
#include "content/public/browser/browser_thread.h"
#include "native_mate/arguments.h"
#include "native_mate/dictionary.h"
#include "native_mate/handle.h"
#include "native_mate/wrappable.h"

namespace base {
class DictionaryValue;
}

namespace net {
class URLRequest;
Expand All @@ -30,10 +34,10 @@ class AtomURLRequestJobFactory;

namespace api {

class Protocol : public mate::Wrappable<Protocol> {
class Protocol : public mate::TrackableObject<Protocol> {
public:
using Handler =
base::Callback<void(const net::URLRequest*, v8::Local<v8::Value>)>;
base::Callback<void(const base::DictionaryValue&, v8::Local<v8::Value>)>;
using CompletionCallback = base::Callback<void(v8::Local<v8::Value>)>;
using BooleanCallback = base::Callback<void(bool)>;

Expand Down
10 changes: 10 additions & 0 deletions atom/browser/api/atom_api_session.cc
Expand Up @@ -9,6 +9,7 @@

#include "atom/browser/api/atom_api_cookies.h"
#include "atom/browser/api/atom_api_download_item.h"
#include "atom/browser/api/atom_api_protocol.h"
#include "atom/browser/api/atom_api_web_request.h"
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/atom_browser_main_parts.h"
Expand Down Expand Up @@ -462,6 +463,14 @@ v8::Local<v8::Value> Session::Cookies(v8::Isolate* isolate) {
return v8::Local<v8::Value>::New(isolate, cookies_);
}

v8::Local<v8::Value> Session::Protocol(v8::Isolate* isolate) {
if (protocol_.IsEmpty()) {
auto handle = atom::api::Protocol::Create(isolate, browser_context());
protocol_.Reset(isolate, handle.ToV8());
}
return v8::Local<v8::Value>::New(isolate, protocol_);
}

v8::Local<v8::Value> Session::WebRequest(v8::Isolate* isolate) {
if (web_request_.IsEmpty()) {
auto handle = atom::api::WebRequest::Create(isolate, browser_context());
Expand Down Expand Up @@ -512,6 +521,7 @@ void Session::BuildPrototype(v8::Isolate* isolate,
.SetMethod("allowNTLMCredentialsForDomains",
&Session::AllowNTLMCredentialsForDomains)
.SetProperty("cookies", &Session::Cookies)
.SetProperty("protocol", &Session::Protocol)
.SetProperty("webRequest", &Session::WebRequest);
}

Expand Down
2 changes: 2 additions & 0 deletions atom/browser/api/atom_api_session.h
Expand Up @@ -81,10 +81,12 @@ class Session: public mate::TrackableObject<Session>,
void ClearHostResolverCache(mate::Arguments* args);
void AllowNTLMCredentialsForDomains(const std::string& domains);
v8::Local<v8::Value> Cookies(v8::Isolate* isolate);
v8::Local<v8::Value> Protocol(v8::Isolate* isolate);
v8::Local<v8::Value> WebRequest(v8::Isolate* isolate);

// Cached object.
v8::Global<v8::Value> cookies_;
v8::Global<v8::Value> protocol_;
v8::Global<v8::Value> web_request_;

// The X-DevTools-Emulate-Network-Conditions-Client-Id.
Expand Down
27 changes: 27 additions & 0 deletions atom/browser/api/atom_api_web_contents.cc
Expand Up @@ -389,6 +389,11 @@ void WebContents::ActivateContents(content::WebContents* source) {
Emit("activate");
}

void WebContents::UpdateTargetURL(content::WebContents* source,
const GURL& url) {
Emit("update-target-url", url);
}

bool WebContents::IsPopupOrPanel(const content::WebContents* source) const {
return type_ == BROWSER_WINDOW;
}
Expand Down Expand Up @@ -739,6 +744,15 @@ int WebContents::GetID() const {
return web_contents()->GetRenderProcessHost()->GetID();
}

std::string WebContents::GetType() const {
switch (type_) {
case BROWSER_WINDOW: return "window";
case WEB_VIEW: return "webview";
case REMOTE: return "remote";
default: return "";
}
}

bool WebContents::Equal(const WebContents* web_contents) const {
return GetID() == web_contents->GetID();
}
Expand Down Expand Up @@ -1089,6 +1103,14 @@ void WebContents::StopFindInPage(content::StopFindAction action) {
web_contents()->StopFinding(action);
}

void WebContents::ShowDefinitionForSelection() {
#if defined(OS_MACOSX)
const auto view = web_contents()->GetRenderWidgetHostView();
if (view)
view->ShowDefinitionForSelection();
#endif
}

void WebContents::Focus() {
web_contents()->Focus();
}
Expand Down Expand Up @@ -1274,6 +1296,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
.SetMethod("endFrameSubscription", &WebContents::EndFrameSubscription)
.SetMethod("setSize", &WebContents::SetSize)
.SetMethod("isGuest", &WebContents::IsGuest)
.SetMethod("getType", &WebContents::GetType)
.SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
.SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow)
.SetMethod("hasServiceWorker", &WebContents::HasServiceWorker)
Expand All @@ -1284,6 +1307,8 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
.SetMethod("_printToPDF", &WebContents::PrintToPDF)
.SetMethod("addWorkSpace", &WebContents::AddWorkSpace)
.SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace)
.SetMethod("showDefinitionForSelection",
&WebContents::ShowDefinitionForSelection)
.SetProperty("id", &WebContents::ID)
.SetProperty("session", &WebContents::Session)
.SetProperty("hostWebContents", &WebContents::HostWebContents)
Expand Down Expand Up @@ -1350,6 +1375,8 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
dict.SetMethod("_setWrapWebContents", &atom::api::SetWrapWebContents);
dict.SetMethod("fromId",
&mate::TrackableObject<atom::api::WebContents>::FromWeakMapID);
dict.SetMethod("getAllWebContents",
&mate::TrackableObject<atom::api::WebContents>::GetAll);
}

} // namespace
Expand Down
3 changes: 3 additions & 0 deletions atom/browser/api/atom_api_web_contents.h
Expand Up @@ -59,6 +59,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
v8::Local<v8::ObjectTemplate> prototype);

int GetID() const;
std::string GetType() const;
bool Equal(const WebContents* web_contents) const;
void LoadURL(const GURL& url, const mate::Dictionary& options);
void DownloadURL(const GURL& url);
Expand Down Expand Up @@ -116,6 +117,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
void ReplaceMisspelling(const base::string16& word);
uint32_t FindInPage(mate::Arguments* args);
void StopFindInPage(content::StopFindAction action);
void ShowDefinitionForSelection();

// Focus.
void Focus();
Expand Down Expand Up @@ -182,6 +184,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
const gfx::Rect& pos) override;
void CloseContents(content::WebContents* source) override;
void ActivateContents(content::WebContents* contents) override;
void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
bool IsPopupOrPanel(const content::WebContents* source) const override;
void HandleKeyboardEvent(
content::WebContents* source,
Expand Down

0 comments on commit 70aa706

Please sign in to comment.