[email protected] | ec057339 | 2014-07-11 03:49:11 | [diff] [blame] | 1 | // Copyright 2014 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 APPS_CUSTOM_LAUNCHER_PAGE_CONTENTS_H_ |
| 6 | #define APPS_CUSTOM_LAUNCHER_PAGE_CONTENTS_H_ |
| 7 | |
| 8 | #include "base/memory/scoped_ptr.h" |
[email protected] | 9649837 | 2014-08-04 13:52:06 | [diff] [blame] | 9 | #include "content/public/browser/web_contents_delegate.h" |
[email protected] | ec057339 | 2014-07-11 03:49:11 | [diff] [blame] | 10 | #include "content/public/browser/web_contents_observer.h" |
| 11 | #include "extensions/browser/extension_function_dispatcher.h" |
| 12 | |
| 13 | class GURL; |
| 14 | |
| 15 | namespace content { |
| 16 | class BrowserContext; |
| 17 | } |
| 18 | |
[email protected] | 21d3f3a | 2014-08-20 09:39:55 | [diff] [blame] | 19 | namespace extensions { |
[email protected] | 9649837 | 2014-08-04 13:52:06 | [diff] [blame] | 20 | class AppDelegate; |
| 21 | class AppWebContentsHelper; |
[email protected] | 21d3f3a | 2014-08-20 09:39:55 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | namespace apps { |
[email protected] | 9649837 | 2014-08-04 13:52:06 | [diff] [blame] | 25 | |
[email protected] | ec057339 | 2014-07-11 03:49:11 | [diff] [blame] | 26 | // Manages the web contents for extension-hosted launcher pages. The |
| 27 | // implementation for this class should create and maintain the WebContents for |
| 28 | // the page, and handle any message passing between the web contents and the |
| 29 | // extension system. |
| 30 | class CustomLauncherPageContents |
[email protected] | 9649837 | 2014-08-04 13:52:06 | [diff] [blame] | 31 | : public content::WebContentsDelegate, |
| 32 | public content::WebContentsObserver, |
[email protected] | ec057339 | 2014-07-11 03:49:11 | [diff] [blame] | 33 | public extensions::ExtensionFunctionDispatcher::Delegate { |
| 34 | public: |
[email protected] | 21d3f3a | 2014-08-20 09:39:55 | [diff] [blame] | 35 | CustomLauncherPageContents(scoped_ptr<extensions::AppDelegate> app_delegate, |
[email protected] | 9649837 | 2014-08-04 13:52:06 | [diff] [blame] | 36 | const std::string& extension_id); |
[email protected] | ec057339 | 2014-07-11 03:49:11 | [diff] [blame] | 37 | virtual ~CustomLauncherPageContents(); |
| 38 | |
| 39 | // Called to initialize and load the WebContents. |
| 40 | void Initialize(content::BrowserContext* context, const GURL& url); |
| 41 | |
| 42 | content::WebContents* web_contents() const { return web_contents_.get(); } |
| 43 | |
[email protected] | 9649837 | 2014-08-04 13:52:06 | [diff] [blame] | 44 | // content::WebContentsDelegate overrides: |
| 45 | virtual content::WebContents* OpenURLFromTab( |
| 46 | content::WebContents* source, |
| 47 | const content::OpenURLParams& params) OVERRIDE; |
| 48 | virtual void AddNewContents(content::WebContents* source, |
| 49 | content::WebContents* new_contents, |
| 50 | WindowOpenDisposition disposition, |
| 51 | const gfx::Rect& initial_pos, |
| 52 | bool user_gesture, |
| 53 | bool* was_blocked) OVERRIDE; |
| 54 | virtual bool IsPopupOrPanel( |
| 55 | const content::WebContents* source) const OVERRIDE; |
| 56 | virtual bool ShouldSuppressDialogs() OVERRIDE; |
| 57 | virtual bool PreHandleGestureEvent( |
| 58 | content::WebContents* source, |
| 59 | const blink::WebGestureEvent& event) OVERRIDE; |
| 60 | virtual content::ColorChooser* OpenColorChooser( |
| 61 | content::WebContents* web_contents, |
| 62 | SkColor color, |
| 63 | const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE; |
| 64 | virtual void RunFileChooser( |
| 65 | content::WebContents* tab, |
| 66 | const content::FileChooserParams& params) OVERRIDE; |
| 67 | virtual void RequestToLockMouse(content::WebContents* web_contents, |
| 68 | bool user_gesture, |
| 69 | bool last_unlocked_by_target) OVERRIDE; |
| 70 | virtual void RequestMediaAccessPermission( |
| 71 | content::WebContents* web_contents, |
| 72 | const content::MediaStreamRequest& request, |
| 73 | const content::MediaResponseCallback& callback) OVERRIDE; |
| 74 | |
[email protected] | ec057339 | 2014-07-11 03:49:11 | [diff] [blame] | 75 | private: |
| 76 | // content::WebContentsObserver overrides: |
| 77 | virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 78 | |
| 79 | // extensions::ExtensionFunctionDispatcher::Delegate overrides: |
| 80 | virtual extensions::WindowController* GetExtensionWindowController() |
| 81 | const OVERRIDE; |
| 82 | virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; |
| 83 | |
| 84 | void OnRequest(const ExtensionHostMsg_Request_Params& params); |
| 85 | |
| 86 | scoped_ptr<content::WebContents> web_contents_; |
| 87 | scoped_ptr<extensions::ExtensionFunctionDispatcher> |
| 88 | extension_function_dispatcher_; |
[email protected] | 21d3f3a | 2014-08-20 09:39:55 | [diff] [blame] | 89 | scoped_ptr<extensions::AppDelegate> app_delegate_; |
| 90 | scoped_ptr<extensions::AppWebContentsHelper> helper_; |
[email protected] | 9649837 | 2014-08-04 13:52:06 | [diff] [blame] | 91 | |
| 92 | std::string extension_id_; |
[email protected] | ec057339 | 2014-07-11 03:49:11 | [diff] [blame] | 93 | |
| 94 | DISALLOW_COPY_AND_ASSIGN(CustomLauncherPageContents); |
| 95 | }; |
| 96 | |
| 97 | } // namespace apps |
| 98 | |
| 99 | #endif // APPS_CUSTOM_LAUNCHER_PAGE_CONTENTS_H_ |