Skip to content
This repository was archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2 from brave/fix-win-opener
Browse files Browse the repository at this point in the history
don't load the url when the opener will do it for you
  • Loading branch information
bbondy committed Jan 15, 2016
2 parents 6ee28c3 + cce9f5a commit 13bbe98
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
33 changes: 17 additions & 16 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ WebContents::WebContents(content::WebContents* web_contents)
WebContents::WebContents(v8::Isolate* isolate,
const mate::Dictionary& options,
const content::WebContents::CreateParams* params)
: request_id_(0) {
: delayed_load_url_(false),
request_id_(0) {
// Whether it is a guest WebContents.
bool is_guest = false;
options.Get("isGuest", &is_guest);
Expand Down Expand Up @@ -327,10 +328,12 @@ void WebContents::WebContentsCreated(content::WebContents* source_contents,
const std::string& frame_name,
const GURL& target_url,
content::WebContents* new_contents) {
if (IsGuest()) {
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());

CreateFrom(isolate(), new_contents)->delayed_load_url_ = true;

if (IsGuest() && opener_render_frame_id == MSG_ROUTING_NONE) {
content::NavigationController::LoadURLParams load_url_params(target_url);
// http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-95229140
load_url_params.referrer = content::Referrer(GetURL(),
Expand Down Expand Up @@ -416,18 +419,6 @@ bool WebContents::ShouldResumeRequestsForCreatedWindow() {
return false;
}

void WebContents::ResumeLoadingCreatedWebContents() {
if (delayed_load_url_params_.get()) {
GetWebContents()->GetController().LoadURLWithParams(
*delayed_load_url_params_.get());
delayed_load_url_params_.reset(nullptr);
}
// we will need this when adding guest view
// GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
// GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
// main_frame_route_id);
}

content::WebContents* WebContents::OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) {
Expand Down Expand Up @@ -755,6 +746,16 @@ bool WebContents::Equal(const WebContents* web_contents) const {
}

void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
if (delayed_load_url_) {
if (delayed_load_url_params_.get()) {
GetWebContents()->GetController().LoadURLWithParams(
*delayed_load_url_params_.get());
delayed_load_url_params_.reset(nullptr);
}
delayed_load_url_ = false;
return;
}

content::NavigationController::LoadURLParams params(url);

GURL http_referrer;
Expand Down
2 changes: 1 addition & 1 deletion atom/browser/api/atom_api_web_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
void SetAudioMuted(bool muted);
bool IsAudioMuted();
void Print(mate::Arguments* args);
void ResumeLoadingCreatedWebContents();

// Print current page as PDF.
void PrintToPDF(const base::DictionaryValue& setting,
Expand Down Expand Up @@ -318,6 +317,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
// needed to continue loading the page once the tab is ready.
scoped_ptr<content::NavigationController::LoadURLParams>
delayed_load_url_params_;
bool delayed_load_url_;

scoped_ptr<WebViewGuestDelegate> guest_delegate_;

Expand Down
6 changes: 1 addition & 5 deletions atom/browser/web_view_guest_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,9 @@ content::WebContents* WebViewGuestDelegate::CreateNewGuestWindow(
web_preferences->GetInteger(options::kGuestInstanceID, &openerId);
options.Set("openerId", openerId);

content::WebContents::CreateParams create_params(params);
create_params.created_with_opener = true;

// get the underlying contents::WebContents object
mate::Handle<api::WebContents> new_api_web_contents =
api::WebContents::CreateWithParams(isolate, options, create_params);
api::WebContents::CreateWithParams(isolate, options, params);
content::WebContents* web_contents = new_api_web_contents->GetWebContents();

// register the guest so we can find it in the new window
Expand Down Expand Up @@ -199,7 +196,6 @@ void WebViewGuestDelegate::DidCommitProvisionalLoadForFrame(

void WebViewGuestDelegate::DidAttach(int guest_proxy_routing_id) {
api_web_contents_->Emit("did-attach", guest_proxy_routing_id);
api_web_contents_->ResumeLoadingCreatedWebContents();
}

content::WebContents* WebViewGuestDelegate::GetOwnerWebContents() const {
Expand Down
7 changes: 1 addition & 6 deletions atom/renderer/atom_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,7 @@ bool AtomRendererClient::ShouldFork(blink::WebLocalFrame* frame,
bool is_initial_navigation,
bool is_server_redirect,
bool* send_referrer) {
// Handle all the navigations and reloads in browser.
// FIXME We only support GET here because http method will be ignored when
// the OpenURLFromTab is triggered, which means form posting would not work,
// we should solve this by patching Chromium in future.
*send_referrer = true;
return http_method == "GET" && !is_server_redirect;
return false;
}

content::BrowserPluginDelegate* AtomRendererClient::CreateBrowserPluginDelegate(
Expand Down

0 comments on commit 13bbe98

Please sign in to comment.