Logo Search packages:      
Sourcecode: chromium-browser version File versions  Download package

user_script_slave.h

// Copyright (c) 2009 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_RENDERER_USER_SCRIPT_SLAVE_H_
#define CHROME_RENDERER_USER_SCRIPT_SLAVE_H_

#include <map>
#include <set>
#include <string>
#include <vector>

#include "base/scoped_ptr.h"
#include "base/shared_memory.h"
#include "base/stl_util-inl.h"
#include "base/string_piece.h"
#include "chrome/common/extensions/user_script.h"
#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"

namespace WebKit {
class WebFrame;
}

using WebKit::WebScriptSource;

// Manages installed UserScripts for a render process.
class UserScriptSlave {
 public:
  UserScriptSlave();

  // Returns the unique set of extension IDs this UserScriptSlave knows about.
  void GetActiveExtensions(std::set<std::string>* extension_ids);

  // Update the parsed scripts from shared memory.
  bool UpdateScripts(base::SharedMemoryHandle shared_memory);

  // Inject the appropriate scripts into a frame based on its URL.
  // TODO(aa): Extract a UserScriptFrame interface out of this to improve
  // testability.
  bool InjectScripts(WebKit::WebFrame* frame, UserScript::RunLocation location);

  static int GetIsolatedWorldId(const std::string& extension_id);

  static void InsertInitExtensionCode(std::vector<WebScriptSource>* sources,
                                      const std::string& extension_id);
 private:
  // Shared memory containing raw script data.
  scoped_ptr<base::SharedMemory> shared_memory_;

  // Parsed script data.
  std::vector<UserScript*> scripts_;
  STLElementDeleter<std::vector<UserScript*> > script_deleter_;

  // Greasemonkey API source that is injected with the scripts.
  base::StringPiece api_js_;

  DISALLOW_COPY_AND_ASSIGN(UserScriptSlave);
};

#endif  // CHROME_RENDERER_USER_SCRIPT_SLAVE_H_

Generated by  Doxygen 1.6.0   Back to index