Home | History | Annotate | Download | only in blocked_content
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/blocked_content/blocked_window_params.h"
      6 
      7 #include "chrome/browser/profiles/profile.h"
      8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
      9 #include "content/public/browser/render_view_host.h"
     10 #include "content/public/browser/web_contents.h"
     11 #include "content/public/browser/web_contents_view.h"
     12 #include "third_party/WebKit/public/web/WebWindowFeatures.h"
     13 #include "url/gurl.h"
     14 
     15 BlockedWindowParams::BlockedWindowParams(
     16     const GURL& target_url,
     17     const content::Referrer& referrer,
     18     WindowOpenDisposition disposition,
     19     const blink::WebWindowFeatures& features,
     20     bool user_gesture,
     21     bool opener_suppressed,
     22     int render_process_id,
     23     int opener_id)
     24     : target_url_(target_url),
     25       referrer_(referrer),
     26       disposition_(disposition),
     27       features_(features),
     28       user_gesture_(user_gesture),
     29       opener_suppressed_(opener_suppressed),
     30       render_process_id_(render_process_id),
     31       opener_id_(opener_id) {
     32 }
     33 
     34 chrome::NavigateParams BlockedWindowParams::CreateNavigateParams(
     35     content::WebContents* web_contents) const {
     36   GURL popup_url(target_url_);
     37   content::RenderViewHost::FilterURL(
     38       web_contents->GetRenderProcessHost(), false, &popup_url);
     39   chrome::NavigateParams nav_params(
     40       Profile::FromBrowserContext(web_contents->GetBrowserContext()),
     41       popup_url,
     42       content::PAGE_TRANSITION_LINK);
     43   nav_params.referrer = referrer_;
     44   nav_params.source_contents = web_contents;
     45   nav_params.is_renderer_initiated = true;
     46   nav_params.tabstrip_add_types = TabStripModel::ADD_ACTIVE;
     47   nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW;
     48   nav_params.user_gesture = user_gesture_;
     49   nav_params.should_set_opener = !opener_suppressed_;
     50   web_contents->GetView()->GetContainerBounds(&nav_params.window_bounds);
     51   if (features_.xSet)
     52     nav_params.window_bounds.set_x(features_.x);
     53   if (features_.ySet)
     54     nav_params.window_bounds.set_y(features_.y);
     55   if (features_.widthSet)
     56     nav_params.window_bounds.set_width(features_.width);
     57   if (features_.heightSet)
     58     nav_params.window_bounds.set_height(features_.height);
     59 
     60   // Compare RenderViewImpl::show().
     61   if (!user_gesture_ && disposition_ != NEW_BACKGROUND_TAB)
     62     nav_params.disposition = NEW_POPUP;
     63   else
     64     nav_params.disposition = disposition_;
     65 
     66   return nav_params;
     67 }
     68