Index: apps/app_window_registry.cc |
diff --git a/apps/shell_window_registry.cc b/apps/app_window_registry.cc |
similarity index 41% |
rename from apps/shell_window_registry.cc |
rename to apps/app_window_registry.cc |
index 093263b9a16092233937a795d601b86530196b41..f6aa789af8ac1b513f5a322439246a331acb77ea 100644 |
--- a/apps/shell_window_registry.cc |
+++ b/apps/app_window_registry.cc |
@@ -2,9 +2,9 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "apps/app_window.h" |
+#include "apps/app_window_registry.h" |
#include "apps/apps_client.h" |
-#include "apps/shell_window.h" |
-#include "apps/shell_window_registry.h" |
#include "apps/ui/native_app_window.h" |
#include "components/browser_context_keyed_service/browser_context_dependency_manager.h" |
#include "content/public/browser/browser_context.h" |
@@ -19,25 +19,25 @@ |
namespace { |
-// Create a key that identifies a ShellWindow in a RenderViewHost across App |
+// Create a key that identifies a AppWindow in a RenderViewHost across App |
// reloads. If the window was given an id in CreateParams, the key is the |
-// extension id, a colon separator, and the ShellWindow's |id|. If there is no |
+// extension id, a colon separator, and the AppWindow's |id|. If there is no |
// |id|, the chrome-extension://extension-id/page.html URL will be used. If the |
-// RenderViewHost is not for a ShellWindow, return an empty string. |
+// RenderViewHost is not for a AppWindow, return an empty string. |
std::string GetWindowKeyForRenderViewHost( |
- const apps::ShellWindowRegistry* registry, |
+ const apps::AppWindowRegistry* registry, |
content::RenderViewHost* render_view_host) { |
- apps::ShellWindow* shell_window = |
- registry->GetShellWindowForRenderViewHost(render_view_host); |
- if (!shell_window) |
- return std::string(); // Not a ShellWindow. |
+ apps::AppWindow* app_window = |
+ registry->GetAppWindowForRenderViewHost(render_view_host); |
+ if (!app_window) |
+ return std::string(); // Not a AppWindow. |
- if (shell_window->window_key().empty()) |
- return shell_window->web_contents()->GetURL().possibly_invalid_spec(); |
+ if (app_window->window_key().empty()) |
+ return app_window->web_contents()->GetURL().possibly_invalid_spec(); |
- std::string key = shell_window->extension()->id(); |
+ std::string key = app_window->extension()->id(); |
key += ':'; |
- key += shell_window->window_key(); |
+ key += app_window->window_key(); |
return key; |
} |
@@ -45,83 +45,80 @@ std::string GetWindowKeyForRenderViewHost( |
namespace apps { |
-ShellWindowRegistry::ShellWindowRegistry(content::BrowserContext* context) |
+AppWindowRegistry::AppWindowRegistry(content::BrowserContext* context) |
: context_(context), |
- devtools_callback_(base::Bind( |
- &ShellWindowRegistry::OnDevToolsStateChanged, |
- base::Unretained(this))) { |
+ devtools_callback_(base::Bind(&AppWindowRegistry::OnDevToolsStateChanged, |
+ base::Unretained(this))) { |
content::DevToolsManager::GetInstance()->AddAgentStateCallback( |
devtools_callback_); |
} |
-ShellWindowRegistry::~ShellWindowRegistry() { |
+AppWindowRegistry::~AppWindowRegistry() { |
content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( |
devtools_callback_); |
} |
// static |
-ShellWindowRegistry* ShellWindowRegistry::Get( |
- content::BrowserContext* context) { |
+AppWindowRegistry* AppWindowRegistry::Get(content::BrowserContext* context) { |
return Factory::GetForBrowserContext(context, true /* create */); |
} |
-void ShellWindowRegistry::AddShellWindow(ShellWindow* shell_window) { |
- BringToFront(shell_window); |
- FOR_EACH_OBSERVER(Observer, observers_, OnShellWindowAdded(shell_window)); |
+void AppWindowRegistry::AddAppWindow(AppWindow* app_window) { |
+ BringToFront(app_window); |
+ FOR_EACH_OBSERVER(Observer, observers_, OnAppWindowAdded(app_window)); |
} |
-void ShellWindowRegistry::ShellWindowIconChanged(ShellWindow* shell_window) { |
- AddShellWindowToList(shell_window); |
- FOR_EACH_OBSERVER(Observer, observers_, |
- OnShellWindowIconChanged(shell_window)); |
+void AppWindowRegistry::AppWindowIconChanged(AppWindow* app_window) { |
+ AddAppWindowToList(app_window); |
+ FOR_EACH_OBSERVER(Observer, observers_, OnAppWindowIconChanged(app_window)); |
} |
-void ShellWindowRegistry::ShellWindowActivated(ShellWindow* shell_window) { |
- BringToFront(shell_window); |
+void AppWindowRegistry::AppWindowActivated(AppWindow* app_window) { |
+ BringToFront(app_window); |
} |
-void ShellWindowRegistry::RemoveShellWindow(ShellWindow* shell_window) { |
- const ShellWindowList::iterator it = std::find(shell_windows_.begin(), |
- shell_windows_.end(), |
- shell_window); |
- if (it != shell_windows_.end()) |
- shell_windows_.erase(it); |
- FOR_EACH_OBSERVER(Observer, observers_, OnShellWindowRemoved(shell_window)); |
+void AppWindowRegistry::RemoveAppWindow(AppWindow* app_window) { |
+ const AppWindowList::iterator it = |
+ std::find(app_windows_.begin(), app_windows_.end(), app_window); |
+ if (it != app_windows_.end()) |
+ app_windows_.erase(it); |
+ FOR_EACH_OBSERVER(Observer, observers_, OnAppWindowRemoved(app_window)); |
} |
-void ShellWindowRegistry::AddObserver(Observer* observer) { |
+void AppWindowRegistry::AddObserver(Observer* observer) { |
observers_.AddObserver(observer); |
} |
-void ShellWindowRegistry::RemoveObserver(Observer* observer) { |
+void AppWindowRegistry::RemoveObserver(Observer* observer) { |
observers_.RemoveObserver(observer); |
} |
-ShellWindowRegistry::ShellWindowList ShellWindowRegistry::GetShellWindowsForApp( |
+AppWindowRegistry::AppWindowList AppWindowRegistry::GetAppWindowsForApp( |
const std::string& app_id) const { |
- ShellWindowList app_windows; |
- for (ShellWindowList::const_iterator i = shell_windows_.begin(); |
- i != shell_windows_.end(); ++i) { |
+ AppWindowList app_windows; |
+ for (AppWindowList::const_iterator i = app_windows_.begin(); |
+ i != app_windows_.end(); |
+ ++i) { |
if ((*i)->extension_id() == app_id) |
app_windows.push_back(*i); |
} |
return app_windows; |
} |
-void ShellWindowRegistry::CloseAllShellWindowsForApp( |
- const std::string& app_id) { |
- for (ShellWindowList::const_iterator i = shell_windows_.begin(); |
- i != shell_windows_.end(); ) { |
- ShellWindow* shell_window = *(i++); |
- if (shell_window->extension_id() == app_id) |
- shell_window->GetBaseWindow()->Close(); |
+void AppWindowRegistry::CloseAllAppWindowsForApp(const std::string& app_id) { |
+ for (AppWindowList::const_iterator i = app_windows_.begin(); |
+ i != app_windows_.end();) { |
+ AppWindow* app_window = *(i++); |
+ if (app_window->extension_id() == app_id) |
+ app_window->GetBaseWindow()->Close(); |
} |
} |
-ShellWindow* ShellWindowRegistry::GetShellWindowForRenderViewHost( |
+AppWindow* AppWindowRegistry::GetAppWindowForRenderViewHost( |
content::RenderViewHost* render_view_host) const { |
- for (ShellWindowList::const_iterator i = shell_windows_.begin(); |
- i != shell_windows_.end(); ++i) { |
+ for (AppWindowList::const_iterator i = app_windows_.begin(); |
+ i != app_windows_.end(); |
+ ++i) { |
if ((*i)->web_contents()->GetRenderViewHost() == render_view_host) |
return *i; |
} |
@@ -129,10 +126,11 @@ ShellWindow* ShellWindowRegistry::GetShellWindowForRenderViewHost( |
return NULL; |
} |
-ShellWindow* ShellWindowRegistry::GetShellWindowForNativeWindow( |
+AppWindow* AppWindowRegistry::GetAppWindowForNativeWindow( |
gfx::NativeWindow window) const { |
- for (ShellWindowList::const_iterator i = shell_windows_.begin(); |
- i != shell_windows_.end(); ++i) { |
+ for (AppWindowList::const_iterator i = app_windows_.begin(); |
+ i != app_windows_.end(); |
+ ++i) { |
if ((*i)->GetNativeWindow() == window) |
return *i; |
} |
@@ -140,11 +138,12 @@ ShellWindow* ShellWindowRegistry::GetShellWindowForNativeWindow( |
return NULL; |
} |
-ShellWindow* ShellWindowRegistry::GetCurrentShellWindowForApp( |
+AppWindow* AppWindowRegistry::GetCurrentAppWindowForApp( |
const std::string& app_id) const { |
- ShellWindow* result = NULL; |
- for (ShellWindowList::const_iterator i = shell_windows_.begin(); |
- i != shell_windows_.end(); ++i) { |
+ AppWindow* result = NULL; |
+ for (AppWindowList::const_iterator i = app_windows_.begin(); |
+ i != app_windows_.end(); |
+ ++i) { |
if ((*i)->extension()->id() == app_id) { |
result = *i; |
if (result->GetBaseWindow()->IsActive()) |
@@ -155,12 +154,13 @@ ShellWindow* ShellWindowRegistry::GetCurrentShellWindowForApp( |
return result; |
} |
-ShellWindow* ShellWindowRegistry::GetShellWindowForAppAndKey( |
+AppWindow* AppWindowRegistry::GetAppWindowForAppAndKey( |
const std::string& app_id, |
const std::string& window_key) const { |
- ShellWindow* result = NULL; |
- for (ShellWindowList::const_iterator i = shell_windows_.begin(); |
- i != shell_windows_.end(); ++i) { |
+ AppWindow* result = NULL; |
+ for (AppWindowList::const_iterator i = app_windows_.begin(); |
+ i != app_windows_.end(); |
+ ++i) { |
if ((*i)->extension()->id() == app_id && (*i)->window_key() == window_key) { |
result = *i; |
if (result->GetBaseWindow()->IsActive()) |
@@ -170,55 +170,56 @@ ShellWindow* ShellWindowRegistry::GetShellWindowForAppAndKey( |
return result; |
} |
-bool ShellWindowRegistry::HadDevToolsAttached( |
+bool AppWindowRegistry::HadDevToolsAttached( |
content::RenderViewHost* render_view_host) const { |
std::string key = GetWindowKeyForRenderViewHost(this, render_view_host); |
return key.empty() ? false : inspected_windows_.count(key) != 0; |
} |
// static |
-ShellWindow* ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile( |
+AppWindow* AppWindowRegistry::GetAppWindowForNativeWindowAnyProfile( |
gfx::NativeWindow window) { |
std::vector<content::BrowserContext*> contexts = |
AppsClient::Get()->GetLoadedBrowserContexts(); |
for (std::vector<content::BrowserContext*>::const_iterator i = |
contexts.begin(); |
- i != contexts.end(); ++i) { |
- ShellWindowRegistry* registry = Factory::GetForBrowserContext( |
- *i, false /* create */); |
+ i != contexts.end(); |
+ ++i) { |
+ AppWindowRegistry* registry = |
+ Factory::GetForBrowserContext(*i, false /* create */); |
if (!registry) |
continue; |
- ShellWindow* shell_window = registry->GetShellWindowForNativeWindow(window); |
- if (shell_window) |
- return shell_window; |
+ AppWindow* app_window = registry->GetAppWindowForNativeWindow(window); |
+ if (app_window) |
+ return app_window; |
} |
return NULL; |
} |
// static |
-bool ShellWindowRegistry::IsShellWindowRegisteredInAnyProfile( |
+bool AppWindowRegistry::IsAppWindowRegisteredInAnyProfile( |
int window_type_mask) { |
std::vector<content::BrowserContext*> contexts = |
AppsClient::Get()->GetLoadedBrowserContexts(); |
for (std::vector<content::BrowserContext*>::const_iterator i = |
contexts.begin(); |
- i != contexts.end(); ++i) { |
- ShellWindowRegistry* registry = Factory::GetForBrowserContext( |
- *i, false /* create */); |
+ i != contexts.end(); |
+ ++i) { |
+ AppWindowRegistry* registry = |
+ Factory::GetForBrowserContext(*i, false /* create */); |
if (!registry) |
continue; |
- const ShellWindowList& shell_windows = registry->shell_windows(); |
- if (shell_windows.empty()) |
+ const AppWindowList& app_windows = registry->app_windows(); |
+ if (app_windows.empty()) |
continue; |
if (window_type_mask == 0) |
return true; |
- for (const_iterator j = shell_windows.begin(); j != shell_windows.end(); |
- ++j) { |
+ for (const_iterator j = app_windows.begin(); j != app_windows.end(); ++j) { |
if ((*j)->window_type() & window_type_mask) |
return true; |
} |
@@ -227,8 +228,9 @@ bool ShellWindowRegistry::IsShellWindowRegisteredInAnyProfile( |
return false; |
} |
-void ShellWindowRegistry::OnDevToolsStateChanged( |
- content::DevToolsAgentHost* agent_host, bool attached) { |
+void AppWindowRegistry::OnDevToolsStateChanged( |
+ content::DevToolsAgentHost* agent_host, |
+ bool attached) { |
content::RenderViewHost* rvh = agent_host->GetRenderViewHost(); |
// Ignore unrelated notifications. |
if (!rvh || |
@@ -245,65 +247,61 @@ void ShellWindowRegistry::OnDevToolsStateChanged( |
inspected_windows_.erase(key); |
} |
-void ShellWindowRegistry::AddShellWindowToList(ShellWindow* shell_window) { |
- const ShellWindowList::iterator it = std::find(shell_windows_.begin(), |
- shell_windows_.end(), |
- shell_window); |
- if (it != shell_windows_.end()) |
+void AppWindowRegistry::AddAppWindowToList(AppWindow* app_window) { |
+ const AppWindowList::iterator it = |
+ std::find(app_windows_.begin(), app_windows_.end(), app_window); |
+ if (it != app_windows_.end()) |
return; |
- shell_windows_.push_back(shell_window); |
+ app_windows_.push_back(app_window); |
} |
-void ShellWindowRegistry::BringToFront(ShellWindow* shell_window) { |
- const ShellWindowList::iterator it = std::find(shell_windows_.begin(), |
- shell_windows_.end(), |
- shell_window); |
- if (it != shell_windows_.end()) |
- shell_windows_.erase(it); |
- shell_windows_.push_front(shell_window); |
+void AppWindowRegistry::BringToFront(AppWindow* app_window) { |
+ const AppWindowList::iterator it = |
+ std::find(app_windows_.begin(), app_windows_.end(), app_window); |
+ if (it != app_windows_.end()) |
+ app_windows_.erase(it); |
+ app_windows_.push_front(app_window); |
} |
/////////////////////////////////////////////////////////////////////////////// |
// Factory boilerplate |
// static |
-ShellWindowRegistry* ShellWindowRegistry::Factory::GetForBrowserContext( |
- content::BrowserContext* context, bool create) { |
- return static_cast<ShellWindowRegistry*>( |
+AppWindowRegistry* AppWindowRegistry::Factory::GetForBrowserContext( |
+ content::BrowserContext* context, |
+ bool create) { |
+ return static_cast<AppWindowRegistry*>( |
GetInstance()->GetServiceForBrowserContext(context, create)); |
} |
-ShellWindowRegistry::Factory* ShellWindowRegistry::Factory::GetInstance() { |
- return Singleton<ShellWindowRegistry::Factory>::get(); |
+AppWindowRegistry::Factory* AppWindowRegistry::Factory::GetInstance() { |
+ return Singleton<AppWindowRegistry::Factory>::get(); |
} |
-ShellWindowRegistry::Factory::Factory() |
+AppWindowRegistry::Factory::Factory() |
: BrowserContextKeyedServiceFactory( |
- "ShellWindowRegistry", |
- BrowserContextDependencyManager::GetInstance()) { |
-} |
+ "AppWindowRegistry", |
+ BrowserContextDependencyManager::GetInstance()) {} |
-ShellWindowRegistry::Factory::~Factory() { |
-} |
+AppWindowRegistry::Factory::~Factory() {} |
-BrowserContextKeyedService* |
-ShellWindowRegistry::Factory::BuildServiceInstanceFor( |
+BrowserContextKeyedService* AppWindowRegistry::Factory::BuildServiceInstanceFor( |
content::BrowserContext* context) const { |
- return new ShellWindowRegistry(context); |
+ return new AppWindowRegistry(context); |
} |
-bool ShellWindowRegistry::Factory::ServiceIsCreatedWithBrowserContext() const { |
+bool AppWindowRegistry::Factory::ServiceIsCreatedWithBrowserContext() const { |
return true; |
} |
-bool ShellWindowRegistry::Factory::ServiceIsNULLWhileTesting() const { |
+bool AppWindowRegistry::Factory::ServiceIsNULLWhileTesting() const { |
return false; |
} |
-content::BrowserContext* ShellWindowRegistry::Factory::GetBrowserContextToUse( |
+content::BrowserContext* AppWindowRegistry::Factory::GetBrowserContextToUse( |
content::BrowserContext* context) const { |
- return extensions::ExtensionsBrowserClient::Get()-> |
- GetOriginalContext(context); |
+ return extensions::ExtensionsBrowserClient::Get()->GetOriginalContext( |
+ context); |
} |
} // namespace extensions |