feat: enhance native window.open to match the custom implementation's behavior (#19703)
Co-authored-by: Andy Locascio <andy@slack-corp.com>
This commit is contained in:
parent
b1f4ac00f0
commit
74372d65ae
20 changed files with 350 additions and 143 deletions
|
@ -671,7 +671,7 @@ bool App::CanCreateWindow(
|
|||
const std::string& frame_name,
|
||||
WindowOpenDisposition disposition,
|
||||
const blink::mojom::WindowFeatures& features,
|
||||
const std::vector<std::string>& additional_features,
|
||||
const std::string& raw_features,
|
||||
const scoped_refptr<network::ResourceRequestBody>& body,
|
||||
bool user_gesture,
|
||||
bool opener_suppressed,
|
||||
|
@ -685,7 +685,7 @@ bool App::CanCreateWindow(
|
|||
// No need to emit any event if the WebContents is not available in JS.
|
||||
if (!api_web_contents.IsEmpty()) {
|
||||
api_web_contents->OnCreateWindow(target_url, referrer, frame_name,
|
||||
disposition, additional_features, body);
|
||||
disposition, raw_features, body);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ class App : public ElectronBrowserClient::Delegate,
|
|||
const std::string& frame_name,
|
||||
WindowOpenDisposition disposition,
|
||||
const blink::mojom::WindowFeatures& features,
|
||||
const std::vector<std::string>& additional_features,
|
||||
const std::string& raw_features,
|
||||
const scoped_refptr<network::ResourceRequestBody>& body,
|
||||
bool user_gesture,
|
||||
bool opener_suppressed,
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include "content/public/browser/site_instance.h"
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/common/referrer_type_converters.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "electron/shell/common/api/api.mojom.h"
|
||||
#include "gin/data_object_builder.h"
|
||||
|
@ -641,25 +642,25 @@ void WebContents::OnCreateWindow(
|
|||
const content::Referrer& referrer,
|
||||
const std::string& frame_name,
|
||||
WindowOpenDisposition disposition,
|
||||
const std::vector<std::string>& features,
|
||||
const std::string& features,
|
||||
const scoped_refptr<network::ResourceRequestBody>& body) {
|
||||
if (type_ == Type::BROWSER_WINDOW || type_ == Type::OFF_SCREEN)
|
||||
Emit("-new-window", target_url, frame_name, disposition, features, body,
|
||||
referrer);
|
||||
else
|
||||
Emit("new-window", target_url, frame_name, disposition, features);
|
||||
Emit("-new-window", target_url, frame_name, disposition, features, referrer,
|
||||
body);
|
||||
}
|
||||
|
||||
void WebContents::WebContentsCreated(content::WebContents* source_contents,
|
||||
int opener_render_process_id,
|
||||
int opener_render_frame_id,
|
||||
const std::string& frame_name,
|
||||
const GURL& target_url,
|
||||
content::WebContents* new_contents) {
|
||||
void WebContents::WebContentsCreatedWithFullParams(
|
||||
content::WebContents* source_contents,
|
||||
int opener_render_process_id,
|
||||
int opener_render_frame_id,
|
||||
const content::mojom::CreateNewWindowParams& params,
|
||||
content::WebContents* new_contents) {
|
||||
ChildWebContentsTracker::CreateForWebContents(new_contents);
|
||||
auto* tracker = ChildWebContentsTracker::FromWebContents(new_contents);
|
||||
tracker->url = target_url;
|
||||
tracker->frame_name = frame_name;
|
||||
tracker->url = params.target_url;
|
||||
tracker->frame_name = params.frame_name;
|
||||
tracker->referrer = params.referrer.To<content::Referrer>();
|
||||
tracker->raw_features = params.raw_features;
|
||||
tracker->body = params.body;
|
||||
}
|
||||
|
||||
void WebContents::AddNewContents(
|
||||
|
@ -678,7 +679,8 @@ void WebContents::AddNewContents(
|
|||
CreateAndTake(isolate(), std::move(new_contents), Type::BROWSER_WINDOW);
|
||||
if (Emit("-add-new-contents", api_web_contents, disposition, user_gesture,
|
||||
initial_rect.x(), initial_rect.y(), initial_rect.width(),
|
||||
initial_rect.height(), tracker->url, tracker->frame_name)) {
|
||||
initial_rect.height(), tracker->url, tracker->frame_name,
|
||||
tracker->referrer, tracker->raw_features, tracker->body)) {
|
||||
// TODO(zcbenz): Can we make this sync?
|
||||
api_web_contents->DestroyWebContents(true /* async */);
|
||||
}
|
||||
|
@ -688,10 +690,8 @@ content::WebContents* WebContents::OpenURLFromTab(
|
|||
content::WebContents* source,
|
||||
const content::OpenURLParams& params) {
|
||||
if (params.disposition != WindowOpenDisposition::CURRENT_TAB) {
|
||||
if (type_ == Type::BROWSER_WINDOW || type_ == Type::OFF_SCREEN)
|
||||
Emit("-new-window", params.url, "", params.disposition);
|
||||
else
|
||||
Emit("new-window", params.url, "", params.disposition);
|
||||
Emit("-new-window", params.url, "", params.disposition, "", params.referrer,
|
||||
params.post_data);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "base/observer_list.h"
|
||||
#include "base/observer_list_types.h"
|
||||
#include "content/common/cursors/webcursor.h"
|
||||
#include "content/common/frame.mojom.h"
|
||||
#include "content/public/browser/devtools_agent_host.h"
|
||||
#include "content/public/browser/keyboard_event_processing_result.h"
|
||||
#include "content/public/browser/render_widget_host.h"
|
||||
|
@ -312,7 +313,7 @@ class WebContents : public gin_helper::TrackableObject<WebContents>,
|
|||
const content::Referrer& referrer,
|
||||
const std::string& frame_name,
|
||||
WindowOpenDisposition disposition,
|
||||
const std::vector<std::string>& features,
|
||||
const std::string& features,
|
||||
const scoped_refptr<network::ResourceRequestBody>& body);
|
||||
|
||||
// Returns the preload script path of current WebContents.
|
||||
|
@ -383,12 +384,12 @@ class WebContents : public gin_helper::TrackableObject<WebContents>,
|
|||
const base::string16& message,
|
||||
int32_t line_no,
|
||||
const base::string16& source_id) override;
|
||||
void WebContentsCreated(content::WebContents* source_contents,
|
||||
int opener_render_process_id,
|
||||
int opener_render_frame_id,
|
||||
const std::string& frame_name,
|
||||
const GURL& target_url,
|
||||
content::WebContents* new_contents) override;
|
||||
void WebContentsCreatedWithFullParams(
|
||||
content::WebContents* source_contents,
|
||||
int opener_render_process_id,
|
||||
int opener_render_frame_id,
|
||||
const content::mojom::CreateNewWindowParams& params,
|
||||
content::WebContents* new_contents) override;
|
||||
void AddNewContents(content::WebContents* source,
|
||||
std::unique_ptr<content::WebContents> new_contents,
|
||||
WindowOpenDisposition disposition,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue