Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] WebTorrent Support #353

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.tags*
/.idea/
/browser/resources/brave_extension/
/components/brave_webtorrent/extension/out/
/dist/
/out/
/vendor/requests
Expand Down Expand Up @@ -39,4 +40,4 @@ npm-debug.log
*~
CMakeLists.txt
cmake-build-debug/
coverage/
coverage/
2 changes: 2 additions & 0 deletions brave_paks.gni
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ template("brave_extra_paks") {
"$root_gen_dir/brave/brave_unscaled_resources.pak",
"$root_gen_dir/components/brave_components_resources.pak",
"$target_gen_dir/browser/resources/brave_extension.pak",
"$target_gen_dir/components/brave_webtorrent/brave_webtorrent_resources.pak",
]

deps = [
"//brave/app:brave_generated_resources_grit",
"//brave/app/theme:brave_unscaled_resources",
"//brave/components/brave_webtorrent:resources",
"//brave/components/resources:brave_components_resources_grit",
"//brave/browser/resources:brave_extension_grit",
"//brave/common/extensions/api"
Expand Down
1 change: 1 addition & 0 deletions browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ source_set("extensions") {

deps = [
"//brave/browser/resources:brave_extension_grit",
"//brave/components/brave_webtorrent:resources",
"//chrome/browser",
"//content/public/browser",
"//extensions/browser",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "brave/browser/extensions/brave_component_extension_resource_manager.h"

#include "brave/browser/resources/grit/brave_extension_resources_map.h"
#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources_map.h"

namespace extensions {

Expand All @@ -13,6 +14,10 @@ BraveComponentExtensionResourceManager() {
AddComponentResourceEntries(
kBraveExtension,
kBraveExtensionSize);

AddComponentResourceEntries(
kBraveWebtorrentResources,
kBraveWebtorrentResourcesSize);
}

BraveComponentExtensionResourceManager::
Expand Down
6 changes: 6 additions & 0 deletions browser/extensions/brave_component_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/command_line.h"
#include "brave/common/brave_switches.h"
#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources.h"
#include "components/grit/brave_components_resources.h"

namespace extensions {
Expand Down Expand Up @@ -33,6 +34,11 @@ void BraveComponentLoader::AddDefaultComponentExtensions(
brave_extension_path.Append(FILE_PATH_LITERAL("brave_extension"));
Add(IDR_BRAVE_EXTENSON, brave_extension_path);
}

base::FilePath brave_webtorrent_path(FILE_PATH_LITERAL(""));
brave_webtorrent_path =
brave_webtorrent_path.Append(FILE_PATH_LITERAL("brave_webtorrent"));
Add(IDR_BRAVE_WEBTORRENT, brave_webtorrent_path);
}

} // namespace extensions
4 changes: 3 additions & 1 deletion browser/extensions/brave_extension_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bool IsWhitelisted(const extensions::Extension* extension) {
}
static std::vector<std::string> whitelist({
brave_extension_id,
brave_webtorrent_extension_id,
pdfjs_extension_id,
// 1Password
"aomjjhallfgjeglblehebfpbcfeobpgk",
Expand Down Expand Up @@ -126,7 +127,8 @@ bool BraveExtensionProvider::UserMayLoad(const Extension* extension,

bool BraveExtensionProvider::MustRemainInstalled(const Extension* extension,
base::string16* error) const {
return extension->id() == brave_extension_id;
return extension->id() == brave_extension_id ||
extension->id() == brave_webtorrent_extension_id;
}

} // namespace extensions
1 change: 1 addition & 0 deletions browser/resources/resource_ids
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
"brave/app/theme/brave_unscaled_resources.grd": {
"includes": [36500],
},
# brave webtorrent 37500
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#define IsComponentExtensionWhitelisted IsComponentExtensionWhitelisted_ChromiumImpl
#include "../../../../../../chrome/browser/extensions/component_extensions_whitelist/whitelist.cc"
#undef IsComponentExtensionWhitelisted

#include "brave/common/extensions/extension_constants.h"
#include "components/grit/brave_components_resources.h"
#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources.h"

namespace extensions {

bool IsComponentExtensionWhitelisted(const std::string& extension_id) {
const char* const kAllowed[] = {
brave_extension_id,
brave_webtorrent_extension_id
};

for (size_t i = 0; i < arraysize(kAllowed); ++i) {
if (extension_id == kAllowed[i])
return true;
}

return IsComponentExtensionWhitelisted_ChromiumImpl(extension_id);
}

bool IsComponentExtensionWhitelisted(int manifest_resource_id) {
switch (manifest_resource_id) {
// Please keep the list in alphabetical order.
case IDR_BRAVE_EXTENSON:
case IDR_BRAVE_WEBTORRENT:
return true;
}

return IsComponentExtensionWhitelisted_ChromiumImpl(manifest_resource_id);
}

} // namespace extensions

6 changes: 6 additions & 0 deletions chromium_src/net/url_request/url_request_context_builder.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/net/url_request/magnet_protocol_handler.h"
#include "../../../../net/url_request/url_request_context_builder.cc"
1 change: 1 addition & 0 deletions common/extensions/api/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ json_features("manifest_features") {
sources = [
"//chrome/common/extensions/api/_manifest_features.json",
"//extensions/common/api/_manifest_features.json",
"_manifest_features.json",
]
}

Expand Down
17 changes: 16 additions & 1 deletion common/extensions/api/_api_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,20 @@
"matches": [
"chrome://newtab/*"
]
}]
}],
"sockets.tcp": {
"dependencies": ["manifest:sockets"],
"contexts": ["blessed_extension"],
"whitelist": ["3D9518A72EB02667A773B69DBA9E72E0F4A37423"]
},
"sockets.tcpServer": {
"dependencies": ["manifest:sockets"],
"contexts": ["blessed_extension"],
"whitelist": ["3D9518A72EB02667A773B69DBA9E72E0F4A37423"]
},
"sockets.udp": {
"dependencies": ["manifest:sockets"],
"contexts": ["blessed_extension"],
"whitelist": ["3D9518A72EB02667A773B69DBA9E72E0F4A37423"]
}
}
11 changes: 11 additions & 0 deletions common/extensions/api/_manifest_features.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

