Skip to content

Commit d67b470

Browse files
author
Cong Liu
committed
Fixed window size not working when using window.open
1 parent 37cec06 commit d67b470

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/nw_package.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ std::wstring ASCIIToWide(const std::string& ascii) {
132132
Package::Package()
133133
: path_(GetSelfPath()),
134134
self_extract_(true) {
135+
135136
// First try to extract self.
136137
if (InitFromPath())
137138
return;
@@ -338,15 +339,20 @@ void Package::InitWithDefault() {
338339
root_.reset(new base::DictionaryValue());
339340
root()->SetString(switches::kmName, "node-webkit");
340341
root()->SetString(switches::kmMain, "nw:blank");
342+
root()->Set(switches::kmWindow, GetNewWindow());
343+
}
344+
345+
base::DictionaryValue* Package::GetNewWindow() {
341346
base::DictionaryValue* window = new base::DictionaryValue();
342-
root()->Set(switches::kmWindow, window);
343347

344348
// Hide toolbar if specifed in the command line.
345349
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoToolbar))
346350
window->SetBoolean(switches::kmToolbar, false);
347351

348352
// Window should show in center by default.
349353
window->SetString(switches::kmPosition, "center");
354+
355+
return window;
350356
}
351357

352358
bool Package::ExtractPath() {

src/nw_package.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class Package {
8181
// Manifest string.
8282
std::string package_string() { return package_string_; }
8383

84+
base::DictionaryValue* GetNewWindow();
85+
8486
private:
8587
bool InitFromPath();
8688
void InitWithDefault();

src/nw_shell.cc

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -569,27 +569,36 @@ void Shell::WebContentsCreated(WebContents* source_contents,
569569
const GURL& target_url,
570570
WebContents* new_contents,
571571
const base::string16& nw_window_manifest) {
572+
573+
bool overwrite_manifest = true;
574+
572575
// Create with package's manifest
573576
scoped_ptr<base::DictionaryValue> manifest(
574-
GetPackage()->window()->DeepCopy());
577+
GetPackage()->GetNewWindow());
575578

576579
scoped_ptr<base::Value> val;
577580
std::string manifest_str = base::UTF16ToUTF8(nw_window_manifest);
578581
val.reset(base::JSONReader().ReadToValue(manifest_str));
579-
if (val.get() && val->IsType(base::Value::TYPE_DICTIONARY))
582+
if (val.get() && val->IsType(base::Value::TYPE_DICTIONARY)) {
580583
manifest.reset(static_cast<base::DictionaryValue*>(val.release()));
584+
overwrite_manifest = false;
585+
}
581586

582587
// Get window features
583588
blink::WebWindowFeatures features = new_contents->GetWindowFeatures();
584-
manifest->SetBoolean(switches::kmResizable, features.resizable);
585-
manifest->SetBoolean(switches::kmFullscreen, features.fullscreen);
586-
if (features.widthSet)
589+
if (overwrite_manifest || !manifest->HasKey(switches::kmResizable))
590+
manifest->SetBoolean(switches::kmResizable, features.resizable);
591+
if (overwrite_manifest || !manifest->HasKey(switches::kmFullscreen))
592+
manifest->SetBoolean(switches::kmFullscreen, features.fullscreen);
593+
if (overwrite_manifest || !manifest->HasKey(switches::kmToolbar))
594+
manifest->SetBoolean(switches::kmToolbar, features.toolBarVisible);
595+
if (features.widthSet && (overwrite_manifest || !manifest->HasKey(switches::kmWidth)))
587596
manifest->SetInteger(switches::kmWidth, features.width);
588-
if (features.heightSet)
597+
if (features.heightSet && (overwrite_manifest || !manifest->HasKey(switches::kmHeight)))
589598
manifest->SetInteger(switches::kmHeight, features.height);
590-
if (features.xSet)
599+
if (features.xSet && (overwrite_manifest || !manifest->HasKey(switches::kmX)))
591600
manifest->SetInteger(switches::kmX, features.x);
592-
if (features.ySet)
601+
if (features.ySet && (overwrite_manifest || !manifest->HasKey(switches::kmY)))
593602
manifest->SetInteger(switches::kmY, features.y);
594603
// window.open should show the window by default.
595604
manifest->SetBoolean(switches::kmShow, true);

0 commit comments

Comments
 (0)