158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// found in the LICENSE file.
458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/profiles/profile.h"
858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h"
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/render_process_host.h"
1058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "content/public/browser/web_contents.h"
1158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "third_party/WebKit/public/web/WebWindowFeatures.h"
1258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "url/gurl.h"
1358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)BlockedWindowParams::BlockedWindowParams(
1558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    const GURL& target_url,
1658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    const content::Referrer& referrer,
1758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    WindowOpenDisposition disposition,
18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const blink::WebWindowFeatures& features,
1958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    bool user_gesture,
2058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    bool opener_suppressed,
2158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    int render_process_id,
2258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    int opener_id)
2358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    : target_url_(target_url),
2458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      referrer_(referrer),
2558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      disposition_(disposition),
2658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      features_(features),
2758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      user_gesture_(user_gesture),
2858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      opener_suppressed_(opener_suppressed),
2958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      render_process_id_(render_process_id),
3058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      opener_id_(opener_id) {
3158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
3258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
3358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)chrome::NavigateParams BlockedWindowParams::CreateNavigateParams(
3458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    content::WebContents* web_contents) const {
3558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  GURL popup_url(target_url_);
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  web_contents->GetRenderProcessHost()->FilterURL(false, &popup_url);
3758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  chrome::NavigateParams nav_params(
3858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      Profile::FromBrowserContext(web_contents->GetBrowserContext()),
3958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      popup_url,
401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      ui::PAGE_TRANSITION_LINK);
4158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  nav_params.referrer = referrer_;
4258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  nav_params.source_contents = web_contents;
4358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  nav_params.is_renderer_initiated = true;
4458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  nav_params.tabstrip_add_types = TabStripModel::ADD_ACTIVE;
4558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW;
4658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  nav_params.user_gesture = user_gesture_;
4758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  nav_params.should_set_opener = !opener_suppressed_;
48010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  nav_params.window_bounds = web_contents->GetContainerBounds();
4958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  if (features_.xSet)
5058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    nav_params.window_bounds.set_x(features_.x);
5158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  if (features_.ySet)
5258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    nav_params.window_bounds.set_y(features_.y);
5358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  if (features_.widthSet)
5458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    nav_params.window_bounds.set_width(features_.width);
5558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  if (features_.heightSet)
5658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    nav_params.window_bounds.set_height(features_.height);
5758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
5858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Compare RenderViewImpl::show().
5958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  if (!user_gesture_ && disposition_ != NEW_BACKGROUND_TAB)
6058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    nav_params.disposition = NEW_POPUP;
6158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  else
6258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    nav_params.disposition = disposition_;
6358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
6458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  return nav_params;
6558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
66