{
"sockets": {
"channel": "stable",
"extension_types": ["extension", "platform_app"],
"whitelist": ["3D9518A72EB02667A773B69DBA9E72E0F4A37423"]
}
}
1 change: 1 addition & 0 deletions common/extensions/extension_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
#include "brave/common/extensions/extension_constants.h"

const char brave_extension_id[] = "mnojpmjdmbbfmejpflffifhffcmidifd";
const char brave_webtorrent_extension_id[] = "lgjmpdmojkpocjcopdikifhejkkjglho";
const char pdfjs_extension_id[] = "oemmndcbldboiebfnladdacbdfmadadm";
const char widevine_extension_id[] = "oimompecagnajdejgnnjijobebaeigek";
1 change: 1 addition & 0 deletions common/extensions/extension_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

extern const char brave_extension_id[];
extern const char brave_webtorrent_extension_id[];
extern const char pdfjs_extension_id[];
extern const char widevine_extension_id[];
2 changes: 1 addition & 1 deletion components/brave_adblock_ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ transpile_web_ui("brave_adblock_ui") {
"reducers/adblock_reducer.ts",
]

bundle_name = "brave_adblock.bundle.js"
bundle_names = ["brave_adblock.bundle.js"]
}
3 changes: 2 additions & 1 deletion components/brave_new_tab_ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ transpile_web_ui("brave_new_tab_ui") {
"reducers/index.ts",
"reducers/new_tab_reducer.tsx",
]
bundle_name = "brave_new_tab.bundle.js"

bundle_names = ["brave_new_tab.bundle.js"]
}
2 changes: 1 addition & 1 deletion components/brave_rewards_ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ transpile_web_ui("brave_rewards_ui") {
"reducers/rewards_reducer.ts",
]

bundle_name = "brave_rewards.bundle.js"
bundle_names = ["brave_rewards.bundle.js"]
}
18 changes: 18 additions & 0 deletions components/brave_webtorrent/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import("//tools/grit/grit_rule.gni")
import("//tools/grit/repack.gni")

grit("resources") {
source = "resources.grd"
outputs = [
"grit/brave_webtorrent_resources_map.cc",
"grit/brave_webtorrent_resources_map.h",
"grit/brave_webtorrent_resources.h",
"brave_webtorrent_resources.pak",
]

deps = [
"//brave/components/brave_webtorrent/extension:brave_webtorrent"
]

resource_ids = ""
}
43 changes: 43 additions & 0 deletions components/brave_webtorrent/extension/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import("//brave/components/common/typescript.gni")

