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