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

Side by Side Diff: chrome/browser/ui/webui/web_dialog_web_contents_delegate.cc

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

Powered by Google App Engine
This is Rietveld 408576698