Merge pull request #5086 from electron/no-throttling

Add backgroundThrottling option to webPreferences
This commit is contained in:
Cheng Zhao 2016-04-08 16:25:09 +09:00
commit 5ff97317fe
5 changed files with 25 additions and 7 deletions

View file

@ -19,6 +19,7 @@
#include "atom/browser/web_view_guest_delegate.h"
#include "atom/common/api/api_messages.h"
#include "atom/common/api/event_emitter_caller.h"
#include "atom/common/mouse_util.h"
#include "atom/common/native_mate_converters/blink_converter.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/content_converter.h"
@ -28,13 +29,14 @@
#include "atom/common/native_mate_converters/image_converter.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/mouse_util.h"
#include "atom/common/options_switches.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "brightray/browser/inspectable_web_contents.h"
#include "brightray/browser/inspectable_web_contents_view.h"
#include "chrome/browser/printing/print_view_manager_basic.h"
#include "chrome/browser/printing/print_preview_message_handler.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/common/view_messages.h"
#include "content/public/browser/favicon_status.h"
#include "content/public/browser/native_web_keyboard_event.h"
@ -212,7 +214,9 @@ content::ServiceWorkerContext* GetServiceWorkerContext(
WebContents::WebContents(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
type_(REMOTE) {
type_(REMOTE),
request_id_(0),
background_throttling_(true) {
AttachAsUserData(web_contents);
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
}
@ -220,7 +224,11 @@ WebContents::WebContents(content::WebContents* web_contents)
WebContents::WebContents(v8::Isolate* isolate,
const mate::Dictionary& options)
: embedder_(nullptr),
request_id_(0) {
request_id_(0),
background_throttling_(true) {
// Read options.
options.Get("backgroundThrottling", &background_throttling_);
// Whether it is a guest WebContents.
bool is_guest = false;
options.Get("isGuest", &is_guest);
@ -744,8 +752,13 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
// override the background color set by the user.
// We have to call it right after LoadURL because the RenderViewHost is only
// created after loading a page.
web_contents()->GetRenderViewHost()->GetWidget()->GetView()
->SetBackgroundColor(SK_ColorTRANSPARENT);
const auto view = web_contents()->GetRenderWidgetHostView();
view->SetBackgroundColor(SK_ColorTRANSPARENT);
// For the same reason we can only disable hidden here.
const auto host = static_cast<content::RenderWidgetHostImpl*>(
view->GetRenderWidgetHost());
host->disable_hidden_ = !background_throttling_;
}
void WebContents::DownloadURL(const GURL& url) {

View file

@ -296,6 +296,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
// Request id used for findInPage request.
uint32_t request_id_;
// Whether background throttling is disabled.
bool background_throttling_;
DISALLOW_COPY_AND_ASSIGN(WebContents);
};

View file

@ -179,6 +179,8 @@ The `webPreferences` option is an object that can have following properties:
* `defaultMonospaceFontSize` Integer - Defaults to `13`.
* `minimumFontSize` Integer - Defaults to `0`.
* `defaultEncoding` String - Defaults to `ISO-8859-1`.
* `backgroundThrottling` Boolean - Whether to throttle animations and timers
when the page becomes background. Defaults to `true`.
## Events

View file

@ -8,7 +8,7 @@ import sys
BASE_URL = os.getenv('LIBCHROMIUMCONTENT_MIRROR') or \
'https://s3.amazonaws.com/github-janky-artifacts/libchromiumcontent'
LIBCHROMIUMCONTENT_COMMIT = '9229f39b44ca1dde25db9c648547861286b61935'
LIBCHROMIUMCONTENT_COMMIT = '4e506867ad95907e0a9cbec4ab3ee0f84214de94'
PLATFORM = {
'cygwin': 'win32',

View file

@ -83,7 +83,7 @@ app.on('ready', function () {
width: 800,
height: 600,
webPreferences: {
javascript: true // Test whether web preferences crashes.
backgroundThrottling: false,
}
})
window.loadURL(url.format({