execute_code_in_tab_function.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2009 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_EXTENSIONS_EXECUTE_CODE_IN_TAB_FUNCTION_H__ 6#define CHROME_BROWSER_EXTENSIONS_EXECUTE_CODE_IN_TAB_FUNCTION_H__ 7 8#include <string> 9#include <vector> 10 11#include "base/file_path.h" 12#include "chrome/browser/extensions/extension_function.h" 13#include "chrome/common/extensions/extension_resource.h" 14#include "chrome/common/notification_service.h" 15#include "chrome/common/notification_registrar.h" 16 17class MessageLoop; 18 19// Implement API call tabs.executeScript and tabs.insertCSS. 20class ExecuteCodeInTabFunction : public AsyncExtensionFunction, 21 public NotificationObserver { 22 public: 23 ExecuteCodeInTabFunction() : execute_tab_id_(-1), 24 all_frames_(false) {} 25 26 private: 27 virtual bool RunImpl(); 28 29 virtual void Observe(NotificationType type, 30 const NotificationSource& source, 31 const NotificationDetails& details); 32 33 // Called when contents from the file whose path is specified in JSON 34 // arguments has been loaded. 35 void DidLoadFile(bool success, const std::string& data); 36 37 // Run in UI thread. Code string contains the code to be executed. Returns 38 // true on success. If true is returned, this does an AddRef. 39 bool Execute(const std::string& code_string); 40 41 NotificationRegistrar registrar_; 42 43 // Id of tab which executes code. 44 int execute_tab_id_; 45 46 // Contains extension resource built from path of file which is 47 // specified in JSON arguments. 48 ExtensionResource resource_; 49 50 // If all_frames_ is true, script or CSS text would be injected 51 // to all frames; Otherwise only injected to top main frame. 52 bool all_frames_; 53}; 54 55class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction { 56 DECLARE_EXTENSION_FUNCTION_NAME("tabs.executeScript") 57}; 58 59class TabsInsertCSSFunction : public ExecuteCodeInTabFunction { 60 DECLARE_EXTENSION_FUNCTION_NAME("tabs.insertCSS") 61}; 62 63#endif // CHROME_BROWSER_EXTENSIONS_EXECUTE_CODE_IN_TAB_FUNCTION_H__ 64