transpile_web_ui("brave_webtorrent") {
inputs = [
"background.ts",
"brave_webtorrent.html",
"brave_webtorrent.tsx",
"actions/tab_actions.ts",
"actions/webtorrent_actions.ts",
"actions/window_actions.ts",
"background/store.ts",
"background/webtorrent.ts",
"background/actions/tabActions.ts",
"background/actions/webtorrentActions.ts",
"background/actions/windowActions.ts",
"background/events/tabsEvents.ts",
"background/events/torrentEvents.ts",
"background/events/webtorrentEvents.ts",
"background/events/windowsEvents.ts",
"background/reducers/index.ts",
"background/reducers/webtorrent_reducer.ts",
"components/app.tsx",
"components/mediaViewer.tsx",
"components/torrentFileList.tsx",
"components/torrentStatus.tsx",
"components/torrentViewer.tsx",
"components/torrentViewerFooter.tsx",
"components/torrentViewerHeader.tsx",
"constants/tab_types.ts",
"constants/theme.ts",
"constants/webtorrentState.ts",
"constants/webtorrent_types.ts",
"constants/window_types.ts"
]

bundle_names = [
"brave_webtorrent.bundle.js",
"brave_webtorrent_background.bundle.js"
]

output_dir =
"$root_gen_dir/../../../brave/components/brave_webtorrent/extension/out"
}
25 changes: 25 additions & 0 deletions components/brave_webtorrent/extension/actions/tab_actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import { action } from 'typesafe-actions'

// Constants
import { types } from '../constants/tab_types'

export const tabCreated = (tab: chrome.tabs.Tab) => action(types.TAB_CREATED, {
tab
})

export const tabUpdated = (tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab) =>
action(types.TAB_UPDATED, {
tabId, changeInfo, tab
})

export const tabRemoved = (tabId: number) => action(types.TAB_REMOVED, {
tabId
})

export const activeTabChanged = (tabId: number, windowId: number) => action(types.ACTIVE_TAB_CHANGED, {
tabId, windowId
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import { action } from 'typesafe-actions'
import { Torrent } from 'webtorrent'

// Constants
import { types } from '../constants/webtorrent_types'

export const progressUpdated = (torrent: Torrent) => action(types.WEBTORRENT_PROGRESS_UPDATED, { torrent })
export const infoUpdated = (torrent: Torrent) => action(types.WEBTORRENT_INFO_UPDATED, { torrent })
export const serverUpdated = (torrent: Torrent, serverURL: string) =>
action(types.WEBTORRENT_SERVER_UPDATED, { torrent, serverURL })
export const startTorrent = (torrentId: string, tabId: number) => action(types.WEBTORRENT_START_TORRENT, { torrentId, tabId })
export const stopDownload = (tabId: number) => action(types.WEBTORRENT_STOP_DOWNLOAD, { tabId })
20 changes: 20 additions & 0 deletions components/brave_webtorrent/extension/actions/window_actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import { action } from 'typesafe-actions'

// Constants
import { types } from '../constants/window_types'

export const windowCreated = (window: chrome.windows.Window) => action(types.WINDOW_CREATED, {
window
})

export const windowRemoved = (windowId: number) => action(types.WINDOW_REMOVED, {
windowId
})

export const windowFocusChanged = (windowId: number) => action(types.WINDOW_FOCUS_CHANGED, {
windowId
})
10 changes: 10 additions & 0 deletions components/brave_webtorrent/extension/background.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import { init } from './background/webtorrent'
init()

require('./background/store')
require('./background/events/tabsEvents')
require('./background/events/windowsEvents')
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import { bindActionCreators } from 'redux'
import store from '../store'
import * as tabActions from '../../actions/tab_actions'
export default bindActionCreators(tabActions, store.dispatch)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import { bindActionCreators } from 'redux'
import store from '../store'
import * as webtorrentActions from '../../actions/webtorrent_actions'
export default bindActionCreators(webtorrentActions, store.dispatch)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import { bindActionCreators } from 'redux'
import store from '../store'
import * as windowActions from '../../actions/window_actions'
export default bindActionCreators(windowActions, store.dispatch)
Loading