Skip to content

Commit

Permalink
setting nw window id when new window is created
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwang committed Feb 18, 2014
1 parent cd0b406 commit 979ac83
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 25 deletions.
1 change: 1 addition & 0 deletions content/browser/frame_host/navigation_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ void NavigationControllerImpl::LoadURLWithParams(const LoadURLParams& params) {
break;
};

entry->set_nw_win_id(params.nw_win_id);
LoadEntry(entry);
}

Expand Down
6 changes: 4 additions & 2 deletions content/browser/frame_host/navigation_entry_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ NavigationEntryImpl::NavigationEntryImpl()
is_renderer_initiated_(false),
should_replace_entry_(false),
should_clear_history_list_(false),
can_load_local_resources_(false) {
can_load_local_resources_(false),
nw_win_id_(0) {
}

NavigationEntryImpl::NavigationEntryImpl(SiteInstanceImpl* instance,
Expand Down Expand Up @@ -80,7 +81,8 @@ NavigationEntryImpl::NavigationEntryImpl(SiteInstanceImpl* instance,
is_renderer_initiated_(is_renderer_initiated),
should_replace_entry_(false),
should_clear_history_list_(false),
can_load_local_resources_(false) {
can_load_local_resources_(false),
nw_win_id_(0) {
}

NavigationEntryImpl::~NavigationEntryImpl() {
Expand Down
5 changes: 5 additions & 0 deletions content/browser/frame_host/navigation_entry_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ class CONTENT_EXPORT NavigationEntryImpl
return is_dev_reload_;
}

void set_nw_win_id(int id) { nw_win_id_ = id; }
int nw_win_id() const { return nw_win_id_; }

private:
// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
// Session/Tab restore save portions of this class so that it can be recreated
Expand Down Expand Up @@ -336,6 +339,8 @@ class CONTENT_EXPORT NavigationEntryImpl
std::map<std::string, string16> extra_data_;

bool is_dev_reload_;

int nw_win_id_;
// Copy and assignment is explicitly allowed for this class.
};

Expand Down
15 changes: 9 additions & 6 deletions content/browser/frame_host/render_view_host_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ RenderViewHostImpl* RenderViewHostManager::Navigate(
// Recreate the opener chain.
int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager(
dest_render_view_host->GetSiteInstance());
if (!InitRenderView(dest_render_view_host, opener_route_id))
if (!InitRenderView(dest_render_view_host, opener_route_id, entry.nw_win_id()))
return NULL;

// Now that we've created a new renderer, be sure to hide it if it isn't
Expand Down Expand Up @@ -709,7 +709,8 @@ int RenderViewHostManager::CreateRenderView(
SiteInstance* instance,
int opener_route_id,
bool swapped_out,
bool hidden) {
bool hidden,
int nw_win_id) {
CHECK(instance);
DCHECK(!swapped_out || hidden); // Swapped out views should always be hidden.

Expand Down Expand Up @@ -741,7 +742,7 @@ int RenderViewHostManager::CreateRenderView(
new_render_view_host->GetProcess()->AddPendingView();
}

bool success = InitRenderView(new_render_view_host, opener_route_id);
bool success = InitRenderView(new_render_view_host, opener_route_id, nw_win_id);
if (success) {
// Don't show the view until we get a DidNavigate from it.
new_render_view_host->GetView()->Hide();
Expand All @@ -758,14 +759,16 @@ int RenderViewHostManager::CreateRenderView(
}

bool RenderViewHostManager::InitRenderView(RenderViewHost* render_view_host,
int opener_route_id) {
int opener_route_id,
int nw_win_id) {
// If the pending navigation is to a WebUI and the RenderView is not in a
// guest process, tell the RenderView about any bindings it will need enabled.
if (pending_web_ui() && !render_view_host->GetProcess()->IsGuest())
render_view_host->AllowBindings(pending_web_ui()->GetBindings());

return delegate_->CreateRenderViewForRenderManager(render_view_host,
opener_route_id);
opener_route_id,
nw_win_id);
}

void RenderViewHostManager::CommitPending() {
Expand Down Expand Up @@ -949,7 +952,7 @@ RenderViewHostImpl* RenderViewHostManager::UpdateRendererStateForNavigate(
// Create a non-swapped-out pending RVH with the given opener and navigate
// it.
int route_id = CreateRenderView(new_instance, opener_route_id, false,
delegate_->IsHidden());
delegate_->IsHidden(), entry.nw_win_id());
if (route_id == MSG_ROUTING_NONE)
return NULL;

Expand Down
7 changes: 4 additions & 3 deletions content/browser/frame_host/render_view_host_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CONTENT_EXPORT RenderViewHostManager
// If you are attaching to an already-existing RenderView, you should call
// InitWithExistingID.
virtual bool CreateRenderViewForRenderManager(
RenderViewHost* render_view_host, int opener_route_id) = 0;
RenderViewHost* render_view_host, int opener_route_id, int nw_win_id = 0) = 0;
virtual void BeforeUnloadFiredFromRenderManager(
bool proceed, const base::TimeTicks& proceed_time,
bool* proceed_to_fire_unload) = 0;
Expand Down Expand Up @@ -188,7 +188,8 @@ class CONTENT_EXPORT RenderViewHostManager
int CreateRenderView(SiteInstance* instance,
int opener_route_id,
bool swapped_out,
bool hidden);
bool hidden,
int nw_win_id = 0);

// Called when a provisional load on the given renderer is aborted.
void RendererAbortedProvisionalLoad(RenderViewHost* render_view_host);
Expand Down Expand Up @@ -315,7 +316,7 @@ class CONTENT_EXPORT RenderViewHostManager
SiteInstance* curr_instance);

// Sets up the necessary state for a new RenderViewHost with the given opener.
bool InitRenderView(RenderViewHost* render_view_host, int opener_route_id);
bool InitRenderView(RenderViewHost* render_view_host, int opener_route_id, int nw_win_id);

// Sets the pending RenderViewHost/WebUI to be the active one. Note that this
// doesn't require the pending render_view_host_ pointer to be non-NULL, since
Expand Down
4 changes: 3 additions & 1 deletion content/browser/renderer_host/render_view_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ SiteInstance* RenderViewHostImpl::GetSiteInstance() const {
bool RenderViewHostImpl::CreateRenderView(
const string16& frame_name,
int opener_route_id,
int32 max_page_id) {
int32 max_page_id,
int nw_win_id) {
TRACE_EVENT0("renderer_host", "RenderViewHostImpl::CreateRenderView");
DCHECK(!IsRenderViewLive()) << "Creating view twice";

Expand Down Expand Up @@ -287,6 +288,7 @@ bool RenderViewHostImpl::CreateRenderView(
GetWebScreenInfo(&params.screen_info);
params.accessibility_mode = accessibility_mode();
params.allow_partial_swap = !GetProcess()->IsGuest();
params.nw_win_id = nw_win_id;

Send(new ViewMsg_New(params));

Expand Down
3 changes: 2 additions & 1 deletion content/browser/renderer_host/render_view_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ class CONTENT_EXPORT RenderViewHostImpl
// RenderView is told to start issuing page IDs at |max_page_id| + 1.
virtual bool CreateRenderView(const string16& frame_name,
int opener_route_id,
int32 max_page_id);
int32 max_page_id,
int nw_win_id = 0);

base::TerminationStatus render_view_termination_status() const {
return render_view_termination_status_;
Expand Down
4 changes: 2 additions & 2 deletions content/browser/web_contents/web_contents_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3545,7 +3545,7 @@ NavigationEntry*
}

bool WebContentsImpl::CreateRenderViewForRenderManager(
RenderViewHost* render_view_host, int opener_route_id) {
RenderViewHost* render_view_host, int opener_route_id, int nw_win_id) {
TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
// Can be NULL during tests.
RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
Expand All @@ -3562,7 +3562,7 @@ bool WebContentsImpl::CreateRenderViewForRenderManager(
if (!static_cast<RenderViewHostImpl*>(
render_view_host)->CreateRenderView(string16(),
opener_route_id,
max_page_id)) {
max_page_id, nw_win_id)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion content/browser/web_contents/web_contents_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class CONTENT_EXPORT WebContentsImpl
// RenderViewHostManager::Delegate -------------------------------------------

virtual bool CreateRenderViewForRenderManager(
RenderViewHost* render_view_host, int opener_route_id) OVERRIDE;
RenderViewHost* render_view_host, int opener_route_id, int nw_win_id = 0) OVERRIDE;
virtual void BeforeUnloadFiredFromRenderManager(
bool proceed, const base::TimeTicks& proceed_time,
bool* proceed_to_fire_unload) OVERRIDE;
Expand Down
2 changes: 2 additions & 0 deletions content/common/view_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,8 @@ IPC_STRUCT_BEGIN(ViewMsg_New_Params)
// allowed for a renderer. Partial swaps will be used if they are both
// allowed and supported.
IPC_STRUCT_MEMBER(bool, allow_partial_swap)

IPC_STRUCT_MEMBER(int32, nw_win_id)
IPC_STRUCT_END()

IPC_STRUCT_BEGIN(ViewMsg_PostMessage_Params)
Expand Down
7 changes: 5 additions & 2 deletions content/public/browser/navigation_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ NavigationController::LoadURLParams::LoadURLParams(const GURL& url)
browser_initiated_post_data(NULL),
can_load_local_resources(false),
should_replace_current_entry(false),
should_clear_history_list(false) {
should_clear_history_list(false),
nw_win_id(0) {
}

NavigationController::LoadURLParams::~LoadURLParams() {
Expand All @@ -37,7 +38,8 @@ NavigationController::LoadURLParams::LoadURLParams(
virtual_url_for_data_url(other.virtual_url_for_data_url),
browser_initiated_post_data(other.browser_initiated_post_data),
should_replace_current_entry(false),
should_clear_history_list(false) {
should_clear_history_list(false),
nw_win_id(0) {
}

NavigationController::LoadURLParams&
Expand All @@ -57,6 +59,7 @@ NavigationController::LoadURLParams::operator=(
browser_initiated_post_data = other.browser_initiated_post_data;
should_replace_current_entry = other.should_replace_current_entry;
should_clear_history_list = other.should_clear_history_list;
nw_win_id = other.nw_win_id;

return *this;
}
Expand Down
2 changes: 2 additions & 0 deletions content/public/browser/navigation_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ class NavigationController {
// commits.
bool should_clear_history_list;

int nw_win_id;

explicit LoadURLParams(const GURL& url);
~LoadURLParams();

Expand Down
3 changes: 2 additions & 1 deletion content/renderer/render_thread_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,8 @@ void RenderThreadImpl::OnCreateNewView(const ViewMsg_New_Params& params) {
params.next_page_id,
params.screen_info,
params.accessibility_mode,
params.allow_partial_swap);
params.allow_partial_swap,
params.nw_win_id);
}

GpuChannelHost* RenderThreadImpl::EstablishGpuChannelSync(
Expand Down
11 changes: 9 additions & 2 deletions content/renderer/render_view_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,11 @@ void RenderViewImpl::Initialize(RenderViewImplParams* params) {
// This ensures we are in a unique origin that others cannot script.
if (is_swapped_out_)
NavigateToSwappedOutURL(webview()->mainFrame());

if (params->nw_win_id) {
v8::Handle<v8::Value> v8win = webview()->mainFrame()->mainWorldScriptContext()->Global();
v8win->ToObject()->Set(v8::String::New("__nwWindowId"), v8::Integer::New(params->nw_win_id));
}
}

RenderViewImpl::~RenderViewImpl() {
Expand Down Expand Up @@ -1113,7 +1118,8 @@ RenderViewImpl* RenderViewImpl::Create(
int32 next_page_id,
const WebKit::WebScreenInfo& screen_info,
AccessibilityMode accessibility_mode,
bool allow_partial_swap) {
bool allow_partial_swap,
int nw_win_id) {
DCHECK(routing_id != MSG_ROUTING_NONE);
RenderViewImplParams params(
opener_id,
Expand All @@ -1130,7 +1136,8 @@ RenderViewImpl* RenderViewImpl::Create(
next_page_id,
screen_info,
accessibility_mode,
allow_partial_swap);
allow_partial_swap,
nw_win_id);
RenderViewImpl* render_view = NULL;
if (g_create_render_view_impl)
render_view = g_create_render_view_impl(&params);
Expand Down
3 changes: 2 additions & 1 deletion content/renderer/render_view_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ class CONTENT_EXPORT RenderViewImpl
int32 next_page_id,
const WebKit::WebScreenInfo& screen_info,
AccessibilityMode accessibility_mode,
bool allow_partial_swap);
bool allow_partial_swap,
int nw_win_id = 0);

// Used by content_layouttest_support to hook into the creation of
// RenderViewImpls.
Expand Down
6 changes: 4 additions & 2 deletions content/renderer/render_view_impl_params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ RenderViewImplParams::RenderViewImplParams(
int32 next_page_id,
const WebKit::WebScreenInfo& screen_info,
AccessibilityMode accessibility_mode,
bool allow_partial_swap)
bool allow_partial_swap,
int nw_win_id)
: opener_id(opener_id),
renderer_prefs(renderer_prefs),
webkit_prefs(webkit_prefs),
Expand All @@ -36,7 +37,8 @@ RenderViewImplParams::RenderViewImplParams(
next_page_id(next_page_id),
screen_info(screen_info),
accessibility_mode(accessibility_mode),
allow_partial_swap(allow_partial_swap){
allow_partial_swap(allow_partial_swap),
nw_win_id(nw_win_id){
}

RenderViewImplParams::~RenderViewImplParams() {}
Expand Down
4 changes: 3 additions & 1 deletion content/renderer/render_view_impl_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ struct CONTENT_EXPORT RenderViewImplParams {
int32 next_page_id,
const WebKit::WebScreenInfo& screen_info,
AccessibilityMode accessibility_mode,
bool allow_partial_swap);
bool allow_partial_swap,
int nw_win_id);
~RenderViewImplParams();

int32 opener_id;
Expand All @@ -55,6 +56,7 @@ struct CONTENT_EXPORT RenderViewImplParams {
const WebKit::WebScreenInfo& screen_info;
AccessibilityMode accessibility_mode;
bool allow_partial_swap;
int nw_win_id;
};

} // namespace content
Expand Down

0 comments on commit 979ac83

Please sign in to comment.