OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/dom_ui/html_dialog_tab_contents_delegate.h" | 5 #include "chrome/browser/dom_ui/html_dialog_tab_contents_delegate.h" |
6 | 6 |
7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
8 #include "chrome/browser/browser_navigator.h" | 8 #include "chrome/browser/browser_navigator.h" |
9 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
10 #include "chrome/browser/tab_contents/tab_contents.h" | 10 #include "chrome/browser/tab_contents/tab_contents.h" |
11 #include "chrome/browser/tabs/tab_strip_model.h" | 11 #include "chrome/browser/tabs/tab_strip_model.h" |
12 | 12 |
13 // Incognito profiles are not long-lived, so we always want to store a | 13 // Incognito profiles are not long-lived, so we always want to store a |
14 // non-incognito profile. | 14 // non-incognito profile. |
15 // | 15 // |
16 // TODO(akalin): Should we make it so that we have a default incognito | 16 // TODO(akalin): Should we make it so that we have a default incognito |
17 // profile that's long-lived? Of course, we'd still have to clear it out | 17 // profile that's long-lived? Of course, we'd still have to clear it out |
18 // when all incognito browsers close. | 18 // when all incognito browsers close. |
19 HtmlDialogTabContentsDelegate::HtmlDialogTabContentsDelegate(Profile* profile) | 19 HtmlDialogTabContentsDelegate::HtmlDialogTabContentsDelegate(Profile* profile) |
20 : profile_(profile->GetOriginalProfile()) {} | 20 : profile_(profile->GetOriginalProfile()) {} |
21 | 21 |
22 HtmlDialogTabContentsDelegate::~HtmlDialogTabContentsDelegate() {} | 22 HtmlDialogTabContentsDelegate::~HtmlDialogTabContentsDelegate() {} |
23 | 23 |
24 Profile* HtmlDialogTabContentsDelegate::profile() const { return profile_; } | 24 Profile* HtmlDialogTabContentsDelegate::profile() const { return profile_; } |
25 | 25 |
26 void HtmlDialogTabContentsDelegate::Detach() { | 26 void HtmlDialogTabContentsDelegate::Detach() { |
27 profile_ = NULL; | 27 profile_ = NULL; |
28 } | 28 } |
29 | 29 |
30 Browser* HtmlDialogTabContentsDelegate::CreateBrowser() { | |
31 DCHECK(profile_); | |
32 return Browser::Create(profile_); | |
33 } | |
34 | |
35 void HtmlDialogTabContentsDelegate::OpenURLFromTab( | 30 void HtmlDialogTabContentsDelegate::OpenURLFromTab( |
36 TabContents* source, const GURL& url, const GURL& referrer, | 31 TabContents* source, const GURL& url, const GURL& referrer, |
37 WindowOpenDisposition disposition, PageTransition::Type transition) { | 32 WindowOpenDisposition disposition, PageTransition::Type transition) { |
38 if (profile_) { | 33 if (profile_) { |
39 // Force all links to open in a new window, ignoring the incoming | 34 // Specify a NULL browser for navigation. This will cause Navigate() |
40 // disposition. This is a tabless, modal dialog so we can't just | 35 // to find a browser matching params.profile or create a new one. |
41 // open it in the current frame. Code adapted from | 36 Browser* browser = NULL; |
42 // Browser::OpenURLFromTab() with disposition == NEW_WINDOW. | 37 browser::NavigateParams params(browser, url, transition); |
43 browser::NavigateParams params(CreateBrowser(), url, transition); | 38 params.profile = profile_; |
44 params.referrer = referrer; | 39 params.referrer = referrer; |
45 params.disposition = NEW_FOREGROUND_TAB; | 40 params.disposition = disposition; |
46 params.show_window = true; | 41 params.show_window = true; |
47 browser::Navigate(¶ms); | 42 browser::Navigate(¶ms); |
48 } | 43 } |
49 } | 44 } |
50 | 45 |
51 void HtmlDialogTabContentsDelegate::NavigationStateChanged( | 46 void HtmlDialogTabContentsDelegate::NavigationStateChanged( |
52 const TabContents* source, unsigned changed_flags) { | 47 const TabContents* source, unsigned changed_flags) { |
53 // We shouldn't receive any NavigationStateChanged except the first | 48 // We shouldn't receive any NavigationStateChanged except the first |
54 // one, which we ignore because we're a dialog box. | 49 // one, which we ignore because we're a dialog box. |
55 } | 50 } |
56 | 51 |
57 void HtmlDialogTabContentsDelegate::AddNewContents( | 52 void HtmlDialogTabContentsDelegate::AddNewContents( |
58 TabContents* source, TabContents* new_contents, | 53 TabContents* source, TabContents* new_contents, |
59 WindowOpenDisposition disposition, const gfx::Rect& initial_pos, | 54 WindowOpenDisposition disposition, const gfx::Rect& initial_pos, |
60 bool user_gesture) { | 55 bool user_gesture) { |
61 if (profile_) { | 56 if (profile_) { |
62 // Force this to open in a new window so that it appears at the top | 57 // Specify a NULL browser for navigation. This will cause Navigate() |
63 // of the z-index. | 58 // to find a browser matching params.profile or create a new one. |
64 browser::NavigateParams params(CreateBrowser(), new_contents); | 59 Browser* browser = NULL; |
| 60 browser::NavigateParams params(browser, new_contents); |
| 61 params.profile = profile_; |
65 params.source_contents = source; | 62 params.source_contents = source; |
66 params.disposition = NEW_FOREGROUND_TAB; | 63 params.disposition = disposition; |
67 params.window_bounds = initial_pos; | 64 params.window_bounds = initial_pos; |
68 params.show_window = true; | 65 params.show_window = true; |
69 browser::Navigate(¶ms); | 66 browser::Navigate(¶ms); |
70 } | 67 } |
71 } | 68 } |
72 | 69 |
73 void HtmlDialogTabContentsDelegate::ActivateContents(TabContents* contents) { | 70 void HtmlDialogTabContentsDelegate::ActivateContents(TabContents* contents) { |
74 // We don't do anything here because there's only one TabContents in | 71 // We don't do anything here because there's only one TabContents in |
75 // this frame and we don't have a TabStripModel. | 72 // this frame and we don't have a TabStripModel. |
76 } | 73 } |
(...skipping 27 matching lines...) Expand all Loading... |
104 void HtmlDialogTabContentsDelegate::UpdateTargetURL(TabContents* source, | 101 void HtmlDialogTabContentsDelegate::UpdateTargetURL(TabContents* source, |
105 const GURL& url) { | 102 const GURL& url) { |
106 // Ignored. | 103 // Ignored. |
107 } | 104 } |
108 | 105 |
109 bool HtmlDialogTabContentsDelegate::ShouldAddNavigationToHistory( | 106 bool HtmlDialogTabContentsDelegate::ShouldAddNavigationToHistory( |
110 const history::HistoryAddPageArgs& add_page_args, | 107 const history::HistoryAddPageArgs& add_page_args, |
111 NavigationType::Type navigation_type) { | 108 NavigationType::Type navigation_type) { |
112 return false; | 109 return false; |
113 } | 110 } |
114 | |
OLD | NEW |