Avoid adding a new option to webPreferences

This commit is contained in:
Cheng Zhao 2016-04-14 10:50:07 +09:00
parent 8f0e594007
commit 31eb793fb0
8 changed files with 8 additions and 28 deletions

View file

@ -1127,12 +1127,6 @@ bool WebContents::IsGuest() const {
return type_ == WEB_VIEW; return type_ == WEB_VIEW;
} }
void WebContents::MergeWebPreferences(const base::DictionaryValue& extend) {
WebContentsPreferences* web_preferences =
WebContentsPreferences::FromWebContents(web_contents());
web_preferences->Merge(extend);
}
v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) { v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
WebContentsPreferences* web_preferences = WebContentsPreferences* web_preferences =
WebContentsPreferences::FromWebContents(web_contents()); WebContentsPreferences::FromWebContents(web_contents());
@ -1227,7 +1221,6 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
.SetMethod("endFrameSubscription", &WebContents::EndFrameSubscription) .SetMethod("endFrameSubscription", &WebContents::EndFrameSubscription)
.SetMethod("setSize", &WebContents::SetSize) .SetMethod("setSize", &WebContents::SetSize)
.SetMethod("isGuest", &WebContents::IsGuest) .SetMethod("isGuest", &WebContents::IsGuest)
.SetMethod("mergeWebPreferences", &WebContents::MergeWebPreferences)
.SetMethod("getWebPreferences", &WebContents::GetWebPreferences) .SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
.SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow) .SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow)
.SetMethod("hasServiceWorker", &WebContents::HasServiceWorker) .SetMethod("hasServiceWorker", &WebContents::HasServiceWorker)

View file

@ -144,7 +144,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
WindowOpenDisposition disposition); WindowOpenDisposition disposition);
// Returns the web preferences of current WebContents. // Returns the web preferences of current WebContents.
void MergeWebPreferences(const base::DictionaryValue& extend);
v8::Local<v8::Value> GetWebPreferences(v8::Isolate* isolate); v8::Local<v8::Value> GetWebPreferences(v8::Isolate* isolate);
// Returns the owner window. // Returns the owner window.

View file

@ -8,6 +8,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "atom/browser/native_window.h"
#include "atom/common/native_mate_converters/value_converter.h" #include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/options_switches.h" #include "atom/common/options_switches.h"
#include "base/command_line.h" #include "base/command_line.h"
@ -147,9 +148,12 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
blink_features); blink_features);
// The initial visibility state. // The initial visibility state.
std::string visibility; NativeWindow* window = NativeWindow::FromWebContents(web_contents);
if (web_preferences.GetString(options::kVisibilityState, &visibility)) if (window) {
command_line->AppendSwitchASCII(switches::kVisibilityState, visibility); bool visible = window->IsVisible() && !window->IsMinimized();
if (!visible) // Default state is visible.
command_line->AppendSwitch("hidden-page");
}
} }
// static // static

View file

@ -106,9 +106,6 @@ const char kOpenerID[] = "openerId";
// Enable blink features. // Enable blink features.
const char kBlinkFeatures[] = "blinkFeatures"; const char kBlinkFeatures[] = "blinkFeatures";
// The initiali visibility state.
const char kVisibilityState[] = "visibilityState";
} // namespace options } // namespace options
namespace switches { namespace switches {
@ -152,7 +149,6 @@ const char kPreloadURL[] = "preload-url";
const char kNodeIntegration[] = "node-integration"; const char kNodeIntegration[] = "node-integration";
const char kGuestInstanceID[] = "guest-instance-id"; const char kGuestInstanceID[] = "guest-instance-id";
const char kOpenerID[] = "opener-id"; const char kOpenerID[] = "opener-id";
const char kVisibilityState[] = "visibility-state";
// Widevine options // Widevine options
// Path to Widevine CDM binaries. // Path to Widevine CDM binaries.

View file

@ -56,7 +56,6 @@ extern const char kGuestInstanceID[];
extern const char kExperimentalFeatures[]; extern const char kExperimentalFeatures[];
extern const char kExperimentalCanvasFeatures[]; extern const char kExperimentalCanvasFeatures[];
extern const char kOpenerID[]; extern const char kOpenerID[];
extern const char kVisibilityState[];
extern const char kBlinkFeatures[]; extern const char kBlinkFeatures[];
} // namespace options } // namespace options
@ -84,7 +83,6 @@ extern const char kPreloadURL[];
extern const char kNodeIntegration[]; extern const char kNodeIntegration[];
extern const char kGuestInstanceID[]; extern const char kGuestInstanceID[];
extern const char kOpenerID[]; extern const char kOpenerID[];
extern const char kVisibilityState[];
extern const char kWidevineCdmPath[]; extern const char kWidevineCdmPath[];
extern const char kWidevineCdmVersion[]; extern const char kWidevineCdmVersion[];

View file

@ -93,11 +93,6 @@ BrowserWindow.prototype._init = function () {
this.on('restore', visibilityChanged) this.on('restore', visibilityChanged)
this.on('maximize', visibilityChanged) this.on('maximize', visibilityChanged)
// Make renderer process have correct initial state.
if (!isVisible) {
this.webContents.mergeWebPreferences({visibilityState: 'hidden'})
}
// Notify the creation of the window. // Notify the creation of the window.
app.emit('browser-window-created', {}, this) app.emit('browser-window-created', {}, this)

View file

@ -58,8 +58,6 @@ for (let arg of process.argv) {
nodeIntegration = arg.substr(arg.indexOf('=') + 1) nodeIntegration = arg.substr(arg.indexOf('=') + 1)
} else if (arg.indexOf('--preload=') === 0) { } else if (arg.indexOf('--preload=') === 0) {
preloadScript = arg.substr(arg.indexOf('=') + 1) preloadScript = arg.substr(arg.indexOf('=') + 1)
} else if (arg.indexOf('--visibility-state=') === 0) {
process.visibilityState = arg.substr(arg.indexOf('=') + 1)
} }
} }

View file

@ -225,10 +225,7 @@ Object.defineProperty(window.history, 'length', {
}) })
// The initial visibilityState. // The initial visibilityState.
let cachedVisibilityState = 'visible' let cachedVisibilityState = process.argv.includes('--hidden-page') ? 'hidden' : 'visible'
if (process.visibilityState) {
cachedVisibilityState = process.visibilityState
}
// Subscribe to visibilityState changes. // Subscribe to visibilityState changes.
ipcRenderer.on('ELECTRON_RENDERER_WINDOW_VISIBILITY_CHANGE', function (event, visibilityState) { ipcRenderer.on('ELECTRON_RENDERER_WINDOW_VISIBILITY_CHANGE', function (event, visibilityState) {