| 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 #ifndef CHROME_BROWSER_UI_WEBUI_WEB_DIALOG_WEB_CONTENTS_DELEGATE_H_ | |
| 6 #define CHROME_BROWSER_UI_WEBUI_WEB_DIALOG_WEB_CONTENTS_DELEGATE_H_ | |
| 7 | |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "content/public/browser/web_contents_delegate.h" | |
| 10 | |
| 11 // This class implements (and mostly ignores) most of | |
| 12 // content::WebContentsDelegate for use in a Web dialog. Subclasses need only | |
| 13 // override a few methods instead of the everything from | |
| 14 // content::WebContentsDelegate; this way, implementations on all platforms | |
| 15 // behave consistently. | |
| 16 class WebDialogWebContentsDelegate : public content::WebContentsDelegate { | |
| 17 public: | |
| 18 // Handles OpenURLFromTab and AddNewContents for WebDialogWebContentsDelegate. | |
| 19 class WebContentsHandler { | |
| 20 public: | |
| 21 virtual ~WebContentsHandler() {} | |
| 22 virtual content::WebContents* OpenURLFromTab( | |
| 23 content::BrowserContext* context, | |
| 24 content::WebContents* source, | |
| 25 const content::OpenURLParams& params) = 0; | |
| 26 virtual void AddNewContents(content::BrowserContext* context, | |
| 27 content::WebContents* source, | |
| 28 content::WebContents* new_contents, | |
| 29 WindowOpenDisposition disposition, | |
| 30 const gfx::Rect& initial_pos, | |
| 31 bool user_gesture) = 0; | |
| 32 }; | |
| 33 | |
| 34 // context and handler must be non-NULL. | |
| 35 // Takes the ownership of handler. | |
| 36 WebDialogWebContentsDelegate(content::BrowserContext* context, | |
| 37 WebContentsHandler* handler); | |
| 38 | |
| 39 virtual ~WebDialogWebContentsDelegate(); | |
| 40 | |
| 41 // The returned browser context is guaranteed to be original if non-NULL. | |
| 42 content::BrowserContext* browser_context() const { | |
| 43 return browser_context_; | |
| 44 } | |
| 45 | |
| 46 // Calling this causes all following events sent from the | |
| 47 // WebContents object to be ignored. It also makes all following | |
| 48 // calls to browser_context() return NULL. | |
| 49 void Detach(); | |
| 50 | |
| 51 // content::WebContentsDelegate declarations. | |
| 52 virtual content::WebContents* OpenURLFromTab( | |
| 53 content::WebContents* source, | |
| 54 const content::OpenURLParams& params) OVERRIDE; | |
| 55 | |
| 56 virtual void AddNewContents(content::WebContents* source, | |
| 57 content::WebContents* new_contents, | |
| 58 WindowOpenDisposition disposition, | |
| 59 const gfx::Rect& initial_pos, | |
| 60 bool user_gesture) OVERRIDE; | |
| 61 virtual bool IsPopupOrPanel( | |
| 62 const content::WebContents* source) const OVERRIDE; | |
| 63 virtual bool ShouldAddNavigationToHistory( | |
| 64 const history::HistoryAddPageArgs& add_page_args, | |
| 65 content::NavigationType navigation_type) OVERRIDE; | |
| 66 | |
| 67 private: | |
| 68 // Weak pointer. Always an original profile. | |
| 69 content::BrowserContext* browser_context_; | |
| 70 | |
| 71 scoped_ptr<WebContentsHandler> handler_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(WebDialogWebContentsDelegate); | |
| 74 }; | |
| 75 | |
| 76 #endif // CHROME_BROWSER_UI_WEBUI_WEB_DIALOG_WEB_CONTENTS_DELEGATE_H_ | |
| OLD | NEW |