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/html_dialog_tab_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 HtmlDialogTabContentsDelegate::HtmlDialogTabContentsDelegate(Profile* profile) | |
24 : profile_(profile) {} | |
25 | |
26 HtmlDialogTabContentsDelegate::~HtmlDialogTabContentsDelegate() {} | |
27 | |
28 Profile* HtmlDialogTabContentsDelegate::profile() const { return profile_; } | |
29 | |
30 void HtmlDialogTabContentsDelegate::Detach() { | |
31 profile_ = NULL; | |
32 } | |
33 | |
34 WebContents* HtmlDialogTabContentsDelegate::OpenURLFromTab( | |
35 WebContents* source, const OpenURLParams& params) { | |
36 WebContents* new_contents = NULL; | |
37 StaticOpenURLFromTab(profile_, source, params, &new_contents); | |
38 return new_contents; | |
39 } | |
40 | |
41 // static | |
42 Browser* HtmlDialogTabContentsDelegate::StaticOpenURLFromTab( | |
43 Profile* profile, WebContents* source, const OpenURLParams& params, | |
44 WebContents** out_new_contents) { | |
45 if (!profile) | |
46 return NULL; | |
47 | |
48 // Specify a NULL browser for navigation. This will cause Navigate() | |
49 // to find a browser matching params.profile or create a new one. | |
50 Browser* browser = NULL; | |
51 browser::NavigateParams nav_params(browser, params.url, params.transition); | |
52 nav_params.profile = profile; | |
53 nav_params.referrer = params.referrer; | |
54 if (source && source->IsCrashed() && | |
55 params.disposition == CURRENT_TAB && | |
56 params.transition == content::PAGE_TRANSITION_LINK) { | |
57 nav_params.disposition = NEW_FOREGROUND_TAB; | |
58 } else { | |
59 nav_params.disposition = params.disposition; | |
60 } | |
61 nav_params.window_action = browser::NavigateParams::SHOW_WINDOW; | |
62 nav_params.user_gesture = true; | |
63 browser::Navigate(&nav_params); | |
64 *out_new_contents = nav_params.target_contents ? | |
65 nav_params.target_contents->web_contents() : NULL; | |
66 return nav_params.browser; | |
67 } | |
68 | |
69 void HtmlDialogTabContentsDelegate::AddNewContents( | |
70 WebContents* source, WebContents* new_contents, | |
71 WindowOpenDisposition disposition, const gfx::Rect& initial_pos, | |
72 bool user_gesture) { | |
73 StaticAddNewContents(profile_, source, new_contents, disposition, | |
74 initial_pos, user_gesture); | |
75 } | |
76 | |
77 // static | |
78 Browser* HtmlDialogTabContentsDelegate::StaticAddNewContents( | |
79 Profile* profile, | |
80 WebContents* source, | |
81 WebContents* new_contents, | |
82 WindowOpenDisposition disposition, | |
83 const gfx::Rect& initial_pos, | |
84 bool user_gesture) { | |
85 if (!profile) | |
86 return NULL; | |
87 | |
88 // Specify a NULL browser for navigation. This will cause Navigate() | |
89 // to find a browser matching params.profile or create a new one. | |
90 Browser* browser = NULL; | |
91 | |
92 TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); | |
93 browser::NavigateParams params(browser, wrapper); | |
94 params.profile = profile; | |
95 // TODO(pinkerton): no way to get a wrapper for this. | |
96 // params.source_contents = source; | |
97 params.disposition = disposition; | |
98 params.window_bounds = initial_pos; | |
99 params.window_action = browser::NavigateParams::SHOW_WINDOW; | |
100 params.user_gesture = true; | |
101 browser::Navigate(¶ms); | |
102 | |
103 return params.browser; | |
104 } | |
105 | |
106 bool HtmlDialogTabContentsDelegate::IsPopupOrPanel( | |
107 const WebContents* source) const { | |
108 // This needs to return true so that we are allowed to be resized by our | |
109 // contents. | |
110 return true; | |
111 } | |
112 | |
113 bool HtmlDialogTabContentsDelegate::ShouldAddNavigationToHistory( | |
114 const history::HistoryAddPageArgs& add_page_args, | |
115 content::NavigationType navigation_type) { | |
116 return false; | |
117 } | |
OLD | NEW |