| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 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/webui/chrome_web_dialog_web_contents_delegate.h" |
| 6 |
| 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/tabs/tab_strip_model.h" |
| 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_navigator.h" |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 12 #include "content/public/browser/web_contents.h" |
| 13 |
| 14 using content::OpenURLParams; |
| 15 using content::WebContents; |
| 16 |
| 17 // Incognito profiles are not long-lived, so we always want to store a |
| 18 // non-incognito profile. |
| 19 // |
| 20 // TODO(akalin): Should we make it so that we have a default incognito |
| 21 // profile that's long-lived? Of course, we'd still have to clear it out |
| 22 // when all incognito browsers close. |
| 23 ChromeWebDialogWebContentsDelegate::ChromeWebDialogWebContentsDelegate( |
| 24 Profile* profile) |
| 25 : web_dialogs::WebDialogWebContentsDelegate(profile), |
| 26 profile_(profile) { |
| 27 } |
| 28 |
| 29 ChromeWebDialogWebContentsDelegate::~ChromeWebDialogWebContentsDelegate() { |
| 30 } |
| 31 |
| 32 Profile* ChromeWebDialogWebContentsDelegate::profile() const { |
| 33 return profile_; |
| 34 } |
| 35 |
| 36 void ChromeWebDialogWebContentsDelegate::Detach() { |
| 37 web_dialogs::WebDialogWebContentsDelegate::Detach(); |
| 38 profile_ = NULL; |
| 39 } |
| 40 |
| 41 WebContents* ChromeWebDialogWebContentsDelegate::OpenURLFromTab( |
| 42 WebContents* source, const OpenURLParams& params) { |
| 43 WebContents* new_contents = NULL; |
| 44 StaticOpenURLFromTab(profile_, source, params, &new_contents); |
| 45 return new_contents; |
| 46 } |
| 47 |
| 48 // static |
| 49 Browser* ChromeWebDialogWebContentsDelegate::StaticOpenURLFromTab( |
| 50 Profile* profile, WebContents* source, const OpenURLParams& params, |
| 51 WebContents** out_new_contents) { |
| 52 if (!profile) |
| 53 return NULL; |
| 54 |
| 55 // Specify a NULL browser for navigation. This will cause Navigate() |
| 56 // to find a browser matching params.profile or create a new one. |
| 57 Browser* browser = NULL; |
| 58 browser::NavigateParams nav_params(browser, params.url, params.transition); |
| 59 nav_params.profile = profile; |
| 60 nav_params.referrer = params.referrer; |
| 61 if (source && source->IsCrashed() && |
| 62 params.disposition == CURRENT_TAB && |
| 63 params.transition == content::PAGE_TRANSITION_LINK) { |
| 64 nav_params.disposition = NEW_FOREGROUND_TAB; |
| 65 } else { |
| 66 nav_params.disposition = params.disposition; |
| 67 } |
| 68 nav_params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 69 nav_params.user_gesture = true; |
| 70 browser::Navigate(&nav_params); |
| 71 *out_new_contents = nav_params.target_contents ? |
| 72 nav_params.target_contents->web_contents() : NULL; |
| 73 return nav_params.browser; |
| 74 } |
| 75 |
| 76 void ChromeWebDialogWebContentsDelegate::AddNewContents( |
| 77 WebContents* source, WebContents* new_contents, |
| 78 WindowOpenDisposition disposition, const gfx::Rect& initial_pos, |
| 79 bool user_gesture) { |
| 80 StaticAddNewContents(profile_, source, new_contents, disposition, |
| 81 initial_pos, user_gesture); |
| 82 } |
| 83 |
| 84 // static |
| 85 Browser* ChromeWebDialogWebContentsDelegate::StaticAddNewContents( |
| 86 Profile* profile, |
| 87 WebContents* source, |
| 88 WebContents* new_contents, |
| 89 WindowOpenDisposition disposition, |
| 90 const gfx::Rect& initial_pos, |
| 91 bool user_gesture) { |
| 92 if (!profile) |
| 93 return NULL; |
| 94 |
| 95 // Specify a NULL browser for navigation. This will cause Navigate() |
| 96 // to find a browser matching params.profile or create a new one. |
| 97 Browser* browser = NULL; |
| 98 |
| 99 TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); |
| 100 browser::NavigateParams params(browser, wrapper); |
| 101 params.profile = profile; |
| 102 // TODO(pinkerton): no way to get a wrapper for this. |
| 103 // params.source_contents = source; |
| 104 params.disposition = disposition; |
| 105 params.window_bounds = initial_pos; |
| 106 params.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 107 params.user_gesture = true; |
| 108 browser::Navigate(¶ms); |
| 109 |
| 110 return params.browser; |
| 111 } |
| OLD | NEW |