decide early on render initiated window creations
This commit is contained in:
parent
7016fbe258
commit
e0fe478ae7
6 changed files with 132 additions and 23 deletions
|
@ -27,6 +27,7 @@
|
||||||
#include "base/path_service.h"
|
#include "base/path_service.h"
|
||||||
#include "brightray/browser/brightray_paths.h"
|
#include "brightray/browser/brightray_paths.h"
|
||||||
#include "chrome/common/chrome_paths.h"
|
#include "chrome/common/chrome_paths.h"
|
||||||
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "content/public/browser/client_certificate_delegate.h"
|
#include "content/public/browser/client_certificate_delegate.h"
|
||||||
#include "content/public/browser/gpu_data_manager.h"
|
#include "content/public/browser/gpu_data_manager.h"
|
||||||
#include "content/public/browser/render_frame_host.h"
|
#include "content/public/browser/render_frame_host.h"
|
||||||
|
@ -275,6 +276,53 @@ void App::SelectClientCertificate(
|
||||||
cert_request_info->client_certs[0].get());
|
cert_request_info->client_certs[0].get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool App::CanCreateWindow(const GURL& opener_url,
|
||||||
|
const GURL& opener_top_level_frame_url,
|
||||||
|
const GURL& source_origin,
|
||||||
|
WindowContainerType container_type,
|
||||||
|
const std::string& frame_name,
|
||||||
|
const GURL& target_url,
|
||||||
|
const content::Referrer& referrer,
|
||||||
|
WindowOpenDisposition disposition,
|
||||||
|
const blink::WebWindowFeatures& features,
|
||||||
|
bool user_gesture,
|
||||||
|
bool opener_suppressed,
|
||||||
|
content::ResourceContext* context,
|
||||||
|
int render_process_id,
|
||||||
|
int opener_render_view_id,
|
||||||
|
int opener_render_frame_id,
|
||||||
|
bool* no_javascript_access) {
|
||||||
|
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
|
||||||
|
|
||||||
|
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
||||||
|
base::Bind(&App::OnCreateWindow,
|
||||||
|
base::Unretained(this),
|
||||||
|
target_url,
|
||||||
|
frame_name,
|
||||||
|
disposition,
|
||||||
|
render_process_id,
|
||||||
|
opener_render_frame_id));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void App::OnCreateWindow(const GURL& target_url,
|
||||||
|
const std::string& frame_name,
|
||||||
|
WindowOpenDisposition disposition,
|
||||||
|
int render_process_id,
|
||||||
|
int render_frame_id) {
|
||||||
|
v8::Locker locker(isolate());
|
||||||
|
v8::HandleScope handle_scope(isolate());
|
||||||
|
content::RenderFrameHost* rfh =
|
||||||
|
content::RenderFrameHost::FromID(render_process_id, render_frame_id);
|
||||||
|
content::WebContents* web_contents =
|
||||||
|
content::WebContents::FromRenderFrameHost(rfh);
|
||||||
|
if (web_contents) {
|
||||||
|
auto api_web_contents = WebContents::CreateFrom(isolate(), web_contents);
|
||||||
|
api_web_contents->CreateWindow(target_url, frame_name, disposition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void App::OnGpuProcessCrashed(base::TerminationStatus exit_code) {
|
void App::OnGpuProcessCrashed(base::TerminationStatus exit_code) {
|
||||||
Emit("gpu-process-crashed");
|
Emit("gpu-process-crashed");
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,22 @@ class App : public AtomBrowserClient::Delegate,
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
net::SSLCertRequestInfo* cert_request_info,
|
net::SSLCertRequestInfo* cert_request_info,
|
||||||
scoped_ptr<content::ClientCertificateDelegate> delegate) override;
|
scoped_ptr<content::ClientCertificateDelegate> delegate) override;
|
||||||
|
bool CanCreateWindow(const GURL& opener_url,
|
||||||
|
const GURL& opener_top_level_frame_url,
|
||||||
|
const GURL& source_origin,
|
||||||
|
WindowContainerType container_type,
|
||||||
|
const std::string& frame_name,
|
||||||
|
const GURL& target_url,
|
||||||
|
const content::Referrer& referrer,
|
||||||
|
WindowOpenDisposition disposition,
|
||||||
|
const blink::WebWindowFeatures& features,
|
||||||
|
bool user_gesture,
|
||||||
|
bool opener_suppressed,
|
||||||
|
content::ResourceContext* context,
|
||||||
|
int render_process_id,
|
||||||
|
int opener_render_view_id,
|
||||||
|
int opener_render_frame_id,
|
||||||
|
bool* no_javascript_access) override;
|
||||||
|
|
||||||
// content::GpuDataManagerObserver:
|
// content::GpuDataManagerObserver:
|
||||||
void OnGpuProcessCrashed(base::TerminationStatus exit_code) override;
|
void OnGpuProcessCrashed(base::TerminationStatus exit_code) override;
|
||||||
|
@ -90,6 +106,11 @@ class App : public AtomBrowserClient::Delegate,
|
||||||
bool MakeSingleInstance(
|
bool MakeSingleInstance(
|
||||||
const ProcessSingleton::NotificationCallback& callback);
|
const ProcessSingleton::NotificationCallback& callback);
|
||||||
std::string GetLocale();
|
std::string GetLocale();
|
||||||
|
void OnCreateWindow(const GURL& target_url,
|
||||||
|
const std::string& frame_name,
|
||||||
|
WindowOpenDisposition disposition,
|
||||||
|
int render_process_id,
|
||||||
|
int render_frame_id);
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
bool IsAeroGlassEnabled();
|
bool IsAeroGlassEnabled();
|
||||||
|
|
|
@ -316,23 +316,13 @@ bool WebContents::AddMessageToConsole(content::WebContents* source,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebContents::ShouldCreateWebContents(
|
void WebContents::CreateWindow(const GURL& target_url,
|
||||||
content::WebContents* web_contents,
|
|
||||||
int32_t route_id,
|
|
||||||
int32_t main_frame_route_id,
|
|
||||||
int32_t main_frame_widget_route_id,
|
|
||||||
WindowContainerType window_container_type,
|
|
||||||
const std::string& frame_name,
|
const std::string& frame_name,
|
||||||
const GURL& target_url,
|
WindowOpenDisposition disposition) {
|
||||||
const std::string& partition_id,
|
|
||||||
content::SessionStorageNamespace* session_storage_namespace) {
|
|
||||||
auto disposition = (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND)
|
|
||||||
? "background-tab" : "new-window";
|
|
||||||
if (type_ == BROWSER_WINDOW)
|
if (type_ == BROWSER_WINDOW)
|
||||||
Emit("-new-window", target_url, frame_name, disposition);
|
Emit("-new-window", target_url, frame_name, disposition);
|
||||||
else
|
else
|
||||||
Emit("new-window", target_url, frame_name, disposition);
|
Emit("new-window", target_url, frame_name, disposition);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
content::WebContents* WebContents::OpenURLFromTab(
|
content::WebContents* WebContents::OpenURLFromTab(
|
||||||
|
|
|
@ -138,6 +138,11 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
const GURL& origin,
|
const GURL& origin,
|
||||||
bool allowed);
|
bool allowed);
|
||||||
|
|
||||||
|
// Create window with the given disposition.
|
||||||
|
void CreateWindow(const GURL& target_url,
|
||||||
|
const std::string& frame_name,
|
||||||
|
WindowOpenDisposition disposition);
|
||||||
|
|
||||||
// Returns the web preferences of current WebContents.
|
// Returns the web preferences of current WebContents.
|
||||||
v8::Local<v8::Value> GetWebPreferences(v8::Isolate* isolate);
|
v8::Local<v8::Value> GetWebPreferences(v8::Isolate* isolate);
|
||||||
|
|
||||||
|
@ -165,16 +170,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
const base::string16& message,
|
const base::string16& message,
|
||||||
int32_t line_no,
|
int32_t line_no,
|
||||||
const base::string16& source_id) override;
|
const base::string16& source_id) override;
|
||||||
bool ShouldCreateWebContents(
|
|
||||||
content::WebContents* web_contents,
|
|
||||||
int32_t route_id,
|
|
||||||
int32_t main_frame_route_id,
|
|
||||||
int32_t main_frame_widget_route_id,
|
|
||||||
WindowContainerType window_container_type,
|
|
||||||
const std::string& frame_name,
|
|
||||||
const GURL& target_url,
|
|
||||||
const std::string& partition_id,
|
|
||||||
content::SessionStorageNamespace* session_storage_namespace) override;
|
|
||||||
content::WebContents* OpenURLFromTab(
|
content::WebContents* OpenURLFromTab(
|
||||||
content::WebContents* source,
|
content::WebContents* source,
|
||||||
const content::OpenURLParams& params) override;
|
const content::OpenURLParams& params) override;
|
||||||
|
|
|
@ -264,6 +264,45 @@ void AtomBrowserClient::ResourceDispatcherHostCreated() {
|
||||||
resource_dispatcher_host_delegate_.get());
|
resource_dispatcher_host_delegate_.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AtomBrowserClient::CanCreateWindow(
|
||||||
|
const GURL& opener_url,
|
||||||
|
const GURL& opener_top_level_frame_url,
|
||||||
|
const GURL& source_origin,
|
||||||
|
WindowContainerType container_type,
|
||||||
|
const std::string& frame_name,
|
||||||
|
const GURL& target_url,
|
||||||
|
const content::Referrer& referrer,
|
||||||
|
WindowOpenDisposition disposition,
|
||||||
|
const blink::WebWindowFeatures& features,
|
||||||
|
bool user_gesture,
|
||||||
|
bool opener_suppressed,
|
||||||
|
content::ResourceContext* context,
|
||||||
|
int render_process_id,
|
||||||
|
int opener_render_view_id,
|
||||||
|
int opener_render_frame_id,
|
||||||
|
bool* no_javascript_access) {
|
||||||
|
if (delegate_) {
|
||||||
|
return delegate_->CanCreateWindow(opener_url,
|
||||||
|
opener_top_level_frame_url,
|
||||||
|
source_origin,
|
||||||
|
container_type,
|
||||||
|
frame_name,
|
||||||
|
target_url,
|
||||||
|
referrer,
|
||||||
|
disposition,
|
||||||
|
features,
|
||||||
|
user_gesture,
|
||||||
|
opener_suppressed,
|
||||||
|
context,
|
||||||
|
render_process_id,
|
||||||
|
opener_render_view_id,
|
||||||
|
opener_render_frame_id,
|
||||||
|
no_javascript_access);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
|
brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
|
||||||
const content::MainFunctionParams&) {
|
const content::MainFunctionParams&) {
|
||||||
v8::V8::Initialize(); // Init V8 before creating main parts.
|
v8::V8::Initialize(); // Init V8 before creating main parts.
|
||||||
|
|
|
@ -76,6 +76,22 @@ class AtomBrowserClient : public brightray::BrowserClient,
|
||||||
net::SSLCertRequestInfo* cert_request_info,
|
net::SSLCertRequestInfo* cert_request_info,
|
||||||
scoped_ptr<content::ClientCertificateDelegate> delegate) override;
|
scoped_ptr<content::ClientCertificateDelegate> delegate) override;
|
||||||
void ResourceDispatcherHostCreated() override;
|
void ResourceDispatcherHostCreated() override;
|
||||||
|
bool CanCreateWindow(const GURL& opener_url,
|
||||||
|
const GURL& opener_top_level_frame_url,
|
||||||
|
const GURL& source_origin,
|
||||||
|
WindowContainerType container_type,
|
||||||
|
const std::string& frame_name,
|
||||||
|
const GURL& target_url,
|
||||||
|
const content::Referrer& referrer,
|
||||||
|
WindowOpenDisposition disposition,
|
||||||
|
const blink::WebWindowFeatures& features,
|
||||||
|
bool user_gesture,
|
||||||
|
bool opener_suppressed,
|
||||||
|
content::ResourceContext* context,
|
||||||
|
int render_process_id,
|
||||||
|
int opener_render_view_id,
|
||||||
|
int opener_render_frame_id,
|
||||||
|
bool* no_javascript_access) override;
|
||||||
|
|
||||||
// brightray::BrowserClient:
|
// brightray::BrowserClient:
|
||||||
brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
|
brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
|
||||||
|
|
Loading…
Reference in a new issue