diff options
author | rdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-17 20:36:57 +0000 |
---|---|---|
committer | rdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-17 20:36:57 +0000 |
commit | 44f4b13cdb4e198475e9150b9f9e9f3fa8d35b47 (patch) | |
tree | be1d09d56535d967e05e709499dca570301c74c8 | |
parent | 0776b0bfbc5a634e3f89cd0f0105d7e2f727db92 (diff) | |
download | chromium_src-44f4b13cdb4e198475e9150b9f9e9f3fa8d35b47.zip chromium_src-44f4b13cdb4e198475e9150b9f9e9f3fa8d35b47.tar.gz chromium_src-44f4b13cdb4e198475e9150b9f9e9f3fa8d35b47.tar.bz2 |
Move ExtensionWindowController and related into extensions namespace
Moved ExtensionWindowController, BrowserExtensionWindowController,
ExtensionWindowList to extensions namespace; renamed appropriately.
BUG=136874, 117261
Review URL: https://chromiumcodereview.appspot.com/10735061
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147083 0039d316-1c4b-4281-b951-d872f2087c98
34 files changed, 206 insertions, 182 deletions
diff --git a/chrome/browser/extensions/api/app_window/app_window_api.cc b/chrome/browser/extensions/api/app_window/app_window_api.cc index a75795d..5bf4ad8 100644 --- a/chrome/browser/extensions/api/app_window/app_window_api.cc +++ b/chrome/browser/extensions/api/app_window/app_window_api.cc @@ -6,9 +6,8 @@ #include "base/time.h" #include "base/values.h" -#include "chrome/browser/extensions/extension_window_controller.h" -#include "chrome/browser/extensions/extension_window_list.h" #include "chrome/browser/extensions/shell_window_registry.h" +#include "chrome/browser/extensions/window_controller.h" #include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/common/extensions/api/app_window.h" #include "chrome/common/extensions/extension_error_utils.h" diff --git a/chrome/browser/extensions/api/tabs/tabs.cc b/chrome/browser/extensions/api/tabs/tabs.cc index 75f3faf..34ed0ea 100644 --- a/chrome/browser/extensions/api/tabs/tabs.cc +++ b/chrome/browser/extensions/api/tabs/tabs.cc @@ -26,9 +26,9 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/tab_helper.h" #include "chrome/browser/extensions/extension_tab_util.h" -#include "chrome/browser/extensions/extension_window_controller.h" -#include "chrome/browser/extensions/extension_window_list.h" #include "chrome/browser/extensions/script_executor.h" +#include "chrome/browser/extensions/window_controller.h" +#include "chrome/browser/extensions/window_controller_list.h" #include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sessions/restore_tab_helper.h" @@ -97,6 +97,8 @@ using content::Referrer; using content::RenderViewHost; using content::WebContents; using extensions::ScriptExecutor; +using extensions::WindowController; +using extensions::WindowControllerList; const int CaptureVisibleTabFunction::kDefaultQuality = 90; @@ -149,16 +151,16 @@ bool GetBrowserFromWindowID( bool GetWindowFromWindowID(UIThreadExtensionFunction* function, int window_id, - ExtensionWindowController** controller) { + WindowController** controller) { if (window_id == extension_misc::kCurrentWindowId) { - ExtensionWindowController* extension_window_controller = + WindowController* extension_window_controller = function->dispatcher()->delegate()->GetExtensionWindowController(); // If there is a window controller associated with this extension, use that. if (extension_window_controller) { *controller = extension_window_controller; } else { // Otherwise get the focused or most recently added window. - *controller = ExtensionWindowList::GetInstance()-> + *controller = WindowControllerList::GetInstance()-> CurrentWindowForFunction(function); } if (!(*controller)) { @@ -166,8 +168,8 @@ bool GetWindowFromWindowID(UIThreadExtensionFunction* function, return false; } } else { - *controller = ExtensionWindowList::GetInstance()->FindWindowForFunctionById( - function, window_id); + *controller = WindowControllerList::GetInstance()-> + FindWindowForFunctionById(function, window_id); if (!(*controller)) { function->SetError(ExtensionErrorUtils::FormatErrorMessage( keys::kWindowNotFoundError, base::IntToString(window_id))); @@ -256,7 +258,7 @@ bool GetWindowFunction::RunImpl() { if (params->get_info.get() && params->get_info->populate.get()) populate_tabs = *params->get_info->populate; - ExtensionWindowController* controller; + WindowController* controller; if (!GetWindowFromWindowID(this, params->window_id, &controller)) return false; @@ -275,7 +277,7 @@ bool GetCurrentWindowFunction::RunImpl() { if (params->get_info.get() && params->get_info->populate.get()) populate_tabs = *params->get_info->populate; - ExtensionWindowController* controller; + WindowController* controller; if (!GetWindowFromWindowID(this, extension_misc::kCurrentWindowId, &controller)) { @@ -299,14 +301,14 @@ bool GetLastFocusedWindowFunction::RunImpl() { // Note: currently this returns the last active browser. If we decide to // include other window types (e.g. panels), we will need to add logic to - // ExtensionWindowList that mirrors the active behavior of BrowserList. + // WindowControllerList that mirrors the active behavior of BrowserList. Browser* browser = browser::FindAnyBrowser( profile(), include_incognito()); if (!browser || !browser->window()) { error_ = keys::kNoLastFocusedWindowError; return false; } - ExtensionWindowController* controller = + WindowController* controller = browser->extension_window_controller(); if (populate_tabs) SetResult(controller->CreateWindowValueWithTabs()); @@ -324,9 +326,9 @@ bool GetAllWindowsFunction::RunImpl() { populate_tabs = *params->get_info->populate; ListValue* window_list = new ListValue(); - const ExtensionWindowList::WindowList& windows = - ExtensionWindowList::GetInstance()->windows(); - for (ExtensionWindowList::WindowList::const_iterator iter = + const WindowControllerList::ControllerList& windows = + WindowControllerList::GetInstance()->windows(); + for (WindowControllerList::ControllerList::const_iterator iter = windows.begin(); iter != windows.end(); ++iter) { if (!this->CanOperateOnWindow(*iter)) @@ -650,7 +652,7 @@ bool UpdateWindowFunction::RunImpl() { DictionaryValue* update_props; EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); - ExtensionWindowController* controller; + WindowController* controller; if (!GetWindowFromWindowID(this, window_id, &controller)) return false; @@ -784,13 +786,13 @@ bool RemoveWindowFunction::RunImpl() { int window_id = -1; EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); - ExtensionWindowController* controller; + WindowController* controller; if (!GetWindowFromWindowID(this, window_id, &controller)) return false; - ExtensionWindowController::Reason reason; + WindowController::Reason reason; if (!controller->CanClose(&reason)) { - if (reason == ExtensionWindowController::REASON_NOT_EDITABLE) + if (reason == WindowController::REASON_NOT_EDITABLE) error_ = keys::kTabStripNotEditableError; return false; } diff --git a/chrome/browser/extensions/browser_extension_window_controller.cc b/chrome/browser/extensions/browser_extension_window_controller.cc index 66aca07..32f2900 100644 --- a/chrome/browser/extensions/browser_extension_window_controller.cc +++ b/chrome/browser/extensions/browser_extension_window_controller.cc @@ -15,7 +15,7 @@ BrowserExtensionWindowController::BrowserExtensionWindowController( Browser* browser) - : ExtensionWindowController(browser->window(), browser->profile()), + : extensions::WindowController(browser->window(), browser->profile()), browser_(browser) { } @@ -37,7 +37,7 @@ std::string BrowserExtensionWindowController::GetWindowTypeText() const { base::DictionaryValue* BrowserExtensionWindowController::CreateWindowValue() const { - DictionaryValue* result = ExtensionWindowController::CreateWindowValue(); + DictionaryValue* result = extensions::WindowController::CreateWindowValue(); return result; } @@ -54,7 +54,7 @@ bool BrowserExtensionWindowController::CanClose(Reason* reason) const { // Don't let an extension remove the window if the user is dragging tabs // in that window. if (!chrome::IsTabStripEditable(browser_)) { - *reason = ExtensionWindowController::REASON_NOT_EDITABLE; + *reason = extensions::WindowController::REASON_NOT_EDITABLE; return false; } return true; diff --git a/chrome/browser/extensions/browser_extension_window_controller.h b/chrome/browser/extensions/browser_extension_window_controller.h index 521f4e3..61b7c80 100644 --- a/chrome/browser/extensions/browser_extension_window_controller.h +++ b/chrome/browser/extensions/browser_extension_window_controller.h @@ -5,15 +5,15 @@ #ifndef CHROME_BROWSER_EXTENSIONS_BROWSER_EXTENSION_WINDOW_CONTROLLER_H_ #define CHROME_BROWSER_EXTENSIONS_BROWSER_EXTENSION_WINDOW_CONTROLLER_H_ -#include "chrome/browser/extensions/extension_window_controller.h" +#include "chrome/browser/extensions/window_controller.h" class Browser; -class BrowserExtensionWindowController : public ExtensionWindowController { +class BrowserExtensionWindowController : public extensions::WindowController { public: explicit BrowserExtensionWindowController(Browser* browser); - // ExtensionWindowController implementation. + // extensions::WindowController implementation. virtual int GetWindowId() const OVERRIDE; virtual std::string GetWindowTypeText() const OVERRIDE; virtual base::DictionaryValue* CreateWindowValue() const OVERRIDE; diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc index 45b5309..861fe0f 100644 --- a/chrome/browser/extensions/extension_browser_event_router.cc +++ b/chrome/browser/extensions/extension_browser_event_router.cc @@ -12,7 +12,7 @@ #include "chrome/browser/extensions/extension_event_router.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_tab_util.h" -#include "chrome/browser/extensions/extension_window_controller.h" +#include "chrome/browser/extensions/window_controller.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" diff --git a/chrome/browser/extensions/extension_function.cc b/chrome/browser/extensions/extension_function.cc index 00a6e18..92c4f86 100644 --- a/chrome/browser/extensions/extension_function.cc +++ b/chrome/browser/extensions/extension_function.cc @@ -8,8 +8,8 @@ #include "base/logging.h" #include "chrome/browser/extensions/extension_function_dispatcher.h" #include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/extensions/extension_window_controller.h" -#include "chrome/browser/extensions/extension_window_list.h" +#include "chrome/browser/extensions/window_controller.h" +#include "chrome/browser/extensions/window_controller_list.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/renderer_host/chrome_render_message_filter.h" #include "chrome/browser/ui/browser_finder.h" @@ -188,7 +188,7 @@ void UIThreadExtensionFunction::SetRenderViewHost( // TODO(stevenjb): Replace this with GetExtensionWindowController(). Browser* UIThreadExtensionFunction::GetCurrentBrowser() { // If the delegate has an associated browser, return it. - ExtensionWindowController* window_controller = + extensions::WindowController* window_controller = dispatcher()->delegate()->GetExtensionWindowController(); if (window_controller) { Browser* browser = window_controller->GetBrowser(); @@ -214,19 +214,20 @@ Browser* UIThreadExtensionFunction::GetCurrentBrowser() { return browser; } -ExtensionWindowController* +extensions::WindowController* UIThreadExtensionFunction::GetExtensionWindowController() { // If the delegate has an associated window controller, return it. - ExtensionWindowController* window_controller = + extensions::WindowController* window_controller = dispatcher()->delegate()->GetExtensionWindowController(); if (window_controller) return window_controller; - return ExtensionWindowList::GetInstance()->CurrentWindowForFunction(this); + return extensions::WindowControllerList::GetInstance()-> + CurrentWindowForFunction(this); } bool UIThreadExtensionFunction::CanOperateOnWindow( - const ExtensionWindowController* window_controller) const { + const extensions::WindowController* window_controller) const { const extensions::Extension* extension = GetExtension(); // |extension| is NULL for unit tests only. if (extension != NULL && !window_controller->IsVisibleToExtension(extension)) diff --git a/chrome/browser/extensions/extension_function.h b/chrome/browser/extensions/extension_function.h index 6b050cc..0698d3bcb 100644 --- a/chrome/browser/extensions/extension_function.h +++ b/chrome/browser/extensions/extension_function.h @@ -26,7 +26,6 @@ class Browser; class ChromeRenderMessageFilter; class ExtensionFunction; class ExtensionFunctionDispatcher; -class ExtensionWindowController; class UIThreadExtensionFunction; class IOThreadExtensionFunction; class Profile; @@ -41,6 +40,10 @@ namespace content { class RenderViewHost; } +namespace extensions { +class WindowController; +} + #define EXTENSION_FUNCTION_VALIDATE(test) do { \ if (!(test)) { \ bad_message_ = true; \ @@ -286,13 +289,13 @@ class UIThreadExtensionFunction : public ExtensionFunction { // TODO(stevenjb): Replace this with GetExtensionWindowController(). Browser* GetCurrentBrowser(); - // Same as above but uses ExtensionWindowList instead of BrowserList. - ExtensionWindowController* GetExtensionWindowController(); + // Same as above but uses WindowControllerList instead of BrowserList. + extensions::WindowController* GetExtensionWindowController(); // Returns true if this function (and the profile and extension that it was // invoked from) can operate on the window wrapped by |window_controller|. bool CanOperateOnWindow( - const ExtensionWindowController* window_controller) const; + const extensions::WindowController* window_controller) const; protected: friend struct content::BrowserThread::DeleteOnThread< diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index 1ad8e28..2e2935d 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -94,14 +94,14 @@ base::LazyInstance<Static> g_global_io_data = LAZY_INSTANCE_INITIALIZER; } // namespace -ExtensionWindowController* - ExtensionFunctionDispatcher::Delegate::GetExtensionWindowController() +extensions::WindowController* +ExtensionFunctionDispatcher::Delegate::GetExtensionWindowController() const { return NULL; } content::WebContents* - ExtensionFunctionDispatcher::Delegate::GetAssociatedWebContents() const { +ExtensionFunctionDispatcher::Delegate::GetAssociatedWebContents() const { return NULL; } diff --git a/chrome/browser/extensions/extension_function_dispatcher.h b/chrome/browser/extensions/extension_function_dispatcher.h index 734f6c5..bb71959 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.h +++ b/chrome/browser/extensions/extension_function_dispatcher.h @@ -15,7 +15,6 @@ class ChromeRenderMessageFilter; class ExtensionFunction; -class ExtensionWindowController; class ExtensionInfoMap; class Profile; struct ExtensionHostMsg_Request_Params; @@ -29,6 +28,7 @@ namespace extensions { class Extension; class ExtensionAPI; class ProcessMap; +class WindowController; } // A factory function for creating new ExtensionFunction instances. @@ -52,9 +52,9 @@ class ExtensionFunctionDispatcher public: class Delegate { public: - // Returns the ExtensionWindowController associated with this delegate, + // Returns the extensions::WindowController associated with this delegate, // or NULL if no window is associated with the delegate. - virtual ExtensionWindowController* GetExtensionWindowController() const; + virtual extensions::WindowController* GetExtensionWindowController() const; // Asks the delegate for any relevant WebContents associated with this // context. For example, the WebbContents in which an infobar or diff --git a/chrome/browser/extensions/extension_function_test_utils.cc b/chrome/browser/extensions/extension_function_test_utils.cc index 29097ec..6bb86b9 100644 --- a/chrome/browser/extensions/extension_function_test_utils.cc +++ b/chrome/browser/extensions/extension_function_test_utils.cc @@ -29,7 +29,7 @@ class TestFunctionDispatcherDelegate virtual ~TestFunctionDispatcherDelegate() {} private: - virtual ExtensionWindowController* GetExtensionWindowController() + virtual extensions::WindowController* GetExtensionWindowController() const OVERRIDE { return browser_->extension_window_controller(); } diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index 10a8f43..43cbd81 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -19,7 +19,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/extension_tab_util.h" -#include "chrome/browser/extensions/extension_window_controller.h" +#include "chrome/browser/extensions/window_controller.h" #include "chrome/browser/file_select_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" @@ -230,7 +230,8 @@ void ExtensionHost::CreateRenderViewNow() { } } -ExtensionWindowController* ExtensionHost::GetExtensionWindowController() const { +extensions::WindowController* +ExtensionHost::GetExtensionWindowController() const { return view() && view()->browser() ? view()->browser()->extension_window_controller() : NULL; } @@ -536,7 +537,7 @@ void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { // If the host is bound to a window, then extract its id. Extensions hosted // in ExternalTabContainer objects may not have an associated window. - ExtensionWindowController* window = GetExtensionWindowController(); + extensions::WindowController* window = GetExtensionWindowController(); if (window) { render_view_host->Send(new ExtensionMsg_UpdateBrowserWindowId( render_view_host->GetRoutingID(), window->GetWindowId())); diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index 1258184..d65174e 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -30,7 +30,6 @@ #endif class Browser; -class ExtensionWindowController; class PrefsTabHelper; namespace content { @@ -41,6 +40,7 @@ class SiteInstance; namespace extensions { class Extension; +class WindowController; } // This class is the browser component of an extension component's RenderView. @@ -183,7 +183,7 @@ class ExtensionHost : public content::WebContentsDelegate, void Close(); // ExtensionFunctionDispatcher::Delegate - virtual ExtensionWindowController* + virtual extensions::WindowController* GetExtensionWindowController() const OVERRIDE; // Message handlers. diff --git a/chrome/browser/extensions/extension_window_list.h b/chrome/browser/extensions/extension_window_list.h deleted file mode 100644 index 07fbbde..0000000 --- a/chrome/browser/extensions/extension_window_list.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WINDOW_LIST_H_ -#define CHROME_BROWSER_EXTENSIONS_EXTENSION_WINDOW_LIST_H_ - -#include <list> - -#include "base/compiler_specific.h" -#include "base/memory/singleton.h" -#include "chrome/browser/extensions/extension_window_controller.h" - -class Profile; -class UIThreadExtensionFunction; - -// Class to maintain a list of ExtensionWindowControllers. -class ExtensionWindowList { - public: - typedef std::list<ExtensionWindowController*> WindowList; - - ExtensionWindowList(); - ~ExtensionWindowList(); - - void AddExtensionWindow(ExtensionWindowController* window); - void RemoveExtensionWindow(ExtensionWindowController* window); - - // Returns a window matching the context the function was invoked in. - ExtensionWindowController* FindWindowForFunctionById( - const UIThreadExtensionFunction* function, - int id) const; - - // Returns the focused or last added window matching the context the function - // was invoked in. - ExtensionWindowController* CurrentWindowForFunction( - const UIThreadExtensionFunction* function) const; - - const WindowList& windows() const { return windows_; } - - static ExtensionWindowList* GetInstance(); - - private: - friend struct DefaultSingletonTraits<ExtensionWindowList>; - - // Entries are not owned by this class and must be removed when destroyed. - WindowList windows_; - - DISALLOW_COPY_AND_ASSIGN(ExtensionWindowList); -}; - -#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WINDOW_LIST_H_ diff --git a/chrome/browser/extensions/tab_helper.cc b/chrome/browser/extensions/tab_helper.cc index fc27c38..b331fa0 100644 --- a/chrome/browser/extensions/tab_helper.cc +++ b/chrome/browser/extensions/tab_helper.cc @@ -398,7 +398,7 @@ void TabHelper::OnImageLoaded(const gfx::Image& image, } } -ExtensionWindowController* TabHelper::GetExtensionWindowController() const { +WindowController* TabHelper::GetExtensionWindowController() const { content::WebContents* contents = web_contents(); TabContentsIterator tab_iterator; for (; !tab_iterator.done(); ++tab_iterator) { diff --git a/chrome/browser/extensions/tab_helper.h b/chrome/browser/extensions/tab_helper.h index 956d10e..582fa12 100644 --- a/chrome/browser/extensions/tab_helper.h +++ b/chrome/browser/extensions/tab_helper.h @@ -131,7 +131,7 @@ class TabHelper : public content::WebContentsObserver, virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; // ExtensionFunctionDispatcher::Delegate overrides. - virtual ExtensionWindowController* GetExtensionWindowController() + virtual extensions::WindowController* GetExtensionWindowController() const OVERRIDE; virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; diff --git a/chrome/browser/extensions/extension_window_controller.cc b/chrome/browser/extensions/window_controller.cc index 890e959..28e1e2e 100644 --- a/chrome/browser/extensions/extension_window_controller.cc +++ b/chrome/browser/extensions/window_controller.cc @@ -2,36 +2,36 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/extensions/extension_window_controller.h" +#include "chrome/browser/extensions/window_controller.h" #include "base/values.h" #include "chrome/browser/extensions/api/tabs/tabs_constants.h" -#include "chrome/browser/extensions/extension_window_list.h" +#include "chrome/browser/extensions/window_controller_list.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/base_window.h" #include "ui/gfx/rect.h" +namespace extensions { + /////////////////////////////////////////////////////////////////////////////// -// ExtensionWindowController +// WindowController -ExtensionWindowController::ExtensionWindowController(BaseWindow* window, - Profile* profile) : - window_(window), - profile_(profile) { - ExtensionWindowList::GetInstance()->AddExtensionWindow(this); +WindowController::WindowController(BaseWindow* window, Profile* profile) + : window_(window), profile_(profile) { + WindowControllerList::GetInstance()->AddExtensionWindow(this); } -ExtensionWindowController::~ExtensionWindowController() { - ExtensionWindowList::GetInstance()->RemoveExtensionWindow(this); +WindowController::~WindowController() { + WindowControllerList::GetInstance()->RemoveExtensionWindow(this); } -Browser* ExtensionWindowController::GetBrowser() const { +Browser* WindowController::GetBrowser() const { return NULL; } -namespace keys = extensions::tabs_constants; +namespace keys = tabs_constants; -base::DictionaryValue* ExtensionWindowController::CreateWindowValue() const { +base::DictionaryValue* WindowController::CreateWindowValue() const { DictionaryValue* result = new DictionaryValue(); result->SetInteger(keys::kIdKey, GetWindowId()); @@ -64,3 +64,5 @@ base::DictionaryValue* ExtensionWindowController::CreateWindowValue() const { return result; } + +} // namespace extensions diff --git a/chrome/browser/extensions/extension_window_controller.h b/chrome/browser/extensions/window_controller.h index 8406dbe..6e82bed 100644 --- a/chrome/browser/extensions/extension_window_controller.h +++ b/chrome/browser/extensions/window_controller.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WINDOW_CONTROLLER_H_ -#define CHROME_BROWSER_EXTENSIONS_EXTENSION_WINDOW_CONTROLLER_H_ +#ifndef CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_ +#define CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_ #include <string> @@ -20,25 +20,24 @@ namespace base { class DictionaryValue; } -namespace extensions { -class Extension; -} - namespace gfx { class Rect; } +namespace extensions { +class Extension; + // This API needs to be implemented by any window that might be accessed // through chrome.windows or chrome.tabs (e.g. browser windows and panels). -class ExtensionWindowController { +class WindowController { public: enum Reason { REASON_NONE, REASON_NOT_EDITABLE, }; - ExtensionWindowController(BaseWindow* window, Profile* profile); - virtual ~ExtensionWindowController(); + WindowController(BaseWindow* window, Profile* profile); + virtual ~WindowController(); BaseWindow* window() const { return window_; } @@ -73,14 +72,15 @@ class ExtensionWindowController { // Extension/window visibility and ownership is window-specific, subclasses // need to define this behavior. - virtual bool IsVisibleToExtension( - const extensions::Extension* extension) const = 0; + virtual bool IsVisibleToExtension(const Extension* extension) const = 0; private: BaseWindow* window_; Profile* profile_; - DISALLOW_COPY_AND_ASSIGN(ExtensionWindowController); + DISALLOW_COPY_AND_ASSIGN(WindowController); }; -#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WINDOW_CONTROLLER_H_ +} // namespace extensions + +#endif // CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_H_ diff --git a/chrome/browser/extensions/extension_window_list.cc b/chrome/browser/extensions/window_controller_list.cc index ba45223..0b221f7 100644 --- a/chrome/browser/extensions/extension_window_list.cc +++ b/chrome/browser/extensions/window_controller_list.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/extensions/extension_window_list.h" +#include "chrome/browser/extensions/window_controller_list.h" #include <algorithm> @@ -10,37 +10,37 @@ #include "chrome/browser/sessions/session_id.h" #include "chrome/browser/ui/base_window.h" +namespace extensions { + /////////////////////////////////////////////////////////////////////////////// -// ExtensionWindowList +// WindowControllerList // static -ExtensionWindowList* ExtensionWindowList::GetInstance() { - return Singleton<ExtensionWindowList>::get(); +WindowControllerList* WindowControllerList::GetInstance() { + return Singleton<WindowControllerList>::get(); } -ExtensionWindowList::ExtensionWindowList() { +WindowControllerList::WindowControllerList() { } -ExtensionWindowList::~ExtensionWindowList() { +WindowControllerList::~WindowControllerList() { } -void ExtensionWindowList::AddExtensionWindow( - ExtensionWindowController* window) { +void WindowControllerList::AddExtensionWindow(WindowController* window) { windows_.push_back(window); } -void ExtensionWindowList::RemoveExtensionWindow( - ExtensionWindowController* window) { - WindowList::iterator iter = std::find( +void WindowControllerList::RemoveExtensionWindow(WindowController* window) { + ControllerList::iterator iter = std::find( windows_.begin(), windows_.end(), window); if (iter != windows_.end()) windows_.erase(iter); } -ExtensionWindowController* ExtensionWindowList::FindWindowForFunctionById( +WindowController* WindowControllerList::FindWindowForFunctionById( const UIThreadExtensionFunction* function, int id) const { - for (WindowList::const_iterator iter = windows().begin(); + for (ControllerList::const_iterator iter = windows().begin(); iter != windows().end(); ++iter) { if (function->CanOperateOnWindow(*iter) && (*iter)->GetWindowId() == id) return *iter; @@ -48,11 +48,11 @@ ExtensionWindowController* ExtensionWindowList::FindWindowForFunctionById( return NULL; } -ExtensionWindowController* ExtensionWindowList::CurrentWindowForFunction( +WindowController* WindowControllerList::CurrentWindowForFunction( const UIThreadExtensionFunction* function) const { - ExtensionWindowController* result = NULL; + WindowController* result = NULL; // Returns either the focused window (if any), or the last window in the list. - for (WindowList::const_iterator iter = windows().begin(); + for (ControllerList::const_iterator iter = windows().begin(); iter != windows().end(); ++iter) { if (function->CanOperateOnWindow(*iter)) { result = *iter; @@ -62,3 +62,5 @@ ExtensionWindowController* ExtensionWindowList::CurrentWindowForFunction( } return result; } + +} // namespace extensions diff --git a/chrome/browser/extensions/window_controller_list.h b/chrome/browser/extensions/window_controller_list.h new file mode 100644 index 0000000..3c6915b --- /dev/null +++ b/chrome/browser/extensions/window_controller_list.h @@ -0,0 +1,55 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_LIST_H_ +#define CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_LIST_H_ + +#include <list> + +#include "base/compiler_specific.h" +#include "base/memory/singleton.h" +#include "chrome/browser/extensions/window_controller.h" + +class Profile; +class UIThreadExtensionFunction; + +namespace extensions { + +// Class to maintain a list of WindowControllers. +class WindowControllerList { + public: + typedef std::list<WindowController*> ControllerList; + + WindowControllerList(); + ~WindowControllerList(); + + void AddExtensionWindow(WindowController* window); + void RemoveExtensionWindow(WindowController* window); + + // Returns a window matching the context the function was invoked in. + WindowController* FindWindowForFunctionById( + const UIThreadExtensionFunction* function, + int id) const; + + // Returns the focused or last added window matching the context the function + // was invoked in. + WindowController* CurrentWindowForFunction( + const UIThreadExtensionFunction* function) const; + + const ControllerList& windows() const { return windows_; } + + static WindowControllerList* GetInstance(); + + private: + friend struct DefaultSingletonTraits<WindowControllerList>; + + // Entries are not owned by this class and must be removed when destroyed. + ControllerList windows_; + + DISALLOW_COPY_AND_ASSIGN(WindowControllerList); +}; + +} // namespace extensions + +#endif // CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_LIST_H_ diff --git a/chrome/browser/infobars/infobar_extension_api.cc b/chrome/browser/infobars/infobar_extension_api.cc index f3b256f..ee392a7 100644 --- a/chrome/browser/infobars/infobar_extension_api.cc +++ b/chrome/browser/infobars/infobar_extension_api.cc @@ -11,7 +11,7 @@ #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_infobar_delegate.h" #include "chrome/browser/extensions/extension_tab_util.h" -#include "chrome/browser/extensions/extension_window_controller.h" +#include "chrome/browser/extensions/window_controller.h" #include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/ui/browser.h" diff --git a/chrome/browser/notifications/balloon_host.cc b/chrome/browser/notifications/balloon_host.cc index 2596142..b3baa9b 100644 --- a/chrome/browser/notifications/balloon_host.cc +++ b/chrome/browser/notifications/balloon_host.cc @@ -49,7 +49,8 @@ void BalloonHost::Shutdown() { web_contents_.reset(); } -ExtensionWindowController* BalloonHost::GetExtensionWindowController() const { +extensions::WindowController* +BalloonHost::GetExtensionWindowController() const { // Notifications don't have a window controller. return NULL; } diff --git a/chrome/browser/notifications/balloon_host.h b/chrome/browser/notifications/balloon_host.h index 5ff8e1b..070c3ac 100644 --- a/chrome/browser/notifications/balloon_host.h +++ b/chrome/browser/notifications/balloon_host.h @@ -35,7 +35,7 @@ class BalloonHost : public content::WebContentsDelegate, void Shutdown(); // ExtensionFunctionDispatcher::Delegate overrides. - virtual ExtensionWindowController* GetExtensionWindowController() + virtual extensions::WindowController* GetExtensionWindowController() const OVERRIDE; virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index 5e8cea2..fc62aee 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -49,7 +49,6 @@ class BrowserSyncedWindowDelegate; class BrowserToolbarModelDelegate; class BrowserTabRestoreServiceDelegate; class BrowserWindow; -class ExtensionWindowController; class FindBarController; class FullscreenController; class PrefService; @@ -78,6 +77,7 @@ class SessionStorageNamespace; namespace extensions { class Extension; +class WindowController; } namespace gfx { @@ -479,7 +479,7 @@ class Browser : public TabStripModelObserver, return fullscreen_controller_.get(); } - ExtensionWindowController* extension_window_controller() const { + extensions::WindowController* extension_window_controller() const { return extension_window_controller_.get(); } @@ -916,7 +916,7 @@ class Browser : public TabStripModelObserver, scoped_refptr<FullscreenController> fullscreen_controller_; - scoped_ptr<ExtensionWindowController> extension_window_controller_; + scoped_ptr<extensions::WindowController> extension_window_controller_; scoped_ptr<chrome::BrowserCommandController> command_controller_; diff --git a/chrome/browser/ui/extensions/shell_window.cc b/chrome/browser/ui/extensions/shell_window.cc index f6650cf..45e04b6 100644 --- a/chrome/browser/ui/extensions/shell_window.cc +++ b/chrome/browser/ui/extensions/shell_window.cc @@ -343,7 +343,8 @@ void ShellWindow::Observe(int type, } } -ExtensionWindowController* ShellWindow::GetExtensionWindowController() const { +extensions::WindowController* +ShellWindow::GetExtensionWindowController() const { return NULL; } diff --git a/chrome/browser/ui/extensions/shell_window.h b/chrome/browser/ui/extensions/shell_window.h index ad1ed9f..4d74fc8c 100644 --- a/chrome/browser/ui/extensions/shell_window.h +++ b/chrome/browser/ui/extensions/shell_window.h @@ -16,7 +16,6 @@ #include "content/public/common/console_message_level.h" #include "ui/gfx/rect.h" -class ExtensionWindowController; class GURL; class Profile; class TabContents; @@ -27,6 +26,7 @@ class WebContents; namespace extensions { class Extension; +class WindowController; } // ShellWindow is the type of window used by platform apps. Shell windows @@ -134,7 +134,7 @@ class ShellWindow : public content::NotificationObserver, const content::NotificationDetails& details) OVERRIDE; // ExtensionFunctionDispatcher::Delegate implementation. - virtual ExtensionWindowController* GetExtensionWindowController() const + virtual extensions::WindowController* GetExtensionWindowController() const OVERRIDE; // Message handlers. diff --git a/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.cc b/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.cc index 5134e12..bd4b38b 100644 --- a/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.cc +++ b/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.cc @@ -107,8 +107,8 @@ content::WebContents* WebIntentInlineDispositionDelegate:: return NULL; } -ExtensionWindowController* WebIntentInlineDispositionDelegate:: - GetExtensionWindowController() const { +extensions::WindowController* +WebIntentInlineDispositionDelegate::GetExtensionWindowController() const { return NULL; } diff --git a/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h b/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h index 5ae7fda..3688ba9 100644 --- a/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h +++ b/chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h @@ -54,7 +54,7 @@ class WebIntentInlineDispositionDelegate content::RenderViewHost* render_view_host) OVERRIDE; // ExtensionFunctionDispatcher::Delegate - virtual ExtensionWindowController* GetExtensionWindowController() + virtual extensions::WindowController* GetExtensionWindowController() const OVERRIDE; virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; diff --git a/chrome/browser/ui/panels/panel.cc b/chrome/browser/ui/panels/panel.cc index 90f4ded..4782616 100644 --- a/chrome/browser/ui/panels/panel.cc +++ b/chrome/browser/ui/panels/panel.cc @@ -9,7 +9,7 @@ #include "base/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/extensions/api/tabs/tabs_constants.h" -#include "chrome/browser/extensions/extension_window_controller.h" +#include "chrome/browser/extensions/window_controller.h" #include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/panels/native_panel.h" @@ -33,11 +33,11 @@ using content::UserMetricsAction; namespace panel_internal { -class PanelExtensionWindowController : public ExtensionWindowController { +class PanelExtensionWindowController : public extensions::WindowController { public: PanelExtensionWindowController(Panel* panel, Profile* profile); - // Overridden from ExtensionWindowController. + // Overridden from extensions::WindowController. virtual int GetWindowId() const OVERRIDE; virtual std::string GetWindowTypeText() const OVERRIDE; virtual base::DictionaryValue* CreateWindowValueWithTabs() const OVERRIDE; @@ -54,7 +54,7 @@ class PanelExtensionWindowController : public ExtensionWindowController { PanelExtensionWindowController::PanelExtensionWindowController( Panel* panel, Profile* profile) - : ExtensionWindowController(panel, profile), + : extensions::WindowController(panel, profile), panel_(panel) { } diff --git a/chrome/browser/ui/panels/panel.h b/chrome/browser/ui/panels/panel.h index 4a3d15d..6d9fa26 100644 --- a/chrome/browser/ui/panels/panel.h +++ b/chrome/browser/ui/panels/panel.h @@ -20,7 +20,6 @@ class Browser; class BrowserWindow; -class ExtensionWindowController; class GURL; class NativePanel; class PanelHost; @@ -34,6 +33,10 @@ class WebContents; struct NativeWebKeyboardEvent; } +namespace extensions { +class WindowController; +} + // A platform independent implementation of BaseWindow for Panels. // This class gets the first crack at all the BaseWindow calls for Panels and // does one or more of the following: @@ -74,7 +77,7 @@ class Panel : public BaseWindow, const std::string& app_name() const { return app_name_; } const SessionID& session_id() const { return session_id_; } - ExtensionWindowController* extension_window_controller() const { + extensions::WindowController* extension_window_controller() const { return extension_window_controller_.get(); } const std::string extension_id() const; @@ -375,7 +378,7 @@ class Panel : public BaseWindow, content::NotificationRegistrar registrar_; const SessionID session_id_; - scoped_ptr<ExtensionWindowController> extension_window_controller_; + scoped_ptr<extensions::WindowController> extension_window_controller_; scoped_ptr<PanelHost> panel_host_; DISALLOW_COPY_AND_ASSIGN(Panel); diff --git a/chrome/browser/ui/panels/panel_host.cc b/chrome/browser/ui/panels/panel_host.cc index b8e09d9..55f1ab5 100644 --- a/chrome/browser/ui/panels/panel_host.cc +++ b/chrome/browser/ui/panels/panel_host.cc @@ -156,7 +156,7 @@ void PanelHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { web_contents_->GetRenderViewHost()); } -ExtensionWindowController* PanelHost::GetExtensionWindowController() const { +extensions::WindowController* PanelHost::GetExtensionWindowController() const { return panel_->extension_window_controller(); } diff --git a/chrome/browser/ui/panels/panel_host.h b/chrome/browser/ui/panels/panel_host.h index 4fab8968..e54017f 100644 --- a/chrome/browser/ui/panels/panel_host.h +++ b/chrome/browser/ui/panels/panel_host.h @@ -12,7 +12,6 @@ #include "content/public/browser/web_contents_observer.h" #include "content/public/common/page_zoom.h" -class ExtensionWindowController; class FaviconTabHelper; class GURL; class Panel; @@ -22,6 +21,10 @@ namespace content { class WebContents; } +namespace extensions { +class WindowController; +} + namespace gfx { class Rect; } @@ -69,7 +72,7 @@ class PanelHost : public content::WebContentsDelegate, virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; // ExtensionFunctionDispatcher::Delegate overrides. - virtual ExtensionWindowController* GetExtensionWindowController() const + virtual extensions::WindowController* GetExtensionWindowController() const OVERRIDE; virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; diff --git a/chrome/browser/ui/views/ash/panel_view_aura.cc b/chrome/browser/ui/views/ash/panel_view_aura.cc index 451f4b2..65915d1 100644 --- a/chrome/browser/ui/views/ash/panel_view_aura.cc +++ b/chrome/browser/ui/views/ash/panel_view_aura.cc @@ -11,8 +11,7 @@ #include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/extension_tab_util.h" -#include "chrome/browser/extensions/extension_window_controller.h" -#include "chrome/browser/extensions/extension_window_list.h" +#include "chrome/browser/extensions/window_controller.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sessions/session_id.h" #include "chrome/browser/ui/browser.h" @@ -58,7 +57,7 @@ class PanelHost : public content::WebContentsDelegate, Profile* profile() const { return profile_; } // ExtensionFunctionDispatcher::Delegate overrides. - virtual ExtensionWindowController* GetExtensionWindowController() + virtual extensions::WindowController* GetExtensionWindowController() const OVERRIDE; virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; @@ -116,7 +115,7 @@ void PanelHost::Init(const GURL& url) { url, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); } -ExtensionWindowController* PanelHost::GetExtensionWindowController() const { +extensions::WindowController* PanelHost::GetExtensionWindowController() const { return panel_view_->extension_window_controller(); } @@ -179,12 +178,12 @@ void PanelHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { //////////////////////////////////////////////////////////////////////////////// // PanelExtensionWindowController -class PanelExtensionWindowController : public ExtensionWindowController { +class PanelExtensionWindowController : public extensions::WindowController { public: PanelExtensionWindowController(PanelViewAura* panel_view, PanelHost* panel_host); - // Overriden from ExtensionWindowController: + // Overriden from extensions::WindowController: virtual int GetWindowId() const OVERRIDE; virtual std::string GetWindowTypeText() const OVERRIDE; virtual base::DictionaryValue* CreateWindowValue() const OVERRIDE; @@ -205,7 +204,7 @@ class PanelExtensionWindowController : public ExtensionWindowController { PanelExtensionWindowController::PanelExtensionWindowController( PanelViewAura* panel_view, PanelHost* panel_host) - : ExtensionWindowController(panel_view, panel_host->profile()), + : extensions::WindowController(panel_view, panel_host->profile()), panel_view_(panel_view), panel_host_(panel_host) { } @@ -220,7 +219,7 @@ std::string PanelExtensionWindowController::GetWindowTypeText() const { base::DictionaryValue* PanelExtensionWindowController::CreateWindowValue() const { - DictionaryValue* result = ExtensionWindowController::CreateWindowValue(); + DictionaryValue* result = extensions::WindowController::CreateWindowValue(); return result; } diff --git a/chrome/browser/ui/views/ash/panel_view_aura.h b/chrome/browser/ui/views/ash/panel_view_aura.h index c92bacf..dbe36d7 100644 --- a/chrome/browser/ui/views/ash/panel_view_aura.h +++ b/chrome/browser/ui/views/ash/panel_view_aura.h @@ -14,7 +14,6 @@ #include "ui/views/controls/native/native_view_host.h" #include "ui/views/widget/widget_delegate.h" -class ExtensionWindowController; class GURL; class Profile; @@ -22,6 +21,10 @@ namespace content { class WebContents; } +namespace extensions { +class WindowController; +} + namespace views { class Widget; } @@ -54,7 +57,7 @@ class PanelViewAura : public views::NativeViewHost, void SetContentPreferredSize(const gfx::Size& size); const SessionID& session_id() const { return session_id_; } - ExtensionWindowController* extension_window_controller() const { + extensions::WindowController* extension_window_controller() const { return extension_window_controller_.get(); } @@ -101,7 +104,7 @@ class PanelViewAura : public views::NativeViewHost, scoped_ptr<internal::PanelHost> host_; // Unowned pointer to the widget. views::Widget* widget_; - scoped_ptr<ExtensionWindowController> extension_window_controller_; + scoped_ptr<extensions::WindowController> extension_window_controller_; DISALLOW_COPY_AND_ASSIGN(PanelViewAura); }; diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi index 9e16c00..3315816 100644 --- a/chrome/chrome_browser_extensions.gypi +++ b/chrome/chrome_browser_extensions.gypi @@ -396,10 +396,6 @@ 'browser/extensions/extension_uninstall_dialog.h', 'browser/extensions/extension_warning_set.cc', 'browser/extensions/extension_warning_set.h', - 'browser/extensions/extension_window_controller.cc', - 'browser/extensions/extension_window_controller.h', - 'browser/extensions/extension_window_list.cc', - 'browser/extensions/extension_window_list.h', 'browser/extensions/extension_web_ui.cc', 'browser/extensions/extension_web_ui.h', 'browser/extensions/extension_webkit_preferences.cc', @@ -506,6 +502,10 @@ 'browser/extensions/webstore_install_helper.h', 'browser/extensions/webstore_installer.cc', 'browser/extensions/webstore_installer.h', + 'browser/extensions/window_controller.cc', + 'browser/extensions/window_controller.h', + 'browser/extensions/window_controller_list.cc', + 'browser/extensions/window_controller_list.h', ], 'conditions': [ ['chromeos==0', { |