| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_REGISTRY_H_ | 5 #ifndef EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_REGISTRY_H_ |
| 6 #define EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_REGISTRY_H_ | 6 #define EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" | 16 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" |
| 17 #include "components/keyed_service/core/keyed_service.h" | 17 #include "components/keyed_service/core/keyed_service.h" |
| 18 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 class BrowserContext; | 21 class BrowserContext; |
| 22 class DevToolsAgentHost; | 22 class DevToolsAgentHost; |
| 23 class RenderViewHost; | |
| 24 class WebContents; | 23 class WebContents; |
| 25 } | 24 } |
| 26 | 25 |
| 27 namespace extensions { | 26 namespace extensions { |
| 28 | 27 |
| 29 class AppWindow; | 28 class AppWindow; |
| 30 | 29 |
| 31 // The AppWindowRegistry tracks the AppWindows for all platform apps for a | 30 // The AppWindowRegistry tracks the AppWindows for all platform apps for a |
| 32 // particular browser context. | 31 // particular browser context. |
| 33 class AppWindowRegistry : public KeyedService { | 32 class AppWindowRegistry : public KeyedService { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 77 |
| 79 // Returns a set of windows owned by the application identified by app_id. | 78 // Returns a set of windows owned by the application identified by app_id. |
| 80 AppWindowList GetAppWindowsForApp(const std::string& app_id) const; | 79 AppWindowList GetAppWindowsForApp(const std::string& app_id) const; |
| 81 const AppWindowList& app_windows() const { return app_windows_; } | 80 const AppWindowList& app_windows() const { return app_windows_; } |
| 82 | 81 |
| 83 // Close all app windows associated with an app. | 82 // Close all app windows associated with an app. |
| 84 void CloseAllAppWindowsForApp(const std::string& app_id); | 83 void CloseAllAppWindowsForApp(const std::string& app_id); |
| 85 | 84 |
| 86 // Helper functions to find app windows with particular attributes. | 85 // Helper functions to find app windows with particular attributes. |
| 87 AppWindow* GetAppWindowForWebContents( | 86 AppWindow* GetAppWindowForWebContents( |
| 88 content::WebContents* web_contents) const; | 87 const content::WebContents* web_contents) const; |
| 89 // TODO(devlin): Remove this when callers have been updated to use the | |
| 90 // above. | |
| 91 AppWindow* GetAppWindowForRenderViewHost( | |
| 92 content::RenderViewHost* render_view_host) const; | |
| 93 AppWindow* GetAppWindowForNativeWindow(gfx::NativeWindow window) const; | 88 AppWindow* GetAppWindowForNativeWindow(gfx::NativeWindow window) const; |
| 94 // Returns an app window for the given app, or NULL if no app windows are | 89 // Returns an app window for the given app, or NULL if no app windows are |
| 95 // open. If there is a window for the given app that is active, that one will | 90 // open. If there is a window for the given app that is active, that one will |
| 96 // be returned, otherwise an arbitrary window will be returned. | 91 // be returned, otherwise an arbitrary window will be returned. |
| 97 AppWindow* GetCurrentAppWindowForApp(const std::string& app_id) const; | 92 AppWindow* GetCurrentAppWindowForApp(const std::string& app_id) const; |
| 98 // Returns an app window for the given app and window key, or NULL if no app | 93 // Returns an app window for the given app and window key, or NULL if no app |
| 99 // window with the key are open. If there is a window for the given app and | 94 // window with the key are open. If there is a window for the given app and |
| 100 // key that is active, that one will be returned, otherwise an arbitrary | 95 // key that is active, that one will be returned, otherwise an arbitrary |
| 101 // window will be returned. | 96 // window will be returned. |
| 102 AppWindow* GetAppWindowForAppAndKey(const std::string& app_id, | 97 AppWindow* GetAppWindowForAppAndKey(const std::string& app_id, |
| 103 const std::string& window_key) const; | 98 const std::string& window_key) const; |
| 104 | 99 |
| 105 // Returns whether a AppWindow's ID was last known to have a DevToolsAgent | 100 // Returns whether a AppWindow's ID was last known to have a DevToolsAgent |
| 106 // attached to it, which should be restored during a reload of a corresponding | 101 // attached to it, which should be restored during a reload of a corresponding |
| 107 // newly created |render_view_host|. | 102 // newly created |web_contents|. |
| 108 bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const; | 103 bool HadDevToolsAttached(content::WebContents* web_contents) const; |
| 109 | 104 |
| 110 class Factory : public BrowserContextKeyedServiceFactory { | 105 class Factory : public BrowserContextKeyedServiceFactory { |
| 111 public: | 106 public: |
| 112 static AppWindowRegistry* GetForBrowserContext( | 107 static AppWindowRegistry* GetForBrowserContext( |
| 113 content::BrowserContext* context, | 108 content::BrowserContext* context, |
| 114 bool create); | 109 bool create); |
| 115 | 110 |
| 116 static Factory* GetInstance(); | 111 static Factory* GetInstance(); |
| 117 | 112 |
| 118 private: | 113 private: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 135 | 130 |
| 136 private: | 131 private: |
| 137 // Ensures the specified |app_window| is included in |app_windows_|. | 132 // Ensures the specified |app_window| is included in |app_windows_|. |
| 138 // Otherwise adds |app_window| to the back of |app_windows_|. | 133 // Otherwise adds |app_window| to the back of |app_windows_|. |
| 139 void AddAppWindowToList(AppWindow* app_window); | 134 void AddAppWindowToList(AppWindow* app_window); |
| 140 | 135 |
| 141 // Bring |app_window| to the front of |app_windows_|. If it is not in the | 136 // Bring |app_window| to the front of |app_windows_|. If it is not in the |
| 142 // list, add it first. | 137 // list, add it first. |
| 143 void BringToFront(AppWindow* app_window); | 138 void BringToFront(AppWindow* app_window); |
| 144 | 139 |
| 140 // Create a key that identifies an AppWindow across App reloads. If the window |
| 141 // was given an id in CreateParams, the key is the extension id, a colon |
| 142 // separator, and the AppWindow's |id|. If there is no |id|, the |
| 143 // chrome-extension://extension-id/page.html URL will be used. If the |
| 144 // WebContents is not for a AppWindow, return an empty string. |
| 145 std::string GetWindowKeyForWebContents( |
| 146 content::WebContents* web_contents) const; |
| 147 |
| 145 content::BrowserContext* context_; | 148 content::BrowserContext* context_; |
| 146 AppWindowList app_windows_; | 149 AppWindowList app_windows_; |
| 147 InspectedWindowSet inspected_windows_; | 150 InspectedWindowSet inspected_windows_; |
| 148 base::ObserverList<Observer> observers_; | 151 base::ObserverList<Observer> observers_; |
| 149 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; | 152 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; |
| 150 }; | 153 }; |
| 151 | 154 |
| 152 } // namespace extensions | 155 } // namespace extensions |
| 153 | 156 |
| 154 #endif // EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_REGISTRY_H_ | 157 #endif // EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_REGISTRY_H_ |
| OLD | NEW |