Get hidden state by using parent window directly
This commit is contained in:
parent
69c69880e5
commit
583bb49f6c
6 changed files with 41 additions and 25 deletions
|
@ -14,22 +14,12 @@ using atom::WebContentsPreferences;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
atom::WebViewManager* GetWebViewManager(content::WebContents* web_contents) {
|
|
||||||
auto context = web_contents->GetBrowserContext();
|
|
||||||
if (context) {
|
|
||||||
auto manager = context->GetGuestManager();
|
|
||||||
return static_cast<atom::WebViewManager*>(manager);
|
|
||||||
} else {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddGuest(int guest_instance_id,
|
void AddGuest(int guest_instance_id,
|
||||||
int element_instance_id,
|
int element_instance_id,
|
||||||
content::WebContents* embedder,
|
content::WebContents* embedder,
|
||||||
content::WebContents* guest_web_contents,
|
content::WebContents* guest_web_contents,
|
||||||
const base::DictionaryValue& options) {
|
const base::DictionaryValue& options) {
|
||||||
auto manager = GetWebViewManager(embedder);
|
auto manager = atom::WebViewManager::GetWebViewManager(embedder);
|
||||||
if (manager)
|
if (manager)
|
||||||
manager->AddGuest(guest_instance_id, element_instance_id, embedder,
|
manager->AddGuest(guest_instance_id, element_instance_id, embedder,
|
||||||
guest_web_contents);
|
guest_web_contents);
|
||||||
|
@ -38,7 +28,7 @@ void AddGuest(int guest_instance_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveGuest(content::WebContents* embedder, int guest_instance_id) {
|
void RemoveGuest(content::WebContents* embedder, int guest_instance_id) {
|
||||||
auto manager = GetWebViewManager(embedder);
|
auto manager = atom::WebViewManager::GetWebViewManager(embedder);
|
||||||
if (manager)
|
if (manager)
|
||||||
manager->RemoveGuest(guest_instance_id);
|
manager->RemoveGuest(guest_instance_id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
|
#include "atom/browser/web_view_manager.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"
|
||||||
|
@ -155,19 +156,23 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
|
||||||
command_line->AppendSwitchASCII(::switches::kEnableBlinkFeatures,
|
command_line->AppendSwitchASCII(::switches::kEnableBlinkFeatures,
|
||||||
blink_features);
|
blink_features);
|
||||||
|
|
||||||
// The initial visibility state.
|
|
||||||
NativeWindow* window = NativeWindow::FromWebContents(web_contents);
|
NativeWindow* window = NativeWindow::FromWebContents(web_contents);
|
||||||
|
|
||||||
|
// Inherit initial visibilty state from parent window in webviews
|
||||||
|
if (guest_instance_id && !window) {
|
||||||
|
auto manager = WebViewManager::GetWebViewManager(web_contents);
|
||||||
|
if (manager) {
|
||||||
|
content::WebContents* embedder = manager->GetEmbedder(guest_instance_id);
|
||||||
|
if (embedder)
|
||||||
|
window = NativeWindow::FromWebContents(embedder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The initial visibility state.
|
||||||
if (window) {
|
if (window) {
|
||||||
bool visible = window->IsVisible() && !window->IsMinimized();
|
bool visible = window->IsVisible() && !window->IsMinimized();
|
||||||
if (!visible) // Default state is visible.
|
if (!visible) // Default state is visible.
|
||||||
command_line->AppendSwitch(switches::kHiddenPage);
|
command_line->AppendSwitch(switches::kHiddenPage);
|
||||||
} else {
|
|
||||||
// Inherit initial visibilty state from parent window in webviews
|
|
||||||
bool hidden_page;
|
|
||||||
if (web_preferences.GetBoolean(options::kHiddenPage, &hidden_page) &&
|
|
||||||
hidden_page) {
|
|
||||||
command_line->AppendSwitch(switches::kHiddenPage);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
#include "atom/browser/atom_browser_context.h"
|
#include "atom/browser/atom_browser_context.h"
|
||||||
#include "content/public/browser/render_process_host.h"
|
#include "content/public/browser/render_process_host.h"
|
||||||
#include "content/public/browser/web_contents.h"
|
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -42,6 +41,13 @@ void WebViewManager::RemoveGuest(int guest_instance_id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content::WebContents* WebViewManager::GetEmbedder(int guest_instance_id) {
|
||||||
|
if (ContainsKey(web_contents_embedder_map_, guest_instance_id))
|
||||||
|
return web_contents_embedder_map_[guest_instance_id].embedder;
|
||||||
|
else
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
content::WebContents* WebViewManager::GetGuestByInstanceID(
|
content::WebContents* WebViewManager::GetGuestByInstanceID(
|
||||||
int owner_process_id,
|
int owner_process_id,
|
||||||
int element_instance_id) {
|
int element_instance_id) {
|
||||||
|
@ -65,4 +71,16 @@ bool WebViewManager::ForEachGuest(content::WebContents* embedder_web_contents,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
WebViewManager* WebViewManager::GetWebViewManager(content::WebContents* web_contents) {
|
||||||
|
auto context = web_contents->GetBrowserContext();
|
||||||
|
if (context) {
|
||||||
|
auto manager = context->GetGuestManager();
|
||||||
|
return static_cast<atom::WebViewManager*>(manager);
|
||||||
|
} else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "content/public/browser/browser_plugin_guest_manager.h"
|
#include "content/public/browser/browser_plugin_guest_manager.h"
|
||||||
|
#include "content/public/browser/web_contents.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -22,6 +23,10 @@ class WebViewManager : public content::BrowserPluginGuestManager {
|
||||||
content::WebContents* web_contents);
|
content::WebContents* web_contents);
|
||||||
void RemoveGuest(int guest_instance_id);
|
void RemoveGuest(int guest_instance_id);
|
||||||
|
|
||||||
|
content::WebContents* GetEmbedder(int guest_instance_id);
|
||||||
|
|
||||||
|
static WebViewManager* GetWebViewManager(content::WebContents* web_contents);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// content::BrowserPluginGuestManager:
|
// content::BrowserPluginGuestManager:
|
||||||
content::WebContents* GetGuestByInstanceID(int owner_process_id,
|
content::WebContents* GetGuestByInstanceID(int owner_process_id,
|
||||||
|
|
|
@ -181,8 +181,7 @@ var attachGuest = function (embedder, elementInstanceId, guestInstanceId, params
|
||||||
plugins: params.plugins,
|
plugins: params.plugins,
|
||||||
zoomFactor: params.zoomFactor,
|
zoomFactor: params.zoomFactor,
|
||||||
webSecurity: !params.disablewebsecurity,
|
webSecurity: !params.disablewebsecurity,
|
||||||
blinkFeatures: params.blinkfeatures,
|
blinkFeatures: params.blinkfeatures
|
||||||
hiddenPage: params.hiddenPage
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.preload) {
|
if (params.preload) {
|
||||||
|
|
|
@ -230,8 +230,7 @@ var WebViewImpl = (function () {
|
||||||
params = {
|
params = {
|
||||||
instanceId: this.viewInstanceId,
|
instanceId: this.viewInstanceId,
|
||||||
userAgentOverride: this.userAgentOverride,
|
userAgentOverride: this.userAgentOverride,
|
||||||
zoomFactor: webFrame.getZoomFactor(),
|
zoomFactor: webFrame.getZoomFactor()
|
||||||
hiddenPage: document.hidden
|
|
||||||
}
|
}
|
||||||
ref1 = this.attributes
|
ref1 = this.attributes
|
||||||
for (attributeName in ref1) {
|
for (attributeName in ref1) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue