summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-23 09:10:13 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-23 09:10:13 +0000
commitdcddcdb0c4f20965aebedf3eade99df81f4414ec (patch)
tree9c867c6cc055329d3a492269b859e6bf3b941648 /chrome/common
parenta068b8fe6850b13c9d0418ebed0fede4518c0da0 (diff)
downloadchromium_src-dcddcdb0c4f20965aebedf3eade99df81f4414ec.zip
chromium_src-dcddcdb0c4f20965aebedf3eade99df81f4414ec.tar.gz
chromium_src-dcddcdb0c4f20965aebedf3eade99df81f4414ec.tar.bz2
Move more files from chrome/common to chrome/browser
to further reduce bad dependencies on chrome/browser. BUG=none TEST=none Review URL: http://codereview.chromium.org/652051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39703 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/accessibility_events.cc80
-rw-r--r--chrome/common/accessibility_events.h205
-rw-r--r--chrome/common/child_process_host.cc309
-rw-r--r--chrome/common/child_process_host.h154
-rw-r--r--chrome/common/chrome_plugin_unittest.cc302
5 files changed, 0 insertions, 1050 deletions
diff --git a/chrome/common/accessibility_events.cc b/chrome/common/accessibility_events.cc
deleted file mode 100644
index 17dc491..0000000
--- a/chrome/common/accessibility_events.cc
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright (c) 2010 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.
-
-#include "chrome/browser/extensions/extension_accessibility_api_constants.h"
-#include "chrome/browser/profile.h"
-#include "chrome/common/accessibility_events.h"
-#include "chrome/common/notification_service.h"
-#include "chrome/common/notification_type.h"
-
-namespace keys = extension_accessibility_api_constants;
-
-void SendAccessibilityNotification(
- NotificationType type, AccessibilityControlInfo* info) {
- Profile *profile = info->profile();
- if (profile->ShouldSendAccessibilityEvents()) {
- NotificationService::current()->Notify(
- type,
- Source<Profile>(profile),
- Details<AccessibilityControlInfo>(info));
- }
-}
-
-void AccessibilityControlInfo::SerializeToDict(DictionaryValue *dict) const {
- dict->SetString(keys::kNameKey, name_);
-}
-
-void AccessibilityWindowInfo::SerializeToDict(DictionaryValue *dict) const {
- AccessibilityControlInfo::SerializeToDict(dict);
- dict->SetString(keys::kTypeKey, keys::kTypeWindow);
-}
-
-void AccessibilityButtonInfo::SerializeToDict(DictionaryValue *dict) const {
- AccessibilityControlInfo::SerializeToDict(dict);
- dict->SetString(keys::kTypeKey, keys::kTypeButton);
-}
-
-void AccessibilityLinkInfo::SerializeToDict(DictionaryValue *dict) const {
- AccessibilityControlInfo::SerializeToDict(dict);
- dict->SetString(keys::kTypeKey, keys::kTypeLink);
-}
-
-void AccessibilityRadioButtonInfo::SerializeToDict(
- DictionaryValue *dict) const {
- AccessibilityControlInfo::SerializeToDict(dict);
- dict->SetString(keys::kTypeKey, keys::kTypeRadioButton);
- dict->SetBoolean(keys::kCheckedKey, checked_);
- dict->SetInteger(keys::kItemIndexKey, item_index_);
- dict->SetInteger(keys::kItemCountKey, item_count_);
-}
-
-void AccessibilityCheckboxInfo::SerializeToDict(DictionaryValue *dict) const {
- AccessibilityControlInfo::SerializeToDict(dict);
- dict->SetString(keys::kTypeKey, keys::kTypeCheckbox);
- dict->SetBoolean(keys::kCheckedKey, checked_);
-}
-
-void AccessibilityTabInfo::SerializeToDict(DictionaryValue *dict) const {
- AccessibilityControlInfo::SerializeToDict(dict);
- dict->SetString(keys::kTypeKey, keys::kTypeTab);
- dict->SetInteger(keys::kItemIndexKey, tab_index_);
- dict->SetInteger(keys::kItemCountKey, tab_count_);
-}
-
-void AccessibilityComboBoxInfo::SerializeToDict(DictionaryValue *dict) const {
- AccessibilityControlInfo::SerializeToDict(dict);
- dict->SetString(keys::kTypeKey, keys::kTypeComboBox);
- dict->SetString(keys::kValueKey, value_);
- dict->SetInteger(keys::kItemIndexKey, item_index_);
- dict->SetInteger(keys::kItemCountKey, item_count_);
-}
-
-void AccessibilityTextBoxInfo::SerializeToDict(DictionaryValue *dict) const {
- AccessibilityControlInfo::SerializeToDict(dict);
- dict->SetString(keys::kTypeKey, keys::kTypeTextBox);
- dict->SetString(keys::kValueKey, value_);
- dict->SetBoolean(keys::kPasswordKey, password_);
- dict->SetInteger(keys::kSelectionStartKey, selection_start_);
- dict->SetInteger(keys::kSelectionEndKey, selection_end_);
-}
diff --git a/chrome/common/accessibility_events.h b/chrome/common/accessibility_events.h
deleted file mode 100644
index bfcf2ae..0000000
--- a/chrome/common/accessibility_events.h
+++ /dev/null
@@ -1,205 +0,0 @@
-// Copyright (c) 2010 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_COMMON_ACCESSIBILITY_EVENTS_H_
-#define CHROME_COMMON_ACCESSIBILITY_EVENTS_H_
-
-#include <string>
-
-#include "base/values.h"
-
-class AccessibilityControlInfo;
-class NotificationType;
-class Profile;
-
-// Use the NotificationService to post the given accessibility
-// notification type with AccessibilityControlInfo details to any
-// listeners. Will not send if the profile's pause level is nonzero
-// (using profile->PauseAccessibilityEvents).
-void SendAccessibilityNotification(
- NotificationType type, AccessibilityControlInfo* info);
-
-// Abstract parent class for accessibility information about a control
-// passed to event listeners.
-class AccessibilityControlInfo {
- public:
- virtual ~AccessibilityControlInfo() { }
-
- // Serialize this class as a DictionaryValue that can be converted to
- // a JavaScript object.
- virtual void SerializeToDict(DictionaryValue *dict) const;
-
- Profile* profile() const { return profile_; }
-
- const std::string& name() const { return name_; }
-
- protected:
- // The constructor can only be called by subclasses.
- AccessibilityControlInfo(Profile* profile, std::string control_name)
- : profile_(profile), name_(control_name) { }
-
- // The profile this control belongs to.
- Profile* profile_;
-
- // The name of the control, like "OK" or "Password".
- std::string name_;
-};
-
-// Accessibility information about a window passed to onWindowOpened
-// and onWindowClosed event listeners.
-class AccessibilityWindowInfo : public AccessibilityControlInfo {
- public:
- AccessibilityWindowInfo(Profile* profile, std::string window_name)
- : AccessibilityControlInfo(profile, window_name) { }
-
- virtual void SerializeToDict(DictionaryValue *dict) const;
-};
-
-// Accessibility information about a push button passed to onControlFocused
-// and onControlAction event listeners.
-class AccessibilityButtonInfo : public AccessibilityControlInfo {
- public:
- AccessibilityButtonInfo(Profile* profile, std::string button_name)
- : AccessibilityControlInfo(profile, button_name) { }
-
- virtual void SerializeToDict(DictionaryValue *dict) const;
-};
-
-// Accessibility information about a hyperlink passed to onControlFocused
-// and onControlAction event listeners.
-class AccessibilityLinkInfo : public AccessibilityControlInfo {
- public:
- AccessibilityLinkInfo(Profile* profile, std::string link_name)
- : AccessibilityControlInfo(profile, link_name) { }
-
- virtual void SerializeToDict(DictionaryValue *dict) const;
-};
-
-// Accessibility information about a radio button passed to onControlFocused
-// and onControlAction event listeners.
-class AccessibilityRadioButtonInfo : public AccessibilityControlInfo {
- public:
- AccessibilityRadioButtonInfo(Profile* profile,
- std::string name,
- bool checked,
- int item_index,
- int item_count)
- : AccessibilityControlInfo(profile, name),
- checked_(checked),
- item_index_(item_index),
- item_count_(item_count) { }
-
- virtual void SerializeToDict(DictionaryValue *dict) const;
-
- void SetChecked(bool checked) { checked_ = checked; }
-
- private:
- bool checked_;
- // The 0-based index of this radio button and number of buttons in the group.
- int item_index_;
- int item_count_;
-};
-
-// Accessibility information about a checkbox passed to onControlFocused
-// and onControlAction event listeners.
-class AccessibilityCheckboxInfo : public AccessibilityControlInfo {
- public:
- AccessibilityCheckboxInfo(Profile* profile,
- std::string name,
- bool checked)
- : AccessibilityControlInfo(profile, name),
- checked_(checked) { }
-
- virtual void SerializeToDict(DictionaryValue *dict) const;
-
- void SetChecked(bool checked) { checked_ = checked; }
-
- private:
- bool checked_;
-};
-
-// Accessibility information about a tab passed to onControlFocused
-// and onControlAction event listeners.
-class AccessibilityTabInfo : public AccessibilityControlInfo {
- public:
- AccessibilityTabInfo(Profile* profile,
- std::string tab_name,
- int tab_index,
- int tab_count)
- : AccessibilityControlInfo(profile, tab_name),
- tab_index_(tab_index),
- tab_count_(tab_count) { }
-
- virtual void SerializeToDict(DictionaryValue *dict) const;
-
- void SetTab(int tab_index, std::string tab_name) {
- tab_index_ = tab_index;
- name_ = tab_name;
- }
-
- private:
- // The 0-based index of this tab and number of tabs in the group.
- int tab_index_;
- int tab_count_;
-};
-
-// Accessibility information about a combo box passed to onControlFocused
-// and onControlAction event listeners.
-class AccessibilityComboBoxInfo : public AccessibilityControlInfo {
- public:
- AccessibilityComboBoxInfo(Profile* profile,
- std::string name,
- std::string value,
- int item_index,
- int item_count)
- : AccessibilityControlInfo(profile, name),
- value_(value),
- item_index_(item_index),
- item_count_(item_count) { }
-
- virtual void SerializeToDict(DictionaryValue *dict) const;
-
- void SetValue(int item_index, std::string value) {
- item_index_ = item_index;
- value_ = value;
- }
-
- private:
- std::string value_;
- // The 0-based index of the current item and the number of total items.
- // If the value is not one of the drop-down options, item_index_ should
- // be -1.
- int item_index_;
- int item_count_;
-};
-
-// Accessibility information about a text box, passed to onControlFocused,
-// onControlAction, and onTextChanged event listeners.
-class AccessibilityTextBoxInfo : public AccessibilityControlInfo {
- public:
- AccessibilityTextBoxInfo(Profile* profile,
- std::string name,
- bool password)
- : AccessibilityControlInfo(profile, name),
- value_(""),
- password_(password),
- selection_start_(0),
- selection_end_(0) { }
-
- virtual void SerializeToDict(DictionaryValue *dict) const;
-
- void SetValue(std::string value, int selection_start, int selection_end) {
- value_ = value;
- selection_start_ = selection_start;
- selection_end_ = selection_end;
- }
-
- private:
- std::string value_;
- bool password_;
- int selection_start_;
- int selection_end_;
-};
-
-#endif // CHROME_COMMON_ACCESSIBILITY_EVENTS_H_
diff --git a/chrome/common/child_process_host.cc b/chrome/common/child_process_host.cc
deleted file mode 100644
index 51c6de4..0000000
--- a/chrome/common/child_process_host.cc
+++ /dev/null
@@ -1,309 +0,0 @@
-// 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.
-
-#include "chrome/common/child_process_host.h"
-
-#include "base/command_line.h"
-#include "base/compiler_specific.h"
-#include "base/file_path.h"
-#include "base/histogram.h"
-#include "base/logging.h"
-#include "base/path_service.h"
-#include "base/process_util.h"
-#include "base/singleton.h"
-#include "base/string_util.h"
-#include "base/waitable_event.h"
-#include "chrome/browser/chrome_thread.h"
-#include "chrome/common/chrome_constants.h"
-#include "chrome/common/chrome_paths_internal.h"
-#include "chrome/common/chrome_switches.h"
-#include "chrome/common/notification_service.h"
-#include "chrome/common/notification_type.h"
-#include "chrome/common/plugin_messages.h"
-#include "chrome/common/process_watcher.h"
-#include "chrome/common/result_codes.h"
-#include "chrome/installer/util/google_update_settings.h"
-
-#if defined(OS_LINUX)
-#include "base/linux_util.h"
-#endif // OS_LINUX
-
-#if defined(OS_POSIX)
-// This is defined in chrome/browser/google_update_settings_posix.cc. It's the
-// static string containing the user's unique GUID. We send this in the crash
-// report.
-namespace google_update {
-extern std::string posix_guid;
-} // namespace google_update
-#endif // OS_POSIX
-
-
-namespace {
-
-typedef std::list<ChildProcessHost*> ChildProcessList;
-
-// The NotificationTask is used to notify about plugin process connection/
-// disconnection. It is needed because the notifications in the
-// NotificationService must happen in the main thread.
-class ChildNotificationTask : public Task {
- public:
- ChildNotificationTask(
- NotificationType notification_type, ChildProcessInfo* info)
- : notification_type_(notification_type), info_(*info) { }
-
- virtual void Run() {
- NotificationService::current()->
- Notify(notification_type_, NotificationService::AllSources(),
- Details<ChildProcessInfo>(&info_));
- }
-
- private:
- NotificationType notification_type_;
- ChildProcessInfo info_;
-};
-
-} // namespace
-
-
-ChildProcessHost::ChildProcessHost(
- ProcessType type, ResourceDispatcherHost* resource_dispatcher_host)
- : Receiver(type, -1),
- ALLOW_THIS_IN_INITIALIZER_LIST(listener_(this)),
- resource_dispatcher_host_(resource_dispatcher_host),
- opening_channel_(false) {
- Singleton<ChildProcessList>::get()->push_back(this);
-}
-
-
-ChildProcessHost::~ChildProcessHost() {
- Singleton<ChildProcessList>::get()->remove(this);
-
- resource_dispatcher_host_->CancelRequestsForProcess(id());
-}
-
-// static
-FilePath ChildProcessHost::GetChildPath(bool allow_self) {
- FilePath child_path;
-
- child_path = CommandLine::ForCurrentProcess()->GetSwitchValuePath(
- switches::kBrowserSubprocessPath);
- if (!child_path.empty())
- return child_path;
-
-#if defined(OS_MACOSX)
- // On the Mac, the child executable lives at a predefined location within
- // the app bundle's versioned directory.
- return chrome::GetVersionedDirectory().
- Append(chrome::kHelperProcessExecutablePath);
-#endif
-
-#if defined(OS_LINUX)
- // Use /proc/self/exe rather than our known binary path so updates
- // can't swap out the binary from underneath us.
- if (allow_self)
- return FilePath("/proc/self/exe");
-#endif
-
- // On most platforms, the child executable is the same as the current
- // executable.
- PathService::Get(base::FILE_EXE, &child_path);
- return child_path;
-}
-
-// static
-void ChildProcessHost::SetCrashReporterCommandLine(CommandLine* command_line) {
-#if defined(USE_LINUX_BREAKPAD)
- const bool unattended = (getenv("CHROME_HEADLESS") != NULL);
- if (unattended || GoogleUpdateSettings::GetCollectStatsConsent()) {
- command_line->AppendSwitchWithValue(switches::kEnableCrashReporter,
- ASCIIToWide(google_update::posix_guid +
- "," +
- base::GetLinuxDistro()));
- }
-#elif defined(OS_MACOSX)
- if (GoogleUpdateSettings::GetCollectStatsConsent())
- command_line->AppendSwitchWithValue(switches::kEnableCrashReporter,
- ASCIIToWide(google_update::posix_guid));
-#endif // OS_MACOSX
-}
-
-void ChildProcessHost::Launch(
-#if defined(OS_WIN)
- const FilePath& exposed_dir,
-#elif defined(OS_POSIX)
- bool use_zygote,
- const base::environment_vector& environ,
-#endif
- CommandLine* cmd_line) {
- child_process_.reset(new ChildProcessLauncher(
-#if defined(OS_WIN)
- exposed_dir,
-#elif defined(OS_POSIX)
- use_zygote,
- environ,
- channel_->GetClientFileDescriptor(),
-#endif
- cmd_line,
- &listener_));
-}
-
-bool ChildProcessHost::CreateChannel() {
- channel_id_ = GenerateRandomChannelID(this);
- channel_.reset(new IPC::Channel(
- channel_id_, IPC::Channel::MODE_SERVER, &listener_));
- if (!channel_->Connect())
- return false;
-
- opening_channel_ = true;
-
- return true;
-}
-
-void ChildProcessHost::InstanceCreated() {
- Notify(NotificationType::CHILD_INSTANCE_CREATED);
-}
-
-bool ChildProcessHost::Send(IPC::Message* msg) {
- if (!channel_.get()) {
- delete msg;
- return false;
- }
- return channel_->Send(msg);
-}
-
-void ChildProcessHost::Notify(NotificationType type) {
- ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE, new ChildNotificationTask(type, this));
-}
-
-bool ChildProcessHost::DidChildCrash() {
- return child_process_->DidProcessCrash();
-}
-
-void ChildProcessHost::OnChildDied() {
- if (handle() != base::kNullProcessHandle) {
- bool did_crash = DidChildCrash();
- if (did_crash) {
- OnProcessCrashed();
- // Report that this child process crashed.
- Notify(NotificationType::CHILD_PROCESS_CRASHED);
- UMA_HISTOGRAM_COUNTS("ChildProcess.Crashes", this->type());
- }
- // Notify in the main loop of the disconnection.
- Notify(NotificationType::CHILD_PROCESS_HOST_DISCONNECTED);
- }
-
- delete this;
-}
-
-ChildProcessHost::ListenerHook::ListenerHook(ChildProcessHost* host)
- : host_(host) {
-}
-
-void ChildProcessHost::ListenerHook::OnMessageReceived(
- const IPC::Message& msg) {
-#ifdef IPC_MESSAGE_LOG_ENABLED
- IPC::Logging* logger = IPC::Logging::current();
- if (msg.type() == IPC_LOGGING_ID) {
- logger->OnReceivedLoggingMessage(msg);
- return;
- }
-
- if (logger->Enabled())
- logger->OnPreDispatchMessage(msg);
-#endif
-
- bool msg_is_ok = true;
- bool handled = host_->resource_dispatcher_host_->OnMessageReceived(
- msg, host_, &msg_is_ok);
-
- if (!handled) {
- if (msg.type() == PluginProcessHostMsg_ShutdownRequest::ID) {
- // Must remove the process from the list now, in case it gets used for a
- // new instance before our watcher tells us that the process terminated.
- Singleton<ChildProcessList>::get()->remove(host_);
- if (host_->CanShutdown())
- host_->Send(new PluginProcessMsg_Shutdown());
- } else {
- host_->OnMessageReceived(msg);
- }
- }
-
- if (!msg_is_ok)
- base::KillProcess(host_->handle(), ResultCodes::KILLED_BAD_MESSAGE, false);
-
-#ifdef IPC_MESSAGE_LOG_ENABLED
- if (logger->Enabled())
- logger->OnPostDispatchMessage(msg, host_->channel_id_);
-#endif
-}
-
-void ChildProcessHost::ListenerHook::OnChannelConnected(int32 peer_pid) {
- host_->opening_channel_ = false;
- host_->OnChannelConnected(peer_pid);
-
-#if defined(IPC_MESSAGE_LOG_ENABLED)
- bool enabled = IPC::Logging::current()->Enabled();
- host_->Send(new PluginProcessMsg_SetIPCLoggingEnabled(enabled));
-#endif
-
- host_->Send(new PluginProcessMsg_AskBeforeShutdown());
-
- // Notify in the main loop of the connection.
- host_->Notify(NotificationType::CHILD_PROCESS_HOST_CONNECTED);
-}
-
-void ChildProcessHost::ListenerHook::OnChannelError() {
- host_->opening_channel_ = false;
- host_->OnChannelError();
-
- // This will delete host_, which will also destroy this!
- host_->OnChildDied();
-}
-
-void ChildProcessHost::ListenerHook::OnProcessLaunched() {
- if (!host_->child_process_->GetHandle()) {
- delete this;
- return;
- }
-
- host_->set_handle(host_->child_process_->GetHandle());
- host_->OnProcessLaunched();
-}
-
-
-ChildProcessHost::Iterator::Iterator()
- : all_(true), type_(UNKNOWN_PROCESS) {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)) <<
- "ChildProcessInfo::Iterator must be used on the IO thread.";
- iterator_ = Singleton<ChildProcessList>::get()->begin();
-}
-
-ChildProcessHost::Iterator::Iterator(ProcessType type)
- : all_(false), type_(type) {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)) <<
- "ChildProcessInfo::Iterator must be used on the IO thread.";
- iterator_ = Singleton<ChildProcessList>::get()->begin();
- if (!Done() && (*iterator_)->type() != type_)
- ++(*this);
-}
-
-ChildProcessHost* ChildProcessHost::Iterator::operator++() {
- do {
- ++iterator_;
- if (Done())
- break;
-
- if (!all_ && (*iterator_)->type() != type_)
- continue;
-
- return *iterator_;
- } while (true);
-
- return NULL;
-}
-
-bool ChildProcessHost::Iterator::Done() {
- return iterator_ == Singleton<ChildProcessList>::get()->end();
-}
diff --git a/chrome/common/child_process_host.h b/chrome/common/child_process_host.h
deleted file mode 100644
index 22d5cc3..0000000
--- a/chrome/common/child_process_host.h
+++ /dev/null
@@ -1,154 +0,0 @@
-// 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_COMMON_CHILD_PROCESS_HOST_H_
-#define CHROME_COMMON_CHILD_PROCESS_HOST_H_
-
-#include <list>
-#include <string>
-
-// Must be included early (e.g. before chrome/common/plugin_messages.h)
-#include "ipc/ipc_logging.h"
-
-#include "base/basictypes.h"
-#include "base/scoped_ptr.h"
-#include "chrome/browser/child_process_launcher.h"
-#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
-#include "ipc/ipc_channel.h"
-
-class CommandLine;
-class NotificationType;
-
-// Plugins/workers and other child processes that live on the IO thread should
-// derive from this class.
-//
-// [Browser]RenderProcessHost is the main exception that doesn't derive from
-// this class. That project lives on the UI thread.
-class ChildProcessHost : public ResourceDispatcherHost::Receiver,
- public IPC::Channel::Listener,
- public ChildProcessLauncher::Client {
- public:
- virtual ~ChildProcessHost();
-
- // Returns the pathname to be used for a child process. If a subprocess
- // pathname was specified on the command line, that will be used. Otherwise,
- // the default child process pathname will be returned. On most platforms,
- // this will be the same as the currently-executing process.
- //
- // The argument allow_self is used on Linux to indicate that we allow us to
- // fork from /proc/self/exe rather than using the "real" app path. This
- // prevents autoupdate from confusing us if it changes the file out from
- // under us. You will generally want to set this to true, except when there
- // is an override to the command line (for example, we're forking a renderer
- // in gdb). In this case, you'd use GetChildPath to get the real executable
- // file name, and then prepend the GDB command to the command line.
- //
- // On failure, returns an empty FilePath.
- static FilePath GetChildPath(bool allow_self);
-
- // Prepares command_line for crash reporting as appropriate. On Linux and
- // Mac, a command-line flag to enable crash reporting in the child process
- // will be appended if needed, because the child process may not have access
- // to the data that determines the status of crash reporting in the
- // currently-executing process. This function is a no-op on Windows.
- static void SetCrashReporterCommandLine(CommandLine* command_line);
-
- // ResourceDispatcherHost::Receiver implementation:
- virtual bool Send(IPC::Message* msg);
-
- // The Iterator class allows iteration through either all child processes, or
- // ones of a specific type, depending on which constructor is used. Note that
- // this should be done from the IO thread and that the iterator should not be
- // kept around as it may be invalidated on subsequent event processing in the
- // event loop.
- class Iterator {
- public:
- Iterator();
- explicit Iterator(ProcessType type);
- ChildProcessHost* operator->() { return *iterator_; }
- ChildProcessHost* operator*() { return *iterator_; }
- ChildProcessHost* operator++();
- bool Done();
-
- private:
- bool all_;
- ProcessType type_;
- std::list<ChildProcessHost*>::iterator iterator_;
- };
-
- protected:
- // The resource_dispatcher_host may be NULL to indicate none is needed for
- // this process type.
- ChildProcessHost(ProcessType type,
- ResourceDispatcherHost* resource_dispatcher_host);
-
- // Derived classes call this to launch the child process asynchronously.
- void Launch(
-#if defined(OS_WIN)
- const FilePath& exposed_dir,
-#elif defined(OS_POSIX)
- bool use_zygote,
- const base::environment_vector& environ,
-#endif
- CommandLine* cmd_line);
-
- // Derived classes return true if it's ok to shut down the child process.
- virtual bool CanShutdown() = 0;
-
- // Creates the IPC channel. Returns true iff it succeeded.
- bool CreateChannel();
-
- // Notifies us that an instance has been created on this child process.
- void InstanceCreated();
-
- // IPC::Channel::Listener implementation:
- virtual void OnMessageReceived(const IPC::Message& msg) { }
- virtual void OnChannelConnected(int32 peer_pid) { }
- virtual void OnChannelError() { }
-
- // ChildProcessLauncher::Client implementation.
- virtual void OnProcessLaunched() {}
-
- // Derived classes can override this to know if the process crashed.
- virtual void OnProcessCrashed() {}
-
- bool opening_channel() { return opening_channel_; }
- const std::string& channel_id() { return channel_id_; }
-
- virtual bool DidChildCrash();
-
- private:
- // Sends the given notification to the notification service on the UI thread.
- void Notify(NotificationType type);
-
- // Called when the child process goes away.
- void OnChildDied();
-
- // By using an internal class as the IPC::Channel::Listener, we can intercept
- // OnMessageReceived/OnChannelConnected and do our own processing before
- // calling the subclass' implementation.
- class ListenerHook : public IPC::Channel::Listener,
- public ChildProcessLauncher::Client {
- public:
- explicit ListenerHook(ChildProcessHost* host);
- virtual void OnMessageReceived(const IPC::Message& msg);
- virtual void OnChannelConnected(int32 peer_pid);
- virtual void OnChannelError();
- virtual void OnProcessLaunched();
- private:
- ChildProcessHost* host_;
- };
-
- ListenerHook listener_;
-
- // May be NULL if this current process has no resource dispatcher host.
- ResourceDispatcherHost* resource_dispatcher_host_;
-
- bool opening_channel_; // True while we're waiting the channel to be opened.
- scoped_ptr<IPC::Channel> channel_;
- std::string channel_id_;
- scoped_ptr<ChildProcessLauncher> child_process_;
-};
-
-#endif // CHROME_COMMON_CHILD_PROCESS_HOST_H_
diff --git a/chrome/common/chrome_plugin_unittest.cc b/chrome/common/chrome_plugin_unittest.cc
deleted file mode 100644
index 43e3c53..0000000
--- a/chrome/common/chrome_plugin_unittest.cc
+++ /dev/null
@@ -1,302 +0,0 @@
-// Copyright (c) 2006-2008 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.
-// Tests exercising the Chrome Plugin API.
-
-#include "base/file_util.h"
-#include "base/path_service.h"
-#include "base/string_util.h"
-#include "chrome/browser/chrome_plugin_host.h"
-#include "chrome/browser/chrome_thread.h"
-#include "chrome/browser/net/url_request_context_getter.h"
-#include "chrome/browser/profile.h"
-#include "chrome/common/chrome_plugin_lib.h"
-#include "chrome/test/chrome_plugin/test_chrome_plugin.h"
-#include "net/base/io_buffer.h"
-#include "net/http/http_response_headers.h"
-#include "net/url_request/url_request_test_job.h"
-#include "net/url_request/url_request_unittest.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace {
-
-const wchar_t kDocRoot[] = L"chrome/test/data";
-const char kPluginFilename[] = "test_chrome_plugin.dll";
-const int kResponseBufferSize = 4096;
-
-class TestURLRequestContextGetter : public URLRequestContextGetter {
- public:
- virtual URLRequestContext* GetURLRequestContext() {
- if (!context_)
- context_ = new TestURLRequestContext();
- return context_;
- }
- private:
- ~TestURLRequestContextGetter() {}
- scoped_refptr<URLRequestContext> context_;
-};
-
-class ChromePluginTest : public testing::Test, public URLRequest::Delegate {
- public:
- ChromePluginTest()
- : io_thread_(ChromeThread::IO, &message_loop_),
- request_(NULL),
- response_buffer_(new net::IOBuffer(kResponseBufferSize)),
- plugin_(NULL),
- expected_payload_(NULL),
- request_context_getter_(new TestURLRequestContextGetter()) {
- test_funcs_.test_make_request = NULL;
- }
-
- // Loads/unloads the chrome test plugin.
- void LoadPlugin();
- void UnloadPlugin();
-
- // Runs the test and expects the given payload as a response. If expectation
- // is NULL, the request is expected to fail.
- void RunTest(const GURL& url, const TestResponsePayload* expected_payload);
-
- // URLRequest::Delegate implementations
- virtual void OnResponseStarted(URLRequest* request);
- virtual void OnReadCompleted(URLRequest* request, int bytes_read);
-
- // Helper called when the URLRequest is done.
- void OnURLRequestComplete();
-
- // testing::Test
- virtual void SetUp() {
- LoadPlugin();
- URLRequest::RegisterProtocolFactory("test", &URLRequestTestJob::Factory);
-
- // We need to setup a default request context in order to issue HTTP
- // requests.
- DCHECK(!Profile::GetDefaultRequestContext());
- Profile::set_default_request_context(request_context_getter_.get());
- }
- virtual void TearDown() {
- UnloadPlugin();
- URLRequest::RegisterProtocolFactory("test", NULL);
-
- Profile::set_default_request_context(NULL);
-
- // Clear the request before flushing the message loop since killing the
- // request can result in the generation of more tasks.
- request_.reset();
-
- // Flush the message loop to make Purify happy.
- message_loop_.RunAllPending();
- }
- protected:
- MessageLoopForIO message_loop_;
- ChromeThread io_thread_;
-
- // Note: we use URLRequest (instead of URLFetcher) because this allows the
- // request to be intercepted.
- scoped_ptr<URLRequest> request_;
- scoped_refptr<net::IOBuffer> response_buffer_;
- std::string response_data_;
-
- ChromePluginLib* plugin_;
- TestFuncParams::PluginFuncs test_funcs_;
- const TestResponsePayload* expected_payload_;
- scoped_refptr<URLRequestContextGetter> request_context_getter_;
-};
-
-static void STDCALL CPT_Complete(CPRequest* request, bool success,
- const std::string& raw_headers,
- const std::string& body) {
- GURL url(request->url);
- if (url == GURL(kChromeTestPluginPayloads[0].url)) {
- // This URL should fail, because the plugin should not have intercepted it.
- EXPECT_FALSE(success);
- MessageLoop::current()->Quit();
- return;
- }
-
- scoped_refptr<net::HttpResponseHeaders> headers(
- new net::HttpResponseHeaders(raw_headers));
- EXPECT_TRUE(success);
- EXPECT_EQ(200, headers->response_code());
-
- if (url == URLRequestTestJob::test_url_1()) {
- EXPECT_EQ(URLRequestTestJob::test_data_1(), body);
- } else if (url == URLRequestTestJob::test_url_2()) {
- EXPECT_EQ(URLRequestTestJob::test_data_2(), body);
- } else if (url.spec().find("echo") != std::string::npos) {
- EXPECT_EQ(kChromeTestPluginPostData, body);
- }
-
- MessageLoop::current()->Quit();
-}
-
-static void STDCALL CPT_InvokeLater(TestFuncParams::CallbackFunc callback,
- void* callback_data, int delay_ms) {
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- NewRunnableFunction(callback, callback_data), delay_ms);
-}
-
-void ChromePluginTest::LoadPlugin() {
- FilePath path;
- PathService::Get(base::DIR_EXE, &path);
- path = path.AppendASCII(kPluginFilename);
- plugin_ = ChromePluginLib::Create(path, GetCPBrowserFuncsForBrowser());
-
- // Exchange test APIs with the plugin.
- TestFuncParams params;
- params.bfuncs.test_complete = CPT_Complete;
- params.bfuncs.invoke_later = CPT_InvokeLater;
- EXPECT_EQ(CPERR_SUCCESS, plugin_->CP_Test(&params));
- test_funcs_ = params.pfuncs;
-
- EXPECT_TRUE(plugin_);
-}
-
-void ChromePluginTest::UnloadPlugin() {
- ChromePluginLib::UnloadAllPlugins();
- plugin_ = NULL;
-}
-
-void ChromePluginTest::RunTest(const GURL& url,
- const TestResponsePayload* expected_payload) {
- expected_payload_ = expected_payload;
-
- response_data_.clear();
- request_.reset(new URLRequest(url, this));
- request_->set_context(new TestURLRequestContext());
- request_->Start();
-
- MessageLoop::current()->Run();
-}
-
-void ChromePluginTest::OnResponseStarted(URLRequest* request) {
- DCHECK(request == request_);
-
- int bytes_read = 0;
- if (request_->status().is_success())
- request_->Read(response_buffer_, kResponseBufferSize, &bytes_read);
- OnReadCompleted(request_.get(), bytes_read);
-}
-
-void ChromePluginTest::OnReadCompleted(URLRequest* request, int bytes_read) {
- DCHECK(request == request_);
-
- do {
- if (!request_->status().is_success() || bytes_read <= 0)
- break;
- response_data_.append(response_buffer_->data(), bytes_read);
- } while (request_->Read(response_buffer_, kResponseBufferSize, &bytes_read));
-
- if (!request_->status().is_io_pending()) {
- OnURLRequestComplete();
- }
-}
-
-void ChromePluginTest::OnURLRequestComplete() {
- if (expected_payload_) {
- EXPECT_TRUE(request_->status().is_success());
-
- EXPECT_EQ(expected_payload_->status, request_->GetResponseCode());
- if (expected_payload_->mime_type) {
- std::string mime_type;
- EXPECT_TRUE(request_->response_headers()->GetMimeType(&mime_type));
- EXPECT_EQ(expected_payload_->mime_type, mime_type);
- }
- if (expected_payload_->body) {
- EXPECT_EQ(expected_payload_->body, response_data_);
- }
- } else {
- EXPECT_FALSE(request_->status().is_success());
- }
-
- MessageLoop::current()->Quit();
- // If MessageLoop::current() != main_loop_, it will be shut down when the
- // main loop returns and this thread subsequently goes out of scope.
-}
-
-}; // namespace
-
-// Tests that the plugin can intercept URLs.
-TEST_F(ChromePluginTest, DoesIntercept) {
- for (int i = 0; i < arraysize(kChromeTestPluginPayloads); ++i) {
- RunTest(GURL(kChromeTestPluginPayloads[i].url),
- &kChromeTestPluginPayloads[i]);
- }
-}
-
-// Tests that non-intercepted URLs are handled normally.
-TEST_F(ChromePluginTest, DoesNotIntercept) {
- TestResponsePayload about_blank = {
- "about:blank",
- false,
- -1,
- NULL,
- ""
- };
- RunTest(GURL(about_blank.url), &about_blank);
-}
-
-// Tests that unloading the plugin correctly unregisters URL interception.
-TEST_F(ChromePluginTest, UnregisterIntercept) {
- UnloadPlugin();
-
- RunTest(GURL(kChromeTestPluginPayloads[0].url), NULL);
-}
-
-static void ProcessAllPendingMessages() {
- while (URLRequestTestJob::ProcessOnePendingMessage());
-}
-
-// Tests that the plugin can issue a GET request and receives the data when
-// it comes back synchronously.
-TEST_F(ChromePluginTest, CanMakeGETRequestSync) {
- // test_url_1 has a synchronous response
- EXPECT_EQ(CPERR_SUCCESS, test_funcs_.test_make_request(
- "GET", URLRequestTestJob::test_url_1()));
-
- // Note: we must add this task after we make the request, so that
- // URLRequestTestJob's StartAsync task is added and run first.
- MessageLoop::current()->PostTask(FROM_HERE,
- NewRunnableFunction(&ProcessAllPendingMessages));
- MessageLoop::current()->Run();
-}
-
-// Tests that the plugin can issue a GET request and receives the data when
-// it comes back asynchronously.
-TEST_F(ChromePluginTest, CanMakeGETRequestAsync) {
- // test_url_2 has an asynchronous response
- EXPECT_EQ(CPERR_SUCCESS, test_funcs_.test_make_request(
- "GET", URLRequestTestJob::test_url_2()));
-
- // Note: we must add this task after we make the request, so that
- // URLRequestTestJob's StartAsync task is added and run first.
- MessageLoop::current()->PostTask(FROM_HERE,
- NewRunnableFunction(&ProcessAllPendingMessages));
- MessageLoop::current()->Run();
-}
-
-// Tests that the plugin can issue a POST request.
-TEST_F(ChromePluginTest, CanMakePOSTRequest) {
- scoped_refptr<HTTPTestServer> server =
- HTTPTestServer::CreateServer(kDocRoot, NULL);
- ASSERT_TRUE(NULL != server.get());
-
- GURL url = server->TestServerPage("echo");
-
- EXPECT_EQ(CPERR_SUCCESS, test_funcs_.test_make_request("POST", url));
-
- // Note: we must add this task after we make the request, so that
- // URLRequestTestJob's StartAsync task is added and run first.
- MessageLoop::current()->PostTask(FROM_HERE,
- NewRunnableFunction(&ProcessAllPendingMessages));
- MessageLoop::current()->Run();
-}
-
-// Tests that the plugin does not intercept its own requests.
-TEST_F(ChromePluginTest, DoesNotInterceptOwnRequest) {
- const TestResponsePayload& payload = kChromeTestPluginPayloads[0];
-
- EXPECT_EQ(CPERR_SUCCESS, test_funcs_.test_make_request(
- "GET", GURL(payload.url)));
-
- MessageLoop::current()->Run();
-}