Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Enable Safe Browsing API in muon
Browse files Browse the repository at this point in the history
  • Loading branch information
jumde committed Mar 29, 2018
1 parent 628e7a6 commit c61e04d
Show file tree
Hide file tree
Showing 42 changed files with 830 additions and 139 deletions.
1 change: 1 addition & 0 deletions atom/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ source_set("browser") {
public_deps = [
"//content/public/browser",
"//content/public/common",
"//net",
"//electron/vendor/brightray:browser",
"//ui/events",
"//components/security_state/content",
Expand Down
27 changes: 4 additions & 23 deletions atom/browser/api/atom_api_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,6 @@ struct Converter<file_dialog::DialogSettings> {

namespace {

// Consider downloads 'dangerous' if they go to the home directory on Linux and
// to the desktop on any platform.
bool DownloadPathIsDangerous(const base::FilePath& download_path) {
#if defined(OS_LINUX)
base::FilePath home_dir = base::GetHomeDir();
if (download_path == home_dir) {
return true;
}
#endif
base::FilePath desktop_dir;
if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop_dir)) {
NOTREACHED();
return false;
}
return (download_path == desktop_dir);
}

void ShowMessageBox(int type,
const std::vector<std::string>& buttons,
int default_id,
Expand Down Expand Up @@ -173,12 +156,10 @@ void ShowDialog(const file_dialog::DialogSettings& settings,
NOTREACHED();
}
}
if (DownloadPathIsDangerous(default_path)) {
// This is only useful on platforms that support
// DIR_DEFAULT_DOWNLOADS_SAFE.
if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS_SAFE, &default_path)) {
NOTREACHED();
}
// This is only useful on platforms that support
// DIR_DEFAULT_DOWNLOADS_SAFE.
if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS_SAFE, &default_path)) {
NOTREACHED();
}
file_type_info.include_all_files = settings.include_all_files;
file_type_info.extension_description_overrides =
Expand Down
14 changes: 12 additions & 2 deletions atom/browser/api/atom_api_download_item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "atom/common/native_mate_converters/gurl_converter.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "content/public/browser/download_item.h"
#include "native_mate/dictionary.h"
#include "net/base/filename_util.h"

Expand Down Expand Up @@ -78,9 +79,10 @@ DownloadItem::~DownloadItem() {
}

void DownloadItem::OnDownloadUpdated(content::DownloadItem* item) {
if (download_item_->IsDone()) {
if (download_item_->IsDangerous()) {
Emit("dangerous");
} else if (download_item_->IsDone()) {
Emit("done", item->GetState());

// Destroy the item once item is downloaded.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, GetDestroyClosure());
Expand All @@ -89,6 +91,10 @@ void DownloadItem::OnDownloadUpdated(content::DownloadItem* item) {
}
}

DownloadDangerType DownloadItem::GetDangerType() const {
return download_item_->GetDangerType();
}

void DownloadItem::OnDownloadRemoved(content::DownloadItem* download) {
Emit("removed");
}
Expand Down Expand Up @@ -164,6 +170,10 @@ bool DownloadItem::IsDone() const {
return download_item_->IsDone();
}

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

void DownloadItem::SetSavePath(const base::FilePath& path) {
save_path_ = path;
}
Expand Down
5 changes: 5 additions & 0 deletions atom/browser/api/atom_api_download_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "atom/browser/api/trackable_object.h"
#include "base/files/file_path.h"
#include "content/public/browser/download_danger_type.h"
#include "content/public/browser/download_item.h"
#include "native_mate/handle.h"
#include "url/gurl.h"
Expand All @@ -17,6 +18,8 @@ namespace atom {

namespace api {

using content::DownloadDangerType;

class DownloadItem : public mate::TrackableObject<DownloadItem>,
public content::DownloadItem::Observer {
public:
Expand Down Expand Up @@ -46,6 +49,8 @@ class DownloadItem : public mate::TrackableObject<DownloadItem>,
std::string GetGuid() const;
void SetPrompt(bool prompt);
bool ShouldPrompt();
bool IsDangerous() const;
DownloadDangerType GetDangerType() const;

protected:
DownloadItem(v8::Isolate* isolate, content::DownloadItem* download_item);
Expand Down
Loading

0 comments on commit c61e04d

Please sign in to comment.