1 // Copyright 2013 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 EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_CONTENTS_H_
6 #define EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_CONTENTS_H_
7 
8 #include <stdint.h>
9 
10 #include <memory>
11 
12 #include "base/macros.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "extensions/browser/app_window/app_window.h"
15 #include "url/gurl.h"
16 
17 namespace content {
18 class BrowserContext;
19 class RenderFrameHost;
20 }
21 
22 namespace extensions {
23 
24 struct DraggableRegion;
25 
26 // AppWindowContents class specific to app windows. It maintains a
27 // WebContents instance and observes it for the purpose of passing
28 // messages to the extensions system.
29 class AppWindowContentsImpl : public AppWindowContents,
30                               public content::WebContentsObserver {
31  public:
32   explicit AppWindowContentsImpl(AppWindow* host);
33   ~AppWindowContentsImpl() override;
34 
35   // AppWindowContents
36   void Initialize(content::BrowserContext* context,
37                   content::RenderFrameHost* creator_frame,
38                   const GURL& url) override;
39   void LoadContents(int32_t creator_process_id) override;
40   void NativeWindowChanged(NativeAppWindow* native_app_window) override;
41   void NativeWindowClosed(bool send_onclosed) override;
42   content::WebContents* GetWebContents() const override;
43   WindowController* GetWindowController() const override;
44 
45  private:
46   // content::WebContentsObserver
47   bool OnMessageReceived(const IPC::Message& message,
48                          content::RenderFrameHost* sender) override;
49   void DidFinishNavigation(content::NavigationHandle* handle) override;
50 
51   void UpdateDraggableRegions(content::RenderFrameHost* sender,
52                               const std::vector<DraggableRegion>& regions);
53 
54   AppWindow* host_;  // This class is owned by |host_|
55   GURL url_;
56   std::unique_ptr<content::WebContents> web_contents_;
57 
58   DISALLOW_COPY_AND_ASSIGN(AppWindowContentsImpl);
59 };
60 
61 }  // namespace extensions
62 
63 #endif  // EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_CONTENTS_H_
64