mirror of
https://github.com/electron/electron.git
synced 2026-02-19 03:14:51 -05:00
Compare commits
271 Commits
v3.0.0-bet
...
v3.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4913fc81d1 | ||
|
|
846b43d7bd | ||
|
|
d644eb4164 | ||
|
|
dc4057bb48 | ||
|
|
c3867ba6d5 | ||
|
|
aa57be70a0 | ||
|
|
9d24d28816 | ||
|
|
75a21678d7 | ||
|
|
7f0056f683 | ||
|
|
02eeef4dc0 | ||
|
|
7d8c59deda | ||
|
|
1e9a75d9f2 | ||
|
|
e7688723f9 | ||
|
|
6fb569cc6c | ||
|
|
349f10d779 | ||
|
|
9f6bee704f | ||
|
|
e6668f60c8 | ||
|
|
409b58525a | ||
|
|
ea83871cf6 | ||
|
|
53ace2e099 | ||
|
|
38fc10f068 | ||
|
|
03b9f0db58 | ||
|
|
aea44b9227 | ||
|
|
eb9e468bcc | ||
|
|
936d088210 | ||
|
|
9490a9f9ba | ||
|
|
3c4cd3f662 | ||
|
|
15f8d15b1b | ||
|
|
9f472acf80 | ||
|
|
0043acf70a | ||
|
|
e25f8c1a08 | ||
|
|
e2be247579 | ||
|
|
9de5965bb7 | ||
|
|
67af030df7 | ||
|
|
f0b47b2541 | ||
|
|
97ffaf058f | ||
|
|
a4a0eff1e7 | ||
|
|
1ad67754c0 | ||
|
|
8408136082 | ||
|
|
56f7359ed3 | ||
|
|
5dc15fc5d9 | ||
|
|
17481882d0 | ||
|
|
b23b72f9c3 | ||
|
|
957ac493e6 | ||
|
|
5ddc2fb6e7 | ||
|
|
31d5e9bbe1 | ||
|
|
386e356ed6 | ||
|
|
250a09a43f | ||
|
|
3ed5a24c72 | ||
|
|
5d05f1c72a | ||
|
|
0fa449f5f4 | ||
|
|
05ffcbdb3b | ||
|
|
4abf55801f | ||
|
|
d5a6bb665b | ||
|
|
4305657858 | ||
|
|
e391b7df69 | ||
|
|
82e7bd3f22 | ||
|
|
eb30cc2ede | ||
|
|
d9efaa946b | ||
|
|
3f99cf4f1d | ||
|
|
a0a9d9d159 | ||
|
|
7165fb181d | ||
|
|
67cf0eb9b0 | ||
|
|
e9823f07be | ||
|
|
c272f5fc56 | ||
|
|
48ebebcafe | ||
|
|
ae9f4ef425 | ||
|
|
5c14992e43 | ||
|
|
53b871ecbd | ||
|
|
ec6fe27fca | ||
|
|
8566f8712c | ||
|
|
08ec270b90 | ||
|
|
b2822ed800 | ||
|
|
6bec85f30c | ||
|
|
6d658b319b | ||
|
|
5c853b681c | ||
|
|
7b0959ed2b | ||
|
|
3e8b854975 | ||
|
|
fd97fcf6f0 | ||
|
|
809534dca0 | ||
|
|
b2763cad9f | ||
|
|
b6b9966162 | ||
|
|
a41e919b95 | ||
|
|
bdda248194 | ||
|
|
41e86efda0 | ||
|
|
88b1f7d9c8 | ||
|
|
dcdbc87ef4 | ||
|
|
9e03783781 | ||
|
|
8208296143 | ||
|
|
518467cf4c | ||
|
|
648bf54bb3 | ||
|
|
8dce40137c | ||
|
|
dab77256d2 | ||
|
|
c7501bd7ca | ||
|
|
203c47f038 | ||
|
|
02cd96875d | ||
|
|
9349b0a273 | ||
|
|
1c42715e1d | ||
|
|
ef4a7e22fd | ||
|
|
ead294fe13 | ||
|
|
f119e4cc4b | ||
|
|
00489e6106 | ||
|
|
a7c34b8a0a | ||
|
|
906436f31b | ||
|
|
b208fcbf0d | ||
|
|
6899ac9bde | ||
|
|
72c033299f | ||
|
|
7fb6b3bda8 | ||
|
|
1d79840025 | ||
|
|
07deaaa502 | ||
|
|
259f0a62e8 | ||
|
|
4f78df9cfa | ||
|
|
b2be093bd3 | ||
|
|
4f666bb6ac | ||
|
|
12f75832b8 | ||
|
|
6f54d58e2a | ||
|
|
8716f718a9 | ||
|
|
714f3ffd29 | ||
|
|
4a5d2117ba | ||
|
|
5cb50b0e33 | ||
|
|
7283b78aa2 | ||
|
|
049381c6ac | ||
|
|
22597474e0 | ||
|
|
760def6147 | ||
|
|
70d4644742 | ||
|
|
f6b7f547bb | ||
|
|
9bb3701f7e | ||
|
|
d7fe65b9bd | ||
|
|
eb8546c8d1 | ||
|
|
6719f66d5a | ||
|
|
b78fb5aa93 | ||
|
|
502b0b988e | ||
|
|
3d8af9d279 | ||
|
|
524bb99948 | ||
|
|
8f743e6fbe | ||
|
|
6c085cda74 | ||
|
|
73935bc5dd | ||
|
|
bf928ee443 | ||
|
|
ee6de82c08 | ||
|
|
8d362150e0 | ||
|
|
385b08881e | ||
|
|
5cd24a4e81 | ||
|
|
9ab77adc94 | ||
|
|
d808423975 | ||
|
|
3979315517 | ||
|
|
35cb671529 | ||
|
|
0f291f9d63 | ||
|
|
8574a55bd8 | ||
|
|
05a429075e | ||
|
|
7eb1c3fb1b | ||
|
|
db0384116e | ||
|
|
0f8fb86e1b | ||
|
|
0c3cfc50a7 | ||
|
|
8d87dffe01 | ||
|
|
9bb6c9dc99 | ||
|
|
e405103880 | ||
|
|
34c202518d | ||
|
|
e5d84e84c2 | ||
|
|
18857f494d | ||
|
|
d417759885 | ||
|
|
46c467a1f6 | ||
|
|
0b3b508eca | ||
|
|
e3195413aa | ||
|
|
96c47ef537 | ||
|
|
89148bcf8d | ||
|
|
7e5815c180 | ||
|
|
f924a16055 | ||
|
|
2a113e512b | ||
|
|
02b1069fd8 | ||
|
|
3348e5162f | ||
|
|
64c8c27575 | ||
|
|
e76a976347 | ||
|
|
8d27657fa5 | ||
|
|
5e81d8dad9 | ||
|
|
b23acab456 | ||
|
|
8950caaa85 | ||
|
|
1b920c25af | ||
|
|
8fd31a3e07 | ||
|
|
893f866c05 | ||
|
|
d36b14a322 | ||
|
|
27a33cc1cf | ||
|
|
7835bceabd | ||
|
|
af4f08e030 | ||
|
|
03dac078d7 | ||
|
|
d3d44bdbc6 | ||
|
|
a370b6982d | ||
|
|
03ef5c25f7 | ||
|
|
3bc6652833 | ||
|
|
664371245a | ||
|
|
08270e6817 | ||
|
|
8f74a77a64 | ||
|
|
85c8ada99a | ||
|
|
b15a3ee2be | ||
|
|
7b043ac554 | ||
|
|
89a6f1efbb | ||
|
|
ce592a5705 | ||
|
|
12087b74e8 | ||
|
|
d365078022 | ||
|
|
3dbd84c224 | ||
|
|
2e479ff799 | ||
|
|
a341ae450a | ||
|
|
0aec308681 | ||
|
|
8e9c5b8338 | ||
|
|
6bc1e37156 | ||
|
|
7da7dd85e3 | ||
|
|
ccf8a797dc | ||
|
|
3301e05f33 | ||
|
|
b1c22ba531 | ||
|
|
873f39b159 | ||
|
|
11864e9e08 | ||
|
|
c8a21dbb92 | ||
|
|
97058837e7 | ||
|
|
ff539c1d61 | ||
|
|
9237d40e09 | ||
|
|
4721dc0856 | ||
|
|
1f7fd985dd | ||
|
|
d432e420ae | ||
|
|
635c3f53d8 | ||
|
|
ba703deee2 | ||
|
|
b03178105d | ||
|
|
ef0a6d9a1c | ||
|
|
4c7af6a429 | ||
|
|
d1886c5d22 | ||
|
|
c558dc2d7d | ||
|
|
be68cfd4ea | ||
|
|
115a15c356 | ||
|
|
d4fb904450 | ||
|
|
c7f7bdab8a | ||
|
|
de7cb9524a | ||
|
|
5d17e48490 | ||
|
|
058c03fdab | ||
|
|
bd0d6b1a02 | ||
|
|
0783eb9881 | ||
|
|
4e3aa2e061 | ||
|
|
92f3d47ab3 | ||
|
|
2a7ec7e051 | ||
|
|
bf465dc233 | ||
|
|
00cf45609f | ||
|
|
26f4190102 | ||
|
|
5d6382270a | ||
|
|
2162c996eb | ||
|
|
2945be4b9b | ||
|
|
c066a51bfe | ||
|
|
ff7dfe4a11 | ||
|
|
6d17663a0b | ||
|
|
bd4334e2b4 | ||
|
|
0f937c2300 | ||
|
|
2ecdf4a0eb | ||
|
|
44b0245ac4 | ||
|
|
c4d6484264 | ||
|
|
ef2ad40bd9 | ||
|
|
2642e064a2 | ||
|
|
daf23288bc | ||
|
|
8eec8e150d | ||
|
|
2af61cbe95 | ||
|
|
32ffb0ba17 | ||
|
|
69caea38c1 | ||
|
|
b5bfd9867b | ||
|
|
fb2afe8656 | ||
|
|
c926f3f6dc | ||
|
|
5aa247a627 | ||
|
|
67d202eaf6 | ||
|
|
98033e4f45 | ||
|
|
3d89185396 | ||
|
|
1f430259ce | ||
|
|
ff86cf5f6a | ||
|
|
274a53654c | ||
|
|
8f5fafb636 | ||
|
|
bfbd4a2540 | ||
|
|
07b93d475d | ||
|
|
c9da2d7669 |
@@ -8,6 +8,7 @@ build-steps: &build-steps
|
||||
echo 'Installing Node.js 10 for MacOS'
|
||||
brew update
|
||||
brew install node@10
|
||||
echo 'export PATH="/usr/local/opt/node@10/bin:$PATH"' >> $BASH_ENV
|
||||
fi
|
||||
- run:
|
||||
name: Check for release
|
||||
@@ -69,6 +70,17 @@ build-steps: &build-steps
|
||||
else
|
||||
echo 'Headless testing not needed'
|
||||
fi
|
||||
|
||||
- run:
|
||||
name: Verify mksnapshot
|
||||
command: |
|
||||
if [ "$RUN_TESTS" == "true" ] && [ "$ELECTRON_RELEASE" == "1" ]; then
|
||||
echo 'Verifying mksnapshot on release build'
|
||||
script/verify-mksnapshot.py
|
||||
else
|
||||
echo 'Skipping mksnapshot tests due to configuration'
|
||||
fi
|
||||
|
||||
- run:
|
||||
name: Test
|
||||
environment:
|
||||
|
||||
7
.env.example
Normal file
7
.env.example
Normal file
@@ -0,0 +1,7 @@
|
||||
# These env vars are only necessary for creating Electron releases.
|
||||
# See docs/development/releasing.md
|
||||
|
||||
APPVEYOR_TOKEN=
|
||||
CIRCLE_TOKEN=
|
||||
ELECTRON_GITHUB_TOKEN=
|
||||
VSTS_TOKEN=
|
||||
13
BUILD.gn
13
BUILD.gn
@@ -27,6 +27,12 @@ declare_args() {
|
||||
enable_desktop_capturer = true
|
||||
enable_run_as_node = true
|
||||
enable_osr = true
|
||||
|
||||
# Provide a fake location provider for mocking
|
||||
# the geolocation responses. Disable it if you
|
||||
# need to test with chromium's location provider.
|
||||
# Should not be enabled for release build.
|
||||
enable_fake_location_provider = !is_official_build
|
||||
}
|
||||
|
||||
filenames_gypi = exec_script(
|
||||
@@ -312,6 +318,13 @@ static_library("electron_lib") {
|
||||
sources = filenames_gypi.lib_sources
|
||||
set_sources_assignment_filter(sources_assignment_filter)
|
||||
|
||||
if (enable_fake_location_provider) {
|
||||
defines += [
|
||||
"OVERRIDE_LOCATION_PROVIDER"
|
||||
]
|
||||
sources += filenames_gypi.lib_sources_location_provider
|
||||
}
|
||||
|
||||
if (enable_run_as_node) {
|
||||
sources += [
|
||||
"atom/app/node_main.cc",
|
||||
|
||||
2
DEPS
2
DEPS
@@ -2,7 +2,7 @@ vars = {
|
||||
'chromium_version':
|
||||
'63.0.3239.150',
|
||||
'libchromiumcontent_revision':
|
||||
'1c542968990da951df27c8a0371a4ab5494a5a6c',
|
||||
'29e02cd4c37777734f97d00b5a538d7c7acfa67a',
|
||||
'node_version':
|
||||
'v9.7.0-33-g538a5023af',
|
||||
'native_mate_revision':
|
||||
|
||||
16
appveyor.yml
16
appveyor.yml
@@ -1,14 +1,14 @@
|
||||
version: 1.0.{build}
|
||||
branches:
|
||||
except:
|
||||
- /^release$|^release-\d-\d-x$/
|
||||
build_cloud: electron-16
|
||||
image: electron-16-vs2017
|
||||
environment:
|
||||
DISABLE_CRASH_REPORTER_TESTS: true
|
||||
image: electron-16-vs2017-15.4.5
|
||||
build_script:
|
||||
- ps: >-
|
||||
if(($env:APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME -split "/")[0] -eq ($env:APPVEYOR_REPO_NAME -split "/")[0]) {
|
||||
echo "Build worker image $env:APPVEYOR_BUILD_WORKER_IMAGE"
|
||||
|
||||
&"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
|
||||
|
||||
if($env:SKIP_GYP_BUILD -eq "true") {
|
||||
Write-warning "Skipping debug build for older branch"; Exit-AppveyorBuild
|
||||
} elseif(($env:APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME -split "/")[0] -eq ($env:APPVEYOR_REPO_NAME -split "/")[0]) {
|
||||
Write-warning "Skipping PR build for branch"; Exit-AppveyorBuild
|
||||
} else {
|
||||
Add-Path "$env:ProgramFiles (x86)\Windows Kits\10\Debuggers\x64"
|
||||
|
||||
@@ -20,12 +20,17 @@
|
||||
#include "content/public/common/user_agent.h"
|
||||
#include "media/media_features.h"
|
||||
#include "ppapi/shared_impl/ppapi_permissions.h"
|
||||
#include "third_party/widevine/cdm/widevine_cdm_common.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "url/url_constants.h"
|
||||
|
||||
#if defined(WIDEVINE_CDM_AVAILABLE) && BUILDFLAG(ENABLE_LIBRARY_CDMS)
|
||||
#if defined(WIDEVINE_CDM_AVAILABLE)
|
||||
#include "base/native_library.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "chrome/common/widevine_cdm_constants.h"
|
||||
#endif
|
||||
#include "content/public/common/cdm_info.h"
|
||||
#include "media/base/video_codecs.h"
|
||||
#endif // defined(WIDEVINE_CDM_AVAILABLE)
|
||||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
#include "atom/common/atom_constants.h"
|
||||
@@ -36,6 +41,67 @@ namespace atom {
|
||||
|
||||
namespace {
|
||||
|
||||
#if defined(WIDEVINE_CDM_AVAILABLE)
|
||||
bool IsWidevineAvailable(base::FilePath* adapter_path,
|
||||
base::FilePath* cdm_path,
|
||||
std::vector<media::VideoCodec>* codecs_supported) {
|
||||
static enum {
|
||||
NOT_CHECKED,
|
||||
FOUND,
|
||||
NOT_FOUND,
|
||||
} widevine_cdm_file_check = NOT_CHECKED;
|
||||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
||||
*adapter_path = command_line->GetSwitchValuePath(switches::kWidevineCdmPath);
|
||||
if (!adapter_path->empty()) {
|
||||
*cdm_path = adapter_path->DirName().AppendASCII(
|
||||
base::GetNativeLibraryName(kWidevineCdmLibraryName));
|
||||
if (widevine_cdm_file_check == NOT_CHECKED) {
|
||||
widevine_cdm_file_check =
|
||||
(base::PathExists(*adapter_path) && base::PathExists(*cdm_path))
|
||||
? FOUND
|
||||
: NOT_FOUND;
|
||||
}
|
||||
if (widevine_cdm_file_check == FOUND) {
|
||||
// Add the supported codecs as if they came from the component manifest.
|
||||
// This list must match the CDM that is being bundled with Chrome.
|
||||
codecs_supported->push_back(media::VideoCodec::kCodecVP8);
|
||||
codecs_supported->push_back(media::VideoCodec::kCodecVP9);
|
||||
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
|
||||
codecs_supported->push_back(media::VideoCodec::kCodecH264);
|
||||
#endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void AddWidevineAdapterFromCommandLine(
|
||||
base::CommandLine* command_line,
|
||||
std::vector<content::PepperPluginInfo>* plugins) {
|
||||
base::FilePath adapter_path;
|
||||
base::FilePath cdm_path;
|
||||
std::vector<media::VideoCodec> video_codecs_supported;
|
||||
if (IsWidevineAvailable(&adapter_path, &cdm_path, &video_codecs_supported)) {
|
||||
auto cdm_version_string =
|
||||
command_line->GetSwitchValueASCII(switches::kWidevineCdmVersion);
|
||||
content::PepperPluginInfo info;
|
||||
info.is_out_of_process = true;
|
||||
info.path = adapter_path;
|
||||
info.name = kWidevineCdmDisplayName;
|
||||
info.description =
|
||||
base::StringPrintf("%s (version: %s)", kWidevineCdmDescription,
|
||||
cdm_version_string.c_str());
|
||||
info.version = cdm_version_string;
|
||||
info.permissions = kWidevineCdmPluginPermissions;
|
||||
content::WebPluginMimeType mime_type(kWidevineCdmPluginMimeType,
|
||||
kWidevineCdmPluginExtension,
|
||||
kWidevineCdmPluginMimeTypeDescription);
|
||||
info.mime_types.push_back(mime_type);
|
||||
plugins->push_back(info);
|
||||
}
|
||||
}
|
||||
#endif // defined(WIDEVINE_CDM_AVAILABLE)
|
||||
|
||||
#if defined(ENABLE_PEPPER_FLASH)
|
||||
content::PepperPluginInfo CreatePepperFlashInfo(const base::FilePath& path,
|
||||
const std::string& version) {
|
||||
content::PepperPluginInfo plugin;
|
||||
@@ -75,29 +141,23 @@ content::PepperPluginInfo CreatePepperFlashInfo(const base::FilePath& path,
|
||||
return plugin;
|
||||
}
|
||||
|
||||
#if defined(WIDEVINE_CDM_AVAILABLE) && BUILDFLAG(ENABLE_LIBRARY_CDMS)
|
||||
content::PepperPluginInfo CreateWidevineCdmInfo(const base::FilePath& path,
|
||||
const std::string& version) {
|
||||
content::PepperPluginInfo widevine_cdm;
|
||||
widevine_cdm.is_out_of_process = true;
|
||||
widevine_cdm.path = path;
|
||||
widevine_cdm.name = kWidevineCdmDisplayName;
|
||||
widevine_cdm.description =
|
||||
kWidevineCdmDescription + std::string(" (version: ") + version + ")";
|
||||
widevine_cdm.version = version;
|
||||
content::WebPluginMimeType widevine_cdm_mime_type(
|
||||
kWidevineCdmPluginMimeType, kWidevineCdmPluginExtension,
|
||||
kWidevineCdmPluginMimeTypeDescription);
|
||||
void AddPepperFlashFromCommandLine(
|
||||
base::CommandLine* command_line,
|
||||
std::vector<content::PepperPluginInfo>* plugins) {
|
||||
base::FilePath flash_path =
|
||||
command_line->GetSwitchValuePath(switches::kPpapiFlashPath);
|
||||
if (flash_path.empty())
|
||||
return;
|
||||
|
||||
widevine_cdm.mime_types.push_back(widevine_cdm_mime_type);
|
||||
widevine_cdm.permissions = kWidevineCdmPluginPermissions;
|
||||
auto flash_version =
|
||||
command_line->GetSwitchValueASCII(switches::kPpapiFlashVersion);
|
||||
|
||||
return widevine_cdm;
|
||||
plugins->push_back(CreatePepperFlashInfo(flash_path, flash_version));
|
||||
}
|
||||
#endif // defined(WIDEVINE_CDM_AVAILABLE) && BUILDFLAG(ENABLE_LIBRARY_CDMS)
|
||||
#endif // defined(ENABLE_PEPPER_FLASH)
|
||||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
void ComputeBuiltInPlugins(std::vector<content::PepperPluginInfo>* plugins) {
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
content::PepperPluginInfo pdf_info;
|
||||
pdf_info.is_internal = true;
|
||||
pdf_info.is_out_of_process = true;
|
||||
@@ -114,8 +174,8 @@ void ComputeBuiltInPlugins(std::vector<content::PepperPluginInfo>* plugins) {
|
||||
chrome_pdf::PPP_ShutdownModule;
|
||||
pdf_info.permissions = ppapi::PERMISSION_PRIVATE | ppapi::PERMISSION_DEV;
|
||||
plugins->push_back(pdf_info);
|
||||
}
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
}
|
||||
|
||||
void ConvertStringWithSeparatorToVector(std::vector<std::string>* vec,
|
||||
const char* separator,
|
||||
@@ -129,42 +189,6 @@ void ConvertStringWithSeparatorToVector(std::vector<std::string>* vec,
|
||||
|
||||
} // namespace
|
||||
|
||||
void AddPepperFlashFromCommandLine(
|
||||
std::vector<content::PepperPluginInfo>* plugins) {
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
base::FilePath flash_path =
|
||||
command_line->GetSwitchValuePath(switches::kPpapiFlashPath);
|
||||
if (flash_path.empty())
|
||||
return;
|
||||
|
||||
auto flash_version =
|
||||
command_line->GetSwitchValueASCII(switches::kPpapiFlashVersion);
|
||||
|
||||
plugins->push_back(CreatePepperFlashInfo(flash_path, flash_version));
|
||||
}
|
||||
|
||||
#if defined(WIDEVINE_CDM_AVAILABLE) && BUILDFLAG(ENABLE_LIBRARY_CDMS)
|
||||
void AddWidevineCdmFromCommandLine(
|
||||
std::vector<content::PepperPluginInfo>* plugins) {
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
base::FilePath widevine_cdm_path =
|
||||
command_line->GetSwitchValuePath(switches::kWidevineCdmPath);
|
||||
if (widevine_cdm_path.empty())
|
||||
return;
|
||||
|
||||
if (!base::PathExists(widevine_cdm_path))
|
||||
return;
|
||||
|
||||
auto widevine_cdm_version =
|
||||
command_line->GetSwitchValueASCII(switches::kWidevineCdmVersion);
|
||||
if (widevine_cdm_version.empty())
|
||||
return;
|
||||
|
||||
plugins->push_back(
|
||||
CreateWidevineCdmInfo(widevine_cdm_path, widevine_cdm_version));
|
||||
}
|
||||
#endif // defined(WIDEVINE_CDM_AVAILABLE) && BUILDFLAG(ENABLE_LIBRARY_CDMS)
|
||||
|
||||
AtomContentClient::AtomContentClient() {}
|
||||
|
||||
AtomContentClient::~AtomContentClient() {}
|
||||
@@ -200,45 +224,43 @@ void AtomContentClient::AddAdditionalSchemes(Schemes* schemes) {
|
||||
|
||||
void AtomContentClient::AddPepperPlugins(
|
||||
std::vector<content::PepperPluginInfo>* plugins) {
|
||||
AddPepperFlashFromCommandLine(plugins);
|
||||
#if defined(WIDEVINE_CDM_AVAILABLE) && BUILDFLAG(ENABLE_LIBRARY_CDMS)
|
||||
AddWidevineCdmFromCommandLine(plugins);
|
||||
#endif // defined(WIDEVINE_CDM_AVAILABLE) && BUILDFLAG(ENABLE_LIBRARY_CDMS)
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
||||
#if defined(ENABLE_PEPPER_FLASH)
|
||||
AddPepperFlashFromCommandLine(command_line, plugins);
|
||||
#endif // defined(ENABLE_PEPPER_FLASH)
|
||||
#if defined(WIDEVINE_CDM_AVAILABLE)
|
||||
AddWidevineAdapterFromCommandLine(command_line, plugins);
|
||||
#endif // defined(WIDEVINE_CDM_AVAILABLE)
|
||||
ComputeBuiltInPlugins(plugins);
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
}
|
||||
|
||||
void AtomContentClient::AddContentDecryptionModules(
|
||||
std::vector<content::CdmInfo>* cdms,
|
||||
std::vector<media::CdmHostFilePath>* cdm_host_file_paths) {
|
||||
#if defined(WIDEVINE_CDM_AVAILABLE) && BUILDFLAG(ENABLE_LIBRARY_CDMS)
|
||||
auto command_line = base::CommandLine::ForCurrentProcess();
|
||||
base::FilePath widevine_cdm_path =
|
||||
command_line->GetSwitchValuePath(switches::kWidevineCdmPath);
|
||||
if (widevine_cdm_path.empty())
|
||||
return;
|
||||
if (cdms) {
|
||||
#if defined(WIDEVINE_CDM_AVAILABLE)
|
||||
base::FilePath adapter_path;
|
||||
base::FilePath cdm_path;
|
||||
std::vector<media::VideoCodec> video_codecs_supported;
|
||||
bool supports_persistent_license = false;
|
||||
if (IsWidevineAvailable(&adapter_path, &cdm_path,
|
||||
&video_codecs_supported)) {
|
||||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
||||
auto cdm_version_string =
|
||||
command_line->GetSwitchValueASCII(switches::kWidevineCdmVersion);
|
||||
// CdmInfo needs |path| to be the actual Widevine library,
|
||||
// not the adapter, so adjust as necessary. It will be in the
|
||||
// same directory as the installed adapter.
|
||||
const base::Version version(cdm_version_string);
|
||||
DCHECK(version.IsValid());
|
||||
|
||||
if (!base::PathExists(widevine_cdm_path))
|
||||
return;
|
||||
|
||||
auto widevine_cdm_version =
|
||||
command_line->GetSwitchValueASCII(switches::kWidevineCdmVersion);
|
||||
if (widevine_cdm_version.empty())
|
||||
return;
|
||||
|
||||
std::vector<media::VideoCodec> supported_video_codecs;
|
||||
supported_video_codecs.push_back(media::VideoCodec::kCodecVP8);
|
||||
supported_video_codecs.push_back(media::VideoCodec::kCodecVP9);
|
||||
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
|
||||
supported_video_codecs.push_back(media::VideoCodec::kCodecH264);
|
||||
#endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
|
||||
content::CdmRegistry::GetInstance()->RegisterCdm(
|
||||
content::CdmInfo(kWidevineCdmDisplayName, kWidevineCdmGuid,
|
||||
base::Version(widevine_cdm_version), widevine_cdm_path,
|
||||
kWidevineCdmFileSystemId, supported_video_codecs, false,
|
||||
kWidevineKeySystem, false));
|
||||
#endif // defined(WIDEVINE_CDM_AVAILABLE) && BUILDFLAG(ENABLE_LIBRARY_CDMS)
|
||||
cdms->push_back(content::CdmInfo(
|
||||
kWidevineCdmDisplayName, kWidevineCdmGuid, version, cdm_path,
|
||||
kWidevineCdmFileSystemId, video_codecs_supported,
|
||||
supports_persistent_license, kWidevineKeySystem, false));
|
||||
}
|
||||
#endif // defined(WIDEVINE_CDM_AVAILABLE)
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -24,10 +24,14 @@
|
||||
#include "base/win/windows_version.h"
|
||||
#include "content/public/app/sandbox_helper_win.h"
|
||||
#include "sandbox/win/src/sandbox_types.h"
|
||||
#elif defined(OS_LINUX) // defined(OS_WIN)
|
||||
#elif defined(OS_LINUX) // defined(OS_WIN)
|
||||
#include <unistd.h>
|
||||
#include <cstdio>
|
||||
#include "atom/app/atom_main_delegate.h" // NOLINT
|
||||
#include "content/public/app/content_main.h"
|
||||
#else // defined(OS_LINUX)
|
||||
#include <unistd.h>
|
||||
#include <cstdio>
|
||||
#include "atom/app/atom_library_main.h"
|
||||
#endif // defined(OS_MACOSX)
|
||||
|
||||
@@ -55,6 +59,25 @@ bool IsEnvSet(const char* name) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(OS_POSIX)
|
||||
void FixStdioStreams() {
|
||||
// libuv may mark stdin/stdout/stderr as close-on-exec, which interferes
|
||||
// with chromium's subprocess spawning. As a workaround, we detect if these
|
||||
// streams are closed on startup, and reopen them as /dev/null if necessary.
|
||||
// Otherwise, an unrelated file descriptor will be assigned as stdout/stderr
|
||||
// which may cause various errors when attempting to write to them.
|
||||
//
|
||||
// For details see https://github.com/libuv/libuv/issues/2062
|
||||
struct stat st;
|
||||
if (fstat(STDIN_FILENO, &st) < 0 && errno == EBADF)
|
||||
freopen("/dev/null", "r", stdin);
|
||||
if (fstat(STDOUT_FILENO, &st) < 0 && errno == EBADF)
|
||||
freopen("/dev/null", "w", stdout);
|
||||
if (fstat(STDERR_FILENO, &st) < 0 && errno == EBADF)
|
||||
freopen("/dev/null", "w", stderr);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
#if defined(OS_WIN)
|
||||
@@ -157,6 +180,8 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
#ifdef ENABLE_RUN_AS_NODE
|
||||
FixStdioStreams();
|
||||
|
||||
if (IsEnvSet(kRunAsNode)) {
|
||||
base::i18n::InitializeICU();
|
||||
base::AtExitManager atexit_manager;
|
||||
@@ -176,6 +201,8 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
#ifdef ENABLE_RUN_AS_NODE
|
||||
FixStdioStreams();
|
||||
|
||||
if (IsEnvSet(kRunAsNode)) {
|
||||
return AtomInitializeICUandStartNode(argc, argv);
|
||||
}
|
||||
|
||||
@@ -667,17 +667,17 @@ void App::OnNewWindowForTab() {
|
||||
}
|
||||
#endif
|
||||
|
||||
void App::OnLogin(LoginHandler* login_handler,
|
||||
void App::OnLogin(scoped_refptr<LoginHandler> login_handler,
|
||||
const base::DictionaryValue& request_details) {
|
||||
v8::Locker locker(isolate());
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
bool prevent_default = false;
|
||||
content::WebContents* web_contents = login_handler->GetWebContents();
|
||||
if (web_contents) {
|
||||
prevent_default =
|
||||
Emit("login", WebContents::CreateFrom(isolate(), web_contents),
|
||||
request_details, login_handler->auth_info(),
|
||||
base::Bind(&PassLoginInformation, WrapRefCounted(login_handler)));
|
||||
prevent_default = Emit(
|
||||
"login", WebContents::CreateFrom(isolate(), web_contents),
|
||||
request_details, login_handler->auth_info(),
|
||||
base::Bind(&PassLoginInformation, base::RetainedRef(login_handler)));
|
||||
}
|
||||
|
||||
// Default behavior is to always cancel the auth.
|
||||
|
||||
@@ -98,7 +98,7 @@ class App : public AtomBrowserClient::Delegate,
|
||||
void OnActivate(bool has_visible_windows) override;
|
||||
void OnWillFinishLaunching() override;
|
||||
void OnFinishLaunching(const base::DictionaryValue& launch_info) override;
|
||||
void OnLogin(LoginHandler* login_handler,
|
||||
void OnLogin(scoped_refptr<LoginHandler> login_handler,
|
||||
const base::DictionaryValue& request_details) override;
|
||||
void OnAccessibilitySupportChanged() override;
|
||||
void OnPreMainMessageLoopRun() override;
|
||||
|
||||
@@ -63,7 +63,12 @@ void BrowserWindow::OverrideNSWindowContentView(
|
||||
NSView* webView = iwc->GetView()->GetNativeView();
|
||||
NSView* contentView = [window()->GetNativeWindow() contentView];
|
||||
[webView setFrame:[contentView bounds]];
|
||||
[contentView addSubview:webView];
|
||||
|
||||
// ensure that buttons view is floated to top of view hierarchy
|
||||
NSArray* subviews = [contentView subviews];
|
||||
NSView* last = subviews.lastObject;
|
||||
[contentView addSubview:webView positioned:NSWindowBelow relativeTo:last];
|
||||
|
||||
[contentView viewDidMoveToWindow];
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "content/public/browser/tracing_controller.h"
|
||||
@@ -23,15 +24,27 @@ struct Converter<base::trace_event::TraceConfig> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::trace_event::TraceConfig* out) {
|
||||
// (alexeykuzmin): A combination of "categoryFilter" and "traceOptions"
|
||||
// has to be checked first because none of the fields
|
||||
// in the `memory_dump_config` dict below are mandatory
|
||||
// and we cannot check the config format.
|
||||
Dictionary options;
|
||||
if (!ConvertFromV8(isolate, val, &options))
|
||||
return false;
|
||||
std::string category_filter, trace_options;
|
||||
if (!options.Get("categoryFilter", &category_filter) ||
|
||||
!options.Get("traceOptions", &trace_options))
|
||||
return false;
|
||||
*out = base::trace_event::TraceConfig(category_filter, trace_options);
|
||||
return true;
|
||||
if (ConvertFromV8(isolate, val, &options)) {
|
||||
std::string category_filter, trace_options;
|
||||
if (options.Get("categoryFilter", &category_filter) &&
|
||||
options.Get("traceOptions", &trace_options)) {
|
||||
*out = base::trace_event::TraceConfig(category_filter, trace_options);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
base::DictionaryValue memory_dump_config;
|
||||
if (ConvertFromV8(isolate, val, &memory_dump_config)) {
|
||||
*out = base::trace_event::TraceConfig(memory_dump_config);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "atom/browser/api/atom_api_cookies.h"
|
||||
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/cookie_change_notifier.h"
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
@@ -55,20 +56,21 @@ struct Converter<net::CanonicalCookie> {
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<net::CookieChangeCause> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const net::CookieChangeCause& val) {
|
||||
struct Converter<network::mojom::CookieChangeCause> {
|
||||
static v8::Local<v8::Value> ToV8(
|
||||
v8::Isolate* isolate,
|
||||
const network::mojom::CookieChangeCause& val) {
|
||||
switch (val) {
|
||||
case net::CookieChangeCause::INSERTED:
|
||||
case net::CookieChangeCause::EXPLICIT:
|
||||
case network::mojom::CookieChangeCause::INSERTED:
|
||||
case network::mojom::CookieChangeCause::EXPLICIT:
|
||||
return mate::StringToV8(isolate, "explicit");
|
||||
case net::CookieChangeCause::OVERWRITE:
|
||||
case network::mojom::CookieChangeCause::OVERWRITE:
|
||||
return mate::StringToV8(isolate, "overwrite");
|
||||
case net::CookieChangeCause::EXPIRED:
|
||||
case network::mojom::CookieChangeCause::EXPIRED:
|
||||
return mate::StringToV8(isolate, "expired");
|
||||
case net::CookieChangeCause::EVICTED:
|
||||
case network::mojom::CookieChangeCause::EVICTED:
|
||||
return mate::StringToV8(isolate, "evicted");
|
||||
case net::CookieChangeCause::EXPIRED_OVERWRITE:
|
||||
case network::mojom::CookieChangeCause::EXPIRED_OVERWRITE:
|
||||
return mate::StringToV8(isolate, "expired-overwrite");
|
||||
default:
|
||||
return mate::StringToV8(isolate, "unknown");
|
||||
@@ -253,9 +255,9 @@ void SetCookieOnIO(scoped_refptr<net::URLRequestContextGetter> getter,
|
||||
Cookies::Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context)
|
||||
: browser_context_(browser_context) {
|
||||
Init(isolate);
|
||||
auto subscription = browser_context->RegisterCookieChangeCallback(
|
||||
base::Bind(&Cookies::OnCookieChanged, base::Unretained(this)));
|
||||
browser_context->set_cookie_change_subscription(std::move(subscription));
|
||||
cookie_change_subscription_ =
|
||||
browser_context_->cookie_change_notifier()->RegisterCookieChangeCallback(
|
||||
base::Bind(&Cookies::OnCookieChanged, base::Unretained(this)));
|
||||
}
|
||||
|
||||
Cookies::~Cookies() {}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "atom/browser/net/cookie_details.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/callback_list.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "net/cookies/canonical_cookie.h"
|
||||
|
||||
@@ -55,10 +55,12 @@ class Cookies : public mate::TrackableObject<Cookies> {
|
||||
void Set(const base::DictionaryValue& details, const SetCallback& callback);
|
||||
void FlushStore(const base::Closure& callback);
|
||||
|
||||
// AtomBrowserContext::RegisterCookieChangeCallback subscription:
|
||||
// CookieChangeNotifier subscription:
|
||||
void OnCookieChanged(const CookieDetails*);
|
||||
|
||||
private:
|
||||
std::unique_ptr<base::CallbackList<void(const CookieDetails*)>::Subscription>
|
||||
cookie_change_subscription_;
|
||||
scoped_refptr<AtomBrowserContext> browser_context_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Cookies);
|
||||
|
||||
@@ -6,16 +6,13 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "base/json/json_reader.h"
|
||||
#include "base/json/json_writer.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "content/public/browser/devtools_agent_host.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
@@ -26,20 +23,22 @@ namespace atom {
|
||||
namespace api {
|
||||
|
||||
Debugger::Debugger(v8::Isolate* isolate, content::WebContents* web_contents)
|
||||
: web_contents_(web_contents) {
|
||||
: content::WebContentsObserver(web_contents), web_contents_(web_contents) {
|
||||
Init(isolate);
|
||||
}
|
||||
|
||||
Debugger::~Debugger() {}
|
||||
|
||||
void Debugger::AgentHostClosed(DevToolsAgentHost* agent_host) {
|
||||
std::string detach_reason = "target closed";
|
||||
Emit("detach", detach_reason);
|
||||
DCHECK(agent_host == agent_host_);
|
||||
agent_host_ = nullptr;
|
||||
ClearPendingRequests();
|
||||
Emit("detach", "target closed");
|
||||
}
|
||||
|
||||
void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host,
|
||||
const std::string& message) {
|
||||
DCHECK(agent_host == agent_host_.get());
|
||||
DCHECK(agent_host == agent_host_);
|
||||
|
||||
v8::Locker locker(isolate());
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
@@ -77,42 +76,52 @@ void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host,
|
||||
}
|
||||
}
|
||||
|
||||
void Debugger::RenderFrameHostChanged(content::RenderFrameHost* old_rfh,
|
||||
content::RenderFrameHost* new_rfh) {
|
||||
if (agent_host_) {
|
||||
agent_host_->DisconnectWebContents();
|
||||
auto* web_contents = content::WebContents::FromRenderFrameHost(new_rfh);
|
||||
agent_host_->ConnectWebContents(web_contents);
|
||||
}
|
||||
}
|
||||
|
||||
void Debugger::Attach(mate::Arguments* args) {
|
||||
std::string protocol_version;
|
||||
args->GetNext(&protocol_version);
|
||||
|
||||
if (agent_host_) {
|
||||
args->ThrowError("Debugger is already attached to the target");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!protocol_version.empty() &&
|
||||
!DevToolsAgentHost::IsSupportedProtocolVersion(protocol_version)) {
|
||||
args->ThrowError("Requested protocol version is not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents_);
|
||||
if (!agent_host_.get()) {
|
||||
if (!agent_host_) {
|
||||
args->ThrowError("No target available");
|
||||
return;
|
||||
}
|
||||
if (agent_host_->IsAttached()) {
|
||||
args->ThrowError("Another debugger is already attached to this target");
|
||||
return;
|
||||
}
|
||||
|
||||
agent_host_->AttachClient(this);
|
||||
}
|
||||
|
||||
bool Debugger::IsAttached() {
|
||||
return agent_host_.get() ? agent_host_->IsAttached() : false;
|
||||
return agent_host_ && agent_host_->IsAttached();
|
||||
}
|
||||
|
||||
void Debugger::Detach() {
|
||||
if (!agent_host_.get())
|
||||
if (!agent_host_)
|
||||
return;
|
||||
agent_host_->DetachClient(this);
|
||||
AgentHostClosed(agent_host_.get());
|
||||
agent_host_ = nullptr;
|
||||
}
|
||||
|
||||
void Debugger::SendCommand(mate::Arguments* args) {
|
||||
if (!agent_host_.get())
|
||||
if (!agent_host_)
|
||||
return;
|
||||
|
||||
std::string method;
|
||||
@@ -138,6 +147,16 @@ void Debugger::SendCommand(mate::Arguments* args) {
|
||||
agent_host_->DispatchProtocolMessage(this, json_args);
|
||||
}
|
||||
|
||||
void Debugger::ClearPendingRequests() {
|
||||
if (pending_requests_.empty())
|
||||
return;
|
||||
base::Value error(base::Value::Type::DICTIONARY);
|
||||
base::Value error_msg("target closed while handling command");
|
||||
error.SetKey("message", std::move(error_msg));
|
||||
for (const auto& it : pending_requests_)
|
||||
it.second.Run(error, base::Value());
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<Debugger> Debugger::Create(v8::Isolate* isolate,
|
||||
content::WebContents* web_contents) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "base/callback.h"
|
||||
#include "base/values.h"
|
||||
#include "content/public/browser/devtools_agent_host_client.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "native_mate/handle.h"
|
||||
|
||||
namespace content {
|
||||
@@ -28,11 +29,11 @@ namespace atom {
|
||||
namespace api {
|
||||
|
||||
class Debugger : public mate::TrackableObject<Debugger>,
|
||||
public content::DevToolsAgentHostClient {
|
||||
public content::DevToolsAgentHostClient,
|
||||
public content::WebContentsObserver {
|
||||
public:
|
||||
using SendCommandCallback =
|
||||
base::Callback<void(const base::DictionaryValue&,
|
||||
const base::DictionaryValue&)>;
|
||||
base::Callback<void(const base::Value&, const base::Value&)>;
|
||||
|
||||
static mate::Handle<Debugger> Create(v8::Isolate* isolate,
|
||||
content::WebContents* web_contents);
|
||||
@@ -50,6 +51,10 @@ class Debugger : public mate::TrackableObject<Debugger>,
|
||||
void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host,
|
||||
const std::string& message) override;
|
||||
|
||||
// content::WebContentsObserver:
|
||||
void RenderFrameHostChanged(content::RenderFrameHost* old_rfh,
|
||||
content::RenderFrameHost* new_rfh) override;
|
||||
|
||||
private:
|
||||
using PendingRequestMap = std::map<int, SendCommandCallback>;
|
||||
|
||||
@@ -57,6 +62,7 @@ class Debugger : public mate::TrackableObject<Debugger>,
|
||||
bool IsAttached();
|
||||
void Detach();
|
||||
void SendCommand(mate::Arguments* args);
|
||||
void ClearPendingRequests();
|
||||
|
||||
content::WebContents* web_contents_; // Weak Reference.
|
||||
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
||||
|
||||
@@ -3,13 +3,19 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/api/atom_api_net_log.h"
|
||||
#include "atom/browser/atom_browser_client.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "base/callback.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "components/net_log/chrome_net_log.h"
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "net/url_request/url_request_context_getter.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
@@ -17,17 +23,17 @@ namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
NetLog::NetLog(v8::Isolate* isolate) {
|
||||
NetLog::NetLog(v8::Isolate* isolate, AtomBrowserContext* browser_context)
|
||||
: browser_context_(browser_context) {
|
||||
Init(isolate);
|
||||
|
||||
net_log_ = atom::AtomBrowserClient::Get()->GetNetLog();
|
||||
net_log_writer_ =
|
||||
atom::AtomBrowserMainParts::Get()->net_log()->net_export_file_writer();
|
||||
net_log_writer_->AddObserver(this);
|
||||
}
|
||||
|
||||
NetLog::~NetLog() {}
|
||||
|
||||
// static
|
||||
v8::Local<v8::Value> NetLog::Create(v8::Isolate* isolate) {
|
||||
return mate::CreateHandle(isolate, new NetLog(isolate)).ToV8();
|
||||
NetLog::~NetLog() {
|
||||
net_log_writer_->RemoveObserver(this);
|
||||
}
|
||||
|
||||
void NetLog::StartLogging(mate::Arguments* args) {
|
||||
@@ -37,22 +43,82 @@ void NetLog::StartLogging(mate::Arguments* args) {
|
||||
return;
|
||||
}
|
||||
|
||||
net_log_->StartDynamicLogging(log_path);
|
||||
net_log::NetExportFileWriter::URLRequestContextGetterList context_getters = {
|
||||
browser_context_->GetRequestContext()};
|
||||
|
||||
// TODO(deepak1556): Provide more flexibility to this module
|
||||
// by allowing customizations on the capturing options.
|
||||
net_log_writer_->StartNetLog(
|
||||
log_path, net::NetLogCaptureMode::Default(),
|
||||
net_log::NetExportFileWriter::kNoLimit /* file size limit */,
|
||||
base::CommandLine::ForCurrentProcess()->GetCommandLineString(),
|
||||
std::string(), context_getters);
|
||||
}
|
||||
|
||||
bool NetLog::IsCurrentlyLogging() {
|
||||
return net_log_->IsDynamicLogging();
|
||||
std::string NetLog::GetLoggingState() const {
|
||||
if (!net_log_state_)
|
||||
return std::string();
|
||||
const base::Value* current_log_state =
|
||||
net_log_state_->FindKeyOfType("state", base::Value::Type::STRING);
|
||||
if (!current_log_state)
|
||||
return std::string();
|
||||
return current_log_state->GetString();
|
||||
}
|
||||
|
||||
base::FilePath::StringType NetLog::GetCurrentlyLoggingPath() {
|
||||
return net_log_->GetDynamicLoggingPath().value();
|
||||
bool NetLog::IsCurrentlyLogging() const {
|
||||
const std::string log_state = GetLoggingState();
|
||||
return (log_state == "STARTING_LOG") || (log_state == "LOGGING");
|
||||
}
|
||||
|
||||
std::string NetLog::GetCurrentlyLoggingPath() const {
|
||||
// Net log exporter has a default path which will be used
|
||||
// when no log path is provided, but since we don't allow
|
||||
// net log capture without user provided file path, this
|
||||
// check is completely safe.
|
||||
if (IsCurrentlyLogging()) {
|
||||
const base::Value* current_log_path =
|
||||
net_log_state_->FindKeyOfType("file", base::Value::Type::STRING);
|
||||
if (current_log_path)
|
||||
return current_log_path->GetString();
|
||||
}
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
void NetLog::StopLogging(mate::Arguments* args) {
|
||||
base::OnceClosure callback;
|
||||
args->GetNext(&callback);
|
||||
net_log::NetExportFileWriter::FilePathCallback callback;
|
||||
if (!args->GetNext(&callback)) {
|
||||
args->ThrowError("Invalid callback function");
|
||||
return;
|
||||
}
|
||||
|
||||
net_log_->StopDynamicLogging(std::move(callback));
|
||||
if (IsCurrentlyLogging()) {
|
||||
stop_callback_queue_.emplace_back(callback);
|
||||
net_log_writer_->StopNetLog(nullptr, nullptr);
|
||||
} else {
|
||||
callback.Run(base::FilePath());
|
||||
}
|
||||
}
|
||||
|
||||
void NetLog::OnNewState(const base::DictionaryValue& state) {
|
||||
net_log_state_ = state.CreateDeepCopy();
|
||||
|
||||
if (stop_callback_queue_.empty())
|
||||
return;
|
||||
|
||||
if (GetLoggingState() == "NOT_LOGGING") {
|
||||
for (auto& callback : stop_callback_queue_) {
|
||||
if (!callback.is_null())
|
||||
net_log_writer_->GetFilePathToCompletedLog(callback);
|
||||
}
|
||||
stop_callback_queue_.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<NetLog> NetLog::Create(v8::Isolate* isolate,
|
||||
AtomBrowserContext* browser_context) {
|
||||
return mate::CreateHandle(isolate, new NetLog(isolate, browser_context));
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -63,28 +129,9 @@ void NetLog::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetProperty("currentlyLogging", &NetLog::IsCurrentlyLogging)
|
||||
.SetProperty("currentlyLoggingPath", &NetLog::GetCurrentlyLoggingPath)
|
||||
.SetMethod("startLogging", &NetLog::StartLogging)
|
||||
.SetMethod("_stopLogging", &NetLog::StopLogging);
|
||||
.SetMethod("stopLogging", &NetLog::StopLogging);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
||||
} // namespace atom
|
||||
|
||||
namespace {
|
||||
|
||||
using atom::api::NetLog;
|
||||
|
||||
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.Set("netLog", NetLog::Create(isolate));
|
||||
dict.Set("NetLog", NetLog::GetConstructor(isolate)->GetFunction());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_net_log, Initialize)
|
||||
|
||||
@@ -5,32 +5,50 @@
|
||||
#ifndef ATOM_BROWSER_API_ATOM_API_NET_LOG_H_
|
||||
#define ATOM_BROWSER_API_ATOM_API_NET_LOG_H_
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "brightray/browser/net_log.h"
|
||||
#include "native_mate/wrappable.h"
|
||||
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/values.h"
|
||||
#include "components/net_log/net_export_file_writer.h"
|
||||
#include "native_mate/handle.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomBrowserContext;
|
||||
|
||||
namespace api {
|
||||
|
||||
class NetLog : public mate::Wrappable<NetLog> {
|
||||
class NetLog : public mate::TrackableObject<NetLog>,
|
||||
public net_log::NetExportFileWriter::StateObserver {
|
||||
public:
|
||||
static v8::Local<v8::Value> Create(v8::Isolate* isolate);
|
||||
static mate::Handle<NetLog> Create(v8::Isolate* isolate,
|
||||
AtomBrowserContext* browser_context);
|
||||
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype);
|
||||
|
||||
void StartLogging(mate::Arguments* args);
|
||||
bool IsCurrentlyLogging();
|
||||
base::FilePath::StringType GetCurrentlyLoggingPath();
|
||||
std::string GetLoggingState() const;
|
||||
bool IsCurrentlyLogging() const;
|
||||
std::string GetCurrentlyLoggingPath() const;
|
||||
void StopLogging(mate::Arguments* args);
|
||||
|
||||
protected:
|
||||
explicit NetLog(v8::Isolate* isolate);
|
||||
explicit NetLog(v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||
~NetLog() override;
|
||||
|
||||
// net_log::NetExportFileWriter::StateObserver implementation
|
||||
void OnNewState(const base::DictionaryValue& state) override;
|
||||
|
||||
private:
|
||||
brightray::NetLog* net_log_;
|
||||
AtomBrowserContext* browser_context_;
|
||||
net_log::NetExportFileWriter* net_log_writer_;
|
||||
std::list<net_log::NetExportFileWriter::FilePathCallback>
|
||||
stop_callback_queue_;
|
||||
std::unique_ptr<base::DictionaryValue> net_log_state_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NetLog);
|
||||
};
|
||||
|
||||
@@ -83,7 +83,8 @@ void Protocol::UnregisterProtocol(const std::string& scheme,
|
||||
mate::Arguments* args) {
|
||||
CompletionCallback callback;
|
||||
args->GetNext(&callback);
|
||||
auto* getter = browser_context_->GetRequestContext();
|
||||
auto* getter = static_cast<URLRequestContextGetter*>(
|
||||
browser_context_->GetRequestContext());
|
||||
content::BrowserThread::PostTaskAndReplyWithResult(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(&Protocol::UnregisterProtocolInIO,
|
||||
@@ -93,10 +94,9 @@ void Protocol::UnregisterProtocol(const std::string& scheme,
|
||||
|
||||
// static
|
||||
Protocol::ProtocolError Protocol::UnregisterProtocolInIO(
|
||||
scoped_refptr<brightray::URLRequestContextGetter> request_context_getter,
|
||||
scoped_refptr<URLRequestContextGetter> request_context_getter,
|
||||
const std::string& scheme) {
|
||||
auto* job_factory = static_cast<AtomURLRequestJobFactory*>(
|
||||
request_context_getter->job_factory());
|
||||
auto* job_factory = request_context_getter->job_factory();
|
||||
if (!job_factory->HasProtocolHandler(scheme))
|
||||
return PROTOCOL_NOT_REGISTERED;
|
||||
job_factory->SetProtocolHandler(scheme, nullptr);
|
||||
@@ -105,7 +105,8 @@ Protocol::ProtocolError Protocol::UnregisterProtocolInIO(
|
||||
|
||||
void Protocol::IsProtocolHandled(const std::string& scheme,
|
||||
const BooleanCallback& callback) {
|
||||
auto* getter = browser_context_->GetRequestContext();
|
||||
auto* getter = static_cast<URLRequestContextGetter*>(
|
||||
browser_context_->GetRequestContext());
|
||||
content::BrowserThread::PostTaskAndReplyWithResult(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::Bind(&Protocol::IsProtocolHandledInIO, base::RetainedRef(getter),
|
||||
@@ -115,7 +116,7 @@ void Protocol::IsProtocolHandled(const std::string& scheme,
|
||||
|
||||
// static
|
||||
bool Protocol::IsProtocolHandledInIO(
|
||||
scoped_refptr<brightray::URLRequestContextGetter> request_context_getter,
|
||||
scoped_refptr<URLRequestContextGetter> request_context_getter,
|
||||
const std::string& scheme) {
|
||||
return request_context_getter->job_factory()->IsHandledProtocol(scheme);
|
||||
}
|
||||
@@ -124,7 +125,8 @@ void Protocol::UninterceptProtocol(const std::string& scheme,
|
||||
mate::Arguments* args) {
|
||||
CompletionCallback callback;
|
||||
args->GetNext(&callback);
|
||||
auto* getter = browser_context_->GetRequestContext();
|
||||
auto* getter = static_cast<URLRequestContextGetter*>(
|
||||
browser_context_->GetRequestContext());
|
||||
content::BrowserThread::PostTaskAndReplyWithResult(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(&Protocol::UninterceptProtocolInIO,
|
||||
@@ -134,11 +136,9 @@ void Protocol::UninterceptProtocol(const std::string& scheme,
|
||||
|
||||
// static
|
||||
Protocol::ProtocolError Protocol::UninterceptProtocolInIO(
|
||||
scoped_refptr<brightray::URLRequestContextGetter> request_context_getter,
|
||||
scoped_refptr<URLRequestContextGetter> request_context_getter,
|
||||
const std::string& scheme) {
|
||||
return static_cast<AtomURLRequestJobFactory*>(
|
||||
request_context_getter->job_factory())
|
||||
->UninterceptProtocol(scheme)
|
||||
return request_context_getter->job_factory()->UninterceptProtocol(scheme)
|
||||
? PROTOCOL_OK
|
||||
: PROTOCOL_NOT_INTERCEPTED;
|
||||
}
|
||||
|
||||
@@ -78,13 +78,13 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
||||
net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate) const override {
|
||||
RequestJob* request_job = new RequestJob(request, network_delegate);
|
||||
request_job->SetHandlerInfo(isolate_, request_context_.get(), handler_);
|
||||
request_job->SetHandlerInfo(isolate_, request_context_, handler_);
|
||||
return request_job;
|
||||
}
|
||||
|
||||
private:
|
||||
v8::Isolate* isolate_;
|
||||
scoped_refptr<net::URLRequestContextGetter> request_context_;
|
||||
net::URLRequestContextGetter* request_context_;
|
||||
Protocol::Handler handler_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CustomProtocolHandler);
|
||||
@@ -100,7 +100,8 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
||||
mate::Arguments* args) {
|
||||
CompletionCallback callback;
|
||||
args->GetNext(&callback);
|
||||
auto* getter = browser_context_->GetRequestContext();
|
||||
auto* getter = static_cast<URLRequestContextGetter*>(
|
||||
browser_context_->GetRequestContext());
|
||||
content::BrowserThread::PostTaskAndReplyWithResult(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(&Protocol::RegisterProtocolInIO<RequestJob>,
|
||||
@@ -109,12 +110,11 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
||||
}
|
||||
template <typename RequestJob>
|
||||
static ProtocolError RegisterProtocolInIO(
|
||||
scoped_refptr<brightray::URLRequestContextGetter> request_context_getter,
|
||||
scoped_refptr<URLRequestContextGetter> request_context_getter,
|
||||
v8::Isolate* isolate,
|
||||
const std::string& scheme,
|
||||
const Handler& handler) {
|
||||
auto* job_factory = static_cast<AtomURLRequestJobFactory*>(
|
||||
request_context_getter->job_factory());
|
||||
auto* job_factory = request_context_getter->job_factory();
|
||||
if (job_factory->IsHandledProtocol(scheme))
|
||||
return PROTOCOL_REGISTERED;
|
||||
auto protocol_handler = std::make_unique<CustomProtocolHandler<RequestJob>>(
|
||||
@@ -128,14 +128,14 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
||||
// Unregister the protocol handler that handles |scheme|.
|
||||
void UnregisterProtocol(const std::string& scheme, mate::Arguments* args);
|
||||
static ProtocolError UnregisterProtocolInIO(
|
||||
scoped_refptr<brightray::URLRequestContextGetter> request_context_getter,
|
||||
scoped_refptr<URLRequestContextGetter> request_context_getter,
|
||||
const std::string& scheme);
|
||||
|
||||
// Whether the protocol has handler registered.
|
||||
void IsProtocolHandled(const std::string& scheme,
|
||||
const BooleanCallback& callback);
|
||||
static bool IsProtocolHandledInIO(
|
||||
scoped_refptr<brightray::URLRequestContextGetter> request_context_getter,
|
||||
scoped_refptr<URLRequestContextGetter> request_context_getter,
|
||||
const std::string& scheme);
|
||||
|
||||
// Replace the protocol handler with a new one.
|
||||
@@ -145,7 +145,8 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
||||
mate::Arguments* args) {
|
||||
CompletionCallback callback;
|
||||
args->GetNext(&callback);
|
||||
auto* getter = browser_context_->GetRequestContext();
|
||||
auto* getter = static_cast<URLRequestContextGetter*>(
|
||||
browser_context_->GetRequestContext());
|
||||
content::BrowserThread::PostTaskAndReplyWithResult(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(&Protocol::InterceptProtocolInIO<RequestJob>,
|
||||
@@ -154,12 +155,11 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
||||
}
|
||||
template <typename RequestJob>
|
||||
static ProtocolError InterceptProtocolInIO(
|
||||
scoped_refptr<brightray::URLRequestContextGetter> request_context_getter,
|
||||
scoped_refptr<URLRequestContextGetter> request_context_getter,
|
||||
v8::Isolate* isolate,
|
||||
const std::string& scheme,
|
||||
const Handler& handler) {
|
||||
auto* job_factory = static_cast<AtomURLRequestJobFactory*>(
|
||||
request_context_getter->job_factory());
|
||||
auto* job_factory = request_context_getter->job_factory();
|
||||
if (!job_factory->IsHandledProtocol(scheme))
|
||||
return PROTOCOL_NOT_REGISTERED;
|
||||
// It is possible a protocol is handled but can not be intercepted.
|
||||
@@ -175,7 +175,7 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
||||
// Restore the |scheme| to its original protocol handler.
|
||||
void UninterceptProtocol(const std::string& scheme, mate::Arguments* args);
|
||||
static ProtocolError UninterceptProtocolInIO(
|
||||
scoped_refptr<brightray::URLRequestContextGetter> request_context_getter,
|
||||
scoped_refptr<URLRequestContextGetter> request_context_getter,
|
||||
const std::string& scheme);
|
||||
|
||||
// Convert error code to JS exception and call the callback.
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "atom/browser/api/atom_api_cookies.h"
|
||||
#include "atom/browser/api/atom_api_download_item.h"
|
||||
#include "atom/browser/api/atom_api_net_log.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"
|
||||
@@ -29,12 +30,14 @@
|
||||
#include "base/guid.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "brightray/browser/media/media_device_id_salt.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/download/public/common/download_danger_type.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "components/prefs/value_map_pref_store.h"
|
||||
#include "components/proxy_config/proxy_config_dictionary.h"
|
||||
#include "components/proxy_config/proxy_config_pref_names.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/download_item_utils.h"
|
||||
#include "content/public/browser/download_manager_delegate.h"
|
||||
@@ -46,8 +49,8 @@
|
||||
#include "net/dns/host_cache.h"
|
||||
#include "net/http/http_auth_handler_factory.h"
|
||||
#include "net/http/http_auth_preferences.h"
|
||||
#include "net/proxy_resolution/proxy_config_service_fixed.h"
|
||||
#include "net/proxy_resolution/proxy_service.h"
|
||||
#include "net/http/http_cache.h"
|
||||
#include "net/http/http_transaction_factory.h"
|
||||
#include "net/url_request/static_http_user_agent_settings.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
#include "net/url_request/url_request_context_getter.h"
|
||||
@@ -179,37 +182,6 @@ struct Converter<ClearAuthCacheOptions> {
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<net::ProxyConfig> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
net::ProxyConfig* out) {
|
||||
std::string proxy_rules, proxy_bypass_rules;
|
||||
GURL pac_url;
|
||||
mate::Dictionary options;
|
||||
// Fallback to previous API when passed String.
|
||||
// https://git.io/vuhjj
|
||||
if (ConvertFromV8(isolate, val, &proxy_rules)) {
|
||||
pac_url = GURL(proxy_rules); // Assume it is PAC script if it is URL.
|
||||
} else if (ConvertFromV8(isolate, val, &options)) {
|
||||
options.Get("pacScript", &pac_url);
|
||||
options.Get("proxyRules", &proxy_rules);
|
||||
options.Get("proxyBypassRules", &proxy_bypass_rules);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// pacScript takes precedence over proxyRules.
|
||||
if (!pac_url.is_empty() && pac_url.is_valid()) {
|
||||
out->set_pac_url(pac_url);
|
||||
} else {
|
||||
out->proxy_rules().ParseFromString(proxy_rules);
|
||||
out->proxy_rules().bypass_rules.ParseFromString(proxy_bypass_rules);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<atom::VerifyRequestParams> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
@@ -236,56 +208,6 @@ const char kPersistPrefix[] = "persist:";
|
||||
// Referenced session objects.
|
||||
std::map<uint32_t, v8::Global<v8::Object>> g_sessions;
|
||||
|
||||
class ResolveProxyHelper {
|
||||
public:
|
||||
ResolveProxyHelper(AtomBrowserContext* browser_context,
|
||||
const GURL& url,
|
||||
const Session::ResolveProxyCallback& callback)
|
||||
: callback_(callback),
|
||||
original_thread_(base::ThreadTaskRunnerHandle::Get()) {
|
||||
scoped_refptr<net::URLRequestContextGetter> context_getter =
|
||||
browser_context->url_request_context_getter();
|
||||
context_getter->GetNetworkTaskRunner()->PostTask(
|
||||
FROM_HERE, base::BindOnce(&ResolveProxyHelper::ResolveProxy,
|
||||
base::Unretained(this), context_getter, url));
|
||||
}
|
||||
|
||||
void OnResolveProxyCompleted(int result) {
|
||||
std::string proxy;
|
||||
if (result == net::OK)
|
||||
proxy = proxy_info_.ToPacString();
|
||||
original_thread_->PostTask(FROM_HERE, base::BindOnce(callback_, proxy));
|
||||
delete this;
|
||||
}
|
||||
|
||||
private:
|
||||
void ResolveProxy(scoped_refptr<net::URLRequestContextGetter> context_getter,
|
||||
const GURL& url) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
|
||||
|
||||
net::ProxyResolutionService* proxy_service =
|
||||
context_getter->GetURLRequestContext()->proxy_resolution_service();
|
||||
net::CompletionCallback completion_callback = base::Bind(
|
||||
&ResolveProxyHelper::OnResolveProxyCompleted, base::Unretained(this));
|
||||
|
||||
// Start the request.
|
||||
int result = proxy_service->ResolveProxy(url, "GET", &proxy_info_,
|
||||
completion_callback, &pac_req_,
|
||||
nullptr, net::NetLogWithSource());
|
||||
|
||||
// Completed synchronously.
|
||||
if (result != net::ERR_IO_PENDING)
|
||||
completion_callback.Run(result);
|
||||
}
|
||||
|
||||
Session::ResolveProxyCallback callback_;
|
||||
net::ProxyInfo proxy_info_;
|
||||
net::ProxyResolutionService::Request* pac_req_;
|
||||
scoped_refptr<base::SingleThreadTaskRunner> original_thread_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ResolveProxyHelper);
|
||||
};
|
||||
|
||||
// Runs the callback in UI thread.
|
||||
void RunCallbackInUI(const base::Callback<void()>& callback) {
|
||||
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
|
||||
@@ -343,18 +265,6 @@ void DoCacheActionInIO(
|
||||
on_get_backend.Run(net::OK);
|
||||
}
|
||||
|
||||
void SetProxyInIO(scoped_refptr<net::URLRequestContextGetter> getter,
|
||||
const net::ProxyConfig& config,
|
||||
const base::Closure& callback) {
|
||||
auto* proxy_service =
|
||||
getter->GetURLRequestContext()->proxy_resolution_service();
|
||||
proxy_service->ResetConfigService(
|
||||
base::WrapUnique(new net::ProxyConfigServiceFixed(config)));
|
||||
// Refetches and applies the new pac script if provided.
|
||||
proxy_service->ForceReloadProxyConfig();
|
||||
RunCallbackInUI(callback);
|
||||
}
|
||||
|
||||
void SetCertVerifyProcInIO(
|
||||
const scoped_refptr<net::URLRequestContextGetter>& context_getter,
|
||||
const AtomCertVerifier::VerifyProc& proc) {
|
||||
@@ -442,7 +352,7 @@ void DownloadIdCallback(content::DownloadManager* download_manager,
|
||||
}
|
||||
|
||||
void SetDevToolsNetworkEmulationClientIdInIO(
|
||||
brightray::URLRequestContextGetter* url_request_context_getter,
|
||||
net::URLRequestContextGetter* url_request_context_getter,
|
||||
const std::string& client_id) {
|
||||
if (!url_request_context_getter)
|
||||
return;
|
||||
@@ -453,15 +363,6 @@ void SetDevToolsNetworkEmulationClientIdInIO(
|
||||
network_delegate->SetDevToolsNetworkEmulationClientId(client_id);
|
||||
}
|
||||
|
||||
// Clear protocol handlers in IO thread.
|
||||
void ClearJobFactoryInIO(
|
||||
scoped_refptr<brightray::URLRequestContextGetter> request_context_getter) {
|
||||
auto* job_factory = static_cast<AtomURLRequestJobFactory*>(
|
||||
request_context_getter->job_factory());
|
||||
if (job_factory)
|
||||
job_factory->Clear();
|
||||
}
|
||||
|
||||
void DestroyGlobalHandle(v8::Isolate* isolate,
|
||||
const v8::Global<v8::Value>& global_handle) {
|
||||
v8::Locker locker(isolate);
|
||||
@@ -495,15 +396,12 @@ Session::Session(v8::Isolate* isolate, AtomBrowserContext* browser_context)
|
||||
}
|
||||
|
||||
Session::~Session() {
|
||||
auto* getter = browser_context_->GetRequestContext();
|
||||
content::BrowserThread::PostTask(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(ClearJobFactoryInIO, base::RetainedRef(getter)));
|
||||
content::BrowserContext::GetDownloadManager(browser_context())
|
||||
->RemoveObserver(this);
|
||||
DestroyGlobalHandle(isolate(), cookies_);
|
||||
DestroyGlobalHandle(isolate(), web_request_);
|
||||
DestroyGlobalHandle(isolate(), protocol_);
|
||||
DestroyGlobalHandle(isolate(), net_log_);
|
||||
g_sessions.erase(weak_map_id());
|
||||
}
|
||||
|
||||
@@ -526,8 +424,10 @@ void Session::OnDownloadCreated(content::DownloadManager* manager,
|
||||
}
|
||||
}
|
||||
|
||||
void Session::ResolveProxy(const GURL& url, ResolveProxyCallback callback) {
|
||||
new ResolveProxyHelper(browser_context(), url, callback);
|
||||
void Session::ResolveProxy(
|
||||
const GURL& url,
|
||||
const ResolveProxyHelper::ResolveProxyCallback& callback) {
|
||||
browser_context_->GetResolveProxyHelper()->ResolveProxy(url, callback);
|
||||
}
|
||||
|
||||
template <Session::CacheAction action>
|
||||
@@ -565,13 +465,34 @@ void Session::FlushStorageData() {
|
||||
storage_partition->Flush();
|
||||
}
|
||||
|
||||
void Session::SetProxy(const net::ProxyConfig& config,
|
||||
void Session::SetProxy(const mate::Dictionary& options,
|
||||
const base::Closure& callback) {
|
||||
auto* getter = browser_context_->GetRequestContext();
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(&SetProxyInIO, base::RetainedRef(getter), config,
|
||||
callback));
|
||||
if (!browser_context_->in_memory_pref_store()) {
|
||||
callback.Run();
|
||||
return;
|
||||
}
|
||||
|
||||
std::string proxy_rules, bypass_list, pac_url;
|
||||
|
||||
options.Get("pacScript", &pac_url);
|
||||
options.Get("proxyRules", &proxy_rules);
|
||||
options.Get("proxyBypassRules", &bypass_list);
|
||||
|
||||
// pacScript takes precedence over proxyRules.
|
||||
if (!pac_url.empty()) {
|
||||
browser_context_->in_memory_pref_store()->SetValue(
|
||||
proxy_config::prefs::kProxy,
|
||||
ProxyConfigDictionary::CreatePacScript(pac_url,
|
||||
true /* pac_mandatory */),
|
||||
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
||||
} else {
|
||||
browser_context_->in_memory_pref_store()->SetValue(
|
||||
proxy_config::prefs::kProxy,
|
||||
ProxyConfigDictionary::CreateFixedServers(proxy_rules, bypass_list),
|
||||
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
||||
}
|
||||
|
||||
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
|
||||
}
|
||||
|
||||
void Session::SetDownloadPath(const base::FilePath& path) {
|
||||
@@ -597,10 +518,9 @@ void Session::EnableNetworkEmulation(const mate::Dictionary& options) {
|
||||
devtools_network_emulation_client_id_, std::move(conditions));
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(
|
||||
&SetDevToolsNetworkEmulationClientIdInIO,
|
||||
base::RetainedRef(browser_context_->url_request_context_getter()),
|
||||
devtools_network_emulation_client_id_));
|
||||
base::BindOnce(&SetDevToolsNetworkEmulationClientIdInIO,
|
||||
base::RetainedRef(browser_context_->GetRequestContext()),
|
||||
devtools_network_emulation_client_id_));
|
||||
}
|
||||
|
||||
void Session::DisableNetworkEmulation() {
|
||||
@@ -609,10 +529,9 @@ void Session::DisableNetworkEmulation() {
|
||||
devtools_network_emulation_client_id_, std::move(conditions));
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(
|
||||
&SetDevToolsNetworkEmulationClientIdInIO,
|
||||
base::RetainedRef(browser_context_->url_request_context_getter()),
|
||||
std::string()));
|
||||
base::BindOnce(&SetDevToolsNetworkEmulationClientIdInIO,
|
||||
base::RetainedRef(browser_context_->GetRequestContext()),
|
||||
std::string()));
|
||||
}
|
||||
|
||||
void Session::SetCertVerifyProc(v8::Local<v8::Value> val,
|
||||
@@ -684,7 +603,7 @@ void Session::SetUserAgent(const std::string& user_agent,
|
||||
std::string accept_lang = g_browser_process->GetApplicationLocale();
|
||||
args->GetNext(&accept_lang);
|
||||
|
||||
scoped_refptr<brightray::URLRequestContextGetter> getter(
|
||||
scoped_refptr<net::URLRequestContextGetter> getter(
|
||||
browser_context_->GetRequestContext());
|
||||
getter->GetNetworkTaskRunner()->PostTask(
|
||||
FROM_HERE,
|
||||
@@ -775,6 +694,14 @@ v8::Local<v8::Value> Session::WebRequest(v8::Isolate* isolate) {
|
||||
return v8::Local<v8::Value>::New(isolate, web_request_);
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> Session::NetLog(v8::Isolate* isolate) {
|
||||
if (net_log_.IsEmpty()) {
|
||||
auto handle = atom::api::NetLog::Create(isolate, browser_context());
|
||||
net_log_.Reset(isolate, handle.ToV8());
|
||||
}
|
||||
return v8::Local<v8::Value>::New(isolate, net_log_);
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<Session> Session::CreateFrom(v8::Isolate* isolate,
|
||||
AtomBrowserContext* browser_context) {
|
||||
@@ -841,6 +768,7 @@ void Session::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("setPreloads", &Session::SetPreloads)
|
||||
.SetMethod("getPreloads", &Session::GetPreloads)
|
||||
.SetProperty("cookies", &Session::Cookies)
|
||||
.SetProperty("netLog", &Session::NetLog)
|
||||
.SetProperty("protocol", &Session::Protocol)
|
||||
.SetProperty("webRequest", &Session::WebRequest);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "atom/browser/api/trackable_object.h"
|
||||
#include "atom/browser/atom_blob_reader.h"
|
||||
#include "atom/browser/net/resolve_proxy_helper.h"
|
||||
#include "base/values.h"
|
||||
#include "content/public/browser/download_manager.h"
|
||||
#include "native_mate/handle.h"
|
||||
@@ -39,8 +40,6 @@ namespace api {
|
||||
class Session : public mate::TrackableObject<Session>,
|
||||
public content::DownloadManager::Observer {
|
||||
public:
|
||||
using ResolveProxyCallback = base::Callback<void(std::string)>;
|
||||
|
||||
enum class CacheAction {
|
||||
CLEAR,
|
||||
STATS,
|
||||
@@ -63,12 +62,13 @@ class Session : public mate::TrackableObject<Session>,
|
||||
v8::Local<v8::FunctionTemplate> prototype);
|
||||
|
||||
// Methods.
|
||||
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
|
||||
void ResolveProxy(const GURL& url,
|
||||
const ResolveProxyHelper::ResolveProxyCallback& callback);
|
||||
template <CacheAction action>
|
||||
void DoCacheAction(const net::CompletionCallback& callback);
|
||||
void ClearStorageData(mate::Arguments* args);
|
||||
void FlushStorageData();
|
||||
void SetProxy(const net::ProxyConfig& config, const base::Closure& callback);
|
||||
void SetProxy(const mate::Dictionary& options, const base::Closure& callback);
|
||||
void SetDownloadPath(const base::FilePath& path);
|
||||
void EnableNetworkEmulation(const mate::Dictionary& options);
|
||||
void DisableNetworkEmulation();
|
||||
@@ -88,6 +88,7 @@ class Session : public mate::TrackableObject<Session>,
|
||||
v8::Local<v8::Value> Cookies(v8::Isolate* isolate);
|
||||
v8::Local<v8::Value> Protocol(v8::Isolate* isolate);
|
||||
v8::Local<v8::Value> WebRequest(v8::Isolate* isolate);
|
||||
v8::Local<v8::Value> NetLog(v8::Isolate* isolate);
|
||||
|
||||
protected:
|
||||
Session(v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||
@@ -102,6 +103,7 @@ class Session : public mate::TrackableObject<Session>,
|
||||
v8::Global<v8::Value> cookies_;
|
||||
v8::Global<v8::Value> protocol_;
|
||||
v8::Global<v8::Value> web_request_;
|
||||
v8::Global<v8::Value> net_log_;
|
||||
|
||||
// The X-DevTools-Emulate-Network-Conditions-Client-Id.
|
||||
std::string devtools_network_emulation_client_id_;
|
||||
|
||||
@@ -142,6 +142,11 @@ void TopLevelWindow::WillCloseWindow(bool* prevent_default) {
|
||||
}
|
||||
|
||||
void TopLevelWindow::OnWindowClosed() {
|
||||
// Invalidate weak ptrs before the Javascript object is destroyed,
|
||||
// there might be some delayed emit events which shouldn't be
|
||||
// triggered after this.
|
||||
weak_factory_.InvalidateWeakPtrs();
|
||||
|
||||
RemoveFromWeakMap();
|
||||
window_->RemoveObserver(this);
|
||||
|
||||
@@ -163,11 +168,11 @@ void TopLevelWindow::OnWindowEndSession() {
|
||||
}
|
||||
|
||||
void TopLevelWindow::OnWindowBlur() {
|
||||
Emit("blur");
|
||||
EmitEventSoon("blur");
|
||||
}
|
||||
|
||||
void TopLevelWindow::OnWindowFocus() {
|
||||
Emit("focus");
|
||||
EmitEventSoon("focus");
|
||||
}
|
||||
|
||||
void TopLevelWindow::OnWindowShow() {
|
||||
@@ -371,8 +376,10 @@ gfx::Rect TopLevelWindow::GetContentBounds() {
|
||||
|
||||
void TopLevelWindow::SetSize(int width, int height, mate::Arguments* args) {
|
||||
bool animate = false;
|
||||
gfx::Size size = window_->GetMinimumSize();
|
||||
size.SetToMax(gfx::Size(width, height));
|
||||
args->GetNext(&animate);
|
||||
window_->SetSize(gfx::Size(width, height), animate);
|
||||
window_->SetSize(size, animate);
|
||||
}
|
||||
|
||||
std::vector<int> TopLevelWindow::GetSize() {
|
||||
@@ -571,6 +578,10 @@ double TopLevelWindow::GetOpacity() {
|
||||
return window_->GetOpacity();
|
||||
}
|
||||
|
||||
void TopLevelWindow::SetShape(const std::vector<gfx::Rect>& rects) {
|
||||
window_->widget()->SetShape(std::make_unique<std::vector<gfx::Rect>>(rects));
|
||||
}
|
||||
|
||||
void TopLevelWindow::SetRepresentedFilename(const std::string& filename) {
|
||||
window_->SetRepresentedFilename(filename);
|
||||
}
|
||||
@@ -653,8 +664,11 @@ void TopLevelWindow::SetBrowserView(v8::Local<v8::Value> value) {
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> TopLevelWindow::GetNativeWindowHandle() {
|
||||
gfx::AcceleratedWidget handle = window_->GetAcceleratedWidget();
|
||||
return ToBuffer(isolate(), static_cast<void*>(&handle), sizeof(handle));
|
||||
// TODO(MarshallOfSound): Replace once
|
||||
// https://chromium-review.googlesource.com/c/chromium/src/+/1253094/ has
|
||||
// landed
|
||||
auto handle = window_->GetNativeWindowHandlePointer();
|
||||
return ToBuffer(isolate(), std::get<0>(handle), std::get<1>(handle));
|
||||
}
|
||||
|
||||
void TopLevelWindow::SetProgressBar(double progress, mate::Arguments* args) {
|
||||
@@ -993,6 +1007,7 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("hasShadow", &TopLevelWindow::HasShadow)
|
||||
.SetMethod("setOpacity", &TopLevelWindow::SetOpacity)
|
||||
.SetMethod("getOpacity", &TopLevelWindow::GetOpacity)
|
||||
.SetMethod("setShape", &TopLevelWindow::SetShape)
|
||||
.SetMethod("setRepresentedFilename",
|
||||
&TopLevelWindow::SetRepresentedFilename)
|
||||
.SetMethod("getRepresentedFilename",
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/native_window_observer.h"
|
||||
#include "atom/common/api/atom_api_native_image.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "native_mate/handle.h"
|
||||
|
||||
namespace atom {
|
||||
@@ -146,6 +147,7 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
|
||||
bool HasShadow();
|
||||
void SetOpacity(const double opacity);
|
||||
double GetOpacity();
|
||||
void SetShape(const std::vector<gfx::Rect>& rects);
|
||||
void SetRepresentedFilename(const std::string& filename);
|
||||
std::string GetRepresentedFilename();
|
||||
void SetDocumentEdited(bool edited);
|
||||
@@ -214,6 +216,14 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
|
||||
// Remove this window from parent window's |child_windows_|.
|
||||
void RemoveFromParentChildWindows();
|
||||
|
||||
template<typename... Args>
|
||||
void EmitEventSoon(base::StringPiece eventName) {
|
||||
content::BrowserThread::PostTask(
|
||||
content::BrowserThread::UI, FROM_HERE,
|
||||
base::BindOnce(base::IgnoreResult(&TopLevelWindow::Emit<Args...>),
|
||||
weak_factory_.GetWeakPtr(), eventName));
|
||||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
typedef std::map<UINT, MessageCallback> MessageCallbackMap;
|
||||
MessageCallbackMap messages_callback_map_;
|
||||
|
||||
@@ -210,7 +210,7 @@ void Tray::PopUpContextMenu(mate::Arguments* args) {
|
||||
|
||||
void Tray::SetContextMenu(v8::Isolate* isolate, mate::Handle<Menu> menu) {
|
||||
menu_.Reset(isolate, menu.ToV8());
|
||||
tray_icon_->SetContextMenu(menu->model());
|
||||
tray_icon_->SetContextMenu(menu.IsEmpty() ? nullptr : menu->model());
|
||||
}
|
||||
|
||||
gfx::Rect Tray::GetBounds() {
|
||||
|
||||
@@ -125,6 +125,18 @@ bool URLRequest::ResponseState::Failed() const {
|
||||
return IsFlagSet(ResponseStateFlags::kFailed);
|
||||
}
|
||||
|
||||
mate::Dictionary URLRequest::GetUploadProgress(v8::Isolate* isolate) {
|
||||
mate::Dictionary progress = mate::Dictionary::CreateEmpty(isolate);
|
||||
|
||||
if (atom_request_) {
|
||||
progress.Set("active", true);
|
||||
atom_request_->GetUploadProgress(&progress);
|
||||
} else {
|
||||
progress.Set("active", false);
|
||||
}
|
||||
return progress;
|
||||
}
|
||||
|
||||
URLRequest::URLRequest(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) {
|
||||
InitWith(isolate, wrapper);
|
||||
}
|
||||
@@ -183,6 +195,7 @@ void URLRequest::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("setChunkedUpload", &URLRequest::SetChunkedUpload)
|
||||
.SetMethod("followRedirect", &URLRequest::FollowRedirect)
|
||||
.SetMethod("_setLoadFlags", &URLRequest::SetLoadFlags)
|
||||
.SetMethod("getUploadProgress", &URLRequest::GetUploadProgress)
|
||||
.SetProperty("notStarted", &URLRequest::NotStarted)
|
||||
.SetProperty("finished", &URLRequest::Finished)
|
||||
// Response APi
|
||||
|
||||
@@ -112,6 +112,7 @@ class URLRequest : public mate::EventEmitter<URLRequest> {
|
||||
void OnResponseData(scoped_refptr<const net::IOBufferWithSize> data);
|
||||
void OnResponseCompleted();
|
||||
void OnError(const std::string& error, bool isRequestError);
|
||||
mate::Dictionary GetUploadProgress(v8::Isolate* isolate);
|
||||
|
||||
protected:
|
||||
explicit URLRequest(v8::Isolate* isolate, v8::Local<v8::Object> wrapper);
|
||||
|
||||
@@ -56,7 +56,6 @@
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/process/process_handle.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "base/values.h"
|
||||
@@ -120,28 +119,6 @@ struct PrintSettings {
|
||||
|
||||
namespace mate {
|
||||
|
||||
template <>
|
||||
struct Converter<atom::SetSizeParams> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
atom::SetSizeParams* out) {
|
||||
mate::Dictionary params;
|
||||
if (!ConvertFromV8(isolate, val, ¶ms))
|
||||
return false;
|
||||
bool autosize;
|
||||
if (params.Get("enableAutoSize", &autosize))
|
||||
out->enable_auto_size.reset(new bool(autosize));
|
||||
gfx::Size size;
|
||||
if (params.Get("min", &size))
|
||||
out->min_size.reset(new gfx::Size(size));
|
||||
if (params.Get("max", &size))
|
||||
out->max_size.reset(new gfx::Size(size));
|
||||
if (params.Get("normal", &size))
|
||||
out->normal_size.reset(new gfx::Size(size));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<PrintSettings> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
@@ -396,7 +373,8 @@ WebContents::WebContents(v8::Isolate* isolate,
|
||||
GURL("chrome-guest://fake-host"));
|
||||
content::WebContents::CreateParams params(session->browser_context(),
|
||||
site_instance);
|
||||
guest_delegate_.reset(new WebViewGuestDelegate);
|
||||
guest_delegate_.reset(
|
||||
new WebViewGuestDelegate(embedder_->web_contents(), this));
|
||||
params.guest_delegate = guest_delegate_.get();
|
||||
|
||||
#if defined(ENABLE_OSR)
|
||||
@@ -448,7 +426,7 @@ void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate,
|
||||
mate::Handle<api::Session> session,
|
||||
const mate::Dictionary& options) {
|
||||
Observe(web_contents);
|
||||
InitWithWebContents(web_contents, session->browser_context());
|
||||
InitWithWebContents(web_contents, session->browser_context(), IsGuest());
|
||||
|
||||
managed_web_contents()->GetView()->SetDelegate(this);
|
||||
|
||||
@@ -481,8 +459,6 @@ void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate,
|
||||
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
|
||||
|
||||
if (IsGuest()) {
|
||||
guest_delegate_->Initialize(this);
|
||||
|
||||
NativeWindow* owner_window = nullptr;
|
||||
if (embedder_) {
|
||||
// New WebContents's owner_window is the embedder's owner_window.
|
||||
@@ -504,11 +480,6 @@ WebContents::~WebContents() {
|
||||
if (managed_web_contents()) {
|
||||
managed_web_contents()->GetView()->SetDelegate(nullptr);
|
||||
|
||||
// For webview we need to tell content module to do some cleanup work before
|
||||
// destroying it.
|
||||
if (type_ == WEB_VIEW)
|
||||
guest_delegate_->Destroy();
|
||||
|
||||
RenderViewDeleted(web_contents()->GetRenderViewHost());
|
||||
|
||||
if (type_ == WEB_VIEW) {
|
||||
@@ -784,13 +755,6 @@ content::JavaScriptDialogManager* WebContents::GetJavaScriptDialogManager(
|
||||
return dialog_manager_.get();
|
||||
}
|
||||
|
||||
void WebContents::ResizeDueToAutoResize(content::WebContents* web_contents,
|
||||
const gfx::Size& new_size) {
|
||||
if (IsGuest()) {
|
||||
guest_delegate_->ResizeDueToAutoResize(new_size);
|
||||
}
|
||||
}
|
||||
|
||||
void WebContents::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
|
||||
// Do nothing, we override this method just to avoid compilation error since
|
||||
// there are two virtual functions named BeforeUnloadFired.
|
||||
@@ -842,8 +806,10 @@ void WebContents::DidChangeThemeColor(SkColor theme_color) {
|
||||
|
||||
void WebContents::DocumentLoadedInFrame(
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
if (!render_frame_host->GetParent())
|
||||
if (!render_frame_host->GetParent()) {
|
||||
is_dom_ready_ = true;
|
||||
Emit("dom-ready");
|
||||
}
|
||||
}
|
||||
|
||||
void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
||||
@@ -870,6 +836,7 @@ void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host,
|
||||
}
|
||||
|
||||
void WebContents::DidStartLoading() {
|
||||
is_dom_ready_ = false;
|
||||
Emit("did-start-loading");
|
||||
}
|
||||
|
||||
@@ -935,6 +902,8 @@ void WebContents::DidFinishNavigation(
|
||||
Emit("did-navigate", url, http_response_code, http_status_text);
|
||||
}
|
||||
}
|
||||
if (IsGuest())
|
||||
Emit("load-commit", url, is_main_frame);
|
||||
} else {
|
||||
auto url = navigation_handle->GetURL();
|
||||
int code = navigation_handle->GetNetErrorCode();
|
||||
@@ -1075,7 +1044,8 @@ bool WebContents::OnMessageReceived(const IPC::Message& message,
|
||||
// 1. call webContents.destroy();
|
||||
// 2. garbage collection;
|
||||
// 3. user closes the window of webContents;
|
||||
// For webview only #1 will happen, for BrowserWindow both #1 and #3 may
|
||||
// 4. the embedder detaches the frame.
|
||||
// For webview both #1 and #4 may happen, for BrowserWindow both #1 and #3 may
|
||||
// happen. The #2 should never happen for webContents, because webview is
|
||||
// managed by GuestViewManager, and BrowserWindow's webContents is managed
|
||||
// by api::BrowserWindow.
|
||||
@@ -1083,6 +1053,7 @@ bool WebContents::OnMessageReceived(const IPC::Message& message,
|
||||
// sure "destroyed" event is emitted. For #3, the content::WebContents will
|
||||
// be destroyed on close, and WebContentsDestroyed would be called for it, so
|
||||
// we need to make sure the api::WebContents is also deleted.
|
||||
// For #4, the WebContents will be destroyed by embedder.
|
||||
void WebContents::WebContentsDestroyed() {
|
||||
// Cleanup relationships with other parts.
|
||||
RemoveFromWeakMap();
|
||||
@@ -1093,6 +1064,13 @@ void WebContents::WebContentsDestroyed() {
|
||||
|
||||
Emit("destroyed");
|
||||
|
||||
// For guest view based on OOPIF, the WebContents is released by the embedder
|
||||
// frame, and we need to clear the reference to the memory.
|
||||
if (IsGuest() && managed_web_contents()) {
|
||||
managed_web_contents()->ReleaseWebContents();
|
||||
ResetManagedWebContents(false);
|
||||
}
|
||||
|
||||
// Destroy the native class in next tick.
|
||||
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, GetDestroyClosure());
|
||||
}
|
||||
@@ -1140,10 +1118,6 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (guest_delegate_ && !guest_delegate_->IsAttached()) {
|
||||
return;
|
||||
}
|
||||
|
||||
content::NavigationController::LoadURLParams params(url);
|
||||
|
||||
if (!options.Get("httpReferrer", ¶ms.referrer)) {
|
||||
@@ -1423,7 +1397,9 @@ void WebContents::UnregisterServiceWorker(
|
||||
}
|
||||
|
||||
void WebContents::SetIgnoreMenuShortcuts(bool ignore) {
|
||||
set_ignore_menu_shortcuts(ignore);
|
||||
auto* web_preferences = WebContentsPreferences::From(web_contents());
|
||||
DCHECK(web_preferences);
|
||||
web_preferences->dict()->SetBoolean("ignoreMenuShortcuts", ignore);
|
||||
}
|
||||
|
||||
void WebContents::SetAudioMuted(bool muted) {
|
||||
@@ -1434,6 +1410,10 @@ bool WebContents::IsAudioMuted() {
|
||||
return web_contents()->IsAudioMuted();
|
||||
}
|
||||
|
||||
bool WebContents::IsDOMReady() const {
|
||||
return is_dom_ready_;
|
||||
}
|
||||
|
||||
void WebContents::Print(mate::Arguments* args) {
|
||||
PrintSettings settings = {false, false, base::string16()};
|
||||
if (args->Length() >= 1 && !args->GetNext(&settings)) {
|
||||
@@ -1754,15 +1734,16 @@ void WebContents::OnCursorChange(const content::WebCursor& cursor) {
|
||||
}
|
||||
}
|
||||
|
||||
void WebContents::SetSize(const SetSizeParams& params) {
|
||||
if (guest_delegate_)
|
||||
guest_delegate_->SetSize(params);
|
||||
}
|
||||
|
||||
bool WebContents::IsGuest() const {
|
||||
return type_ == WEB_VIEW;
|
||||
}
|
||||
|
||||
void WebContents::AttachToIframe(content::WebContents* embedder_web_contents,
|
||||
int embedder_frame_id) {
|
||||
if (guest_delegate_)
|
||||
guest_delegate_->AttachToIframe(embedder_web_contents, embedder_frame_id);
|
||||
}
|
||||
|
||||
bool WebContents::IsOffScreen() const {
|
||||
#if defined(ENABLE_OSR)
|
||||
return type_ == OFF_SCREEN;
|
||||
@@ -1891,6 +1872,16 @@ void WebContents::OnGetZoomLevel(content::RenderFrameHost* rfh,
|
||||
rfh->Send(reply_msg);
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> WebContents::GetPreloadPath(v8::Isolate* isolate) const {
|
||||
if (auto* web_preferences = WebContentsPreferences::From(web_contents())) {
|
||||
base::FilePath::StringType preload;
|
||||
if (web_preferences->GetPreloadPath(&preload)) {
|
||||
return mate::ConvertToV8(isolate, preload);
|
||||
}
|
||||
}
|
||||
return v8::Null(isolate);
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
|
||||
auto* web_preferences = WebContentsPreferences::From(web_contents());
|
||||
if (!web_preferences)
|
||||
@@ -2018,6 +2009,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("setIgnoreMenuShortcuts", &WebContents::SetIgnoreMenuShortcuts)
|
||||
.SetMethod("setAudioMuted", &WebContents::SetAudioMuted)
|
||||
.SetMethod("isAudioMuted", &WebContents::IsAudioMuted)
|
||||
.SetMethod("isDomReady", &WebContents::IsDOMReady)
|
||||
.SetMethod("undo", &WebContents::Undo)
|
||||
.SetMethod("redo", &WebContents::Redo)
|
||||
.SetMethod("cut", &WebContents::Cut)
|
||||
@@ -2039,8 +2031,8 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("beginFrameSubscription", &WebContents::BeginFrameSubscription)
|
||||
.SetMethod("endFrameSubscription", &WebContents::EndFrameSubscription)
|
||||
.SetMethod("startDrag", &WebContents::StartDrag)
|
||||
.SetMethod("setSize", &WebContents::SetSize)
|
||||
.SetMethod("isGuest", &WebContents::IsGuest)
|
||||
.SetMethod("attachToIframe", &WebContents::AttachToIframe)
|
||||
.SetMethod("isOffscreen", &WebContents::IsOffScreen)
|
||||
.SetMethod("startPainting", &WebContents::StartPainting)
|
||||
.SetMethod("stopPainting", &WebContents::StopPainting)
|
||||
@@ -2053,6 +2045,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||
.SetMethod("setZoomFactor", &WebContents::SetZoomFactor)
|
||||
.SetMethod("_getZoomFactor", &WebContents::GetZoomFactor)
|
||||
.SetMethod("getType", &WebContents::GetType)
|
||||
.SetMethod("_getPreloadPath", &WebContents::GetPreloadPath)
|
||||
.SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
|
||||
.SetMethod("getLastWebPreferences", &WebContents::GetLastWebPreferences)
|
||||
.SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow)
|
||||
|
||||
@@ -42,7 +42,6 @@ class ResourceRequestBody;
|
||||
|
||||
namespace atom {
|
||||
|
||||
struct SetSizeParams;
|
||||
class AtomBrowserContext;
|
||||
class AtomJavaScriptDialogManager;
|
||||
class WebContentsZoomController;
|
||||
@@ -143,6 +142,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
void SetIgnoreMenuShortcuts(bool ignore);
|
||||
void SetAudioMuted(bool muted);
|
||||
bool IsAudioMuted();
|
||||
bool IsDOMReady() const;
|
||||
void Print(mate::Arguments* args);
|
||||
std::vector<printing::PrinterBasicInfo> GetPrinterList();
|
||||
void SetEmbedder(const WebContents* embedder);
|
||||
@@ -199,8 +199,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
void CapturePage(mate::Arguments* args);
|
||||
|
||||
// Methods for creating <webview>.
|
||||
void SetSize(const SetSizeParams& params);
|
||||
bool IsGuest() const;
|
||||
void AttachToIframe(content::WebContents* embedder_web_contents,
|
||||
int embedder_frame_id);
|
||||
|
||||
// Methods for offscreen rendering
|
||||
bool IsOffScreen() const;
|
||||
@@ -232,6 +233,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
const std::vector<std::string>& features,
|
||||
const scoped_refptr<network::ResourceRequestBody>& body);
|
||||
|
||||
// Returns the preload script path of current WebContents.
|
||||
v8::Local<v8::Value> GetPreloadPath(v8::Isolate* isolate) const;
|
||||
|
||||
// Returns the web preferences of current WebContents.
|
||||
v8::Local<v8::Value> GetWebPreferences(v8::Isolate* isolate);
|
||||
v8::Local<v8::Value> GetLastWebPreferences(v8::Isolate* isolate);
|
||||
@@ -339,8 +343,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
const content::BluetoothChooser::EventHandler& handler) override;
|
||||
content::JavaScriptDialogManager* GetJavaScriptDialogManager(
|
||||
content::WebContents* source) override;
|
||||
void ResizeDueToAutoResize(content::WebContents* web_contents,
|
||||
const gfx::Size& new_size) override;
|
||||
|
||||
// content::WebContentsObserver:
|
||||
void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
|
||||
@@ -461,6 +463,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
// Whether to enable devtools.
|
||||
bool enable_devtools_ = true;
|
||||
|
||||
// Whether page's document is ready.
|
||||
bool is_dom_ready_ = false;
|
||||
|
||||
// Observers of this WebContents.
|
||||
base::ObserverList<ExtendedWebContentsObserver> observers_;
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace {
|
||||
|
||||
template <typename Method, typename Event, typename Listener>
|
||||
void CallNetworkDelegateMethod(
|
||||
brightray::URLRequestContextGetter* url_request_context_getter,
|
||||
URLRequestContextGetter* url_request_context_getter,
|
||||
Method method,
|
||||
Event type,
|
||||
URLPatterns patterns,
|
||||
@@ -94,8 +94,8 @@ void WebRequest::SetListener(Method method, Event type, mate::Arguments* args) {
|
||||
return;
|
||||
}
|
||||
|
||||
brightray::URLRequestContextGetter* url_request_context_getter =
|
||||
browser_context_->url_request_context_getter();
|
||||
auto* url_request_context_getter = static_cast<URLRequestContextGetter*>(
|
||||
browser_context_->GetRequestContext());
|
||||
if (!url_request_context_getter)
|
||||
return;
|
||||
BrowserThread::PostTask(
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "content/public/browser/browser_context.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
|
||||
// Must be the last in the includes list.
|
||||
// See https://github.com/electron/electron/issues/10363
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "atom/browser/atom_resource_dispatcher_host_delegate.h"
|
||||
#include "atom/browser/atom_speech_recognition_manager_delegate.h"
|
||||
#include "atom/browser/child_web_contents_tracker.h"
|
||||
#include "atom/browser/login_handler.h"
|
||||
#include "atom/browser/io_thread.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/session_preferences.h"
|
||||
#include "atom/browser/web_contents_permission_helper.h"
|
||||
@@ -28,12 +28,16 @@
|
||||
#include "base/command_line.h"
|
||||
#include "base/environment.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/json/json_reader.h"
|
||||
#include "base/no_destructor.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "chrome/browser/printing/printing_message_filter.h"
|
||||
#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
|
||||
#include "chrome/browser/speech/tts_message_filter.h"
|
||||
#include "components/net_log/chrome_net_log.h"
|
||||
#include "content/public/browser/browser_ppapi_host.h"
|
||||
#include "content/public/browser/client_certificate_delegate.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
@@ -44,11 +48,15 @@
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/common/content_paths.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "content/public/common/service_names.mojom.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
#include "content/public/common/web_preferences.h"
|
||||
#include "device/geolocation/public/cpp/location_provider.h"
|
||||
#include "net/base/escape.h"
|
||||
#include "net/ssl/ssl_cert_request_info.h"
|
||||
#include "ppapi/host/ppapi_host.h"
|
||||
#include "services/network/public/cpp/resource_request_body.h"
|
||||
#include "services/proxy_resolver/public/mojom/proxy_resolver.mojom.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
@@ -62,6 +70,10 @@
|
||||
#include "net/ssl/client_cert_store.h"
|
||||
#endif
|
||||
|
||||
#if defined(OVERRIDE_LOCATION_PROVIDER)
|
||||
#include "atom/browser/fake_location_provider.h"
|
||||
#endif // defined(OVERRIDE_LOCATION_PROVIDER)
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
namespace atom {
|
||||
@@ -341,10 +353,6 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||
web_preferences->AppendCommandLineSwitches(command_line);
|
||||
SessionPreferences::AppendExtraCommandLineSwitches(
|
||||
web_contents->GetBrowserContext(), command_line);
|
||||
|
||||
auto context_id = atom::api::WebContents::GetIDForContents(web_contents);
|
||||
command_line->AppendSwitchASCII(switches::kContextId,
|
||||
base::IntToString(context_id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -495,23 +503,37 @@ std::unique_ptr<net::ClientCertStore> AtomBrowserClient::CreateClientCertStore(
|
||||
#endif
|
||||
}
|
||||
|
||||
content::ResourceDispatcherHostLoginDelegate*
|
||||
AtomBrowserClient::CreateLoginDelegate(
|
||||
net::AuthChallengeInfo* auth_info,
|
||||
content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
|
||||
bool is_main_frame,
|
||||
const GURL& url,
|
||||
bool first_auth_attempt,
|
||||
const base::Callback<void(const base::Optional<net::AuthCredentials>&)>&
|
||||
auth_required_callback) {
|
||||
return new LoginHandler(auth_info, web_contents_getter, url,
|
||||
auth_required_callback);
|
||||
std::unique_ptr<device::LocationProvider>
|
||||
AtomBrowserClient::OverrideSystemLocationProvider() {
|
||||
#if defined(OVERRIDE_LOCATION_PROVIDER)
|
||||
return std::make_unique<FakeLocationProvider>();
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
network::mojom::NetworkContextPtr AtomBrowserClient::CreateNetworkContext(
|
||||
content::BrowserContext* browser_context,
|
||||
bool /*in_memory*/,
|
||||
const base::FilePath& /*relative_partition_path*/) {
|
||||
if (!browser_context)
|
||||
return nullptr;
|
||||
return static_cast<AtomBrowserContext*>(browser_context)->GetNetworkContext();
|
||||
}
|
||||
|
||||
void AtomBrowserClient::RegisterOutOfProcessServices(
|
||||
OutOfProcessServiceMap* services) {
|
||||
(*services)[proxy_resolver::mojom::kProxyResolverServiceName] =
|
||||
base::ASCIIToUTF16("V8 Proxy Resolver");
|
||||
}
|
||||
|
||||
net::NetLog* AtomBrowserClient::GetNetLog() {
|
||||
return AtomBrowserMainParts::Get()->net_log();
|
||||
}
|
||||
|
||||
brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
|
||||
const content::MainFunctionParams&) {
|
||||
v8::V8::Initialize(); // Init V8 before creating main parts.
|
||||
return new AtomBrowserMainParts;
|
||||
const content::MainFunctionParams& params) {
|
||||
return new AtomBrowserMainParts(params);
|
||||
}
|
||||
|
||||
void AtomBrowserClient::WebNotificationAllowed(
|
||||
|
||||
@@ -106,14 +106,14 @@ class AtomBrowserClient : public brightray::BrowserClient,
|
||||
void SiteInstanceDeleting(content::SiteInstance* site_instance) override;
|
||||
std::unique_ptr<net::ClientCertStore> CreateClientCertStore(
|
||||
content::ResourceContext* resource_context) override;
|
||||
content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
|
||||
net::AuthChallengeInfo* auth_info,
|
||||
content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
|
||||
bool is_main_frame,
|
||||
const GURL& url,
|
||||
bool first_auth_attempt,
|
||||
const base::Callback<void(const base::Optional<net::AuthCredentials>&)>&
|
||||
auth_required_callback) override;
|
||||
std::unique_ptr<device::LocationProvider> OverrideSystemLocationProvider()
|
||||
override;
|
||||
network::mojom::NetworkContextPtr CreateNetworkContext(
|
||||
content::BrowserContext* browser_context,
|
||||
bool in_memory,
|
||||
const base::FilePath& relative_partition_path) override;
|
||||
void RegisterOutOfProcessServices(OutOfProcessServiceMap* services) override;
|
||||
net::NetLog* GetNetLog() override;
|
||||
|
||||
// brightray::BrowserClient:
|
||||
brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
|
||||
|
||||
@@ -4,44 +4,46 @@
|
||||
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
|
||||
#include "atom/browser/api/atom_api_protocol.h"
|
||||
#include <utility>
|
||||
|
||||
#include "atom/browser/atom_blob_reader.h"
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/browser/atom_download_manager_delegate.h"
|
||||
#include "atom/browser/atom_permission_manager.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/net/about_protocol_handler.h"
|
||||
#include "atom/browser/net/asar/asar_protocol_handler.h"
|
||||
#include "atom/browser/net/atom_cert_verifier.h"
|
||||
#include "atom/browser/net/atom_network_delegate.h"
|
||||
#include "atom/browser/net/atom_url_request_job_factory.h"
|
||||
#include "atom/browser/net/cookie_details.h"
|
||||
#include "atom/browser/net/http_protocol_handler.h"
|
||||
#include "atom/browser/cookie_change_notifier.h"
|
||||
#include "atom/browser/net/resolve_proxy_helper.h"
|
||||
#include "atom/browser/pref_store_delegate.h"
|
||||
#include "atom/browser/web_view_manager.h"
|
||||
#include "atom/common/atom_version.h"
|
||||
#include "atom/common/chrome_version.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/task_scheduler/post_task.h"
|
||||
#include "base/threading/sequenced_task_runner_handle.h"
|
||||
#include "base/threading/thread_restrictions.h"
|
||||
#include "brightray/browser/brightray_paths.h"
|
||||
#include "brightray/browser/inspectable_web_contents_impl.h"
|
||||
#include "brightray/browser/special_storage_policy.h"
|
||||
#include "brightray/browser/zoom_level_delegate.h"
|
||||
#include "brightray/common/application_info.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/prefs/json_pref_store.h"
|
||||
#include "components/prefs/pref_registry_simple.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "components/prefs/pref_service_factory.h"
|
||||
#include "components/prefs/value_map_pref_store.h"
|
||||
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
|
||||
#include "components/proxy_config/proxy_config_pref_names.h"
|
||||
#include "content/browser/blob_storage/chrome_blob_storage_context.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
#include "content/public/common/user_agent.h"
|
||||
#include "net/ftp/ftp_network_layer.h"
|
||||
#include "net/url_request/data_protocol_handler.h"
|
||||
#include "net/url_request/ftp_protocol_handler.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
#include "net/url_request/url_request_intercepting_job_factory.h"
|
||||
#include "url/url_constants.h"
|
||||
#include "net/base/escape.h"
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
@@ -49,14 +51,6 @@ namespace atom {
|
||||
|
||||
namespace {
|
||||
|
||||
class NoCacheBackend : public net::HttpCache::BackendFactory {
|
||||
int CreateBackend(net::NetLog* net_log,
|
||||
std::unique_ptr<disk_cache::Backend>* backend,
|
||||
const net::CompletionCallback& callback) override {
|
||||
return net::ERR_FAILED;
|
||||
}
|
||||
};
|
||||
|
||||
std::string RemoveWhitespace(const std::string& str) {
|
||||
std::string trimmed;
|
||||
if (base::RemoveChars(str, " ", &trimmed))
|
||||
@@ -65,12 +59,25 @@ std::string RemoveWhitespace(const std::string& str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
// Convert string to lower case and escape it.
|
||||
std::string MakePartitionName(const std::string& input) {
|
||||
return net::EscapePath(base::ToLowerASCII(input));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
AtomBrowserContext::BrowserContextMap AtomBrowserContext::browser_context_map_;
|
||||
|
||||
AtomBrowserContext::AtomBrowserContext(const std::string& partition,
|
||||
bool in_memory,
|
||||
const base::DictionaryValue& options)
|
||||
: brightray::BrowserContext(partition, in_memory) {
|
||||
: base::RefCountedDeleteOnSequence<AtomBrowserContext>(
|
||||
base::SequencedTaskRunnerHandle::Get()),
|
||||
in_memory_pref_store_(nullptr),
|
||||
storage_policy_(new brightray::SpecialStoragePolicy),
|
||||
in_memory_(in_memory),
|
||||
weak_factory_(this) {
|
||||
// Construct user agent string.
|
||||
Browser* browser = Browser::Get();
|
||||
std::string name = RemoveWhitespace(browser->GetName());
|
||||
@@ -86,85 +93,130 @@ AtomBrowserContext::AtomBrowserContext(const std::string& partition,
|
||||
user_agent_ = content::BuildUserAgentFromProduct(user_agent);
|
||||
|
||||
// Read options.
|
||||
use_cache_ = true;
|
||||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
||||
use_cache_ = !command_line->HasSwitch(switches::kDisableHttpCache);
|
||||
options.GetBoolean("cache", &use_cache_);
|
||||
|
||||
// Initialize Pref Registry in brightray.
|
||||
base::StringToInt(command_line->GetSwitchValueASCII(switches::kDiskCacheSize),
|
||||
&max_cache_size_);
|
||||
|
||||
if (!base::PathService::Get(brightray::DIR_USER_DATA, &path_)) {
|
||||
base::PathService::Get(brightray::DIR_APP_DATA, &path_);
|
||||
path_ = path_.Append(
|
||||
base::FilePath::FromUTF8Unsafe(brightray::GetApplicationName()));
|
||||
base::PathService::Override(brightray::DIR_USER_DATA, path_);
|
||||
}
|
||||
|
||||
if (!in_memory && !partition.empty())
|
||||
path_ = path_.Append(FILE_PATH_LITERAL("Partitions"))
|
||||
.Append(base::FilePath::FromUTF8Unsafe(
|
||||
MakePartitionName(partition)));
|
||||
|
||||
content::BrowserContext::Initialize(this, path_);
|
||||
|
||||
// Initialize Pref Registry.
|
||||
InitPrefs();
|
||||
|
||||
proxy_config_monitor_ = std::make_unique<ProxyConfigMonitor>(prefs_.get());
|
||||
io_handle_ = new URLRequestContextGetter::Handle(weak_factory_.GetWeakPtr());
|
||||
cookie_change_notifier_ = std::make_unique<CookieChangeNotifier>(this);
|
||||
}
|
||||
|
||||
AtomBrowserContext::~AtomBrowserContext() {}
|
||||
AtomBrowserContext::~AtomBrowserContext() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
NotifyWillBeDestroyed(this);
|
||||
ShutdownStoragePartitions();
|
||||
io_handle_->ShutdownOnUIThread();
|
||||
}
|
||||
|
||||
void AtomBrowserContext::InitPrefs() {
|
||||
auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences"));
|
||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||
PrefServiceFactory prefs_factory;
|
||||
scoped_refptr<JsonPrefStore> pref_store =
|
||||
base::MakeRefCounted<JsonPrefStore>(prefs_path);
|
||||
pref_store->ReadPrefs(); // Synchronous.
|
||||
prefs_factory.set_user_prefs(pref_store);
|
||||
|
||||
auto registry = WrapRefCounted(new PrefRegistrySimple);
|
||||
|
||||
registry->RegisterFilePathPref(prefs::kSelectFileLastDirectory,
|
||||
base::FilePath());
|
||||
base::FilePath download_dir;
|
||||
base::PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &download_dir);
|
||||
registry->RegisterFilePathPref(prefs::kDownloadDefaultDirectory,
|
||||
download_dir);
|
||||
registry->RegisterDictionaryPref(prefs::kDevToolsFileSystemPaths);
|
||||
brightray::InspectableWebContentsImpl::RegisterPrefs(registry.get());
|
||||
brightray::MediaDeviceIDSalt::RegisterPrefs(registry.get());
|
||||
brightray::ZoomLevelDelegate::RegisterPrefs(registry.get());
|
||||
PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get());
|
||||
|
||||
prefs_ = prefs_factory.Create(
|
||||
registry.get(),
|
||||
std::make_unique<PrefStoreDelegate>(weak_factory_.GetWeakPtr()));
|
||||
prefs_->UpdateCommandLinePrefStore(new ValueMapPrefStore);
|
||||
}
|
||||
|
||||
void AtomBrowserContext::SetUserAgent(const std::string& user_agent) {
|
||||
user_agent_ = user_agent;
|
||||
}
|
||||
|
||||
std::unique_ptr<base::CallbackList<void(const CookieDetails*)>::Subscription>
|
||||
AtomBrowserContext::RegisterCookieChangeCallback(
|
||||
const base::Callback<void(const CookieDetails*)>& cb) {
|
||||
return cookie_change_sub_list_.Add(cb);
|
||||
net::URLRequestContextGetter* AtomBrowserContext::CreateRequestContext(
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::URLRequestInterceptorScopedVector protocol_interceptors) {
|
||||
return io_handle_
|
||||
->CreateMainRequestContextGetter(protocol_handlers,
|
||||
std::move(protocol_interceptors))
|
||||
.get();
|
||||
}
|
||||
|
||||
std::unique_ptr<net::NetworkDelegate>
|
||||
AtomBrowserContext::CreateNetworkDelegate() {
|
||||
return std::make_unique<AtomNetworkDelegate>();
|
||||
net::URLRequestContextGetter* AtomBrowserContext::CreateMediaRequestContext() {
|
||||
return io_handle_->GetMainRequestContextGetter().get();
|
||||
}
|
||||
|
||||
std::string AtomBrowserContext::GetUserAgent() {
|
||||
return user_agent_;
|
||||
net::URLRequestContextGetter* AtomBrowserContext::GetRequestContext() {
|
||||
return GetDefaultStoragePartition(this)->GetURLRequestContext();
|
||||
}
|
||||
|
||||
std::unique_ptr<net::URLRequestJobFactory>
|
||||
AtomBrowserContext::CreateURLRequestJobFactory(
|
||||
content::ProtocolHandlerMap* protocol_handlers) {
|
||||
std::unique_ptr<AtomURLRequestJobFactory> job_factory(
|
||||
new AtomURLRequestJobFactory);
|
||||
network::mojom::NetworkContextPtr AtomBrowserContext::GetNetworkContext() {
|
||||
return io_handle_->GetNetworkContext();
|
||||
}
|
||||
|
||||
for (auto& it : *protocol_handlers) {
|
||||
job_factory->SetProtocolHandler(it.first,
|
||||
base::WrapUnique(it.second.release()));
|
||||
base::FilePath AtomBrowserContext::GetPath() const {
|
||||
return path_;
|
||||
}
|
||||
|
||||
bool AtomBrowserContext::IsOffTheRecord() const {
|
||||
return in_memory_;
|
||||
}
|
||||
|
||||
bool AtomBrowserContext::CanUseHttpCache() const {
|
||||
return use_cache_;
|
||||
}
|
||||
|
||||
int AtomBrowserContext::GetMaxCacheSize() const {
|
||||
return max_cache_size_;
|
||||
}
|
||||
|
||||
content::ResourceContext* AtomBrowserContext::GetResourceContext() {
|
||||
return io_handle_->GetResourceContext();
|
||||
}
|
||||
|
||||
std::string AtomBrowserContext::GetMediaDeviceIDSalt() {
|
||||
if (!media_device_id_salt_.get())
|
||||
media_device_id_salt_.reset(new brightray::MediaDeviceIDSalt(prefs_.get()));
|
||||
return media_device_id_salt_->GetSalt();
|
||||
}
|
||||
|
||||
std::unique_ptr<content::ZoomLevelDelegate>
|
||||
AtomBrowserContext::CreateZoomLevelDelegate(
|
||||
const base::FilePath& partition_path) {
|
||||
if (!IsOffTheRecord()) {
|
||||
return std::make_unique<brightray::ZoomLevelDelegate>(prefs(),
|
||||
partition_path);
|
||||
}
|
||||
protocol_handlers->clear();
|
||||
|
||||
job_factory->SetProtocolHandler(url::kAboutScheme,
|
||||
base::WrapUnique(new AboutProtocolHandler));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kDataScheme, base::WrapUnique(new net::DataProtocolHandler));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kFileScheme,
|
||||
base::WrapUnique(
|
||||
new asar::AsarProtocolHandler(base::CreateTaskRunnerWithTraits(
|
||||
{base::MayBlock(), base::TaskPriority::USER_VISIBLE,
|
||||
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}))));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kHttpScheme,
|
||||
base::WrapUnique(new HttpProtocolHandler(url::kHttpScheme)));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kHttpsScheme,
|
||||
base::WrapUnique(new HttpProtocolHandler(url::kHttpsScheme)));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kWsScheme,
|
||||
base::WrapUnique(new HttpProtocolHandler(url::kWsScheme)));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kWssScheme,
|
||||
base::WrapUnique(new HttpProtocolHandler(url::kWssScheme)));
|
||||
|
||||
auto* host_resolver =
|
||||
url_request_context_getter()->GetURLRequestContext()->host_resolver();
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kFtpScheme, net::FtpProtocolHandler::Create(host_resolver));
|
||||
|
||||
return std::move(job_factory);
|
||||
}
|
||||
|
||||
net::HttpCache::BackendFactory*
|
||||
AtomBrowserContext::CreateHttpCacheBackendFactory(
|
||||
const base::FilePath& base_path) {
|
||||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
||||
if (!use_cache_ || command_line->HasSwitch(switches::kDisableHttpCache))
|
||||
return new NoCacheBackend;
|
||||
else
|
||||
return brightray::BrowserContext::CreateHttpCacheBackendFactory(base_path);
|
||||
return std::unique_ptr<content::ZoomLevelDelegate>();
|
||||
}
|
||||
|
||||
content::DownloadManagerDelegate*
|
||||
@@ -189,34 +241,12 @@ content::PermissionManager* AtomBrowserContext::GetPermissionManager() {
|
||||
return permission_manager_.get();
|
||||
}
|
||||
|
||||
std::unique_ptr<net::CertVerifier> AtomBrowserContext::CreateCertVerifier(
|
||||
brightray::RequireCTDelegate* ct_delegate) {
|
||||
return base::WrapUnique(new AtomCertVerifier(ct_delegate));
|
||||
storage::SpecialStoragePolicy* AtomBrowserContext::GetSpecialStoragePolicy() {
|
||||
return storage_policy_.get();
|
||||
}
|
||||
|
||||
std::vector<std::string> AtomBrowserContext::GetCookieableSchemes() {
|
||||
auto default_schemes = brightray::BrowserContext::GetCookieableSchemes();
|
||||
const auto& standard_schemes = atom::api::GetStandardSchemes();
|
||||
default_schemes.insert(default_schemes.end(), standard_schemes.begin(),
|
||||
standard_schemes.end());
|
||||
return default_schemes;
|
||||
}
|
||||
|
||||
void AtomBrowserContext::NotifyCookieChange(const net::CanonicalCookie& cookie,
|
||||
bool removed,
|
||||
net::CookieChangeCause cause) {
|
||||
CookieDetails cookie_details(&cookie, removed, cause);
|
||||
cookie_change_sub_list_.Notify(&cookie_details);
|
||||
}
|
||||
|
||||
void AtomBrowserContext::RegisterPrefs(PrefRegistrySimple* pref_registry) {
|
||||
pref_registry->RegisterFilePathPref(prefs::kSelectFileLastDirectory,
|
||||
base::FilePath());
|
||||
base::FilePath download_dir;
|
||||
PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &download_dir);
|
||||
pref_registry->RegisterFilePathPref(prefs::kDownloadDefaultDirectory,
|
||||
download_dir);
|
||||
pref_registry->RegisterDictionaryPref(prefs::kDevToolsFileSystemPaths);
|
||||
std::string AtomBrowserContext::GetUserAgent() const {
|
||||
return user_agent_;
|
||||
}
|
||||
|
||||
AtomBlobReader* AtomBrowserContext::GetBlobReader() {
|
||||
@@ -228,16 +258,67 @@ AtomBlobReader* AtomBrowserContext::GetBlobReader() {
|
||||
return blob_reader_.get();
|
||||
}
|
||||
|
||||
content::PushMessagingService* AtomBrowserContext::GetPushMessagingService() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
content::SSLHostStateDelegate* AtomBrowserContext::GetSSLHostStateDelegate() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
content::BackgroundFetchDelegate*
|
||||
AtomBrowserContext::GetBackgroundFetchDelegate() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
content::BackgroundSyncController*
|
||||
AtomBrowserContext::GetBackgroundSyncController() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
content::BrowsingDataRemoverDelegate*
|
||||
AtomBrowserContext::GetBrowsingDataRemoverDelegate() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
net::URLRequestContextGetter*
|
||||
AtomBrowserContext::CreateRequestContextForStoragePartition(
|
||||
const base::FilePath& partition_path,
|
||||
bool in_memory,
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::URLRequestInterceptorScopedVector request_interceptors) {
|
||||
NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
net::URLRequestContextGetter*
|
||||
AtomBrowserContext::CreateMediaRequestContextForStoragePartition(
|
||||
const base::FilePath& partition_path,
|
||||
bool in_memory) {
|
||||
NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ResolveProxyHelper* AtomBrowserContext::GetResolveProxyHelper() {
|
||||
if (!resolve_proxy_helper_) {
|
||||
resolve_proxy_helper_ = base::MakeRefCounted<ResolveProxyHelper>(this);
|
||||
}
|
||||
return resolve_proxy_helper_.get();
|
||||
}
|
||||
|
||||
// static
|
||||
scoped_refptr<AtomBrowserContext> AtomBrowserContext::From(
|
||||
const std::string& partition,
|
||||
bool in_memory,
|
||||
const base::DictionaryValue& options) {
|
||||
auto browser_context = brightray::BrowserContext::Get(partition, in_memory);
|
||||
PartitionKey key(partition, in_memory);
|
||||
auto* browser_context = browser_context_map_[key].get();
|
||||
if (browser_context)
|
||||
return static_cast<AtomBrowserContext*>(browser_context.get());
|
||||
return scoped_refptr<AtomBrowserContext>(browser_context);
|
||||
|
||||
return new AtomBrowserContext(partition, in_memory, options);
|
||||
auto* new_context = new AtomBrowserContext(partition, in_memory, options);
|
||||
browser_context_map_[key] = new_context->GetWeakPtr();
|
||||
return scoped_refptr<AtomBrowserContext>(new_context);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -5,22 +5,39 @@
|
||||
#ifndef ATOM_BROWSER_ATOM_BROWSER_CONTEXT_H_
|
||||
#define ATOM_BROWSER_ATOM_BROWSER_CONTEXT_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/callback_list.h"
|
||||
#include "brightray/browser/browser_context.h"
|
||||
#include "atom/browser/net/url_request_context_getter.h"
|
||||
#include "base/memory/ref_counted_delete_on_sequence.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "brightray/browser/media/media_device_id_salt.h"
|
||||
#include "chrome/browser/net/proxy_config_monitor.h"
|
||||
#include "content/public/browser/browser_context.h"
|
||||
|
||||
class PrefRegistrySimple;
|
||||
class PrefService;
|
||||
class ValueMapPrefStore;
|
||||
|
||||
namespace brightray {
|
||||
class SpecialStoragePolicy;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomBlobReader;
|
||||
class AtomBrowserContext;
|
||||
class AtomDownloadManagerDelegate;
|
||||
class AtomNetworkDelegate;
|
||||
class AtomPermissionManager;
|
||||
class CookieChangeNotifier;
|
||||
class ResolveProxyHelper;
|
||||
class WebViewManager;
|
||||
struct CookieDetails;
|
||||
|
||||
class AtomBrowserContext : public brightray::BrowserContext {
|
||||
class AtomBrowserContext
|
||||
: public base::RefCountedDeleteOnSequence<AtomBrowserContext>,
|
||||
public content::BrowserContext {
|
||||
public:
|
||||
// Get or create the BrowserContext according to its |partition| and
|
||||
// |in_memory|. The |options| will be passed to constructor when there is no
|
||||
@@ -31,40 +48,60 @@ class AtomBrowserContext : public brightray::BrowserContext {
|
||||
const base::DictionaryValue& options = base::DictionaryValue());
|
||||
|
||||
void SetUserAgent(const std::string& user_agent);
|
||||
// Register callbacks that needs to notified on any cookie store changes.
|
||||
std::unique_ptr<base::CallbackList<void(const CookieDetails*)>::Subscription>
|
||||
RegisterCookieChangeCallback(
|
||||
const base::Callback<void(const CookieDetails*)>& cb);
|
||||
|
||||
// brightray::URLRequestContextGetter::Delegate:
|
||||
std::unique_ptr<net::NetworkDelegate> CreateNetworkDelegate() override;
|
||||
std::string GetUserAgent() override;
|
||||
std::unique_ptr<net::URLRequestJobFactory> CreateURLRequestJobFactory(
|
||||
content::ProtocolHandlerMap* protocol_handlers) override;
|
||||
net::HttpCache::BackendFactory* CreateHttpCacheBackendFactory(
|
||||
const base::FilePath& base_path) override;
|
||||
std::unique_ptr<net::CertVerifier> CreateCertVerifier(
|
||||
brightray::RequireCTDelegate* ct_delegate) override;
|
||||
std::vector<std::string> GetCookieableSchemes() override;
|
||||
void NotifyCookieChange(const net::CanonicalCookie& cookie,
|
||||
bool removed,
|
||||
net::CookieChangeCause cause) override;
|
||||
std::string GetUserAgent() const;
|
||||
bool CanUseHttpCache() const;
|
||||
int GetMaxCacheSize() const;
|
||||
AtomBlobReader* GetBlobReader();
|
||||
network::mojom::NetworkContextPtr GetNetworkContext();
|
||||
// Get the request context, if there is none, create it.
|
||||
net::URLRequestContextGetter* GetRequestContext();
|
||||
ResolveProxyHelper* GetResolveProxyHelper();
|
||||
|
||||
// content::BrowserContext:
|
||||
base::FilePath GetPath() const override;
|
||||
bool IsOffTheRecord() const override;
|
||||
content::ResourceContext* GetResourceContext() override;
|
||||
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
|
||||
const base::FilePath& partition_path) override;
|
||||
content::PushMessagingService* GetPushMessagingService() override;
|
||||
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
|
||||
content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override;
|
||||
content::BackgroundSyncController* GetBackgroundSyncController() override;
|
||||
content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate()
|
||||
override;
|
||||
net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
|
||||
const base::FilePath& partition_path,
|
||||
bool in_memory,
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::URLRequestInterceptorScopedVector request_interceptors) override;
|
||||
net::URLRequestContextGetter* CreateMediaRequestContextForStoragePartition(
|
||||
const base::FilePath& partition_path,
|
||||
bool in_memory) override;
|
||||
std::string GetMediaDeviceIDSalt() override;
|
||||
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
|
||||
content::BrowserPluginGuestManager* GetGuestManager() override;
|
||||
content::PermissionManager* GetPermissionManager() override;
|
||||
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
|
||||
net::URLRequestContextGetter* CreateRequestContext(
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::URLRequestInterceptorScopedVector request_interceptors) override;
|
||||
net::URLRequestContextGetter* CreateMediaRequestContext() override;
|
||||
|
||||
// brightray::BrowserContext:
|
||||
void RegisterPrefs(PrefRegistrySimple* pref_registry) override;
|
||||
|
||||
AtomBlobReader* GetBlobReader();
|
||||
|
||||
void set_cookie_change_subscription(
|
||||
std::unique_ptr<
|
||||
base::CallbackList<void(const CookieDetails*)>::Subscription>
|
||||
subscription) {
|
||||
cookie_change_subscription_.swap(subscription);
|
||||
CookieChangeNotifier* cookie_change_notifier() const {
|
||||
return cookie_change_notifier_.get();
|
||||
}
|
||||
ProxyConfigMonitor* proxy_config_monitor() {
|
||||
return proxy_config_monitor_.get();
|
||||
}
|
||||
PrefService* prefs() const { return prefs_.get(); }
|
||||
void set_in_memory_pref_store(ValueMapPrefStore* pref_store) {
|
||||
in_memory_pref_store_ = pref_store;
|
||||
}
|
||||
ValueMapPrefStore* in_memory_pref_store() const {
|
||||
return in_memory_pref_store_;
|
||||
}
|
||||
base::WeakPtr<AtomBrowserContext> GetWeakPtr() {
|
||||
return weak_factory_.GetWeakPtr();
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -74,16 +111,60 @@ class AtomBrowserContext : public brightray::BrowserContext {
|
||||
~AtomBrowserContext() override;
|
||||
|
||||
private:
|
||||
friend class base::RefCountedDeleteOnSequence<AtomBrowserContext>;
|
||||
friend class base::DeleteHelper<AtomBrowserContext>;
|
||||
|
||||
// Initialize pref registry.
|
||||
void InitPrefs();
|
||||
|
||||
// partition_id => browser_context
|
||||
struct PartitionKey {
|
||||
std::string partition;
|
||||
bool in_memory;
|
||||
|
||||
PartitionKey(const std::string& partition, bool in_memory)
|
||||
: partition(partition), in_memory(in_memory) {}
|
||||
|
||||
bool operator<(const PartitionKey& other) const {
|
||||
if (partition == other.partition)
|
||||
return in_memory < other.in_memory;
|
||||
return partition < other.partition;
|
||||
}
|
||||
|
||||
bool operator==(const PartitionKey& other) const {
|
||||
return (partition == other.partition) && (in_memory == other.in_memory);
|
||||
}
|
||||
};
|
||||
using BrowserContextMap =
|
||||
std::map<PartitionKey, base::WeakPtr<AtomBrowserContext>>;
|
||||
static BrowserContextMap browser_context_map_;
|
||||
|
||||
// Self-destructing class responsible for creating URLRequestContextGetter
|
||||
// on the UI thread and deletes itself on the IO thread.
|
||||
URLRequestContextGetter::Handle* io_handle_;
|
||||
ValueMapPrefStore* in_memory_pref_store_;
|
||||
|
||||
std::unique_ptr<CookieChangeNotifier> cookie_change_notifier_;
|
||||
std::unique_ptr<PrefService> prefs_;
|
||||
std::unique_ptr<AtomDownloadManagerDelegate> download_manager_delegate_;
|
||||
std::unique_ptr<WebViewManager> guest_manager_;
|
||||
std::unique_ptr<AtomPermissionManager> permission_manager_;
|
||||
std::unique_ptr<AtomBlobReader> blob_reader_;
|
||||
std::string user_agent_;
|
||||
bool use_cache_;
|
||||
std::unique_ptr<brightray::MediaDeviceIDSalt> media_device_id_salt_;
|
||||
scoped_refptr<ResolveProxyHelper> resolve_proxy_helper_;
|
||||
scoped_refptr<storage::SpecialStoragePolicy> storage_policy_;
|
||||
|
||||
base::CallbackList<void(const CookieDetails*)> cookie_change_sub_list_;
|
||||
std::unique_ptr<base::CallbackList<void(const CookieDetails*)>::Subscription>
|
||||
cookie_change_subscription_;
|
||||
// Tracks the ProxyConfig to use, and passes any updates to a NetworkContext
|
||||
// ProxyConfigClient.
|
||||
std::unique_ptr<ProxyConfigMonitor> proxy_config_monitor_;
|
||||
|
||||
std::string user_agent_;
|
||||
base::FilePath path_;
|
||||
bool in_memory_ = false;
|
||||
bool use_cache_ = true;
|
||||
int max_cache_size_ = 0;
|
||||
|
||||
base::WeakPtrFactory<AtomBrowserContext> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomBrowserContext);
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/bridge_task_runner.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/io_thread.h"
|
||||
#include "atom/browser/javascript_environment.h"
|
||||
#include "atom/browser/node_debugger.h"
|
||||
#include "atom/common/api/atom_bindings.h"
|
||||
@@ -18,10 +19,15 @@
|
||||
#include "base/command_line.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/net/chrome_net_log_helper.h"
|
||||
#include "components/net_log/chrome_net_log.h"
|
||||
#include "components/net_log/net_export_file_writer.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/child_process_security_policy.h"
|
||||
#include "content/public/common/result_codes.h"
|
||||
#include "content/public/common/service_manager_connection.h"
|
||||
#include "services/device/public/mojom/constants.mojom.h"
|
||||
#include "services/network/public/cpp/network_switches.h"
|
||||
#include "services/service_manager/public/cpp/connector.h"
|
||||
#include "ui/base/idle/idle.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
@@ -58,12 +64,14 @@ void Erase(T* container, typename T::iterator iter) {
|
||||
// static
|
||||
AtomBrowserMainParts* AtomBrowserMainParts::self_ = nullptr;
|
||||
|
||||
AtomBrowserMainParts::AtomBrowserMainParts()
|
||||
AtomBrowserMainParts::AtomBrowserMainParts(
|
||||
const content::MainFunctionParams& params)
|
||||
: fake_browser_process_(new BrowserProcess),
|
||||
browser_(new Browser),
|
||||
node_bindings_(NodeBindings::Create(NodeBindings::BROWSER)),
|
||||
atom_bindings_(new AtomBindings(uv_default_loop())),
|
||||
gc_timer_(true, true) {
|
||||
gc_timer_(true, true),
|
||||
main_function_params_(params) {
|
||||
DCHECK(!self_) << "Cannot have two AtomBrowserMainParts";
|
||||
self_ = this;
|
||||
// Register extension scheme as web safe scheme.
|
||||
@@ -154,6 +162,14 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
|
||||
|
||||
// Wrap the uv loop with global env.
|
||||
node_bindings_->set_uv_env(env);
|
||||
|
||||
// We already initialized the feature list in
|
||||
// brightray::BrowserMainParts::PreEarlyInitialization(), but
|
||||
// the user JS script would not have had a chance to alter the command-line
|
||||
// switches at that point. Lets reinitialize it here to pick up the
|
||||
// command-line changes.
|
||||
base::FeatureList::ClearInstanceForTesting();
|
||||
brightray::BrowserMainParts::InitializeFeatureList();
|
||||
}
|
||||
|
||||
int AtomBrowserMainParts::PreCreateThreads() {
|
||||
@@ -167,9 +183,34 @@ int AtomBrowserMainParts::PreCreateThreads() {
|
||||
ui::InitIdleMonitor();
|
||||
#endif
|
||||
|
||||
net_log_ = std::make_unique<net_log::ChromeNetLog>();
|
||||
auto& command_line = main_function_params_.command_line;
|
||||
// start net log trace if --log-net-log is passed in the command line.
|
||||
if (command_line.HasSwitch(network::switches::kLogNetLog)) {
|
||||
base::FilePath log_file =
|
||||
command_line.GetSwitchValuePath(network::switches::kLogNetLog);
|
||||
if (!log_file.empty()) {
|
||||
net_log_->StartWritingToFile(
|
||||
log_file, GetNetCaptureModeFromCommandLine(command_line),
|
||||
command_line.GetCommandLineString(), std::string());
|
||||
}
|
||||
}
|
||||
// Initialize net log file exporter.
|
||||
net_log_->net_export_file_writer()->Initialize(
|
||||
content::BrowserThread::GetTaskRunnerForThread(
|
||||
content::BrowserThread::IO));
|
||||
|
||||
// Manage global state of net and other IO thread related.
|
||||
io_thread_ = std::make_unique<IOThread>(net_log_.get());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void AtomBrowserMainParts::PostDestroyThreads() {
|
||||
brightray::BrowserMainParts::PostDestroyThreads();
|
||||
io_thread_.reset();
|
||||
}
|
||||
|
||||
void AtomBrowserMainParts::ToolkitInitialized() {
|
||||
brightray::BrowserMainParts::ToolkitInitialized();
|
||||
#if defined(OS_MACOSX)
|
||||
@@ -229,9 +270,6 @@ void AtomBrowserMainParts::PostMainMessageLoopStart() {
|
||||
#if defined(OS_POSIX)
|
||||
HandleShutdownSignals();
|
||||
#endif
|
||||
// TODO(deepak1556): Enable this optionally based on response
|
||||
// from AtomPermissionManager.
|
||||
GetGeolocationControl()->UserDidOptIntoLocationServices();
|
||||
}
|
||||
|
||||
void AtomBrowserMainParts::PostMainMessageLoopRun() {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "base/timer/timer.h"
|
||||
#include "brightray/browser/browser_main_parts.h"
|
||||
#include "content/public/browser/browser_context.h"
|
||||
#include "content/public/common/main_function_params.h"
|
||||
#include "services/device/public/mojom/geolocation_control.mojom.h"
|
||||
|
||||
class BrowserProcess;
|
||||
@@ -22,10 +23,15 @@ class ViewsDelegate;
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace net_log {
|
||||
class ChromeNetLog;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomBindings;
|
||||
class Browser;
|
||||
class IOThread;
|
||||
class JavascriptEnvironment;
|
||||
class NodeBindings;
|
||||
class NodeDebugger;
|
||||
@@ -38,7 +44,7 @@ class ViewsDelegateMac;
|
||||
|
||||
class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||
public:
|
||||
AtomBrowserMainParts();
|
||||
explicit AtomBrowserMainParts(const content::MainFunctionParams& params);
|
||||
~AtomBrowserMainParts() override;
|
||||
|
||||
static AtomBrowserMainParts* Get();
|
||||
@@ -54,7 +60,13 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||
// Returns a closure that can be used to remove |callback| from the list.
|
||||
void RegisterDestructionCallback(base::OnceClosure callback);
|
||||
|
||||
// Returns the connection to GeolocationControl which can be
|
||||
// used to enable the location services once per client.
|
||||
device::mojom::GeolocationControl* GetGeolocationControl();
|
||||
|
||||
Browser* browser() { return browser_.get(); }
|
||||
IOThread* io_thread() const { return io_thread_.get(); }
|
||||
net_log::ChromeNetLog* net_log() { return net_log_.get(); }
|
||||
|
||||
protected:
|
||||
// content::BrowserMainParts:
|
||||
@@ -69,6 +81,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||
#if defined(OS_MACOSX)
|
||||
void PreMainMessageLoopStart() override;
|
||||
#endif
|
||||
void PostDestroyThreads() override;
|
||||
|
||||
private:
|
||||
#if defined(OS_POSIX)
|
||||
@@ -87,8 +100,6 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||
std::unique_ptr<brightray::ViewsDelegate> views_delegate_;
|
||||
#endif
|
||||
|
||||
device::mojom::GeolocationControl* GetGeolocationControl();
|
||||
|
||||
// A fake BrowserProcess object that used to feed the source code from chrome.
|
||||
std::unique_ptr<BrowserProcess> fake_browser_process_;
|
||||
|
||||
@@ -105,6 +116,8 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||
std::unique_ptr<AtomBindings> atom_bindings_;
|
||||
std::unique_ptr<NodeEnvironment> node_env_;
|
||||
std::unique_ptr<NodeDebugger> node_debugger_;
|
||||
std::unique_ptr<IOThread> io_thread_;
|
||||
std::unique_ptr<net_log::ChromeNetLog> net_log_;
|
||||
|
||||
base::Timer gc_timer_;
|
||||
|
||||
@@ -113,6 +126,8 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||
|
||||
device::mojom::GeolocationControlPtr geolocation_control_;
|
||||
|
||||
const content::MainFunctionParams main_function_params_;
|
||||
|
||||
static AtomBrowserMainParts* self_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/atom_browser_client.h"
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/browser/web_contents_preferences.h"
|
||||
#include "content/public/browser/child_process_security_policy.h"
|
||||
#include "content/public/browser/permission_type.h"
|
||||
@@ -43,6 +44,7 @@ class AtomPermissionManager::PendingRequest {
|
||||
const StatusesCallback& callback)
|
||||
: render_process_id_(render_frame_host->GetProcess()->GetID()),
|
||||
callback_(callback),
|
||||
permissions_(permissions),
|
||||
results_(permissions.size(), blink::mojom::PermissionStatus::DENIED),
|
||||
remaining_results_(permissions.size()) {}
|
||||
|
||||
@@ -50,6 +52,18 @@ class AtomPermissionManager::PendingRequest {
|
||||
blink::mojom::PermissionStatus status) {
|
||||
DCHECK(!IsComplete());
|
||||
|
||||
if (status == blink::mojom::PermissionStatus::GRANTED) {
|
||||
const auto permission = permissions_[permission_id];
|
||||
if (permission == content::PermissionType::MIDI_SYSEX) {
|
||||
content::ChildProcessSecurityPolicy::GetInstance()
|
||||
->GrantSendMidiSysExMessage(render_process_id_);
|
||||
} else if (permission == content::PermissionType::GEOLOCATION) {
|
||||
AtomBrowserMainParts::Get()
|
||||
->GetGeolocationControl()
|
||||
->UserDidOptIntoLocationServices();
|
||||
}
|
||||
}
|
||||
|
||||
results_[permission_id] = status;
|
||||
--remaining_results_;
|
||||
}
|
||||
@@ -63,6 +77,7 @@ class AtomPermissionManager::PendingRequest {
|
||||
private:
|
||||
int render_process_id_;
|
||||
const StatusesCallback callback_;
|
||||
std::vector<content::PermissionType> permissions_;
|
||||
std::vector<blink::mojom::PermissionStatus> results_;
|
||||
size_t remaining_results_;
|
||||
};
|
||||
@@ -139,6 +154,10 @@ int AtomPermissionManager::RequestPermissionsWithDetails(
|
||||
content::ChildProcessSecurityPolicy::GetInstance()
|
||||
->GrantSendMidiSysExMessage(
|
||||
render_frame_host->GetProcess()->GetID());
|
||||
} else if (permission == content::PermissionType::GEOLOCATION) {
|
||||
AtomBrowserMainParts::Get()
|
||||
->GetGeolocationControl()
|
||||
->UserDidOptIntoLocationServices();
|
||||
}
|
||||
statuses.push_back(blink::mojom::PermissionStatus::GRANTED);
|
||||
}
|
||||
@@ -153,10 +172,6 @@ int AtomPermissionManager::RequestPermissionsWithDetails(
|
||||
|
||||
for (size_t i = 0; i < permissions.size(); ++i) {
|
||||
auto permission = permissions[i];
|
||||
if (permission == content::PermissionType::MIDI_SYSEX) {
|
||||
content::ChildProcessSecurityPolicy::GetInstance()
|
||||
->GrantSendMidiSysExMessage(render_frame_host->GetProcess()->GetID());
|
||||
}
|
||||
const auto callback =
|
||||
base::Bind(&AtomPermissionManager::OnPermissionResponse,
|
||||
base::Unretained(this), request_id, i);
|
||||
@@ -186,7 +201,6 @@ void AtomPermissionManager::OnPermissionResponse(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AtomPermissionManager::ResetPermission(content::PermissionType permission,
|
||||
const GURL& requesting_origin,
|
||||
const GURL& embedding_origin) {}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/browser/browser_observer.h"
|
||||
#include "atom/browser/login_handler.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/window_list.h"
|
||||
#include "base/files/file_util.h"
|
||||
@@ -164,7 +165,7 @@ void Browser::OnAccessibilitySupportChanged() {
|
||||
}
|
||||
|
||||
void Browser::RequestLogin(
|
||||
LoginHandler* login_handler,
|
||||
scoped_refptr<LoginHandler> login_handler,
|
||||
std::unique_ptr<base::DictionaryValue> request_details) {
|
||||
for (BrowserObserver& observer : observers_)
|
||||
observer.OnLogin(login_handler, *(request_details.get()));
|
||||
|
||||
@@ -33,7 +33,6 @@ class Image;
|
||||
namespace atom {
|
||||
|
||||
class AtomMenuModel;
|
||||
class LoginHandler;
|
||||
|
||||
// This class is used for control application-wide operations.
|
||||
class Browser : public WindowListObserver {
|
||||
@@ -229,7 +228,7 @@ class Browser : public WindowListObserver {
|
||||
void OnAccessibilitySupportChanged();
|
||||
|
||||
// Request basic auth login.
|
||||
void RequestLogin(LoginHandler* login_handler,
|
||||
void RequestLogin(scoped_refptr<LoginHandler> login_handler,
|
||||
std::unique_ptr<base::DictionaryValue> request_details);
|
||||
|
||||
void PreMainMessageLoopRun();
|
||||
|
||||
@@ -217,6 +217,65 @@ Browser::LoginItemSettings Browser::GetLoginItemSettings(
|
||||
return settings;
|
||||
}
|
||||
|
||||
// copied from GetLoginItemForApp in base/mac/mac_util.mm
|
||||
LSSharedFileListItemRef GetLoginItemForApp() {
|
||||
base::ScopedCFTypeRef<LSSharedFileListRef> login_items(
|
||||
LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL));
|
||||
if (!login_items.get()) {
|
||||
LOG(ERROR) << "Couldn't get a Login Items list.";
|
||||
return NULL;
|
||||
}
|
||||
base::scoped_nsobject<NSArray> login_items_array(
|
||||
base::mac::CFToNSCast(LSSharedFileListCopySnapshot(login_items, NULL)));
|
||||
NSURL* url = [NSURL fileURLWithPath:[base::mac::MainBundle() bundlePath]];
|
||||
for (NSUInteger i = 0; i < [login_items_array count]; ++i) {
|
||||
LSSharedFileListItemRef item =
|
||||
reinterpret_cast<LSSharedFileListItemRef>(login_items_array[i]);
|
||||
CFURLRef item_url_ref = NULL;
|
||||
if (LSSharedFileListItemResolve(item, 0, &item_url_ref, NULL) == noErr &&
|
||||
item_url_ref) {
|
||||
base::ScopedCFTypeRef<CFURLRef> item_url(item_url_ref);
|
||||
if (CFEqual(item_url, url)) {
|
||||
CFRetain(item);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void RemoveFromLoginItems() {
|
||||
base::ScopedCFTypeRef<LSSharedFileListRef> list(
|
||||
LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL));
|
||||
if (!list) {
|
||||
LOG(ERROR) << "Unable to access shared file list";
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetLoginItemForApp() != NULL) {
|
||||
base::scoped_nsobject<NSArray> login_items_array(
|
||||
base::mac::CFToNSCast(LSSharedFileListCopySnapshot(list, NULL)));
|
||||
|
||||
if (!login_items_array) {
|
||||
LOG(ERROR) << "No items in list of auto-loaded apps";
|
||||
return;
|
||||
}
|
||||
|
||||
for (NSUInteger i = 0; i < [login_items_array count]; ++i) {
|
||||
LSSharedFileListItemRef item =
|
||||
reinterpret_cast<LSSharedFileListItemRef>(login_items_array[i]);
|
||||
CFURLRef url_ref = NULL;
|
||||
if (LSSharedFileListItemResolve(item, 0, &url_ref, NULL) == noErr &&
|
||||
item) {
|
||||
base::ScopedCFTypeRef<CFURLRef> url(url_ref);
|
||||
if ([[base::mac::CFToNSCast(url.get()) path]
|
||||
hasPrefix:[[NSBundle mainBundle] bundlePath]])
|
||||
LSSharedFileListItemRemove(list, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Browser::SetLoginItemSettings(LoginItemSettings settings) {
|
||||
#if defined(MAS_BUILD)
|
||||
platform_util::SetLoginItemEnabled(settings.open_at_login);
|
||||
@@ -224,7 +283,7 @@ void Browser::SetLoginItemSettings(LoginItemSettings settings) {
|
||||
if (settings.open_at_login)
|
||||
base::mac::AddToLoginItems(settings.open_as_hidden);
|
||||
else
|
||||
base::mac::RemoveFromLoginItems();
|
||||
RemoveFromLoginItems();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/login_handler.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "build/build_config.h"
|
||||
|
||||
namespace base {
|
||||
@@ -15,8 +17,6 @@ class DictionaryValue;
|
||||
|
||||
namespace atom {
|
||||
|
||||
class LoginHandler;
|
||||
|
||||
class BrowserObserver {
|
||||
public:
|
||||
// The browser is about to close all windows.
|
||||
@@ -49,7 +49,7 @@ class BrowserObserver {
|
||||
virtual void OnFinishLaunching(const base::DictionaryValue& launch_info) {}
|
||||
|
||||
// The browser requests HTTP login.
|
||||
virtual void OnLogin(LoginHandler* login_handler,
|
||||
virtual void OnLogin(scoped_refptr<LoginHandler> login_handler,
|
||||
const base::DictionaryValue& request_details) {}
|
||||
|
||||
// The browser's accessibility suppport has changed.
|
||||
|
||||
@@ -152,7 +152,8 @@ CommonWebContentsDelegate::~CommonWebContentsDelegate() {}
|
||||
|
||||
void CommonWebContentsDelegate::InitWithWebContents(
|
||||
content::WebContents* web_contents,
|
||||
AtomBrowserContext* browser_context) {
|
||||
AtomBrowserContext* browser_context,
|
||||
bool is_guest) {
|
||||
browser_context_ = browser_context;
|
||||
web_contents->SetDelegate(this);
|
||||
|
||||
@@ -165,7 +166,8 @@ void CommonWebContentsDelegate::InitWithWebContents(
|
||||
!web_preferences || web_preferences->IsEnabled(options::kOffscreen);
|
||||
|
||||
// Create InspectableWebContents.
|
||||
web_contents_.reset(brightray::InspectableWebContents::Create(web_contents));
|
||||
web_contents_.reset(brightray::InspectableWebContents::Create(
|
||||
web_contents, browser_context->prefs(), is_guest));
|
||||
web_contents_->SetDelegate(this);
|
||||
}
|
||||
|
||||
@@ -192,8 +194,17 @@ void CommonWebContentsDelegate::SetOwnerWindow(
|
||||
|
||||
void CommonWebContentsDelegate::ResetManagedWebContents(bool async) {
|
||||
if (async) {
|
||||
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE,
|
||||
web_contents_.release());
|
||||
// Browser context should be destroyed only after the WebContents,
|
||||
// this is guaranteed in the sync mode by the order of declaration,
|
||||
// in the async version we maintain a reference until the WebContents
|
||||
// is destroyed.
|
||||
base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce([](scoped_refptr<AtomBrowserContext> browser_context,
|
||||
std::unique_ptr<brightray::InspectableWebContents>
|
||||
web_contents) { web_contents.reset(); },
|
||||
base::RetainedRef(browser_context_),
|
||||
std::move(web_contents_)));
|
||||
} else {
|
||||
web_contents_.reset();
|
||||
}
|
||||
|
||||
@@ -42,7 +42,8 @@ class CommonWebContentsDelegate
|
||||
// Creates a InspectableWebContents object and takes onwership of
|
||||
// |web_contents|.
|
||||
void InitWithWebContents(content::WebContents* web_contents,
|
||||
AtomBrowserContext* browser_context);
|
||||
AtomBrowserContext* browser_context,
|
||||
bool is_guest);
|
||||
|
||||
// Set the window as owner window.
|
||||
void SetOwnerWindow(NativeWindow* owner_window);
|
||||
@@ -61,10 +62,6 @@ class CommonWebContentsDelegate
|
||||
|
||||
NativeWindow* owner_window() const { return owner_window_.get(); }
|
||||
|
||||
void set_ignore_menu_shortcuts(bool ignore) {
|
||||
ignore_menu_shortcuts_ = ignore;
|
||||
}
|
||||
|
||||
bool is_html_fullscreen() const { return html_fullscreen_; }
|
||||
|
||||
protected:
|
||||
@@ -156,7 +153,6 @@ class CommonWebContentsDelegate
|
||||
base::WeakPtr<NativeWindow> owner_window_;
|
||||
|
||||
bool offscreen_ = false;
|
||||
bool ignore_menu_shortcuts_ = false;
|
||||
|
||||
// Whether window is fullscreened by HTML5 api.
|
||||
bool html_fullscreen_ = false;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "atom/browser/web_contents_preferences.h"
|
||||
#include "brightray/browser/mac/event_dispatching_window.h"
|
||||
#include "content/public/browser/native_web_keyboard_event.h"
|
||||
#include "ui/events/keycodes/keyboard_codes.h"
|
||||
@@ -27,16 +28,20 @@ void CommonWebContentsDelegate::HandleKeyboardEvent(
|
||||
if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen())
|
||||
ExitFullscreenModeForTab(source);
|
||||
|
||||
if (!ignore_menu_shortcuts_) {
|
||||
// Send the event to the menu before sending it to the window
|
||||
if (event.os_event.type == NSKeyDown &&
|
||||
[[NSApp mainMenu] performKeyEquivalent:event.os_event])
|
||||
return;
|
||||
// Check if the webContents has preferences and to ignore shortcuts
|
||||
auto* web_preferences = WebContentsPreferences::From(source);
|
||||
if (web_preferences &&
|
||||
web_preferences->IsEnabled("ignoreMenuShortcuts", false))
|
||||
return;
|
||||
|
||||
if (event.os_event.window &&
|
||||
[event.os_event.window isKindOfClass:[EventDispatchingWindow class]])
|
||||
[event.os_event.window redispatchKeyEvent:event.os_event];
|
||||
}
|
||||
// Send the event to the menu before sending it to the window
|
||||
if (event.os_event.type == NSKeyDown &&
|
||||
[[NSApp mainMenu] performKeyEquivalent:event.os_event])
|
||||
return;
|
||||
|
||||
if (event.os_event.window &&
|
||||
[event.os_event.window isKindOfClass:[EventDispatchingWindow class]])
|
||||
[event.os_event.window redispatchKeyEvent:event.os_event];
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "atom/browser/api/atom_api_web_contents_view.h"
|
||||
#include "atom/browser/native_window_views.h"
|
||||
#include "atom/browser/web_contents_preferences.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "content/public/browser/native_web_keyboard_event.h"
|
||||
#include "ui/events/keycodes/keyboard_codes.h"
|
||||
@@ -23,9 +24,16 @@ void CommonWebContentsDelegate::HandleKeyboardEvent(
|
||||
if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen())
|
||||
ExitFullscreenModeForTab(source);
|
||||
|
||||
// Check if the webContents has preferences and to ignore shortcuts
|
||||
auto* web_preferences = WebContentsPreferences::From(source);
|
||||
if (web_preferences &&
|
||||
web_preferences->IsEnabled("ignoreMenuShortcuts", false))
|
||||
return;
|
||||
|
||||
// Let the NativeWindow handle other parts.
|
||||
if (!ignore_menu_shortcuts_ && owner_window())
|
||||
if (owner_window()) {
|
||||
owner_window()->HandleKeyboardEvent(source, event);
|
||||
}
|
||||
}
|
||||
|
||||
void CommonWebContentsDelegate::ShowAutofillPopup(
|
||||
|
||||
72
atom/browser/cookie_change_notifier.cc
Normal file
72
atom/browser/cookie_change_notifier.cc
Normal file
@@ -0,0 +1,72 @@
|
||||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/cookie_change_notifier.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/net/cookie_details.h"
|
||||
#include "base/bind.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "net/cookies/canonical_cookie.h"
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
namespace atom {
|
||||
|
||||
CookieChangeNotifier::CookieChangeNotifier(AtomBrowserContext* browser_context)
|
||||
: browser_context_(browser_context), binding_(this) {
|
||||
StartListening();
|
||||
}
|
||||
|
||||
CookieChangeNotifier::~CookieChangeNotifier() = default;
|
||||
|
||||
std::unique_ptr<base::CallbackList<void(const CookieDetails*)>::Subscription>
|
||||
CookieChangeNotifier::RegisterCookieChangeCallback(
|
||||
const base::Callback<void(const CookieDetails*)>& cb) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
|
||||
return cookie_change_sub_list_.Add(cb);
|
||||
}
|
||||
|
||||
void CookieChangeNotifier::StartListening() {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
DCHECK(!binding_.is_bound());
|
||||
|
||||
network::mojom::CookieManager* cookie_manager =
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
|
||||
->GetCookieManagerForBrowserProcess();
|
||||
// Cookie manager should be created whenever network context is created,
|
||||
// if this fails then there is something wrong with our context creation
|
||||
// cycle.
|
||||
CHECK(cookie_manager);
|
||||
|
||||
network::mojom::CookieChangeListenerPtr listener_ptr;
|
||||
binding_.Bind(mojo::MakeRequest(&listener_ptr));
|
||||
binding_.set_connection_error_handler(base::BindOnce(
|
||||
&CookieChangeNotifier::OnConnectionError, base::Unretained(this)));
|
||||
|
||||
cookie_manager->AddGlobalChangeListener(std::move(listener_ptr));
|
||||
}
|
||||
|
||||
void CookieChangeNotifier::OnConnectionError() {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
|
||||
binding_.Close();
|
||||
StartListening();
|
||||
}
|
||||
|
||||
void CookieChangeNotifier::OnCookieChange(
|
||||
const net::CanonicalCookie& cookie,
|
||||
network::mojom::CookieChangeCause cause) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
|
||||
CookieDetails cookie_details(
|
||||
&cookie, cause != network::mojom::CookieChangeCause::INSERTED, cause);
|
||||
cookie_change_sub_list_.Notify(&cookie_details);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
48
atom/browser/cookie_change_notifier.h
Normal file
48
atom/browser/cookie_change_notifier.h
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_COOKIE_CHANGE_NOTIFIER_H_
|
||||
#define ATOM_BROWSER_COOKIE_CHANGE_NOTIFIER_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "base/callback_list.h"
|
||||
#include "base/macros.h"
|
||||
#include "mojo/public/cpp/bindings/binding.h"
|
||||
#include "services/network/public/mojom/cookie_manager.mojom.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomBrowserContext;
|
||||
struct CookieDetails;
|
||||
|
||||
// Sends cookie-change notifications on the UI thread.
|
||||
class CookieChangeNotifier : public network::mojom::CookieChangeListener {
|
||||
public:
|
||||
explicit CookieChangeNotifier(AtomBrowserContext* browser_context);
|
||||
~CookieChangeNotifier() override;
|
||||
|
||||
// Register callbacks that needs to notified on any cookie store changes.
|
||||
std::unique_ptr<base::CallbackList<void(const CookieDetails*)>::Subscription>
|
||||
RegisterCookieChangeCallback(
|
||||
const base::Callback<void(const CookieDetails*)>& cb);
|
||||
|
||||
private:
|
||||
void StartListening();
|
||||
void OnConnectionError();
|
||||
|
||||
// network::mojom::CookieChangeListener implementation.
|
||||
void OnCookieChange(const net::CanonicalCookie& cookie,
|
||||
network::mojom::CookieChangeCause cause) override;
|
||||
|
||||
AtomBrowserContext* browser_context_;
|
||||
base::CallbackList<void(const CookieDetails*)> cookie_change_sub_list_;
|
||||
mojo::Binding<network::mojom::CookieChangeListener> binding_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CookieChangeNotifier);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_COOKIE_CHANGE_NOTIFIER_H_
|
||||
44
atom/browser/fake_location_provider.cc
Normal file
44
atom/browser/fake_location_provider.cc
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/fake_location_provider.h"
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/time/time.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
FakeLocationProvider::FakeLocationProvider() {
|
||||
position_.latitude = 10;
|
||||
position_.longitude = -10;
|
||||
position_.accuracy = 1;
|
||||
position_.error_code =
|
||||
device::mojom::Geoposition::ErrorCode::POSITION_UNAVAILABLE;
|
||||
}
|
||||
|
||||
FakeLocationProvider::~FakeLocationProvider() = default;
|
||||
|
||||
void FakeLocationProvider::SetUpdateCallback(
|
||||
const LocationProviderUpdateCallback& callback) {
|
||||
callback_ = callback;
|
||||
}
|
||||
|
||||
void FakeLocationProvider::StartProvider(bool high_accuracy) {}
|
||||
|
||||
void FakeLocationProvider::StopProvider() {}
|
||||
|
||||
const device::mojom::Geoposition& FakeLocationProvider::GetPosition() {
|
||||
return position_;
|
||||
}
|
||||
|
||||
void FakeLocationProvider::OnPermissionGranted() {
|
||||
if (!callback_.is_null()) {
|
||||
// Check device::ValidateGeoPosition for range of values.
|
||||
position_.error_code = device::mojom::Geoposition::ErrorCode::NONE;
|
||||
position_.timestamp = base::Time::Now();
|
||||
callback_.Run(this, position_);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
36
atom/browser/fake_location_provider.h
Normal file
36
atom/browser/fake_location_provider.h
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_FAKE_LOCATION_PROVIDER_H_
|
||||
#define ATOM_BROWSER_FAKE_LOCATION_PROVIDER_H_
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "device/geolocation/public/cpp/location_provider.h"
|
||||
#include "services/device/public/mojom/geoposition.mojom.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class FakeLocationProvider : public device::LocationProvider {
|
||||
public:
|
||||
FakeLocationProvider();
|
||||
~FakeLocationProvider() override;
|
||||
|
||||
// LocationProvider Implementation:
|
||||
void SetUpdateCallback(
|
||||
const LocationProviderUpdateCallback& callback) override;
|
||||
void StartProvider(bool high_accuracy) override;
|
||||
void StopProvider() override;
|
||||
const device::mojom::Geoposition& GetPosition() override;
|
||||
void OnPermissionGranted() override;
|
||||
|
||||
private:
|
||||
device::mojom::Geoposition position_;
|
||||
LocationProviderUpdateCallback callback_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FakeLocationProvider);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_FAKE_LOCATION_PROVIDER_H_
|
||||
80
atom/browser/io_thread.cc
Normal file
80
atom/browser/io_thread.cc
Normal file
@@ -0,0 +1,80 @@
|
||||
// Copyright (c) 2017 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/io_thread.h"
|
||||
|
||||
#include "components/net_log/chrome_net_log.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "net/proxy_resolution/proxy_service.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
#include "net/url_request/url_request_context_builder.h"
|
||||
#include "net/url_request/url_request_context_getter.h"
|
||||
|
||||
#if defined(USE_NSS_CERTS)
|
||||
#include "net/cert_net/nss_ocsp.h"
|
||||
#endif
|
||||
|
||||
#if defined(OS_LINUX) || defined(OS_MACOSX)
|
||||
#include "net/cert/cert_net_fetcher.h"
|
||||
#include "net/cert_net/cert_net_fetcher_impl.h"
|
||||
#endif
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
namespace atom {
|
||||
|
||||
IOThread::IOThread(net_log::ChromeNetLog* net_log) : net_log_(net_log) {
|
||||
BrowserThread::SetIOThreadDelegate(this);
|
||||
}
|
||||
|
||||
IOThread::~IOThread() {
|
||||
BrowserThread::SetIOThreadDelegate(nullptr);
|
||||
}
|
||||
|
||||
void IOThread::Init() {
|
||||
net::URLRequestContextBuilder builder;
|
||||
// TODO(deepak1556): We need to respoect user proxy configurations,
|
||||
// the following initialization has to happen before any request
|
||||
// contexts are utilized by the io thread, so that proper cert validation
|
||||
// take place, solutions:
|
||||
// 1) Use the request context from default partition, but since
|
||||
// an app can completely run on a custom session without ever creating
|
||||
// the default session, we will have to force create the default session
|
||||
// in those scenarios.
|
||||
// 2) Add a new api on app module that sets the proxy configuration
|
||||
// for the global requests, like the cert fetchers below and
|
||||
// geolocation requests.
|
||||
// 3) There is also ongoing work in upstream which will eventually allow
|
||||
// localizing these global fetchers to their own URLRequestContexts.
|
||||
builder.set_proxy_resolution_service(
|
||||
net::ProxyResolutionService::CreateDirect());
|
||||
url_request_context_ = builder.Build();
|
||||
url_request_context_getter_ = new net::TrivialURLRequestContextGetter(
|
||||
url_request_context_.get(), base::ThreadTaskRunnerHandle::Get());
|
||||
|
||||
#if defined(USE_NSS_CERTS)
|
||||
net::SetURLRequestContextForNSSHttpIO(url_request_context_.get());
|
||||
#endif
|
||||
#if defined(OS_LINUX) || defined(OS_MACOSX)
|
||||
net::SetGlobalCertNetFetcher(
|
||||
net::CreateCertNetFetcher(url_request_context_.get()));
|
||||
#endif
|
||||
}
|
||||
|
||||
void IOThread::CleanUp() {
|
||||
#if defined(USE_NSS_CERTS)
|
||||
net::SetURLRequestContextForNSSHttpIO(nullptr);
|
||||
#endif
|
||||
#if defined(OS_LINUX) || defined(OS_MACOSX)
|
||||
net::ShutdownGlobalCertNetFetcher();
|
||||
#endif
|
||||
// Explicitly release before the IO thread gets destroyed.
|
||||
url_request_context_.reset();
|
||||
url_request_context_getter_ = nullptr;
|
||||
|
||||
if (net_log_)
|
||||
net_log_->ShutDownBeforeTaskScheduler();
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
@@ -2,12 +2,13 @@
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef BRIGHTRAY_BROWSER_IO_THREAD_H_
|
||||
#define BRIGHTRAY_BROWSER_IO_THREAD_H_
|
||||
#ifndef ATOM_BROWSER_IO_THREAD_H_
|
||||
#define ATOM_BROWSER_IO_THREAD_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "content/public/browser/browser_thread_delegate.h"
|
||||
|
||||
namespace net {
|
||||
@@ -15,15 +16,19 @@ class URLRequestContext;
|
||||
class URLRequestContextGetter;
|
||||
} // namespace net
|
||||
|
||||
namespace brightray {
|
||||
namespace net_log {
|
||||
class ChromeNetLog;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
class IOThread : public content::BrowserThreadDelegate {
|
||||
public:
|
||||
IOThread();
|
||||
explicit IOThread(net_log::ChromeNetLog* net_log);
|
||||
~IOThread() override;
|
||||
|
||||
net::URLRequestContextGetter* GetRequestContext() {
|
||||
return url_request_context_getter_;
|
||||
return url_request_context_getter_.get();
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -32,12 +37,15 @@ class IOThread : public content::BrowserThreadDelegate {
|
||||
void CleanUp() override;
|
||||
|
||||
private:
|
||||
// The NetLog is owned by the browser process, to allow logging from other
|
||||
// threads during shutdown, but is used most frequently on the IOThread.
|
||||
net_log::ChromeNetLog* net_log_;
|
||||
std::unique_ptr<net::URLRequestContext> url_request_context_;
|
||||
net::URLRequestContextGetter* url_request_context_getter_;
|
||||
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(IOThread);
|
||||
};
|
||||
|
||||
} // namespace brightray
|
||||
} // namespace atom
|
||||
|
||||
#endif // BRIGHTRAY_BROWSER_IO_THREAD_H_
|
||||
#endif // ATOM_BROWSER_IO_THREAD_H_
|
||||
@@ -49,11 +49,12 @@ bool JavascriptEnvironment::Initialize() {
|
||||
|
||||
// The V8Platform of gin relies on Chromium's task schedule, which has not
|
||||
// been started at this point, so we have to rely on Node's V8Platform.
|
||||
auto* tracing_controller = new v8::TracingController();
|
||||
node::tracing::TraceEventHelper::SetTracingController(tracing_controller);
|
||||
platform_ = node::CreatePlatform(
|
||||
base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0), nullptr);
|
||||
base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0),
|
||||
tracing_controller);
|
||||
v8::V8::InitializePlatform(platform_);
|
||||
node::tracing::TraceEventHelper::SetTracingController(
|
||||
new v8::TracingController());
|
||||
gin::IsolateHolder::Initialize(
|
||||
gin::IsolateHolder::kNonStrictMode, gin::IsolateHolder::kStableV8Extras,
|
||||
gin::ArrayBufferAllocator::SharedInstance(),
|
||||
|
||||
@@ -32,21 +32,28 @@ namespace atom {
|
||||
|
||||
PowerObserverLinux::PowerObserverLinux()
|
||||
: lock_owner_name_(get_executable_basename()), weak_ptr_factory_(this) {
|
||||
auto* dbus_thread_manager = bluez::DBusThreadManagerLinux::Get();
|
||||
if (dbus_thread_manager) {
|
||||
bus_ = dbus_thread_manager->GetSystemBus();
|
||||
if (bus_) {
|
||||
logind_ = bus_->GetObjectProxy(kLogindServiceName,
|
||||
dbus::ObjectPath(kLogindObjectPath));
|
||||
logind_->WaitForServiceToBeAvailable(
|
||||
base::Bind(&PowerObserverLinux::OnLoginServiceAvailable,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
} else {
|
||||
LOG(WARNING) << "Failed to get system bus connection";
|
||||
}
|
||||
} else {
|
||||
LOG(WARNING) << "DBusThreadManagerLinux instance isn't available";
|
||||
auto* bus = bluez::DBusThreadManagerLinux::Get()->GetSystemBus();
|
||||
if (!bus) {
|
||||
LOG(WARNING) << "Failed to get system bus connection";
|
||||
return;
|
||||
}
|
||||
|
||||
// set up the logind proxy
|
||||
|
||||
const auto weakThis = weak_ptr_factory_.GetWeakPtr();
|
||||
|
||||
logind_ = bus->GetObjectProxy(kLogindServiceName,
|
||||
dbus::ObjectPath(kLogindObjectPath));
|
||||
logind_->ConnectToSignal(
|
||||
kLogindManagerInterface, "PrepareForShutdown",
|
||||
base::BindRepeating(&PowerObserverLinux::OnPrepareForShutdown, weakThis),
|
||||
base::BindRepeating(&PowerObserverLinux::OnSignalConnected, weakThis));
|
||||
logind_->ConnectToSignal(
|
||||
kLogindManagerInterface, "PrepareForSleep",
|
||||
base::BindRepeating(&PowerObserverLinux::OnPrepareForSleep, weakThis),
|
||||
base::BindRepeating(&PowerObserverLinux::OnSignalConnected, weakThis));
|
||||
logind_->WaitForServiceToBeAvailable(base::BindRepeating(
|
||||
&PowerObserverLinux::OnLoginServiceAvailable, weakThis));
|
||||
}
|
||||
|
||||
PowerObserverLinux::~PowerObserverLinux() = default;
|
||||
@@ -56,17 +63,6 @@ void PowerObserverLinux::OnLoginServiceAvailable(bool service_available) {
|
||||
LOG(WARNING) << kLogindServiceName << " not available";
|
||||
return;
|
||||
}
|
||||
// Connect to PrepareForShutdown/PrepareForSleep signals
|
||||
logind_->ConnectToSignal(kLogindManagerInterface, "PrepareForShutdown",
|
||||
base::Bind(&PowerObserverLinux::OnPrepareForShutdown,
|
||||
weak_ptr_factory_.GetWeakPtr()),
|
||||
base::Bind(&PowerObserverLinux::OnSignalConnected,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
logind_->ConnectToSignal(kLogindManagerInterface, "PrepareForSleep",
|
||||
base::Bind(&PowerObserverLinux::OnPrepareForSleep,
|
||||
weak_ptr_factory_.GetWeakPtr()),
|
||||
base::Bind(&PowerObserverLinux::OnSignalConnected,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
// Take sleep inhibit lock
|
||||
BlockSleep();
|
||||
}
|
||||
@@ -80,10 +76,10 @@ void PowerObserverLinux::BlockSleep() {
|
||||
inhibit_writer.AppendString(lock_owner_name_); // who
|
||||
inhibit_writer.AppendString("Application cleanup before suspend"); // why
|
||||
inhibit_writer.AppendString("delay"); // mode
|
||||
logind_->CallMethod(&sleep_inhibit_call,
|
||||
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
|
||||
base::Bind(&PowerObserverLinux::OnInhibitResponse,
|
||||
weak_ptr_factory_.GetWeakPtr(), &sleep_lock_));
|
||||
logind_->CallMethod(
|
||||
&sleep_inhibit_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
|
||||
base::BindOnce(&PowerObserverLinux::OnInhibitResponse,
|
||||
weak_ptr_factory_.GetWeakPtr(), &sleep_lock_));
|
||||
}
|
||||
|
||||
void PowerObserverLinux::UnblockSleep() {
|
||||
@@ -103,8 +99,8 @@ void PowerObserverLinux::BlockShutdown() {
|
||||
inhibit_writer.AppendString("delay"); // mode
|
||||
logind_->CallMethod(
|
||||
&shutdown_inhibit_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
|
||||
base::Bind(&PowerObserverLinux::OnInhibitResponse,
|
||||
weak_ptr_factory_.GetWeakPtr(), &shutdown_lock_));
|
||||
base::BindOnce(&PowerObserverLinux::OnInhibitResponse,
|
||||
weak_ptr_factory_.GetWeakPtr(), &shutdown_lock_));
|
||||
}
|
||||
|
||||
void PowerObserverLinux::UnblockShutdown() {
|
||||
@@ -122,8 +118,10 @@ void PowerObserverLinux::SetShutdownHandler(base::Callback<bool()> handler) {
|
||||
|
||||
void PowerObserverLinux::OnInhibitResponse(base::ScopedFD* scoped_fd,
|
||||
dbus::Response* response) {
|
||||
dbus::MessageReader reader(response);
|
||||
reader.PopFileDescriptor(scoped_fd);
|
||||
if (response != nullptr) {
|
||||
dbus::MessageReader reader(response);
|
||||
reader.PopFileDescriptor(scoped_fd);
|
||||
}
|
||||
}
|
||||
|
||||
void PowerObserverLinux::OnPrepareForSleep(dbus::Signal* signal) {
|
||||
@@ -158,7 +156,7 @@ void PowerObserverLinux::OnPrepareForShutdown(dbus::Signal* signal) {
|
||||
}
|
||||
}
|
||||
|
||||
void PowerObserverLinux::OnSignalConnected(const std::string& interface,
|
||||
void PowerObserverLinux::OnSignalConnected(const std::string& /*interface*/,
|
||||
const std::string& signal,
|
||||
bool success) {
|
||||
LOG_IF(WARNING, !success) << "Failed to connect to " << signal;
|
||||
|
||||
@@ -40,7 +40,6 @@ class PowerObserverLinux : public base::PowerObserver {
|
||||
|
||||
base::Callback<bool()> should_shutdown_;
|
||||
|
||||
scoped_refptr<dbus::Bus> bus_;
|
||||
scoped_refptr<dbus::ObjectProxy> logind_;
|
||||
std::string lock_owner_name_;
|
||||
base::ScopedFD sleep_lock_;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "atom/browser/login_handler.h"
|
||||
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/common/native_mate_converters/net_converter.h"
|
||||
#include "base/values.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
@@ -15,78 +16,75 @@ using content::BrowserThread;
|
||||
namespace atom {
|
||||
|
||||
LoginHandler::LoginHandler(
|
||||
net::AuthChallengeInfo* auth_info,
|
||||
content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
|
||||
const GURL& url,
|
||||
const base::Callback<void(const base::Optional<net::AuthCredentials>&)>&
|
||||
auth_required_callback)
|
||||
: auth_info_(auth_info),
|
||||
web_contents_getter_(web_contents_getter),
|
||||
auth_required_callback_(auth_required_callback) {
|
||||
// Fill request details on IO thread.
|
||||
// TODO(deepak1556): Fill in method and referrer details to
|
||||
// avoid breaking the app login event.
|
||||
net::URLRequest* request,
|
||||
const net::AuthChallengeInfo& auth_info,
|
||||
const net::NetworkDelegate::AuthCallback& callback,
|
||||
net::AuthCredentials* credentials,
|
||||
const content::ResourceRequestInfo* resource_request_info)
|
||||
: credentials_(credentials),
|
||||
auth_info_(&auth_info),
|
||||
auth_callback_(std::move(callback)),
|
||||
weak_factory_(this) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
|
||||
std::unique_ptr<base::DictionaryValue> request_details(
|
||||
new base::DictionaryValue);
|
||||
request_details->SetKey("url", base::Value(url.spec()));
|
||||
FillRequestDetails(request_details.get(), request);
|
||||
|
||||
web_contents_getter_ =
|
||||
resource_request_info->GetWebContentsGetterForRequest();
|
||||
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::UI, FROM_HERE,
|
||||
base::BindOnce(&Browser::RequestLogin, base::Unretained(Browser::Get()),
|
||||
base::RetainedRef(WrapRefCounted(this)),
|
||||
std::move(request_details)));
|
||||
base::RetainedRef(this), std::move(request_details)));
|
||||
}
|
||||
|
||||
LoginHandler::~LoginHandler() {}
|
||||
|
||||
void LoginHandler::Login(const base::string16& username,
|
||||
const base::string16& password) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(&LoginHandler::DoLogin, weak_factory_.GetWeakPtr(),
|
||||
username, password));
|
||||
}
|
||||
|
||||
void LoginHandler::CancelAuth() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(&LoginHandler::DoCancelAuth, weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void LoginHandler::NotifyRequestDestroyed() {
|
||||
auth_callback_.Reset();
|
||||
credentials_ = nullptr;
|
||||
weak_factory_.InvalidateWeakPtrs();
|
||||
}
|
||||
|
||||
content::WebContents* LoginHandler::GetWebContents() const {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
return web_contents_getter_.Run();
|
||||
}
|
||||
|
||||
void LoginHandler::Login(const base::string16& username,
|
||||
const base::string16& password) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
if (TestAndSetAuthHandled())
|
||||
return;
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(&LoginHandler::DoLogin, this, username, password));
|
||||
}
|
||||
|
||||
void LoginHandler::CancelAuth() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
if (TestAndSetAuthHandled())
|
||||
return;
|
||||
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(&LoginHandler::DoCancelAuth, this));
|
||||
}
|
||||
|
||||
void LoginHandler::OnRequestCancelled() {
|
||||
TestAndSetAuthHandled();
|
||||
auth_required_callback_.Reset();
|
||||
}
|
||||
|
||||
// Marks authentication as handled and returns the previous handled state.
|
||||
bool LoginHandler::TestAndSetAuthHandled() {
|
||||
base::AutoLock lock(handled_auth_lock_);
|
||||
bool was_handled = handled_auth_;
|
||||
handled_auth_ = true;
|
||||
return was_handled;
|
||||
}
|
||||
|
||||
void LoginHandler::DoCancelAuth() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
if (!auth_required_callback_.is_null())
|
||||
std::move(auth_required_callback_).Run(base::nullopt);
|
||||
if (!auth_callback_.is_null())
|
||||
std::move(auth_callback_)
|
||||
.Run(net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH);
|
||||
}
|
||||
|
||||
void LoginHandler::DoLogin(const base::string16& username,
|
||||
const base::string16& password) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
if (!auth_required_callback_.is_null()) {
|
||||
std::move(auth_required_callback_)
|
||||
.Run(net::AuthCredentials(username, password));
|
||||
if (!auth_callback_.is_null()) {
|
||||
credentials_->Set(username, password);
|
||||
std::move(auth_callback_)
|
||||
.Run(net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,72 +6,65 @@
|
||||
#define ATOM_BROWSER_LOGIN_HANDLER_H_
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/optional.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/strings/string16.h"
|
||||
#include "base/synchronization/lock.h"
|
||||
#include "content/public/browser/resource_dispatcher_host_login_delegate.h"
|
||||
#include "content/public/browser/resource_request_info.h"
|
||||
#include "net/base/network_delegate.h"
|
||||
|
||||
namespace content {
|
||||
class WebContents;
|
||||
}
|
||||
|
||||
namespace net {
|
||||
class AuthChallengeInfo;
|
||||
class AuthCredentials;
|
||||
} // namespace net
|
||||
|
||||
namespace atom {
|
||||
|
||||
// Handles the HTTP basic auth, must be created on IO thread.
|
||||
class LoginHandler : public content::ResourceDispatcherHostLoginDelegate {
|
||||
class LoginHandler : public base::RefCountedThreadSafe<LoginHandler> {
|
||||
public:
|
||||
LoginHandler(
|
||||
net::AuthChallengeInfo* auth_info,
|
||||
content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
|
||||
const GURL& url,
|
||||
const base::Callback<void(const base::Optional<net::AuthCredentials>&)>&
|
||||
auth_required_callback);
|
||||
LoginHandler(net::URLRequest* request,
|
||||
const net::AuthChallengeInfo& auth_info,
|
||||
const net::NetworkDelegate::AuthCallback& callback,
|
||||
net::AuthCredentials* credentials,
|
||||
const content::ResourceRequestInfo* resource_request_info);
|
||||
|
||||
// The auth is cancelled, must be called on UI thread.
|
||||
void CancelAuth();
|
||||
|
||||
// The URLRequest associated with the auth is destroyed.
|
||||
void NotifyRequestDestroyed();
|
||||
|
||||
// Login with |username| and |password|, must be called on UI thread.
|
||||
void Login(const base::string16& username, const base::string16& password);
|
||||
|
||||
// Returns the WebContents associated with the request, must be called on UI
|
||||
// thread.
|
||||
content::WebContents* GetWebContents() const;
|
||||
|
||||
// The auth is cancelled, must be called on UI thread.
|
||||
void CancelAuth();
|
||||
|
||||
// Login with |username| and |password|, must be called on UI thread.
|
||||
void Login(const base::string16& username, const base::string16& password);
|
||||
|
||||
const net::AuthChallengeInfo* auth_info() const { return auth_info_.get(); }
|
||||
|
||||
protected:
|
||||
~LoginHandler() override;
|
||||
|
||||
// content::ResourceDispatcherHostLoginDelegate:
|
||||
void OnRequestCancelled() override;
|
||||
|
||||
private:
|
||||
friend class base::RefCountedThreadSafe<LoginHandler>;
|
||||
friend class base::DeleteHelper<LoginHandler>;
|
||||
|
||||
~LoginHandler();
|
||||
|
||||
// Must be called on IO thread.
|
||||
void DoCancelAuth();
|
||||
void DoLogin(const base::string16& username, const base::string16& password);
|
||||
|
||||
// Marks authentication as handled and returns the previous handled
|
||||
// state.
|
||||
bool TestAndSetAuthHandled();
|
||||
|
||||
// True if we've handled auth (Login or CancelAuth has been called).
|
||||
bool handled_auth_ = false;
|
||||
mutable base::Lock handled_auth_lock_;
|
||||
// Credentials to be used for the auth.
|
||||
net::AuthCredentials* credentials_;
|
||||
|
||||
// Who/where/what asked for the authentication.
|
||||
scoped_refptr<net::AuthChallengeInfo> auth_info_;
|
||||
scoped_refptr<const net::AuthChallengeInfo> auth_info_;
|
||||
|
||||
// WebContents associated with the login request.
|
||||
content::ResourceRequestInfo::WebContentsGetter web_contents_getter_;
|
||||
|
||||
base::Callback<void(const base::Optional<net::AuthCredentials>&)>
|
||||
auth_required_callback_;
|
||||
// Called with preferred value of net::NetworkDelegate::AuthRequiredResponse.
|
||||
net::NetworkDelegate::AuthCallback auth_callback_;
|
||||
|
||||
base::WeakPtrFactory<LoginHandler> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(LoginHandler);
|
||||
};
|
||||
|
||||
@@ -167,7 +167,7 @@ void FinishTransactionByDate(const std::string& date) {
|
||||
std::string GetReceiptURL() {
|
||||
NSURL* receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
|
||||
if (receiptURL != nil) {
|
||||
return [[receiptURL absoluteString] UTF8String];
|
||||
return std::string([[receiptURL path] UTF8String]);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/native_window_observer.h"
|
||||
@@ -150,6 +151,7 @@ class NativeWindow : public base::SupportsUserData,
|
||||
virtual gfx::NativeView GetNativeView() const = 0;
|
||||
virtual gfx::NativeWindow GetNativeWindow() const = 0;
|
||||
virtual gfx::AcceleratedWidget GetAcceleratedWidget() const = 0;
|
||||
virtual std::tuple<void*, int> GetNativeWindowHandlePointer() const = 0;
|
||||
|
||||
// Taskbar/Dock APIs.
|
||||
enum ProgressState {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/native_window.h"
|
||||
@@ -103,6 +104,7 @@ class NativeWindowMac : public NativeWindow {
|
||||
gfx::NativeView GetNativeView() const override;
|
||||
gfx::NativeWindow GetNativeWindow() const override;
|
||||
gfx::AcceleratedWidget GetAcceleratedWidget() const override;
|
||||
std::tuple<void*, int> GetNativeWindowHandlePointer() const override;
|
||||
void SetProgressBar(double progress, const ProgressState state) override;
|
||||
void SetOverlayIcon(const gfx::Image& overlay,
|
||||
const std::string& description) override;
|
||||
@@ -199,6 +201,7 @@ class NativeWindowMac : public NativeWindow {
|
||||
bool was_maximizable_ = false;
|
||||
bool was_movable_ = false;
|
||||
NSRect original_frame_;
|
||||
NSInteger original_level_;
|
||||
NSUInteger simple_fullscreen_mask_;
|
||||
|
||||
base::scoped_nsobject<NSColor> background_color_before_vibrancy_;
|
||||
|
||||
@@ -74,9 +74,7 @@
|
||||
forStyleMask:NSTitledWindowMask];
|
||||
NSButton* miniaturize_button =
|
||||
[NSWindow standardWindowButton:NSWindowMiniaturizeButton
|
||||
forStyleMask:NSTitledWindowMask];
|
||||
NSButton* zoom_button = [NSWindow standardWindowButton:NSWindowZoomButton
|
||||
forStyleMask:NSTitledWindowMask];
|
||||
forStyleMask:NSWindowStyleMaskTitled];
|
||||
|
||||
CGFloat x = 0;
|
||||
const CGFloat space_between = 20;
|
||||
@@ -89,11 +87,7 @@
|
||||
x += space_between;
|
||||
[self addSubview:miniaturize_button];
|
||||
|
||||
[zoom_button setFrameOrigin:NSMakePoint(x, 0)];
|
||||
x += space_between;
|
||||
[self addSubview:zoom_button];
|
||||
|
||||
const auto last_button_frame = zoom_button.frame;
|
||||
const auto last_button_frame = miniaturize_button.frame;
|
||||
[self setFrameSize:NSMakeSize(last_button_frame.origin.x +
|
||||
last_button_frame.size.width,
|
||||
last_button_frame.size.height)];
|
||||
@@ -339,6 +333,9 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
||||
if (!useStandardWindow || transparent() || !has_frame()) {
|
||||
styleMask |= NSTexturedBackgroundWindowMask;
|
||||
}
|
||||
if (resizable_) {
|
||||
styleMask |= NSResizableWindowMask;
|
||||
}
|
||||
|
||||
// Create views::Widget and assign window_ with it.
|
||||
// TODO(zcbenz): Get rid of the window_ in future.
|
||||
@@ -469,10 +466,14 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
||||
// Default content view.
|
||||
SetContentView(new views::View());
|
||||
AddContentViewLayers();
|
||||
|
||||
original_frame_ = [window_ frame];
|
||||
original_level_ = [window_ level];
|
||||
}
|
||||
|
||||
NativeWindowMac::~NativeWindowMac() {
|
||||
[NSEvent removeMonitor:wheel_event_monitor_];
|
||||
if (wheel_event_monitor_)
|
||||
[NSEvent removeMonitor:wheel_event_monitor_];
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetContentView(views::View* view) {
|
||||
@@ -509,6 +510,18 @@ void NativeWindowMac::Close() {
|
||||
}
|
||||
|
||||
void NativeWindowMac::CloseImmediately() {
|
||||
// Remove event monitor before destroying window, otherwise the monitor may
|
||||
// call its callback after window has been destroyed.
|
||||
if (wheel_event_monitor_) {
|
||||
[NSEvent removeMonitor:wheel_event_monitor_];
|
||||
wheel_event_monitor_ = nil;
|
||||
}
|
||||
|
||||
// Retain the child window before closing it. If the last reference to the
|
||||
// NSWindow goes away inside -[NSWindow close], then bad stuff can happen.
|
||||
// See e.g. http://crbug.com/616701.
|
||||
base::scoped_nsobject<NSWindow> child_window(window_,
|
||||
base::scoped_policy::RETAIN);
|
||||
[window_ close];
|
||||
}
|
||||
|
||||
@@ -580,13 +593,13 @@ bool NativeWindowMac::IsEnabled() {
|
||||
|
||||
void NativeWindowMac::SetEnabled(bool enable) {
|
||||
if (enable) {
|
||||
[window_ endSheet:[window_ attachedSheet]];
|
||||
} else {
|
||||
[window_ beginSheet:window_
|
||||
completionHandler:^(NSModalResponse returnCode) {
|
||||
NSLog(@"modal enabled");
|
||||
return;
|
||||
}];
|
||||
} else {
|
||||
[window_ endSheet:[window_ attachedSheet]];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -859,8 +872,9 @@ void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
|
||||
if (simple_fullscreen && !is_simple_fullscreen_) {
|
||||
is_simple_fullscreen_ = true;
|
||||
|
||||
// Take note of the current window size
|
||||
// Take note of the current window size and level
|
||||
original_frame_ = [window frame];
|
||||
original_level_ = [window level];
|
||||
|
||||
simple_fullscreen_options_ = [NSApp currentSystemPresentationOptions];
|
||||
simple_fullscreen_mask_ = [window styleMask];
|
||||
@@ -877,6 +891,13 @@ void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
|
||||
|
||||
NSRect fullscreenFrame = [window.screen frame];
|
||||
|
||||
// If our app has dock hidden, set the window level higher so another app's
|
||||
// menu bar doesn't appear on top of our fullscreen app.
|
||||
if ([[NSRunningApplication currentApplication] activationPolicy] !=
|
||||
NSApplicationActivationPolicyRegular) {
|
||||
window.level = NSPopUpMenuWindowLevel;
|
||||
}
|
||||
|
||||
if (!fullscreen_window_title()) {
|
||||
// Hide the titlebar
|
||||
SetStyleMask(false, NSTitledWindowMask);
|
||||
@@ -912,6 +933,7 @@ void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
|
||||
}
|
||||
|
||||
[window setFrame:original_frame_ display:YES animate:YES];
|
||||
window.level = original_level_;
|
||||
|
||||
[NSApp setPresentationOptions:simple_fullscreen_options_];
|
||||
|
||||
@@ -1019,6 +1041,9 @@ void NativeWindowMac::SetContentProtection(bool enable) {
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetBrowserView(NativeBrowserView* view) {
|
||||
[CATransaction begin];
|
||||
[CATransaction setDisableActions:YES];
|
||||
|
||||
if (browser_view()) {
|
||||
[browser_view()->GetInspectableWebContentsView()->GetNativeView()
|
||||
removeFromSuperview];
|
||||
@@ -1026,6 +1051,7 @@ void NativeWindowMac::SetBrowserView(NativeBrowserView* view) {
|
||||
}
|
||||
|
||||
if (!view) {
|
||||
[CATransaction commit];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1035,6 +1061,8 @@ void NativeWindowMac::SetBrowserView(NativeBrowserView* view) {
|
||||
positioned:NSWindowAbove
|
||||
relativeTo:nil];
|
||||
native_view.hidden = NO;
|
||||
|
||||
[CATransaction commit];
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetParentWindow(NativeWindow* parent) {
|
||||
@@ -1053,6 +1081,11 @@ gfx::AcceleratedWidget NativeWindowMac::GetAcceleratedWidget() const {
|
||||
return gfx::kNullAcceleratedWidget;
|
||||
}
|
||||
|
||||
std::tuple<void*, int> NativeWindowMac::GetNativeWindowHandlePointer() const {
|
||||
NSView* view = [window_ contentView];
|
||||
return std::make_tuple(static_cast<void*>(view), sizeof(view));
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetProgressBar(double progress,
|
||||
const NativeWindow::ProgressState state) {
|
||||
NSDockTile* dock_tile = [NSApp dockTile];
|
||||
@@ -1296,10 +1329,16 @@ void NativeWindowMac::AddContentViewLayers() {
|
||||
// http://crbug.com/396264. But do not enable it on OS X 10.9 for transparent
|
||||
// window, otherwise a semi-transparent frame would show.
|
||||
if (!(transparent() && base::mac::IsOS10_9()) && !is_modal()) {
|
||||
base::scoped_nsobject<CALayer> background_layer([[CALayer alloc] init]);
|
||||
[background_layer
|
||||
setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable];
|
||||
[[window_ contentView] setLayer:background_layer];
|
||||
// For normal window, we need to explicitly set layer for contentView to
|
||||
// make setBackgroundColor work correctly.
|
||||
// There is no need to do so for frameless window, and doing so would make
|
||||
// titleBarStyle stop working.
|
||||
if (has_frame()) {
|
||||
base::scoped_nsobject<CALayer> background_layer([[CALayer alloc] init]);
|
||||
[background_layer
|
||||
setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable];
|
||||
[[window_ contentView] setLayer:background_layer];
|
||||
}
|
||||
[[window_ contentView] setWantsLayer:YES];
|
||||
}
|
||||
|
||||
@@ -1324,6 +1363,8 @@ void NativeWindowMac::AddContentViewLayers() {
|
||||
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) {
|
||||
buttons_view_.reset(
|
||||
[[CustomWindowButtonView alloc] initWithFrame:NSZeroRect]);
|
||||
// NSWindowStyleMaskFullSizeContentView does not work with zoom button
|
||||
SetFullScreenable(false);
|
||||
[[window_ contentView] addSubview:buttons_view_];
|
||||
} else {
|
||||
if (title_bar_style_ != NORMAL) {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <wrl/client.h>
|
||||
#endif
|
||||
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/api/atom_api_web_contents.h"
|
||||
@@ -342,7 +343,7 @@ bool NativeWindowViews::IsFocused() {
|
||||
void NativeWindowViews::Show() {
|
||||
if (is_modal() && NativeWindow::parent() &&
|
||||
!widget()->native_widget_private()->IsVisible())
|
||||
NativeWindow::parent()->SetEnabled(false);
|
||||
static_cast<NativeWindowViews*>(parent())->IncrementChildModals();
|
||||
|
||||
widget()->native_widget_private()->ShowWithWindowState(GetRestoredState());
|
||||
|
||||
@@ -367,7 +368,7 @@ void NativeWindowViews::ShowInactive() {
|
||||
|
||||
void NativeWindowViews::Hide() {
|
||||
if (is_modal() && NativeWindow::parent())
|
||||
NativeWindow::parent()->SetEnabled(true);
|
||||
static_cast<NativeWindowViews*>(parent())->DecrementChildModals();
|
||||
|
||||
widget()->Hide();
|
||||
|
||||
@@ -391,16 +392,34 @@ bool NativeWindowViews::IsEnabled() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void NativeWindowViews::IncrementChildModals() {
|
||||
num_modal_children_++;
|
||||
SetEnabledInternal(ShouldBeEnabled());
|
||||
}
|
||||
|
||||
void NativeWindowViews::DecrementChildModals() {
|
||||
if (num_modal_children_ > 0) {
|
||||
num_modal_children_--;
|
||||
}
|
||||
SetEnabledInternal(ShouldBeEnabled());
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetEnabled(bool enable) {
|
||||
// Handle multiple calls of SetEnabled correctly.
|
||||
if (enable) {
|
||||
--disable_count_;
|
||||
if (disable_count_ != 0)
|
||||
return;
|
||||
} else {
|
||||
++disable_count_;
|
||||
if (disable_count_ != 1)
|
||||
return;
|
||||
if (enable != is_enabled_) {
|
||||
is_enabled_ = enable;
|
||||
SetEnabledInternal(ShouldBeEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
bool NativeWindowViews::ShouldBeEnabled() {
|
||||
return is_enabled_ && (num_modal_children_ == 0);
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetEnabledInternal(bool enable) {
|
||||
if (enable && IsEnabled()) {
|
||||
return;
|
||||
} else if (!enable && !IsEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
@@ -585,6 +604,7 @@ void NativeWindowViews::SetResizable(bool resizable) {
|
||||
// both the minimum and maximum size to the window size to achieve it.
|
||||
if (resizable) {
|
||||
SetContentSizeConstraints(old_size_constraints_);
|
||||
SetMaximizable(maximizable_);
|
||||
} else {
|
||||
old_size_constraints_ = GetContentSizeConstraints();
|
||||
resizable_ = false;
|
||||
@@ -788,6 +808,7 @@ void NativeWindowViews::SetBackgroundColor(SkColor background_color) {
|
||||
reinterpret_cast<LONG_PTR>(brush));
|
||||
if (previous_brush)
|
||||
DeleteObject((HBRUSH)previous_brush);
|
||||
InvalidateRect(GetAcceleratedWidget(), NULL, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -871,14 +892,17 @@ void NativeWindowViews::SetFocusable(bool focusable) {
|
||||
|
||||
void NativeWindowViews::SetMenu(AtomMenuModel* menu_model) {
|
||||
#if defined(USE_X11)
|
||||
if (menu_model == nullptr)
|
||||
if (menu_model == nullptr) {
|
||||
global_menu_bar_.reset();
|
||||
root_view_->UnregisterAcceleratorsWithFocusManager();
|
||||
}
|
||||
|
||||
if (!global_menu_bar_ && ShouldUseGlobalMenuBar())
|
||||
global_menu_bar_.reset(new GlobalMenuBarX11(this));
|
||||
|
||||
// Use global application menu bar when possible.
|
||||
if (global_menu_bar_ && global_menu_bar_->IsServerStarted()) {
|
||||
root_view_->RegisterAcceleratorsWithFocusManager(menu_model);
|
||||
global_menu_bar_->SetMenu(menu_model);
|
||||
return;
|
||||
}
|
||||
@@ -1023,6 +1047,11 @@ gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() const {
|
||||
return GetNativeWindow()->GetHost()->GetAcceleratedWidget();
|
||||
}
|
||||
|
||||
std::tuple<void*, int> NativeWindowViews::GetNativeWindowHandlePointer() const {
|
||||
gfx::AcceleratedWidget handle = GetAcceleratedWidget();
|
||||
return std::make_tuple(static_cast<void*>(&handle), sizeof(handle));
|
||||
}
|
||||
|
||||
gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(
|
||||
const gfx::Rect& bounds) const {
|
||||
if (!has_frame())
|
||||
@@ -1104,12 +1133,10 @@ void NativeWindowViews::OnWidgetActivationChanged(views::Widget* changed_widget,
|
||||
if (changed_widget != widget())
|
||||
return;
|
||||
|
||||
// Post the notification to next tick.
|
||||
content::BrowserThread::PostTask(
|
||||
content::BrowserThread::UI, FROM_HERE,
|
||||
base::Bind(active ? &NativeWindow::NotifyWindowFocus
|
||||
: &NativeWindow::NotifyWindowBlur,
|
||||
GetWeakPtr()));
|
||||
if (active)
|
||||
NativeWindow::NotifyWindowFocus();
|
||||
else
|
||||
NativeWindow::NotifyWindowBlur();
|
||||
|
||||
// Hide menu bar when window is blured.
|
||||
if (!active && IsMenuBarAutoHide() && IsMenuBarVisible())
|
||||
@@ -1152,10 +1179,10 @@ void NativeWindowViews::OnWidgetBoundsChanged(views::Widget* changed_widget,
|
||||
}
|
||||
|
||||
void NativeWindowViews::DeleteDelegate() {
|
||||
if (is_modal() && NativeWindow::parent()) {
|
||||
auto* parent = NativeWindow::parent();
|
||||
if (is_modal() && this->parent()) {
|
||||
auto* parent = this->parent();
|
||||
// Enable parent window after current window gets closed.
|
||||
parent->SetEnabled(true);
|
||||
static_cast<NativeWindowViews*>(parent)->DecrementChildModals();
|
||||
// Focus on parent window.
|
||||
parent->Focus(true);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
#include "ui/views/widget/widget_observer.h"
|
||||
|
||||
@@ -123,12 +124,16 @@ class NativeWindowViews : public NativeWindow,
|
||||
bool IsVisibleOnAllWorkspaces() override;
|
||||
|
||||
gfx::AcceleratedWidget GetAcceleratedWidget() const override;
|
||||
std::tuple<void*, int> GetNativeWindowHandlePointer() const override;
|
||||
|
||||
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const override;
|
||||
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const override;
|
||||
|
||||
void UpdateDraggableRegions(std::unique_ptr<SkRegion> region);
|
||||
|
||||
void IncrementChildModals();
|
||||
void DecrementChildModals();
|
||||
|
||||
#if defined(OS_WIN)
|
||||
void SetIcon(HICON small_icon, HICON app_icon);
|
||||
#elif defined(USE_X11)
|
||||
@@ -185,6 +190,10 @@ class NativeWindowViews : public NativeWindow,
|
||||
LPARAM l_param);
|
||||
#endif
|
||||
|
||||
// Enable/disable:
|
||||
bool ShouldBeEnabled();
|
||||
void SetEnabledInternal(bool enabled);
|
||||
|
||||
// NativeWindow:
|
||||
void HandleKeyboardEvent(
|
||||
content::WebContents*,
|
||||
@@ -268,8 +277,11 @@ class NativeWindowViews : public NativeWindow,
|
||||
// has to been explicitly provided.
|
||||
std::unique_ptr<SkRegion> draggable_region_; // used in custom drag.
|
||||
|
||||
// How many times the Disable has been called.
|
||||
int disable_count_ = 0;
|
||||
// Whether the window should be enabled based on user calls to SetEnabled()
|
||||
bool is_enabled_ = true;
|
||||
// How many modal children this window has;
|
||||
// used to determine enabled state
|
||||
unsigned int num_modal_children_ = 0;
|
||||
|
||||
bool use_content_size_ = false;
|
||||
bool movable_ = true;
|
||||
|
||||
@@ -7,11 +7,17 @@
|
||||
#include <utility>
|
||||
|
||||
#include "atom/browser/api/atom_api_web_contents.h"
|
||||
#include "atom/browser/login_handler.h"
|
||||
#include "atom/common/native_mate_converters/net_converter.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/resource_request_info.h"
|
||||
#include "net/base/load_flags.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "net/url_request/url_request.h"
|
||||
#include "services/network/throttling/throttling_network_transaction.h"
|
||||
|
||||
@@ -231,7 +237,15 @@ AtomNetworkDelegate::ResponseListenerInfo::ResponseListenerInfo(
|
||||
AtomNetworkDelegate::ResponseListenerInfo::ResponseListenerInfo() = default;
|
||||
AtomNetworkDelegate::ResponseListenerInfo::~ResponseListenerInfo() = default;
|
||||
|
||||
AtomNetworkDelegate::AtomNetworkDelegate() {}
|
||||
AtomNetworkDelegate::AtomNetworkDelegate() {
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
if (command_line->HasSwitch(switches::kIgnoreConnectionsLimit)) {
|
||||
std::string value =
|
||||
command_line->GetSwitchValueASCII(switches::kIgnoreConnectionsLimit);
|
||||
ignore_connections_limit_domains_ = base::SplitString(
|
||||
value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
AtomNetworkDelegate::~AtomNetworkDelegate() {}
|
||||
|
||||
@@ -262,9 +276,17 @@ int AtomNetworkDelegate::OnBeforeURLRequest(
|
||||
net::URLRequest* request,
|
||||
const net::CompletionCallback& callback,
|
||||
GURL* new_url) {
|
||||
if (!base::ContainsKey(response_listeners_, kOnBeforeRequest))
|
||||
return brightray::NetworkDelegate::OnBeforeURLRequest(request, callback,
|
||||
new_url);
|
||||
if (!base::ContainsKey(response_listeners_, kOnBeforeRequest)) {
|
||||
for (const auto& domain : ignore_connections_limit_domains_) {
|
||||
if (request->url().DomainIs(domain)) {
|
||||
// Allow unlimited concurrent connections.
|
||||
request->SetPriority(net::MAXIMUM_PRIORITY);
|
||||
request->SetLoadFlags(request->load_flags() | net::LOAD_IGNORE_LIMITS);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return net::OK;
|
||||
}
|
||||
|
||||
return HandleResponseEvent(kOnBeforeRequest, request, callback, new_url);
|
||||
}
|
||||
@@ -278,8 +300,7 @@ int AtomNetworkDelegate::OnBeforeStartTransaction(
|
||||
kDevToolsEmulateNetworkConditionsClientId,
|
||||
client_id_);
|
||||
if (!base::ContainsKey(response_listeners_, kOnBeforeSendHeaders))
|
||||
return brightray::NetworkDelegate::OnBeforeStartTransaction(
|
||||
request, callback, headers);
|
||||
return net::OK;
|
||||
|
||||
return HandleResponseEvent(kOnBeforeSendHeaders, request, callback, headers,
|
||||
*headers);
|
||||
@@ -288,10 +309,8 @@ int AtomNetworkDelegate::OnBeforeStartTransaction(
|
||||
void AtomNetworkDelegate::OnStartTransaction(
|
||||
net::URLRequest* request,
|
||||
const net::HttpRequestHeaders& headers) {
|
||||
if (!base::ContainsKey(simple_listeners_, kOnSendHeaders)) {
|
||||
brightray::NetworkDelegate::OnStartTransaction(request, headers);
|
||||
if (!base::ContainsKey(simple_listeners_, kOnSendHeaders))
|
||||
return;
|
||||
}
|
||||
|
||||
HandleSimpleEvent(kOnSendHeaders, request, headers);
|
||||
}
|
||||
@@ -303,8 +322,7 @@ int AtomNetworkDelegate::OnHeadersReceived(
|
||||
scoped_refptr<net::HttpResponseHeaders>* override,
|
||||
GURL* allowed) {
|
||||
if (!base::ContainsKey(response_listeners_, kOnHeadersReceived))
|
||||
return brightray::NetworkDelegate::OnHeadersReceived(
|
||||
request, callback, original, override, allowed);
|
||||
return net::OK;
|
||||
|
||||
return HandleResponseEvent(
|
||||
kOnHeadersReceived, request, callback,
|
||||
@@ -313,10 +331,8 @@ int AtomNetworkDelegate::OnHeadersReceived(
|
||||
|
||||
void AtomNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
|
||||
const GURL& new_location) {
|
||||
if (!base::ContainsKey(simple_listeners_, kOnBeforeRedirect)) {
|
||||
brightray::NetworkDelegate::OnBeforeRedirect(request, new_location);
|
||||
if (!base::ContainsKey(simple_listeners_, kOnBeforeRedirect))
|
||||
return;
|
||||
}
|
||||
|
||||
HandleSimpleEvent(kOnBeforeRedirect, request, new_location,
|
||||
request->response_headers(), request->GetSocketAddress(),
|
||||
@@ -325,10 +341,8 @@ void AtomNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
|
||||
|
||||
void AtomNetworkDelegate::OnResponseStarted(net::URLRequest* request,
|
||||
int net_error) {
|
||||
if (!base::ContainsKey(simple_listeners_, kOnResponseStarted)) {
|
||||
brightray::NetworkDelegate::OnResponseStarted(request, net_error);
|
||||
if (!base::ContainsKey(simple_listeners_, kOnResponseStarted))
|
||||
return;
|
||||
}
|
||||
|
||||
if (request->status().status() != net::URLRequestStatus::SUCCESS)
|
||||
return;
|
||||
@@ -346,33 +360,109 @@ void AtomNetworkDelegate::OnCompleted(net::URLRequest* request, bool started) {
|
||||
// Error event.
|
||||
OnErrorOccurred(request, started);
|
||||
return;
|
||||
} else if (request->response_headers() &&
|
||||
net::HttpResponseHeaders::IsRedirectResponseCode(
|
||||
request->response_headers()->response_code())) {
|
||||
}
|
||||
|
||||
if (request->response_headers() &&
|
||||
net::HttpResponseHeaders::IsRedirectResponseCode(
|
||||
request->response_headers()->response_code())) {
|
||||
// Redirect event.
|
||||
brightray::NetworkDelegate::OnCompleted(request, started);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!base::ContainsKey(simple_listeners_, kOnCompleted)) {
|
||||
brightray::NetworkDelegate::OnCompleted(request, started);
|
||||
if (!base::ContainsKey(simple_listeners_, kOnCompleted))
|
||||
return;
|
||||
}
|
||||
|
||||
HandleSimpleEvent(kOnCompleted, request, request->response_headers(),
|
||||
request->was_cached());
|
||||
}
|
||||
|
||||
void AtomNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
|
||||
const auto& it = login_handler_map_.find(request->identifier());
|
||||
if (it != login_handler_map_.end()) {
|
||||
it->second->NotifyRequestDestroyed();
|
||||
it->second = nullptr;
|
||||
login_handler_map_.erase(it);
|
||||
}
|
||||
callbacks_.erase(request->identifier());
|
||||
}
|
||||
|
||||
net::NetworkDelegate::AuthRequiredResponse AtomNetworkDelegate::OnAuthRequired(
|
||||
net::URLRequest* request,
|
||||
const net::AuthChallengeInfo& auth_info,
|
||||
const AuthCallback& callback,
|
||||
net::AuthCredentials* credentials) {
|
||||
auto* resource_request_info =
|
||||
content::ResourceRequestInfo::ForRequest(request);
|
||||
if (!resource_request_info)
|
||||
return AUTH_REQUIRED_RESPONSE_NO_ACTION;
|
||||
login_handler_map_.emplace(
|
||||
request->identifier(),
|
||||
new LoginHandler(request, auth_info, std::move(callback), credentials,
|
||||
resource_request_info));
|
||||
return AUTH_REQUIRED_RESPONSE_IO_PENDING;
|
||||
}
|
||||
|
||||
bool AtomNetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
|
||||
const net::CookieList& cookie_list) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AtomNetworkDelegate::OnCanSetCookie(
|
||||
const net::URLRequest& request,
|
||||
const net::CanonicalCookie& cookie_line,
|
||||
net::CookieOptions* options) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AtomNetworkDelegate::OnCanAccessFile(
|
||||
const net::URLRequest& request,
|
||||
const base::FilePath& original_path,
|
||||
const base::FilePath& absolute_path) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AtomNetworkDelegate::OnCanEnablePrivacyMode(
|
||||
const GURL& url,
|
||||
const GURL& first_party_for_cookies) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AtomNetworkDelegate::OnAreExperimentalCookieFeaturesEnabled() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AtomNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader(
|
||||
const net::URLRequest& request,
|
||||
const GURL& target_url,
|
||||
const GURL& referrer_url) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO(deepak1556) : Enable after hooking into the reporting service
|
||||
// https://crbug.com/704259
|
||||
bool AtomNetworkDelegate::OnCanQueueReportingReport(
|
||||
const url::Origin& origin) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void AtomNetworkDelegate::OnCanSendReportingReports(
|
||||
std::set<url::Origin> origins,
|
||||
base::OnceCallback<void(std::set<url::Origin>)> result_callback) const {}
|
||||
|
||||
bool AtomNetworkDelegate::OnCanSetReportingClient(const url::Origin& origin,
|
||||
const GURL& endpoint) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AtomNetworkDelegate::OnCanUseReportingClient(const url::Origin& origin,
|
||||
const GURL& endpoint) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void AtomNetworkDelegate::OnErrorOccurred(net::URLRequest* request,
|
||||
bool started) {
|
||||
if (!base::ContainsKey(simple_listeners_, kOnErrorOccurred)) {
|
||||
brightray::NetworkDelegate::OnCompleted(request, started);
|
||||
if (!base::ContainsKey(simple_listeners_, kOnErrorOccurred))
|
||||
return;
|
||||
}
|
||||
|
||||
HandleSimpleEvent(kOnErrorOccurred, request, request->was_cached(),
|
||||
request->status());
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/synchronization/lock.h"
|
||||
#include "base/values.h"
|
||||
#include "brightray/browser/network_delegate.h"
|
||||
#include "content/public/browser/resource_request_info.h"
|
||||
#include "extensions/common/url_pattern.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "net/base/network_delegate.h"
|
||||
#include "net/http/http_request_headers.h"
|
||||
#include "net/http/http_response_headers.h"
|
||||
|
||||
@@ -27,7 +27,9 @@ using URLPatterns = std::set<URLPattern>;
|
||||
|
||||
const char* ResourceTypeToString(content::ResourceType type);
|
||||
|
||||
class AtomNetworkDelegate : public brightray::NetworkDelegate {
|
||||
class LoginHandler;
|
||||
|
||||
class AtomNetworkDelegate : public net::NetworkDelegate {
|
||||
public:
|
||||
using ResponseCallback = base::Callback<void(const base::DictionaryValue&)>;
|
||||
using SimpleListener = base::Callback<void(const base::DictionaryValue&)>;
|
||||
@@ -86,6 +88,10 @@ class AtomNetworkDelegate : public brightray::NetworkDelegate {
|
||||
int OnBeforeStartTransaction(net::URLRequest* request,
|
||||
const net::CompletionCallback& callback,
|
||||
net::HttpRequestHeaders* headers) override;
|
||||
void OnBeforeSendHeaders(net::URLRequest* request,
|
||||
const net::ProxyInfo& proxy_info,
|
||||
const net::ProxyRetryInfoMap& proxy_retry_info,
|
||||
net::HttpRequestHeaders* headers) override {}
|
||||
void OnStartTransaction(net::URLRequest* request,
|
||||
const net::HttpRequestHeaders& headers) override;
|
||||
int OnHeadersReceived(
|
||||
@@ -97,8 +103,43 @@ class AtomNetworkDelegate : public brightray::NetworkDelegate {
|
||||
void OnBeforeRedirect(net::URLRequest* request,
|
||||
const GURL& new_location) override;
|
||||
void OnResponseStarted(net::URLRequest* request, int net_error) override;
|
||||
void OnNetworkBytesReceived(net::URLRequest* request,
|
||||
int64_t bytes_read) override {}
|
||||
void OnNetworkBytesSent(net::URLRequest* request,
|
||||
int64_t bytes_sent) override {}
|
||||
void OnCompleted(net::URLRequest* request, bool started) override;
|
||||
void OnURLRequestDestroyed(net::URLRequest* request) override;
|
||||
void OnPACScriptError(int line_number, const base::string16& error) override {
|
||||
}
|
||||
AuthRequiredResponse OnAuthRequired(
|
||||
net::URLRequest* request,
|
||||
const net::AuthChallengeInfo& auth_info,
|
||||
const AuthCallback& callback,
|
||||
net::AuthCredentials* credentials) override;
|
||||
bool OnCanGetCookies(const net::URLRequest& request,
|
||||
const net::CookieList& cookie_list) override;
|
||||
bool OnCanSetCookie(const net::URLRequest& request,
|
||||
const net::CanonicalCookie& cookie_line,
|
||||
net::CookieOptions* options) override;
|
||||
bool OnCanAccessFile(const net::URLRequest& request,
|
||||
const base::FilePath& original_path,
|
||||
const base::FilePath& absolute_path) const override;
|
||||
bool OnCanEnablePrivacyMode(
|
||||
const GURL& url,
|
||||
const GURL& first_party_for_cookies) const override;
|
||||
bool OnAreExperimentalCookieFeaturesEnabled() const override;
|
||||
bool OnCancelURLRequestWithPolicyViolatingReferrerHeader(
|
||||
const net::URLRequest& request,
|
||||
const GURL& target_url,
|
||||
const GURL& referrer_url) const override;
|
||||
bool OnCanQueueReportingReport(const url::Origin& origin) const override;
|
||||
void OnCanSendReportingReports(std::set<url::Origin> origins,
|
||||
base::OnceCallback<void(std::set<url::Origin>)>
|
||||
result_callback) const override;
|
||||
bool OnCanSetReportingClient(const url::Origin& origin,
|
||||
const GURL& endpoint) const override;
|
||||
bool OnCanUseReportingClient(const url::Origin& origin,
|
||||
const GURL& endpoint) const override;
|
||||
|
||||
private:
|
||||
void OnErrorOccurred(net::URLRequest* request, bool started);
|
||||
@@ -124,9 +165,11 @@ class AtomNetworkDelegate : public brightray::NetworkDelegate {
|
||||
T out,
|
||||
const base::DictionaryValue& response);
|
||||
|
||||
std::map<uint64_t, scoped_refptr<LoginHandler>> login_handler_map_;
|
||||
std::map<SimpleEvent, SimpleListenerInfo> simple_listeners_;
|
||||
std::map<ResponseEvent, ResponseListenerInfo> response_listeners_;
|
||||
std::map<uint64_t, net::CompletionCallback> callbacks_;
|
||||
std::vector<std::string> ignore_connections_limit_domains_;
|
||||
|
||||
// Client id for devtools network emulation.
|
||||
std::string client_id_;
|
||||
|
||||
@@ -69,12 +69,9 @@ scoped_refptr<AtomURLRequest> AtomURLRequest::Create(
|
||||
if (!browser_context || url.empty() || !delegate) {
|
||||
return nullptr;
|
||||
}
|
||||
scoped_refptr<brightray::URLRequestContextGetter> request_context_getter(
|
||||
browser_context->url_request_context_getter());
|
||||
scoped_refptr<net::URLRequestContextGetter> request_context_getter(
|
||||
browser_context->GetRequestContext());
|
||||
DCHECK(request_context_getter);
|
||||
if (!request_context_getter) {
|
||||
return nullptr;
|
||||
}
|
||||
scoped_refptr<AtomURLRequest> atom_url_request(new AtomURLRequest(delegate));
|
||||
if (content::BrowserThread::PostTask(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
@@ -504,4 +501,16 @@ void AtomURLRequest::InformDelegateErrorOccured(const std::string& error,
|
||||
delegate_->OnError(error, isRequestError);
|
||||
}
|
||||
|
||||
void AtomURLRequest::GetUploadProgress(mate::Dictionary* progress) const {
|
||||
net::UploadProgress upload_progress;
|
||||
if (request_) {
|
||||
progress->Set("started", true);
|
||||
upload_progress = request_->GetUploadProgress();
|
||||
} else {
|
||||
progress->Set("started", false);
|
||||
}
|
||||
progress->Set("current", upload_progress.position());
|
||||
progress->Set("total", upload_progress.size());
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -43,6 +43,7 @@ class AtomURLRequest : public base::RefCountedThreadSafe<AtomURLRequest>,
|
||||
void PassLoginInformation(const base::string16& username,
|
||||
const base::string16& password) const;
|
||||
void SetLoadFlags(int flags) const;
|
||||
void GetUploadProgress(mate::Dictionary* progress) const;
|
||||
|
||||
protected:
|
||||
// Overrides of net::URLRequest::Delegate
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "atom/browser/net/atom_url_request_job_factory.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
@@ -33,6 +35,11 @@ AtomURLRequestJobFactory::~AtomURLRequestJobFactory() {
|
||||
Clear();
|
||||
}
|
||||
|
||||
void AtomURLRequestJobFactory::Chain(
|
||||
std::unique_ptr<net::URLRequestJobFactory> job_factory) {
|
||||
job_factory_ = std::move(job_factory);
|
||||
}
|
||||
|
||||
bool AtomURLRequestJobFactory::SetProtocolHandler(
|
||||
const std::string& scheme,
|
||||
std::unique_ptr<ProtocolHandler> protocol_handler) {
|
||||
@@ -73,16 +80,6 @@ bool AtomURLRequestJobFactory::UninterceptProtocol(const std::string& scheme) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ProtocolHandler* AtomURLRequestJobFactory::GetProtocolHandler(
|
||||
const std::string& scheme) const {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
|
||||
auto it = protocol_handler_map_.find(scheme);
|
||||
if (it == protocol_handler_map_.end())
|
||||
return nullptr;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
bool AtomURLRequestJobFactory::HasProtocolHandler(
|
||||
const std::string& scheme) const {
|
||||
return base::ContainsKey(protocol_handler_map_, scheme);
|
||||
@@ -101,11 +98,18 @@ net::URLRequestJob* AtomURLRequestJobFactory::MaybeCreateJobWithProtocolHandler(
|
||||
net::NetworkDelegate* network_delegate) const {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
|
||||
auto* job = job_factory_->MaybeCreateJobWithProtocolHandler(scheme, request,
|
||||
network_delegate);
|
||||
if (job)
|
||||
return job;
|
||||
|
||||
auto it = protocol_handler_map_.find(scheme);
|
||||
if (it == protocol_handler_map_.end())
|
||||
return nullptr;
|
||||
|
||||
if (request->GetUserData(DisableProtocolInterceptFlagKey()))
|
||||
return nullptr;
|
||||
|
||||
return it->second->MaybeCreateJob(request, network_delegate);
|
||||
}
|
||||
|
||||
@@ -113,13 +117,14 @@ net::URLRequestJob* AtomURLRequestJobFactory::MaybeInterceptRedirect(
|
||||
net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate,
|
||||
const GURL& location) const {
|
||||
return nullptr;
|
||||
return job_factory_->MaybeInterceptRedirect(request, network_delegate,
|
||||
location);
|
||||
}
|
||||
|
||||
net::URLRequestJob* AtomURLRequestJobFactory::MaybeInterceptResponse(
|
||||
net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate) const {
|
||||
return nullptr;
|
||||
return job_factory_->MaybeInterceptResponse(request, network_delegate);
|
||||
}
|
||||
|
||||
bool AtomURLRequestJobFactory::IsHandledProtocol(
|
||||
|
||||
@@ -23,6 +23,9 @@ class AtomURLRequestJobFactory : public net::URLRequestJobFactory {
|
||||
AtomURLRequestJobFactory();
|
||||
~AtomURLRequestJobFactory() override;
|
||||
|
||||
// Requests are forwarded to the chained job factory first.
|
||||
void Chain(std::unique_ptr<net::URLRequestJobFactory> job_factory);
|
||||
|
||||
// Sets the ProtocolHandler for a scheme. Returns true on success, false on
|
||||
// failure (a ProtocolHandler already exists for |scheme|). On success,
|
||||
// URLRequestJobFactory takes ownership of |protocol_handler|.
|
||||
@@ -34,9 +37,6 @@ class AtomURLRequestJobFactory : public net::URLRequestJobFactory {
|
||||
std::unique_ptr<ProtocolHandler> protocol_handler);
|
||||
bool UninterceptProtocol(const std::string& scheme);
|
||||
|
||||
// Returns the protocol handler registered with scheme.
|
||||
ProtocolHandler* GetProtocolHandler(const std::string& scheme) const;
|
||||
|
||||
// Whether the protocol handler is registered by the job factory.
|
||||
bool HasProtocolHandler(const std::string& scheme) const;
|
||||
|
||||
@@ -69,6 +69,8 @@ class AtomURLRequestJobFactory : public net::URLRequestJobFactory {
|
||||
// Can only be accessed in IO thread.
|
||||
OriginalProtocolsMap original_protocols_;
|
||||
|
||||
std::unique_ptr<net::URLRequestJobFactory> job_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomURLRequestJobFactory);
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,11 @@
|
||||
#define ATOM_BROWSER_NET_COOKIE_DETAILS_H_
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "net/cookies/cookie_change_dispatcher.h"
|
||||
#include "services/network/public/mojom/cookie_manager.mojom.h"
|
||||
|
||||
namespace net {
|
||||
class CanonicalCookie;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
@@ -14,12 +18,12 @@ struct CookieDetails {
|
||||
public:
|
||||
CookieDetails(const net::CanonicalCookie* cookie_copy,
|
||||
bool is_removed,
|
||||
net::CookieChangeCause cause)
|
||||
network::mojom::CookieChangeCause cause)
|
||||
: cookie(cookie_copy), removed(is_removed), cause(cause) {}
|
||||
|
||||
const net::CanonicalCookie* cookie;
|
||||
bool removed;
|
||||
net::CookieChangeCause cause;
|
||||
network::mojom::CookieChangeCause cause;
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
87
atom/browser/net/resolve_proxy_helper.cc
Normal file
87
atom/browser/net/resolve_proxy_helper.cc
Normal file
@@ -0,0 +1,87 @@
|
||||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/net/resolve_proxy_helper.h"
|
||||
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
#include "net/url_request/url_request_context_getter.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
ResolveProxyHelper::ResolveProxyHelper(AtomBrowserContext* browser_context)
|
||||
: context_getter_(browser_context->GetRequestContext()),
|
||||
original_thread_(base::ThreadTaskRunnerHandle::Get()) {}
|
||||
|
||||
ResolveProxyHelper::~ResolveProxyHelper() {
|
||||
// Clear all pending requests if the ProxyService is still alive.
|
||||
pending_requests_.clear();
|
||||
}
|
||||
|
||||
void ResolveProxyHelper::ResolveProxy(const GURL& url,
|
||||
const ResolveProxyCallback& callback) {
|
||||
// Enqueue the pending request.
|
||||
pending_requests_.push_back(PendingRequest(url, callback));
|
||||
|
||||
// If nothing is in progress, start.
|
||||
if (pending_requests_.size() == 1)
|
||||
StartPendingRequest();
|
||||
}
|
||||
|
||||
void ResolveProxyHelper::StartPendingRequest() {
|
||||
auto& pending_request = pending_requests_.front();
|
||||
context_getter_->GetNetworkTaskRunner()->PostTask(
|
||||
FROM_HERE, base::BindOnce(&ResolveProxyHelper::StartPendingRequestInIO,
|
||||
base::Unretained(this), pending_request.url));
|
||||
}
|
||||
|
||||
void ResolveProxyHelper::StartPendingRequestInIO(const GURL& url) {
|
||||
auto* proxy_service =
|
||||
context_getter_->GetURLRequestContext()->proxy_resolution_service();
|
||||
// Start the request.
|
||||
int result = proxy_service->ResolveProxy(
|
||||
url, std::string(), &proxy_info_,
|
||||
base::Bind(&ResolveProxyHelper::OnProxyResolveComplete,
|
||||
base::RetainedRef(this)),
|
||||
nullptr, nullptr, net::NetLogWithSource());
|
||||
// Completed synchronously.
|
||||
if (result != net::ERR_IO_PENDING)
|
||||
OnProxyResolveComplete(result);
|
||||
}
|
||||
|
||||
void ResolveProxyHelper::OnProxyResolveComplete(int result) {
|
||||
DCHECK(!pending_requests_.empty());
|
||||
|
||||
std::string proxy;
|
||||
if (result == net::OK)
|
||||
proxy = proxy_info_.ToPacString();
|
||||
|
||||
original_thread_->PostTask(
|
||||
FROM_HERE, base::BindOnce(&ResolveProxyHelper::SendProxyResult,
|
||||
base::RetainedRef(this), proxy));
|
||||
}
|
||||
|
||||
void ResolveProxyHelper::SendProxyResult(const std::string& proxy) {
|
||||
DCHECK(!pending_requests_.empty());
|
||||
|
||||
const auto& completed_request = pending_requests_.front();
|
||||
if (!completed_request.callback.is_null())
|
||||
completed_request.callback.Run(proxy);
|
||||
|
||||
// Clear the current (completed) request.
|
||||
pending_requests_.pop_front();
|
||||
|
||||
// Start the next request.
|
||||
if (!pending_requests_.empty())
|
||||
StartPendingRequest();
|
||||
}
|
||||
|
||||
ResolveProxyHelper::PendingRequest::PendingRequest(
|
||||
const GURL& url,
|
||||
const ResolveProxyCallback& callback)
|
||||
: url(url), callback(callback) {}
|
||||
|
||||
} // namespace atom
|
||||
61
atom/browser/net/resolve_proxy_helper.h
Normal file
61
atom/browser/net/resolve_proxy_helper.h
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_NET_RESOLVE_PROXY_HELPER_H_
|
||||
#define ATOM_BROWSER_NET_RESOLVE_PROXY_HELPER_H_
|
||||
|
||||
#include <deque>
|
||||
#include <string>
|
||||
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "net/proxy_resolution/proxy_service.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
namespace net {
|
||||
class URLRequestContextGetter;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomBrowserContext;
|
||||
|
||||
class ResolveProxyHelper
|
||||
: public base::RefCountedThreadSafe<ResolveProxyHelper> {
|
||||
public:
|
||||
using ResolveProxyCallback = base::Callback<void(std::string)>;
|
||||
|
||||
explicit ResolveProxyHelper(AtomBrowserContext* browser_context);
|
||||
|
||||
void ResolveProxy(const GURL& url, const ResolveProxyCallback& callback);
|
||||
|
||||
private:
|
||||
friend class base::RefCountedThreadSafe<ResolveProxyHelper>;
|
||||
// A PendingRequest is a resolve request that is in progress, or queued.
|
||||
struct PendingRequest {
|
||||
public:
|
||||
PendingRequest(const GURL& url, const ResolveProxyCallback& callback);
|
||||
|
||||
GURL url;
|
||||
ResolveProxyCallback callback;
|
||||
};
|
||||
|
||||
~ResolveProxyHelper();
|
||||
|
||||
// Starts the first pending request.
|
||||
void StartPendingRequest();
|
||||
void StartPendingRequestInIO(const GURL& url);
|
||||
void OnProxyResolveComplete(int result);
|
||||
void SendProxyResult(const std::string& proxy);
|
||||
|
||||
net::ProxyInfo proxy_info_;
|
||||
std::deque<PendingRequest> pending_requests_;
|
||||
scoped_refptr<net::URLRequestContextGetter> context_getter_;
|
||||
scoped_refptr<base::SingleThreadTaskRunner> original_thread_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ResolveProxyHelper);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_NET_RESOLVE_PROXY_HELPER_H_
|
||||
424
atom/browser/net/url_request_context_getter.cc
Normal file
424
atom/browser/net/url_request_context_getter.cc
Normal file
@@ -0,0 +1,424 @@
|
||||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/net/url_request_context_getter.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "atom/browser/api/atom_api_protocol.h"
|
||||
#include "atom/browser/atom_browser_client.h"
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/net/about_protocol_handler.h"
|
||||
#include "atom/browser/net/asar/asar_protocol_handler.h"
|
||||
#include "atom/browser/net/atom_cert_verifier.h"
|
||||
#include "atom/browser/net/atom_network_delegate.h"
|
||||
#include "atom/browser/net/atom_url_request_job_factory.h"
|
||||
#include "atom/browser/net/http_protocol_handler.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/task_scheduler/post_task.h"
|
||||
#include "brightray/browser/net/require_ct_delegate.h"
|
||||
#include "chrome/browser/net/chrome_mojo_proxy_resolver_factory.h"
|
||||
#include "chrome/common/chrome_constants.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/network_session_configurator/common/network_switches.h"
|
||||
#include "components/prefs/value_map_pref_store.h"
|
||||
#include "components/proxy_config/proxy_config_dictionary.h"
|
||||
#include "components/proxy_config/proxy_config_pref_names.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/devtools_network_transaction_factory.h"
|
||||
#include "content/public/browser/network_service_instance.h"
|
||||
#include "content/public/browser/resource_context.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "net/base/host_mapping_rules.h"
|
||||
#include "net/cert/multi_log_ct_verifier.h"
|
||||
#include "net/cookies/cookie_monster.h"
|
||||
#include "net/dns/mapped_host_resolver.h"
|
||||
#include "net/http/http_auth_handler_factory.h"
|
||||
#include "net/http/http_auth_preferences.h"
|
||||
#include "net/http/http_auth_scheme.h"
|
||||
#include "net/http/http_transaction_factory.h"
|
||||
#include "net/log/net_log.h"
|
||||
#include "net/proxy_resolution/proxy_config.h"
|
||||
#include "net/proxy_resolution/proxy_config_service.h"
|
||||
#include "net/proxy_resolution/proxy_service.h"
|
||||
#include "net/traffic_annotation/network_traffic_annotation.h"
|
||||
#include "net/url_request/data_protocol_handler.h"
|
||||
#include "net/url_request/static_http_user_agent_settings.h"
|
||||
#include "net/url_request/url_request_intercepting_job_factory.h"
|
||||
#include "net/url_request/url_request_job_factory_impl.h"
|
||||
#include "services/network/ignore_errors_cert_verifier.h"
|
||||
#include "services/network/network_service.h"
|
||||
#include "services/network/public/cpp/network_switches.h"
|
||||
#include "services/network/url_request_context_builder_mojo.h"
|
||||
#include "url/url_constants.h"
|
||||
|
||||
#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
|
||||
#include "net/url_request/ftp_protocol_handler.h"
|
||||
#endif
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
|
||||
network::mojom::NetworkContextParamsPtr CreateDefaultNetworkContextParams(
|
||||
const base::FilePath& base_path,
|
||||
const std::string& user_agent,
|
||||
bool in_memory,
|
||||
bool use_cache,
|
||||
int max_cache_size) {
|
||||
network::mojom::NetworkContextParamsPtr network_context_params =
|
||||
network::mojom::NetworkContextParams::New();
|
||||
network_context_params->enable_brotli = true;
|
||||
network_context_params->user_agent = user_agent;
|
||||
network_context_params->http_cache_enabled = use_cache;
|
||||
network_context_params->enable_data_url_support = false;
|
||||
network_context_params->proxy_resolver_factory =
|
||||
ChromeMojoProxyResolverFactory::CreateWithStrongBinding().PassInterface();
|
||||
if (!in_memory) {
|
||||
network_context_params->http_cache_path =
|
||||
base_path.Append(chrome::kCacheDirname);
|
||||
network_context_params->http_cache_max_size = max_cache_size;
|
||||
network_context_params->http_server_properties_path =
|
||||
base_path.Append(chrome::kNetworkPersistentStateFilename);
|
||||
network_context_params->cookie_path =
|
||||
base_path.Append(chrome::kCookieFilename);
|
||||
network_context_params->channel_id_path =
|
||||
base_path.Append(chrome::kChannelIDFilename);
|
||||
network_context_params->restore_old_session_cookies = false;
|
||||
network_context_params->persist_session_cookies = false;
|
||||
}
|
||||
// TODO(deepak1556): Decide the stand on chrome ct policy and
|
||||
// enable it.
|
||||
// See //net/docs/certificate-transparency.md
|
||||
// network_context_params->enforce_chrome_ct_policy = true;
|
||||
return network_context_params;
|
||||
}
|
||||
|
||||
void SetupAtomURLRequestJobFactory(
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
net::URLRequestContext* url_request_context,
|
||||
AtomURLRequestJobFactory* job_factory) {
|
||||
for (auto& protocol_handler : *protocol_handlers) {
|
||||
job_factory->SetProtocolHandler(
|
||||
protocol_handler.first,
|
||||
base::WrapUnique(protocol_handler.second.release()));
|
||||
}
|
||||
protocol_handlers->clear();
|
||||
|
||||
job_factory->SetProtocolHandler(url::kAboutScheme,
|
||||
std::make_unique<AboutProtocolHandler>());
|
||||
job_factory->SetProtocolHandler(url::kDataScheme,
|
||||
std::make_unique<net::DataProtocolHandler>());
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kFileScheme,
|
||||
std::make_unique<asar::AsarProtocolHandler>(
|
||||
base::CreateTaskRunnerWithTraits(
|
||||
{base::MayBlock(), base::TaskPriority::USER_BLOCKING,
|
||||
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kHttpScheme,
|
||||
std::make_unique<HttpProtocolHandler>(url::kHttpScheme));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kHttpsScheme,
|
||||
std::make_unique<HttpProtocolHandler>(url::kHttpsScheme));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kWsScheme, std::make_unique<HttpProtocolHandler>(url::kWsScheme));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kWssScheme, std::make_unique<HttpProtocolHandler>(url::kWssScheme));
|
||||
|
||||
#if !BUILDFLAG(DISABLE_FTP_SUPPORT)
|
||||
auto* host_resolver = url_request_context->host_resolver();
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kFtpScheme, net::FtpProtocolHandler::Create(host_resolver));
|
||||
#endif
|
||||
}
|
||||
|
||||
void ApplyProxyModeFromCommandLine(ValueMapPrefStore* pref_store) {
|
||||
if (!pref_store)
|
||||
return;
|
||||
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
|
||||
if (command_line->HasSwitch(::switches::kNoProxyServer)) {
|
||||
pref_store->SetValue(proxy_config::prefs::kProxy,
|
||||
ProxyConfigDictionary::CreateDirect(),
|
||||
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
||||
} else if (command_line->HasSwitch(::switches::kProxyPacUrl)) {
|
||||
std::string pac_script_url =
|
||||
command_line->GetSwitchValueASCII(::switches::kProxyPacUrl);
|
||||
pref_store->SetValue(proxy_config::prefs::kProxy,
|
||||
ProxyConfigDictionary::CreatePacScript(
|
||||
pac_script_url, false /* pac_mandatory */),
|
||||
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
||||
} else if (command_line->HasSwitch(::switches::kProxyAutoDetect)) {
|
||||
pref_store->SetValue(proxy_config::prefs::kProxy,
|
||||
ProxyConfigDictionary::CreateAutoDetect(),
|
||||
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
||||
} else if (command_line->HasSwitch(::switches::kProxyServer)) {
|
||||
std::string proxy_server =
|
||||
command_line->GetSwitchValueASCII(::switches::kProxyServer);
|
||||
std::string bypass_list =
|
||||
command_line->GetSwitchValueASCII(::switches::kProxyBypassList);
|
||||
pref_store->SetValue(
|
||||
proxy_config::prefs::kProxy,
|
||||
ProxyConfigDictionary::CreateFixedServers(proxy_server, bypass_list),
|
||||
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class ResourceContext : public content::ResourceContext {
|
||||
public:
|
||||
ResourceContext() = default;
|
||||
~ResourceContext() override = default;
|
||||
|
||||
net::HostResolver* GetHostResolver() override {
|
||||
if (request_context_)
|
||||
return request_context_->host_resolver();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
net::URLRequestContext* GetRequestContext() override {
|
||||
return request_context_;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class URLRequestContextGetter;
|
||||
|
||||
net::URLRequestContext* request_context_ = nullptr;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ResourceContext);
|
||||
};
|
||||
|
||||
URLRequestContextGetter::Handle::Handle(
|
||||
base::WeakPtr<AtomBrowserContext> browser_context)
|
||||
: resource_context_(new ResourceContext),
|
||||
browser_context_(browser_context),
|
||||
initialized_(false) {}
|
||||
|
||||
URLRequestContextGetter::Handle::~Handle() {}
|
||||
|
||||
content::ResourceContext*
|
||||
URLRequestContextGetter::Handle::GetResourceContext() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
LazyInitialize();
|
||||
return resource_context_.get();
|
||||
}
|
||||
|
||||
scoped_refptr<URLRequestContextGetter>
|
||||
URLRequestContextGetter::Handle::CreateMainRequestContextGetter(
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::URLRequestInterceptorScopedVector protocol_interceptors) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
DCHECK(!main_request_context_getter_.get());
|
||||
LazyInitialize();
|
||||
main_request_context_getter_ = new URLRequestContextGetter(
|
||||
AtomBrowserClient::Get()->GetNetLog(), this, protocol_handlers,
|
||||
std::move(protocol_interceptors));
|
||||
return main_request_context_getter_;
|
||||
}
|
||||
|
||||
scoped_refptr<URLRequestContextGetter>
|
||||
URLRequestContextGetter::Handle::GetMainRequestContextGetter() {
|
||||
return main_request_context_getter_;
|
||||
}
|
||||
|
||||
network::mojom::NetworkContextPtr
|
||||
URLRequestContextGetter::Handle::GetNetworkContext() {
|
||||
if (!main_network_context_) {
|
||||
main_network_context_request_ = mojo::MakeRequest(&main_network_context_);
|
||||
}
|
||||
return std::move(main_network_context_);
|
||||
}
|
||||
|
||||
void URLRequestContextGetter::Handle::LazyInitialize() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
if (initialized_)
|
||||
return;
|
||||
|
||||
initialized_ = true;
|
||||
main_network_context_params_ = CreateDefaultNetworkContextParams(
|
||||
browser_context_->GetPath(), browser_context_->GetUserAgent(),
|
||||
browser_context_->IsOffTheRecord(), browser_context_->CanUseHttpCache(),
|
||||
browser_context_->GetMaxCacheSize());
|
||||
|
||||
browser_context_->proxy_config_monitor()->AddToNetworkContextParams(
|
||||
main_network_context_params_.get());
|
||||
|
||||
ApplyProxyModeFromCommandLine(browser_context_->in_memory_pref_store());
|
||||
|
||||
if (!main_network_context_request_.is_pending()) {
|
||||
main_network_context_request_ = mojo::MakeRequest(&main_network_context_);
|
||||
}
|
||||
content::BrowserContext::EnsureResourceContextInitialized(
|
||||
browser_context_.get());
|
||||
}
|
||||
|
||||
void URLRequestContextGetter::Handle::ShutdownOnUIThread() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
if (main_request_context_getter_.get()) {
|
||||
if (BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(&URLRequestContextGetter::NotifyContextShuttingDown,
|
||||
base::RetainedRef(main_request_context_getter_),
|
||||
std::move(resource_context_)));
|
||||
}
|
||||
}
|
||||
|
||||
if (!BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this))
|
||||
delete this;
|
||||
}
|
||||
|
||||
URLRequestContextGetter::URLRequestContextGetter(
|
||||
net::NetLog* net_log,
|
||||
URLRequestContextGetter::Handle* context_handle,
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::URLRequestInterceptorScopedVector protocol_interceptors)
|
||||
: net_log_(net_log),
|
||||
context_handle_(context_handle),
|
||||
url_request_context_(nullptr),
|
||||
protocol_interceptors_(std::move(protocol_interceptors)),
|
||||
context_shutting_down_(false) {
|
||||
// Must first be created on the UI thread.
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
|
||||
if (protocol_handlers)
|
||||
std::swap(protocol_handlers_, *protocol_handlers);
|
||||
}
|
||||
|
||||
URLRequestContextGetter::~URLRequestContextGetter() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
// NotifyContextShuttingDown should have been called.
|
||||
DCHECK(context_shutting_down_);
|
||||
}
|
||||
|
||||
void URLRequestContextGetter::NotifyContextShuttingDown(
|
||||
std::unique_ptr<ResourceContext> resource_context) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
|
||||
context_shutting_down_ = true;
|
||||
resource_context.reset();
|
||||
http_auth_preferences_.reset();
|
||||
net::URLRequestContextGetter::NotifyContextShuttingDown();
|
||||
}
|
||||
|
||||
net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
|
||||
if (context_shutting_down_)
|
||||
return nullptr;
|
||||
|
||||
if (!url_request_context_) {
|
||||
auto& command_line = *base::CommandLine::ForCurrentProcess();
|
||||
std::unique_ptr<network::URLRequestContextBuilderMojo> builder =
|
||||
std::make_unique<network::URLRequestContextBuilderMojo>();
|
||||
builder->set_network_delegate(std::make_unique<AtomNetworkDelegate>());
|
||||
|
||||
ct_delegate_.reset(new brightray::RequireCTDelegate);
|
||||
auto cert_verifier = std::make_unique<AtomCertVerifier>(ct_delegate_.get());
|
||||
builder->SetCertVerifier(std::move(cert_verifier));
|
||||
|
||||
builder->SetCreateHttpTransactionFactoryCallback(
|
||||
base::BindOnce(&content::CreateDevToolsNetworkTransactionFactory));
|
||||
|
||||
std::unique_ptr<net::HostResolver> host_resolver =
|
||||
net::HostResolver::CreateDefaultResolver(net_log_);
|
||||
// --host-resolver-rules
|
||||
if (command_line.HasSwitch(network::switches::kHostResolverRules)) {
|
||||
auto remapped_resolver =
|
||||
std::make_unique<net::MappedHostResolver>(std::move(host_resolver));
|
||||
remapped_resolver->SetRulesFromString(command_line.GetSwitchValueASCII(
|
||||
network::switches::kHostResolverRules));
|
||||
host_resolver = std::move(remapped_resolver);
|
||||
}
|
||||
|
||||
std::vector<std::string> supported_schemes = {
|
||||
net::kBasicAuthScheme, net::kDigestAuthScheme,
|
||||
net::kNegotiateAuthScheme, net::kNtlmAuthScheme};
|
||||
http_auth_preferences_ =
|
||||
std::make_unique<net::HttpAuthPreferences>(supported_schemes
|
||||
#if defined(OS_POSIX)
|
||||
,
|
||||
std::string()
|
||||
#endif
|
||||
); // NOLINT(whitespace/parens)
|
||||
|
||||
// --auth-server-whitelist
|
||||
if (command_line.HasSwitch(switches::kAuthServerWhitelist)) {
|
||||
http_auth_preferences_->SetServerWhitelist(
|
||||
command_line.GetSwitchValueASCII(switches::kAuthServerWhitelist));
|
||||
}
|
||||
|
||||
// --auth-negotiate-delegate-whitelist
|
||||
if (command_line.HasSwitch(switches::kAuthNegotiateDelegateWhitelist)) {
|
||||
http_auth_preferences_->SetDelegateWhitelist(
|
||||
command_line.GetSwitchValueASCII(
|
||||
switches::kAuthNegotiateDelegateWhitelist));
|
||||
}
|
||||
auto http_auth_handler_factory =
|
||||
net::HttpAuthHandlerRegistryFactory::Create(
|
||||
http_auth_preferences_.get(), host_resolver.get());
|
||||
builder->SetHttpAuthHandlerFactory(std::move(http_auth_handler_factory));
|
||||
builder->set_host_resolver(std::move(host_resolver));
|
||||
builder->set_ct_verifier(std::make_unique<net::MultiLogCTVerifier>());
|
||||
|
||||
network_context_ =
|
||||
content::GetNetworkServiceImpl()->CreateNetworkContextWithBuilder(
|
||||
std::move(context_handle_->main_network_context_request_),
|
||||
std::move(context_handle_->main_network_context_params_),
|
||||
std::move(builder), &url_request_context_);
|
||||
|
||||
net::TransportSecurityState* transport_security_state =
|
||||
url_request_context_->transport_security_state();
|
||||
transport_security_state->SetRequireCTDelegate(ct_delegate_.get());
|
||||
|
||||
// Add custom standard schemes to cookie schemes.
|
||||
auto* cookie_monster =
|
||||
static_cast<net::CookieMonster*>(url_request_context_->cookie_store());
|
||||
std::vector<std::string> cookie_schemes(
|
||||
{url::kHttpScheme, url::kHttpsScheme, url::kWsScheme, url::kWssScheme});
|
||||
const auto& custom_standard_schemes = atom::api::GetStandardSchemes();
|
||||
cookie_schemes.insert(cookie_schemes.end(), custom_standard_schemes.begin(),
|
||||
custom_standard_schemes.end());
|
||||
cookie_monster->SetCookieableSchemes(cookie_schemes);
|
||||
|
||||
// Setup handlers for custom job factory.
|
||||
top_job_factory_.reset(new AtomURLRequestJobFactory);
|
||||
SetupAtomURLRequestJobFactory(&protocol_handlers_, url_request_context_,
|
||||
top_job_factory_.get());
|
||||
std::unique_ptr<net::URLRequestJobFactory> inner_job_factory(
|
||||
new net::URLRequestJobFactoryImpl);
|
||||
if (!protocol_interceptors_.empty()) {
|
||||
// Set up interceptors in the reverse order.
|
||||
for (auto it = protocol_interceptors_.rbegin();
|
||||
it != protocol_interceptors_.rend(); ++it) {
|
||||
inner_job_factory.reset(new net::URLRequestInterceptingJobFactory(
|
||||
std::move(inner_job_factory), std::move(*it)));
|
||||
}
|
||||
protocol_interceptors_.clear();
|
||||
}
|
||||
top_job_factory_->Chain(std::move(inner_job_factory));
|
||||
url_request_context_->set_job_factory(top_job_factory_.get());
|
||||
|
||||
context_handle_->resource_context_->request_context_ = url_request_context_;
|
||||
}
|
||||
|
||||
return url_request_context_;
|
||||
}
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner>
|
||||
URLRequestContextGetter::GetNetworkTaskRunner() const {
|
||||
return BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
119
atom/browser/net/url_request_context_getter.h
Normal file
119
atom/browser/net/url_request_context_getter.h
Normal file
@@ -0,0 +1,119 @@
|
||||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_H_
|
||||
#define ATOM_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "content/public/browser/browser_context.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
#include "net/url_request/url_request_context_getter.h"
|
||||
#include "services/network/public/mojom/network_service.mojom.h"
|
||||
|
||||
#if DCHECK_IS_ON()
|
||||
#include "base/debug/leak_tracker.h"
|
||||
#endif
|
||||
|
||||
namespace brightray {
|
||||
class RequireCTDelegate;
|
||||
} // namespace brightray
|
||||
|
||||
namespace net {
|
||||
class HttpAuthPreferences;
|
||||
class NetLog;
|
||||
} // namespace net
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomBrowserContext;
|
||||
class AtomURLRequestJobFactory;
|
||||
class ResourceContext;
|
||||
|
||||
class URLRequestContextGetter : public net::URLRequestContextGetter {
|
||||
public:
|
||||
// net::URLRequestContextGetter:
|
||||
net::URLRequestContext* GetURLRequestContext() override;
|
||||
scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
|
||||
const override;
|
||||
|
||||
// Discard reference to URLRequestContext and inform observers to
|
||||
// shutdown. Must be called only on IO thread.
|
||||
void NotifyContextShuttingDown(std::unique_ptr<ResourceContext>);
|
||||
|
||||
AtomURLRequestJobFactory* job_factory() const {
|
||||
return top_job_factory_.get();
|
||||
}
|
||||
|
||||
private:
|
||||
friend class AtomBrowserContext;
|
||||
|
||||
// Responsible for destroying URLRequestContextGetter
|
||||
// on the IO thread.
|
||||
class Handle {
|
||||
public:
|
||||
explicit Handle(base::WeakPtr<AtomBrowserContext> browser_context);
|
||||
~Handle();
|
||||
|
||||
scoped_refptr<URLRequestContextGetter> CreateMainRequestContextGetter(
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::URLRequestInterceptorScopedVector protocol_interceptors);
|
||||
content::ResourceContext* GetResourceContext();
|
||||
scoped_refptr<URLRequestContextGetter> GetMainRequestContextGetter();
|
||||
network::mojom::NetworkContextPtr GetNetworkContext();
|
||||
|
||||
void ShutdownOnUIThread();
|
||||
|
||||
private:
|
||||
friend class URLRequestContextGetter;
|
||||
void LazyInitialize();
|
||||
|
||||
scoped_refptr<URLRequestContextGetter> main_request_context_getter_;
|
||||
std::unique_ptr<ResourceContext> resource_context_;
|
||||
base::WeakPtr<AtomBrowserContext> browser_context_;
|
||||
// This is a NetworkContext interface that uses URLRequestContextGetter
|
||||
// NetworkContext, ownership is passed to StoragePartition when
|
||||
// CreateMainNetworkContext is called.
|
||||
network::mojom::NetworkContextPtr main_network_context_;
|
||||
// Request corresponding to |main_network_context_|. Ownership
|
||||
// is passed to network service.
|
||||
network::mojom::NetworkContextRequest main_network_context_request_;
|
||||
network::mojom::NetworkContextParamsPtr main_network_context_params_;
|
||||
bool initialized_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Handle);
|
||||
};
|
||||
|
||||
URLRequestContextGetter(
|
||||
net::NetLog* net_log,
|
||||
URLRequestContextGetter::Handle* context_handle,
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::URLRequestInterceptorScopedVector protocol_interceptors);
|
||||
~URLRequestContextGetter() override;
|
||||
|
||||
#if DCHECK_IS_ON()
|
||||
base::debug::LeakTracker<URLRequestContextGetter> leak_tracker_;
|
||||
#endif
|
||||
|
||||
std::unique_ptr<brightray::RequireCTDelegate> ct_delegate_;
|
||||
std::unique_ptr<AtomURLRequestJobFactory> top_job_factory_;
|
||||
std::unique_ptr<net::HttpAuthPreferences> http_auth_preferences_;
|
||||
std::unique_ptr<network::mojom::NetworkContext> network_context_;
|
||||
|
||||
net::NetLog* net_log_;
|
||||
URLRequestContextGetter::Handle* context_handle_;
|
||||
net::URLRequestContext* url_request_context_;
|
||||
content::ProtocolHandlerMap protocol_handlers_;
|
||||
content::URLRequestInterceptorScopedVector protocol_interceptors_;
|
||||
bool context_shutting_down_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(URLRequestContextGetter);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_NET_URL_REQUEST_CONTEXT_GETTER_H_
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "atom/browser/api/atom_api_session.h"
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "base/guid.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
@@ -93,16 +94,15 @@ void URLRequestFetchJob::BeforeStartInUI(v8::Isolate* isolate,
|
||||
if (options.Get("session", &val)) {
|
||||
if (val->IsNull()) {
|
||||
// We have to create the URLRequestContextGetter on UI thread.
|
||||
url_request_context_getter_ = new brightray::URLRequestContextGetter(
|
||||
this, nullptr, base::FilePath(), true,
|
||||
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), nullptr,
|
||||
content::URLRequestInterceptorScopedVector());
|
||||
custom_browser_context_ =
|
||||
AtomBrowserContext::From(base::GenerateGUID(), true);
|
||||
url_request_context_getter_ =
|
||||
custom_browser_context_->GetRequestContext();
|
||||
} else {
|
||||
mate::Handle<api::Session> session;
|
||||
if (mate::ConvertFromV8(isolate, val, &session) && !session.IsEmpty()) {
|
||||
AtomBrowserContext* browser_context = session->browser_context();
|
||||
url_request_context_getter_ =
|
||||
browser_context->url_request_context_getter();
|
||||
url_request_context_getter_ = browser_context->GetRequestContext();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,6 +167,9 @@ void URLRequestFetchJob::StartAsync(std::unique_ptr<base::Value> options) {
|
||||
request()->extra_request_headers().ToString());
|
||||
|
||||
fetcher_->Start();
|
||||
// URLFetcher has a refernce to the context, which
|
||||
// will be cleared when the request is destroyed.
|
||||
url_request_context_getter_ = nullptr;
|
||||
}
|
||||
|
||||
void URLRequestFetchJob::HeadersCompleted() {
|
||||
@@ -199,6 +202,7 @@ int URLRequestFetchJob::DataAvailable(net::IOBuffer* buffer,
|
||||
void URLRequestFetchJob::Kill() {
|
||||
JsAsker<URLRequestJob>::Kill();
|
||||
fetcher_.reset();
|
||||
custom_browser_context_ = nullptr;
|
||||
}
|
||||
|
||||
int URLRequestFetchJob::ReadRawData(net::IOBuffer* dest, int dest_size) {
|
||||
|
||||
@@ -8,16 +8,17 @@
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/net/js_asker.h"
|
||||
#include "brightray/browser/url_request_context_getter.h"
|
||||
#include "content/browser/streams/stream.h"
|
||||
#include "content/browser/streams/stream_read_observer.h"
|
||||
#include "net/url_request/url_fetcher_delegate.h"
|
||||
#include "net/url_request/url_request_context_getter.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomBrowserContext;
|
||||
|
||||
class URLRequestFetchJob : public JsAsker<net::URLRequestJob>,
|
||||
public net::URLFetcherDelegate,
|
||||
public brightray::URLRequestContextGetter::Delegate {
|
||||
public net::URLFetcherDelegate {
|
||||
public:
|
||||
URLRequestFetchJob(net::URLRequest*, net::NetworkDelegate*);
|
||||
~URLRequestFetchJob() override;
|
||||
@@ -51,6 +52,7 @@ class URLRequestFetchJob : public JsAsker<net::URLRequestJob>,
|
||||
void ClearPendingBuffer();
|
||||
void ClearWriteBuffer();
|
||||
|
||||
scoped_refptr<AtomBrowserContext> custom_browser_context_;
|
||||
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
|
||||
std::unique_ptr<net::URLFetcher> fetcher_;
|
||||
std::unique_ptr<net::HttpResponseInfo> response_info_;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "atom/browser/node_debugger.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "libplatform/libplatform.h"
|
||||
@@ -25,10 +27,15 @@ void NodeDebugger::Start(node::MultiIsolatePlatform* platform) {
|
||||
node::DebugOptions options;
|
||||
for (auto& arg : base::CommandLine::ForCurrentProcess()->argv()) {
|
||||
#if defined(OS_WIN)
|
||||
options.ParseOption("Electron", base::UTF16ToUTF8(arg));
|
||||
const std::string nice_arg = base::UTF16ToUTF8(arg);
|
||||
#else
|
||||
options.ParseOption("Electron", arg);
|
||||
const std::string& nice_arg = arg;
|
||||
#endif
|
||||
// Stop handling arguments after a "--" to be consistent with Chromium
|
||||
if (nice_arg == "--")
|
||||
break;
|
||||
|
||||
options.ParseOption("Electron", nice_arg);
|
||||
}
|
||||
|
||||
// Set process._debugWaitConnect if --inspect-brk was specified to stop
|
||||
|
||||
@@ -264,6 +264,7 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
|
||||
size_(native_window->GetSize()),
|
||||
painting_(painting),
|
||||
is_showing_(!render_widget_host_->is_hidden()),
|
||||
mouse_wheel_phase_handler_(render_widget_host_, this),
|
||||
weak_ptr_factory_(this) {
|
||||
DCHECK(render_widget_host_);
|
||||
bool is_guest_view_hack = parent_host_view_ != nullptr;
|
||||
@@ -279,10 +280,8 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
|
||||
|
||||
local_surface_id_ = local_surface_id_allocator_.GenerateId();
|
||||
|
||||
// Surface synchronization is not supported with OSR.
|
||||
DCHECK(!features::IsSurfaceSynchronizationEnabled());
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
last_frame_root_background_color_ = SK_ColorTRANSPARENT;
|
||||
CreatePlatformWidget(is_guest_view_hack);
|
||||
#else
|
||||
// On macOS the ui::Compositor is created/owned by the platform view.
|
||||
@@ -303,7 +302,7 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
|
||||
|
||||
native_window_->AddObserver(this);
|
||||
|
||||
ResizeRootLayer();
|
||||
ResizeRootLayer(false);
|
||||
render_widget_host_->SetView(this);
|
||||
InstallTransparency();
|
||||
}
|
||||
@@ -385,7 +384,7 @@ void OffScreenRenderWidgetHostView::InitAsChild(gfx::NativeView) {
|
||||
parent_host_view_->set_child_host_view(this);
|
||||
parent_host_view_->Hide();
|
||||
|
||||
ResizeRootLayer();
|
||||
ResizeRootLayer(false);
|
||||
Show();
|
||||
}
|
||||
|
||||
@@ -514,6 +513,10 @@ void OffScreenRenderWidgetHostView::SubmitCompositorFrame(
|
||||
TRACE_EVENT0("electron",
|
||||
"OffScreenRenderWidgetHostView::SubmitCompositorFrame");
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
last_frame_root_background_color_ = frame.metadata.root_background_color;
|
||||
#endif
|
||||
|
||||
if (frame.metadata.root_scroll_offset != last_scroll_offset_) {
|
||||
last_scroll_offset_ = frame.metadata.root_scroll_offset;
|
||||
}
|
||||
@@ -579,7 +582,7 @@ void OffScreenRenderWidgetHostView::InitAsPopup(
|
||||
|
||||
popup_position_ = pos;
|
||||
|
||||
ResizeRootLayer();
|
||||
ResizeRootLayer(false);
|
||||
Show();
|
||||
}
|
||||
|
||||
@@ -743,10 +746,6 @@ OffScreenRenderWidgetHostView::DelegatedFrameHostCreateResizeLock() {
|
||||
return std::make_unique<content::CompositorResizeLock>(this, desired_size);
|
||||
}
|
||||
|
||||
viz::LocalSurfaceId OffScreenRenderWidgetHostView::GetLocalSurfaceId() const {
|
||||
return local_surface_id_;
|
||||
}
|
||||
|
||||
void OffScreenRenderWidgetHostView::OnFirstSurfaceActivation(
|
||||
const viz::SurfaceInfo& surface_info) {}
|
||||
|
||||
@@ -774,8 +773,26 @@ bool OffScreenRenderWidgetHostView::IsAutoResizeEnabled() const {
|
||||
return render_widget_host_->auto_resize_enabled();
|
||||
}
|
||||
|
||||
viz::LocalSurfaceId OffScreenRenderWidgetHostView::GetLocalSurfaceId() const {
|
||||
return local_surface_id_;
|
||||
}
|
||||
|
||||
#endif // !defined(OS_MACOSX)
|
||||
|
||||
viz::FrameSinkId OffScreenRenderWidgetHostView::GetFrameSinkId() {
|
||||
return GetDelegatedFrameHost()->frame_sink_id();
|
||||
}
|
||||
|
||||
void OffScreenRenderWidgetHostView::DidNavigate() {
|
||||
ResizeRootLayer(true);
|
||||
#if defined(OS_MACOSX)
|
||||
browser_compositor_->DidNavigate();
|
||||
#else
|
||||
if (delegated_frame_host_)
|
||||
delegated_frame_host_->DidNavigate();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool OffScreenRenderWidgetHostView::TransformPointToLocalCoordSpace(
|
||||
const gfx::PointF& point,
|
||||
const viz::SurfaceId& original_surface,
|
||||
@@ -882,7 +899,7 @@ OffScreenRenderWidgetHostView::CreateSoftwareOutputDevice(
|
||||
DCHECK(!copy_frame_generator_);
|
||||
DCHECK(!software_output_device_);
|
||||
|
||||
ResizeRootLayer();
|
||||
ResizeRootLayer(false);
|
||||
|
||||
software_output_device_ = new OffScreenOutputDevice(
|
||||
transparent_, base::Bind(&OffScreenRenderWidgetHostView::OnPaint,
|
||||
@@ -1034,7 +1051,7 @@ void OffScreenRenderWidgetHostView::WasResized() {
|
||||
return;
|
||||
}
|
||||
|
||||
ResizeRootLayer();
|
||||
ResizeRootLayer(false);
|
||||
if (render_widget_host_)
|
||||
render_widget_host_->WasResized();
|
||||
GetDelegatedFrameHost()->WasResized(local_surface_id_, size_,
|
||||
@@ -1096,18 +1113,29 @@ void OffScreenRenderWidgetHostView::SendMouseWheelEvent(
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
blink::WebMouseWheelEvent mouse_wheel_event(event);
|
||||
|
||||
mouse_wheel_phase_handler_.SendWheelEndIfNeeded();
|
||||
mouse_wheel_phase_handler_.AddPhaseIfNeededAndScheduleEndEvent(
|
||||
mouse_wheel_event, false);
|
||||
|
||||
if (!IsPopupWidget()) {
|
||||
if (popup_host_view_) {
|
||||
if (popup_host_view_->popup_position_.Contains(
|
||||
event.PositionInWidget().x, event.PositionInWidget().y)) {
|
||||
blink::WebMouseWheelEvent popup_event(event);
|
||||
popup_event.SetPositionInWidget(
|
||||
popup_event.PositionInWidget().x -
|
||||
mouse_wheel_event.PositionInWidget().x,
|
||||
mouse_wheel_event.PositionInWidget().y)) {
|
||||
blink::WebMouseWheelEvent popup_mouse_wheel_event(mouse_wheel_event);
|
||||
popup_mouse_wheel_event.SetPositionInWidget(
|
||||
mouse_wheel_event.PositionInWidget().x -
|
||||
popup_host_view_->popup_position_.x(),
|
||||
popup_event.PositionInWidget().y -
|
||||
mouse_wheel_event.PositionInWidget().y -
|
||||
popup_host_view_->popup_position_.y());
|
||||
popup_host_view_->ProcessMouseWheelEvent(popup_event,
|
||||
ui::LatencyInfo());
|
||||
popup_mouse_wheel_event.SetPositionInScreen(
|
||||
popup_mouse_wheel_event.PositionInWidget().x,
|
||||
popup_mouse_wheel_event.PositionInWidget().y);
|
||||
|
||||
popup_host_view_->SendMouseWheelEvent(popup_mouse_wheel_event);
|
||||
return;
|
||||
} else {
|
||||
// Scrolling outside of the popup widget so destroy it.
|
||||
@@ -1118,6 +1146,28 @@ void OffScreenRenderWidgetHostView::SendMouseWheelEvent(
|
||||
base::BindOnce(&OffScreenRenderWidgetHostView::CancelWidget,
|
||||
popup_host_view_->weak_ptr_factory_.GetWeakPtr()));
|
||||
}
|
||||
} else if (!guest_host_views_.empty()) {
|
||||
for (auto guest_host_view : guest_host_views_) {
|
||||
if (!guest_host_view->render_widget_host_ ||
|
||||
!guest_host_view->render_widget_host_->GetView()) {
|
||||
continue;
|
||||
}
|
||||
const gfx::Rect& guest_bounds =
|
||||
guest_host_view->render_widget_host_->GetView()->GetViewBounds();
|
||||
if (guest_bounds.Contains(mouse_wheel_event.PositionInWidget().x,
|
||||
mouse_wheel_event.PositionInWidget().y)) {
|
||||
blink::WebMouseWheelEvent guest_mouse_wheel_event(mouse_wheel_event);
|
||||
guest_mouse_wheel_event.SetPositionInWidget(
|
||||
mouse_wheel_event.PositionInWidget().x - guest_bounds.x(),
|
||||
mouse_wheel_event.PositionInWidget().y - guest_bounds.y());
|
||||
guest_mouse_wheel_event.SetPositionInScreen(
|
||||
guest_mouse_wheel_event.PositionInWidget().x,
|
||||
guest_mouse_wheel_event.PositionInWidget().y);
|
||||
|
||||
guest_host_view->SendMouseWheelEvent(guest_mouse_wheel_event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!render_widget_host_)
|
||||
@@ -1183,8 +1233,10 @@ void OffScreenRenderWidgetHostView::SetupFrameRate(bool force) {
|
||||
|
||||
frame_rate_threshold_us_ = 1000000 / frame_rate_;
|
||||
|
||||
GetCompositor()->SetAuthoritativeVSyncInterval(
|
||||
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us_));
|
||||
if (GetCompositor()) {
|
||||
GetCompositor()->SetAuthoritativeVSyncInterval(
|
||||
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us_));
|
||||
}
|
||||
|
||||
if (copy_frame_generator_.get()) {
|
||||
copy_frame_generator_->set_frame_rate_threshold_us(
|
||||
@@ -1213,7 +1265,7 @@ void OffScreenRenderWidgetHostView::InvalidateBounds(const gfx::Rect& bounds) {
|
||||
}
|
||||
}
|
||||
|
||||
void OffScreenRenderWidgetHostView::ResizeRootLayer() {
|
||||
void OffScreenRenderWidgetHostView::ResizeRootLayer(bool force) {
|
||||
SetupFrameRate(false);
|
||||
|
||||
const float compositorScaleFactor = GetCompositor()->device_scale_factor();
|
||||
@@ -1225,7 +1277,8 @@ void OffScreenRenderWidgetHostView::ResizeRootLayer() {
|
||||
else
|
||||
size = popup_position_.size();
|
||||
|
||||
if (!scaleFactorDidChange && size == GetRootLayer()->bounds().size())
|
||||
if (!force && !scaleFactorDidChange &&
|
||||
size == GetRootLayer()->bounds().size())
|
||||
return;
|
||||
|
||||
const gfx::Size& size_in_pixels =
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "content/browser/frame_host/render_widget_host_view_guest.h"
|
||||
#include "content/browser/renderer_host/compositor_resize_lock.h"
|
||||
#include "content/browser/renderer_host/delegated_frame_host.h"
|
||||
#include "content/browser/renderer_host/input/mouse_wheel_phase_handler.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_view_base.h"
|
||||
#include "content/browser/web_contents/web_contents_view.h"
|
||||
@@ -108,12 +109,12 @@ class OffScreenRenderWidgetHostView
|
||||
void SetNeedsBeginFrames(bool needs_begin_frames) override;
|
||||
void SetWantsAnimateOnlyBeginFrames() override;
|
||||
#if defined(OS_MACOSX)
|
||||
ui::AcceleratedWidgetMac* GetAcceleratedWidgetMac() const override;
|
||||
void SetActive(bool active) override;
|
||||
void ShowDefinitionForSelection() override;
|
||||
bool SupportsSpeech() const override;
|
||||
void SpeakSelection() override;
|
||||
bool IsSpeaking() const override;
|
||||
bool ShouldContinueToPauseForFrame() override;
|
||||
void StopSpeaking() override;
|
||||
#endif // defined(OS_MACOSX)
|
||||
|
||||
@@ -169,7 +170,6 @@ class OffScreenRenderWidgetHostView
|
||||
bool DelegatedFrameCanCreateResizeLock() const override;
|
||||
std::unique_ptr<content::CompositorResizeLock>
|
||||
DelegatedFrameHostCreateResizeLock() override;
|
||||
viz::LocalSurfaceId GetLocalSurfaceId() const override;
|
||||
void OnFirstSurfaceActivation(const viz::SurfaceInfo& surface_info) override;
|
||||
void OnBeginFrame(base::TimeTicks frame_time) override;
|
||||
void OnFrameTokenChanged(uint32_t frame_token) override;
|
||||
@@ -181,6 +181,11 @@ class OffScreenRenderWidgetHostView
|
||||
bool IsAutoResizeEnabled() const override;
|
||||
#endif // !defined(OS_MACOSX)
|
||||
|
||||
viz::LocalSurfaceId GetLocalSurfaceId() const override;
|
||||
viz::FrameSinkId GetFrameSinkId() override;
|
||||
|
||||
void DidNavigate() override;
|
||||
|
||||
bool TransformPointToLocalCoordSpace(const gfx::PointF& point,
|
||||
const viz::SurfaceId& original_surface,
|
||||
gfx::PointF* transformed_point) override;
|
||||
@@ -205,6 +210,9 @@ class OffScreenRenderWidgetHostView
|
||||
#if defined(OS_MACOSX)
|
||||
void CreatePlatformWidget(bool is_guest_view_hack);
|
||||
void DestroyPlatformWidget();
|
||||
SkColor last_frame_root_background_color() const {
|
||||
return last_frame_root_background_color_;
|
||||
}
|
||||
#endif
|
||||
|
||||
void CancelWidget();
|
||||
@@ -260,11 +268,9 @@ class OffScreenRenderWidgetHostView
|
||||
child_host_view_ = child_view;
|
||||
}
|
||||
|
||||
viz::LocalSurfaceId local_surface_id() const { return local_surface_id_; }
|
||||
|
||||
private:
|
||||
void SetupFrameRate(bool force);
|
||||
void ResizeRootLayer();
|
||||
void ResizeRootLayer(bool force);
|
||||
|
||||
viz::FrameSinkId AllocateFrameSinkId(bool is_guest_view_hack);
|
||||
|
||||
@@ -325,6 +331,8 @@ class OffScreenRenderWidgetHostView
|
||||
#if defined(OS_MACOSX)
|
||||
std::unique_ptr<content::BrowserCompositorMac> browser_compositor_;
|
||||
|
||||
SkColor last_frame_root_background_color_;
|
||||
|
||||
// Can not be managed by smart pointer because its header can not be included
|
||||
// in the file that has the destructor.
|
||||
MacHelper* mac_helper_;
|
||||
@@ -333,6 +341,8 @@ class OffScreenRenderWidgetHostView
|
||||
std::string selected_text_;
|
||||
#endif
|
||||
|
||||
content::MouseWheelPhaseHandler mouse_wheel_phase_handler_;
|
||||
|
||||
viz::mojom::CompositorFrameSinkClient* renderer_compositor_frame_sink_ =
|
||||
nullptr;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class MacHelper : public content::BrowserCompositorMacClient,
|
||||
virtual ~MacHelper() {}
|
||||
|
||||
// content::BrowserCompositorMacClient:
|
||||
SkColor BrowserCompositorMacGetGutterColor(SkColor color) const override {
|
||||
SkColor BrowserCompositorMacGetGutterColor() const override {
|
||||
// When making an element on the page fullscreen the element's background
|
||||
// may not match the page's, so use black as the gutter color to avoid
|
||||
// flashes of brighter colors during the transition.
|
||||
@@ -30,7 +30,7 @@ class MacHelper : public content::BrowserCompositorMacClient,
|
||||
view_->render_widget_host()->delegate()->IsFullscreenForCurrentTab()) {
|
||||
return SK_ColorBLACK;
|
||||
}
|
||||
return color;
|
||||
return view_->last_frame_root_background_color();
|
||||
}
|
||||
|
||||
void BrowserCompositorMacOnBeginFrame() override {}
|
||||
@@ -81,7 +81,7 @@ bool OffScreenRenderWidgetHostView::IsSpeaking() const {
|
||||
|
||||
void OffScreenRenderWidgetHostView::StopSpeaking() {}
|
||||
|
||||
bool CefRenderWidgetHostViewOSR::ShouldContinueToPauseForFrame() {
|
||||
bool OffScreenRenderWidgetHostView::ShouldContinueToPauseForFrame() {
|
||||
return browser_compositor_->ShouldContinueToPauseForFrame();
|
||||
}
|
||||
|
||||
@@ -98,6 +98,10 @@ void OffScreenRenderWidgetHostView::DestroyPlatformWidget() {
|
||||
delete mac_helper_;
|
||||
}
|
||||
|
||||
viz::LocalSurfaceId OffScreenRenderWidgetHostView::GetLocalSurfaceId() const {
|
||||
return browser_compositor_->GetRendererLocalSurfaceId();
|
||||
}
|
||||
|
||||
ui::Compositor* OffScreenRenderWidgetHostView::GetCompositor() const {
|
||||
return browser_compositor_->GetCompositor();
|
||||
}
|
||||
|
||||
30
atom/browser/pref_store_delegate.cc
Normal file
30
atom/browser/pref_store_delegate.cc
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/pref_store_delegate.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "components/prefs/value_map_pref_store.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
PrefStoreDelegate::PrefStoreDelegate(
|
||||
base::WeakPtr<AtomBrowserContext> browser_context)
|
||||
: browser_context_(std::move(browser_context)) {}
|
||||
|
||||
PrefStoreDelegate::~PrefStoreDelegate() {
|
||||
if (browser_context_)
|
||||
browser_context_->set_in_memory_pref_store(nullptr);
|
||||
}
|
||||
|
||||
void PrefStoreDelegate::UpdateCommandLinePrefStore(
|
||||
PrefStore* command_line_prefs) {
|
||||
if (browser_context_)
|
||||
browser_context_->set_in_memory_pref_store(
|
||||
static_cast<ValueMapPrefStore*>(command_line_prefs));
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
52
atom/browser/pref_store_delegate.h
Normal file
52
atom/browser/pref_store_delegate.h
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) 2018 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_PREF_STORE_DELEGATE_H_
|
||||
#define ATOM_BROWSER_PREF_STORE_DELEGATE_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "components/prefs/persistent_pref_store.h"
|
||||
#include "components/prefs/pref_value_store.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomBrowserContext;
|
||||
|
||||
// Retrieves handle to the in memory pref store that gets
|
||||
// initialized with the pref service.
|
||||
class PrefStoreDelegate : public PrefValueStore::Delegate {
|
||||
public:
|
||||
explicit PrefStoreDelegate(base::WeakPtr<AtomBrowserContext> browser_context);
|
||||
~PrefStoreDelegate() override;
|
||||
|
||||
void Init(PrefStore* managed_prefs,
|
||||
PrefStore* supervised_user_prefs,
|
||||
PrefStore* extension_prefs,
|
||||
PrefStore* command_line_prefs,
|
||||
PrefStore* user_prefs,
|
||||
PrefStore* recommended_prefs,
|
||||
PrefStore* default_prefs,
|
||||
PrefNotifier* pref_notifier) override {}
|
||||
|
||||
void InitIncognitoUserPrefs(
|
||||
scoped_refptr<PersistentPrefStore> incognito_user_prefs_overlay,
|
||||
scoped_refptr<PersistentPrefStore> incognito_user_prefs_underlay,
|
||||
const std::vector<const char*>& overlay_pref_names) override {}
|
||||
|
||||
void InitPrefRegistry(PrefRegistry* pref_registry) override {}
|
||||
|
||||
void UpdateCommandLinePrefStore(PrefStore* command_line_prefs) override;
|
||||
|
||||
private:
|
||||
base::WeakPtr<AtomBrowserContext> browser_context_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PrefStoreDelegate);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_PREF_STORE_DELEGATE_H_
|
||||
@@ -17,9 +17,9 @@
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>electron.icns</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>3.0.0</string>
|
||||
<string>3.1.0</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>3.0.0</string>
|
||||
<string>3.1.0</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.developer-tools</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
|
||||
@@ -56,8 +56,8 @@ END
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 3,0,0,4
|
||||
PRODUCTVERSION 3,0,0,4
|
||||
FILEVERSION 3,1,0,0
|
||||
PRODUCTVERSION 3,1,0,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@@ -74,12 +74,12 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "CompanyName", "GitHub, Inc."
|
||||
VALUE "FileDescription", "Electron"
|
||||
VALUE "FileVersion", "3.0.0"
|
||||
VALUE "FileVersion", "3.1.0"
|
||||
VALUE "InternalName", "electron.exe"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2015 GitHub, Inc. All rights reserved."
|
||||
VALUE "OriginalFilename", "electron.exe"
|
||||
VALUE "ProductName", "Electron"
|
||||
VALUE "ProductVersion", "3.0.0"
|
||||
VALUE "ProductVersion", "3.1.0"
|
||||
VALUE "SquirrelAwareVersion", "1"
|
||||
END
|
||||
END
|
||||
|
||||
@@ -91,7 +91,9 @@ bool TriggerAcceleratorTableCommand(AcceleratorTable* table,
|
||||
if (base::ContainsKey(*table, accelerator)) {
|
||||
const accelerator_util::MenuItem& item = (*table)[accelerator];
|
||||
if (item.model->IsEnabledAt(item.position)) {
|
||||
item.model->ActivatedAt(item.position);
|
||||
const auto event_flags =
|
||||
accelerator.MaskOutKeyEventFlags(accelerator.modifiers());
|
||||
item.model->ActivatedAt(item.position, event_flags);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,7 +208,15 @@ static base::scoped_nsobject<NSMenu> recentDocumentsMenuSwap_;
|
||||
|
||||
base::string16 role = model->GetRoleAt(index);
|
||||
atom::AtomMenuModel::ItemType type = model->GetTypeAt(index);
|
||||
if (type == atom::AtomMenuModel::TYPE_SUBMENU) {
|
||||
if (role == base::ASCIIToUTF16("services")) {
|
||||
base::string16 title = base::ASCIIToUTF16("Services");
|
||||
NSString* label = l10n_util::FixUpWindowsStyleLabel(title);
|
||||
[item setTarget:nil];
|
||||
[item setAction:nil];
|
||||
NSMenu* submenu = [[NSMenu alloc] initWithTitle:label];
|
||||
[item setSubmenu:submenu];
|
||||
[NSApp setServicesMenu:submenu];
|
||||
} else if (type == atom::AtomMenuModel::TYPE_SUBMENU) {
|
||||
// Recursively build a submenu from the sub-model at this index.
|
||||
[item setTarget:nil];
|
||||
[item setAction:nil];
|
||||
@@ -223,8 +231,6 @@ static base::scoped_nsobject<NSMenu> recentDocumentsMenuSwap_;
|
||||
[NSApp setWindowsMenu:submenu];
|
||||
else if (role == base::ASCIIToUTF16("help"))
|
||||
[NSApp setHelpMenu:submenu];
|
||||
else if (role == base::ASCIIToUTF16("services"))
|
||||
[NSApp setServicesMenu:submenu];
|
||||
else if (role == base::ASCIIToUTF16("recentdocuments"))
|
||||
[self replaceSubmenuShowingRecentDocuments:item];
|
||||
} else {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "brightray/browser/mac/event_dispatching_window.h"
|
||||
#include "ui/views/cocoa/native_widget_mac_nswindow.h"
|
||||
#include "ui/views/widget/native_widget_mac.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
@@ -40,6 +41,7 @@ class ScopedDisableResize {
|
||||
- (id)initWithShell:(atom::NativeWindowMac*)shell
|
||||
styleMask:(NSUInteger)styleMask;
|
||||
- (atom::NativeWindowMac*)shell;
|
||||
- (id)accessibilityFocusedUIElement;
|
||||
- (NSRect)originalContentRectForFrameRect:(NSRect)frameRect;
|
||||
- (void)enableWindowButtonsOffset;
|
||||
- (void)toggleFullScreenMode:(id)sender;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "atom/browser/native_window_mac.h"
|
||||
#include "atom/browser/ui/cocoa/atom_preview_item.h"
|
||||
#include "atom/browser/ui/cocoa/atom_touch_bar.h"
|
||||
#include "atom/browser/ui/cocoa/root_view_mac.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "ui/base/cocoa/window_size_constants.h"
|
||||
|
||||
namespace atom {
|
||||
@@ -39,6 +41,13 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||
return shell_;
|
||||
}
|
||||
|
||||
- (id)accessibilityFocusedUIElement {
|
||||
views::Widget* widget = shell_->widget();
|
||||
id superFocus = [super accessibilityFocusedUIElement];
|
||||
if (!widget || shell_->IsFocused())
|
||||
return superFocus;
|
||||
return nil;
|
||||
}
|
||||
- (NSRect)originalContentRectForFrameRect:(NSRect)frameRect {
|
||||
return [super contentRectForFrameRect:frameRect];
|
||||
}
|
||||
@@ -91,6 +100,10 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||
}
|
||||
|
||||
- (id)accessibilityAttributeValue:(NSString*)attribute {
|
||||
if ([attribute isEqual:NSAccessibilityTitleAttribute])
|
||||
return base::SysUTF8ToNSString(shell_->GetTitle());
|
||||
if ([attribute isEqual:NSAccessibilityEnabledAttribute])
|
||||
return [NSNumber numberWithBool:YES];
|
||||
if (![attribute isEqualToString:@"AXChildren"])
|
||||
return [super accessibilityAttributeValue:attribute];
|
||||
|
||||
@@ -211,12 +224,22 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||
|
||||
// Custom window button methods
|
||||
|
||||
- (BOOL)windowShouldClose:(id)sender { return YES; }
|
||||
|
||||
- (void)performClose:(id)sender {
|
||||
if (shell_->title_bar_style() ==
|
||||
atom::NativeWindowMac::CUSTOM_BUTTONS_ON_HOVER)
|
||||
atom::NativeWindowMac::CUSTOM_BUTTONS_ON_HOVER) {
|
||||
[[self delegate] windowShouldClose:self];
|
||||
else
|
||||
} else if (shell_->IsSimpleFullScreen()) {
|
||||
if([[self delegate] respondsToSelector:@selector(windowShouldClose:)]) {
|
||||
if(![[self delegate] windowShouldClose:self]) return;
|
||||
} else if([self respondsToSelector:@selector(windowShouldClose:)]) {
|
||||
if(![self windowShouldClose:self]) return;
|
||||
}
|
||||
[self close];
|
||||
} else {
|
||||
[super performClose:sender];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)toggleFullScreenMode:(id)sender {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "atom/browser/ui/cocoa/atom_preview_item.h"
|
||||
#include "atom/browser/ui/cocoa/atom_touch_bar.h"
|
||||
#include "base/mac/mac_util.h"
|
||||
#include "ui/views/cocoa/bridged_native_widget.h"
|
||||
#include "ui/views/widget/native_widget_mac.h"
|
||||
|
||||
@implementation AtomNSWindowDelegate
|
||||
@@ -203,6 +204,7 @@
|
||||
|
||||
// Set window style to hide the toolbar, otherwise the toolbar will show
|
||||
// in fullscreen mode.
|
||||
[window setTitlebarAppearsTransparent:NO];
|
||||
shell_->SetStyleMask(true, NSFullSizeContentViewWindowMask);
|
||||
}
|
||||
}
|
||||
@@ -221,6 +223,7 @@
|
||||
// Turn off the style for toolbar.
|
||||
if (shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) {
|
||||
shell_->SetStyleMask(false, NSFullSizeContentViewWindowMask);
|
||||
[window setTitlebarAppearsTransparent:YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -236,7 +239,10 @@
|
||||
// Clears the delegate when window is going to be closed, since EL Capitan it
|
||||
// is possible that the methods of delegate would get called after the window
|
||||
// has been closed.
|
||||
[shell_->GetNativeWindow() setDelegate:nil];
|
||||
views::BridgedNativeWidget* bridged_view =
|
||||
views::NativeWidgetMac::GetBridgeForNativeWindow(
|
||||
shell_->GetNativeWindow());
|
||||
bridged_view->OnWindowWillClose();
|
||||
}
|
||||
|
||||
- (BOOL)windowShouldClose:(id)window {
|
||||
|
||||
@@ -40,7 +40,8 @@ class GtkMessageBox : public NativeWindowObserver {
|
||||
const std::string& message,
|
||||
const std::string& detail,
|
||||
const std::string& checkbox_label,
|
||||
bool checkbox_checked)
|
||||
bool checkbox_checked,
|
||||
const gfx::ImageSkia& icon)
|
||||
: cancel_id_(cancel_id),
|
||||
parent_(static_cast<NativeWindow*>(parent_window)) {
|
||||
// Create dialog.
|
||||
@@ -56,6 +57,21 @@ class GtkMessageBox : public NativeWindowObserver {
|
||||
if (!title.empty())
|
||||
gtk_window_set_title(GTK_WINDOW(dialog_), title.c_str());
|
||||
|
||||
if (!icon.isNull()) {
|
||||
// No easy way to obtain this programmatically, but GTK+'s docs
|
||||
// define GTK_ICON_SIZE_DIALOG to be 48 pixels
|
||||
static constexpr int pixel_width = 48;
|
||||
static constexpr int pixel_height = 48;
|
||||
GdkPixbuf* pixbuf = libgtkui::GdkPixbufFromSkBitmap(*icon.bitmap());
|
||||
GdkPixbuf* scaled_pixbuf = gdk_pixbuf_scale_simple(
|
||||
pixbuf, pixel_width, pixel_height, GDK_INTERP_BILINEAR);
|
||||
GtkWidget* w = gtk_image_new_from_pixbuf(scaled_pixbuf);
|
||||
gtk_message_dialog_set_image(GTK_MESSAGE_DIALOG(dialog_), w);
|
||||
gtk_widget_show(w);
|
||||
g_clear_pointer(&scaled_pixbuf, gdk_pixbuf_unref);
|
||||
g_clear_pointer(&pixbuf, gdk_pixbuf_unref);
|
||||
}
|
||||
|
||||
if (!checkbox_label.empty()) {
|
||||
GtkWidget* message_area =
|
||||
gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(dialog_));
|
||||
@@ -66,15 +82,15 @@ class GtkMessageBox : public NativeWindowObserver {
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_button),
|
||||
checkbox_checked);
|
||||
gtk_container_add(GTK_CONTAINER(message_area), check_button);
|
||||
gtk_widget_show(check_button);
|
||||
}
|
||||
|
||||
// Add buttons.
|
||||
GtkDialog* dialog = GTK_DIALOG(dialog_);
|
||||
for (size_t i = 0; i < buttons.size(); ++i) {
|
||||
GtkWidget* button = gtk_dialog_add_button(
|
||||
GTK_DIALOG(dialog_), TranslateToStock(i, buttons[i]), i);
|
||||
if (static_cast<int>(i) == default_id)
|
||||
gtk_widget_grab_focus(button);
|
||||
gtk_dialog_add_button(dialog, TranslateToStock(i, buttons[i]), i);
|
||||
}
|
||||
gtk_dialog_set_default_response(dialog, default_id);
|
||||
|
||||
// Parent window.
|
||||
if (parent_) {
|
||||
@@ -122,7 +138,7 @@ class GtkMessageBox : public NativeWindowObserver {
|
||||
}
|
||||
|
||||
void Show() {
|
||||
gtk_widget_show_all(dialog_);
|
||||
gtk_widget_show(dialog_);
|
||||
// We need to call gtk_window_present after making the widgets visible to
|
||||
// make sure window gets correctly raised and gets focus.
|
||||
int time = ui::X11EventSource::GetInstance()->GetTimestamp();
|
||||
@@ -195,9 +211,9 @@ int ShowMessageBox(NativeWindow* parent,
|
||||
const std::string& title,
|
||||
const std::string& message,
|
||||
const std::string& detail,
|
||||
const gfx::ImageSkia& /*icon*/) {
|
||||
const gfx::ImageSkia& icon) {
|
||||
return GtkMessageBox(parent, type, buttons, default_id, cancel_id, title,
|
||||
message, detail, "", false)
|
||||
message, detail, "", false, icon)
|
||||
.RunSynchronous();
|
||||
}
|
||||
|
||||
@@ -212,10 +228,10 @@ void ShowMessageBox(NativeWindow* parent,
|
||||
const std::string& detail,
|
||||
const std::string& checkbox_label,
|
||||
bool checkbox_checked,
|
||||
const gfx::ImageSkia& /*icon*/,
|
||||
const gfx::ImageSkia& icon,
|
||||
const MessageBoxCallback& callback) {
|
||||
(new GtkMessageBox(parent, type, buttons, default_id, cancel_id, title,
|
||||
message, detail, checkbox_label, checkbox_checked))
|
||||
message, detail, checkbox_label, checkbox_checked, icon))
|
||||
->RunAsynchronous(callback);
|
||||
}
|
||||
|
||||
@@ -223,7 +239,8 @@ void ShowErrorBox(const base::string16& title, const base::string16& content) {
|
||||
if (Browser::Get()->is_ready()) {
|
||||
GtkMessageBox(nullptr, MESSAGE_BOX_TYPE_ERROR, {"OK"}, -1, 0, "Error",
|
||||
base::UTF16ToUTF8(title).c_str(),
|
||||
base::UTF16ToUTF8(content).c_str(), "", false)
|
||||
base::UTF16ToUTF8(content).c_str(), "", false,
|
||||
gfx::ImageSkia())
|
||||
.RunSynchronous();
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
|
||||
@@ -97,11 +97,6 @@ NSAlert* CreateNSAlert(NativeWindow* parent_window,
|
||||
NSArray* ns_buttons = [alert buttons];
|
||||
int button_count = static_cast<int>([ns_buttons count]);
|
||||
|
||||
// Bind cancel id button to escape key if there is more than one button
|
||||
if (button_count > 1 && cancel_id >= 0 && cancel_id < button_count) {
|
||||
[[ns_buttons objectAtIndex:cancel_id] setKeyEquivalent:@"\e"];
|
||||
}
|
||||
|
||||
if (default_id >= 0 && default_id < button_count) {
|
||||
// Focus the button at default_id if the user opted to do so.
|
||||
// The first button added gets set as the default selected.
|
||||
@@ -110,6 +105,11 @@ NSAlert* CreateNSAlert(NativeWindow* parent_window,
|
||||
[[ns_buttons objectAtIndex:default_id] setKeyEquivalent:@"\r"];
|
||||
}
|
||||
|
||||
// Bind cancel id button to escape key if there is more than one button
|
||||
if (button_count > 1 && cancel_id >= 0 && cancel_id < button_count) {
|
||||
[[ns_buttons objectAtIndex:cancel_id] setKeyEquivalent:@"\e"];
|
||||
}
|
||||
|
||||
if (!checkbox_label.empty()) {
|
||||
alert.showsSuppressionButton = YES;
|
||||
alert.suppressionButton.title = base::SysUTF8ToNSString(checkbox_label);
|
||||
|
||||
@@ -41,9 +41,15 @@ const CGFloat kVerticalTitleMargin = 2;
|
||||
|
||||
@implementation StatusItemView
|
||||
|
||||
- (id)initWithImage:(NSImage*)image icon:(atom::TrayIconCocoa*)icon {
|
||||
image_.reset([image copy]);
|
||||
- (void)dealloc {
|
||||
trayIcon_ = nil;
|
||||
menuController_ = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id)initWithIcon:(atom::TrayIconCocoa*)icon {
|
||||
trayIcon_ = icon;
|
||||
menuController_ = nil;
|
||||
highlight_mode_ = atom::TrayIcon::HighlightMode::SELECTION;
|
||||
ignoreDoubleClickEvents_ = NO;
|
||||
forceHighlight_ = NO;
|
||||
@@ -89,6 +95,7 @@ const CGFloat kVerticalTitleMargin = 2;
|
||||
trackingArea_.reset();
|
||||
}
|
||||
[[NSStatusBar systemStatusBar] removeStatusItem:statusItem_];
|
||||
[statusItem_ setView:nil];
|
||||
statusItem_.reset();
|
||||
}
|
||||
|
||||
@@ -156,6 +163,8 @@ const CGFloat kVerticalTitleMargin = 2;
|
||||
|
||||
// The width of the icon.
|
||||
- (CGFloat)iconWidth {
|
||||
if (!image_ && title_)
|
||||
return kHorizontalMargin;
|
||||
CGFloat thickness = [[NSStatusBar systemStatusBar] thickness];
|
||||
CGFloat imageHeight = [image_ size].height;
|
||||
CGFloat imageWidth = [image_ size].width;
|
||||
@@ -424,7 +433,9 @@ const CGFloat kVerticalTitleMargin = 2;
|
||||
|
||||
namespace atom {
|
||||
|
||||
TrayIconCocoa::TrayIconCocoa() {}
|
||||
TrayIconCocoa::TrayIconCocoa() {
|
||||
status_item_view_.reset([[StatusItemView alloc] initWithIcon:this]);
|
||||
}
|
||||
|
||||
TrayIconCocoa::~TrayIconCocoa() {
|
||||
[status_item_view_ removeItem];
|
||||
@@ -433,12 +444,7 @@ TrayIconCocoa::~TrayIconCocoa() {
|
||||
}
|
||||
|
||||
void TrayIconCocoa::SetImage(const gfx::Image& image) {
|
||||
if (status_item_view_) {
|
||||
[status_item_view_ setImage:image.AsNSImage()];
|
||||
} else {
|
||||
status_item_view_.reset(
|
||||
[[StatusItemView alloc] initWithImage:image.AsNSImage() icon:this]);
|
||||
}
|
||||
[status_item_view_ setImage:image.IsEmpty() ? nil : image.AsNSImage()];
|
||||
}
|
||||
|
||||
void TrayIconCocoa::SetPressedImage(const gfx::Image& image) {
|
||||
@@ -474,11 +480,18 @@ void TrayIconCocoa::SetContextMenu(AtomMenuModel* menu_model) {
|
||||
// Substribe to MenuClosed event.
|
||||
if (menu_model_)
|
||||
menu_model_->RemoveObserver(this);
|
||||
menu_model->AddObserver(this);
|
||||
|
||||
// Create native menu.
|
||||
menu_.reset([[AtomMenuController alloc] initWithModel:menu_model
|
||||
useDefaultAccelerator:NO]);
|
||||
menu_model_ = menu_model;
|
||||
|
||||
if (menu_model) {
|
||||
menu_model->AddObserver(this);
|
||||
// Create native menu.
|
||||
menu_.reset([[AtomMenuController alloc] initWithModel:menu_model
|
||||
useDefaultAccelerator:NO]);
|
||||
} else {
|
||||
menu_.reset();
|
||||
}
|
||||
|
||||
[status_item_view_ setMenuController:menu_.get()];
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,19 @@
|
||||
|
||||
#include "atom/browser/ui/views/menu_bar.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/ui/views/menu_delegate.h"
|
||||
#include "atom/browser/ui/views/submenu_button.h"
|
||||
#include "ui/base/models/menu_model.h"
|
||||
#include "ui/views/background.h"
|
||||
#include "ui/views/layout/box_layout.h"
|
||||
|
||||
#if defined(USE_X11)
|
||||
#include "chrome/browser/ui/libgtkui/gtk_util.h"
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "ui/gfx/color_utils.h"
|
||||
#endif
|
||||
@@ -29,8 +36,8 @@ MenuBar::MenuBar(views::View* window)
|
||||
: background_color_(kDefaultColor), window_(window) {
|
||||
RefreshColorCache();
|
||||
UpdateViewColors();
|
||||
SetLayoutManager(std::make_unique<views::BoxLayout>(
|
||||
views::BoxLayout::kHorizontal));
|
||||
SetLayoutManager(
|
||||
std::make_unique<views::BoxLayout>(views::BoxLayout::kHorizontal));
|
||||
window_->GetFocusManager()->AddFocusChangeListener(this);
|
||||
}
|
||||
|
||||
@@ -121,13 +128,17 @@ void MenuBar::RefreshColorCache(const ui::NativeTheme* theme) {
|
||||
if (!theme)
|
||||
theme = ui::NativeTheme::GetInstanceForNativeUi();
|
||||
if (theme) {
|
||||
background_color_ =
|
||||
theme->GetSystemColor(ui::NativeTheme::kColorId_MenuBackgroundColor);
|
||||
#if defined(USE_X11)
|
||||
const std::string menubar_selector = "GtkMenuBar#menubar";
|
||||
background_color_ = libgtkui::GetBgColor(menubar_selector);
|
||||
|
||||
enabled_color_ = theme->GetSystemColor(
|
||||
ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor);
|
||||
disabled_color_ = theme->GetSystemColor(
|
||||
ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor);
|
||||
#else
|
||||
background_color_ =
|
||||
theme->GetSystemColor(ui::NativeTheme::kColorId_MenuBackgroundColor);
|
||||
#endif
|
||||
}
|
||||
#if defined(OS_WIN)
|
||||
|
||||
@@ -44,15 +44,14 @@ RootView::~RootView() {}
|
||||
void RootView::SetMenu(AtomMenuModel* menu_model) {
|
||||
if (menu_model == nullptr) {
|
||||
// Remove accelerators
|
||||
accelerator_table_.clear();
|
||||
GetFocusManager()->UnregisterAccelerators(this);
|
||||
UnregisterAcceleratorsWithFocusManager();
|
||||
// and menu bar.
|
||||
SetMenuBarVisibility(false);
|
||||
menu_bar_.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
RegisterAccelerators(menu_model);
|
||||
RegisterAcceleratorsWithFocusManager(menu_model);
|
||||
|
||||
// Do not show menu bar in frameless window.
|
||||
if (!window_->has_frame())
|
||||
@@ -178,12 +177,12 @@ bool RootView::AcceleratorPressed(const ui::Accelerator& accelerator) {
|
||||
accelerator);
|
||||
}
|
||||
|
||||
void RootView::RegisterAccelerators(AtomMenuModel* menu_model) {
|
||||
void RootView::RegisterAcceleratorsWithFocusManager(AtomMenuModel* menu_model) {
|
||||
if (!menu_model)
|
||||
return;
|
||||
// Clear previous accelerators.
|
||||
UnregisterAcceleratorsWithFocusManager();
|
||||
views::FocusManager* focus_manager = GetFocusManager();
|
||||
accelerator_table_.clear();
|
||||
focus_manager->UnregisterAccelerators(this);
|
||||
|
||||
// Register accelerators with focus manager.
|
||||
accelerator_util::GenerateAcceleratorTable(&accelerator_table_, menu_model);
|
||||
for (const auto& iter : accelerator_table_) {
|
||||
@@ -192,4 +191,10 @@ void RootView::RegisterAccelerators(AtomMenuModel* menu_model) {
|
||||
}
|
||||
}
|
||||
|
||||
void RootView::UnregisterAcceleratorsWithFocusManager() {
|
||||
views::FocusManager* focus_manager = GetFocusManager();
|
||||
accelerator_table_.clear();
|
||||
focus_manager->UnregisterAccelerators(this);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
||||
@@ -34,6 +34,9 @@ class RootView : public views::View {
|
||||
bool IsMenuBarVisible() const;
|
||||
void HandleKeyEvent(const content::NativeWebKeyboardEvent& event);
|
||||
void ResetAltState();
|
||||
// Register/Unregister accelerators supported by the menu model.
|
||||
void RegisterAcceleratorsWithFocusManager(AtomMenuModel* menu_model);
|
||||
void UnregisterAcceleratorsWithFocusManager();
|
||||
|
||||
// views::View:
|
||||
void Layout() override;
|
||||
@@ -42,9 +45,6 @@ class RootView : public views::View {
|
||||
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
||||
|
||||
private:
|
||||
// Register accelerators supported by the menu model.
|
||||
void RegisterAccelerators(AtomMenuModel* menu_model);
|
||||
|
||||
// Parent window, weak ref.
|
||||
NativeWindow* window_;
|
||||
|
||||
|
||||
@@ -109,6 +109,30 @@ void WebContentsPreferences::Merge(const base::DictionaryValue& extend) {
|
||||
dict_.MergeDictionary(&extend);
|
||||
}
|
||||
|
||||
bool WebContentsPreferences::GetPreloadPath(
|
||||
base::FilePath::StringType* path) const {
|
||||
DCHECK(path);
|
||||
base::FilePath::StringType preload;
|
||||
if (dict_.GetString(options::kPreloadScript, &preload)) {
|
||||
if (base::FilePath(preload).IsAbsolute()) {
|
||||
*path = std::move(preload);
|
||||
return true;
|
||||
} else {
|
||||
LOG(ERROR) << "preload script must have absolute path.";
|
||||
}
|
||||
} else if (dict_.GetString(options::kPreloadURL, &preload)) {
|
||||
// Translate to file path if there is "preload-url" option.
|
||||
base::FilePath preload_path;
|
||||
if (net::FileURLToFilePath(GURL(preload), &preload_path)) {
|
||||
*path = std::move(preload_path.value());
|
||||
return true;
|
||||
} else {
|
||||
LOG(ERROR) << "preload url must be file:// protocol.";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// static
|
||||
content::WebContents* WebContentsPreferences::GetWebContentsFromProcessID(
|
||||
int process_id) {
|
||||
@@ -171,19 +195,8 @@ void WebContentsPreferences::AppendCommandLineSwitches(
|
||||
|
||||
// The preload script.
|
||||
base::FilePath::StringType preload;
|
||||
if (dict_.GetString(options::kPreloadScript, &preload)) {
|
||||
if (base::FilePath(preload).IsAbsolute())
|
||||
command_line->AppendSwitchNative(switches::kPreloadScript, preload);
|
||||
else
|
||||
LOG(ERROR) << "preload script must have absolute path.";
|
||||
} else if (dict_.GetString(options::kPreloadURL, &preload)) {
|
||||
// Translate to file path if there is "preload-url" option.
|
||||
base::FilePath preload_path;
|
||||
if (net::FileURLToFilePath(GURL(preload), &preload_path))
|
||||
command_line->AppendSwitchPath(switches::kPreloadScript, preload_path);
|
||||
else
|
||||
LOG(ERROR) << "preload url must be file:// protocol.";
|
||||
}
|
||||
if (GetPreloadPath(&preload))
|
||||
command_line->AppendSwitchNative(switches::kPreloadScript, preload);
|
||||
|
||||
// Custom args for renderer process
|
||||
base::Value* customArgs;
|
||||
@@ -200,8 +213,13 @@ void WebContentsPreferences::AppendCommandLineSwitches(
|
||||
|
||||
// --background-color.
|
||||
std::string s;
|
||||
if (dict_.GetString(options::kBackgroundColor, &s))
|
||||
if (dict_.GetString(options::kBackgroundColor, &s)) {
|
||||
command_line->AppendSwitchASCII(switches::kBackgroundColor, s);
|
||||
} else if (!(dict_.GetBoolean(options::kOffscreen, &b) && b)) {
|
||||
// For non-OSR WebContents, we expect to have white background, see
|
||||
// https://github.com/electron/electron/issues/13764 for more.
|
||||
command_line->AppendSwitchASCII(switches::kBackgroundColor, "#fff");
|
||||
}
|
||||
|
||||
// --guest-instance-id, which is used to identify guest WebContents.
|
||||
int guest_instance_id = 0;
|
||||
@@ -313,6 +331,10 @@ void WebContentsPreferences::OverrideWebkitPrefs(
|
||||
std::string encoding;
|
||||
if (dict_.GetString("defaultEncoding", &encoding))
|
||||
prefs->default_encoding = encoding;
|
||||
|
||||
bool node_integration = false;
|
||||
dict_.GetBoolean(options::kNodeIntegration, &node_integration);
|
||||
prefs->node_integration = node_integration;
|
||||
}
|
||||
|
||||
bool WebContentsPreferences::GetInteger(const base::StringPiece& attribute_name,
|
||||
|
||||
@@ -48,6 +48,9 @@ class WebContentsPreferences
|
||||
// Modify the WebPreferences according to preferences.
|
||||
void OverrideWebkitPrefs(content::WebPreferences* prefs);
|
||||
|
||||
// Returns the preload script path.
|
||||
bool GetPreloadPath(base::FilePath::StringType* path) const;
|
||||
|
||||
// Returns the web preferences.
|
||||
base::DictionaryValue* dict() { return &dict_; }
|
||||
const base::DictionaryValue* dict() const { return &dict_; }
|
||||
|
||||
@@ -228,6 +228,9 @@ void WebContentsZoomController::DidFinishNavigation(
|
||||
}
|
||||
|
||||
void WebContentsZoomController::WebContentsDestroyed() {
|
||||
for (Observer& observer : observers_)
|
||||
observer.OnZoomControllerWebContentsDestroyed();
|
||||
|
||||
observers_.Clear();
|
||||
embedder_zoom_controller_ = nullptr;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ class WebContentsZoomController
|
||||
virtual void OnZoomLevelChanged(content::WebContents* web_contents,
|
||||
double level,
|
||||
bool is_temporary) {}
|
||||
virtual void OnZoomControllerWebContentsDestroyed() {}
|
||||
|
||||
protected:
|
||||
virtual ~Observer() {}
|
||||
|
||||
@@ -7,144 +7,60 @@
|
||||
#include "atom/browser/api/atom_api_web_contents.h"
|
||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||
#include "content/browser/web_contents/web_contents_impl.h"
|
||||
#include "content/public/browser/guest_host.h"
|
||||
#include "content/public/browser/navigation_handle.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "content/public/browser/render_widget_host.h"
|
||||
#include "content/public/browser/render_widget_host_view.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
WebViewGuestDelegate::WebViewGuestDelegate(content::WebContents* embedder,
|
||||
api::WebContents* api_web_contents)
|
||||
: embedder_web_contents_(embedder), api_web_contents_(api_web_contents) {}
|
||||
|
||||
const int kDefaultWidth = 300;
|
||||
const int kDefaultHeight = 300;
|
||||
|
||||
} // namespace
|
||||
|
||||
SetSizeParams::SetSizeParams() = default;
|
||||
SetSizeParams::~SetSizeParams() = default;
|
||||
|
||||
WebViewGuestDelegate::WebViewGuestDelegate() {}
|
||||
|
||||
WebViewGuestDelegate::~WebViewGuestDelegate() {}
|
||||
|
||||
void WebViewGuestDelegate::Initialize(api::WebContents* api_web_contents) {
|
||||
api_web_contents_ = api_web_contents;
|
||||
Observe(api_web_contents->GetWebContents());
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::Destroy() {
|
||||
// Give the content module an opportunity to perform some cleanup.
|
||||
ResetZoomController();
|
||||
guest_host_->WillDestroy();
|
||||
guest_host_ = nullptr;
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::SetSize(const SetSizeParams& params) {
|
||||
bool enable_auto_size =
|
||||
params.enable_auto_size ? *params.enable_auto_size : auto_size_enabled_;
|
||||
gfx::Size min_size = params.min_size ? *params.min_size : min_auto_size_;
|
||||
gfx::Size max_size = params.max_size ? *params.max_size : max_auto_size_;
|
||||
|
||||
if (params.normal_size)
|
||||
normal_size_ = *params.normal_size;
|
||||
|
||||
min_auto_size_ = min_size;
|
||||
min_auto_size_.SetToMin(max_size);
|
||||
max_auto_size_ = max_size;
|
||||
max_auto_size_.SetToMax(min_size);
|
||||
|
||||
enable_auto_size &= !min_auto_size_.IsEmpty() && !max_auto_size_.IsEmpty();
|
||||
|
||||
auto* rvh = web_contents()->GetRenderViewHost();
|
||||
if (enable_auto_size) {
|
||||
// Autosize is being enabled.
|
||||
rvh->EnableAutoResize(min_auto_size_, max_auto_size_);
|
||||
normal_size_.SetSize(0, 0);
|
||||
} else {
|
||||
// Autosize is being disabled.
|
||||
// Use default width/height if missing from partially defined normal size.
|
||||
if (normal_size_.width() && !normal_size_.height())
|
||||
normal_size_.set_height(GetDefaultSize().height());
|
||||
if (!normal_size_.width() && normal_size_.height())
|
||||
normal_size_.set_width(GetDefaultSize().width());
|
||||
|
||||
gfx::Size new_size;
|
||||
if (!normal_size_.IsEmpty()) {
|
||||
new_size = normal_size_;
|
||||
} else if (!guest_size_.IsEmpty()) {
|
||||
new_size = guest_size_;
|
||||
} else {
|
||||
new_size = GetDefaultSize();
|
||||
}
|
||||
|
||||
bool changed_due_to_auto_resize = false;
|
||||
if (auto_size_enabled_) {
|
||||
// Autosize was previously enabled.
|
||||
rvh->DisableAutoResize(new_size);
|
||||
changed_due_to_auto_resize = true;
|
||||
} else {
|
||||
// Autosize was already disabled.
|
||||
guest_host_->SizeContents(new_size);
|
||||
}
|
||||
|
||||
UpdateGuestSize(new_size, changed_due_to_auto_resize);
|
||||
}
|
||||
|
||||
auto_size_enabled_ = enable_auto_size;
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::ResizeDueToAutoResize(const gfx::Size& new_size) {
|
||||
UpdateGuestSize(new_size, auto_size_enabled_);
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::DidFinishNavigation(
|
||||
content::NavigationHandle* navigation_handle) {
|
||||
if (navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage()) {
|
||||
auto is_main_frame = navigation_handle->IsInMainFrame();
|
||||
auto url = navigation_handle->GetURL();
|
||||
api_web_contents_->Emit("load-commit", url, is_main_frame);
|
||||
}
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::DidDetach() {
|
||||
attached_ = false;
|
||||
WebViewGuestDelegate::~WebViewGuestDelegate() {
|
||||
ResetZoomController();
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::DidAttach(int guest_proxy_routing_id) {
|
||||
attached_ = true;
|
||||
api_web_contents_->Emit("did-attach");
|
||||
void WebViewGuestDelegate::AttachToIframe(
|
||||
content::WebContents* embedder_web_contents,
|
||||
int embedder_frame_id) {
|
||||
embedder_web_contents_ = embedder_web_contents;
|
||||
|
||||
int embedder_process_id =
|
||||
embedder_web_contents_->GetMainFrame()->GetProcess()->GetID();
|
||||
auto* embedder_frame =
|
||||
content::RenderFrameHost::FromID(embedder_process_id, embedder_frame_id);
|
||||
DCHECK_EQ(embedder_web_contents_,
|
||||
content::WebContents::FromRenderFrameHost(embedder_frame));
|
||||
|
||||
// Attach this inner WebContents |guest_web_contents| to the outer
|
||||
// WebContents |embedder_web_contents|. The outer WebContents's
|
||||
// frame |embedder_frame| hosts the inner WebContents.
|
||||
api_web_contents_->web_contents()->AttachToOuterWebContentsFrame(
|
||||
embedder_web_contents_, embedder_frame);
|
||||
|
||||
ResetZoomController();
|
||||
|
||||
embedder_zoom_controller_ =
|
||||
WebContentsZoomController::FromWebContents(embedder_web_contents_);
|
||||
auto* zoom_controller = api_web_contents_->GetZoomController();
|
||||
embedder_zoom_controller_->AddObserver(this);
|
||||
auto* zoom_controller = api_web_contents_->GetZoomController();
|
||||
zoom_controller->SetEmbedderZoomController(embedder_zoom_controller_);
|
||||
|
||||
api_web_contents_->Emit("did-attach");
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::DidDetach() {
|
||||
ResetZoomController();
|
||||
}
|
||||
|
||||
content::WebContents* WebViewGuestDelegate::GetOwnerWebContents() const {
|
||||
return embedder_web_contents_;
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::SetGuestHost(content::GuestHost* guest_host) {
|
||||
guest_host_ = guest_host;
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::WillAttach(
|
||||
content::WebContents* embedder_web_contents,
|
||||
int element_instance_id,
|
||||
bool is_full_page_plugin,
|
||||
const base::Closure& completion_callback) {
|
||||
embedder_web_contents_ = embedder_web_contents;
|
||||
is_full_page_plugin_ = is_full_page_plugin;
|
||||
completion_callback.Run();
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::OnZoomLevelChanged(
|
||||
content::WebContents* web_contents,
|
||||
double level,
|
||||
@@ -161,23 +77,8 @@ void WebViewGuestDelegate::OnZoomLevelChanged(
|
||||
}
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::UpdateGuestSize(const gfx::Size& new_size,
|
||||
bool due_to_auto_resize) {
|
||||
if (due_to_auto_resize)
|
||||
api_web_contents_->Emit("size-changed", guest_size_.width(),
|
||||
guest_size_.height(), new_size.width(),
|
||||
new_size.height());
|
||||
guest_size_ = new_size;
|
||||
}
|
||||
|
||||
gfx::Size WebViewGuestDelegate::GetDefaultSize() const {
|
||||
if (is_full_page_plugin_) {
|
||||
// Full page plugins default to the size of the owner's viewport.
|
||||
return embedder_web_contents_->GetRenderWidgetHostView()
|
||||
->GetVisibleViewportSize();
|
||||
} else {
|
||||
return gfx::Size(kDefaultWidth, kDefaultHeight);
|
||||
}
|
||||
void WebViewGuestDelegate::OnZoomControllerWebContentsDestroyed() {
|
||||
ResetZoomController();
|
||||
}
|
||||
|
||||
void WebViewGuestDelegate::ResetZoomController() {
|
||||
@@ -187,10 +88,6 @@ void WebViewGuestDelegate::ResetZoomController() {
|
||||
}
|
||||
}
|
||||
|
||||
bool WebViewGuestDelegate::CanBeEmbeddedInsideCrossProcessFrames() {
|
||||
return true;
|
||||
}
|
||||
|
||||
content::RenderWidgetHost* WebViewGuestDelegate::GetOwnerRenderWidgetHost() {
|
||||
return embedder_web_contents_->GetRenderViewHost()->GetWidget();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "atom/browser/web_contents_zoom_controller.h"
|
||||
#include "content/public/browser/browser_plugin_guest_delegate.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
@@ -15,80 +14,33 @@ namespace api {
|
||||
class WebContents;
|
||||
}
|
||||
|
||||
// A struct of parameters for SetSize(). The parameters are all declared as
|
||||
// scoped pointers since they are all optional. Null pointers indicate that the
|
||||
// parameter has not been provided, and the last used value should be used. Note
|
||||
// that when |enable_auto_size| is true, providing |normal_size| is not
|
||||
// meaningful. This is because the normal size of the guestview is overridden
|
||||
// whenever autosizing occurs.
|
||||
struct SetSizeParams {
|
||||
SetSizeParams();
|
||||
~SetSizeParams();
|
||||
|
||||
std::unique_ptr<bool> enable_auto_size;
|
||||
std::unique_ptr<gfx::Size> min_size;
|
||||
std::unique_ptr<gfx::Size> max_size;
|
||||
std::unique_ptr<gfx::Size> normal_size;
|
||||
};
|
||||
|
||||
class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
|
||||
public content::WebContentsObserver,
|
||||
public WebContentsZoomController::Observer {
|
||||
public:
|
||||
WebViewGuestDelegate();
|
||||
WebViewGuestDelegate(content::WebContents* embedder,
|
||||
api::WebContents* api_web_contents);
|
||||
~WebViewGuestDelegate() override;
|
||||
|
||||
void Initialize(api::WebContents* api_web_contents);
|
||||
|
||||
// Called when the WebContents is going to be destroyed.
|
||||
void Destroy();
|
||||
|
||||
// Used to toggle autosize mode for this GuestView, and set both the automatic
|
||||
// and normal sizes.
|
||||
void SetSize(const SetSizeParams& params);
|
||||
|
||||
// Invoked when the contents auto-resized and the container should match it.
|
||||
void ResizeDueToAutoResize(const gfx::Size& new_size);
|
||||
|
||||
// Return true if attached.
|
||||
bool IsAttached() const { return attached_; }
|
||||
// Attach to the iframe.
|
||||
void AttachToIframe(content::WebContents* embedder_web_contents,
|
||||
int embedder_frame_id);
|
||||
|
||||
protected:
|
||||
// content::WebContentsObserver:
|
||||
void DidFinishNavigation(
|
||||
content::NavigationHandle* navigation_handle) override;
|
||||
|
||||
// content::BrowserPluginGuestDelegate:
|
||||
void DidAttach(int guest_proxy_routing_id) final;
|
||||
void DidDetach() final;
|
||||
content::WebContents* GetOwnerWebContents() const final;
|
||||
void SetGuestHost(content::GuestHost* guest_host) final;
|
||||
void WillAttach(content::WebContents* embedder_web_contents,
|
||||
int element_instance_id,
|
||||
bool is_full_page_plugin,
|
||||
const base::Closure& completion_callback) final;
|
||||
bool CanBeEmbeddedInsideCrossProcessFrames() override;
|
||||
content::RenderWidgetHost* GetOwnerRenderWidgetHost() override;
|
||||
content::SiteInstance* GetOwnerSiteInstance() override;
|
||||
content::RenderWidgetHost* GetOwnerRenderWidgetHost() final;
|
||||
content::SiteInstance* GetOwnerSiteInstance() final;
|
||||
content::WebContents* CreateNewGuestWindow(
|
||||
const content::WebContents::CreateParams& create_params) override;
|
||||
const content::WebContents::CreateParams& create_params) final;
|
||||
|
||||
// WebContentsZoomController::Observer:
|
||||
void OnZoomLevelChanged(content::WebContents* web_contents,
|
||||
double level,
|
||||
bool is_temporary) override;
|
||||
void OnZoomControllerWebContentsDestroyed() override;
|
||||
|
||||
private:
|
||||
// This method is invoked when the contents auto-resized to give the container
|
||||
// an opportunity to match it if it wishes.
|
||||
//
|
||||
// This gives the derived class an opportunity to inform its container element
|
||||
// or perform other actions.
|
||||
void UpdateGuestSize(const gfx::Size& new_size, bool due_to_auto_resize);
|
||||
|
||||
// Returns the default size of the guestview.
|
||||
gfx::Size GetDefaultSize() const;
|
||||
|
||||
void ResetZoomController();
|
||||
|
||||
// The WebContents that attaches this guest view.
|
||||
@@ -98,34 +50,6 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
|
||||
// to subscribe for zoom changes.
|
||||
WebContentsZoomController* embedder_zoom_controller_ = nullptr;
|
||||
|
||||
// The size of the container element.
|
||||
gfx::Size element_size_;
|
||||
|
||||
// The size of the guest content. Note: In autosize mode, the container
|
||||
// element may not match the size of the guest.
|
||||
gfx::Size guest_size_;
|
||||
|
||||
// A pointer to the guest_host.
|
||||
content::GuestHost* guest_host_ = nullptr;
|
||||
|
||||
// Indicates whether autosize mode is enabled or not.
|
||||
bool auto_size_enabled_ = false;
|
||||
|
||||
// The maximum size constraints of the container element in autosize mode.
|
||||
gfx::Size max_auto_size_;
|
||||
|
||||
// The minimum size constraints of the container element in autosize mode.
|
||||
gfx::Size min_auto_size_;
|
||||
|
||||
// The size that will be used when autosize mode is disabled.
|
||||
gfx::Size normal_size_;
|
||||
|
||||
// Whether the guest view is inside a plugin document.
|
||||
bool is_full_page_plugin_ = false;
|
||||
|
||||
// Whether attached.
|
||||
bool attached_ = false;
|
||||
|
||||
api::WebContents* api_web_contents_ = nullptr;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(WebViewGuestDelegate);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user