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 #ifndef CHROME_BROWSER_UI_WEBUI_HTML_DIALOG_TAB_CONTENTS_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_WEB_DIALOG_WEB_CONTENTS_DELEGATE_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_HTML_DIALOG_TAB_CONTENTS_DELEGATE_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_WEB_DIALOG_WEB_CONTENTS_DELEGATE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "content/public/browser/web_contents_delegate.h" | 10 #include "content/public/browser/web_contents_delegate.h" |
11 | 11 |
12 class Browser; | 12 class Browser; |
13 class Profile; | 13 class Profile; |
14 | 14 |
15 // This class implements (and mostly ignores) most of | 15 // This class implements (and mostly ignores) most of |
16 // content::WebContentsDelegate for use in an HTML dialog. Subclasses need only | 16 // content::WebContentsDelegate for use in a Web dialog. Subclasses need only |
17 // override a few methods instead of the everything from | 17 // override a few methods instead of the everything from |
18 // content::WebContentsDelegate; this way, implementations on all platforms | 18 // content::WebContentsDelegate; this way, implementations on all platforms |
19 // behave consistently. | 19 // behave consistently. |
20 class HtmlDialogTabContentsDelegate : public content::WebContentsDelegate { | 20 class WebDialogWebContentsDelegate : public content::WebContentsDelegate { |
21 public: | 21 public: |
22 // Opens a new URL inside |source| (if source is NULL open in the current | 22 // Opens a new URL inside |source| (if source is NULL open in the current |
23 // front-most tab). |profile| is the profile that the browser should be owened | 23 // front-most tab). |profile| is the profile that the browser should be owened |
24 // by. |params| contains the URL to open and various attributes such as | 24 // by. |params| contains the URL to open and various attributes such as |
25 // disposition. On return |out_new_contents| contains the WebContents the | 25 // disposition. On return |out_new_contents| contains the WebContents the |
26 // URL is opened in. Returns the browser spawned by the operation. | 26 // URL is opened in. Returns the browser spawned by the operation. |
27 static Browser* StaticOpenURLFromTab(Profile* profile, | 27 static Browser* StaticOpenURLFromTab(Profile* profile, |
28 content::WebContents* source, | 28 content::WebContents* source, |
29 const content::OpenURLParams& params, | 29 const content::OpenURLParams& params, |
30 content::WebContents** out_new_contents); | 30 content::WebContents** out_new_contents); |
31 | 31 |
32 // Creates a new tab with |new_contents|. |profile| is the profile that the | 32 // Creates a new tab with |new_contents|. |profile| is the profile that the |
33 // browser should be owned by. |source| is the WebContent where the operation | 33 // browser should be owned by. |source| is the WebContent where the operation |
34 // originated. |disposition| controls how the new tab should be opened. | 34 // originated. |disposition| controls how the new tab should be opened. |
35 // |initial_pos| is the position of the window if a new window is created. | 35 // |initial_pos| is the position of the window if a new window is created. |
36 // |user_gesture| is true if the operation was started by a user gesture. | 36 // |user_gesture| is true if the operation was started by a user gesture. |
37 // Returns the browser spawned by the operation. | 37 // Returns the browser spawned by the operation. |
38 static Browser* StaticAddNewContents(Profile* profile, | 38 static Browser* StaticAddNewContents(Profile* profile, |
39 content::WebContents* source, | 39 content::WebContents* source, |
40 content::WebContents* new_contents, | 40 content::WebContents* new_contents, |
41 WindowOpenDisposition disposition, | 41 WindowOpenDisposition disposition, |
42 const gfx::Rect& initial_pos, | 42 const gfx::Rect& initial_pos, |
43 bool user_gesture); | 43 bool user_gesture); |
44 | 44 |
45 // Profile must be non-NULL. | 45 // Profile must be non-NULL. |
46 explicit HtmlDialogTabContentsDelegate(Profile* profile); | 46 explicit WebDialogWebContentsDelegate(Profile* profile); |
47 | 47 |
48 virtual ~HtmlDialogTabContentsDelegate(); | 48 virtual ~WebDialogWebContentsDelegate(); |
49 | 49 |
50 // The returned profile is guaranteed to be original if non-NULL. | 50 // The returned profile is guaranteed to be original if non-NULL. |
51 Profile* profile() const; | 51 Profile* profile() const; |
52 | 52 |
53 // Calling this causes all following events sent from the | 53 // Calling this causes all following events sent from the |
54 // WebContents object to be ignored. It also makes all following | 54 // WebContents object to be ignored. It also makes all following |
55 // calls to profile() return NULL. | 55 // calls to profile() return NULL. |
56 void Detach(); | 56 void Detach(); |
57 | 57 |
58 // content::WebContentsDelegate declarations. | 58 // content::WebContentsDelegate declarations. |
59 virtual content::WebContents* OpenURLFromTab( | 59 virtual content::WebContents* OpenURLFromTab( |
60 content::WebContents* source, | 60 content::WebContents* source, |
61 const content::OpenURLParams& params) OVERRIDE; | 61 const content::OpenURLParams& params) OVERRIDE; |
62 | 62 |
63 virtual void AddNewContents(content::WebContents* source, | 63 virtual void AddNewContents(content::WebContents* source, |
64 content::WebContents* new_contents, | 64 content::WebContents* new_contents, |
65 WindowOpenDisposition disposition, | 65 WindowOpenDisposition disposition, |
66 const gfx::Rect& initial_pos, | 66 const gfx::Rect& initial_pos, |
67 bool user_gesture) OVERRIDE; | 67 bool user_gesture) OVERRIDE; |
68 virtual bool IsPopupOrPanel( | 68 virtual bool IsPopupOrPanel( |
69 const content::WebContents* source) const OVERRIDE; | 69 const content::WebContents* source) const OVERRIDE; |
70 virtual bool ShouldAddNavigationToHistory( | 70 virtual bool ShouldAddNavigationToHistory( |
71 const history::HistoryAddPageArgs& add_page_args, | 71 const history::HistoryAddPageArgs& add_page_args, |
72 content::NavigationType navigation_type) OVERRIDE; | 72 content::NavigationType navigation_type) OVERRIDE; |
73 | 73 |
74 private: | 74 private: |
75 Profile* profile_; // Weak pointer. Always an original profile. | 75 Profile* profile_; // Weak pointer. Always an original profile. |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(WebDialogWebContentsDelegate); |
76 }; | 78 }; |
77 | 79 |
78 #endif // CHROME_BROWSER_UI_WEBUI_HTML_DIALOG_TAB_CONTENTS_DELEGATE_H_ | 80 #endif // CHROME_BROWSER_UI_WEBUI_WEB_DIALOG_WEB_CONTENTS_DELEGATE_H_ |
OLD | NEW |