// 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_TAB_UTIL_H__ #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_UTIL_H__ #pragma once #include class Browser; class GURL; class Profile; class TabContents; class TabStripModel; namespace base { class DictionaryValue; class ListValue; } namespace content { class WebContents; } namespace extensions { class Extension; } // Provides various utility functions that help manipulate tabs. class ExtensionTabUtil { public: static int GetWindowId(const Browser* browser); static int GetWindowIdOfTabStripModel(const TabStripModel* tab_strip_model); static int GetTabId(const content::WebContents* web_contents); static bool GetTabIdFromArgument(const base::ListValue &args, int argument_index, int *tab_id, std::string* error_message); static std::string GetTabStatusText(bool is_loading); static int GetWindowIdOfTab(const content::WebContents* web_contents); static base::ListValue* CreateTabList(const Browser* browser); static base::DictionaryValue* CreateTabValue( const content::WebContents* web_contents); static base::DictionaryValue* CreateTabValue( const content::WebContents* web_contents, TabStripModel* tab_strip, int tab_index); // Create a tab value, overriding its kSelectedKey to the provided boolean. static base::DictionaryValue* CreateTabValueActive( const content::WebContents* web_contents, bool active); // Gets the |tab_strip_model| and |tab_index| for the given |web_contents|. static bool GetTabStripModel(const content::WebContents* web_contents, TabStripModel** tab_strip_model, int* tab_index); static bool GetDefaultTab(Browser* browser, TabContents** contents, int* tab_id); // Any out parameter (|browser|, |tab_strip|, |contents|, & |tab_index|) may // be NULL and will not be set within the function. static bool GetTabById(int tab_id, Profile* profile, bool incognito_enabled, Browser** browser, TabStripModel** tab_strip, TabContents** contents, int* tab_index); // Takes |url_string| and returns a GURL which is either valid and absolute // or invalid. If |url_string| is not directly interpretable as a valid (it is // likely a relative URL) an attempt is made to resolve it. |extension| is // provided so it can be resolved relative to its extension base // (chrome-extension:///). Using the source frame url would be more // correct, but because the api shipped with urls resolved relative to their // extension base, we decided it wasn't worth breaking existing extensions to // fix. static GURL ResolvePossiblyRelativeURL(const std::string& url_string, const extensions::Extension* extension); // Returns true if |url| is used for testing crashes. static bool IsCrashURL(const GURL& url); }; #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_UTIL_H__