зеркало из https://github.com/electron/electron.git
Pending renderer process no longer has render view attached
This commit is contained in:
Родитель
6de9c4332f
Коммит
bfc6d77bb3
|
@ -203,13 +203,8 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
|||
|
||||
// Certain render process will be created with no associated render view,
|
||||
// for example: ServiceWorker.
|
||||
auto rvh = content::RenderViewHost::FromID(process_id, kDefaultRoutingID);
|
||||
if (!rvh)
|
||||
return;
|
||||
|
||||
// Get the WebContents of the render process.
|
||||
content::WebContents* web_contents =
|
||||
content::WebContents::FromRenderViewHost(rvh);
|
||||
WebContentsPreferences::GetWebContentsFromProcessID(process_id);
|
||||
if (!web_contents)
|
||||
return;
|
||||
|
||||
|
|
|
@ -4,12 +4,15 @@
|
|||
|
||||
#include "atom/browser/web_contents_preferences.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "content/public/common/web_preferences.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
|
@ -23,9 +26,13 @@ DEFINE_WEB_CONTENTS_USER_DATA_KEY(atom::WebContentsPreferences);
|
|||
|
||||
namespace atom {
|
||||
|
||||
// static
|
||||
std::vector<WebContentsPreferences*> WebContentsPreferences::instances_;
|
||||
|
||||
WebContentsPreferences::WebContentsPreferences(
|
||||
content::WebContents* web_contents,
|
||||
const mate::Dictionary& web_preferences) {
|
||||
const mate::Dictionary& web_preferences)
|
||||
: web_contents_(web_contents) {
|
||||
v8::Isolate* isolate = web_preferences.isolate();
|
||||
mate::Dictionary copied(isolate, web_preferences.GetHandle()->Clone());
|
||||
// Following fields should not be stored.
|
||||
|
@ -35,15 +42,31 @@ WebContentsPreferences::WebContentsPreferences(
|
|||
|
||||
mate::ConvertFromV8(isolate, copied.GetHandle(), &web_preferences_);
|
||||
web_contents->SetUserData(UserDataKey(), this);
|
||||
|
||||
instances_.push_back(this);
|
||||
}
|
||||
|
||||
WebContentsPreferences::~WebContentsPreferences() {
|
||||
instances_.erase(
|
||||
std::remove(instances_.begin(), instances_.end(), this),
|
||||
instances_.end());
|
||||
}
|
||||
|
||||
void WebContentsPreferences::Merge(const base::DictionaryValue& extend) {
|
||||
web_preferences_.MergeDictionary(&extend);
|
||||
}
|
||||
|
||||
// static
|
||||
content::WebContents* WebContentsPreferences::GetWebContentsFromProcessID(
|
||||
int process_id) {
|
||||
for (WebContentsPreferences* preferences : instances_) {
|
||||
content::WebContents* web_contents = preferences->web_contents_;
|
||||
if (web_contents->GetRenderProcessHost()->GetID() == process_id)
|
||||
return web_contents;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// static
|
||||
void WebContentsPreferences::AppendExtraCommandLineSwitches(
|
||||
content::WebContents* web_contents, base::CommandLine* command_line) {
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#ifndef ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_
|
||||
#define ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/values.h"
|
||||
#include "content/public/browser/web_contents_user_data.h"
|
||||
|
||||
|
@ -26,6 +28,9 @@ namespace atom {
|
|||
class WebContentsPreferences
|
||||
: public content::WebContentsUserData<WebContentsPreferences> {
|
||||
public:
|
||||
// Get WebContents according to process ID.
|
||||
static content::WebContents* GetWebContentsFromProcessID(int process_id);
|
||||
|
||||
// Append command paramters according to |web_contents|'s preferences.
|
||||
static void AppendExtraCommandLineSwitches(
|
||||
content::WebContents* web_contents, base::CommandLine* command_line);
|
||||
|
@ -47,6 +52,9 @@ class WebContentsPreferences
|
|||
private:
|
||||
friend class content::WebContentsUserData<WebContentsPreferences>;
|
||||
|
||||
static std::vector<WebContentsPreferences*> instances_;
|
||||
|
||||
content::WebContents* web_contents_;
|
||||
base::DictionaryValue web_preferences_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(WebContentsPreferences);
|
||||
|
|
Загрузка…
Ссылка в новой задаче