+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/browser/parse-features-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ const keysOfTypeNumberCompileTimeCheck: { [K in IntegerBrowserWindowOptionKeys]
};
// Note `top` / `left` are special cases from the browser which we later convert
// to y / x.
const keysOfTypeNumber = new Set(['top', 'left', ...Object.keys(keysOfTypeNumberCompileTimeCheck)]);
// NOTE(@mlaurencin) `innerWidth` / `innerHeight` are also special cases. The spec
// states that `width` and `height` represent the window content size and are equivalent
// to `innerWidth` / `innerHeight`. However, our implementation currently incorrectly maps
// `width` and `height` to `outerWidth` and `outerHeight`, or the size of the window
// with all border and related window chrome.
const keysOfTypeNumber = new Set(['top', 'left', 'innerWidth', 'innerHeight', ...Object.keys(keysOfTypeNumberCompileTimeCheck)]);

/**
* Note that we only allow "0" and "1" boolean conversion when the type is known
Expand Down
16 changes: 16 additions & 0 deletions shell/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,22 @@ static bool FromV8(v8::Isolate* isolate,
// Resize to content bounds.
bool use_content_size = false;
options.Get(options::kUseContentSize, &use_content_size);
// NOTE(@mlaurencin) Spec requirements can be found here:
// https://developer.mozilla.org/en-US/docs/Web/API/Window/open#width
constexpr int kMinSizeReqdBySpec = 100;
int inner_width = 0;
int inner_height = 0;

options.Get(options::kinnerWidth, &inner_width);
options.Get(options::kinnerHeight, &inner_height);
if (inner_width || inner_height) {
use_content_size = true;
if (inner_width)
width = std::max(kMinSizeReqdBySpec, inner_width);
if (inner_height)
height = std::max(kMinSizeReqdBySpec, inner_height);
}

if (!has_frame() || use_content_size)
SetContentSize(gfx::Size(width, height));

Expand Down
22 changes: 19 additions & 3 deletions shell/browser/native_window_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
options.Get(options::kWidth, &width);
options.Get(options::kHeight, &height);
gfx::Rect bounds(0, 0, width, height);

widget_size_ = bounds.size();

widget()->AddObserver(this);
Expand Down Expand Up @@ -409,10 +410,25 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
// Default content view.
SetContentView(new views::View());

options.Get(options::kUseContentSize, &use_content_size_);

// NOTE(@mlaurencin) Spec requirements can be found here:
// https://developer.mozilla.org/en-US/docs/Web/API/Window/open#width
int kMinSizeReqdBySpec = 100;
int inner_width = 0;
int inner_height = 0;
options.Get(options::kinnerWidth, &inner_width);
options.Get(options::kinnerHeight, &inner_height);
if (inner_width || inner_height) {
use_content_size_ = true;
if (inner_width)
bounds.set_width(std::max(kMinSizeReqdBySpec, inner_width));
if (inner_height)
bounds.set_height(std::max(kMinSizeReqdBySpec, inner_height));
}

gfx::Size size = bounds.size();
if (has_frame() &&
options.Get(options::kUseContentSize, &use_content_size_) &&
use_content_size_)
if (has_frame() && use_content_size_)
size = ContentBoundsToWindowBounds(gfx::Rect(size)).size();

widget()->CenterWindow(size);
Expand Down
2 changes: 2 additions & 0 deletions shell/common/options_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ inline constexpr std::string_view kMinWidth = "minWidth";
inline constexpr std::string_view kMinHeight = "minHeight";
inline constexpr std::string_view kMaxWidth = "maxWidth";
inline constexpr std::string_view kMaxHeight = "maxHeight";
inline constexpr std::string_view kinnerWidth = "innerWidth";
inline constexpr std::string_view kinnerHeight = "innerHeight";
inline constexpr std::string_view kResizable = "resizable";
inline constexpr std::string_view kMovable = "movable";
inline constexpr std::string_view kMinimizable = "minimizable";
Expand Down
35 changes: 35 additions & 0 deletions spec/chromium-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,41 @@ describe('chromium features', () => {
expect(eventData).to.equal('size: 350 450');
});

it('window opened with innerWidth option has the same innerWidth', async () => {
const w = new BrowserWindow({ show: false });
w.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
const windowUrl = `file://${fixturesPath}/pages/window-open-size-inner.html`;
const windowCreatedPromise = once(app, 'browser-window-created') as Promise<[any, BrowserWindow]>;
const eventDataPromise = w.webContents.executeJavaScript(`(async () => {
const message = new Promise(resolve => window.addEventListener('message', resolve, { once: true }));
b = window.open(${JSON.stringify(windowUrl)}, '', 'show=no,innerWidth=400,height=450');
const e = await message;
b.close();
return e.data;
})()`);
const [[, newWindow], eventData] = await Promise.all([windowCreatedPromise, eventDataPromise]);

expect(newWindow.getContentSize().toString()).to.equal('400,450');
expect(eventData).to.equal('size: 400 450');
});
it('window opened with innerHeight option has the same innerHeight', async () => {
const w = new BrowserWindow({ show: false });
w.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
const windowUrl = `file://${fixturesPath}/pages/window-open-size-inner.html`;
const windowCreatedPromise = once(app, 'browser-window-created') as Promise<[any, BrowserWindow]>;
const eventDataPromise = w.webContents.executeJavaScript(`(async () => {
const message = new Promise(resolve => window.addEventListener('message', resolve, {once: true}));
const b = window.open(${JSON.stringify(windowUrl)}, '', 'show=no,width=350,innerHeight=400')
const e = await message;
b.close();
return e.data;
})()`);
const [[, newWindow], eventData] = await Promise.all([windowCreatedPromise, eventDataPromise]);

expect(newWindow.getContentSize().toString()).to.equal('350,400');
expect(eventData).to.equal('size: 350 400');
});

it('loads preload script after setting opener to null', async () => {
const w = new BrowserWindow({ show: false });
w.webContents.setWindowOpenHandler(() => ({
Expand Down
7 changes: 7 additions & 0 deletions spec/fixtures/pages/window-open-size-inner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
window.opener.postMessage('size: ' + innerWidth + ' ' + innerHeight, '*')
</script>
</body>
</html>
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载