Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: chrome/browser/dom_ui/html_dialog_tab_contents_delegate.cc

Issue 441011: Created HtmlDialogTabContentsDelegate, which encapsulates the (Closed)
Patch Set: Synced to head. Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/dom_ui/html_dialog_tab_contents_delegate.h"
6
7 #include "chrome/browser/browser.h"
8 #include "chrome/browser/browser_window.h"
9 #include "chrome/browser/profile.h"
10 #include "chrome/browser/tab_contents/tab_contents.h"
11
12 // Incognito profiles are not long-lived, so we always want to store a
13 // non-incognito profile.
14 //
15 // TODO(akalin): Should we make it so that we have a default incognito
16 // profile that's long-lived? Of course, we'd still have to clear it out
17 // when all incognito browsers close.
18 HtmlDialogTabContentsDelegate::HtmlDialogTabContentsDelegate(Profile* profile)
19 : profile_(profile->GetOriginalProfile()) {}
20
21 HtmlDialogTabContentsDelegate::~HtmlDialogTabContentsDelegate() {}
22
23 Profile* HtmlDialogTabContentsDelegate::profile() const { return profile_; }
24
25 void HtmlDialogTabContentsDelegate::Detach() {
26 profile_ = NULL;
27 }
28
29 Browser* HtmlDialogTabContentsDelegate::CreateBrowser() {
30 DCHECK(profile_);
31 return Browser::Create(profile_);
32 }
33
34 void HtmlDialogTabContentsDelegate::OpenURLFromTab(
35 TabContents* source, const GURL& url, const GURL& referrer,
36 WindowOpenDisposition disposition, PageTransition::Type transition) {
37 if (profile_) {
38 // Force all links to open in a new window, ignoring the incoming
39 // disposition. This is a tabless, modal dialog so we can't just
40 // open it in the current frame. Code adapted from
41 // Browser::OpenURLFromTab() with disposition == NEW_WINDOW.
42 Browser* browser = CreateBrowser();
43 TabContents* new_contents =
44 browser->AddTabWithURL(url, referrer, transition, true, -1, false,
45 NULL);
46 DCHECK(new_contents);
47 browser->window()->Show();
48 new_contents->Focus();
49 }
50 }
51
52 void HtmlDialogTabContentsDelegate::NavigationStateChanged(
53 const TabContents* source, unsigned changed_flags) {
54 // We shouldn't receive any NavigationStateChanged except the first
55 // one, which we ignore because we're a dialog box.
56 }
57
58 void HtmlDialogTabContentsDelegate::AddNewContents(
59 TabContents* source, TabContents* new_contents,
60 WindowOpenDisposition disposition, const gfx::Rect& initial_pos,
61 bool user_gesture) {
62 if (profile_) {
63 // Force this to open in a new window, too. Code adapted from
64 // Browser::AddNewContents() with disposition == NEW_WINDOW.
65 Browser* browser = CreateBrowser();
66 static_cast<TabContentsDelegate*>(browser)->
67 AddNewContents(source, new_contents, NEW_FOREGROUND_TAB,
68 initial_pos, user_gesture);
69 browser->window()->Show();
70 }
71 }
72
73 void HtmlDialogTabContentsDelegate::ActivateContents(TabContents* contents) {
74 // We don't do anything here because there's only one TabContents in
75 // this frame and we don't have a TabStripModel.
76 }
77
78 void HtmlDialogTabContentsDelegate::LoadingStateChanged(TabContents* source) {
79 // We don't care about this notification.
80 }
81
82 void HtmlDialogTabContentsDelegate::CloseContents(TabContents* source) {
83 // We receive this message but don't handle it because we really do the
84 // cleanup somewhere else (namely, HtmlDialogUIDelegate::OnDialogClosed()).
85 }
86
87 bool HtmlDialogTabContentsDelegate::IsPopup(TabContents* source) {
88 // This needs to return true so that we are allowed to be resized by our
89 // contents.
90 return true;
91 }
92
93 void HtmlDialogTabContentsDelegate::URLStarredChanged(TabContents* source,
94 bool starred) {
95 // We don't have a visible star to click in the window.
96 NOTREACHED();
97 }
98
99 void HtmlDialogTabContentsDelegate::UpdateTargetURL(TabContents* source,
100 const GURL& url) {
101 // Ignored.
102 }
103
104 bool HtmlDialogTabContentsDelegate::ShouldAddNavigationToHistory() const {
105 return false;
106 }
107
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698