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