12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_ 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector> 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/compiler_specific.h" 121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/extensions/chrome_extension_function.h" 131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/browser/extensions/chrome_extension_function_details.h" 14116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "chrome/browser/ui/zoom/zoom_controller.h" 15b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "chrome/common/extensions/api/tabs.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/notification_observer.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/notification_registrar.h" 181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/browser/api/capture_web_contents_function.h" 191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "extensions/browser/api/execute_code_function.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "extensions/common/extension_resource.h" 21ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "extensions/common/user_script.h" 227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h" 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class GURL; 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class SkBitmap; 26b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class TabStripModel; 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace base { 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class DictionaryValue; 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace content { 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class WebContents; 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 36b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace ui { 37b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class ListSelectionModel; 38b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 40c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace user_prefs { 41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class PrefRegistrySyncable; 42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 44b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace extensions { 45b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 46116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Converts a ZoomMode to its ZoomSettings representation. 47116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid ZoomModeToZoomSettings(ZoomController::ZoomMode zoom_mode, 48116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch api::tabs::ZoomSettings* zoom_settings); 49116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Windows 511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsGetFunction : public ChromeSyncExtensionFunction { 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowsGetFunction() {} 535c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("windows.get", WINDOWS_GET) 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsGetCurrentFunction : public ChromeSyncExtensionFunction { 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowsGetCurrentFunction() {} 585c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("windows.getCurrent", WINDOWS_GETCURRENT) 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsGetLastFocusedFunction : public ChromeSyncExtensionFunction { 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowsGetLastFocusedFunction() {} 635c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("windows.getLastFocused", WINDOWS_GETLASTFOCUSED) 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsGetAllFunction : public ChromeSyncExtensionFunction { 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowsGetAllFunction() {} 685c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("windows.getAll", WINDOWS_GETALL) 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsCreateFunction : public ChromeSyncExtensionFunction { 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowsCreateFunction() {} 735c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns whether the window should be created in incognito mode. 75424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // |create_data| are the options passed by the extension. It may be NULL. 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |urls| is the list of urls to open. If we are creating an incognito window, 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the function will remove these urls which may not be opened in incognito 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // mode. If window creation leads the browser into an erroneous state, 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |is_error| is set to true (also, error_ member variable is assigned 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the proper error message). 81424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) bool ShouldOpenIncognitoWindow( 82424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const api::windows::Create::Params::CreateData* create_data, 83424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) std::vector<GURL>* urls, 84424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) bool* is_error); 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("windows.create", WINDOWS_CREATE) 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsUpdateFunction : public ChromeSyncExtensionFunction { 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowsUpdateFunction() {} 895c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("windows.update", WINDOWS_UPDATE) 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WindowsRemoveFunction : public ChromeSyncExtensionFunction { 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowsRemoveFunction() {} 945c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("windows.remove", WINDOWS_REMOVE) 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Tabs 991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsGetFunction : public ChromeSyncExtensionFunction { 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsGetFunction() {} 1015c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.get", TABS_GET) 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsGetCurrentFunction : public ChromeSyncExtensionFunction { 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsGetCurrentFunction() {} 1065c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.getCurrent", TABS_GETCURRENT) 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsGetSelectedFunction : public ChromeSyncExtensionFunction { 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsGetSelectedFunction() {} 1115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.getSelected", TABS_GETSELECTED) 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsGetAllInWindowFunction : public ChromeSyncExtensionFunction { 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsGetAllInWindowFunction() {} 1165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.getAllInWindow", TABS_GETALLINWINDOW) 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsQueryFunction : public ChromeSyncExtensionFunction { 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsQueryFunction() {} 1215c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.query", TABS_QUERY) 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsCreateFunction : public ChromeSyncExtensionFunction { 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsCreateFunction() {} 1265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.create", TABS_CREATE) 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsDuplicateFunction : public ChromeSyncExtensionFunction { 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsDuplicateFunction() {} 1315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.duplicate", TABS_DUPLICATE) 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsHighlightFunction : public ChromeSyncExtensionFunction { 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsHighlightFunction() {} 1365c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 137b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) bool HighlightTab(TabStripModel* tabstrip, 138b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) ui::ListSelectionModel* selection, 139b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int *active_index, 140b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int index); 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.highlight", TABS_HIGHLIGHT) 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsUpdateFunction : public ChromeAsyncExtensionFunction { 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TabsUpdateFunction(); 1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsUpdateFunction() {} 149b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) virtual bool UpdateURL(const std::string& url, 150b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int tab_id, 151b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) bool* is_async); 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void PopulateResult(); 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents_; 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 157010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual bool RunAsync() OVERRIDE; 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnExecuteCodeFinished(const std::string& error, 1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& on_url, 160eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const base::ListValue& script_result); 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.update", TABS_UPDATE) 1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsMoveFunction : public ChromeSyncExtensionFunction { 1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsMoveFunction() {} 1665c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 167b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) bool MoveTab(int tab_id, 168b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int* new_index, 169b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int iteration, 170eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::ListValue* tab_values, 171b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int* window_id); 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.move", TABS_MOVE) 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsReloadFunction : public ChromeSyncExtensionFunction { 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsReloadFunction() {} 1765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.reload", TABS_RELOAD) 1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsRemoveFunction : public ChromeSyncExtensionFunction { 1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsRemoveFunction() {} 1815c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu virtual bool RunSync() OVERRIDE; 182b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) bool RemoveTab(int tab_id); 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.remove", TABS_REMOVE) 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TabsDetectLanguageFunction : public ChromeAsyncExtensionFunction, 1861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public content::NotificationObserver { 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsDetectLanguageFunction() {} 189010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual bool RunAsync() OVERRIDE; 1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void Observe(int type, 1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const content::NotificationSource& source, 1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const content::NotificationDetails& details) OVERRIDE; 1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void GotLanguage(const std::string& language); 1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::NotificationRegistrar registrar_; 1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.detectLanguage", TABS_DETECTLANGUAGE) 1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 198a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class TabsCaptureVisibleTabFunction 199a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) : public extensions::CaptureWebContentsFunction { 2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 2011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci TabsCaptureVisibleTabFunction(); 2027dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsCaptureVisibleTabFunction() {} 2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 2081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ChromeExtensionFunctionDetails chrome_details_; 2091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 210a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // extensions::CaptureWebContentsFunction: 211a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual bool IsScreenshotEnabled() OVERRIDE; 212a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual content::WebContents* GetWebContentsForID(int id) OVERRIDE; 213a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual void OnCaptureFailure(FailureReason reason) OVERRIDE; 2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.captureVisibleTab", TABS_CAPTUREVISIBLETAB) 2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Implement API call tabs.executeScript and tabs.insertCSS. 219a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class ExecuteCodeInTabFunction : public ExecuteCodeFunction { 2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ExecuteCodeInTabFunction(); 2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~ExecuteCodeInTabFunction(); 2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ExtensionFunction: 2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool HasPermission() OVERRIDE; 2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Initialize the |execute_tab_id_| and |details_| if they haven't already 2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // been. Returns whether initialization was successful. 231a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual bool Init() OVERRIDE; 232a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual bool CanExecuteScriptOnPage() OVERRIDE; 233a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual ScriptExecutor* GetScriptExecutor() OVERRIDE; 234a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual bool IsWebView() const OVERRIDE; 235a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch virtual const GURL& GetWebViewSrc() const OVERRIDE; 2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 237a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) private: 2381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const ChromeExtensionFunctionDetails chrome_details_; 2391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Id of tab which executes code. 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int execute_tab_id_; 2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction { 245a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) protected: 246a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual bool ShouldInsertCSS() const OVERRIDE; 247a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsExecuteScriptFunction() {} 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 251eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual void OnExecuteCodeFinished( 252eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const std::string& error, 253eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const GURL& on_url, 254eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const base::ListValue& script_result) OVERRIDE; 2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.executeScript", TABS_EXECUTESCRIPT) 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TabsInsertCSSFunction : public ExecuteCodeInTabFunction { 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~TabsInsertCSSFunction() {} 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 263a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual bool ShouldInsertCSS() const OVERRIDE; 264a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("tabs.insertCSS", TABS_INSERTCSS) 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 268116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass ZoomAPIFunction : public ChromeAsyncExtensionFunction { 269116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch protected: 270116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual ~ZoomAPIFunction() {} 271116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 272116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Gets the WebContents for |tab_id| if it is specified. Otherwise get the 273116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // WebContents for the active tab in the current window. Calling this function 274116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // may set error_. 275116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // 276116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // TODO(...) many other tabs API functions use similar behavior. There should 277116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // be a way to share this implementation somehow. 278116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch content::WebContents* GetWebContents(int tab_id); 279116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}; 280116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 281116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass TabsSetZoomFunction : public ZoomAPIFunction { 282116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch private: 283116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual ~TabsSetZoomFunction() {} 284116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 285116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual bool RunAsync() OVERRIDE; 286116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 287116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch DECLARE_EXTENSION_FUNCTION("tabs.setZoom", TABS_SETZOOM) 288116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}; 289116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 290116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass TabsGetZoomFunction : public ZoomAPIFunction { 291116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch private: 292116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual ~TabsGetZoomFunction() {} 293116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 294116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual bool RunAsync() OVERRIDE; 295116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 296116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch DECLARE_EXTENSION_FUNCTION("tabs.getZoom", TABS_GETZOOM) 297116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}; 298116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 299116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass TabsSetZoomSettingsFunction : public ZoomAPIFunction { 300116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch private: 301116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual ~TabsSetZoomSettingsFunction() {} 302116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 303116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual bool RunAsync() OVERRIDE; 304116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 305116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch DECLARE_EXTENSION_FUNCTION("tabs.setZoomSettings", TABS_SETZOOMSETTINGS) 306116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}; 307116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 308116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass TabsGetZoomSettingsFunction : public ZoomAPIFunction { 309116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch private: 310116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual ~TabsGetZoomSettingsFunction() {} 311116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 312116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual bool RunAsync() OVERRIDE; 313116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 314116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch DECLARE_EXTENSION_FUNCTION("tabs.getZoomSettings", TABS_GETZOOMSETTINGS) 315116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}; 316116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 317b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} // namespace extensions 318b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 3192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_ 320